mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 04:30:23 +00:00
Eliminate the unused CodeGenPrepare option to split critical edges.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@126825 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fd8978b021
commit
56e3793acf
@ -58,11 +58,6 @@ STATISTIC(NumMemoryInsts, "Number of memory instructions whose address "
|
||||
STATISTIC(NumExtsMoved, "Number of [s|z]ext instructions combined with loads");
|
||||
STATISTIC(NumExtUses, "Number of uses of [s|z]ext instructions optimized");
|
||||
|
||||
static cl::opt<bool>
|
||||
CriticalEdgeSplit("cgp-critical-edge-splitting",
|
||||
cl::desc("Split critical edges during codegen prepare"),
|
||||
cl::init(false), cl::Hidden);
|
||||
|
||||
namespace {
|
||||
class CodeGenPrepare : public FunctionPass {
|
||||
/// TLI - Keep a pointer of a TargetLowering to consult for determining
|
||||
@ -144,11 +139,6 @@ bool CodeGenPrepare::runOnFunction(Function &F) {
|
||||
// unconditional branch.
|
||||
EverMadeChange |= EliminateMostlyEmptyBlocks(F);
|
||||
|
||||
// Now find loop back edges, but only if they are being used to decide which
|
||||
// critical edges to split.
|
||||
if (CriticalEdgeSplit)
|
||||
findLoopBackEdges(F);
|
||||
|
||||
bool MadeChange = true;
|
||||
while (MadeChange) {
|
||||
MadeChange = false;
|
||||
@ -350,110 +340,6 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) {
|
||||
DEBUG(dbgs() << "AFTER:\n" << *DestBB << "\n\n\n");
|
||||
}
|
||||
|
||||
/// FindReusablePredBB - Check all of the predecessors of the block DestPHI
|
||||
/// lives in to see if there is a block that we can reuse as a critical edge
|
||||
/// from TIBB.
|
||||
static BasicBlock *FindReusablePredBB(PHINode *DestPHI, BasicBlock *TIBB) {
|
||||
BasicBlock *Dest = DestPHI->getParent();
|
||||
|
||||
/// TIPHIValues - This array is lazily computed to determine the values of
|
||||
/// PHIs in Dest that TI would provide.
|
||||
SmallVector<Value*, 32> TIPHIValues;
|
||||
|
||||
/// TIBBEntryNo - This is a cache to speed up pred queries for TIBB.
|
||||
unsigned TIBBEntryNo = 0;
|
||||
|
||||
// Check to see if Dest has any blocks that can be used as a split edge for
|
||||
// this terminator.
|
||||
for (unsigned pi = 0, e = DestPHI->getNumIncomingValues(); pi != e; ++pi) {
|
||||
BasicBlock *Pred = DestPHI->getIncomingBlock(pi);
|
||||
// To be usable, the pred has to end with an uncond branch to the dest.
|
||||
BranchInst *PredBr = dyn_cast<BranchInst>(Pred->getTerminator());
|
||||
if (!PredBr || !PredBr->isUnconditional())
|
||||
continue;
|
||||
// Must be empty other than the branch and debug info.
|
||||
BasicBlock::iterator I = Pred->begin();
|
||||
while (isa<DbgInfoIntrinsic>(I))
|
||||
I++;
|
||||
if (&*I != PredBr)
|
||||
continue;
|
||||
// Cannot be the entry block; its label does not get emitted.
|
||||
if (Pred == &Dest->getParent()->getEntryBlock())
|
||||
continue;
|
||||
|
||||
// Finally, since we know that Dest has phi nodes in it, we have to make
|
||||
// sure that jumping to Pred will have the same effect as going to Dest in
|
||||
// terms of PHI values.
|
||||
PHINode *PN;
|
||||
unsigned PHINo = 0;
|
||||
unsigned PredEntryNo = pi;
|
||||
|
||||
bool FoundMatch = true;
|
||||
for (BasicBlock::iterator I = Dest->begin();
|
||||
(PN = dyn_cast<PHINode>(I)); ++I, ++PHINo) {
|
||||
if (PHINo == TIPHIValues.size()) {
|
||||
if (PN->getIncomingBlock(TIBBEntryNo) != TIBB)
|
||||
TIBBEntryNo = PN->getBasicBlockIndex(TIBB);
|
||||
TIPHIValues.push_back(PN->getIncomingValue(TIBBEntryNo));
|
||||
}
|
||||
|
||||
// If the PHI entry doesn't work, we can't use this pred.
|
||||
if (PN->getIncomingBlock(PredEntryNo) != Pred)
|
||||
PredEntryNo = PN->getBasicBlockIndex(Pred);
|
||||
|
||||
if (TIPHIValues[PHINo] != PN->getIncomingValue(PredEntryNo)) {
|
||||
FoundMatch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we found a workable predecessor, change TI to branch to Succ.
|
||||
if (FoundMatch)
|
||||
return Pred;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/// SplitEdgeNicely - Split the critical edge from TI to its specified
|
||||
/// successor if it will improve codegen. We only do this if the successor has
|
||||
/// phi nodes (otherwise critical edges are ok). If there is already another
|
||||
/// predecessor of the succ that is empty (and thus has no phi nodes), use it
|
||||
/// instead of introducing a new block.
|
||||
static void SplitEdgeNicely(TerminatorInst *TI, unsigned SuccNum,
|
||||
SmallSet<std::pair<const BasicBlock*,
|
||||
const BasicBlock*>, 8> &BackEdges,
|
||||
Pass *P) {
|
||||
BasicBlock *TIBB = TI->getParent();
|
||||
BasicBlock *Dest = TI->getSuccessor(SuccNum);
|
||||
assert(isa<PHINode>(Dest->begin()) &&
|
||||
"This should only be called if Dest has a PHI!");
|
||||
PHINode *DestPHI = cast<PHINode>(Dest->begin());
|
||||
|
||||
// Do not split edges to EH landing pads.
|
||||
if (InvokeInst *Invoke = dyn_cast<InvokeInst>(TI))
|
||||
if (Invoke->getSuccessor(1) == Dest)
|
||||
return;
|
||||
|
||||
// As a hack, never split backedges of loops. Even though the copy for any
|
||||
// PHIs inserted on the backedge would be dead for exits from the loop, we
|
||||
// assume that the cost of *splitting* the backedge would be too high.
|
||||
if (BackEdges.count(std::make_pair(TIBB, Dest)))
|
||||
return;
|
||||
|
||||
if (BasicBlock *ReuseBB = FindReusablePredBB(DestPHI, TIBB)) {
|
||||
ProfileInfo *PFI = P->getAnalysisIfAvailable<ProfileInfo>();
|
||||
if (PFI)
|
||||
PFI->splitEdge(TIBB, Dest, ReuseBB);
|
||||
Dest->removePredecessor(TIBB);
|
||||
TI->setSuccessor(SuccNum, ReuseBB);
|
||||
return;
|
||||
}
|
||||
|
||||
SplitCriticalEdge(TI, SuccNum, P, true);
|
||||
}
|
||||
|
||||
|
||||
/// OptimizeNoopCopyExpression - If the specified cast instruction is a noop
|
||||
/// copy (e.g. it's casting from one pointer type to another, i32->i8 on PPC),
|
||||
/// sink it into user blocks to reduce the number of virtual
|
||||
@ -1081,21 +967,8 @@ bool CodeGenPrepare::OptimizeInst(Instruction *I) {
|
||||
// across basic blocks and rewrite them to improve basic-block-at-a-time
|
||||
// selection.
|
||||
bool CodeGenPrepare::OptimizeBlock(BasicBlock &BB) {
|
||||
bool MadeChange = false;
|
||||
|
||||
// Split all critical edges where the dest block has a PHI.
|
||||
if (CriticalEdgeSplit) {
|
||||
TerminatorInst *BBTI = BB.getTerminator();
|
||||
if (BBTI->getNumSuccessors() > 1 && !isa<IndirectBrInst>(BBTI)) {
|
||||
for (unsigned i = 0, e = BBTI->getNumSuccessors(); i != e; ++i) {
|
||||
BasicBlock *SuccBB = BBTI->getSuccessor(i);
|
||||
if (isa<PHINode>(SuccBB->begin()) && isCriticalEdge(BBTI, i, true))
|
||||
SplitEdgeNicely(BBTI, i, BackEdges, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SunkAddrs.clear();
|
||||
bool MadeChange = false;
|
||||
|
||||
CurInstIterator = BB.begin();
|
||||
for (BasicBlock::iterator E = BB.end(); CurInstIterator != E; )
|
||||
|
@ -1,4 +1,4 @@
|
||||
; RUN: llc < %s -mtriple=armv7-apple-darwin -cgp-critical-edge-splitting=0 | FileCheck %s
|
||||
; RUN: llc < %s -mtriple=armv7-apple-darwin | FileCheck %s
|
||||
; PHI elimination shouldn't break backedge.
|
||||
; rdar://8263994
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
; RUN: llc -verify-machineinstrs -cgp-critical-edge-splitting=0 -mcpu=i386 < %s
|
||||
; RUN: llc -verify-machineinstrs -mcpu=i386 < %s
|
||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
|
||||
target triple = "i386-pc-linux-gnu"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user