Rework dominator interfaces to handle changes in the post-dominance
[oota-llvm.git] / lib / VMCore / Pass.cpp
index 0be92e9f551d0c9bcb2359c52e2a895abf2d4d6d..ccb0ef90d195bf198c6faf827b0bebdf04326ef9 100644 (file)
 #include "llvm/Module.h"
 #include "Support/STLExtras.h"
 #include "Support/TypeInfo.h"
-#include <stdio.h>
-#include <sys/resource.h>
-#include <sys/time.h>
-#include <sys/unistd.h>
+#include "Config/stdio.h"
+#include "Config/sys/resource.h"
+#include "Config/sys/time.h"
+#include "Config/unistd.h"
 #include <set>
 
 // IncludeFile - Stub function used to help linking out.
@@ -43,7 +43,7 @@ void AnalysisResolver::setAnalysisResolver(Pass *P, AnalysisResolver *AR) {
 //   AnalysisUsage Class Implementation
 //
 
-// preservesCFG - This function should be called to by the pass, iff they do
+// setPreservesCFG - This function should be called to by the pass, iff they do
 // not:
 //
 //  1. Add or remove basic blocks from the function
@@ -52,7 +52,7 @@ void AnalysisResolver::setAnalysisResolver(Pass *P, AnalysisResolver *AR) {
 // This function annotates the AnalysisUsage info object to say that analyses
 // that only depend on the CFG are preserved by this pass.
 //
-void AnalysisUsage::preservesCFG() {
+void AnalysisUsage::setPreservesCFG() {
   // Since this transformation doesn't modify the CFG, it preserves all analyses
   // that only depend on the CFG (like dominators, loop info, etc...)
   //
@@ -70,6 +70,17 @@ PassManager::~PassManager() { delete PM; }
 void PassManager::add(Pass *P) { PM->add(P); }
 bool PassManager::run(Module &M) { return PM->run(M); }
 
+//===----------------------------------------------------------------------===//
+// FunctionPassManager implementation - The FunctionPassManager class
+// is a simple Pimpl class that wraps the PassManagerT template. It
+// is like PassManager, but only deals in FunctionPasses.
+//
+FunctionPassManager::FunctionPassManager() : PM(new PassManagerT<Function>()) {}
+FunctionPassManager::~FunctionPassManager() { delete PM; }
+void FunctionPassManager::add(FunctionPass *P) { PM->add(P); }
+void FunctionPassManager::add(ImmutablePass *IP) { PM->add(IP); }
+bool FunctionPassManager::run(Function &F) { return PM->run(F); }
+
 
 //===----------------------------------------------------------------------===//
 // TimingInfo Class - This class is used to calculate information about the
@@ -80,11 +91,17 @@ static cl::opt<bool>
 EnableTiming("time-passes",
             cl::desc("Time each pass, printing elapsed time for each on exit"));
 
-// Create method.  If Timing is enabled, this creates and returns a new timing
-// object, otherwise it returns null.
-//
-TimingInfo *TimingInfo::create() {
-  return EnableTiming ? new TimingInfo() : 0;
+// createTheTimeInfo - This method either initializes the TheTimeInfo pointer to
+// a non null value (if the -time-passes option is enabled) or it leaves it
+// null.  It may be called multiple times.
+void TimingInfo::createTheTimeInfo() {
+  if (!EnableTiming || TheTimeInfo) return;
+
+  // Constructed the first time this is called, iff -time-passes is enabled.
+  // This guarantees that the object will be constructed before static globals,
+  // thus it will be destroyed before them.
+  static TimingInfo TTI;
+  TheTimeInfo = &TTI;
 }
 
 void PMDebug::PrintArgumentInformation(const Pass *P) {
@@ -142,6 +159,10 @@ void Pass::addToPassManager(PassManagerT<Module> *PM, AnalysisUsage &AU) {
   PM->addPass(this, AU);
 }
 
+bool Pass::mustPreserveAnalysisID(const PassInfo *AnalysisID) const {
+  return Resolver->getAnalysisToUpdate(AnalysisID) != 0;
+}
+
 // dumpPassStructure - Implement the -debug-passes=Structure option
 void Pass::dumpPassStructure(unsigned Offset) {
   std::cerr << std::string(Offset*2, ' ') << getPassName() << "\n";
@@ -156,7 +177,7 @@ const char *Pass::getPassName() const {
 }
 
 // print - Print out the internal state of the pass.  This is called by Analyse
-// to print out the contents of an analysis.  Otherwise it is not neccesary to
+// to print out the contents of an analysis.  Otherwise it is not necessary to
 // implement this method.
 //
 void Pass::print(std::ostream &O) const {