[llvm-commits] CVS: llvm/lib/VMCore/Pass.cpp PassManagerT.h

Chris Lattner lattner at cs.uiuc.edu
Wed Sep 25 16:59:03 PDT 2002


Changes in directory llvm/lib/VMCore:

Pass.cpp updated: 1.37 -> 1.38
PassManagerT.h updated: 1.27 -> 1.28

---
Log message:

Add support for ImmutablePasses, which are not run, and cannot be
invalidated.


---
Diffs of the changes:

Index: llvm/lib/VMCore/Pass.cpp
diff -u llvm/lib/VMCore/Pass.cpp:1.37 llvm/lib/VMCore/Pass.cpp:1.38
--- llvm/lib/VMCore/Pass.cpp:1.37	Fri Sep 13 09:47:12 2002
+++ llvm/lib/VMCore/Pass.cpp	Wed Sep 25 16:59:11 2002
@@ -299,6 +299,15 @@
 }
 
 //===----------------------------------------------------------------------===//
+// ImmutablePass Implementation
+//
+void ImmutablePass::addToPassManager(PassManagerT<Module> *PM,
+                                     AnalysisUsage &AU) {
+  PM->addPass(this, AU);
+}
+
+
+//===----------------------------------------------------------------------===//
 // FunctionPass Implementation
 //
 


Index: llvm/lib/VMCore/PassManagerT.h
diff -u llvm/lib/VMCore/PassManagerT.h:1.27 llvm/lib/VMCore/PassManagerT.h:1.28
--- llvm/lib/VMCore/PassManagerT.h:1.27	Thu Sep 12 12:06:40 2002
+++ llvm/lib/VMCore/PassManagerT.h	Wed Sep 25 16:59:11 2002
@@ -129,8 +129,10 @@
   friend typename Traits::PassClass;
   friend typename Traits::SubPassClass;  
   friend class Traits;
+  friend class ImmutablePass;
 
   std::vector<PassClass*> Passes;    // List of passes to run
+  std::vector<ImmutablePass*> ImmutablePasses;  // List of immutable passes
 
   // The parent of this pass manager...
   ParentClass * const Parent;
@@ -157,6 +159,10 @@
     for (typename std::vector<PassClass*>::iterator
            I = Passes.begin(), E = Passes.end(); I != E; ++I)
       delete *I;
+
+    for (std::vector<ImmutablePass*>::iterator
+           I = ImmutablePasses.begin(), E = ImmutablePasses.end(); I != E; ++I)
+      delete *I;
   }
 
   // run - Run all of the queued passes on the specified module in an optimal
@@ -166,6 +172,17 @@
     closeBatcher();
     CurrentAnalyses.clear();
 
+    // Add any immutable passes to the CurrentAnalyses set...
+    for (unsigned i = 0, e = ImmutablePasses.size(); i != e; ++i)
+      if (const PassInfo *PI = ImmutablePasses[i]->getPassInfo()) {
+        CurrentAnalyses[PI] = ImmutablePasses[i];
+
+        const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
+        for (unsigned i = 0, e = II.size(); i != e; ++i)
+          CurrentAnalyses[II[i]] = ImmutablePasses[i];
+      }
+
+
     // LastUserOf - This contains the inverted LastUseOfMap...
     std::map<Pass *, std::vector<Pass*> > LastUserOf;
     for (std::map<Pass*, Pass*>::iterator I = LastUseOf.begin(),
@@ -238,13 +255,17 @@
               PreservedSet.end())
             ++I; // This analysis is preserved, leave it in the available set...
           else {
+            if (!dynamic_cast<ImmutablePass*>(I->second)) {
 #if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
-            I = CurrentAnalyses.erase(I);   // Analysis not preserved!
+              I = CurrentAnalyses.erase(I);   // Analysis not preserved!
 #else
-            // GCC 2.95.3 STL doesn't have correct erase member!
-            CurrentAnalyses.erase(I);
-            I = CurrentAnalyses.begin();
+              // GCC 2.95.3 STL doesn't have correct erase member!
+              CurrentAnalyses.erase(I);
+              I = CurrentAnalyses.begin();
 #endif
+            } else {
+              ++I;
+            }
           }
       }
 
@@ -345,11 +366,15 @@
       // parent that we (the passmanager) are using the analysis so that it
       // frees the analysis AFTER this pass manager runs.
       //
-      assert(Parent != 0 && "Pass available but not found!");
-      Parent->markPassUsed(P, this);
+      if (Parent) {
+        Parent->markPassUsed(P, this);
+      } else {
+        assert(0 && "Pass available but not found! "
+               "Perhaps this is a module pass requiring a function pass?");
+      }
     }
   }
-
+  
   // Return the number of parent PassManagers that exist
   virtual unsigned getDepth() const {
     if (Parent == 0) return 0;
@@ -428,18 +453,15 @@
     if (!AnUsage.preservesAll()) {
       const std::vector<AnalysisID> &PreservedSet = AnUsage.getPreservedSet();
       for (std::map<AnalysisID, Pass*>::iterator I = CurrentAnalyses.begin(),
-             E = CurrentAnalyses.end(); I != E; )
-        if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) !=
-            PreservedSet.end())
-          ++I;  // This analysis is preserved, leave it in the available set...
-        else {
-#if MAP_DOESNT_HAVE_BROKEN_ERASE_MEMBER
-          I = CurrentAnalyses.erase(I);   // Analysis not preserved!
-#else
-          CurrentAnalyses.erase(I);// GCC 2.95.3 STL doesn't have correct erase!
+             E = CurrentAnalyses.end(); I != E; ) {
+        if (std::find(PreservedSet.begin(), PreservedSet.end(), I->first) ==
+            PreservedSet.end()) {             // Analysis not preserved!
+          CurrentAnalyses.erase(I);           // Remove from available analyses
           I = CurrentAnalyses.begin();
-#endif
+        } else {
+          ++I;
         }
+      }
     }
 
     // Add this pass to the currently available set...
@@ -474,6 +496,34 @@
     if (Batcher) {
       Passes.push_back(Batcher);
       Batcher = 0;
+    }
+  }
+
+public:
+  // When an ImmutablePass is added, it gets added to the top level pass
+  // manager.
+  void addPass(ImmutablePass *IP, AnalysisUsage &AU) {
+    if (Parent) { // Make sure this request goes to the top level passmanager...
+      Parent->addPass(IP, AU);
+      return;
+    }
+
+    // Set the Resolver instance variable in the Pass so that it knows where to 
+    // find this object...
+    //
+    setAnalysisResolver(IP, this);
+    ImmutablePasses.push_back(IP);
+    
+    // Add this pass to the currently available set...
+    if (const PassInfo *PI = IP->getPassInfo()) {
+      CurrentAnalyses[PI] = IP;
+
+      // This pass is the current implementation of all of the interfaces it
+      // implements as well.
+      //
+      const std::vector<const PassInfo*> &II = PI->getInterfacesImplemented();
+      for (unsigned i = 0, e = II.size(); i != e; ++i)
+        CurrentAnalyses[II[i]] = IP;
     }
   }
 };





More information about the llvm-commits mailing list