30 MemorySpaceAttrInterface defaultMemorySpace) {
31 for (DataLayoutEntryInterface entry : params) {
32 if (!entry.isTypeEntry())
34 if (cast<PtrType>(cast<Type>(entry.getKey())).getMemorySpace() ==
35 type.getMemorySpace()) {
36 if (
auto spec = dyn_cast<SpecAttr>(entry.getValue()))
43 if (type.getMemorySpace() == defaultMemorySpace ||
44 defaultMemorySpace ==
nullptr)
53 DataLayoutSpecInterface newSpec,
55 for (DataLayoutEntryInterface newEntry : newLayout) {
56 if (!newEntry.isTypeEntry())
60 auto newType = llvm::cast<PtrType>(llvm::cast<Type>(newEntry.getKey()));
62 llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
63 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
64 return llvm::cast<PtrType>(type).getMemorySpace() ==
65 newType.getMemorySpace();
69 if (it == oldLayout.end()) {
71 map.lookup(newSpec.getDefaultMemorySpaceIdentifier(
getContext())));
72 it = llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
73 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
74 auto ptrTy = llvm::cast<PtrType>(type);
75 return ptrTy.getMemorySpace() == defaultMemorySpace;
80 if (it != oldLayout.end()) {
81 auto spec = llvm::cast<SpecAttr>(*it);
82 size = spec.getSize();
86 auto newSpec = llvm::cast<SpecAttr>(newEntry.getValue());
87 uint32_t newSize = newSpec.getSize();
88 uint32_t newAbi = newSpec.getAbi();
89 if (size != newSize || abi < newAbi || abi % newAbi != 0)
95 uint64_t PtrType::getABIAlignment(
const DataLayout &dataLayout,
97 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
99 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
105 std::optional<uint64_t>
108 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
110 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace)) {
111 return spec.getIndex() == SpecAttr::kOptionalSpecValue ? spec.getSize()
118 llvm::TypeSize PtrType::getTypeSizeInBits(
const DataLayout &dataLayout,
120 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
122 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
123 return llvm::TypeSize::getFixed(spec.getSize());
130 uint64_t PtrType::getPreferredAlignment(
const DataLayout &dataLayout,
132 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
134 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
142 for (DataLayoutEntryInterface entry : entries) {
143 if (!entry.isTypeEntry())
145 auto key = llvm::cast<Type>(entry.getKey());
146 if (!llvm::isa<SpecAttr>(entry.getValue())) {
147 return emitError(loc) <<
"expected layout attribute for " << key
148 <<
" to be a #ptr.spec attribute";
160 PtrLikeTypeInterface type) {
161 if (!type.hasPtrMetadata())
162 return emitError() <<
"the ptr-like type has no metadata";
static LogicalResult verifyEntries(function_ref< InFlightDiagnostic()> emitError, ArrayRef< DataLayoutEntryInterface > entries, bool allowTypes=true)
Verify entries, with the option to disallow types as keys.
static uint64_t getIndexBitwidth(DataLayoutEntryListRef params)
Returns the bitwidth of the index type if specified in the param list.
static MLIRContext * getContext(OpFoldResult val)
constexpr static const unsigned kDefaultPointerAlignmentBits
constexpr static const unsigned kDefaultPointerSizeBits
constexpr static const unsigned kBitsInByte
static SpecAttr getPointerSpec(DataLayoutEntryListRef params, PtrType type, MemorySpaceAttrInterface defaultMemorySpace)
Searches the data layout for the pointer spec, returns nullptr if it is not found.
Attributes are known-constant values of operations.
The main mechanism for performing data layout queries.
std::optional< uint64_t > getTypeIndexBitwidth(Type t) const
Returns the bitwidth that should be used when performing index computations for the given pointer-lik...
uint64_t getTypePreferredAlignment(Type t) const
Returns the preferred of the given type in the current scope.
uint64_t getTypeABIAlignment(Type t) const
Returns the required alignment of the given type in the current scope.
llvm::TypeSize getTypeSizeInBits(Type t) const
Returns the size in bits of the given type in the current scope.
Attribute getDefaultMemorySpace() const
Returns the default memory space used for memory operations.
This class represents a diagnostic that is inflight and set to be reported.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Attribute getDefaultMemorySpace(DataLayoutEntryInterface entry)
Default handler for the default memory space request.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
::llvm::MapVector<::mlir::StringAttr, ::mlir::DataLayoutEntryInterface > DataLayoutIdentifiedEntryMap
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...