1212#include " mlir/IR/MLIRContext.h"
1313
1414#include " llvm/ADT/TypeSwitch.h"
15- #include " llvm/IR/DataLayout.h"
1615#include " llvm/IR/DerivedTypes.h"
1716#include " llvm/IR/Type.h"
1817
@@ -25,7 +24,9 @@ namespace detail {
2524class TypeFromLLVMIRTranslatorImpl {
2625public:
2726 // / Constructs a class creating types in the given MLIR context.
28- TypeFromLLVMIRTranslatorImpl (MLIRContext &context) : context(context) {}
27+ TypeFromLLVMIRTranslatorImpl (MLIRContext &context,
28+ bool importStructsAsLiterals)
29+ : context(context), importStructsAsLiterals(importStructsAsLiterals) {}
2930
3031 // / Translates the given type.
3132 Type translateType (llvm::Type *type) {
@@ -103,7 +104,7 @@ class TypeFromLLVMIRTranslatorImpl {
103104 // / Translates the given structure type.
104105 Type translate (llvm::StructType *type) {
105106 SmallVector<Type, 8 > subtypes;
106- if (type->isLiteral ()) {
107+ if (type->isLiteral () || importStructsAsLiterals ) {
107108 translateTypes (type->subtypes (), subtypes);
108109 return LLVM::LLVMStructType::getLiteral (&context, subtypes,
109110 type->isPacked ());
@@ -132,7 +133,7 @@ class TypeFromLLVMIRTranslatorImpl {
132133 Type translate (llvm::ScalableVectorType *type) {
133134 return VectorType::get (type->getMinNumElements (),
134135 translateType (type->getElementType ()),
135- /* scalable =*/ true );
136+ /* scalableDims =*/ true );
136137 }
137138
138139 // / Translates the given target extension type.
@@ -158,14 +159,20 @@ class TypeFromLLVMIRTranslatorImpl {
158159
159160 // / The context in which MLIR types are created.
160161 MLIRContext &context;
162+
163+ // / Controls if structs should be imported as literal structs, i.e., nameless
164+ // / structs.
165+ bool importStructsAsLiterals;
161166};
162167
163168} // namespace detail
164169} // namespace LLVM
165170} // namespace mlir
166171
167- LLVM::TypeFromLLVMIRTranslator::TypeFromLLVMIRTranslator (MLIRContext &context)
168- : impl(new detail::TypeFromLLVMIRTranslatorImpl(context)) {}
172+ LLVM::TypeFromLLVMIRTranslator::TypeFromLLVMIRTranslator (
173+ MLIRContext &context, bool importStructsAsLiterals)
174+ : impl(std::make_unique<detail::TypeFromLLVMIRTranslatorImpl>(
175+ context, importStructsAsLiterals)) {}
169176
170177LLVM::TypeFromLLVMIRTranslator::~TypeFromLLVMIRTranslator () = default ;
171178
0 commit comments