summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/RewriteStatepointsForGC
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/Transforms/RewriteStatepointsForGC')
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/call-gc-result.ll38
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/invokes.ll111
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/leaf-function.ll33
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-calling-conventions.ll42
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-coreclr.ll31
-rw-r--r--llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-format.ll42
6 files changed, 297 insertions, 0 deletions
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/call-gc-result.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/call-gc-result.ll
new file mode 100644
index 00000000000..d3c37cef9c5
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/call-gc-result.ll
@@ -0,0 +1,38 @@
+;; RUN: opt < %s -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S | FileCheck %s
+
+;; This test is to verify that gc_result from a call statepoint
+;; can have preceding phis in its parent basic block. Unlike
+;; invoke statepoint, call statepoint does not terminate the
+;; block, and thus its gc_result is in the same block with the
+;; call statepoint.
+
+declare i32 @foo()
+
+define i32 @test1(i1 %cond, i32 %a) gc "statepoint-example" {
+entry:
+ br i1 %cond, label %branch1, label %branch2
+
+branch1:
+ %b = add i32 %a, 1
+ br label %merge
+
+branch2:
+ br label %merge
+
+merge:
+;; CHECK: %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
+;; CHECK-NEXT: [[TOKEN:%[^ ]+]] = call token (i64, i32, i32 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i32f(i64 2882400000, i32 0, i32 ()* @foo, i32 0, i32 0, i32 0, i32 0
+;; CHECK-NEXT: call i32 @llvm.experimental.gc.result.i32(token [[TOKEN]])
+ %phi = phi i32 [ %a, %branch2 ], [ %b, %branch1 ]
+ %ret = call i32 @foo()
+ ret i32 %ret
+}
+
+; This function is inlined when inserting a poll.
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+entry:
+ call void @do_safepoint()
+ ret void
+}
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/invokes.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/invokes.ll
new file mode 100644
index 00000000000..ac0c1740fd0
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/invokes.ll
@@ -0,0 +1,111 @@
+; RUN: opt < %s -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles | FileCheck %s
+
+declare i64 addrspace(1)* @some_call(i64 addrspace(1)*)
+declare i32 @personality_function()
+
+define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality_function {
+; CHECK-LABEL: entry:
+entry:
+ ; CHECK: invoke
+ ; CHECK: statepoint
+ ; CHECK: some_call
+ %ret_val = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
+ to label %normal_return unwind label %exceptional_return
+
+; CHECK-LABEL: normal_return:
+; CHECK: gc.result
+; CHECK: ret i64
+
+normal_return:
+ ret i64 addrspace(1)* %ret_val
+
+; CHECK-LABEL: exceptional_return:
+; CHECK: landingpad
+; CHECK: ret i64
+
+exceptional_return:
+ %landing_pad4 = landingpad token
+ cleanup
+ ret i64 addrspace(1)* %obj1
+}
+
+define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality_function {
+; CHECK-LABEL: entry:
+entry:
+ ; CHECK: invoke
+ ; CHECK: statepoint
+ ; CHECK: some_call
+ %ret_val1 = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
+ to label %second_invoke unwind label %exceptional_return
+
+; CHECK-LABEL: second_invoke:
+second_invoke:
+ ; CHECK: invoke
+ ; CHECK: statepoint
+ ; CHECK: some_call
+ %ret_val2 = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %ret_val1)
+ to label %normal_return unwind label %exceptional_return
+
+; CHECK-LABEL: normal_return:
+normal_return:
+ ; CHECK: gc.result
+ ; CHECK: ret i64
+ ret i64 addrspace(1)* %ret_val2
+
+; CHECK: exceptional_return:
+; CHECK: ret i64
+
+exceptional_return:
+ %landing_pad4 = landingpad token
+ cleanup
+ ret i64 addrspace(1)* %obj1
+}
+
+define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) gc "statepoint-example" personality i32 ()* @personality_function {
+; CHECK-LABEL: @test_phi_node
+; CHECK-LABEL: entry:
+entry:
+ br i1 %cond, label %left, label %right
+
+left:
+ %ret_val_left = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
+ to label %merge unwind label %exceptional_return
+
+right:
+ %ret_val_right = invoke i64 addrspace(1)* @some_call(i64 addrspace(1)* %obj)
+ to label %merge unwind label %exceptional_return
+
+; CHECK: merge[[A:[0-9]]]:
+; CHECK: gc.result
+; CHECK: br label %[[with_phi:merge[0-9]*]]
+
+; CHECK: merge[[B:[0-9]]]:
+; CHECK: gc.result
+; CHECK: br label %[[with_phi]]
+
+; CHECK: [[with_phi]]:
+; CHECK: phi
+; CHECK: ret i64 addrspace(1)* %ret_val
+merge:
+ %ret_val = phi i64 addrspace(1)* [%ret_val_left, %left], [%ret_val_right, %right]
+ ret i64 addrspace(1)* %ret_val
+
+; CHECK-LABEL: exceptional_return:
+; CHECK: ret i64 addrspace(1)*
+
+exceptional_return:
+ %landing_pad4 = landingpad token
+ cleanup
+ ret i64 addrspace(1)* %obj
+}
+
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+; CHECK-LABEL: entry
+; CHECK-NEXT: do_safepoint
+; CHECK-NEXT: ret void
+entry:
+ call void @do_safepoint()
+ ret void
+}
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/leaf-function.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/leaf-function.ll
new file mode 100644
index 00000000000..79757a3dc90
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/leaf-function.ll
@@ -0,0 +1,33 @@
+; RUN: opt < %s -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles | FileCheck %s
+
+declare void @foo() "gc-leaf-function"
+declare void @bar()
+
+; Calls of functions with the "gc-leaf-function" attribute shouldn't be turned
+; into a safepoint. An entry safepoint should get inserted, though.
+define void @test_leaf_function() gc "statepoint-example" {
+; CHECK-LABEL: test_leaf_function
+; CHECK-NOT: gc.statepoint
+; CHECK-NOT: gc.result
+entry:
+ call void @foo()
+ ret void
+}
+
+define void @test_leaf_function_call() gc "statepoint-example" {
+; CHECK-LABEL: test_leaf_function_call
+; CHECK-NOT: gc.statepoint
+; CHECK-NOT: gc.result
+entry:
+ call void @bar() "gc-leaf-function"
+ ret void
+}
+
+; This function is inlined when inserting a poll.
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+entry:
+ call void @do_safepoint()
+ ret void
+}
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-calling-conventions.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-calling-conventions.ll
new file mode 100644
index 00000000000..c1cd4be035d
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-calling-conventions.ll
@@ -0,0 +1,42 @@
+; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S < %s | FileCheck %s
+
+; Ensure that the gc.statepoint calls / invokes we generate carry over
+; the right calling conventions.
+
+define i64 addrspace(1)* @test_invoke_format(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality {
+; CHECK-LABEL: @test_invoke_format(
+; CHECK-LABEL: entry:
+; CHECK: invoke coldcc token (i64, i32, i64 addrspace(1)* (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* (i64 addrspace(1)*)* @callee, i32 1, i32 0, i64 addrspace(1)* %obj, i32 0, i32 0
+entry:
+ %ret_val = invoke coldcc i64 addrspace(1)* @callee(i64 addrspace(1)* %obj)
+ to label %normal_return unwind label %exceptional_return
+
+normal_return:
+ ret i64 addrspace(1)* %ret_val
+
+exceptional_return:
+ %landing_pad4 = landingpad token
+ cleanup
+ ret i64 addrspace(1)* %obj1
+}
+
+define i64 addrspace(1)* @test_call_format(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
+; CHECK-LABEL: @test_call_format(
+; CHECK-LABEL: entry:
+; CHECK: call coldcc token (i64, i32, i64 addrspace(1)* (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* (i64 addrspace(1)*)* @callee, i32 1, i32 0, i64 addrspace(1)* %obj, i32 0, i32 0
+entry:
+ %ret_val = call coldcc i64 addrspace(1)* @callee(i64 addrspace(1)* %obj)
+ ret i64 addrspace(1)* %ret_val
+}
+
+; This function is inlined when inserting a poll.
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+entry:
+ call void @do_safepoint()
+ ret void
+}
+
+declare coldcc i64 addrspace(1)* @callee(i64 addrspace(1)*)
+declare i32 @personality()
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-coreclr.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-coreclr.ll
new file mode 100644
index 00000000000..d8648a5afd6
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-coreclr.ll
@@ -0,0 +1,31 @@
+; RUN: opt < %s -S -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles | FileCheck %s
+
+; Basic test to make sure that safepoints are placed
+; for CoreCLR GC
+
+declare void @foo()
+
+define void @test_simple_call() gc "coreclr" {
+; CHECK-LABEL: test_simple_call
+entry:
+ br label %other
+other:
+; CHECK-LABEL: other
+; CHECK: statepoint
+; CHECK-NOT: gc.result
+ call void @foo()
+ ret void
+}
+
+; This function is inlined when inserting a poll. To avoid recursive
+; issues, make sure we don't place safepoints in it.
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+; CHECK-LABEL: entry
+; CHECK-NEXT: do_safepoint
+; CHECK-NEXT: ret void
+entry:
+ call void @do_safepoint()
+ ret void
+}
diff --git a/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-format.ll b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-format.ll
new file mode 100644
index 00000000000..ebf89aac9d2
--- /dev/null
+++ b/llvm/test/Transforms/RewriteStatepointsForGC/deopt-bundles/statepoint-format.ll
@@ -0,0 +1,42 @@
+; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -S < %s | FileCheck %s
+
+; Ensure that the gc.statepoint calls / invokes we generate have the
+; set of arguments we expect it to have.
+
+define i64 addrspace(1)* @test_invoke_format(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" personality i32 ()* @personality {
+; CHECK-LABEL: @test_invoke_format(
+; CHECK-LABEL: entry:
+; CHECK: invoke token (i64, i32, i64 addrspace(1)* (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* (i64 addrspace(1)*)* @callee, i32 1, i32 0, i64 addrspace(1)* %obj, i32 0, i32 0, i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1)
+entry:
+ %ret_val = invoke i64 addrspace(1)* @callee(i64 addrspace(1)* %obj)
+ to label %normal_return unwind label %exceptional_return
+
+normal_return:
+ ret i64 addrspace(1)* %ret_val
+
+exceptional_return:
+ %landing_pad4 = landingpad token
+ cleanup
+ ret i64 addrspace(1)* %obj1
+}
+
+define i64 addrspace(1)* @test_call_format(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
+; CHECK-LABEL: @test_call_format(
+; CHECK-LABEL: entry:
+; CHECK: call token (i64, i32, i64 addrspace(1)* (i64 addrspace(1)*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_p1i64p1i64f(i64 2882400000, i32 0, i64 addrspace(1)* (i64 addrspace(1)*)* @callee, i32 1, i32 0, i64 addrspace(1)* %obj, i32 0, i32 0, i64 addrspace(1)* %obj)
+entry:
+ %ret_val = call i64 addrspace(1)* @callee(i64 addrspace(1)* %obj)
+ ret i64 addrspace(1)* %ret_val
+}
+
+; This function is inlined when inserting a poll.
+declare void @do_safepoint()
+define void @gc.safepoint_poll() {
+; CHECK-LABEL: gc.safepoint_poll
+entry:
+ call void @do_safepoint()
+ ret void
+}
+
+declare i64 addrspace(1)* @callee(i64 addrspace(1)*)
+declare i32 @personality()
OpenPOWER on IntegriCloud