12
12
#include " mlir/IR/MLIRContext.h"
13
13
14
14
#include " llvm/ADT/TypeSwitch.h"
15
- #include " llvm/IR/DataLayout.h"
16
15
#include " llvm/IR/DerivedTypes.h"
17
16
#include " llvm/IR/Type.h"
18
17
@@ -25,7 +24,9 @@ namespace detail {
25
24
class TypeFromLLVMIRTranslatorImpl {
26
25
public:
27
26
// / 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) {}
29
30
30
31
// / Translates the given type.
31
32
Type translateType (llvm::Type *type) {
@@ -103,7 +104,7 @@ class TypeFromLLVMIRTranslatorImpl {
103
104
// / Translates the given structure type.
104
105
Type translate (llvm::StructType *type) {
105
106
SmallVector<Type, 8 > subtypes;
106
- if (type->isLiteral ()) {
107
+ if (type->isLiteral () || importStructsAsLiterals ) {
107
108
translateTypes (type->subtypes (), subtypes);
108
109
return LLVM::LLVMStructType::getLiteral (&context, subtypes,
109
110
type->isPacked ());
@@ -132,7 +133,7 @@ class TypeFromLLVMIRTranslatorImpl {
132
133
Type translate (llvm::ScalableVectorType *type) {
133
134
return VectorType::get (type->getMinNumElements (),
134
135
translateType (type->getElementType ()),
135
- /* scalable =*/ true );
136
+ /* scalableDims =*/ true );
136
137
}
137
138
138
139
// / Translates the given target extension type.
@@ -158,14 +159,20 @@ class TypeFromLLVMIRTranslatorImpl {
158
159
159
160
// / The context in which MLIR types are created.
160
161
MLIRContext &context;
162
+
163
+ // / Controls if structs should be imported as literal structs, i.e., nameless
164
+ // / structs.
165
+ bool importStructsAsLiterals;
161
166
};
162
167
163
168
} // namespace detail
164
169
} // namespace LLVM
165
170
} // namespace mlir
166
171
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)) {}
169
176
170
177
LLVM::TypeFromLLVMIRTranslator::~TypeFromLLVMIRTranslator () = default ;
171
178
0 commit comments