tvm
Loading...
Searching...
No Matches
location.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
23#ifndef TVM_IR_LOCATION_H_
24#define TVM_IR_LOCATION_H_
25
26#include <tvm/ffi/container/array.h>
27#include <tvm/ffi/function.h>
28#include <tvm/ffi/reflection/registry.h>
29#include <tvm/runtime/base.h>
30
31#include <fstream>
32#include <string>
33#include <utility>
34#include <vector>
35
36namespace tvm {
37
42class SourceName;
46class SourceNameObj : public ffi::Object {
47 public:
49 ffi::String name;
50
51 static void RegisterReflection() {
52 namespace refl = tvm::ffi::reflection;
53 refl::ObjectDef<SourceNameObj>().def_ro("name", &SourceNameObj::name);
54 }
55
56 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
57 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SourceName", SourceNameObj, ffi::Object);
58};
59
64class SourceName : public ffi::ObjectRef {
65 public:
72 TVM_TIRX_DLL static SourceName Get(const ffi::String& name);
73
74 explicit SourceName(ffi::UnsafeInit tag, ffi::ObjectPtr<SourceNameObj> n) : ffi::ObjectRef(tag) {
75 data_ = std::move(n);
76 }
77
79};
80
82class LocationObj : public ffi::Object {
83 public:
84 static void RegisterReflection() { ffi::reflection::ObjectDef<LocationObj>(); }
85
86 static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind = kTVMFFISEqHashKindTreeNode;
87 TVM_FFI_DECLARE_OBJECT_INFO("ir.Location", LocationObj, ffi::Object);
88};
89
91class Location : public ffi::ObjectRef {
92 public:
94};
95
97class UnknownLocObj : public LocationObj {
98 public:
99 static void RegisterReflection() { ffi::reflection::ObjectDef<UnknownLocObj>(); }
100
102};
103
111
113class SourceLocObj : public LocationObj {
114 public:
116 explicit SourceLocObj(ffi::UnsafeInit tag) : source_name(tag) {}
127
128 static void RegisterReflection() {
129 namespace refl = tvm::ffi::reflection;
130 refl::ObjectDef<SourceLocObj>()
131 .def_ro("source_name", &SourceLocObj::source_name)
132 .def_ro("start_line", &SourceLocObj::start_line)
133 .def_ro("start_column", &SourceLocObj::start_column)
134 .def_ro("end_line", &SourceLocObj::end_line)
135 .def_ro("end_column", &SourceLocObj::end_column);
136 }
137
139};
140
142class SourceLoc : public Location {
143 public:
144 TVM_TIRX_DLL SourceLoc(SourceName source_name, int start_line, int start_column, int end_line,
145 int end_column);
146
149
151};
152
155 public:
158
159 static void RegisterReflection() {
160 namespace refl = tvm::ffi::reflection;
161 refl::ObjectDef<CallSiteLocObj>()
162 .def_ro("callee", &CallSiteLocObj::callee)
163 .def_ro("caller", &CallSiteLocObj::caller);
164 }
165
167};
168
176
177} // namespace tvm
178
179#endif // TVM_IR_LOCATION_H_
#define TVM_TIRX_DLL
Definition base.h:55
The location of a callee together with its caller's provenance.
Definition location.h:154
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.CallSiteLoc", CallSiteLocObj, LocationObj)
Location callee
Definition location.h:156
static void RegisterReflection()
Definition location.h:159
Location caller
Definition location.h:157
Explicit inline callee/caller provenance.
Definition location.h:170
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(CallSiteLoc, Location, CallSiteLocObj)
TVM_TIRX_DLL CallSiteLoc(Location callee, Location caller)
Base class for immutable source-location metadata.
Definition location.h:82
TVM_FFI_DECLARE_OBJECT_INFO("ir.Location", LocationObj, ffi::Object)
static void RegisterReflection()
Definition location.h:84
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition location.h:86
Non-nullable source-location metadata.
Definition location.h:91
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Location, ffi::ObjectRef, LocationObj)
A range in one source, retaining frontend coordinate conventions.
Definition location.h:113
int start_line
The starting line number.
Definition location.h:120
int start_column
The starting column offset.
Definition location.h:122
SourceName source_name
The source name.
Definition location.h:118
SourceLocObj(SourceName source_name)
Definition location.h:115
int end_column
The ending column offset.
Definition location.h:126
SourceLocObj(ffi::UnsafeInit tag)
Definition location.h:116
static void RegisterReflection()
Definition location.h:128
int end_line
The ending line number.
Definition location.h:124
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SourceLoc", SourceLocObj, LocationObj)
A concrete source range.
Definition location.h:142
TVM_TIRX_DLL SourceLoc Merge(const SourceLoc &other) const
Merge two ranges in the same source.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SourceLoc, Location, SourceLocObj)
TVM_TIRX_DLL SourceLoc(SourceName source_name, int start_line, int start_column, int end_line, int end_column)
The name of a source fragment.
Definition location.h:46
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.SourceName", SourceNameObj, ffi::Object)
ffi::String name
The source name.
Definition location.h:49
static constexpr TVMFFISEqHashKind _type_s_eq_hash_kind
Definition location.h:56
static void RegisterReflection()
Definition location.h:51
The source name of a file loc.
Definition location.h:64
SourceName(ffi::UnsafeInit tag, ffi::ObjectPtr< SourceNameObj > n)
Definition location.h:74
static TVM_TIRX_DLL SourceName Get(const ffi::String &name)
Get an SourceName for a given operator name. Will raise an error if the source name has not been regi...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SourceName, ffi::ObjectRef, SourceNameObj)
No source-location information is available.
Definition location.h:97
static void RegisterReflection()
Definition location.h:99
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("ir.UnknownLoc", UnknownLocObj, LocationObj)
Reference to the shared immutable unknown location.
Definition location.h:105
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(UnknownLoc, Location, UnknownLocObj)
TVM_TIRX_DLL UnknownLoc()
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41