Skip to content

Commit 5340347

Browse files
authored
[mlir][llvm] Import call site calling conventions (#76391)
This revision adds support for importing call site calling conventions. Additionally, the revision also adds a roundtrip test for an indirect call with a non-standard calling convention.
1 parent c01e844 commit 5340347

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

mlir/lib/Target/LLVMIR/ModuleImport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,6 +1439,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
14391439
} else {
14401440
callOp = builder.create<CallOp>(loc, funcTy, operands);
14411441
}
1442+
callOp.setCConv(convertCConvFromLLVM(callInst->getCallingConv()));
14421443
setFastmathFlagsAttr(inst, callOp);
14431444
if (!callInst->getType()->isVoidTy())
14441445
mapValue(inst, callOp.getResult());
@@ -1516,6 +1517,7 @@ LogicalResult ModuleImport::convertInstruction(llvm::Instruction *inst) {
15161517
loc, funcTy, /*callee=*/nullptr, operands, directNormalDest,
15171518
ValueRange(), lookupBlock(invokeInst->getUnwindDest()), unwindArgs);
15181519
}
1520+
invokeOp.setCConv(convertCConvFromLLVM(invokeInst->getCallingConv()));
15191521
if (!invokeInst->getType()->isVoidTy())
15201522
mapValue(inst, invokeOp.getResults().front());
15211523
else

mlir/test/Dialect/LLVMIR/func.mlir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ module {
191191

192192
// CHECK: llvm.func @test_ccs
193193
llvm.func @test_ccs() {
194+
// CHECK-NEXT: %[[PTR:.*]] = llvm.mlir.addressof @cconv4 : !llvm.ptr
195+
%ptr = llvm.mlir.addressof @cconv4 : !llvm.ptr
194196
// CHECK-NEXT: llvm.call @cconv1() : () -> ()
195197
// CHECK-NEXT: llvm.call @cconv2() : () -> ()
196198
// CHECK-NEXT: llvm.call fastcc @cconv3() : () -> ()
197-
// CHECK-NEXT: llvm.call cc_10 @cconv4() : () -> ()
199+
// CHECK-NEXT: llvm.call cc_10 %[[PTR]]() : !llvm.ptr, () -> ()
198200
llvm.call @cconv1() : () -> ()
199201
llvm.call ccc @cconv2() : () -> ()
200202
llvm.call fastcc @cconv3() : () -> ()
201-
llvm.call cc_10 @cconv4() : () -> ()
203+
llvm.call cc_10 %ptr() : !llvm.ptr, () -> ()
202204
llvm.return
203205
}
204206

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
2+
3+
; CHECK: llvm.func fastcc @cconv_fastcc()
4+
declare fastcc void @cconv_fastcc()
5+
; CHECK: llvm.func @cconv_ccc()
6+
declare ccc void @cconv_ccc()
7+
8+
; CHECK-LABEL: @call_cconv
9+
define void @call_cconv() {
10+
; CHECK: llvm.call fastcc @cconv_fastcc()
11+
call fastcc void @cconv_fastcc()
12+
; CHECK: llvm.call @cconv_ccc()
13+
call ccc void @cconv_ccc()
14+
ret void
15+
}
16+
17+
; // -----
18+
19+
; CHECK: llvm.func fastcc @cconv_fastcc()
20+
declare fastcc void @cconv_fastcc()
21+
declare i32 @__gxx_personality_v0(...)
22+
23+
; CHECK-LABEL: @invoke_cconv
24+
define i32 @invoke_cconv() personality ptr @__gxx_personality_v0 {
25+
; CHECK: llvm.invoke fastcc @cconv_fastcc() to ^bb2 unwind ^bb1 : () -> ()
26+
invoke fastcc void @cconv_fastcc() to label %bb2 unwind label %bb1
27+
bb1:
28+
%1 = landingpad { ptr, i32 } cleanup
29+
br label %bb2
30+
bb2:
31+
ret i32 1
32+
}

0 commit comments

Comments
 (0)