23static std::optional<TypeSizeAndAlignment>
31std::optional<TypeSizeAndAlignment>
35 isa<ComplexType, VectorType, DataLayoutTypeInterface>(ty))
43 if (
auto memrefTy = dyn_cast<MemRefType>(ty)) {
44 if (!memrefTy.hasStaticShape())
47 memrefTy.getElementType(), module, dl, support);
48 if (!elemSizeAndAlignment)
50 int64_t totalSize = elemSizeAndAlignment->first.getFixedValue();
51 int64_t alignment = elemSizeAndAlignment->second.getFixedValue();
52 for (
int64_t dim : memrefTy.getShape())
55 llvm::TypeSize::getFixed(alignment)};
60 if (
auto tupleTy = dyn_cast<TupleType>(ty)) {
61 if (tupleTy.size() == 0)
63 auto sizeAndAlignment =
65 if (!sizeAndAlignment)
67 llvm::TypeSize size = sizeAndAlignment->first;
68 for (
unsigned i = 1, e = tupleTy.size(); i < e; ++i) {
78 if (isa<FunctionType>(ty))
80 LLVM::LLVMPointerType::get(ty.
getContext()), module, dl, support);
84 if (
auto mappableTy = dyn_cast<MappableType>(ty)) {
85 std::optional<llvm::TypeSize> size =
86 mappableTy.getSizeInBytes(var, {}, dl);
87 if (!size || size->isScalable())
89 llvm::TypeSize alignment = llvm::TypeSize::getFixed(1);
99std::optional<TypeSizeAndAlignment>
110 if (value.
getType() == resultType)
112 if (PointerLikeType ptrLike = dyn_cast<PointerLikeType>(value.
getType())) {
113 if (
Value casted = ptrLike.genCast(builder, loc, value, resultType))
116 if (PointerLikeType ptrLike = dyn_cast<PointerLikeType>(resultType)) {
117 if (
Value casted = ptrLike.genCast(builder, loc, value, resultType))
120 emitError(loc) <<
"unsupported pointer-like type cast from "
121 << value.
getType() <<
" to " << resultType;
The main mechanism for performing data layout queries.
llvm::TypeSize getTypeSize(Type t) const
Returns the size 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.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class helps build Operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
std::optional< TypeSizeAndAlignment > getTypeSizeAndAlignment(Type ty, ModuleOp module)
Returns the size and ABI alignment in bytes for ty.
std::optional< DataLayout > getDataLayout(Operation *op, bool allowDefault=true)
Get the data layout for an operation.
static std::optional< TypeSizeAndAlignment > getTypeSizeAndAlignmentHelper(Type ty, ModuleOp module, const DataLayout &dl, OpenACCSupport *support)
Value castPointerLikeTypeIfNeeded(OpBuilder &builder, Location loc, Value value, Type resultType)
Cast value to resultType via PointerLikeType::genCast when needed.
std::pair< llvm::TypeSize, llvm::TypeSize > TypeSizeAndAlignment
std::optional< TypeSizeAndAlignment > getTypeSizeAndAlignment(Type ty, ModuleOp module, const DataLayout &dl, OpenACCSupport *support=nullptr, Value var={})
Returns the size and ABI alignment in bytes.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.