10#include "llvm/ADT/APFloat.h"
11#include "llvm/Support/Alignment.h"
17 : dl(dataLayout), builder(allocator) {}
20 if (
auto intTy = dyn_cast<mlir::IntegerType>(type))
21 return mapIntegerType(intTy);
23 if (
auto floatTy = dyn_cast<mlir::FloatType>(type))
24 return mapFloatType(floatTy);
26 if (
auto indexTy = dyn_cast<mlir::IndexType>(type))
27 return mapIndexType(indexTy);
29 if (
auto vecTy = dyn_cast<mlir::VectorType>(type))
30 return mapVectorType(vecTy);
32 if (
auto memRefTy = dyn_cast<mlir::MemRefType>(type))
33 return mapMemRefType(memRefTy);
35 if (
auto noneTy = dyn_cast<mlir::NoneType>(type))
36 return mapNoneType(noneTy);
40 llvm::TypeSize sizeInBits = dl.getTypeSizeInBits(type);
41 uint64_t abiAlign = dl.getTypeABIAlignment(type);
42 return builder.getIntegerType(sizeInBits.getFixedValue(),
43 llvm::Align(abiAlign),
47const llvm::abi::Type *ABITypeMapper::mapIntegerType(mlir::IntegerType type) {
48 uint64_t width = type.getWidth();
50 bool isSigned = type.isSigned() || type.isSignless();
51 return builder.getIntegerType(width, llvm::Align(abiAlign), isSigned);
54const llvm::abi::Type *ABITypeMapper::mapFloatType(mlir::FloatType type) {
56 const llvm::fltSemantics &semantics = type.getFloatSemantics();
57 return builder.getFloatType(semantics, llvm::Align(abiAlign));
60const llvm::abi::Type *ABITypeMapper::mapIndexType(mlir::IndexType type) {
63 return builder.getIntegerType(sizeInBits.getFixedValue(),
64 llvm::Align(abiAlign),
68const llvm::abi::Type *ABITypeMapper::mapVectorType(mlir::VectorType type) {
69 const llvm::abi::Type *elementTy =
map(type.getElementType());
73 auto shape = type.getShape();
74 uint64_t totalElements = 1;
75 for (int64_t dim : shape)
78 llvm::ElementCount ec = llvm::ElementCount::getFixed(totalElements);
79 uint64_t abiAlign = dl.getTypeABIAlignment(type);
80 return builder.getVectorType(elementTy, ec, llvm::Align(abiAlign));
83const llvm::abi::Type *ABITypeMapper::mapMemRefType(mlir::MemRefType type) {
84 llvm::TypeSize sizeInBits = dl.getTypeSizeInBits(type);
85 uint64_t abiAlign = dl.getTypeABIAlignment(type);
86 unsigned addrSpace = 0;
87 if (
auto as = type.getMemorySpace())
88 if (
auto intAttr = dyn_cast<IntegerAttr>(as))
89 addrSpace = intAttr.getInt();
90 return builder.getPointerType(sizeInBits.getFixedValue(),
91 llvm::Align(abiAlign), addrSpace);
94const llvm::abi::Type *ABITypeMapper::mapNoneType(mlir::NoneType type) {
95 return builder.getVoidType();
The main mechanism for performing data layout queries.
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.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
const llvm::abi::Type * map(mlir::Type type)
Map an MLIR type to its ABI type representation.
ABITypeMapper(const DataLayout &dl)
Include the generated interface declarations.