Skip to content

Commit

Permalink
Get rid of static constructors for pass registration. Instead, every …
Browse files Browse the repository at this point in the history
…pass exposes an initializeMyPassFunction(), which

must be called in the pass's constructor.  This function uses static dependency declarations to recursively initialize
the pass's dependencies.

Clients that only create passes through the createFooPass() APIs will require no changes.  Clients that want to use the
CommandLine options for passes will need to manually call the appropriate initialization functions in PassInitialization.h
before parsing commandline arguments.

I have tested this with all standard configurations of clang and llvm-gcc on Darwin.  It is possible that there are problems
with the static dependencies that will only be visible with non-standard options.  If you encounter any crash in pass
registration/creation, please send the testcase to me directly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116820 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Oct 19, 2010
1 parent 9869413 commit 081c34b
Show file tree
Hide file tree
Showing 140 changed files with 561 additions and 177 deletions.
5 changes: 4 additions & 1 deletion include/llvm/Analysis/Dominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ class DominatorTree : public FunctionPass {
DominatorTreeBase<BasicBlock>* DT;

DominatorTree() : FunctionPass(ID) {
initializeDominatorTreePass(*PassRegistry::getPassRegistry());
DT = new DominatorTreeBase<BasicBlock>(false);
}

Expand Down Expand Up @@ -1028,7 +1029,9 @@ class DominanceFrontier : public DominanceFrontierBase {
public:
static char ID; // Pass ID, replacement for typeid
DominanceFrontier() :
DominanceFrontierBase(ID, false) {}
DominanceFrontierBase(ID, false) {
initializeDominanceFrontierPass(*PassRegistry::getPassRegistry());
}

BasicBlock *getRoot() const {
assert(Roots.size() == 1 && "Should always have entry node!");
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Analysis/FindUsedTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class FindUsedTypes : public ModulePass {
std::set<const Type *> UsedTypes;
public:
static char ID; // Pass identification, replacement for typeid
FindUsedTypes() : ModulePass(ID) {}
FindUsedTypes() : ModulePass(ID) {
initializeFindUsedTypesPass(*PassRegistry::getPassRegistry());
}

/// getTypes - After the pass has been run, return the set containing all of
/// the types used in the module.
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Analysis/IntervalPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class IntervalPartition : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid

IntervalPartition() : FunctionPass(ID), RootInterval(0) {}
IntervalPartition() : FunctionPass(ID), RootInterval(0) {
initializeIntervalPartitionPass(*PassRegistry::getPassRegistry());
}

// run - Calculate the interval partition for this function
virtual bool runOnFunction(Function &F);
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Analysis/LazyValueInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class LazyValueInfo : public FunctionPass {
void operator=(const LazyValueInfo&); // DO NOT IMPLEMENT.
public:
static char ID;
LazyValueInfo() : FunctionPass(ID), PImpl(0) {}
LazyValueInfo() : FunctionPass(ID), PImpl(0) {
initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
}
~LazyValueInfo() { assert(PImpl == 0 && "releaseMemory not called"); }

/// Tristate - This is used to return true/false/dunno results.
Expand Down
6 changes: 4 additions & 2 deletions include/llvm/Analysis/LibCallAliasAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ namespace llvm {
LibCallInfo *LCI;

explicit LibCallAliasAnalysis(LibCallInfo *LC = 0)
: FunctionPass(ID), LCI(LC) {
: FunctionPass(ID), LCI(LC) {
initializeLibCallAliasAnalysisPass(*PassRegistry::getPassRegistry());
}
explicit LibCallAliasAnalysis(char &ID, LibCallInfo *LC)
: FunctionPass(ID), LCI(LC) {
: FunctionPass(ID), LCI(LC) {
initializeLibCallAliasAnalysisPass(*PassRegistry::getPassRegistry());
}
~LibCallAliasAnalysis();

Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Analysis/LoopDependenceAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ class LoopDependenceAnalysis : public LoopPass {

public:
static char ID; // Class identification, replacement for typeinfo
LoopDependenceAnalysis() : LoopPass(ID) {}
LoopDependenceAnalysis() : LoopPass(ID) {
initializeLoopDependenceAnalysisPass(*PassRegistry::getPassRegistry());
}

/// isDependencePair - Check whether two values can possibly give rise to
/// a data dependence: that is the case if both are instructions accessing
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Analysis/LoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,9 @@ class LoopInfo : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid

LoopInfo() : FunctionPass(ID) {}
LoopInfo() : FunctionPass(ID) {
initializeLoopInfoPass(*PassRegistry::getPassRegistry());
}

LoopInfoBase<BasicBlock, Loop>& getBase() { return LI; }

Expand Down
5 changes: 4 additions & 1 deletion include/llvm/Analysis/PostDominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct PostDominatorTree : public FunctionPass {
DominatorTreeBase<BasicBlock>* DT;

PostDominatorTree() : FunctionPass(ID) {
initializePostDominatorTreePass(*PassRegistry::getPassRegistry());
DT = new DominatorTreeBase<BasicBlock>(true);
}

Expand Down Expand Up @@ -106,7 +107,9 @@ template <> struct GraphTraits<PostDominatorTree*>
struct PostDominanceFrontier : public DominanceFrontierBase {
static char ID;
PostDominanceFrontier()
: DominanceFrontierBase(ID, true) {}
: DominanceFrontierBase(ID, true) {
initializePostDominanceFrontierPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &) {
Frontiers.clear();
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/CalcSpillWeights.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ namespace llvm {
public:
static char ID;

CalculateSpillWeights() : MachineFunctionPass(ID) {}
CalculateSpillWeights() : MachineFunctionPass(ID) {
initializeCalculateSpillWeightsPass(*PassRegistry::getPassRegistry());
}

virtual void getAnalysisUsage(AnalysisUsage &au) const;

Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/LiveIntervalAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ namespace llvm {

public:
static char ID; // Pass identification, replacement for typeid
LiveIntervals() : MachineFunctionPass(ID) {}
LiveIntervals() : MachineFunctionPass(ID) {
initializeLiveIntervalsPass(*PassRegistry::getPassRegistry());
}

// Calculate the spill weight to assign to a single instruction.
static float getSpillWeight(bool isDef, bool isUse, unsigned loopDepth);
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/LiveStackAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ namespace llvm {

public:
static char ID; // Pass identification, replacement for typeid
LiveStacks() : MachineFunctionPass(ID) {}
LiveStacks() : MachineFunctionPass(ID) {
initializeLiveStacksPass(*PassRegistry::getPassRegistry());
}

typedef SS2IntervalMap::iterator iterator;
typedef SS2IntervalMap::const_iterator const_iterator;
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/LiveVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class TargetRegisterInfo;
class LiveVariables : public MachineFunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
LiveVariables() : MachineFunctionPass(ID) {}
LiveVariables() : MachineFunctionPass(ID) {
initializeLiveVariablesPass(*PassRegistry::getPassRegistry());
}

/// VarInfo - This represents the regions where a virtual register is live in
/// the program. We represent this with three different pieces of
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/MachineLoopInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ class MachineLoopInfo : public MachineFunctionPass {
public:
static char ID; // Pass identification, replacement for typeid

MachineLoopInfo() : MachineFunctionPass(ID) {}
MachineLoopInfo() : MachineFunctionPass(ID) {
initializeMachineLoopInfoPass(*PassRegistry::getPassRegistry());
}

LoopInfoBase<MachineBasicBlock, MachineLoop>& getBase() { return LI; }

Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/ProcessImplicitDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace llvm {
public:
static char ID;

ProcessImplicitDefs() : MachineFunctionPass(ID) {}
ProcessImplicitDefs() : MachineFunctionPass(ID) {
initializeProcessImplicitDefsPass(*PassRegistry::getPassRegistry());
}

virtual void getAnalysisUsage(AnalysisUsage &au) const;

Expand Down
4 changes: 3 additions & 1 deletion include/llvm/CodeGen/SlotIndexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ namespace llvm {
public:
static char ID;

SlotIndexes() : MachineFunctionPass(ID), indexListHead(0) {}
SlotIndexes() : MachineFunctionPass(ID), indexListHead(0) {
initializeSlotIndexesPass(*PassRegistry::getPassRegistry());
}

virtual void getAnalysisUsage(AnalysisUsage &au) const;
virtual void releaseMemory();
Expand Down
1 change: 1 addition & 0 deletions include/llvm/InitializePasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void initializeLoopStrengthReducePass(PassRegistry&);
void initializeLoopUnrollPass(PassRegistry&);
void initializeLoopUnswitchPass(PassRegistry&);
void initializeLowerAtomicPass(PassRegistry&);
void initializeLowerIntrinsicsPass(PassRegistry&);
void initializeLowerInvokePass(PassRegistry&);
void initializeLowerSetJmpPass(PassRegistry&);
void initializeLowerSwitchPass(PassRegistry&);
Expand Down
21 changes: 8 additions & 13 deletions include/llvm/PassSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ class PassInfo {
sys::MemoryFence(); \
} \
} \
} \
static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis);
}

#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
Expand Down Expand Up @@ -183,8 +182,7 @@ class PassInfo {
sys::MemoryFence(); \
} \
} \
} \
static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis);
}

template<typename PassName>
Pass *callDefaultCtor() { return new PassName(); }
Expand Down Expand Up @@ -282,12 +280,12 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
sys::MemoryFence(); \
} \
} \
} \
static RegisterAnalysisGroup<agName> agName##_info (name);
}


#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
if (!def) initialize##agName##AnalysisGroup(Registry); \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
Registry.registerPass(*PI); \
Expand All @@ -311,13 +309,12 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
sys::MemoryFence(); \
} \
} \
} \
static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis); \
static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info);
}


