15 #include "llvm/ADT/TypeSwitch.h"
31 MemorySpaceAttrInterface defaultMemorySpace) {
32 for (DataLayoutEntryInterface entry : params) {
33 if (!entry.isTypeEntry())
35 if (cast<PtrType>(cast<Type>(entry.getKey())).getMemorySpace() ==
36 type.getMemorySpace()) {
37 if (
auto spec = dyn_cast<SpecAttr>(entry.getValue()))
44 if (type.getMemorySpace() == defaultMemorySpace ||
45 defaultMemorySpace ==
nullptr)
54 DataLayoutSpecInterface newSpec,
56 for (DataLayoutEntryInterface newEntry : newLayout) {
57 if (!newEntry.isTypeEntry())
61 auto newType = llvm::cast<PtrType>(llvm::cast<Type>(newEntry.getKey()));
63 llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
64 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
65 return llvm::cast<PtrType>(type).getMemorySpace() ==
66 newType.getMemorySpace();
70 if (it == oldLayout.end()) {
72 map.lookup(newSpec.getDefaultMemorySpaceIdentifier(
getContext())));
73 it = llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
74 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
75 auto ptrTy = llvm::cast<PtrType>(type);
76 return ptrTy.getMemorySpace() == defaultMemorySpace;
81 if (it != oldLayout.end()) {
82 auto spec = llvm::cast<SpecAttr>(*it);
83 size = spec.getSize();
87 auto newSpec = llvm::cast<SpecAttr>(newEntry.getValue());
88 uint32_t newSize = newSpec.getSize();
89 uint32_t newAbi = newSpec.getAbi();
90 if (size != newSize || abi < newAbi || abi % newAbi != 0)
96 uint64_t PtrType::getABIAlignment(
const DataLayout &dataLayout,
98 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
100 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
106 std::optional<uint64_t>
109 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
111 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace)) {
112 return spec.getIndex() == SpecAttr::kOptionalSpecValue ? spec.getSize()
119 llvm::TypeSize PtrType::getTypeSizeInBits(
const DataLayout &dataLayout,
121 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
123 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
124 return llvm::TypeSize::getFixed(spec.getSize());
131 uint64_t PtrType::getPreferredAlignment(
const DataLayout &dataLayout,
133 auto defaultMemorySpace = llvm::cast_if_present<MemorySpaceAttrInterface>(
135 if (SpecAttr spec =
getPointerSpec(params, *
this, defaultMemorySpace))
143 for (DataLayoutEntryInterface entry : entries) {
144 if (!entry.isTypeEntry())
146 auto key = llvm::cast<Type>(entry.getKey());
147 if (!llvm::isa<SpecAttr>(entry.getValue())) {
148 return emitError(loc) <<
"expected layout attribute for " << key
149 <<
" to be a #ptr.spec attribute";
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 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...