LPPassManager. Implement preparePassManager() hook.
authorDevang Patel <dpatel@apple.com>
Tue, 6 Mar 2007 17:59:37 +0000 (17:59 +0000)
committerDevang Patel <dpatel@apple.com>
Tue, 6 Mar 2007 17:59:37 +0000 (17:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34975 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4f449952d9449f28c27c6f05ad889a230d50eb4d..d04287d1ba1e8e8526f988ada42fa4d8a3ba2c43 100644 (file)
@@ -44,7 +44,15 @@ class LoopPass : public Pass {
   // Finalization hook does not supply Loop because at this time
   // loop nest is completely different.
   virtual bool doFinalization() { return false; }
+
+  // Check if this pass is suitable for the current LPPassManager, if
+  // available. This pass P is not suitable for a LPPassManager if P
+  // is not preserving higher level analysis info used by other
+  // LPPassManager passes. In such case, pop LPPassManager from the
+  // stack. This will force assignPassManager() to create new
+  // LPPassManger as expected.
+  void preparePassManager(PMStack &PMS);
+
   /// Assign pass manager to manager this pass
   virtual void assignPassManager(PMStack &PMS,
                                 PassManagerType PMT = PMT_LoopPassManager);
index 8d613b09f4234b2cd9955b4e9db212f4fe4ff133..de062baec8ef351cd1d548e7b21f62d6e73ab4e8 100644 (file)
@@ -129,6 +129,31 @@ bool LPPassManager::runOnFunction(Function &F) {
 //===----------------------------------------------------------------------===//
 // LoopPass
 
+// Check if this pass is suitable for the current LPPassManager, if
+// available. This pass P is not suitable for a LPPassManager if P
+// is not preserving higher level analysis info used by other
+// LPPassManager passes. In such case, pop LPPassManager from the
+// stack. This will force assignPassManager() to create new
+// LPPassManger as expected.
+void LoopPass::preparePassManager(PMStack &PMS) {
+
+  // Find LPPassManager 
+  while (!PMS.empty()) {
+    if (PMS.top()->getPassManagerType() > PMT_LoopPassManager)
+      PMS.pop();
+    else;
+    break;
+  }
+
+  LPPassManager *LPPM = dynamic_cast<LPPassManager *>(PMS.top());
+
+  // If this pass is destroying high level information that is used
+  // by other passes that are managed by LPM then do not insert
+  // this pass in current LPM. Use new LPPassManager.
+  if (LPPM && !LPPM->preserveHigherLevelAnalysis(this)) 
+    PMS.pop();
+}
+
 /// Assign pass manager to manage this pass.
 void LoopPass::assignPassManager(PMStack &PMS,
                                  PassManagerType PreferredType) {