31
31
#include " mlir/IR/OperationSupport.h"
32
32
#include " mlir/IR/SymbolTable.h"
33
33
#include " mlir/IR/Verifier.h"
34
+ #include " mlir/Target/LLVMIR/Import.h"
34
35
#include " clang/CIR/MissingFeatures.h"
35
36
36
37
#include " clang/AST/ASTConsumer.h"
@@ -96,6 +97,14 @@ static CIRGenCXXABI *createCXXABI(CIRGenModule &CGM) {
96
97
}
97
98
}
98
99
100
+ static void setMLIRDataLayout (mlir::ModuleOp &mod, const llvm::DataLayout &dl) {
101
+ auto *context = mod.getContext ();
102
+ mod->setAttr (mlir::LLVM::LLVMDialect::getDataLayoutAttrName (),
103
+ mlir::StringAttr::get (context, dl.getStringRepresentation ()));
104
+ mlir::DataLayoutSpecInterface dlSpec = mlir::translateDataLayout (dl, context);
105
+ mod->setAttr (mlir::DLTIDialect::kDataLayoutAttrName , dlSpec);
106
+ }
107
+
99
108
CIRGenModule::CIRGenModule (mlir::MLIRContext &context,
100
109
clang::ASTContext &astctx,
101
110
const clang::CodeGenOptions &CGO,
@@ -106,6 +115,10 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
106
115
target (astCtx.getTargetInfo()), ABI(createCXXABI(*this )), genTypes{*this },
107
116
VTables{*this }, openMPRuntime(new CIRGenOpenMPRuntime(*this )) {
108
117
118
+ // Initialize DataLayout in the module op.
119
+ auto layout = llvm::DataLayout (astCtx.getTargetInfo ().getDataLayoutString ());
120
+ setMLIRDataLayout (theModule, layout);
121
+
109
122
// Initialize CIR signed integer types cache.
110
123
SInt8Ty =
111
124
::mlir::cir::IntType::get (builder.getContext(), 8, /* isSigned=*/ true);
@@ -156,7 +169,8 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
156
169
/* isSigned=*/ false );
157
170
UInt8PtrTy = builder.getPointerTo (UInt8Ty);
158
171
UInt8PtrPtrTy = builder.getPointerTo (UInt8PtrTy);
159
- AllocaInt8PtrTy = UInt8PtrTy;
172
+ AllocaInt8PtrTy =
173
+ builder.getPointerTo (UInt8Ty, getDataLayout ().getAllocaMemorySpace ());
160
174
// TODO: GlobalsInt8PtrTy
161
175
// TODO: ConstGlobalsPtrTy
162
176
ASTAllocaAddressSpace = getTargetCIRGenInfo ().getASTAllocaAddressSpace ();
0 commit comments