diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index 7a73c170b94f..d26faa2a4fb2 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -1995,6 +1995,16 @@ createCallLLVMIntrinsicOp(mlir::ConversionPatternRewriter &rewriter, loc, resultTy, intrinsicNameAttr, operands); } +static mlir::LLVM::CallIntrinsicOp replaceOpWithCallLLVMIntrinsicOp( + mlir::ConversionPatternRewriter &rewriter, mlir::Operation *op, + const llvm::Twine &intrinsicName, mlir::Type resultTy, + mlir::ValueRange operands) { + auto callIntrinOp = createCallLLVMIntrinsicOp( + rewriter, op->getLoc(), intrinsicName, resultTy, operands); + rewriter.replaceOp(op, callIntrinOp.getOperation()); + return callIntrinOp; +} + static mlir::Value createLLVMBitOp(mlir::Location loc, const llvm::Twine &llvmIntrinBaseName, mlir::Type resultTy, mlir::Value operand, @@ -2079,16 +2089,14 @@ class CIRObjSizeOpLowering auto llvmResTy = getTypeConverter()->convertType(op.getType()); auto loc = op->getLoc(); - auto llvmIntrinNameAttr = - mlir::StringAttr::get(rewriter.getContext(), "llvm.objectsize"); mlir::cir::SizeInfoType kindInfo = op.getKind(); auto falseValue = rewriter.create( loc, rewriter.getI1Type(), false); auto trueValue = rewriter.create( loc, rewriter.getI1Type(), true); - rewriter.replaceOpWithNewOp( - op, llvmResTy, llvmIntrinNameAttr, + replaceOpWithCallLLVMIntrinsicOp( + rewriter, op, "llvm.objectsize", llvmResTy, mlir::ValueRange{adaptor.getPtr(), kindInfo == mlir::cir::SizeInfoType::max ? falseValue : trueValue, @@ -2467,11 +2475,8 @@ class CIRByteswapOpLowering std::string llvmIntrinName = "llvm.bswap.i"; llvmIntrinName.append(std::to_string(resTy.getWidth())); - auto llvmIntrinNameAttr = - mlir::StringAttr::get(rewriter.getContext(), llvmIntrinName); - rewriter.replaceOpWithNewOp( - op, resTy, llvmIntrinNameAttr, adaptor.getInput()); + rewriter.replaceOpWithNewOp(op, adaptor.getInput()); return mlir::LogicalResult::success(); } @@ -2682,10 +2687,7 @@ class CIRTrapLowering : public mlir::OpConversionPattern { auto loc = op->getLoc(); rewriter.eraseOp(op); - auto llvmTrapIntrinsicType = - mlir::LLVM::LLVMVoidType::get(op->getContext()); - rewriter.create( - loc, llvmTrapIntrinsicType, "llvm.trap", mlir::ValueRange{}); + rewriter.create(loc); // Note that the call to llvm.trap is not a terminator in LLVM dialect. // So we must emit an additional llvm.unreachable to terminate the current diff --git a/clang/test/CIR/Lowering/bswap.cir b/clang/test/CIR/Lowering/bswap.cir index 7e778820a131..7733b4de1dae 100644 --- a/clang/test/CIR/Lowering/bswap.cir +++ b/clang/test/CIR/Lowering/bswap.cir @@ -9,7 +9,7 @@ cir.func @test(%arg0: !u32i) -> !u32i { } // MLIR: llvm.func @test(%arg0: i32) -> i32 -// MLIR-NEXT: %0 = llvm.call_intrinsic "llvm.bswap.i32"(%arg0) : (i32) -> i32 +// MLIR-NEXT: %0 = llvm.intr.bswap(%arg0) : (i32) -> i32 // MLIR-NEXT: llvm.return %0 : i32 // MLIR-NEXT: } diff --git a/clang/test/CIR/Lowering/intrinsics.cir b/clang/test/CIR/Lowering/intrinsics.cir index ddf8e0708ad4..25b0b34738bc 100644 --- a/clang/test/CIR/Lowering/intrinsics.cir +++ b/clang/test/CIR/Lowering/intrinsics.cir @@ -14,7 +14,7 @@ module { } // MLIR: llvm.func @test_trap() - // MLIR-NEXT: llvm.call_intrinsic "llvm.trap"() : () -> !llvm.void + // MLIR-NEXT: "llvm.intr.trap"() : () -> () // MLIR-NEXT: llvm.unreachable // LLVM: define void @test_trap()