forked from OSchip/llvm-project
[PM] Replace another Pass argument with specific analyses that are
optionally updated by MergeBlockIntoPredecessors. No functionality changed, just refactoring to clear the way for the new pass manager. llvm-svn: 226392
This commit is contained in:
parent
94209094a5
commit
b5c115357c
|
@ -25,6 +25,7 @@ namespace llvm {
|
||||||
class AliasAnalysis;
|
class AliasAnalysis;
|
||||||
class MemoryDependenceAnalysis;
|
class MemoryDependenceAnalysis;
|
||||||
class DominatorTree;
|
class DominatorTree;
|
||||||
|
class LoopInfo;
|
||||||
class Instruction;
|
class Instruction;
|
||||||
class MDNode;
|
class MDNode;
|
||||||
class Pass;
|
class Pass;
|
||||||
|
@ -52,7 +53,10 @@ bool DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI = nullptr);
|
||||||
|
|
||||||
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
||||||
/// if possible. The return value indicates success or failure.
|
/// if possible. The return value indicates success or failure.
|
||||||
bool MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P = nullptr);
|
bool MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT = nullptr,
|
||||||
|
LoopInfo *LI = nullptr,
|
||||||
|
AliasAnalysis *AA = nullptr,
|
||||||
|
MemoryDependenceAnalysis *MemDep = nullptr);
|
||||||
|
|
||||||
// ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
|
// ReplaceInstWithValue - Replace all uses of an instruction (specified by BI)
|
||||||
// with a value, then remove and delete the original instruction.
|
// with a value, then remove and delete the original instruction.
|
||||||
|
|
|
@ -2363,7 +2363,8 @@ bool GVN::runOnFunction(Function& F) {
|
||||||
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
|
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
|
||||||
BasicBlock *BB = FI++;
|
BasicBlock *BB = FI++;
|
||||||
|
|
||||||
bool removedBlock = MergeBlockIntoPredecessor(BB, this);
|
bool removedBlock = MergeBlockIntoPredecessor(
|
||||||
|
BB, DT, /* LoopInfo */ nullptr, VN.getAliasAnalysis(), MD);
|
||||||
if (removedBlock) ++NumGVNBlocks;
|
if (removedBlock) ++NumGVNBlocks;
|
||||||
|
|
||||||
Changed |= removedBlock;
|
Changed |= removedBlock;
|
||||||
|
|
|
@ -593,7 +593,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
|
||||||
// the OrigHeader block into OrigLatch. This will succeed if they are
|
// the OrigHeader block into OrigLatch. This will succeed if they are
|
||||||
// connected by an unconditional branch. This is just a cleanup so the
|
// connected by an unconditional branch. This is just a cleanup so the
|
||||||
// emitted code isn't too gross in this common case.
|
// emitted code isn't too gross in this common case.
|
||||||
MergeBlockIntoPredecessor(OrigHeader, this);
|
MergeBlockIntoPredecessor(OrigHeader, DT, LI);
|
||||||
|
|
||||||
DEBUG(dbgs() << "LoopRotation: into "; L->dump());
|
DEBUG(dbgs() << "LoopRotation: into "; L->dump());
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,9 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI) {
|
||||||
|
|
||||||
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
|
||||||
/// if possible. The return value indicates success or failure.
|
/// if possible. The return value indicates success or failure.
|
||||||
bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, DominatorTree *DT,
|
||||||
|
LoopInfo *LI, AliasAnalysis *AA,
|
||||||
|
MemoryDependenceAnalysis *MemDep) {
|
||||||
// Don't merge away blocks who have their address taken.
|
// Don't merge away blocks who have their address taken.
|
||||||
if (BB->hasAddressTaken()) return false;
|
if (BB->hasAddressTaken()) return false;
|
||||||
|
|
||||||
|
@ -142,11 +144,8 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begin by getting rid of unneeded PHIs.
|
// Begin by getting rid of unneeded PHIs.
|
||||||
if (isa<PHINode>(BB->front())) {
|
if (isa<PHINode>(BB->front()))
|
||||||
auto *AA = P ? P->getAnalysisIfAvailable<AliasAnalysis>() : nullptr;
|
|
||||||
auto *MemDep = P ? P->getAnalysisIfAvailable<MemoryDependenceAnalysis>() : nullptr;
|
|
||||||
FoldSingleEntryPHINodes(BB, AA, MemDep);
|
FoldSingleEntryPHINodes(BB, AA, MemDep);
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the unconditional branch from the predecessor...
|
// Delete the unconditional branch from the predecessor...
|
||||||
PredBB->getInstList().pop_back();
|
PredBB->getInstList().pop_back();
|
||||||
|
@ -163,28 +162,23 @@ bool llvm::MergeBlockIntoPredecessor(BasicBlock *BB, Pass *P) {
|
||||||
PredBB->takeName(BB);
|
PredBB->takeName(BB);
|
||||||
|
|
||||||
// Finally, erase the old block and update dominator info.
|
// Finally, erase the old block and update dominator info.
|
||||||
if (P) {
|
if (DT)
|
||||||
if (DominatorTreeWrapperPass *DTWP =
|
if (DomTreeNode *DTN = DT->getNode(BB)) {
|
||||||
P->getAnalysisIfAvailable<DominatorTreeWrapperPass>()) {
|
DomTreeNode *PredDTN = DT->getNode(PredBB);
|
||||||
DominatorTree &DT = DTWP->getDomTree();
|
SmallVector<DomTreeNode *, 8> Children(DTN->begin(), DTN->end());
|
||||||
if (DomTreeNode *DTN = DT.getNode(BB)) {
|
for (SmallVectorImpl<DomTreeNode *>::iterator DI = Children.begin(),
|
||||||
DomTreeNode *PredDTN = DT.getNode(PredBB);
|
DE = Children.end();
|
||||||
SmallVector<DomTreeNode*, 8> Children(DTN->begin(), DTN->end());
|
DI != DE; ++DI)
|
||||||
for (SmallVectorImpl<DomTreeNode *>::iterator DI = Children.begin(),
|
DT->changeImmediateDominator(*DI, PredDTN);
|
||||||
DE = Children.end(); DI != DE; ++DI)
|
|
||||||
DT.changeImmediateDominator(*DI, PredDTN);
|
|
||||||
|
|
||||||
DT.eraseNode(BB);
|
DT->eraseNode(BB);
|
||||||
}
|
|
||||||
|
|
||||||
if (auto *LIWP = P->getAnalysisIfAvailable<LoopInfoWrapperPass>())
|
|
||||||
LIWP->getLoopInfo().removeBlock(BB);
|
|
||||||
|
|
||||||
if (MemoryDependenceAnalysis *MD =
|
|
||||||
P->getAnalysisIfAvailable<MemoryDependenceAnalysis>())
|
|
||||||
MD->invalidateCachedPredecessors();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if (LI)
|
||||||
|
LI->removeBlock(BB);
|
||||||
|
|
||||||
|
if (MemDep)
|
||||||
|
MemDep->invalidateCachedPredecessors();
|
||||||
|
|
||||||
BB->eraseFromParent();
|
BB->eraseFromParent();
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue