Remove attribution from file headers, per discussion on llvmdev.
[oota-llvm.git] / lib / Analysis / IPA / CallGraphSCCPass.cpp
index 7ec7a87d2ca5edf21cefa7520198811a0ef70723..90e26266f8ba886bbd3b82d3da81995034c545af 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     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 is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -19,6 +19,7 @@
 #include "llvm/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/PassManagers.h"
+#include "llvm/Function.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -29,7 +30,9 @@ using namespace llvm;
 class CGPassManager : public ModulePass, public PMDataManager {
 
 public:
-  CGPassManager(int Depth) : PMDataManager(Depth) { }
+  static char ID;
+  explicit CGPassManager(int Depth) 
+    : ModulePass((intptr_t)&ID), PMDataManager(Depth) { }
 
   /// run - Execute all of the passes scheduled for execution.  Keep track of
   /// whether any of the passes modifies the module, and if so, return true.
@@ -45,6 +48,10 @@ public:
     Info.setPreservesAll();
   }
 
+  virtual const char *getPassName() const {
+    return "CallGraph Pass Manager";
+  }
+
   // Print passes managed by this manager
   void dumpPassStructure(unsigned Offset) {
     llvm::cerr << std::string(Offset*2, ' ') << "Call Graph SCC Pass Manager\n";
@@ -61,61 +68,60 @@ public:
     return FP;
   }
 
-  virtual PassManagerType getPassManagerType() { 
+  virtual PassManagerType getPassManagerType() const 
     return PMT_CallGraphPassManager; 
   }
 };
 
+char CGPassManager::ID = 0;
 /// run - Execute all of the passes scheduled for execution.  Keep track of
 /// whether any of the passes modifies the module, and if so, return true.
 bool CGPassManager::runOnModule(Module &M) {
   CallGraph &CG = getAnalysis<CallGraph>();
   bool Changed = doInitialization(CG);
 
-  std::string Msg1 = "Executing Pass '";
-  std::string Msg3 = "' Made Modification '";
-
   // Walk SCC
   for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
        I != E; ++I) {
 
     // Run all passes on current SCC
-    for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {  
-
+    for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
       Pass *P = getContainedPass(Index);
       AnalysisUsage AnUsage;
       P->getAnalysisUsage(AnUsage);
 
-      std::string Msg2 = "' on Call Graph ...\n'";
-      dumpPassInfo(P, Msg1, Msg2);
+      dumpPassInfo(P, EXECUTION_MSG, ON_CG_MSG, "");
       dumpAnalysisSetInfo("Required", P, AnUsage.getRequiredSet());
 
       initializeAnalysisImpl(P);
 
-      //        if (TheTimeInfo) TheTimeInfo->passStarted(P);
+      StartPassTimer(P);
       if (CallGraphSCCPass *CGSP = dynamic_cast<CallGraphSCCPass *>(P))
-       Changed |= CGSP->runOnSCC(*I);   // TODO : What if CG is changed ?
+        Changed |= CGSP->runOnSCC(*I);   // TODO : What if CG is changed ?
       else {
-       FPPassManager *FPP = dynamic_cast<FPPassManager *>(P);
-       assert (FPP && "Invalid CGPassManager member");
-
-       // Run pass P on all functions current SCC
-       std::vector<CallGraphNode*> &SCC = *I;
-       for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
-         Function *F = SCC[i]->getFunction();
-         if (F) 
-           Changed |= FPP->runOnFunction(*F);
-       }
+        FPPassManager *FPP = dynamic_cast<FPPassManager *>(P);
+        assert (FPP && "Invalid CGPassManager member");
+
+        // Run pass P on all functions current SCC
+        std::vector<CallGraphNode*> &SCC = *I;
+        for (unsigned i = 0, e = SCC.size(); i != e; ++i) {
+          Function *F = SCC[i]->getFunction();
+          if (F) {
+            dumpPassInfo(P, EXECUTION_MSG, ON_FUNCTION_MSG, F->getNameStart());
+            Changed |= FPP->runOnFunction(*F);
+          }
+        }
       }
-      //        if (TheTimeInfo) TheTimeInfo->passEnded(MP);
+      StopPassTimer(P);
 
       if (Changed)
-       dumpPassInfo(P, Msg3, Msg2);
+        dumpPassInfo(P, MODIFICATION_MSG, ON_CG_MSG, "");
       dumpAnalysisSetInfo("Preserved", P, AnUsage.getPreservedSet());
-      
+
+      verifyPreservedAnalysis(P);      
       removeNotPreservedAnalysis(P);
       recordAvailableAnalysis(P);
-      removeDeadPasses(P, Msg2);
+      removeDeadPasses(P, "", ON_CG_MSG);
     }
   }
   Changed |= doFinalization(CG);
@@ -144,6 +150,41 @@ bool CGPassManager::doFinalization(CallGraph &CG) {
   return Changed;
 }
 
+/// Assign pass manager to manage this pass.
+void CallGraphSCCPass::assignPassManager(PMStack &PMS,
+                                         PassManagerType PreferredType) {
+  // Find CGPassManager 
+  while (!PMS.empty() &&
+         PMS.top()->getPassManagerType() > PMT_CallGraphPassManager)
+    PMS.pop();
+
+  CGPassManager *CGP = dynamic_cast<CGPassManager *>(PMS.top());
+
+  // Create new Call Graph SCC Pass Manager if it does not exist. 
+  if (!CGP) {
+
+    assert (!PMS.empty() && "Unable to create Call Graph Pass Manager");
+    PMDataManager *PMD = PMS.top();
+
+    // [1] Create new Call Graph Pass Manager
+    CGP = new CGPassManager(PMD->getDepth() + 1);
+
+    // [2] Set up new manager's top level manager
+    PMTopLevelManager *TPM = PMD->getTopLevelManager();
+    TPM->addIndirectPassManager(CGP);
+
+    // [3] Assign manager to manage this new manager. This may create
+    // and push new managers into PMS
+    Pass *P = dynamic_cast<Pass *>(CGP);
+    TPM->schedulePass(P);
+
+    // [4] Push new manager into PMS
+    PMS.push(CGP);
+  }
+
+  CGP->add(this);
+}
+
 /// getAnalysisUsage - For this class, we declare that we require and preserve
 /// the call graph.  If the derived class implements this method, it should
 /// always explicitly call the implementation here.
@@ -151,12 +192,3 @@ void CallGraphSCCPass::getAnalysisUsage(AnalysisUsage &AU) const {
   AU.addRequired<CallGraph>();
   AU.addPreserved<CallGraph>();
 }
-
-bool CallGraphSCCPass::runOnModule(Module &M) {
-  CallGraph &CG = getAnalysis<CallGraph>();
-  bool Changed = doInitialization(CG);
-  for (scc_iterator<CallGraph*> I = scc_begin(&CG), E = scc_end(&CG);
-       I != E; ++I)
-    Changed = runOnSCC(*I);
-  return Changed | doFinalization(CG);
-}