#define INITIALIZE_AG_PASS_BEGIN(passName, agName, arg, n, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
if (!def) initialize##agName##AnalysisGroup(Registry);

#define INITIALIZE_AG_PASS_END(passName, agName, arg, n, cfg, analysis, def) \
PassInfo *PI = new PassInfo(n, arg, & passName ::ID, \
Expand All @@ -343,9 +340,7 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
sys::MemoryFence(); \
} \
} \
} \
static RegisterPass<passName> passName ## _info(arg, n, cfg, analysis); \
static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info);
}

//===---------------------------------------------------------------------------
/// PassRegistrationListener class - This class is meant to be derived from by
Expand Down
4 changes: 3 additions & 1 deletion include/llvm/Transforms/Utils/UnifyFunctionExitNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ struct UnifyFunctionExitNodes : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
UnifyFunctionExitNodes() : FunctionPass(ID),
ReturnBlock(0), UnwindBlock(0) {}
ReturnBlock(0), UnwindBlock(0) {
initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry());
}

// We can preserve non-critical-edgeness when we unify function exit nodes
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/Analysis/AliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
using namespace llvm;

// Register the AliasAnalysis interface, providing a nice name to refer to.
INITIALIZE_ANALYSIS_GROUP(AliasAnalysis, "Alias Analysis", BasicAliasAnalysis)
INITIALIZE_ANALYSIS_GROUP(AliasAnalysis, "Alias Analysis", NoAA)
char AliasAnalysis::ID = 0;

