summaryrefslogtreecommitdiff
path: root/lib/Analysis/LoopPass.cpp
diff options
context:
space:
mode:
authorDevang Patel <dpatel@apple.com>2007-02-22 23:45:15 +0000
committerDevang Patel <dpatel@apple.com>2007-02-22 23:45:15 +0000
commit643a79b4b32610651fe728ff95c9fecc60eaa687 (patch)
tree7e3bbf4b4d2611b0ef31f826e368d8d9f54b284e /lib/Analysis/LoopPass.cpp
parentd0e6e33043aa8cca678face8dce205155e2a69b3 (diff)
downloadllvm-643a79b4b32610651fe728ff95c9fecc60eaa687.tar.gz
llvm-643a79b4b32610651fe728ff95c9fecc60eaa687.tar.bz2
llvm-643a79b4b32610651fe728ff95c9fecc60eaa687.tar.xz
Populate and walk loop queue.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34505 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/LoopPass.cpp')
-rw-r--r--lib/Analysis/LoopPass.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/Analysis/LoopPass.cpp b/lib/Analysis/LoopPass.cpp
index 2e3df71c87..95a18e5b00 100644
--- a/lib/Analysis/LoopPass.cpp
+++ b/lib/Analysis/LoopPass.cpp
@@ -33,11 +33,11 @@ public:
// Loop queue used by Loop Pass Manager. This is a wrapper class
// that hides implemenation detail (use of priority_queue) inside .cpp file.
class LoopQueue {
-
+public:
inline void push(Loop *L) { LPQ.push(L); }
inline void pop() { LPQ.pop(); }
inline Loop *top() { return LPQ.top(); }
-
+ inline bool empty() { return LPQ.empty(); }
private:
std::priority_queue<Loop *, std::vector<Loop *>, LoopCompare> LPQ;
};
@@ -57,22 +57,33 @@ LPPassManager::~LPPassManager() {
delete LQ;
}
+// Recurse through all subloops and all loops into LQ.
+static void addLoopIntoQueue(Loop *L, LoopQueue *LQ) {
+ for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
+ addLoopIntoQueue(*I, LQ);
+ LQ->push(L);
+}
+
/// run - Execute all of the passes scheduled for execution. Keep track of
/// whether any of the passes modifies the function, and if so, return true.
bool LPPassManager::runOnFunction(Function &F) {
LoopInfo &LI = getAnalysis<LoopInfo>();
bool Changed = false;
+ // Populate Loop Queue
+ for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I)
+ addLoopIntoQueue(*I, LQ);
+
std::string Msg1 = "Executing Pass '";
std::string Msg3 = "' Made Modification '";
// Walk Loops
- for (LoopInfo::iterator I = LI.begin(), E = LI.end(); I != E; ++I) {
-
- Loop *L = *I;
+ while (!LQ->empty()) {
+
+ Loop *L = LQ->top();
// Run all passes on current SCC
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
-
+
Pass *P = getContainedPass(Index);
AnalysisUsage AnUsage;
P->getAnalysisUsage(AnUsage);
@@ -97,6 +108,9 @@ bool LPPassManager::runOnFunction(Function &F) {
recordAvailableAnalysis(P);
removeDeadPasses(P, Msg2);
}
+
+ // Pop the loop from queue after running all passes.
+ LQ->pop();
}
return Changed;