Do not use typeinfo to identify pass in pass manager.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36632 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2007-05-01 21:15:47 +00:00
parent e50fb9ac17
commit 794fd75c67
154 changed files with 687 additions and 129 deletions

View File

@@ -61,6 +61,7 @@ protected:
virtual void getAnalysisUsage(AnalysisUsage &AU) const;
public:
static const int ID; // Class identification, replacement for typeinfo
AliasAnalysis() : TD(0), AA(0) {}
virtual ~AliasAnalysis(); // We want to be subclassed

View File

@@ -73,6 +73,7 @@ protected:
FunctionMapTy FunctionMap; // Map from a function to its node
public:
static const int ID; // Class identification, replacement for typeinfo
//===---------------------------------------------------------------------
// Accessors...
//

View File

@@ -42,9 +42,10 @@ class DominatorBase : public FunctionPass {
protected:
std::vector<BasicBlock*> Roots;
const bool IsPostDominators;
inline DominatorBase(bool isPostDom) : Roots(), IsPostDominators(isPostDom) {}
inline DominatorBase(intptr_t ID, bool isPostDom) :
FunctionPass(ID), Roots(), IsPostDominators(isPostDom) {}
public:
/// getRoots - Return the root blocks of the current CFG. This may include
/// multiple blocks if we are computing post dominators. For forward
/// dominators, this will always be a single block (the entry node).
@@ -135,7 +136,8 @@ public:
};
public:
DominatorTreeBase(bool isPostDom) : DominatorBase(isPostDom) {}
DominatorTreeBase(intptr_t ID, bool isPostDom)
: DominatorBase(ID, isPostDom) {}
~DominatorTreeBase() { reset(); }
virtual void releaseMemory() { reset(); }
@@ -206,7 +208,8 @@ public:
///
class DominatorTree : public DominatorTreeBase {
public:
DominatorTree() : DominatorTreeBase(false) {}
static const int ID; // Pass ID, replacement for typeid
DominatorTree() : DominatorTreeBase((intptr_t)&ID, false) {}
BasicBlock *getRoot() const {
assert(Roots.size() == 1 && "Should always have entry node!");
@@ -264,8 +267,9 @@ template <> struct GraphTraits<DominatorTree*>
///
class ETForestBase : public DominatorBase {
public:
ETForestBase(bool isPostDom) : DominatorBase(isPostDom), Nodes(),
DFSInfoValid(false), SlowQueries(0) {}
ETForestBase(intptr_t ID, bool isPostDom)
: DominatorBase(ID, isPostDom), Nodes(),
DFSInfoValid(false), SlowQueries(0) {}
virtual void releaseMemory() { reset(); }
@@ -395,7 +399,9 @@ protected:
class ETForest : public ETForestBase {
public:
ETForest() : ETForestBase(false) {}
static const int ID; // Pass identifcation, replacement for typeid
ETForest() : ETForestBase((intptr_t)&ID, false) {}
BasicBlock *getRoot() const {
assert(Roots.size() == 1 && "Should always have entry node!");
@@ -425,7 +431,8 @@ public:
protected:
DomSetMapType Frontiers;
public:
DominanceFrontierBase(bool isPostDom) : DominatorBase(isPostDom) {}
DominanceFrontierBase(intptr_t ID, bool isPostDom)
: DominatorBase(ID, isPostDom) {}
virtual void releaseMemory() { Frontiers.clear(); }
@@ -470,7 +477,9 @@ public:
///
class DominanceFrontier : public DominanceFrontierBase {
public:
DominanceFrontier() : DominanceFrontierBase(false) {}
static const int ID; // Pass ID, replacement for typeid
DominanceFrontier() :
DominanceFrontierBase((intptr_t)& ID, false) {}
BasicBlock *getRoot() const {
assert(Roots.size() == 1 && "Should always have entry node!");

View File

@@ -24,6 +24,9 @@ class Type;
class FindUsedTypes : public ModulePass {
std::set<const Type *> UsedTypes;
public:
static const int ID; // Pass identifcation, replacement for typeid
FindUsedTypes() : ModulePass((intptr_t)&ID) {}
/// getTypes - After the pass has been run, return the set containing all of
/// the types used in the module.
///

View File

@@ -45,7 +45,9 @@ class IntervalPartition : public FunctionPass {
std::vector<Interval*> Intervals;
public:
IntervalPartition() : RootInterval(0) {}
static const int ID; // Pass identifcation, replacement for typeid
IntervalPartition() : FunctionPass((intptr_t)&ID), RootInterval(0) {}
// run - Calculate the interval partition for this function
virtual bool runOnFunction(Function &F);

View File

@@ -241,6 +241,9 @@ class LoopInfo : public FunctionPass {
std::vector<Loop*> TopLevelLoops;
friend class Loop;
public:
static const int ID; // Pass identifcation, replacement for typeid
LoopInfo() : FunctionPass((intptr_t)&ID) {}
~LoopInfo() { releaseMemory(); }
/// iterator/begin/end - The interface to the top-level loops in the current

View File

@@ -29,6 +29,8 @@ class Function;
class LoopPass : public Pass {
public:
LoopPass(intptr_t pid) : Pass(pid) {}
// runOnLoop - THis method should be implemented by the subclass to perform
// whatever action is necessary for the specfied Loop.
virtual bool runOnLoop (Loop *L, LPPassManager &LPM) = 0;
@@ -66,6 +68,7 @@ class LoopPass : public Pass {
class LPPassManager : public FunctionPass, public PMDataManager {
public:
static const int ID;
LPPassManager(int Depth);
/// run - Execute all of the passes scheduled for execution. Keep track of

View File

@@ -22,7 +22,10 @@ namespace llvm {
/// compute the a post-dominator tree.
///
struct PostDominatorTree : public DominatorTreeBase {
PostDominatorTree() : DominatorTreeBase(true) {}
static const int ID; // Pass identifcation, replacement for typeid
PostDominatorTree() :
DominatorTreeBase((intptr_t)&ID, true) {}
virtual bool runOnFunction(Function &F) {
reset(); // Reset from the last time we were run...
@@ -51,7 +54,8 @@ private:
/// PostETForest Class - Concrete subclass of ETForestBase that is used to
/// compute a forwards post-dominator ET-Forest.
struct PostETForest : public ETForestBase {
PostETForest() : ETForestBase(true) {}
static const int ID;
PostETForest() : ETForestBase((intptr_t)&ID, true) {}
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
@@ -75,7 +79,9 @@ struct PostETForest : public ETForestBase {
/// used to compute the a post-dominance frontier.
///
struct PostDominanceFrontier : public DominanceFrontierBase {
PostDominanceFrontier() : DominanceFrontierBase(true) {}
static const int ID;
PostDominanceFrontier()
: DominanceFrontierBase((intptr_t) &ID, true) {}
virtual bool runOnFunction(Function &) {
Frontiers.clear();

View File

@@ -38,6 +38,7 @@ namespace llvm {
// entered.
std::map<std::pair<BasicBlock*, BasicBlock*>, unsigned> EdgeCounts;
public:
static const int ID; // Class identification, replacement for typeinfo
virtual ~ProfileInfo(); // We want to be subclassed
//===------------------------------------------------------------------===//

View File

@@ -197,7 +197,8 @@ namespace llvm {
class ScalarEvolution : public FunctionPass {
void *Impl; // ScalarEvolution uses the pimpl pattern
public:
ScalarEvolution() : Impl(0) {}
static const int ID; // Pass identifcation, replacement for typeid
ScalarEvolution() : FunctionPass((intptr_t)&ID), Impl(0) {}
/// getSCEV - Return a SCEV expression handle for the full generality of the
/// specified expression.

View File

@@ -29,6 +29,7 @@ class Value;
class Instruction;
struct ValueNumbering {
static const int ID; // Class identification, replacement for typeinfo
virtual ~ValueNumbering(); // We want to be subclassed
/// getEqualNumberNodes - Return nodes with the same value number as the

View File

@@ -28,9 +28,10 @@ class PrintModulePass : public ModulePass {
OStream *Out; // ostream to print on
bool DeleteStream; // Delete the ostream in our dtor?
public:
PrintModulePass() : Out(&cerr), DeleteStream(false) {}
static const int ID;
PrintModulePass() : ModulePass((intptr_t)&ID), Out(&cerr), DeleteStream(false) {}
PrintModulePass(OStream *o, bool DS = false)
: Out(o), DeleteStream(DS) {}
: ModulePass((intptr_t)&ID), Out(o), DeleteStream(DS) {}
~PrintModulePass() {
if (DeleteStream) delete Out;
@@ -51,10 +52,12 @@ class PrintFunctionPass : public FunctionPass {
OStream *Out; // ostream to print on
bool DeleteStream; // Delete the ostream in our dtor?
public:
PrintFunctionPass() : Banner(""), Out(&cerr), DeleteStream(false) {}
static const int ID;
PrintFunctionPass() : FunctionPass((intptr_t)&ID), Banner(""), Out(&cerr),
DeleteStream(false) {}
PrintFunctionPass(const std::string &B, OStream *o = &cout,
bool DS = false)
: Banner(B), Out(o), DeleteStream(DS) {}
: FunctionPass((intptr_t)&ID), Banner(B), Out(o), DeleteStream(DS) {}
inline ~PrintFunctionPass() {
if (DeleteStream) delete Out;

View File

@@ -26,10 +26,12 @@ class WriteBytecodePass : public ModulePass {
bool DeleteStream;
bool CompressFile;
public:
static const int ID; // Pass identifcation, replacement for typeid
WriteBytecodePass()
: Out(&cout), DeleteStream(false), CompressFile(false) {}
: ModulePass((intptr_t) &ID), Out(&cout), DeleteStream(false),
CompressFile(false) {}
WriteBytecodePass(OStream *o, bool DS = false, bool CF = false)
: Out(o), DeleteStream(DS), CompressFile(CF) {}
: ModulePass((intptr_t) &ID), Out(o), DeleteStream(DS), CompressFile(CF) {}
inline ~WriteBytecodePass() {
if (DeleteStream) delete Out;

View File

@@ -31,6 +31,8 @@ class PMStack;
struct CallGraphSCCPass : public Pass {
CallGraphSCCPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - This method is called before the SCC's of the program
/// has been processed, allowing the pass to do initialization as necessary.
virtual bool doInitialization(CallGraph &CG) {

View File

@@ -34,6 +34,8 @@ namespace llvm {
/// AsmPrinter - This class is intended to be used as a driving class for all
/// asm writers.
class AsmPrinter : public MachineFunctionPass {
static const int ID;
/// FunctionNumber - This provides a unique ID for each function emitted in
/// this translation unit. It is autoincremented by SetupMachineFunction,
/// and can be accessed with getFunctionNumber() and

View File

@@ -65,6 +65,9 @@ namespace llvm {
BitVector JoinedLIs;
public:
static const int ID; // Pass identifcation, replacement for typeid
LiveIntervals() : MachineFunctionPass((intptr_t)&ID) {}
struct CopyRec {
MachineInstr *MI;
unsigned SrcReg, DstReg;

View File

@@ -40,6 +40,9 @@ class MRegisterInfo;
class LiveVariables : public MachineFunctionPass {
public:
static const int ID; // Pass identifcation, replacement for typeid
LiveVariables() : MachineFunctionPass((intptr_t)&ID) {}
/// VarInfo - This represents the regions where a virtual register is live in
/// the program. We represent this with three different pieces of
/// information: the instruction that uniquely defines the value, the set of

View File

@@ -26,6 +26,8 @@ namespace llvm {
struct MachineFunctionPass : public FunctionPass {
MachineFunctionPass(intptr_t ID) : FunctionPass(ID) {}
/// runOnMachineFunction - This method must be overloaded to perform the
/// desired machine code transformation or analysis.
///

View File

@@ -1022,6 +1022,8 @@ private:
std::vector<GlobalVariable *> TypeInfos;
public:
static const int ID; // Pass identifcation, replacement for typeid
MachineModuleInfo();
~MachineModuleInfo();

View File

@@ -41,8 +41,10 @@ public:
MachineBasicBlock *BB;
std::vector<SDNode*> TopOrder;
unsigned DAGSize;
static const int ID;
explicit SelectionDAGISel(TargetLowering &tli) : TLI(tli), DAGSize(0) {}
explicit SelectionDAGISel(TargetLowering &tli) :
FunctionPass((intptr_t)&ID), TLI(tli), DAGSize(0) {}
TargetLowering &getTargetLowering() { return TLI; }

View File

@@ -34,8 +34,8 @@
#include <deque>
#include <map>
#include <iosfwd>
#include <typeinfo>
#include <cassert>
#include <stdint.h>
namespace llvm {
@@ -77,7 +77,7 @@ typedef enum PassManagerType PassManagerType;
///
class Pass {
AnalysisResolver *Resolver; // Used to resolve analysis
const PassInfo *PassInfoCache;
intptr_t PassID;
// AnalysisImpls - This keeps track of which passes implement the interfaces
// that are required by the current pass (to implement getAnalysis()).
@@ -87,7 +87,7 @@ class Pass {
void operator=(const Pass&); // DO NOT IMPLEMENT
Pass(const Pass &); // DO NOT IMPLEMENT
public:
Pass() : Resolver(0), PassInfoCache(0) {}
Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
virtual ~Pass();
/// getPassName - Return a nice clean name for a pass. This usually
@@ -163,12 +163,12 @@ public:
template<typename AnalysisClass>
static const PassInfo *getClassPassInfo() {
return lookupPassInfo(typeid(AnalysisClass));
return lookupPassInfo((intptr_t)&AnalysisClass::ID);
}
// lookupPassInfo - Return the pass info object for the specified pass class,
// or null if it is not known.
static const PassInfo *lookupPassInfo(const std::type_info &TI);
static const PassInfo *lookupPassInfo(intptr_t TI);
/// getAnalysisToUpdate<AnalysisType>() - This function is used by subclasses
/// to get to the analysis information that might be around that needs to be
@@ -232,6 +232,7 @@ public:
return PMT_ModulePassManager;
}
ModulePass(intptr_t pid) : Pass(pid) {}
// Force out-of-line virtual method.
virtual ~ModulePass();
};
@@ -256,6 +257,7 @@ public:
///
virtual bool runOnModule(Module &M) { return false; }
ImmutablePass(intptr_t pid) : ModulePass(pid) {}
// Force out-of-line virtual method.
virtual ~ImmutablePass();
};
@@ -271,6 +273,8 @@ public:
///
class FunctionPass : public Pass {
public:
FunctionPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization.
///
@@ -320,6 +324,8 @@ public:
///
class BasicBlockPass : public Pass {
public:
BasicBlockPass(intptr_t pid) : Pass(pid) {}
/// doInitialization - Virtual method overridden by subclasses to do
/// any necessary per-module initialization.
///

View File

@@ -336,7 +336,9 @@ private:
class FPPassManager : public ModulePass, public PMDataManager {
public:
explicit FPPassManager(int Depth) : PMDataManager(Depth) { }
static const int ID;
explicit FPPassManager(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.

View File

@@ -37,19 +37,19 @@ class TargetMachine;
class PassInfo {
const char *PassName; // Nice name for Pass
const char *PassArgument; // Command Line argument to run this pass
const std::type_info &TypeInfo; // type_info object for this Pass class
intptr_t PassID;
bool IsCFGOnlyPass; // Pass only looks at the CFG.
bool IsAnalysisGroup; // True if an analysis group.
std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass
Pass *(*NormalCtor)(); // No argument ctor
Pass *(*NormalCtor)();
public:
/// PassInfo ctor - Do not call this directly, this should only be invoked
/// through RegisterPass.
PassInfo(const char *name, const char *arg, const std::type_info &ti,
PassInfo(const char *name, const char *arg, intptr_t pi,
Pass *(*normal)() = 0, bool isCFGOnly = false)
: PassName(name), PassArgument(arg), TypeInfo(ti),
: PassName(name), PassArgument(arg), PassID(pi),
IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
}
@@ -65,8 +65,8 @@ public:
const char *getPassArgument() const { return PassArgument; }
/// getTypeInfo - Return the type_info object for the pass...
///
const std::type_info &getTypeInfo() const { return TypeInfo; }
/// TODO : Rename
intptr_t getTypeInfo() const { return PassID; }
/// isAnalysisGroup - Return true if this is an analysis group, not a normal
/// pass.
@@ -139,12 +139,12 @@ struct RegisterPassBase {
typedef Pass* (*NormalCtor_t)();
RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI,
RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
: PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
registerPass();
}
RegisterPassBase(const std::type_info &TI)
RegisterPassBase(intptr_t TI)
: PIObj("", "", TI) {
// This ctor may only be used for analysis groups: it does not auto-register
// the pass.
@@ -165,7 +165,7 @@ struct RegisterPass : public RegisterPassBase {
// Register Pass using default constructor...
RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
: RegisterPassBase(Name, PassArg, typeid(PassName),
: RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID,
(RegisterPassBase::NormalCtor_t)callDefaultCtor<PassName>, CFGOnly) {
}
};
@@ -195,8 +195,8 @@ class RegisterAGBase : public RegisterPassBase {
const PassInfo *ImplementationInfo;
bool isDefaultImplementation;
protected:
explicit RegisterAGBase(const std::type_info &Interface,
const std::type_info *Pass = 0,
explicit RegisterAGBase(intptr_t InterfaceID,
intptr_t PassID = 0,
bool isDefault = false);
void setGroupName(const char *Name);
};
@@ -204,12 +204,12 @@ protected:
template<typename Interface, bool Default = false>
struct RegisterAnalysisGroup : public RegisterAGBase {
explicit RegisterAnalysisGroup(RegisterPassBase &RPB)
: RegisterAGBase(typeid(Interface), &RPB.getPassInfo()->getTypeInfo(),
: RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(),
Default) {
}
explicit RegisterAnalysisGroup(const char *Name)
: RegisterAGBase(typeid(Interface)) {
: RegisterAGBase((intptr_t) &Interface::ID) {
setGroupName(Name);
}
};

View File

@@ -108,14 +108,15 @@ public:
///
/// @note This has to exist, because this is a pass, but it should never be
/// used.
TargetData() {
TargetData() : ImmutablePass((intptr_t)&ID) {
assert(0 && "ERROR: Bad TargetData ctor used. "
"Tool did not specify a TargetData to use?");
abort();
}
/// Constructs a TargetData from a specification string. See init().
TargetData(const std::string &TargetDescription) {
TargetData(const std::string &TargetDescription)
: ImmutablePass((intptr_t)&ID) {
init(TargetDescription);
}
@@ -123,7 +124,7 @@ public:
TargetData(const Module *M);
TargetData(const TargetData &TD) :
ImmutablePass(),
ImmutablePass((intptr_t)&ID),
LittleEndian(TD.isLittleEndian()),
PointerMemSize(TD.PointerMemSize),
PointerABIAlign(TD.PointerABIAlign),
@@ -200,6 +201,8 @@ public:
/// specified global, returned in log form. This includes an explicitly
/// requested alignment (if the global has one).
unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
static const int ID; // Pass identifcation, replacement for typeid
};
/// StructLayout - used to lazily calculate structure layout information for a

View File

@@ -23,6 +23,9 @@ namespace llvm {
/// this interface are expected to chain to other implementations, such that
/// multiple profilers can be support simultaniously.
struct RSProfilers : public ModulePass {
static const int ID; // Pass identification, replacement for typeinfo
RSProfilers() : ModulePass((intptr_t)&ID) {}
/// isProfiling - This method returns true if the value passed it was
/// inserted by the profiler.
virtual bool isProfiling(Value* v) = 0;

View File

@@ -25,7 +25,9 @@ namespace llvm {
struct UnifyFunctionExitNodes : public FunctionPass {
BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
public:
UnifyFunctionExitNodes() : ReturnBlock(0), UnwindBlock(0) {}
static const int ID; // Pass identifcation, replacement for typeid
UnifyFunctionExitNodes() : FunctionPass((intptr_t)&ID),
ReturnBlock(0), UnwindBlock(0) {}
// We can preserve non-critical-edgeness when we unify function exit nodes
virtual void getAnalysisUsage(AnalysisUsage &AU) const;