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();
183 if (
auto range = mlir::dyn_cast<FileLineColRange>(attr))
184 return range.getImpl()->size() == 2;
192 StringAttr FileLineColRange::getFilename()
const {
193 return getImpl()->filenameAndTrailing.getPointer();
196 unsigned FileLineColRange::getStartLine()
const {
197 return getImpl()->getStartLine();
199 unsigned FileLineColRange::getStartColumn()
const {
200 return getImpl()->getStartColumn();
202 unsigned FileLineColRange::getEndColumn()
const {
203 return getImpl()->getEndColumn();
205 unsigned FileLineColRange::getEndLine()
const {
206 return getImpl()->getEndLine();
216 llvm::SmallSetVector<Location, 4> decomposedLocs;
217 for (
auto loc : locs) {
220 if (
auto fusedLoc = llvm::dyn_cast<FusedLoc>(loc)) {
221 if (fusedLoc.getMetadata() == metadata) {
224 decomposedLocs.insert(fusedLoc.getLocations().begin(),
225 fusedLoc.getLocations().end());
230 if (!llvm::isa<UnknownLoc>(loc))
231 decomposedLocs.insert(loc);
233 locs = decomposedLocs.getArrayRef();
245 if (locs.size() == 1 && !metadata)
248 return Base::get(context, locs, metadata);
255 void BuiltinDialect::registerLocationAttributes() {
257 #define GET_ATTRDEF_LIST
258 #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
static bool classof(Attribute attr)
Methods for support type inquiry through isa, cast, and dyn_cast.
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...
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