16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/Hashing.h"
18 #include "llvm/ADT/PointerIntPair.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/ADT/SetVector.h"
21 #include "llvm/Support/Casting.h"
22 #include "llvm/Support/TrailingObjects.h"
33 private llvm::TrailingObjects<FileLineColRangeAttrStorage, unsigned> {
34 friend llvm::TrailingObjects<FileLineColRangeAttrStorage, unsigned>;
36 using KeyTy = std::tuple<StringAttr, ::llvm::ArrayRef<unsigned>>;
43 auto numInArray = std::get<1>(tblgenKey).
size();
49 auto locEnc = numInArray == 0 ? 1 : numInArray;
52 FileLineColRangeAttrStorage::totalSizeToAlloc<unsigned>(locEnc - 1);
56 std::move(std::get<0>(tblgenKey)), locEnc - 1);
59 result->startLine = elements[0];
61 llvm::uninitialized_copy(elements.drop_front(),
62 result->getTrailingObjects());
72 (
size() == std::get<1>(tblgenKey).size()) &&
73 (
startLine == std::get<1>(tblgenKey)[0]) &&
74 (getTrailingObjects(
size() - 1) ==
75 std::get<1>(tblgenKey).drop_front());
79 return getTrailingObjects()[index - 1];
100 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
117 #define GET_ATTRDEF_CLASSES
118 #include "mlir/IR/BuiltinLocationAttributes.cpp.inc"
128 if (
auto loc = llvm::dyn_cast<LocationAttr>(attr))
146 assert(!frames.empty() &&
"required at least 1 call frame");
148 for (
auto frame : llvm::reverse(frames.drop_back()))
159 return llvm::cast<FileLineColLoc>(
164 unsigned line,
unsigned column) {
165 return llvm::cast<FileLineColLoc>(
170 return FileLineColRange::getFilename();
178 if (
auto range = mlir::dyn_cast<FileLineColRange>(loc))
179 return range.getImpl()->size() == 2;
187 StringAttr FileLineColRange::getFilename()
const {
188 return getImpl()->filenameAndTrailing.getPointer();
191 unsigned FileLineColRange::getStartLine()
const {
192 return getImpl()->getStartLine();
194 unsigned FileLineColRange::getStartColumn()
const {
195 return getImpl()->getStartColumn();
197 unsigned FileLineColRange::getEndColumn()
const {
198 return getImpl()->getEndColumn();
200 unsigned FileLineColRange::getEndLine()
const {
201 return getImpl()->getEndLine();
211 llvm::SmallSetVector<Location, 4> decomposedLocs;
212 for (
auto loc : locs) {
215 if (
auto fusedLoc = llvm::dyn_cast<FusedLoc>(loc)) {
216 if (fusedLoc.getMetadata() == metadata) {
219 decomposedLocs.insert_range(fusedLoc.getLocations());
224 if (!llvm::isa<UnknownLoc>(loc))
225 decomposedLocs.insert(loc);
227 locs = decomposedLocs.getArrayRef();
239 if (locs.size() == 1 && !metadata)
242 return Base::get(context, locs, metadata);
249 void BuiltinDialect::registerLocationAttributes() {
251 #define GET_ATTRDEF_LIST
252 #include "mlir/IR/BuiltinLocationAttributes.cpp.inc"
void addWalk(WalkFn< Attribute > &&fn)
Register a walk function for a given attribute or type.
WalkResult walk(T element)
Walk the given attribute/type, and recursively walk any sub elements.
Base storage class appearing in an attribute.
Attributes are known-constant values of operations.
bool hasTrait()
Returns true if the type was registered with a particular trait.
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
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.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This is a utility allocator used to allocate memory for instances of derived types.
T * allocate()
Allocate an instance of the provided type.
A utility result that is used to signal how to proceed with an ongoing walk:
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...
bool isStrictFileLineColLoc(Location loc)
Returns true iff the given location is a FileLineColRange with exactly one line and column.
This trait is used to determine if an attribute is a location or not.
unsigned getLineCols(unsigned index) const
static FileLineColRangeAttrStorage * construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey)
FileLineColRangeAttrStorage(StringAttr filename, int numLocs)
unsigned getStartColumn() const
::llvm::hash_code hashKey(const KeyTy &tblgenKey)
unsigned getEndColumn() const
unsigned getEndLine() const
std::tuple< StringAttr, ::llvm::ArrayRef< unsigned > > KeyTy
unsigned getStartLine() const
llvm::PointerIntPair< StringAttr, 2 > PointerPair
llvm::PointerIntPair< StringAttr, 2 > filenameAndTrailing
bool operator==(const KeyTy &tblgenKey) const