//===----------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions lib/Analysis/AliasAnalysisCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace {
public:
static char ID; // Class identification, replacement for typeinfo
AliasAnalysisCounter() : ModulePass(ID) {
initializeAliasAnalysisCounterPass(*PassRegistry::getPassRegistry());
No = May = Must = 0;
NoMR = JustRef = JustMod = MR = 0;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Analysis/AliasAnalysisEvaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ namespace {

public:
static char ID; // Pass identification, replacement for typeid
AAEval() : FunctionPass(ID) {}
AAEval() : FunctionPass(ID) {
initializeAAEvalPass(*PassRegistry::getPassRegistry());
}

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<AliasAnalysis>();
Expand Down
4 changes: 3 additions & 1 deletion lib/Analysis/AliasDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ namespace {

public:
static char ID; // Class identification, replacement for typeinfo
AliasDebugger() : ModulePass(ID) {}
AliasDebugger() : ModulePass(ID) {
initializeAliasDebuggerPass(*PassRegistry::getPassRegistry());
}

bool runOnModule(Module &M) {
InitializeAliasAnalysis(this); // set up super class
Expand Down
4 changes: 3 additions & 1 deletion lib/Analysis/AliasSetTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ namespace {
AliasSetTracker *Tracker;
public:
static char ID; // Pass identification, replacement for typeid
AliasSetPrinter() : FunctionPass(ID) {}
AliasSetPrinter() : FunctionPass(ID) {
initializeAliasSetPrinterPass(*PassRegistry::getPassRegistry());
}

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
Expand Down
10 changes: 7 additions & 3 deletions lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ namespace {
///
struct NoAA : public ImmutablePass, public AliasAnalysis {
static char ID; // Class identification, replacement for typeinfo
NoAA() : ImmutablePass(ID) {}
explicit NoAA(char &PID) : ImmutablePass(PID) { }
NoAA() : ImmutablePass(ID) {
initializeNoAAPass(*PassRegistry::getPassRegistry());
}
explicit NoAA(char &PID) : ImmutablePass(PID) {}

virtual void getAnalysisUsage(AnalysisUsage &AU) const {
}
Expand Down Expand Up @@ -490,7 +492,9 @@ namespace {
/// derives from the NoAA class.
struct BasicAliasAnalysis : public NoAA {
static char ID; // Class identification, replacement for typeinfo
BasicAliasAnalysis() : NoAA(ID) {}
BasicAliasAnalysis() : NoAA(ID) {
initializeBasicAliasAnalysisPass(*PassRegistry::getPassRegistry());
}

virtual void initializePass() {
InitializeAliasAnalysis(this);
Expand Down
17 changes: 13 additions & 4 deletions lib/Analysis/CFGPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ using namespace llvm;
namespace {
struct CFGViewer : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
CFGViewer() : FunctionPass(ID) {}
CFGViewer() : FunctionPass(ID) {
initializeCFGOnlyViewerPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &F) {
F.viewCFG();
Expand All @@ -46,7 +48,9 @@ INITIALIZE_PASS(CFGViewer, "view-cfg", "View CFG of function", false, true)
namespace {
struct CFGOnlyViewer : public FunctionPass {
static char ID; // Pass identifcation, replacement for typeid
CFGOnlyViewer() : FunctionPass(ID) {}
CFGOnlyViewer() : FunctionPass(ID) {
initializeCFGOnlyViewerPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &F) {
F.viewCFGOnly();
Expand All @@ -68,7 +72,9 @@ INITIALIZE_PASS(CFGOnlyViewer, "view-cfg-only",
namespace {
struct CFGPrinter : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
CFGPrinter() : FunctionPass(ID) {}
CFGPrinter() : FunctionPass(ID) {
initializeCFGPrinterPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &F) {
std::string Filename = "cfg." + F.getNameStr() + ".dot";
Expand Down Expand Up @@ -100,7 +106,10 @@ INITIALIZE_PASS(CFGPrinter, "dot-cfg", "Print CFG of function to 'dot' file",
namespace {
struct CFGOnlyPrinter : public FunctionPass {
static char ID; // Pass identification, replacement for typeid
CFGOnlyPrinter() : FunctionPass(ID) {}
CFGOnlyPrinter() : FunctionPass(ID) {
initializeCFGOnlyPrinterPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &F) {
std::string Filename = "cfg." + F.getNameStr() + ".dot";
errs() << "Writing '" << Filename << "'...";
Expand Down
4 changes: 3 additions & 1 deletion lib/Analysis/DbgInfoPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ namespace {
void printVariableDeclaration(const Value *V);
public:
static char ID; // Pass identification
PrintDbgInfo() : FunctionPass(ID), Out(errs()) {}
PrintDbgInfo() : FunctionPass(ID), Out(errs()) {
initializePrintDbgInfoPass(*PassRegistry::getPassRegistry());
}

virtual bool runOnFunction(Function &F);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Expand Down
Loading

0 comments on commit 081c34b

Please sign in to comment.