[llvm] r226392 - [PM] Replace another Pass argument with specific analyses that are
Chandler Carruth
chandlerc at gmail.com
Sat Jan 17 18:11:23 PST 2015
Author: chandlerc
Date: Sat Jan 17 20:11:23 2015
New Revision: 226392
URL: http://llvm.org/viewvc/llvm-project?rev=226392&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h?rev=226392&r1=226391&r2=226392&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/BasicBlockUtils.h Sat Jan 17 20:11:23 2015
@@ -25,6 +25,7 @@ namespace llvm {
class AliasAnalysis;
class MemoryDependenceAnalysis;
class DominatorTree;
+class LoopInfo;
class Instruction;
class MDNode;
class Pass;
@@ -52,7 +53,10 @@ bool DeleteDeadPHIs(BasicBlock *BB, cons
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
/// 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)
// with a value, then remove and delete the original instruction.
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=226392&r1=226391&r2=226392&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Sat Jan 17 20:11:23 2015
@@ -2363,7 +2363,8 @@ bool GVN::runOnFunction(Function& F) {
for (Function::iterator FI = F.begin(), FE = F.end(); FI != FE; ) {
BasicBlock *BB = FI++;
- bool removedBlock = MergeBlockIntoPredecessor(BB, this);
+ bool removedBlock = MergeBlockIntoPredecessor(
+ BB, DT, /* LoopInfo */ nullptr, VN.getAliasAnalysis(), MD);
if (removedBlock) ++NumGVNBlocks;
Changed |= removedBlock;
Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=226392&r1=226391&r2=226392&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Sat Jan 17 20:11:23 2015
@@ -593,7 +593,7 @@ bool LoopRotate::rotateLoop(Loop *L, boo
// the OrigHeader block into OrigLatch. This will succeed if they are
// connected by an unconditional branch. This is just a cleanup so the
// emitted code isn't too gross in this common case.
- MergeBlockIntoPredecessor(OrigHeader, this);
+ MergeBlockIntoPredecessor(OrigHeader, DT, LI);
DEBUG(dbgs() << "LoopRotation: into "; L->dump());
Modified: llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp?rev=226392&r1=226391&r2=226392&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/BasicBlockUtils.cpp Sat Jan 17 20:11:23 2015
@@ -107,7 +107,9 @@ bool llvm::DeleteDeadPHIs(BasicBlock *BB
/// MergeBlockIntoPredecessor - Attempts to merge a block into its predecessor,
/// 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.
if (BB->hasAddressTaken()) return false;
@@ -142,11 +144,8 @@ bool llvm::MergeBlockIntoPredecessor(Bas
}
// Begin by getting rid of unneeded PHIs.
- if (isa<PHINode>(BB->front())) {
- auto *AA = P ? P->getAnalysisIfAvailable<AliasAnalysis>() : nullptr;
- auto *MemDep = P ? P->getAnalysisIfAvailable<MemoryDependenceAnalysis>() : nullptr;
+ if (isa<PHINode>(BB->front()))
FoldSingleEntryPHINodes(BB, AA, MemDep);
- }
// Delete the unconditional branch from the predecessor...
PredBB->getInstList().pop_back();
@@ -163,28 +162,23 @@ bool llvm::MergeBlockIntoPredecessor(Bas
PredBB->takeName(BB);
// Finally, erase the old block and update dominator info.
- if (P) {
- if (DominatorTreeWrapperPass *DTWP =
- P->getAnalysisIfAvailable<DominatorTreeWrapperPass>()) {
- DominatorTree &DT = DTWP->getDomTree();
- if (DomTreeNode *DTN = DT.getNode(BB)) {
- DomTreeNode *PredDTN = DT.getNode(PredBB);
- SmallVector<DomTreeNode*, 8> Children(DTN->begin(), DTN->end());
- for (SmallVectorImpl<DomTreeNode *>::iterator DI = Children.begin(),
- DE = Children.end(); DI != DE; ++DI)
- DT.changeImmediateDominator(*DI, PredDTN);
-
- DT.eraseNode(BB);
- }
-
- if (auto *LIWP = P->getAnalysisIfAvailable<LoopInfoWrapperPass>())
- LIWP->getLoopInfo().removeBlock(BB);
-
- if (MemoryDependenceAnalysis *MD =
- P->getAnalysisIfAvailable<MemoryDependenceAnalysis>())
- MD->invalidateCachedPredecessors();
+ if (DT)
+ if (DomTreeNode *DTN = DT->getNode(BB)) {
+ DomTreeNode *PredDTN = DT->getNode(PredBB);
+ SmallVector<DomTreeNode *, 8> Children(DTN->begin(), DTN->end());
+ for (SmallVectorImpl<DomTreeNode *>::iterator DI = Children.begin(),
+ DE = Children.end();
+ DI != DE; ++DI)
+ DT->changeImmediateDominator(*DI, PredDTN);
+
+ DT->eraseNode(BB);
}
- }
+
+ if (LI)
+ LI->removeBlock(BB);
+
+ if (MemDep)
+ MemDep->invalidateCachedPredecessors();
BB->eraseFromParent();
return true;
More information about the llvm-commits
mailing list