Fix bug where we didn't initialize and finalize basic block passes
authorChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2002 00:40:44 +0000 (00:40 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 31 Jan 2002 00:40:44 +0000 (00:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1599 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/PassManagerT.h

index 07bf738fcdc0dffeca09c3b13d39d8800fa020d6..70f2cde66ea2707f394ed5438e01b9576ac48db6 100644 (file)
@@ -150,7 +150,7 @@ public:
     for (std::vector<AnalysisID>::iterator I = Required.begin(),
                                            E = Required.end(); I != E; ++I) {
       if (getAnalysisOrNullDown(*I) == 0)
-        add(I->createPass());
+        add((PassClass*)I->createPass());
     }
 
     // Tell the pass to add itself to this PassManager... the way it does so
@@ -282,14 +282,19 @@ template<> struct PassManagerTraits<BasicBlock> : public BasicBlockPass {
   // ParentClass - The type of the parent PassManager...
   typedef PassManagerT<Method> ParentClass;
 
+  // PMType - The type of the passmanager that subclasses this class
+  typedef PassManagerT<BasicBlock> PMType;
+
   // runPass - Specify how the pass should be run on the UnitType
   static bool runPass(PassClass *P, BasicBlock *M) {
     // todo, init and finalize
     return P->runOnBasicBlock(M);
   }
 
-  // run - Implement the Pass interface...
+  // Implement the BasicBlockPass interface...
+  virtual bool doInitialization(Module *M);
   virtual bool runOnBasicBlock(BasicBlock *BB);
+  virtual bool doFinalization(Module *M);
 };
 
 
@@ -364,8 +369,22 @@ template<> struct PassManagerTraits<Module> : public Pass {
 
 // PassManagerTraits<BasicBlock> Implementations
 //
+inline bool PassManagerTraits<BasicBlock>::doInitialization(Module *M) {
+  bool Changed = false;
+  for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
+    ((PMType*)this)->Passes[i]->doInitialization(M);
+  return Changed;
+}
+
 inline bool PassManagerTraits<BasicBlock>::runOnBasicBlock(BasicBlock *BB) {
-  return ((PassManagerT<BasicBlock>*)this)->runOnUnit(BB);
+  return ((PMType*)this)->runOnUnit(BB);
+}
+
+inline bool PassManagerTraits<BasicBlock>::doFinalization(Module *M) {
+  bool Changed = false;
+  for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)
+    ((PMType*)this)->Passes[i]->doFinalization(M);
+  return Changed;
 }
 
 
@@ -382,9 +401,6 @@ inline bool PassManagerTraits<Method>::runOnMethod(Method *M) {
   return ((PMType*)this)->runOnUnit(M);
 }
 
-
-// PassManagerTraits<Module> Implementations
-//
 inline bool PassManagerTraits<Method>::doFinalization(Module *M) {
   bool Changed = false;
   for (unsigned i = 0, e = ((PMType*)this)->Passes.size(); i != e; ++i)