mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-14 16:33:28 +00:00
Fixed minor bug in SafeToHoist and made some changes suggested by Chris.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7614 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
7526eed382
commit
11a49a722f
@ -67,7 +67,7 @@ namespace {
|
|||||||
BasicBlock *Preheader; // The preheader block of the current loop...
|
BasicBlock *Preheader; // The preheader block of the current loop...
|
||||||
Loop *CurLoop; // The current loop we are working on...
|
Loop *CurLoop; // The current loop we are working on...
|
||||||
AliasSetTracker *CurAST; // AliasSet information for the current loop...
|
AliasSetTracker *CurAST; // AliasSet information for the current loop...
|
||||||
DominatorTree *CurDT; // Dominator Tree for the current Loop...
|
DominatorTree *DT; // Dominator Tree for the current Loop...
|
||||||
|
|
||||||
/// visitLoop - Hoist expressions out of the specified loop...
|
/// visitLoop - Hoist expressions out of the specified loop...
|
||||||
///
|
///
|
||||||
@ -173,6 +173,7 @@ bool LICM::runOnFunction(Function &) {
|
|||||||
// Get our Loop and Alias Analysis information...
|
// Get our Loop and Alias Analysis information...
|
||||||
LI = &getAnalysis<LoopInfo>();
|
LI = &getAnalysis<LoopInfo>();
|
||||||
AA = &getAnalysis<AliasAnalysis>();
|
AA = &getAnalysis<AliasAnalysis>();
|
||||||
|
DT = &getAnalysis<DominatorTree>();
|
||||||
|
|
||||||
// Hoist expressions out of all of the top-level loops.
|
// Hoist expressions out of all of the top-level loops.
|
||||||
const std::vector<Loop*> &TopLevelLoops = LI->getTopLevelLoops();
|
const std::vector<Loop*> &TopLevelLoops = LI->getTopLevelLoops();
|
||||||
@ -223,9 +224,7 @@ void LICM::visitLoop(Loop *L, AliasSetTracker &AST) {
|
|||||||
// that we are guaranteed to see definitions before we see uses. This allows
|
// that we are guaranteed to see definitions before we see uses. This allows
|
||||||
// us to perform the LICM transformation in one pass, without iteration.
|
// us to perform the LICM transformation in one pass, without iteration.
|
||||||
//
|
//
|
||||||
CurDT = &getAnalysis<DominatorTree>();
|
HoistRegion(DT->getNode(L->getHeader()));
|
||||||
|
|
||||||
HoistRegion(CurDT->getNode(L->getHeader()));
|
|
||||||
|
|
||||||
// Now that all loop invariants have been removed from the loop, promote any
|
// Now that all loop invariants have been removed from the loop, promote any
|
||||||
// memory references to scalars that we can...
|
// memory references to scalars that we can...
|
||||||
@ -290,36 +289,28 @@ bool LICM::SafeToHoist(Instruction &Inst) {
|
|||||||
BasicBlock *InstBB = Inst.getParent();
|
BasicBlock *InstBB = Inst.getParent();
|
||||||
|
|
||||||
//Get the Dominator Tree Node for the instruction's basic block/
|
//Get the Dominator Tree Node for the instruction's basic block/
|
||||||
DominatorTree::Node *InstDTNode = CurDT->getNode(InstBB);
|
DominatorTree::Node *InstDTNode = DT->getNode(InstBB);
|
||||||
|
|
||||||
//Get the exit blocks for the current loop.
|
//Get the exit blocks for the current loop.
|
||||||
const std::vector<BasicBlock* > ExitBlocks = CurLoop->getExitBlocks();
|
const std::vector<BasicBlock* > &ExitBlocks = CurLoop->getExitBlocks();
|
||||||
|
|
||||||
//For each exit block, get the DT node and walk up the DT until
|
//For each exit block, get the DT node and walk up the DT until
|
||||||
//the instruction's basic block is found or we exit the loop.
|
//the instruction's basic block is found or we exit the loop.
|
||||||
for(unsigned i=0; i < ExitBlocks.size(); ++i) {
|
for(unsigned i=0; i < ExitBlocks.size(); ++i) {
|
||||||
DominatorTree::Node *IDom = CurDT->getNode(ExitBlocks[i]);
|
DominatorTree::Node *IDom = DT->getNode(ExitBlocks[i]);
|
||||||
|
|
||||||
//Using boolean variable because exit nodes are not "contained"
|
while(IDom != InstDTNode) {
|
||||||
//in the loop, so can not use that as the while test condition
|
|
||||||
//for first pass.
|
|
||||||
bool inLoop = true;
|
|
||||||
|
|
||||||
while(inLoop) {
|
|
||||||
|
|
||||||
//compare Instruction DT node to Current DT Node
|
|
||||||
if(IDom == InstDTNode)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
//Get next Immediate Dominator.
|
//Get next Immediate Dominator.
|
||||||
IDom = IDom->getIDom();
|
IDom = IDom->getIDom();
|
||||||
|
|
||||||
//See if we exited the loop.
|
//See if we exited the loop.
|
||||||
inLoop = CurLoop->contains(IDom->getNode());
|
if(!CurLoop->contains(IDom->getNode()))
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user