llvm.org GIT mirror llvm / 66e29d1
[RS4GC] Re-purpose `normalizeForInvokeSafepoint`; NFC. `normalizeForInvokeSafepoint` in RewriteStatepointsForGC.cpp, as it is written today, deals with `gc.relocate` and `gc.result` uses of a statepoint equally well. This change documents this fact and adds a test case. There is no functional change here -- only documentation of existing functionality. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@250784 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
2 changed file(s) with 41 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
12381238 }
12391239 }
12401240
1241 // When inserting gc.relocate calls, we need to ensure there are no uses
1242 // of the original value between the gc.statepoint and the gc.relocate call.
1243 // One case which can arise is a phi node starting one of the successor blocks.
1244 // We also need to be able to insert the gc.relocates only on the path which
1245 // goes through the statepoint. We might need to split an edge to make this
1246 // possible.
1241 // When inserting gc.relocate and gc.result calls, we need to ensure there are
1242 // no uses of the original value / return value between the gc.statepoint and
1243 // the gc.relocate / gc.result call. One case which can arise is a phi node
1244 // starting one of the successor blocks. We also need to be able to insert the
1245 // gc.relocates only on the path which goes through the statepoint. We might
1246 // need to split an edge to make this possible.
12471247 static BasicBlock *
12481248 normalizeForInvokeSafepoint(BasicBlock *BB, BasicBlock *InvokeParent,
12491249 DominatorTree &DT) {
12511251 if (!BB->getUniquePredecessor())
12521252 Ret = SplitBlockPredecessors(BB, InvokeParent, "", &DT);
12531253
1254 // Now that 'ret' has unique predecessor we can safely remove all phi nodes
1254 // Now that 'Ret' has unique predecessor we can safely remove all phi nodes
12551255 // from it
12561256 FoldSingleEntryPHINodes(Ret);
12571257 assert(!isa(Ret->begin()) &&
12581258 "All PHI nodes should have been removed!");
12591259
1260 // At this point, we can safely insert a gc.relocate as the first instruction
1261 // in Ret if needed.
1260 // At this point, we can safely insert a gc.relocate or gc.result as the first
1261 // instruction in Ret if needed.
12621262 return Ret;
12631263 }
12641264
0 ; RUN: opt -rewrite-statepoints-for-gc -rs4gc-use-deopt-bundles -verify -S < %s | FileCheck %s
1
2 declare i8 addrspace(1)* @gc_call()
3
4 declare i32* @fake_personality_function()
5
6 define i8 addrspace(1)* @test(i1 %c) gc "statepoint-example" personality i32* ()* @fake_personality_function {
7 ; CHECK-LABEL: @test(
8 entry:
9 br i1 %c, label %gc_invoke, label %normal_dest
10
11 gc_invoke:
12 ; CHECK: [[TOKEN:%[^ ]+]] = invoke i32 {{[^@]+}}@llvm.experimental.gc.statepoint{{[^@]+}}@gc_call
13 %obj = invoke i8 addrspace(1)* @gc_call() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
14 to label %normal_dest unwind label %unwind_dest
15
16 unwind_dest:
17 ; CHECK: unwind_dest:
18 %lpad = landingpad { i8*, i32 }
19 cleanup
20 resume { i8*, i32 } undef
21
22 ; CHECK: [[NORMAL_DEST_SPLIT:[^:]+:]]
23 ; CHECK-NEXT: [[RET_VAL:%[^ ]+]] = call i8 addrspace(1)* @llvm.experimental.gc.result.p1i8(i32 [[TOKEN]])
24 ; CHECK-NEXT: br label %normal_dest
25
26 normal_dest:
27 ; CHECK: normal_dest:
28 ; CHECK-NEXT: %merge = phi i8 addrspace(1)* [ null, %entry ], [ %obj.2, %normal_dest1 ]
29 %merge = phi i8 addrspace(1)* [ null, %entry ], [ %obj, %gc_invoke ]
30 ret i8 addrspace(1)* %merge
31 }