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 public llvm::TrailingObjects<FileLineColRangeAttrStorage, unsigned> {
39 using KeyTy = std::tuple<StringAttr, ::llvm::ArrayRef<unsigned>>;
46 auto numInArray = std::get<1>(tblgenKey).
size();
52 auto locEnc = numInArray == 0 ? 1 : numInArray;
55 FileLineColRangeAttrStorage::totalSizeToAlloc<unsigned>(locEnc - 1);
59 std::move(std::get<0>(tblgenKey)), locEnc - 1);
61 result->startLine = std::get<1>(tblgenKey)[0];
63 std::uninitialized_copy(std::next(std::get<1>(tblgenKey).begin()),
64 std::get<1>(tblgenKey).end(),
65 result->getTrailingObjects<
unsigned>());
75 (
size() == std::get<1>(tblgenKey).size()) &&
76 (
startLine == std::get<1>(tblgenKey)[0]) &&
82 return getTrailingObjects<unsigned>()[index - 1];
103 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
120 #define GET_ATTRDEF_CLASSES
121 #include "mlir/IR/BuiltinLocationAttributes.cpp.inc"
131 if (
auto loc = llvm::dyn_cast<LocationAttr>(attr))
149 assert(!frames.empty() &&
"required at least 1 call frame");
151 for (
auto frame : llvm::reverse(frames.drop_back()))
162 return llvm::cast<FileLineColLoc>(
167 unsigned line,
unsigned column) {
168 return llvm::cast<FileLineColLoc>(
173 return FileLineColRange::getFilename();
181 if (
auto range = mlir::dyn_cast<FileLineColRange>(loc))
182 return range.getImpl()->size() == 2;
190 StringAttr FileLineColRange::getFilename()
const {
191 return getImpl()->filenameAndTrailing.getPointer();
194 unsigned FileLineColRange::getStartLine()
const {
195 return getImpl()->getStartLine();
197 unsigned FileLineColRange::getStartColumn()
const {
198 return getImpl()->getStartColumn();
200 unsigned FileLineColRange::getEndColumn()
const {
201 return getImpl()->getEndColumn();
203 unsigned FileLineColRange::getEndLine()
const {
204 return getImpl()->getEndLine();
214 llvm::SmallSetVector<Location, 4> decomposedLocs;
215 for (
auto loc : locs) {
218 if (
auto fusedLoc = llvm::dyn_cast<FusedLoc>(loc)) {
219 if (fusedLoc.getMetadata() == metadata) {
222 decomposedLocs.insert_range(fusedLoc.getLocations());
227 if (!llvm::isa<UnknownLoc>(loc))
228 decomposedLocs.insert(loc);
230 locs = decomposedLocs.getArrayRef();
242 if (locs.size() == 1 && !metadata)
245 return Base::get(context, locs, metadata);
252 void BuiltinDialect::registerLocationAttributes() {
254 #define GET_ATTRDEF_LIST
255 #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