Teach LoopPass to assign itself one Loop Pass Manager.
authorDevang Patel <dpatel@apple.com>
Fri, 23 Feb 2007 00:36:57 +0000 (00:36 +0000)
committerDevang Patel <dpatel@apple.com>
Fri, 23 Feb 2007 00:36:57 +0000 (00:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34510 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/LoopPass.h
lib/Analysis/LoopPass.cpp

index b3d4c6e89721017734220b172c7ffd2139a45e05..2fd14f2dad4a1ecf26bb34256c4e7e73c6257af3 100644 (file)
@@ -37,6 +37,10 @@ class LoopPass : public Pass {
     return false; 
   }
 
+  /// Assign pass manager to manager this pass
+  virtual void assignPassManager(PMStack &PMS,
+                                PassManagerType PMT = PMT_LoopPassManager);
+
 };
 
 class LPPassManager : public FunctionPass, public PMDataManager {
index dc5c5683fb218d72b844796b5080f4b4aff7bbb8..425e46e6e0b736f81a7f3db7360ffb074b7d3d13 100644 (file)
@@ -143,3 +143,44 @@ bool LPPassManager::runOnFunction(Function &F) {
 }
 
 
+//===----------------------------------------------------------------------===//
+// LoopPass
+
+/// Assign pass manager to manage this pass.
+void LoopPass::assignPassManager(PMStack &PMS,
+                                 PassManagerType PreferredType) {
+  // Find LPPassManager 
+  while (!PMS.empty()) {
+    if (PMS.top()->getPassManagerType() > PMT_LoopPassManager)
+      PMS.pop();
+    else;
+    break;
+  }
+
+  LPPassManager *LPPM = dynamic_cast<LPPassManager *>(PMS.top());
+
+  // Create new Loop Pass Manager if it does not exist. 
+  if (!LPPM) {
+
+    assert (!PMS.empty() && "Unable to create Loop Pass Manager");
+    PMDataManager *PMD = PMS.top();
+
+    // [1] Create new Call Graph Pass Manager
+    LPPM = new LPPassManager(PMD->getDepth() + 1);
+
+    // [2] Set up new manager's top level manager
+    PMTopLevelManager *TPM = PMD->getTopLevelManager();
+    TPM->addIndirectPassManager(LPPM);
+
+    // [3] Assign manager to manage this new manager. This may create
+    // and push new managers into PMS
+    Pass *P = dynamic_cast<Pass *>(LPPM);
+    P->assignPassManager(PMS);
+
+    // [4] Push new manager into PMS
+    PMS.push(LPPM);
+  }
+
+  LPPM->add(this);
+}
+