aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Analysis/LoopPass.h9
-rw-r--r--lib/Analysis/LoopPass.cpp20
2 files changed, 29 insertions, 0 deletions
diff --git a/include/llvm/Analysis/LoopPass.h b/include/llvm/Analysis/LoopPass.h
index cf5611beb5..4f449952d9 100644
--- a/include/llvm/Analysis/LoopPass.h
+++ b/include/llvm/Analysis/LoopPass.h
@@ -36,6 +36,15 @@ class LoopPass : public Pass {
return false;
}
+ // Initialization and finalization hooks.
+ virtual bool doInitialization(Loop *L, LPPassManager &LPM) {
+ return false;
+ }
+
+ // Finalization hook does not supply Loop because at this time
+ // loop nest is completely different.
+ virtual bool doFinalization() { return false; }
+
/// Assign pass manager to manager this pass
virtual void assignPassManager(PMStack &PMS,
PassManagerType PMT = PMT_LoopPassManager);
diff --git a/lib/Analysis/LoopPass.cpp b/lib/Analysis/LoopPass.cpp
index fe1672a403..8d613b09f4 100644
--- a/lib/Analysis/LoopPass.cpp
+++ b/lib/Analysis/LoopPass.cpp
@@ -57,6 +57,18 @@ bool LPPassManager::runOnFunction(Function &F) {
for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
addLoopIntoQueue(*I, LQ);
+ // Initialization
+ for (std::deque<Loop *>::const_iterator I = LQ.begin(), E = LQ.end();
+ I != E; ++I) {
+ Loop *L = *I;
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
+ Pass *P = getContainedPass(Index);
+ LoopPass *LP = dynamic_cast<LoopPass *>(P);
+ if (LP)
+ Changed |= LP->doInitialization(L, *this);
+ }
+ }
+
// Walk Loops
while (!LQ.empty()) {
@@ -101,6 +113,14 @@ bool LPPassManager::runOnFunction(Function &F) {
if (redoThisLoop)
LQ.push_back(L);
}
+
+ // Finalization
+ for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
+ Pass *P = getContainedPass(Index);
+ LoopPass *LP = dynamic_cast <LoopPass *>(P);
+ if (LP)
+ Changed |= LP->doFinalization();
+ }
return Changed;
}