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/ADT/TypeSwitch.h"
22 #include "llvm/Support/Casting.h"
23 #include "llvm/Support/TrailingObjects.h"
37 private llvm::TrailingObjects<FileLineColRangeAttrStorage, unsigned> {
38 friend llvm::TrailingObjects<FileLineColRangeAttrStorage, unsigned>;
40 using KeyTy = std::tuple<StringAttr, ::llvm::ArrayRef<unsigned>>;
47 auto numInArray = std::get<1>(tblgenKey).
size();
53 auto locEnc = numInArray == 0 ? 1 : numInArray;
56 FileLineColRangeAttrStorage::totalSizeToAlloc<unsigned>(locEnc - 1);
60 std::move(std::get<0>(tblgenKey)), locEnc - 1);
63 result->startLine = elements[0];
65 llvm::uninitialized_copy(elements.drop_front(),
66 result->getTrailingObjects());
76 (
size() == std::get<1>(tblgenKey).size()) &&
77 (
startLine == std::get<1>(tblgenKey)[0]) &&
78 (getTrailingObjects(
size() - 1) ==
79 std::get<1>(tblgenKey).drop_front());
83 return getTrailingObjects()[index - 1];
104 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
121 #define GET_ATTRDEF_CLASSES
122 #include "mlir/IR/BuiltinLocationAttributes.cpp.inc"
132 if (
auto loc = llvm::dyn_cast<LocationAttr>(attr))
150 assert(!frames.empty() &&
"required at least 1 call frame");
152 for (
auto frame : llvm::reverse(frames.drop_back()))
163 return llvm::cast<FileLineColLoc>(
168 unsigned line,
unsigned column) {
169 return llvm::cast<FileLineColLoc>(
174 return FileLineColRange::getFilename();
182 if (
auto range = mlir::dyn_cast<FileLineColRange>(loc))
183 return range.getImpl()->size() == 2;
191 StringAttr FileLineColRange::getFilename()
const {
192 return getImpl()->filenameAndTrailing.getPointer();
195 unsigned FileLineColRange::getStartLine()
const {
196 return getImpl()->getStartLine();
198 unsigned FileLineColRange::getStartColumn()
const {
199 return getImpl()->getStartColumn();
201 unsigned FileLineColRange::getEndColumn()
const {
202 return getImpl()->getEndColumn();
204 unsigned FileLineColRange::getEndLine()
const {
205 return getImpl()->getEndLine();
215 llvm::SmallSetVector<Location, 4> decomposedLocs;
216 for (
auto loc : locs) {
219 if (
auto fusedLoc = llvm::dyn_cast<FusedLoc>(loc)) {
220 if (fusedLoc.getMetadata() == metadata) {
223 decomposedLocs.insert_range(fusedLoc.getLocations());
228 if (!llvm::isa<UnknownLoc>(loc))
229 decomposedLocs.insert(loc);
231 locs = decomposedLocs.getArrayRef();
243 if (locs.size() == 1 && !metadata)
246 return Base::get(context, locs, metadata);
253 void BuiltinDialect::registerLocationAttributes() {
255 #define GET_ATTRDEF_LIST
256 #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