diff options
author | Christian Ulmann <christian.ulmann@nextsilicon.com> | 2023-10-17 11:33:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-17 11:33:45 +0200 |
commit | 484668c7597d9198e21332b30d2f15ece536a0bb (patch) | |
tree | 134f4cc385c9dd88cf121eef6f4c39c11f4e8135 /mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp | |
parent | 815193f6be08e0f5876c9a0cb88c9df104710e68 (diff) | |
download | llvm-484668c7597d9198e21332b30d2f15ece536a0bb.zip llvm-484668c7597d9198e21332b30d2f15ece536a0bb.tar.gz llvm-484668c7597d9198e21332b30d2f15ece536a0bb.tar.bz2 |
Reland "[MLIR][LLVM] Change addressof builders to use opaque pointers" (#69292)
This relands fbde19a664e5fd7196080fb4ff0aeaa31dce8508, which was broken due to incorrect GEP element type creation.
This commit changes the builders of the `llvm.mlir.addressof` operations
to no longer produce typed pointers.
As a consequence, a GPU to NVVM pattern had to be updated, that still
relied on typed pointers.
Diffstat (limited to 'mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp')
-rw-r--r-- | mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp index 96d8fce..6d2585a 100644 --- a/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp +++ b/mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp @@ -441,7 +441,7 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite( Location loc = gpuPrintfOp->getLoc(); mlir::Type llvmI8 = typeConverter->convertType(rewriter.getIntegerType(8)); - mlir::Type i8Ptr = LLVM::LLVMPointerType::get(llvmI8); + mlir::Type ptrType = LLVM::LLVMPointerType::get(rewriter.getContext()); // Note: this is the GPUModule op, not the ModuleOp that surrounds it // This ensures that global constants and declarations are placed within @@ -449,7 +449,7 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite( auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>(); auto vprintfType = - LLVM::LLVMFunctionType::get(rewriter.getI32Type(), {i8Ptr, i8Ptr}); + LLVM::LLVMFunctionType::get(rewriter.getI32Type(), {ptrType, ptrType}); LLVM::LLVMFuncOp vprintfDecl = getOrDefineFunction(moduleOp, loc, rewriter, "vprintf", vprintfType); @@ -473,7 +473,8 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite( // Get a pointer to the format string's first element Value globalPtr = rewriter.create<LLVM::AddressOfOp>(loc, global); Value stringStart = rewriter.create<LLVM::GEPOp>( - loc, i8Ptr, globalPtr, ArrayRef<LLVM::GEPArg>{0, 0}); + loc, getTypeConverter()->getPointerType(globalType), globalType, + globalPtr, ArrayRef<LLVM::GEPArg>{0, 0}); SmallVector<Type> types; SmallVector<Value> args; // Promote and pack the arguments into a stack allocation. @@ -490,18 +491,17 @@ LogicalResult GPUPrintfOpToVPrintfLowering::matchAndRewrite( } Type structType = LLVM::LLVMStructType::getLiteral(gpuPrintfOp.getContext(), types); - Type structPtrType = LLVM::LLVMPointerType::get(structType); Value one = rewriter.create<LLVM::ConstantOp>(loc, rewriter.getI64Type(), rewriter.getIndexAttr(1)); - Value tempAlloc = rewriter.create<LLVM::AllocaOp>(loc, structPtrType, one, - /*alignment=*/0); + Value tempAlloc = + rewriter.create<LLVM::AllocaOp>(loc, ptrType, structType, one, + /*alignment=*/0); for (auto [index, arg] : llvm::enumerate(args)) { Value ptr = rewriter.create<LLVM::GEPOp>( - loc, LLVM::LLVMPointerType::get(arg.getType()), tempAlloc, - ArrayRef<LLVM::GEPArg>{0, index}); + loc, getTypeConverter()->getPointerType(structType), structType, + tempAlloc, ArrayRef<LLVM::GEPArg>{0, index}); rewriter.create<LLVM::StoreOp>(loc, arg, ptr); } - tempAlloc = rewriter.create<LLVM::BitcastOp>(loc, i8Ptr, tempAlloc); std::array<Value, 2> printfArgs = {stringStart, tempAlloc}; rewriter.create<LLVM::CallOp>(loc, vprintfDecl, printfArgs); |