@@ -45,7 +45,7 @@ static std::string generateGlobalMsgSymbolName(ModuleOp moduleOp) {
45
45
46
46
// / Generate IR that prints the given string to stderr.
47
47
static void createPrintMsg (OpBuilder &builder, Location loc, ModuleOp moduleOp,
48
- StringRef msg) {
48
+ StringRef msg, LLVMTypeConverter &typeConverter ) {
49
49
auto ip = builder.saveInsertionPoint ();
50
50
builder.setInsertionPointToStart (moduleOp.getBody ());
51
51
MLIRContext *ctx = builder.getContext ();
@@ -68,12 +68,13 @@ static void createPrintMsg(OpBuilder &builder, Location loc, ModuleOp moduleOp,
68
68
// Emit call to `printStr` in runtime library.
69
69
builder.restoreInsertionPoint (ip);
70
70
auto msgAddr = builder.create <LLVM::AddressOfOp>(
71
- loc, LLVM::LLVMPointerType::get (arrayTy), globalOp.getName ());
71
+ loc, typeConverter. getPointerType (arrayTy), globalOp.getName ());
72
72
SmallVector<LLVM::GEPArg> indices (1 , 0 );
73
73
Value gep = builder.create <LLVM::GEPOp>(
74
- loc, LLVM::LLVMPointerType::get (builder.getI8Type ()), msgAddr, indices);
75
- Operation *printer =
76
- LLVM::lookupOrCreatePrintStrFn (moduleOp, /* TODO: opaquePointers=*/ false );
74
+ loc, typeConverter.getPointerType (builder.getI8Type ()), arrayTy, msgAddr,
75
+ indices);
76
+ Operation *printer = LLVM::lookupOrCreatePrintStrFn (
77
+ moduleOp, typeConverter.useOpaquePointers ());
77
78
builder.create <LLVM::CallOp>(loc, TypeRange (), SymbolRefAttr::get (printer),
78
79
gep);
79
80
}
@@ -102,7 +103,7 @@ struct AssertOpLowering : public ConvertOpToLLVMPattern<cf::AssertOp> {
102
103
103
104
// Failed block: Generate IR to print the message and call `abort`.
104
105
Block *failureBlock = rewriter.createBlock (opBlock->getParent ());
105
- createPrintMsg (rewriter, loc, module , op.getMsg ());
106
+ createPrintMsg (rewriter, loc, module , op.getMsg (), * getTypeConverter () );
106
107
if (abortOnFailedAssert) {
107
108
// Insert the `abort` declaration if necessary.
108
109
auto abortFunc = module .lookupSymbol <LLVM::LLVMFuncOp>(" abort" );
@@ -274,6 +275,7 @@ struct ConvertControlFlowToLLVM
274
275
LowerToLLVMOptions options (&getContext ());
275
276
if (indexBitwidth != kDeriveIndexBitwidthFromDataLayout )
276
277
options.overrideIndexBitwidth (indexBitwidth);
278
+ options.useOpaquePointers = useOpaquePointers;
277
279
278
280
LLVMTypeConverter converter (&getContext (), options);
279
281
mlir::cf::populateControlFlowToLLVMConversionPatterns (converter, patterns);
0 commit comments