diff --git a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp index 3df40df861fd..63e8115bea60 100644 --- a/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp +++ b/llvm/lib/Transforms/Scalar/PlaceSafepoints.cpp @@ -108,6 +108,11 @@ static cl::opt CountedLoopTripWidth("spp-counted-loop-trip-width", static cl::opt SplitBackedge("spp-split-backedge", cl::Hidden, cl::init(false)); +// If true, don't wrap calls (the ones present in the IR, and the ones +// introduced due to polls) in gc.statepoint. +static cl::opt NoStatepoints("spp-no-statepoints", cl::Hidden, + cl::init(false)); + // Print tracing output static cl::opt TraceLSP("spp-trace", cl::Hidden, cl::init(false)); @@ -661,6 +666,15 @@ bool PlaceSafepoints::runOnFunction(Function &F) { ParsePointNeeded.insert(ParsePointNeeded.end(), RuntimeCalls.begin(), RuntimeCalls.end()); } + + // If we've been asked to not wrap the calls with gc.statepoint, then we're + // done. In the near future, this option will be "constant folded" to true, + // and the code below that deals with insert gc.statepoint calls will be + // removed. Wrapping potentially safepointing calls in gc.statepoint will + // then become the responsibility of the RewriteStatepointsForGC pass. + if (NoStatepoints) + return modified; + PollsNeeded.clear(); // make sure we don't accidentally use // The dominator tree has been invalidated by the inlining performed in the // above loop. TODO: Teach the inliner how to update the dom tree? diff --git a/llvm/test/Transforms/PlaceSafepoints/no-statepoints.ll b/llvm/test/Transforms/PlaceSafepoints/no-statepoints.ll new file mode 100644 index 000000000000..3e4988cb316f --- /dev/null +++ b/llvm/test/Transforms/PlaceSafepoints/no-statepoints.ll @@ -0,0 +1,21 @@ +; RUN: opt -spp-no-statepoints -S -place-safepoints < %s | FileCheck %s + +define void @test() gc "statepoint-example" { +; CHECK-LABEL: test( +entry: +; CHECK: entry: +; CHECK: call void @do_safepoint() + br label %other + +other: +; CHECK: other: + call void undef() "gc-leaf-function" +; CHECK: call void @do_safepoint() + br label %other +} + +declare void @do_safepoint() +define void @gc.safepoint_poll() { + call void @do_safepoint() + ret void +}