Transform BU pass to not use the horrible DSCallSiteIterator class.
[oota-llvm.git] / lib / VMCore / PassManagerT.h
index 370aa4c42ed017b05cf4c23f7e030929bd055512..8b3425adc3bd2f75e3b035c07860bd67d7e9778e 100644 (file)
@@ -1,4 +1,11 @@
-//===- PassManagerT.h - Container for Passes ------------------------------===//
+//===- PassManagerT.h - Container for Passes --------------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This file defines the PassManagerT class.  This class is used to hold,
 // maintain, and optimize execution of Pass's.  The PassManager class ensures
 #define LLVM_PASSMANAGER_T_H
 
 #include "llvm/Pass.h"
-#include "Support/CommandLine.h"
-#include "Support/LeakDetector.h"
-#include "Support/Timer.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/LeakDetector.h"
+#include "llvm/Support/Timer.h"
 #include <algorithm>
 #include <iostream>
-class Annotable;
+
+namespace llvm {
 
 //===----------------------------------------------------------------------===//
 // Pass debugging information.  Often it is useful to find out what pass is
@@ -44,7 +52,7 @@ PassDebugging("debug-pass", cl::Hidden,
   clEnumVal(Structure , "print pass structure before run()"),
   clEnumVal(Executions, "print pass name before it is executed"),
   clEnumVal(Details   , "print pass details when it is executed"),
-                         0));
+                         clEnumValEnd));
 
 //===----------------------------------------------------------------------===//
 // PMDebug class - a set of debugging functions, that are not to be
@@ -65,7 +73,9 @@ struct PMDebug {
   }
 
   static void PrintArgumentInformation(const Pass *P);
-  static void PrintPassInformation(unsigned,const char*,Pass *, Annotable *);
+  static void PrintPassInformation(unsigned,const char*,Pass *, Module *);
+  static void PrintPassInformation(unsigned,const char*,Pass *, Function *);
+  static void PrintPassInformation(unsigned,const char*,Pass *, BasicBlock *);
   static void PrintAnalysisSetInfo(unsigned,const char*,Pass *P,
                                    const std::vector<AnalysisID> &);
 };
@@ -132,9 +142,14 @@ class PassManagerT : public PassManagerTraits<UnitType>,public AnalysisResolver{
   typedef typename Traits::BatcherClass BatcherClass;
   typedef typename Traits::ParentClass   ParentClass;
 
+#if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__HP_aCC)
+  friend PassClass;
+  friend SubPassClass;
+#else
   friend class PassManagerTraits<UnitType>::PassClass;
   friend class PassManagerTraits<UnitType>::SubPassClass;  
-  friend class Traits;
+#endif
+  friend class PassManagerTraits<UnitType>;
   friend class ImmutablePass;
 
   std::vector<PassClass*> Passes;    // List of passes to run
@@ -198,7 +213,6 @@ public:
                                           E = LastUseOf.end(); I != E; ++I)
       LastUserOf[I->second].push_back(I->first);
 
-
     // Output debug information...
     if (Parent == 0) PMDebug::PerformPassStartupStuff(this);
 
@@ -206,8 +220,7 @@ public:
     for (unsigned i = 0, e = Passes.size(); i < e; ++i) {
       PassClass *P = Passes[i];
       
-      PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P,
-                                    (Annotable*)M);
+      PMDebug::PrintPassInformation(getDepth(), "Executing Pass", P, M);
 
       // Get information about what analyses the pass uses...
       AnalysisUsage AnUsage;
@@ -249,8 +262,7 @@ public:
                                     P->getPassName() + "'");
 
       if (Changed)
-        PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P,
-                                      (Annotable*)M);
+        PMDebug::PrintPassInformation(getDepth()+1, "Made Modification", P, M);
       PMDebug::PrintAnalysisSetInfo(getDepth(), "Preserved", P,
                                     AnUsage.getPreservedSet());
 
@@ -291,8 +303,7 @@ public:
       std::vector<Pass*> &DeadPass = LastUserOf[P];
       for (std::vector<Pass*>::iterator I = DeadPass.begin(),E = DeadPass.end();
            I != E; ++I) {
-        PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I,
-                                      (Annotable*)M);
+        PMDebug::PrintPassInformation(getDepth()+1, "Freeing Pass", *I, M);
         (*I)->releaseMemory();
       }
 
