14 #include "llvm/ADT/TypeSwitch.h" 15 #include "llvm/IR/DataLayout.h" 16 #include "llvm/IR/DerivedTypes.h" 17 #include "llvm/IR/Type.h" 33 if (knownTranslations.count(type))
34 return knownTranslations.lookup(type);
37 llvm::Type *translated =
39 .Case([
this](LLVM::LLVMVoidType) {
40 return llvm::Type::getVoidTy(context);
43 [
this](Float16Type) {
return llvm::Type::getHalfTy(context); })
44 .Case([
this](BFloat16Type) {
45 return llvm::Type::getBFloatTy(context);
48 [
this](Float32Type) {
return llvm::Type::getFloatTy(context); })
49 .Case([
this](Float64Type) {
50 return llvm::Type::getDoubleTy(context);
52 .Case([
this](Float80Type) {
53 return llvm::Type::getX86_FP80Ty(context);
55 .Case([
this](Float128Type) {
56 return llvm::Type::getFP128Ty(context);
58 .Case([
this](LLVM::LLVMPPCFP128Type) {
59 return llvm::Type::getPPC_FP128Ty(context);
61 .Case([
this](LLVM::LLVMX86MMXType) {
62 return llvm::Type::getX86_MMXTy(context);
64 .Case([
this](LLVM::LLVMTokenType) {
65 return llvm::Type::getTokenTy(context);
67 .Case([
this](LLVM::LLVMLabelType) {
68 return llvm::Type::getLabelTy(context);
70 .Case([
this](LLVM::LLVMMetadataType) {
71 return llvm::Type::getMetadataTy(context);
77 [
this](
auto type) {
return this->translate(type); })
78 .Default([](
Type t) -> llvm::Type * {
79 llvm_unreachable(
"unknown LLVM dialect type");
83 knownTranslations.try_emplace(type, translated);
97 translateTypes(type.
getParams(), paramTypes);
103 llvm::Type *translate(IntegerType type) {
104 return llvm::IntegerType::get(context, type.getWidth());
121 translateTypes(type.
getBody(), subtypes);
122 return llvm::StructType::get(context, subtypes, type.
isPacked());
125 llvm::StructType *structType =
126 llvm::StructType::create(context, type.
getName());
129 knownTranslations.try_emplace(type, structType);
133 translateTypes(type.
getBody(), subtypes);
134 structType->setBody(subtypes, type.
isPacked());
139 llvm::Type *translate(VectorType type) {
141 "expected compatible with LLVM vector type");
142 if (type.isScalable())
143 return llvm::ScalableVectorType::get(
translateType(type.getElementType()),
144 type.getNumElements());
145 return llvm::FixedVectorType::get(
translateType(type.getElementType()),
146 type.getNumElements());
164 result.reserve(result.size() + types.size());
165 for (
auto type : types)
170 llvm::LLVMContext &context;
188 return impl->translateType(type);
192 Type type,
const llvm::DataLayout &layout) {
TODO: Remove this file when SCCP and integer range analysis have been ported to the new framework...
LLVM dialect scalable vector type, represents a sequence of elements of unknown length that is known ...
unsigned getMinNumElements()
Returns the scaling factor of the number of elements in the vector.
StringRef getName()
Returns the name of an identified struct.
llvm::Type * translateType(Type type)
Translates a single type.
TypeToLLVMIRTranslator(llvm::LLVMContext &context)
Support for translating MLIR LLVM dialect types to LLVM IR.
LLVM dialect function type.
bool isOpaque() const
Returns true if this type is the opaque pointer type, i.e., it has no pointed-to type.
unsigned getAddressSpace() const
Returns the address space of the pointer.
bool isOpaque()
Checks if a struct is opaque.
Type getElementType() const
Returns the element type of the vector.
bool isVarArg() const
Returns whether the function is variadic.
Type getElementType() const
Returns the element type of the array.
Type getElementType() const
Returns the element type of the vector.
unsigned getNumElements()
Returns the number of elements in the fixed vector.
ArrayRef< Type > getBody() const
Returns the list of element types contained in a non-opaque struct.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
ArrayRef< Type > getParams() const
Returns a list of argument types of the function.
unsigned getNumElements() const
Returns the number of elements in the array type.
bool isPacked() const
Checks if a struct is packed.
LLVM dialect structure type representing a collection of different-typed elements manipulated togethe...
bool isCompatibleVectorType(Type type)
Returns true if the given type is a vector type compatible with the LLVM dialect. ...
TypeToLLVMIRTranslatorImpl(llvm::LLVMContext &context)
Constructs a class creating types in the given LLVM context.
bool isIdentified() const
Checks if a struct is identified.
LLVM dialect pointer type.
llvm::Type * translateType(Type type)
Translates the given MLIR LLVM dialect type to LLVM IR.
Type getReturnType() const
Returns the result type of the function.
unsigned getPreferredAlignment(Type type, const llvm::DataLayout &layout)
Returns the preferred alignment for the type given the data layout.
LLVM dialect fixed vector type, represents a sequence of elements of known length that can be process...
Type getElementType() const
Returns the pointed-to type. It may be null if the pointer is opaque.
~TypeToLLVMIRTranslator()