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)
95uint64_t PtrType::getABIAlignment(
const DataLayout &dataLayout,
97 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
99 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
105std::optional<uint64_t>
106PtrType::getIndexBitwidth(
const DataLayout &dataLayout,
108 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
110 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace)) {
111 return spec.getIndex() == SpecAttr::kOptionalSpecValue ? spec.getSize()
118llvm::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());
130uint64_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";
constexpr static const uint64_t kDefaultPointerSizeBits
constexpr static const uint64_t kBitsInByte
constexpr static const unsigned kDefaultPointerAlignmentBits
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.
::llvm::MapVector<::mlir::StringAttr, ::mlir::DataLayoutEntryInterface > DataLayoutIdentifiedEntryMap
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
llvm::ArrayRef< DataLayoutEntryInterface > DataLayoutEntryListRef
llvm::function_ref< Fn > function_ref