@@ -390,6 +401,16 @@ public:
 
     if (I != CurrentAnalyses.end()) {
       LastUseOf[I->second] = User;    // Local pass, extend the lifetime
+
+      // Prolong live range of analyses that are needed after an analysis pass
+      // is destroyed, for querying by subsequent passes
+      AnalysisUsage AnUsage;
+      I->second->getAnalysisUsage(AnUsage);
+      const std::vector<AnalysisID> &IDs = AnUsage.getRequiredTransitiveSet();
+      for (std::vector<AnalysisID>::const_iterator i = IDs.begin(),
+             e = IDs.end(); i != e; ++i)
+        markPassUsed(*i, User);
+
     } else {
       // Pass not in current available set, must be a higher level pass
       // available to us, propagate to parent pass manager...  We tell the
@@ -433,8 +454,12 @@ public:
     // Loop over all of the analyses used by this pass,
     for (std::vector<AnalysisID>::const_iterator I = Required.begin(),
            E = Required.end(); I != E; ++I) {
-      if (getAnalysisOrNullDown(*I) == 0)
-        add((PassClass*)(*I)->createPass());
+      if (getAnalysisOrNullDown(*I) == 0) {
+        Pass *AP = (*I)->createPass();
+        if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (AP)) { add(IP); }
+        else if (PassClass *RP = dynamic_cast<PassClass *> (AP)) { add(RP); }
+        else { assert (0 && "Wrong kind of pass for this PassManager"); }
+      }
     }
 
     // Tell the pass to add itself to this PassManager... the way it does so
@@ -456,8 +481,12 @@ public:
     // Loop over all of the analyses used by this pass,
     for (std::vector<AnalysisID>::const_iterator I = Required.begin(),
            E = Required.end(); I != E; ++I) {
-      if (getAnalysisOrNullDown(*I) == 0)
-        add((PassClass*)(*I)->createPass());
+      if (getAnalysisOrNullDown(*I) == 0) {
+        Pass *AP = (*I)->createPass();
+        if (ImmutablePass *IP = dynamic_cast<ImmutablePass *> (AP)) add(IP);
+        else if (PassClass *RP = dynamic_cast<PassClass *> (AP)) add(RP);
+        else assert (0 && "Wrong kind of pass for this PassManager");
+      }
     }
 
     // Add the ImmutablePass to this PassManager.
@@ -601,7 +630,8 @@ public:
 // This pass manager is used to group together all of the BasicBlockPass's
 // into a single unit.
 //
-template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
+template<> class PassManagerTraits<BasicBlock> : public BasicBlockPass {
+public:
   // PassClass - The type of passes tracked by this PassManager
   typedef BasicBlockPass PassClass;
 
@@ -654,7 +684,8 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
 // This pass manager is used to group together all of the FunctionPass's
 // into a single unit.
 //
-template<> struct PassManagerTraits<Function> : public FunctionPass {
+template<> class PassManagerTraits<Function> : public FunctionPass {
+public:
   // PassClass - The type of passes tracked by this PassManager
   typedef FunctionPass PassClass;
 
@@ -697,9 +728,10 @@ template<> struct PassManagerTraits<Function> : public FunctionPass {
 //
 // This is the top level PassManager implementation that holds generic passes.
 //
-template<> struct PassManagerTraits<Module> : public Pass {
+template<> class PassManagerTraits<Module> : public ModulePass {
+public:
   // PassClass - The type of passes tracked by this PassManager
-  typedef Pass PassClass;
+  typedef ModulePass PassClass;
 
   // SubPassClass - The types of classes that should be collated together
   typedef FunctionPass SubPassClass;
@@ -711,15 +743,15 @@ template<> struct PassManagerTraits<Module> : public Pass {
   typedef AnalysisResolver ParentClass;
 
   // runPass - Specify how the pass should be run on the UnitType
-  static bool runPass(PassClass *P, Module *M) { return P->run(*M); }
+  static bool runPass(PassClass *P, Module *M) { return P->runOnModule(*M); }
 
   // getPMName() - Return the name of the unit the PassManager operates on for
   // debugging.
   const char *getPMName() const { return "Module"; }
   virtual const char *getPassName() const { return "Module Pass Manager"; }
 
-  // run - Implement the PassManager interface...
-  bool run(Module &M) {
+  // runOnModule - Implement the PassManager interface.
+  bool runOnModule(Module &M) {
     return ((PassManagerT<Module>*)this)->runOnUnit(&M);
   }
 };
@@ -785,4 +817,6 @@ inline bool PassManagerTraits<Function>::doFinalization(Module &M) {
   return Changed;
 }
 
+} // End llvm namespace
+
 #endif