mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-10-01 10:57:21 +00:00
various code cleanups, enhance MergeBlockIntoPredecessor to preserve
loop info. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123074 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a1ae0c74af
commit
dc85f8ab80
@ -110,7 +110,7 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
if (isa<InvokeInst>(PredBB->getTerminator())) return false;
|
if (isa<InvokeInst>(PredBB->getTerminator())) return false;
|
||||||
|
|
||||||
succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
|
succ_iterator SI(succ_begin(PredBB)), SE(succ_end(PredBB));
|
||||||
BasicBlock* OnlySucc = BB;
|
BasicBlock *OnlySucc = BB;
|
||||||
for (; SI != SE; ++SI)
|
for (; SI != SE; ++SI)
|
||||||
if (*SI != OnlySucc) {
|
if (*SI != OnlySucc) {
|
||||||
OnlySucc = 0; // There are multiple distinct successors!
|
OnlySucc = 0; // There are multiple distinct successors!
|
||||||
@ -131,10 +131,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Begin by getting rid of unneeded PHIs.
|
// Begin by getting rid of unneeded PHIs.
|
||||||
while (PHINode *PN = dyn_cast<PHINode>(&BB->front())) {
|
if (isa<PHINode>(BB->front()))
|
||||||
PN->replaceAllUsesWith(PN->getIncomingValue(0));
|
FoldSingleEntryPHINodes(BB);
|
||||||
BB->getInstList().pop_front(); // Delete the phi node...
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the unconditional branch from the predecessor...
|
// Delete the unconditional branch from the predecessor...
|
||||||
PredBB->getInstList().pop_back();
|
PredBB->getInstList().pop_back();
|
||||||
@ -152,11 +150,9 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
|
|
||||||
// Finally, erase the old block and update dominator info.
|
// Finally, erase the old block and update dominator info.
|
||||||
if (P) {
|
if (P) {
|
||||||
if (DominatorTree* DT = P->getAnalysisIfAvailable<DominatorTree>()) {
|
if (DominatorTree *DT = P->getAnalysisIfAvailable<DominatorTree>()) {
|
||||||
DomTreeNode* DTN = DT->getNode(BB);
|
if (DomTreeNode *DTN = DT->getNode(BB)) {
|
||||||
DomTreeNode* PredDTN = DT->getNode(PredBB);
|
DomTreeNode *PredDTN = DT->getNode(PredBB);
|
||||||
|
|
||||||
if (DTN) {
|
|
||||||
SmallPtrSet<DomTreeNode*, 8> Children(DTN->begin(), DTN->end());
|
SmallPtrSet<DomTreeNode*, 8> Children(DTN->begin(), DTN->end());
|
||||||
for (SmallPtrSet<DomTreeNode*, 8>::iterator DI = Children.begin(),
|
for (SmallPtrSet<DomTreeNode*, 8>::iterator DI = Children.begin(),
|
||||||
DE = Children.end(); DI != DE; ++DI)
|
DE = Children.end(); DI != DE; ++DI)
|
||||||
@ -164,12 +160,13 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
|||||||
|
|
||||||
DT->eraseNode(BB);
|
DT->eraseNode(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
|
||||||
|
LI->removeBlock(BB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +273,7 @@ BasicBlock *llvm::SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P) {
|
|||||||
|
|
||||||
// The new block lives in whichever loop the old one did. This preserves
|
// The new block lives in whichever loop the old one did. This preserves
|
||||||
// LCSSA as well, because we force the split point to be after any PHI nodes.
|
// LCSSA as well, because we force the split point to be after any PHI nodes.
|
||||||
if (LoopInfo* LI = P->getAnalysisIfAvailable<LoopInfo>())
|
if (LoopInfo *LI = P->getAnalysisIfAvailable<LoopInfo>())
|
||||||
if (Loop *L = LI->getLoopFor(Old))
|
if (Loop *L = LI->getLoopFor(Old))
|
||||||
L->addBasicBlockToLoop(New, LI->getBase());
|
L->addBasicBlockToLoop(New, LI->getBase());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user