forked from OSchip/llvm-project
parent
2603b0758d
commit
331521c688
|
@ -104,10 +104,7 @@ static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT,
|
|||
|
||||
// Insert the LCSSA phi's into all of the exit blocks dominated by the
|
||||
// value, and add them to the Phi's map.
|
||||
for (SmallVectorImpl<BasicBlock *>::const_iterator BBI = ExitBlocks.begin(),
|
||||
BBE = ExitBlocks.end();
|
||||
BBI != BBE; ++BBI) {
|
||||
BasicBlock *ExitBB = *BBI;
|
||||
for (BasicBlock *ExitBB : ExitBlocks) {
|
||||
if (!DT.dominates(DomNode, DT.getNode(ExitBB)))
|
||||
continue;
|
||||
|
||||
|
@ -151,26 +148,26 @@ static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT,
|
|||
|
||||
// Rewrite all uses outside the loop in terms of the new PHIs we just
|
||||
// inserted.
|
||||
for (unsigned i = 0, e = UsesToRewrite.size(); i != e; ++i) {
|
||||
for (Use *UseToRewrite : UsesToRewrite) {
|
||||
// If this use is in an exit block, rewrite to use the newly inserted PHI.
|
||||
// This is required for correctness because SSAUpdate doesn't handle uses in
|
||||
// the same block. It assumes the PHI we inserted is at the end of the
|
||||
// block.
|
||||
Instruction *User = cast<Instruction>(UsesToRewrite[i]->getUser());
|
||||
Instruction *User = cast<Instruction>(UseToRewrite->getUser());
|
||||
BasicBlock *UserBB = User->getParent();
|
||||
if (PHINode *PN = dyn_cast<PHINode>(User))
|
||||
UserBB = PN->getIncomingBlock(*UsesToRewrite[i]);
|
||||
UserBB = PN->getIncomingBlock(*UseToRewrite);
|
||||
|
||||
if (isa<PHINode>(UserBB->begin()) && isExitBlock(UserBB, ExitBlocks)) {
|
||||
// Tell the VHs that the uses changed. This updates SCEV's caches.
|
||||
if (UsesToRewrite[i]->get()->hasValueHandle())
|
||||
ValueHandleBase::ValueIsRAUWd(*UsesToRewrite[i], &UserBB->front());
|
||||
UsesToRewrite[i]->set(&UserBB->front());
|
||||
if (UseToRewrite->get()->hasValueHandle())
|
||||
ValueHandleBase::ValueIsRAUWd(*UseToRewrite, &UserBB->front());
|
||||
UseToRewrite->set(&UserBB->front());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Otherwise, do full PHI insertion.
|
||||
SSAUpdate.RewriteUse(*UsesToRewrite[i]);
|
||||
SSAUpdate.RewriteUse(*UseToRewrite);
|
||||
}
|
||||
|
||||
// Post process PHI instructions that were inserted into another disjoint loop
|
||||
|
@ -193,10 +190,9 @@ static bool processInstruction(Loop &L, Instruction &Inst, DominatorTree &DT,
|
|||
}
|
||||
|
||||
// Remove PHI nodes that did not have any uses rewritten.
|
||||
for (unsigned i = 0, e = AddedPHIs.size(); i != e; ++i) {
|
||||
if (AddedPHIs[i]->use_empty())
|
||||
AddedPHIs[i]->eraseFromParent();
|
||||
}
|
||||
for (PHINode *PN : AddedPHIs)
|
||||
if (PN->use_empty())
|
||||
PN->eraseFromParent();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -208,8 +204,8 @@ blockDominatesAnExit(BasicBlock *BB,
|
|||
DominatorTree &DT,
|
||||
const SmallVectorImpl<BasicBlock *> &ExitBlocks) {
|
||||
DomTreeNode *DomNode = DT.getNode(BB);
|
||||
for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
|
||||
if (DT.dominates(DomNode, DT.getNode(ExitBlocks[i])))
|
||||
for (BasicBlock *ExitBB : ExitBlocks)
|
||||
if (DT.dominates(DomNode, DT.getNode(ExitBB)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -230,25 +226,22 @@ bool llvm::formLCSSA(Loop &L, DominatorTree &DT, LoopInfo *LI,
|
|||
|
||||
// Look at all the instructions in the loop, checking to see if they have uses
|
||||
// outside the loop. If so, rewrite those uses.
|
||||
for (Loop::block_iterator BBI = L.block_begin(), BBE = L.block_end();
|
||||
BBI != BBE; ++BBI) {
|
||||
BasicBlock *BB = *BBI;
|
||||
|
||||
for (BasicBlock *BB : L.blocks()) {
|
||||
// For large loops, avoid use-scanning by using dominance information: In
|
||||
// particular, if a block does not dominate any of the loop exits, then none
|
||||
// of the values defined in the block could be used outside the loop.
|
||||
if (!blockDominatesAnExit(BB, DT, ExitBlocks))
|
||||
continue;
|
||||
|
||||
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
|
||||
for (Instruction &I : *BB) {
|
||||
// Reject two common cases fast: instructions with no uses (like stores)
|
||||
// and instructions with one use that is in the same block as this.
|
||||
if (I->use_empty() ||
|
||||
(I->hasOneUse() && I->user_back()->getParent() == BB &&
|
||||
!isa<PHINode>(I->user_back())))
|
||||
if (I.use_empty() ||
|
||||
(I.hasOneUse() && I.user_back()->getParent() == BB &&
|
||||
!isa<PHINode>(I.user_back())))
|
||||
continue;
|
||||
|
||||
Changed |= processInstruction(L, *I, DT, ExitBlocks, PredCache, LI);
|
||||
Changed |= processInstruction(L, I, DT, ExitBlocks, PredCache, LI);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,8 +262,8 @@ bool llvm::formLCSSARecursively(Loop &L, DominatorTree &DT, LoopInfo *LI,
|
|||
bool Changed = false;
|
||||
|
||||
// Recurse depth-first through inner loops.
|
||||
for (Loop::iterator I = L.begin(), E = L.end(); I != E; ++I)
|
||||
Changed |= formLCSSARecursively(**I, DT, LI, SE);
|
||||
for (Loop *L : L.getSubLoops())
|
||||
Changed |= formLCSSARecursively(*L, DT, LI, SE);
|
||||
|
||||
Changed |= formLCSSA(L, DT, LI, SE);
|
||||
return Changed;
|
||||
|
|
Loading…
Reference in New Issue