[llvm] r230097 - [PlaceSafepoints] Adjust enablement logic to default to off and be GC configurable per GC

Philip Reames listmail at philipreames.com
Fri Feb 20 16:09:09 PST 2015


Author: reames
Date: Fri Feb 20 18:09:09 2015
New Revision: 230097

URL: http://llvm.org/viewvc/llvm-project?rev=230097&view=rev
Log:
[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.


Modified:
    llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
    llvm/trunk/test/Transforms/PlaceSafepoints/basic.ll
    llvm/trunk/test/Transforms/PlaceSafepoints/call-in-loop.ll
    llvm/trunk/test/Transforms/PlaceSafepoints/finite-loops.ll
    llvm/trunk/test/Transforms/PlaceSafepoints/invokes.ll
    llvm/trunk/test/Transforms/PlaceSafepoints/split-backedge.ll

Modified: llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/PlaceSafepoints.cpp Fri Feb 20 18:09:09 2015
@@ -150,15 +150,8 @@ namespace {
 struct PlaceSafepoints : public ModulePass {
   static char ID; // Pass identification, replacement for typeid
 
-  bool EnableEntrySafepoints;
-  bool EnableBackedgeSafepoints;
-  bool EnableCallSafepoints;
-
   PlaceSafepoints() : ModulePass(ID) {
     initializePlaceSafepointsPass(*PassRegistry::getPassRegistry());
-    EnableEntrySafepoints = !NoEntry;
-    EnableBackedgeSafepoints = !NoBackedge;
-    EnableCallSafepoints = !NoCall;
   }
   bool runOnModule(Module &M) override {
     bool modified = false;
@@ -504,6 +497,25 @@ static bool isGCSafepointPoll(Function &
   return F.getName().equals(GCSafepointPollName);
 }
 
+/// Returns true if this function should be rewritten to include safepoint
+/// polls and parseable call sites.  The main point of this function is to be
+/// an extension point for custom logic. 
+static bool shouldRewriteFunction(Function &F) {
+  // TODO: This should check the GCStrategy
+  if (F.hasGC()) {
+    const std::string StatepointExampleName("statepoint-example");
+    return StatepointExampleName == F.getGC();
+  } else
+    return false;
+}
+
+// TODO: These should become properties of the GCStrategy, possibly with
+// command line overrides.
+static bool enableEntrySafepoints(Function &F) { return !NoEntry; }
+static bool enableBackedgeSafepoints(Function &F) { return !NoBackedge; }
+static bool enableCallSafepoints(Function &F) { return !NoCall; }
+
+
 bool PlaceSafepoints::runOnFunction(Function &F) {
   if (F.isDeclaration() || F.empty()) {
     // This is a declaration, nothing to do.  Must exit early to avoid crash in
@@ -518,6 +530,9 @@ bool PlaceSafepoints::runOnFunction(Func
     return false;
   }
 
+  if (!shouldRewriteFunction(F))
+    return false;
+
   bool modified = false;
 
   // In various bits below, we rely on the fact that uses are reachable from
@@ -536,13 +551,13 @@ bool PlaceSafepoints::runOnFunction(Func
 
   std::vector<CallSite> ParsePointNeeded;
 
-  if (EnableBackedgeSafepoints) {
+  if (enableBackedgeSafepoints(F)) {
     // Construct a pass manager to run the LoopPass backedge logic.  We
     // need the pass manager to handle scheduling all the loop passes
     // appropriately.  Doing this by hand is painful and just not worth messing
     // with for the moment.
     legacy::FunctionPassManager FPM(F.getParent());
-    bool CanAssumeCallSafepoints = EnableCallSafepoints;
+    bool CanAssumeCallSafepoints = enableCallSafepoints(F);
     PlaceBackedgeSafepointsImpl *PBS =
       new PlaceBackedgeSafepointsImpl(CanAssumeCallSafepoints);
     FPM.add(PBS);
@@ -609,7 +624,7 @@ bool PlaceSafepoints::runOnFunction(Func
     }
   }
 
-  if (EnableEntrySafepoints) {
+  if (enableEntrySafepoints(F)) {
     DT.recalculate(F);
     Instruction *term = findLocationForEntrySafepoint(F, DT);
     if (!term) {
@@ -624,7 +639,7 @@ bool PlaceSafepoints::runOnFunction(Func
     }
   }
 
-  if (EnableCallSafepoints) {
+  if (enableCallSafepoints(F)) {
     DT.recalculate(F);
     std::vector<CallSite> Calls;
     findCallSafepoints(F, Calls);

Modified: llvm/trunk/test/Transforms/PlaceSafepoints/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PlaceSafepoints/basic.ll?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PlaceSafepoints/basic.ll (original)
+++ llvm/trunk/test/Transforms/PlaceSafepoints/basic.ll Fri Feb 20 18:09:09 2015
@@ -10,6 +10,14 @@ entry:
   ret void
 }
 
+; On a non-gc function, we should NOT get an entry safepoint
+define void @test_negative() {
+; CHECK-LABEL: @test_negative
+entry:
+; CHECK-NOT: statepoint
+  ret void
+}
+
 ; Do we insert a backedge safepoint in a statically
 ; infinite loop?
 define void @test_backedge() gc "statepoint-example" {

Modified: llvm/trunk/test/Transforms/PlaceSafepoints/call-in-loop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PlaceSafepoints/call-in-loop.ll?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PlaceSafepoints/call-in-loop.ll (original)
+++ llvm/trunk/test/Transforms/PlaceSafepoints/call-in-loop.ll Fri Feb 20 18:09:09 2015
@@ -5,7 +5,7 @@
 
 declare void @foo()
 
-define void @test1() {
+define void @test1() gc "statepoint-example" {
 ; CHECK-LABEL: test1
 
 entry:

Modified: llvm/trunk/test/Transforms/PlaceSafepoints/finite-loops.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PlaceSafepoints/finite-loops.ll?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PlaceSafepoints/finite-loops.ll (original)
+++ llvm/trunk/test/Transforms/PlaceSafepoints/finite-loops.ll Fri Feb 20 18:09:09 2015
@@ -4,7 +4,7 @@
 
 
 ; A simple counted loop with trivially known range
-define void @test1(i32) {
+define void @test1(i32) gc "statepoint-example" {
 ; CHECK-LABEL: test1
 ; CHECK-LABEL: entry
 ; CHECK: statepoint
@@ -25,7 +25,7 @@ exit:
 }
 
 ; The same counted loop, but with an unknown early exit
-define void @test2(i32) {
+define void @test2(i32) gc "statepoint-example" {
 ; CHECK-LABEL: test2
 ; CHECK-LABEL: entry
 ; CHECK: statepoint
@@ -49,7 +49,7 @@ exit:
 }
 
 ; The range is a 8 bit value and we can't overflow
-define void @test3(i8 %upper) {
+define void @test3(i8 %upper) gc "statepoint-example" {
 ; CHECK-LABEL: test3
 ; CHECK-LABEL: entry
 ; CHECK: statepoint

Modified: llvm/trunk/test/Transforms/PlaceSafepoints/invokes.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PlaceSafepoints/invokes.ll?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PlaceSafepoints/invokes.ll (original)
+++ llvm/trunk/test/Transforms/PlaceSafepoints/invokes.ll Fri Feb 20 18:09:09 2015
@@ -3,7 +3,7 @@
 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) {
+define i64 addrspace(1)* @test_basic(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
 ; CHECK-LABEL: entry:
 entry:
   ; CHECK: invoke
@@ -29,7 +29,7 @@ exceptional_return:
   ret i64 addrspace(1)* %obj1
 }
 
-define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) {
+define i64 addrspace(1)* @test_two_invokes(i64 addrspace(1)* %obj, i64 addrspace(1)* %obj1) gc "statepoint-example" {
 ; CHECK-LABEL: entry:
 entry:
   ; CHECK: invoke 
@@ -61,7 +61,7 @@ exceptional_return:
   ret i64 addrspace(1)* %obj1
 }
 
-define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) {
+define i64 addrspace(1)* @test_phi_node(i1 %cond, i64 addrspace(1)* %obj) gc "statepoint-example" {
 ; CHECK-LABEL: entry:
 entry:
   br i1 %cond, label %left, label %right

Modified: llvm/trunk/test/Transforms/PlaceSafepoints/split-backedge.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PlaceSafepoints/split-backedge.ll?rev=230097&r1=230096&r2=230097&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/PlaceSafepoints/split-backedge.ll (original)
+++ llvm/trunk/test/Transforms/PlaceSafepoints/split-backedge.ll Fri Feb 20 18:09:09 2015
@@ -1,7 +1,7 @@
 ;; A very basic test to make sure that splitting the backedge keeps working
 ;; RUN: opt -place-safepoints -spp-split-backedge=1 -S %s | FileCheck %s
 
-define void @test(i32, i1 %cond) {
+define void @test(i32, i1 %cond) gc "statepoint-example" {
 ; CHECK-LABEL: @test
 ; CHECK-LABEL: loop.loop_crit_edge
 ; CHECK: gc.statepoint
@@ -20,7 +20,7 @@ exit:
 ; different loop header blocks.  Since we're currently using LoopSimplfy
 ; this doesn't hit the interesting case, but once we remove that, we need
 ; to be sure this keeps working.
-define void @test2(i32, i1 %cond) {
+define void @test2(i32, i1 %cond) gc "statepoint-example" {
 ; CHECK-LABEL: @test2
 ; CHECK-LABE: loop.loopexit.split
 ; CHECK: gc.statepoint





More information about the llvm-commits mailing list