llvm.org GIT mirror llvm / 7a62a2a
[PlaceSafepoints] Adjust enablement logic to default to off and be GC configurable per GC Previously, this pass ran over every function in the Module if added to the pass order. With this change, it runs only over those with a GC attribute where the GC explicitly opts in. A GC can also choose which of entry safepoint polls, backedge safepoint polls, and call safepoints it wants. I hope to get these exposed as checks on the GCStrategy at some point, but for now, the checks are manual string comparisons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@230097 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 4 years ago
6 changed file(s) with 43 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
149149 struct PlaceSafepoints : public ModulePass {
150150 static char ID; // Pass identification, replacement for typeid
151151
152 bool EnableEntrySafepoints;
153 bool EnableBackedgeSafepoints;
154 bool EnableCallSafepoints;
155
156152 PlaceSafepoints() : ModulePass(ID) {
157153 initializePlaceSafepointsPass(*PassRegistry::getPassRegistry());
158 EnableEntrySafepoints = !NoEntry;
159 EnableBackedgeSafepoints = !NoBackedge;
160 EnableCallSafepoints = !NoCall;
161154 }
162155 bool runOnModule(Module &M) override {
163156 bool modified = false;
503496 return F.getName().equals(GCSafepointPollName);
504497 }
505498
499 /// Returns true if this function should be rewritten to include safepoint
500 /// polls and parseable call sites. The main point of this function is to be
501 /// an extension point for custom logic.
502 static bool shouldRewriteFunction(Function &F) {
503 // TODO: This should check the GCStrategy
504 if (F.hasGC()) {
505 const std::string StatepointExampleName("statepoint-example");
506 return StatepointExampleName == F.getGC();
507 } else
508 return false;
509 }
510
511 // TODO: These should become properties of the GCStrategy, possibly with
512 // command line overrides.
513 static bool enableEntrySafepoints(Function &F) { return !NoEntry; }
514 static bool enableBackedgeSafepoints(Function &F) { return !NoBackedge; }
515 static bool enableCallSafepoints(Function &F) { return !NoCall; }
516
517
506518 bool PlaceSafepoints::runOnFunction(Function &F) {
507519 if (F.isDeclaration() || F.empty()) {
508520 // This is a declaration, nothing to do. Must exit early to avoid crash in
517529 return false;
518530 }
519531
532 if (!shouldRewriteFunction(F))
533 return false;
534
520535 bool modified = false;
521536
522537 // In various bits below, we rely on the fact that uses are reachable from
535550
536551 std::vector ParsePointNeeded;
537552
538 if (EnableBackedgeSafepoints) {
553 if (enableBackedgeSafepoints(F)) {
539554 // Construct a pass manager to run the LoopPass backedge logic. We
540555 // need the pass manager to handle scheduling all the loop passes
541556 // appropriately. Doing this by hand is painful and just not worth messing
542557 // with for the moment.
543558 legacy::FunctionPassManager FPM(F.getParent());
544 bool CanAssumeCallSafepoints = EnableCallSafepoints;
559 bool CanAssumeCallSafepoints = enableCallSafepoints(F);
545560 PlaceBackedgeSafepointsImpl *PBS =
546561 new PlaceBackedgeSafepointsImpl(CanAssumeCallSafepoints);
547562 FPM.add(PBS);
608623 }
609624 }
610625
611 if (EnableEntrySafepoints) {
626 if (enableEntrySafepoints(F)) {
612627 DT.recalculate(F);
613628 Instruction *term = findLocationForEntrySafepoint(F, DT);
614629 if (!term) {
623638 }
624639 }
625640
626 if (EnableCallSafepoints) {
641 if (enableCallSafepoints(F)) {
627642 DT.recalculate(F);
628643 std::vector Calls;
629644 findCallSafepoints(F, Calls);
66 entry:
77 ; CHECK-LABEL: entry
88 ; CHECK: statepoint
9 ret void
10 }
11
12 ; On a non-gc function, we should NOT get an entry safepoint
13 define void @test_negative() {
14 ; CHECK-LABEL: @test_negative
15 entry:
16 ; CHECK-NOT: statepoint
917 ret void
1018 }
1119
44
55 declare void @foo()
66
7 define void @test1() {
7 define void @test1() gc "statepoint-example" {
88 ; CHECK-LABEL: test1
99
1010 entry:
33
44
55 ; A simple counted loop with trivially known range
6 define void @test1(i32) {
6 define void @test1(i32) gc "statepoint-example" {
77 ; CHECK-LABEL: test1
88 ; CHECK-LABEL: entry
99 ; CHECK: statepoint
2424 }
2525
2626 ; The same counted loop, but with an unknown early exit
27 define void @test2(i32) {
27 define void @test2(i32) gc "statepoint-example" {
2828 ; CHECK-LABEL: test2
2929 ; CHECK-LABEL: entry
3030 ; CHECK: statepoint
4848 }
4949
5050 ; The range is a 8 bit value and we can't overflow
51 define void @test3(i8 %upper) {
51 define void @test3(i8 %upper) gc "statepoint-example" {
5252 ; CHECK-LABEL: test3
5353 ; CHECK-LABEL: entry
5454 ; CHECK: statepoint
22 declare i64 addrspace(1)* @"some_call"(i64 addrspace(1)*)
33 declare i32 @"personality_function"()
44
5 define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) {
5 define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
66 ; CHECK-LABEL: entry:
77 entry:
88 ; CHECK: invoke
2828 ret i64 addrspace(1)* %obj1
2929 }
3030
31 define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) {
31 define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
3232 ; CHECK-LABEL: entry:
3333 entry:
3434 ; CHECK: invoke
6060 ret i64 addrspace(1)* %obj1
6161 }
6262
63 define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) {
63 define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) gc "statepoint-example" {
6464 ; CHECK-LABEL: entry:
6565 entry:
6666 br i1 %cond, label %left, label %right
0 ;; A very basic test to make sure that splitting the backedge keeps working
11 ;; RUN: opt -place-safepoints -spp-split-backedge=1 -S %s | FileCheck %s
22
3 define void @test(i32, i1 %cond) {
3 define void @test(i32, i1 %cond) gc "statepoint-example" {
44 ; CHECK-LABEL: @test
55 ; CHECK-LABEL: loop.loop_crit_edge
66 ; CHECK: gc.statepoint
1919 ; different loop header blocks. Since we're currently using LoopSimplfy
2020 ; this doesn't hit the interesting case, but once we remove that, we need
2121 ; to be sure this keeps working.
22 define void @test2(i32, i1 %cond) {
22 define void @test2(i32, i1 %cond) gc "statepoint-example" {
2323 ; CHECK-LABEL: @test2
2424 ; CHECK-LABE: loop.loopexit.split
2525 ; CHECK: gc.statepoint