15 #include "llvm/ADT/TypeSwitch.h"
18 using namespace mlir::ptr;
33 for (DataLayoutEntryInterface entry : params) {
34 if (!entry.isTypeEntry())
36 if (cast<PtrType>(cast<Type>(entry.getKey())).getMemorySpace() ==
37 type.getMemorySpace()) {
38 if (
auto spec = dyn_cast<SpecAttr>(entry.getValue()))
53 for (DataLayoutEntryInterface newEntry : newLayout) {
54 if (!newEntry.isTypeEntry())
58 auto newType = llvm::cast<PtrType>(llvm::cast<Type>(newEntry.getKey()));
60 llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
61 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
62 return llvm::cast<PtrType>(type).getMemorySpace() ==
63 newType.getMemorySpace();
67 if (it == oldLayout.end()) {
68 it = llvm::find_if(oldLayout, [&](DataLayoutEntryInterface entry) {
69 if (
auto type = llvm::dyn_cast_if_present<Type>(entry.getKey())) {
70 auto ptrTy = llvm::cast<PtrType>(type);
71 return ptrTy.getMemorySpace() == getDefaultMemorySpace(ptrTy);
76 if (it != oldLayout.end()) {
77 auto spec = llvm::cast<SpecAttr>(*it);
78 size = spec.getSize();
82 auto newSpec = llvm::cast<SpecAttr>(newEntry.getValue());
83 uint32_t newSize = newSpec.getSize();
84 uint32_t newAbi = newSpec.getAbi();
85 if (size != newSize || abi < newAbi || abi % newAbi != 0)
91 uint64_t PtrType::getABIAlignment(
const DataLayout &dataLayout,
100 std::optional<uint64_t>
104 return spec.getIndex() == SpecAttr::kOptionalSpecValue ? spec.getSize()
112 llvm::TypeSize PtrType::getTypeSizeInBits(
const DataLayout &dataLayout,
115 return llvm::TypeSize::getFixed(spec.getSize());
123 uint64_t PtrType::getPreferredAlignment(
const DataLayout &dataLayout,
134 for (DataLayoutEntryInterface entry : entries) {
135 if (!entry.isTypeEntry())
137 auto key = llvm::cast<Type>(entry.getKey());
138 if (!llvm::isa<SpecAttr>(entry.getValue())) {
139 return emitError(loc) <<
"expected layout attribute for " << key
140 <<
" 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 kDefaultPointerAlignment
static Attribute getDefaultMemorySpace(PtrType ptr)
static SpecAttr getPointerSpec(DataLayoutEntryListRef params, PtrType type)
Searches the data layout for the pointer spec, returns nullptr if it is not found.
constexpr static const unsigned kDefaultPointerSizeBits
constexpr static const unsigned kBitsInByte
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.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
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...