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);
55 auto *
result = ::new (rawMem)
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));
113#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
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()))
153 caller = CallSiteLoc::get(frame, caller);
154 return CallSiteLoc::get(name, caller);
163 return llvm::cast<FileLineColLoc>(
164 FileLineColRange::get(filename, line, column));
168 unsigned line,
unsigned column) {
169 return llvm::cast<FileLineColLoc>(
170 FileLineColRange::get(context, fileName, line, column));
174 return FileLineColRange::getFilename();
182 if (
auto range = mlir::dyn_cast<FileLineColRange>(loc))
183 return range.getImpl()->size() == 2;
191StringAttr FileLineColRange::getFilename()
const {
192 return getImpl()->filenameAndTrailing.getPointer();
195unsigned FileLineColRange::getStartLine()
const {
196 return getImpl()->getStartLine();
198unsigned FileLineColRange::getStartColumn()
const {
199 return getImpl()->getStartColumn();
201unsigned FileLineColRange::getEndColumn()
const {
202 return getImpl()->getEndColumn();
204unsigned 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();
237 return UnknownLoc::get(context);
243 if (locs.size() == 1 && !metadata)
246 return Base::get(context, locs, metadata);
253void 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.
constexpr Attribute()=default
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
LLVM_DUMP_METHOD void dump() const
MLIRContext is the top-level object for a collection of MLIR operations.
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.
StorageUniquer::StorageAllocator AttributeStorageAllocator
llvm::function_ref< Fn > function_ref
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
FileLineColRangeAttrStorage(StringAttr filename, int numLocs)
unsigned getStartColumn() const
::llvm::hash_code hashKey(const KeyTy &tblgenKey)
unsigned getEndColumn() const
unsigned getEndLine() const
static FileLineColRangeAttrStorage * construct(::mlir::AttributeStorageAllocator &allocator, KeyTy &&tblgenKey)
unsigned getStartLine() const
llvm::PointerIntPair< StringAttr, 2 > PointerPair
llvm::PointerIntPair< StringAttr, 2 > filenameAndTrailing
std::tuple< StringAttr, ::llvm::ArrayRef< unsigned > > KeyTy
bool operator==(const KeyTy &tblgenKey) const