-//===- 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
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
}
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> &);
};
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
E = LastUseOf.end(); I != E; ++I)
LastUserOf[I->second].push_back(I->first);
-
// Output debug information...
if (Parent == 0) PMDebug::PerformPassStartupStuff(this);
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;
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());
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();
}
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
// 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
// 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.
// 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;
// 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;
//
// 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;
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);
}
};
return Changed;
}
+} // End llvm namespace
+
#endif