Skip to content

[mlir][llvm] Import call site calling conventions #76391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mlir/lib/Target/LLVMIR/ModuleImport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
} else {
callOp = builder.create<CallOp>(loc, funcTy, operands);
}
callOp.setCConv(convertCConvFromLLVM(callInst->getCallingConv()));
setFastmathFlagsAttr(inst, callOp);
if (!callInst->getType()->isVoidTy())
mapValue(inst, callOp.getResult());
Expand Down Expand Up @@ -1516,6 +1517,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
loc, funcTy, /*callee=*/nullptr, operands, directNormalDest,
ValueRange(), lookupBlock(invokeInst->getUnwindDest()), unwindArgs);
}
invokeOp.setCConv(convertCConvFromLLVM(invokeInst->getCallingConv()));
if (!invokeInst->getType()->isVoidTy())
mapValue(inst, invokeOp.getResults().front());
else
Expand Down
6 changes: 4 additions & 2 deletions mlir/test/Dialect/LLVMIR/func.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,16 @@ module {

// CHECK: llvm.func @test_ccs
llvm.func @test_ccs() {
// CHECK-NEXT: %[[PTR:.*]] = llvm.mlir.addressof @cconv4 : !llvm.ptr
%ptr = llvm.mlir.addressof @cconv4 : !llvm.ptr
// CHECK-NEXT: llvm.call @cconv1() : () -> ()
// CHECK-NEXT: llvm.call @cconv2() : () -> ()
// CHECK-NEXT: llvm.call fastcc @cconv3() : () -> ()
// CHECK-NEXT: llvm.call cc_10 @cconv4() : () -> ()
// CHECK-NEXT: llvm.call cc_10 %[[PTR]]() : !llvm.ptr, () -> ()
llvm.call @cconv1() : () -> ()
llvm.call ccc @cconv2() : () -> ()
llvm.call fastcc @cconv3() : () -> ()
llvm.call cc_10 @cconv4() : () -> ()
llvm.call cc_10 %ptr() : !llvm.ptr, () -> ()
llvm.return
}

Expand Down
32 changes: 32 additions & 0 deletions mlir/test/Target/LLVMIR/Import/calling-convention.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

; CHECK: llvm.func fastcc @cconv_fastcc()
declare fastcc void @cconv_fastcc()
; CHECK: llvm.func @cconv_ccc()
declare ccc void @cconv_ccc()

; CHECK-LABEL: @call_cconv
define void @call_cconv() {
; CHECK: llvm.call fastcc @cconv_fastcc()
call fastcc void @cconv_fastcc()
; CHECK: llvm.call @cconv_ccc()
call ccc void @cconv_ccc()
ret void
}

; // -----

; CHECK: llvm.func fastcc @cconv_fastcc()
declare fastcc void @cconv_fastcc()
declare i32 @__gxx_personality_v0(...)

; CHECK-LABEL: @invoke_cconv
define i32 @invoke_cconv() personality ptr @__gxx_personality_v0 {
; CHECK: llvm.invoke fastcc @cconv_fastcc() to ^bb2 unwind ^bb1 : () -> ()
invoke fastcc void @cconv_fastcc() to label %bb2 unwind label %bb1
bb1:
%1 = landingpad { ptr, i32 } cleanup
br label %bb2
bb2:
ret i32 1
}