Skip to content

Commit 4d186a1

Browse files
committed
Lower statepoints with multi-def targets.
Statepoint lowering currently expects that the target method of a statepoint only defines a single value. This precludes using statepoints with ABIs that return values in multiple registers (e.g. the SysV AMD64 ABI). This change adds support for lowering statepoints with mutli-def targets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253339 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7673d24 commit 4d186a1

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

lib/CodeGen/SelectionDAG/StatepointLowering.cpp

+11-7
Original file line numberDiff line numberDiff line change
@@ -333,13 +333,17 @@ lowerCallFromStatepoint(ImmutableStatepoint ISP, const BasicBlock *EHPadBB,
333333
// ch, glue = callseq_end ch, glue
334334
// get_return_value ch, glue
335335
//
336-
// get_return_value can either be a CopyFromReg to grab the return value from
337-
// %RAX, or it can be a LOAD to load a value returned by reference via a stack
338-
// slot.
339-
340-
if (HasDef && (CallEnd->getOpcode() == ISD::CopyFromReg ||
341-
CallEnd->getOpcode() == ISD::LOAD))
342-
CallEnd = CallEnd->getOperand(0).getNode();
336+
// get_return_value can either be a sequence of CopyFromReg instructions
337+
// to grab the return value from the return register(s), or it can be a LOAD
338+
// to load a value returned by reference via a stack slot.
339+
340+
if (HasDef) {
341+
if (CallEnd->getOpcode() == ISD::LOAD)
342+
CallEnd = CallEnd->getOperand(0).getNode();
343+
else
344+
while (CallEnd->getOpcode() == ISD::CopyFromReg)
345+
CallEnd = CallEnd->getOperand(0).getNode();
346+
}
343347

344348
assert(CallEnd->getOpcode() == ISD::CALLSEQ_END && "expected!");
345349

test/CodeGen/X86/statepoint-call-lowering.ll

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
66
target triple = "x86_64-pc-linux-gnu"
77

8+
%struct = type { i64, i64 }
9+
810
declare zeroext i1 @return_i1()
911
declare zeroext i32 @return_i32()
1012
declare i32* @return_i32ptr()
1113
declare float @return_float()
14+
declare %struct @return_struct()
1215
declare void @varargf(i32, ...)
1316

1417
define i1 @test_i1_return() gc "statepoint-example" {
@@ -61,12 +64,24 @@ entry:
6164
ret float %call1
6265
}
6366

67+
define %struct @test_struct_return() gc "statepoint-example" {
68+
; CHECK-LABEL: test_struct_return
69+
; CHECK: pushq %rax
70+
; CHECK: callq return_struct
71+
; CHECK: popq %rcx
72+
; CHECK: retq
73+
entry:
74+
%safepoint_token = tail call i32 (i64, i32, %struct ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_structf(i64 0, i32 0, %struct ()* @return_struct, i32 0, i32 0, i32 0, i32 0)
75+
%call1 = call %struct @llvm.experimental.gc.result.struct(i32 %safepoint_token)
76+
ret %struct %call1
77+
}
78+
6479
define i1 @test_relocate(i32 addrspace(1)* %a) gc "statepoint-example" {
6580
; CHECK-LABEL: test_relocate
6681
; Check that an ununsed relocate has no code-generation impact
6782
; CHECK: pushq %rax
6883
; CHECK: callq return_i1
69-
; CHECK-NEXT: .Ltmp9:
84+
; CHECK-NEXT: .Ltmp11:
7085
; CHECK-NEXT: popq %rdx
7186
; CHECK-NEXT: retq
7287
entry:
@@ -137,6 +152,9 @@ declare i32* @llvm.experimental.gc.result.p0i32(i32)
137152
declare i32 @llvm.experimental.gc.statepoint.p0f_f32f(i64, i32, float ()*, i32, i32, ...)
138153
declare float @llvm.experimental.gc.result.f32(i32)
139154

155+
declare i32 @llvm.experimental.gc.statepoint.p0f_structf(i64, i32, %struct ()*, i32, i32, ...)
156+
declare %struct @llvm.experimental.gc.result.struct(i32)
157+
140158
declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidi32varargf(i64, i32, void (i32, ...)*, i32, i32, ...)
141159

142160
declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)

0 commit comments

Comments
 (0)