MLIR: include/mlir/IR/Location.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14 #ifndef MLIR_IR_LOCATION_H

15 #define MLIR_IR_LOCATION_H

16

18 #include "llvm/Support/PointerLikeTypeTraits.h"

19

20 namespace mlir {

21

22 class Location;

23 class WalkResult;

24 class UnknownLoc;

25

26

27

28

29

30

31

33 public:

35

36

37

38

39

41

42

43

44 template

46 T result = {};

47 walk([&](auto loc) {

48 if (auto typedLoc = llvm::dyn_cast(loc)) {

49 result = typedLoc;

51 }

53 });

54 return result;

55 }

56

57

58

59 template <typename T, typename UnknownT = UnknownLoc>

61 if (T result = findInstanceOf())

62 return result;

64 }

65

66

68 };

69

70

71

72

73

74

75

77 public:

79 assert(loc && "location should never be null.");

80 }

82 assert(impl && "location should never be null.");

83 }

84

85

87

88

91

92

95

96

97 void print(raw_ostream &os) const { impl.print(os); }

99

101

102

106 }

107

108

109 static bool classof(Attribute attr) { return llvm::isa(attr); }

110

111 protected:

112

114 };

115

118 return os;

119 }

120

121

124 }

125

126 }

127

128

129

130

131

132

134 struct FileLineColRangeAttrStorage;

135 }

136

137 #define GET_ATTRDEF_CLASSES

138 #include "mlir/IR/BuiltinLocationAttributes.h.inc"

139

140 namespace mlir {

141

142

143

144

145

146

147

148 template

150 public:

151 using FusedLoc::FusedLoc;

152

153

155 return llvm::cast(FusedLoc::getMetadata());

156 }

157

158

160 auto fusedLoc = llvm::dyn_cast(attr);

161 return fusedLoc && mlir::isa_and_nonnull(fusedLoc.getMetadata());

162 }

163 };

164

165

166

167

168

169

170

171

172

173

175 public:

176 using FileLineColRange::FileLineColRange;

177

179 unsigned column);

181 unsigned line, unsigned column);

182

184 unsigned getLine() const;

186 };

187

188

189

191

192

193

194

195

196

197

198 template

200 return get(reinterpret_cast<uintptr_t>(underlyingLocation), TypeID::get(),

202 }

203

204

205

206

207

208

209 template <>

212 walker.walk(param);

213 }

216 return cast(attrRepls.take_front(1)[0]);

217 }

218 };

219

220 }

221

222

223

224

225

226 namespace llvm {

227

228

229 template <>

234 }

238 }

241 }

243 return LHS == RHS;

244 }

245 };

246

247

248 template <>

249 struct PointerLikeTypeTraits<mlir::Location> {

250 public:

253 }

256 }

257 static constexpr int NumLowBitsAvailable =

259 };

260

261

262

263

264 template <>

265 struct ValueIsPresent<mlir::Location> {

268 };

269

270

271

272 template <typename To, typename From>

274 std::enable_if_t<

275 std::is_same_v<mlir::Location, std::remove_const_t> ||

276 std::is_base_of_v<mlir::Location, From>>>

278

280

281

282

283 return std::is_same_v<To, std::remove_const_t> ||

285 }

286

288

290 return To(location->getImpl());

291 }

292 };

293

294 }

295

296 #endif

This class is used by AttrTypeSubElementHandler instances to process sub element replacements.

ArrayRef< T > take_front(unsigned n)

Take the first N replacements as an ArrayRef, dropping them from this replacement list.

Base storage class appearing in an attribute.

Attributes are known-constant values of operations.

constexpr Attribute()=default

MLIRContext * getContext() const

Return the context this attribute belongs to.

ImplType * getImpl() const

Return the internal Attribute implementation.

An instance of this location represents a tuple of file, line number, and column number.

StringAttr getFilename() const

static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)

unsigned getColumn() const

This class represents a fused location whose metadata is known to be an instance of the given type.

MetadataT getMetadata() const

Return the metadata associated with this fused location.

static bool classof(Attribute attr)

Support llvm style casting.

Location objects represent source locations information in MLIR.

WalkResult walk(function_ref< WalkResult(Location)> walkFn)

Walk all of the locations nested directly under, and including, the current.

static bool classof(Attribute attr)

Methods for support type inquiry through isa, cast, and dyn_cast.

T findInstanceOf()

Return an instance of the given location type if one is nested under the current location.

LocationAttr findInstanceOfOrUnknown()

Return an instance of the given location type if one is nested under the current location else return...

This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...

const void * getAsOpaquePointer() const

Methods for supporting PointerLikeTypeTraits.

MLIRContext * getContext() const

Return the context this location is uniqued in.

friend ::llvm::hash_code hash_value(Location arg)

Location(LocationAttr loc)

static bool classof(Attribute attr)

Support llvm style casting.

Location(const LocationAttr::ImplType *impl)

LocationAttr impl

The internal backing location attribute.

static Location getFromOpaquePointer(const void *pointer)

bool operator!=(Location rhs) const

LocationAttr * operator->() const

bool operator==(Location rhs) const

Comparison operators.

void print(raw_ostream &os) const

Print the location.

MLIRContext is the top-level object for a collection of MLIR operations.

A utility result that is used to signal how to proceed with an ongoing walk:

static WalkResult advance()

static WalkResult interrupt()

The OpAsmOpInterface, see OpAsmInterface.td for more details.

Include the generated interface declarations.

auto get(MLIRContext *context, Ts &&...params)

Helper method that injects context only if needed, this helps unify some of the attribute constructio...

inline ::llvm::hash_code hash_value(AffineExpr arg)

Make AffineExpr hashable.

raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)

bool isStrictFileLineColLoc(Location loc)

Returns true iff the given location is a FileLineColRange with exactly one line and column.

static bool isPossible(mlir::Location location)

static To doCast(mlir::Location location)

static bool isEqual(mlir::Location LHS, mlir::Location RHS)

static unsigned getHashValue(mlir::Location val)

static mlir::Location getEmptyKey()

static mlir::Location getTombstoneKey()

static constexpr int NumLowBitsAvailable

static void * getAsVoidPointer(mlir::Location I)

static mlir::Location getFromVoidPointer(void *P)

static bool isPresent(const mlir::Location &location)

static Location replace(Location param, AttrSubElementReplacements &attrRepls, TypeSubElementReplacements &typeRepls)

static void walk(Location param, AttrTypeImmediateSubElementWalker &walker)

This class provides support for interacting with the SubElementInterfaces for different types of para...