mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[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. llvm-svn: 230097
This commit is contained in:
parent
d50d0da4e2
commit
fe3f4cccba
@ -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 &F) {
|
||||
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(Function &F) {
|
||||
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(Function &F) {
|
||||
|
||||
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(Function &F) {
|
||||
}
|
||||
}
|
||||
|
||||
if (EnableEntrySafepoints) {
|
||||
if (enableEntrySafepoints(F)) {
|
||||
DT.recalculate(F);
|
||||
Instruction *term = findLocationForEntrySafepoint(F, DT);
|
||||
if (!term) {
|
||||
@ -624,7 +639,7 @@ bool PlaceSafepoints::runOnFunction(Function &F) {
|
||||
}
|
||||
}
|
||||
|
||||
if (EnableCallSafepoints) {
|
||||
if (enableCallSafepoints(F)) {
|
||||
DT.recalculate(F);
|
||||
std::vector<CallSite> Calls;
|
||||
findCallSafepoints(F, Calls);
|
||||
|
@ -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" {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
declare void @foo()
|
||||
|
||||
define void @test1() {
|
||||
define void @test1() gc "statepoint-example" {
|
||||
; CHECK-LABEL: test1
|
||||
|
||||
entry:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user