llvm.org GIT mirror llvm / 794fd75
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 Devang Patel 12 years ago
154 changed file(s) with 690 addition(s) and 132 deletion(s). Raw diff Collapse all Expand all
6060 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
6161
6262 public:
63 static const int ID; // Class identification, replacement for typeinfo
6364 AliasAnalysis() : TD(0), AA(0) {}
6465 virtual ~AliasAnalysis(); // We want to be subclassed
6566
7272 FunctionMapTy FunctionMap; // Map from a function to its node
7373
7474 public:
75 static const int ID; // Class identification, replacement for typeinfo
7576 //===---------------------------------------------------------------------
7677 // Accessors...
7778 //
4141 protected:
4242 std::vector Roots;
4343 const bool IsPostDominators;
44
45 inline DominatorBase(bool isPostDom) : Roots(), IsPostDominators(isPostDom) {}
46 public:
44 inline DominatorBase(intptr_t ID, bool isPostDom) :
45 FunctionPass(ID), Roots(), IsPostDominators(isPostDom) {}
46 public:
47
4748 /// getRoots - Return the root blocks of the current CFG. This may include
4849 /// multiple blocks if we are computing post dominators. For forward
4950 /// dominators, this will always be a single block (the entry node).
134135 };
135136
136137 public:
137 DominatorTreeBase(bool isPostDom) : DominatorBase(isPostDom) {}
138 DominatorTreeBase(intptr_t ID, bool isPostDom)
139 : DominatorBase(ID, isPostDom) {}
138140 ~DominatorTreeBase() { reset(); }
139141
140142 virtual void releaseMemory() { reset(); }
205207 ///
206208 class DominatorTree : public DominatorTreeBase {
207209 public:
208 DominatorTree() : DominatorTreeBase(false) {}
210 static const int ID; // Pass ID, replacement for typeid
211 DominatorTree() : DominatorTreeBase((intptr_t)&ID, false) {}
209212
210213 BasicBlock *getRoot() const {
211214 assert(Roots.size() == 1 && "Should always have entry node!");
263266 ///
264267 class ETForestBase : public DominatorBase {
265268 public:
266 ETForestBase(bool isPostDom) : DominatorBase(isPostDom), Nodes(),
267 DFSInfoValid(false), SlowQueries(0) {}
269 ETForestBase(intptr_t ID, bool isPostDom)
270 : DominatorBase(ID, isPostDom), Nodes(),
271 DFSInfoValid(false), SlowQueries(0) {}
268272
269273 virtual void releaseMemory() { reset(); }
270274
394398
395399 class ETForest : public ETForestBase {
396400 public:
397 ETForest() : ETForestBase(false) {}
401 static const int ID; // Pass identifcation, replacement for typeid
402
403 ETForest() : ETForestBase((intptr_t)&ID, false) {}
398404
399405 BasicBlock *getRoot() const {
400406 assert(Roots.size() == 1 && "Should always have entry node!");
424430 protected:
425431 DomSetMapType Frontiers;
426432 public:
427 DominanceFrontierBase(bool isPostDom) : DominatorBase(isPostDom) {}
433 DominanceFrontierBase(intptr_t ID, bool isPostDom)
434 : DominatorBase(ID, isPostDom) {}
428435
429436 virtual void releaseMemory() { Frontiers.clear(); }
430437
469476 ///
470477 class DominanceFrontier : public DominanceFrontierBase {
471478 public:
472 DominanceFrontier() : DominanceFrontierBase(false) {}
479 static const int ID; // Pass ID, replacement for typeid
480 DominanceFrontier() :
481 DominanceFrontierBase((intptr_t)& ID, false) {}
473482
474483 BasicBlock *getRoot() const {
475484 assert(Roots.size() == 1 && "Should always have entry node!");
2323 class FindUsedTypes : public ModulePass {
2424 std::set UsedTypes;
2525 public:
26 static const int ID; // Pass identifcation, replacement for typeid
27 FindUsedTypes() : ModulePass((intptr_t)&ID) {}
28
2629 /// getTypes - After the pass has been run, return the set containing all of
2730 /// the types used in the module.
2831 ///
4444 std::vector Intervals;
4545
4646 public:
47 IntervalPartition() : RootInterval(0) {}
47 static const int ID; // Pass identifcation, replacement for typeid
48
49 IntervalPartition() : FunctionPass((intptr_t)&ID), RootInterval(0) {}
4850
4951 // run - Calculate the interval partition for this function
5052 virtual bool runOnFunction(Function &F);
240240 std::vector TopLevelLoops;
241241 friend class Loop;
242242 public:
243 static const int ID; // Pass identifcation, replacement for typeid
244
245 LoopInfo() : FunctionPass((intptr_t)&ID) {}
243246 ~LoopInfo() { releaseMemory(); }
244247
245248 /// iterator/begin/end - The interface to the top-level loops in the current
2828 class LoopPass : public Pass {
2929
3030 public:
31 LoopPass(intptr_t pid) : Pass(pid) {}
32
3133 // runOnLoop - THis method should be implemented by the subclass to perform
3234 // whatever action is necessary for the specfied Loop.
3335 virtual bool runOnLoop (Loop *L, LPPassManager &LPM) = 0;
6567 class LPPassManager : public FunctionPass, public PMDataManager {
6668
6769 public:
70 static const int ID;
6871 LPPassManager(int Depth);
6972
7073 /// run - Execute all of the passes scheduled for execution. Keep track of
2121 /// compute the a post-dominator tree.
2222 ///
2323 struct PostDominatorTree : public DominatorTreeBase {
24 PostDominatorTree() : DominatorTreeBase(true) {}
24 static const int ID; // Pass identifcation, replacement for typeid
25
26 PostDominatorTree() :
27 DominatorTreeBase((intptr_t)&ID, true) {}
2528
2629 virtual bool runOnFunction(Function &F) {
2730 reset(); // Reset from the last time we were run...
5053 /// PostETForest Class - Concrete subclass of ETForestBase that is used to
5154 /// compute a forwards post-dominator ET-Forest.
5255 struct PostETForest : public ETForestBase {
53 PostETForest() : ETForestBase(true) {}
56 static const int ID;
57 PostETForest() : ETForestBase((intptr_t)&ID, true) {}
5458
5559 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
5660 AU.setPreservesAll();
7478 /// used to compute the a post-dominance frontier.
7579 ///
7680 struct PostDominanceFrontier : public DominanceFrontierBase {
77 PostDominanceFrontier() : DominanceFrontierBase(true) {}
81 static const int ID;
82 PostDominanceFrontier()
83 : DominanceFrontierBase((intptr_t) &ID, true) {}
7884
7985 virtual bool runOnFunction(Function &) {
8086 Frontiers.clear();
3737 // entered.
3838 std::map, unsigned> EdgeCounts;
3939 public:
40 static const int ID; // Class identification, replacement for typeinfo
4041 virtual ~ProfileInfo(); // We want to be subclassed
4142
4243 //===------------------------------------------------------------------===//
196196 class ScalarEvolution : public FunctionPass {
197197 void *Impl; // ScalarEvolution uses the pimpl pattern
198198 public:
199 ScalarEvolution() : Impl(0) {}
199 static const int ID; // Pass identifcation, replacement for typeid
200 ScalarEvolution() : FunctionPass((intptr_t)&ID), Impl(0) {}
200201
201202 /// getSCEV - Return a SCEV expression handle for the full generality of the
202203 /// specified expression.
2828 class Instruction;
2929
3030 struct ValueNumbering {
31 static const int ID; // Class identification, replacement for typeinfo
3132 virtual ~ValueNumbering(); // We want to be subclassed
3233
3334 /// getEqualNumberNodes - Return nodes with the same value number as the
2727 OStream *Out; // ostream to print on
2828 bool DeleteStream; // Delete the ostream in our dtor?
2929 public:
30 PrintModulePass() : Out(&cerr), DeleteStream(false) {}
30 static const int ID;
31 PrintModulePass() : ModulePass((intptr_t)&ID), Out(&cerr), DeleteStream(false) {}
3132 PrintModulePass(OStream *o, bool DS = false)
32 : Out(o), DeleteStream(DS) {}
33 : ModulePass((intptr_t)&ID), Out(o), DeleteStream(DS) {}
3334
3435 ~PrintModulePass() {
3536 if (DeleteStream) delete Out;
5051 OStream *Out; // ostream to print on
5152 bool DeleteStream; // Delete the ostream in our dtor?
5253 public:
53 PrintFunctionPass() : Banner(""), Out(&cerr), DeleteStream(false) {}
54 static const int ID;
55 PrintFunctionPass() : FunctionPass((intptr_t)&ID), Banner(""), Out(&cerr),
56 DeleteStream(false) {}
5457 PrintFunctionPass(const std::string &B, OStream *o = &cout,
5558 bool DS = false)
56 : Banner(B), Out(o), DeleteStream(DS) {}
59 : FunctionPass((intptr_t)&ID), Banner(B), Out(o), DeleteStream(DS) {}
5760
5861 inline ~PrintFunctionPass() {
5962 if (DeleteStream) delete Out;
2525 bool DeleteStream;
2626 bool CompressFile;
2727 public:
28 static const int ID; // Pass identifcation, replacement for typeid
2829 WriteBytecodePass()
29 : Out(&cout), DeleteStream(false), CompressFile(false) {}
30 : ModulePass((intptr_t) &ID), Out(&cout), DeleteStream(false),
31 CompressFile(false) {}
3032 WriteBytecodePass(OStream *o, bool DS = false, bool CF = false)
31 : Out(o), DeleteStream(DS), CompressFile(CF) {}
33 : ModulePass((intptr_t) &ID), Out(o), DeleteStream(DS), CompressFile(CF) {}
3234
3335 inline ~WriteBytecodePass() {
3436 if (DeleteStream) delete Out;
2929 class PMStack;
3030
3131 struct CallGraphSCCPass : public Pass {
32
33 CallGraphSCCPass(intptr_t pid) : Pass(pid) {}
3234
3335 /// doInitialization - This method is called before the SCC's of the program
3436 /// has been processed, allowing the pass to do initialization as necessary.
3333 /// AsmPrinter - This class is intended to be used as a driving class for all
3434 /// asm writers.
3535 class AsmPrinter : public MachineFunctionPass {
36 static const int ID;
37
3638 /// FunctionNumber - This provides a unique ID for each function emitted in
3739 /// this translation unit. It is autoincremented by SetupMachineFunction,
3840 /// and can be accessed with getFunctionNumber() and
6464 BitVector JoinedLIs;
6565
6666 public:
67 static const int ID; // Pass identifcation, replacement for typeid
68 LiveIntervals() : MachineFunctionPass((intptr_t)&ID) {}
69
6770 struct CopyRec {
6871 MachineInstr *MI;
6972 unsigned SrcReg, DstReg;
3939
4040 class LiveVariables : public MachineFunctionPass {
4141 public:
42 static const int ID; // Pass identifcation, replacement for typeid
43 LiveVariables() : MachineFunctionPass((intptr_t)&ID) {}
44
4245 /// VarInfo - This represents the regions where a virtual register is live in
4346 /// the program. We represent this with three different pieces of
4447 /// information: the instruction that uniquely defines the value, the set of
2525
2626 struct MachineFunctionPass : public FunctionPass {
2727
28 MachineFunctionPass(intptr_t ID) : FunctionPass(ID) {}
29
2830 /// runOnMachineFunction - This method must be overloaded to perform the
2931 /// desired machine code transformation or analysis.
3032 ///
10211021 std::vector TypeInfos;
10221022
10231023 public:
1024 static const int ID; // Pass identifcation, replacement for typeid
1025
10241026 MachineModuleInfo();
10251027 ~MachineModuleInfo();
10261028
4040 MachineBasicBlock *BB;
4141 std::vector TopOrder;
4242 unsigned DAGSize;
43 static const int ID;
4344
44 explicit SelectionDAGISel(TargetLowering &tli) : TLI(tli), DAGSize(0) {}
45 explicit SelectionDAGISel(TargetLowering &tli) :
46 FunctionPass((intptr_t)&ID), TLI(tli), DAGSize(0) {}
4547
4648 TargetLowering &getTargetLowering() { return TLI; }
4749
3333 #include
3434 #include
3535 #include
36 #include
3736 #include
37 #include
3838
3939 namespace llvm {
4040
7676 ///
7777 class Pass {
7878 AnalysisResolver *Resolver; // Used to resolve analysis
79 const PassInfo *PassInfoCache;
79 intptr_t PassID;
8080
8181 // AnalysisImpls - This keeps track of which passes implement the interfaces
8282 // that are required by the current pass (to implement getAnalysis()).
8686 void operator=(const Pass&); // DO NOT IMPLEMENT
8787 Pass(const Pass &); // DO NOT IMPLEMENT
8888 public:
89 Pass() : Resolver(0), PassInfoCache(0) {}
89 Pass(intptr_t pid) : Resolver(0), PassID(pid) {}
9090 virtual ~Pass();
9191
9292 /// getPassName - Return a nice clean name for a pass. This usually
162162
163163 template
164164 static const PassInfo *getClassPassInfo() {
165 return lookupPassInfo(typeid(AnalysisClass));
165 return lookupPassInfo((intptr_t)&AnalysisClass::ID);
166166 }
167167
168168 // lookupPassInfo - Return the pass info object for the specified pass class,
169169 // or null if it is not known.
170 static const PassInfo *lookupPassInfo(const std::type_info &TI);
170 static const PassInfo *lookupPassInfo(intptr_t TI);
171171
172172 /// getAnalysisToUpdate() - This function is used by subclasses
173173 /// to get to the analysis information that might be around that needs to be
231231 return PMT_ModulePassManager;
232232 }
233233
234 ModulePass(intptr_t pid) : Pass(pid) {}
234235 // Force out-of-line virtual method.
235236 virtual ~ModulePass();
236237 };
255256 ///
256257 virtual bool runOnModule(Module &M) { return false; }
257258
259 ImmutablePass(intptr_t pid) : ModulePass(pid) {}
258260 // Force out-of-line virtual method.
259261 virtual ~ImmutablePass();
260262 };
270272 ///
271273 class FunctionPass : public Pass {
272274 public:
275 FunctionPass(intptr_t pid) : Pass(pid) {}
276
273277 /// doInitialization - Virtual method overridden by subclasses to do
274278 /// any necessary per-module initialization.
275279 ///
319323 ///
320324 class BasicBlockPass : public Pass {
321325 public:
326 BasicBlockPass(intptr_t pid) : Pass(pid) {}
327
322328 /// doInitialization - Virtual method overridden by subclasses to do
323329 /// any necessary per-module initialization.
324330 ///
335335 class FPPassManager : public ModulePass, public PMDataManager {
336336
337337 public:
338 explicit FPPassManager(int Depth) : PMDataManager(Depth) { }
338 static const int ID;
339 explicit FPPassManager(int Depth)
340 : ModulePass((intptr_t)&ID), PMDataManager(Depth) { }
339341
340342 /// run - Execute all of the passes scheduled for execution. Keep track of
341343 /// whether any of the passes modifies the module, and if so, return true.
3636 class PassInfo {
3737 const char *PassName; // Nice name for Pass
3838 const char *PassArgument; // Command Line argument to run this pass
39 const std::type_info &TypeInfo; // type_info object for this Pass class
39 intptr_t PassID;
4040 bool IsCFGOnlyPass; // Pass only looks at the CFG.
4141 bool IsAnalysisGroup; // True if an analysis group.
4242 std::vector ItfImpl;// Interfaces implemented by this pass
4343
44 Pass *(*NormalCtor)(); // No argument ctor
44 Pass *(*NormalCtor)();
4545
4646 public:
4747 /// PassInfo ctor - Do not call this directly, this should only be invoked
4848 /// through RegisterPass.
49 PassInfo(const char *name, const char *arg, const std::type_info &ti,
49 PassInfo(const char *name, const char *arg, intptr_t pi,
5050 Pass *(*normal)() = 0, bool isCFGOnly = false)
51 : PassName(name), PassArgument(arg), TypeInfo(ti),
51 : PassName(name), PassArgument(arg), PassID(pi),
5252 IsCFGOnlyPass(isCFGOnly), IsAnalysisGroup(false), NormalCtor(normal) {
5353 }
5454
6464 const char *getPassArgument() const { return PassArgument; }
6565
6666 /// getTypeInfo - Return the type_info object for the pass...
67 ///
68 const std::type_info &getTypeInfo() const { return TypeInfo; }
67 /// TODO : Rename
68 intptr_t getTypeInfo() const { return PassID; }
6969
7070 /// isAnalysisGroup - Return true if this is an analysis group, not a normal
7171 /// pass.
138138
139139 typedef Pass* (*NormalCtor_t)();
140140
141 RegisterPassBase(const char *Name, const char *Arg, const std::type_info &TI,
141 RegisterPassBase(const char *Name, const char *Arg, intptr_t TI,
142142 NormalCtor_t NormalCtor = 0, bool CFGOnly = false)
143143 : PIObj(Name, Arg, TI, NormalCtor, CFGOnly) {
144144 registerPass();
145145 }
146 RegisterPassBase(const std::type_info &TI)
146 RegisterPassBase(intptr_t TI)
147147 : PIObj("", "", TI) {
148148 // This ctor may only be used for analysis groups: it does not auto-register
149149 // the pass.
164164
165165 // Register Pass using default constructor...
166166 RegisterPass(const char *PassArg, const char *Name, bool CFGOnly = false)
167 : RegisterPassBase(Name, PassArg, typeid(PassName),
167 : RegisterPassBase(Name, PassArg, (intptr_t)&PassName::ID,
168168 (RegisterPassBase::NormalCtor_t)callDefaultCtor, CFGOnly) {
169169 }
170170 };
194194 const PassInfo *ImplementationInfo;
195195 bool isDefaultImplementation;
196196 protected:
197 explicit RegisterAGBase(const std::type_info &Interface,
198 const std::type_info *Pass = 0,
197 explicit RegisterAGBase(intptr_t InterfaceID,
198 intptr_t PassID = 0,
199199 bool isDefault = false);
200200 void setGroupName(const char *Name);
201201 };
203203 template
204204 struct RegisterAnalysisGroup : public RegisterAGBase {
205205 explicit RegisterAnalysisGroup(RegisterPassBase &RPB)
206 : RegisterAGBase(typeid(Interface), &RPB.getPassInfo()->getTypeInfo(),
206 : RegisterAGBase((intptr_t) &Interface::ID, RPB.getPassInfo()->getTypeInfo(),
207207 Default) {
208208 }
209209
210210 explicit RegisterAnalysisGroup(const char *Name)
211 : RegisterAGBase(typeid(Interface)) {
211 : RegisterAGBase((intptr_t) &Interface::ID) {
212212 setGroupName(Name);
213213 }
214214 };
107107 ///
108108 /// @note This has to exist, because this is a pass, but it should never be
109109 /// used.
110 TargetData() {
110 TargetData() : ImmutablePass((intptr_t)&ID) {
111111 assert(0 && "ERROR: Bad TargetData ctor used. "
112112 "Tool did not specify a TargetData to use?");
113113 abort();
114114 }
115115
116116 /// Constructs a TargetData from a specification string. See init().
117 TargetData(const std::string &TargetDescription) {
117 TargetData(const std::string &TargetDescription)
118 : ImmutablePass((intptr_t)&ID) {
118119 init(TargetDescription);
119120 }
120121
122123 TargetData(const Module *M);
123124
124125 TargetData(const TargetData &TD) :
125 ImmutablePass(),
126 ImmutablePass((intptr_t)&ID),
126127 LittleEndian(TD.isLittleEndian()),
127128 PointerMemSize(TD.PointerMemSize),
128129 PointerABIAlign(TD.PointerABIAlign),
199200 /// specified global, returned in log form. This includes an explicitly
200201 /// requested alignment (if the global has one).
201202 unsigned getPreferredAlignmentLog(const GlobalVariable *GV) const;
203
204 static const int ID; // Pass identifcation, replacement for typeid
202205 };
203206
204207 /// StructLayout - used to lazily calculate structure layout information for a
2222 /// this interface are expected to chain to other implementations, such that
2323 /// multiple profilers can be support simultaniously.
2424 struct RSProfilers : public ModulePass {
25 static const int ID; // Pass identification, replacement for typeinfo
26 RSProfilers() : ModulePass((intptr_t)&ID) {}
27
2528 /// isProfiling - This method returns true if the value passed it was
2629 /// inserted by the profiler.
2730 virtual bool isProfiling(Value* v) = 0;
2424 struct UnifyFunctionExitNodes : public FunctionPass {
2525 BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
2626 public:
27 UnifyFunctionExitNodes() : ReturnBlock(0), UnwindBlock(0) {}
27 static const int ID; // Pass identifcation, replacement for typeid
28 UnifyFunctionExitNodes() : FunctionPass((intptr_t)&ID),
29 ReturnBlock(0), UnwindBlock(0) {}
2830
2931 // We can preserve non-critical-edgeness when we unify function exit nodes
3032 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
3333
3434 // Register the AliasAnalysis interface, providing a nice name to refer to.
3535 namespace {
36 const int AliasAnalysis::ID = 0;
3637 RegisterAnalysisGroup Z("Alias Analysis");
3738 }
3839
3333 const char *Name;
3434 Module *M;
3535 public:
36 AliasAnalysisCounter() {
36 static const int ID; // Class identification, replacement for typeinfo
37 AliasAnalysisCounter() : ModulePass((intptr_t) &ID) {
3738 No = May = Must = 0;
3839 NoMR = JustRef = JustMod = MR = 0;
3940 }
106107 }
107108 };
108109
110 const int AliasAnalysisCounter::ID = 0;
109111 RegisterPass
110112 X("count-aa", "Count Alias Analysis Query Responses");
111113 RegisterAnalysisGroup Y(X);
4949 unsigned NoModRef, Mod, Ref, ModRef;
5050
5151 public:
52 static const int ID; // Pass identifcation, replacement for typeid
53 AAEval() : FunctionPass((intptr_t)&ID) {}
54
5255 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
5356 AU.addRequired();
5457 AU.setPreservesAll();
6972 bool doFinalization(Module &M);
7073 };
7174
75 const int AAEval::ID = 0;
7276 RegisterPass
7377 X("aa-eval", "Exhaustive Alias Analysis Precision Evaluator");
7478 }
3939 std::set Vals;
4040
4141 public:
42 static const int ID; // Class identification, replacement for typeinfo
43 AliasDebugger() : ModulePass((intptr_t)&ID) {}
44
4245 bool runOnModule(Module &M) {
4346 InitializeAliasAnalysis(this); // set up super class
4447
118121
119122 };
120123
124 const int AliasDebugger::ID = 0;
121125 RegisterPass X("debug-aa", "AA use debugger");
122126 RegisterAnalysisGroup Y(X);
123127 }
554554 class VISIBILITY_HIDDEN AliasSetPrinter : public FunctionPass {
555555 AliasSetTracker *Tracker;
556556 public:
557 static const int ID; // Pass identifcation, replacement for typeid
558 AliasSetPrinter() : FunctionPass((intptr_t)&ID) {}
559
557560 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
558561 AU.setPreservesAll();
559562 AU.addRequired();
569572 return false;
570573 }
571574 };
575 const int AliasSetPrinter::ID = 0;
572576 RegisterPass X("print-alias-sets", "Alias Set Printer");
573577 }
3535 /// such it doesn't follow many of the rules that other alias analyses must.
3636 ///
3737 struct VISIBILITY_HIDDEN NoAA : public ImmutablePass, public AliasAnalysis {
38 static const int ID; // Class identification, replacement for typeinfo
39 NoAA() : ImmutablePass((intptr_t)&ID) {}
40
3841 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
3942 AU.addRequired();
4043 }
7376 };
7477
7578 // Register this pass...
79 const int NoAA::ID = 0;
7680 RegisterPass
7781 U("no-aa", "No Alias Analysis (always returns 'may' alias)");
7882
8791 /// Because it doesn't chain to a previous alias analysis (like -no-aa), it
8892 /// derives from the NoAA class.
8993 struct VISIBILITY_HIDDEN BasicAliasAnalysis : public NoAA {
94 static const int ID; // Class identification, replacement for typeinfo
9095 AliasResult alias(const Value *V1, unsigned V1Size,
9196 const Value *V2, unsigned V2Size);
9297
118123 };
119124
120125 // Register this pass...
126 const int BasicAliasAnalysis::ID = 0;
121127 RegisterPass
122128 X("basicaa", "Basic Alias Analysis (default AA impl)");
123129
9090
9191 namespace {
9292 struct VISIBILITY_HIDDEN CFGPrinter : public FunctionPass {
93 static const int ID; // Pass identifcation, replacement for typeid
94 CFGPrinter() : FunctionPass((intptr_t)&ID) {}
95
9396 virtual bool runOnFunction(Function &F) {
9497 std::string Filename = "cfg." + F.getName() + ".dot";
9598 cerr << "Writing '" << Filename << "'...";
110113 }
111114 };
112115
116 const int CFGPrinter::ID = 0;
113117 RegisterPass P1("print-cfg",
114118 "Print CFG of function to 'dot' file");
115119
116120 struct VISIBILITY_HIDDEN CFGOnlyPrinter : public CFGPrinter {
121 static const int ID; // Pass identifcation, replacement for typeid
117122 virtual bool runOnFunction(Function &F) {
118123 bool OldCFGOnly = CFGOnly;
119124 CFGOnly = true;
128133 }
129134 };
130135
136 const int CFGOnlyPrinter::ID = 0;
131137 RegisterPass
132138 P2("print-cfg-only",
133139 "Print CFG of function to 'dot' file (with no function bodies)");
7474 namespace {
7575 class VISIBILITY_HIDDEN Andersens : public ModulePass, public AliasAnalysis,
7676 private InstVisitor {
77 public:
78 static const int ID; // Class identification, replacement for typeinfo
79 Andersens() : ModulePass((intptr_t)&ID) {}
80 private:
7781 /// Node class - This class is used to represent a memory object in the
7882 /// program, and is the primitive used to build the points-to graph.
7983 class Node {
8084 std::vector Pointees;
8185 Value *Val;
8286 public:
87 static const unsigned ID; // Pass identifcation, replacement for typeid
8388 Node() : Val(0) {}
8489 Node *setValue(Value *V) {
8590 assert(Val == 0 && "Value already set for this node!");
333338 void visitInstruction(Instruction &I);
334339 };
335340
341 const int Andersens::ID = 0;
336342 RegisterPass X("anders-aa",
337343 "Andersen's Interprocedural Alias Analysis");
338344 RegisterAnalysisGroup Y(X);
5050 CallGraphNode *CallsExternalNode;
5151
5252 public:
53 BasicCallGraph() : Root(0), ExternalCallingNode(0), CallsExternalNode(0) {}
53 static const int ID; // Class identification, replacement for typeinfo
54 BasicCallGraph() : ModulePass((intptr_t)&ID), Root(0),
55 ExternalCallingNode(0), CallsExternalNode(0) {}
5456
5557 // runOnModule - Compute the call graph for the specified module.
5658 virtual bool runOnModule(Module &M) {
187189 }
188190 };
189191
192 const int CallGraph::ID = 0;
190193 RegisterAnalysisGroup X("Call Graph");
194 const int BasicCallGraph::ID = 0;
191195 RegisterPass Y("basiccg", "Basic CallGraph Construction");
192196 RegisterAnalysisGroup Z(Y);
193197
2929 class CGPassManager : public ModulePass, public PMDataManager {
3030
3131 public:
32 CGPassManager(int Depth) : PMDataManager(Depth) { }
32 static const int ID;
33 CGPassManager(int Depth)
34 : ModulePass((intptr_t)&ID), PMDataManager(Depth) { }
3335
3436 /// run - Execute all of the passes scheduled for execution. Keep track of
3537 /// whether any of the passes modifies the module, and if so, return true.
7072 }
7173 };
7274
75 const int CGPassManager::ID = 0;
7376 /// run - Execute all of the passes scheduled for execution. Keep track of
7477 /// whether any of the passes modifies the module, and if so, return true.
7578 bool CGPassManager::runOnModule(Module &M) {
2020 #include "llvm/Support/InstIterator.h"
2121 using namespace llvm;
2222
23 const int FindUsedTypes::ID = 0;
2324 static RegisterPass
2425 X("printusedtypes", "Find Used Types");
2526
8282 std::map FunctionInfo;
8383
8484 public:
85 static const int ID;
86 GlobalsModRef() : ModulePass((intptr_t)&ID) {}
87
8588 bool runOnModule(Module &M) {
8689 InitializeAliasAnalysis(this); // set up super class
8790 AnalyzeGlobals(M); // find non-addr taken globals
142145 bool AnalyzeIndirectGlobalMemory(GlobalValue *GV);
143146 };
144147
148 const int GlobalsModRef::ID = 0;
145149 RegisterPass X("globalsmodref-aa",
146150 "Simple mod/ref analysis for globals");
147151 RegisterAnalysisGroup Y(X);
5050 abort();
5151 }
5252 public:
53 static const int ID; // Pass identifcation, replacement for typeid
54 InstCount() : FunctionPass((intptr_t)&ID) {}
55
5356 virtual bool runOnFunction(Function &F);
5457
5558 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
5962
6063 };
6164
65 const int InstCount::ID = 0;
6266 RegisterPass X("instcount",
6367 "Counts the various types of Instructions");
6468 }
1414 #include "llvm/Analysis/IntervalIterator.h"
1515 using namespace llvm;
1616
17 const int IntervalPartition::ID = 0;
1718 static RegisterPass
1819 X("intervals", "Interval Partition Construction", true);
1920
8788 // existing interval graph. This takes an additional boolean parameter to
8889 // distinguish it from a copy constructor. Always pass in false for now.
8990 //
90 IntervalPartition::IntervalPartition(IntervalPartition &IP, bool) {
91 IntervalPartition::IntervalPartition(IntervalPartition &IP, bool)
92 : FunctionPass((intptr_t) &ID) {
9193 Interval *FunctionStart = IP.getRootInterval();
9294 assert(FunctionStart && "Cannot operate on empty IntervalPartitions!");
9395
3939 namespace {
4040 // FIXME: This should not be a FunctionPass.
4141 struct VISIBILITY_HIDDEN LoadVN : public FunctionPass, public ValueNumbering {
42 static const int ID; // Class identification, replacement for typeinfo
43 LoadVN() : FunctionPass((intptr_t)&ID) {}
4244
4345 /// Pass Implementation stuff. This doesn't do any analysis.
4446 ///
8082 std::vector &RetVals) const;
8183 };
8284
85 const int LoadVN::ID = 0;
8386 // Register this pass...
8487 RegisterPass X("load-vn", "Load Value Numbering");
8588
2626 #include
2727 using namespace llvm;
2828
29 const int LoopInfo::ID = 0;
2930 static RegisterPass
3031 X("loops", "Natural Loop Construction", true);
3132
1919 //===----------------------------------------------------------------------===//
2020 // LPPassManager
2121 //
22
23 const int LPPassManager::ID = 0;
2224 /// LPPassManager manages FPPassManagers and CalLGraphSCCPasses.
2325
24 LPPassManager::LPPassManager(int Depth) : PMDataManager(Depth) {
26 LPPassManager::LPPassManager(int Depth)
27 : FunctionPass((intptr_t)&ID), PMDataManager(Depth) {
2528 skipThisLoop = false;
2629 redoThisLoop = false;
2730 LI = NULL;
2121 // PostDominatorTree Implementation
2222 //===----------------------------------------------------------------------===//
2323
24 const int PostDominatorTree::ID = 0;
25 const int PostDominanceFrontier::ID = 0;
26 const int PostETForest::ID = 0;
2427 static RegisterPass
2528 F("postdomtree", "Post-Dominator Tree Construction", true);
2629
2121
2222 // Register the ProfileInfo interface, providing a nice name to refer to.
2323 namespace {
24 const int ProfileInfo::ID = 0;
2425 RegisterAnalysisGroup Z("Profile Information");
2526 }
2627
8384
8485 namespace {
8586 struct VISIBILITY_HIDDEN NoProfileInfo
86 : public ImmutablePass, public ProfileInfo {};
87 : public ImmutablePass, public ProfileInfo {
88 static const int ID; // Class identification, replacement for typeinfo
89 NoProfileInfo() : ImmutablePass((intptr_t)&ID) {}
90 };
8791
92 const int NoProfileInfo::ID = 0;
8893 // Register this pass...
8994 RegisterPass
9095 X("no-profile", "No Profile Information");
3131 class VISIBILITY_HIDDEN LoaderPass : public ModulePass, public ProfileInfo {
3232 std::string Filename;
3333 public:
34 static const int ID; // Class identification, replacement for typeinfo
3435 LoaderPass(const std::string &filename = "")
35 : Filename(filename) {
36 : ModulePass((intptr_t)&ID), Filename(filename) {
3637 if (filename.empty()) Filename = ProfileInfoFilename;
3738 }
3839
4849 virtual bool runOnModule(Module &M);
4950 };
5051
52 const int LoaderPass::ID = 0;
5153 RegisterPass
5254 X("profile-loader", "Load profile information from llvmprof.out");
5355
101101 cl::init(100));
102102
103103 namespace {
104 const int ScalarEvolution::ID = 0;
104105 RegisterPass
105106 R("scalar-evolution", "Scalar Evolution Analysis");
106107 }
2121 #include "llvm/Support/Compiler.h"
2222 using namespace llvm;
2323
24 const int ValueNumbering::ID = 0;
2425 // Register the ValueNumbering interface, providing a nice name to refer to.
2526 static RegisterAnalysisGroup X("Value Numbering");
2627
5051 ///
5152 struct VISIBILITY_HIDDEN BasicVN
5253 : public ImmutablePass, public ValueNumbering {
54 static const int ID; // Class identification, replacement for typeinfo
55 BasicVN() : ImmutablePass((intptr_t)&ID) {}
56
5357 /// getEqualNumberNodes - Return nodes with the same value number as the
5458 /// specified Value. This fills in the argument vector with any equal
5559 /// values.
6064 std::vector &RetVals) const;
6165 };
6266
67 const int BasicVN::ID = 0;
6368 // Register this pass...
6469 RegisterPass
6570 X("basicvn", "Basic Value Numbering (default GVN impl)");
4646 /// @brief The bytecode version number
4747 const unsigned BCVersionNum = 7;
4848
49 const int WriteBytecodePass::ID = 0;
4950 static RegisterPass X("emitbytecode", "Bytecode Writer");
5051
5152 STATISTIC(BytesWritten, "Number of bytecode bytes written");
3131 static cl::opt
3232 AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
3333
34 const int AsmPrinter::ID = 0;
3435 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
3536 const TargetAsmInfo *T)
36 : FunctionNumber(0), O(o), TM(tm), TAI(T)
37 : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
3738 {}
3839
3940 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
3838
3939 namespace {
4040 struct BranchFolder : public MachineFunctionPass {
41 static const int ID;
42 BranchFolder() : MachineFunctionPass((intptr_t)&ID) {}
43
4144 virtual bool runOnMachineFunction(MachineFunction &MF);
4245 virtual const char *getPassName() const { return "Control Flow Optimizer"; }
4346 const TargetInstrInfo *TII;
6366 MachineBasicBlock *TBB, MachineBasicBlock *FBB,
6467 const std::vector &Cond);
6568 };
69 const int BranchFolder::ID = 0;
6670 }
6771
6872 FunctionPass *llvm::createBranchFoldingPass() { return new BranchFolder(); }
4646 #include
4747 using namespace llvm;
4848
49 const int ELFWriter::ID = 0;
4950 /// AddELFWriter - Concrete function to add the ELF writer to the function pass
5051 /// manager.
5152 MachineCodeEmitter *llvm::AddELFWriter(FunctionPassManager &FPM,
175176 // ELFWriter Implementation
176177 //===----------------------------------------------------------------------===//
177178
178 ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
179 ELFWriter::ELFWriter(std::ostream &o, TargetMachine &tm)
180 : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
179181 e_flags = 0; // e_flags defaults to 0, no flags.
180182
181183 is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
2929 class ELFWriter : public MachineFunctionPass {
3030 friend class ELFCodeEmitter;
3131 public:
32 static const int ID;
33
3234 MachineCodeEmitter &getMachineCodeEmitter() const {
3335 return *(MachineCodeEmitter*)MCE;
3436 }
4444 STATISTIC(numAborts , "Number of times interval joining aborted");
4545
4646 namespace {
47 const int LiveIntervals::ID = 0;
4748 RegisterPass X("liveintervals", "Live Interval Analysis");
4849
4950 static cl::opt
3636 #include
3737 using namespace llvm;
3838
39 const int LiveVariables::ID = 0;
3940 static RegisterPass X("livevars", "Live Variable Analysis");
4041
4142 void LiveVariables::VarInfo::dump() const {
316316 // MachOWriter Implementation
317317 //===----------------------------------------------------------------------===//
318318
319 MachOWriter::MachOWriter(std::ostream &o, TargetMachine &tm) : O(o), TM(tm) {
319 const int MachOWriter::ID = 0;
320 MachOWriter::MachOWriter(std::ostream &o, TargetMachine &tm)
321 : MachineFunctionPass((intptr_t)&ID), O(o), TM(tm) {
320322 is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
321323 isLittleEndian = TM.getTargetData()->isLittleEndian();
322324
8383 class MachOWriter : public MachineFunctionPass {
8484 friend class MachOCodeEmitter;
8585 public:
86 static const int ID;
8687 MachineCodeEmitter &getMachineCodeEmitter() const {
8788 return *(MachineCodeEmitter*)MCE;
8889 }
4343
4444 namespace {
4545 struct VISIBILITY_HIDDEN Printer : public MachineFunctionPass {
46 static const int ID;
47
4648 std::ostream *OS;
4749 const std::string Banner;
4850
49 Printer (std::ostream *_OS, const std::string &_Banner) :
50 OS (_OS), Banner (_Banner) { }
51 Printer (std::ostream *_OS, const std::string &_Banner)
52 : MachineFunctionPass((intptr_t)&ID), OS (_OS), Banner (_Banner) { }
5153
5254 const char *getPassName() const { return "MachineFunction Printer"; }
5355
6163 return false;
6264 }
6365 };
66 const int Printer::ID = 0;
6467 }
6568
6669 /// Returns a newly-created MachineFunction Printer pass. The default output
7376
7477 namespace {
7578 struct VISIBILITY_HIDDEN Deleter : public MachineFunctionPass {
79 static const int ID;
80 Deleter() : MachineFunctionPass((intptr_t)&ID) {}
81
7682 const char *getPassName() const { return "Machine Code Deleter"; }
7783
7884 bool runOnMachineFunction(MachineFunction &MF) {
8187 return true;
8288 }
8389 };
90 const int Deleter::ID = 0;
8491 }
8592
8693 /// MachineCodeDeletion Pass - This pass deletes all of the machine code for
2727
2828 // Handle the Pass registration stuff necessary to use TargetData's.
2929 namespace {
30 const int MachineModuleInfo::ID = 0;
3031 RegisterPass X("machinemoduleinfo", "Module Information");
3132 }
3233
14611462 //===----------------------------------------------------------------------===//
14621463
14631464 MachineModuleInfo::MachineModuleInfo()
1464 : DR()
1465 : ImmutablePass((intptr_t)&ID)
1466 , DR()
14651467 , VR()
14661468 , CompileUnits()
14671469 , Directories()
17481750 namespace llvm {
17491751
17501752 struct DebugLabelFolder : public MachineFunctionPass {
1753 static const int ID;
1754 DebugLabelFolder() : MachineFunctionPass((intptr_t)&ID) {}
1755
17511756 virtual bool runOnMachineFunction(MachineFunction &MF);
17521757 virtual const char *getPassName() const { return "Label Folder"; }
17531758 };
1759
1760 const int DebugLabelFolder::ID = 0;
17541761
17551762 bool DebugLabelFolder::runOnMachineFunction(MachineFunction &MF) {
17561763 // Get machine module info.
3232
3333 namespace {
3434 struct VISIBILITY_HIDDEN PNE : public MachineFunctionPass {
35 static const int ID; // Pass identifcation, replacement for typeid
36 PNE() : MachineFunctionPass((intptr_t)&ID) {}
37
3538 bool runOnMachineFunction(MachineFunction &Fn) {
3639 analyzePHINodes(Fn);
3740
7275 VRegPHIUse VRegPHIUseCount;
7376 };
7477
78 const int PNE::ID = 0;
7579 RegisterPass X("phi-node-elimination",
7680 "Eliminate PHI nodes for register allocation");
7781 }
3131
3232 namespace {
3333 struct VISIBILITY_HIDDEN PEI : public MachineFunctionPass {
34 static const int ID;
35 PEI() : MachineFunctionPass((intptr_t)&ID) {}
36
3437 const char *getPassName() const {
3538 return "Prolog/Epilog Insertion & Frame Finalization";
3639 }
97100 void replaceFrameIndices(MachineFunction &Fn);
98101 void insertPrologEpilogCode(MachineFunction &Fn);
99102 };
103 const int PEI::ID = 0;
100104 }
101105
102106
4747 static unsigned numIntervals = 0;
4848
4949 struct VISIBILITY_HIDDEN RA : public MachineFunctionPass {
50 static const int ID;
51 RA() : MachineFunctionPass((intptr_t)&ID) {}
52
5053 typedef std::pair IntervalPtr;
5154 typedef std::vector IntervalPtrs;
5255 private:
145148 }
146149 }
147150 };
151 const int RA::ID = 0;
148152 }
149153
150154 void RA::ComputeRelatedRegClasses() {
4242
4343
4444 class VISIBILITY_HIDDEN RA : public MachineFunctionPass {
45 public:
46 static const int ID;
47 RA() : MachineFunctionPass((intptr_t)&ID) {}
48 private:
4549 const TargetMachine *TM;
4650 MachineFunction *MF;
4751 const MRegisterInfo *RegInfo;
223227 void reloadPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &I,
224228 unsigned PhysReg);
225229 };
230 const int RA::ID = 0;
226231 }
227232
228233 /// getStackSpaceFor - This allocates space for the specified virtual register
3737 createSimpleRegisterAllocator);
3838
3939 class VISIBILITY_HIDDEN RegAllocSimple : public MachineFunctionPass {
40 public:
41 static const int ID;
42 RegAllocSimple() : MachineFunctionPass((intptr_t)&ID) {}
43 private:
4044 MachineFunction *MF;
4145 const TargetMachine *TM;
4246 const MRegisterInfo *RegInfo;
8993 void spillVirtReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
9094 unsigned VirtReg, unsigned PhysReg);
9195 };
92
96 const int RegAllocSimple::ID = 0;
9397 }
9498
9599 /// getStackSpaceFor - This allocates space for the specified virtual
50105010 if (e != InOps.size())
50115011 Ops.push_back(InOps.back());
50125012 }
5013
5014 const int SelectionDAGISel::ID = 0;
4949 namespace {
5050 struct VISIBILITY_HIDDEN TwoAddressInstructionPass
5151 : public MachineFunctionPass {
52 static const int ID; // Pass identifcation, replacement for typeid
53 TwoAddressInstructionPass() : MachineFunctionPass((intptr_t)&ID) {}
54
5255 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
5356
5457 /// runOnMachineFunction - pass entry point
5558 bool runOnMachineFunction(MachineFunction&);
5659 };
5760
61 const int TwoAddressInstructionPass::ID = 0;
5862 RegisterPass
5963 X("twoaddressinstruction", "Two-Address instruction pass");
6064 }
3333 namespace {
3434 class VISIBILITY_HIDDEN UnreachableBlockElim : public FunctionPass {
3535 virtual bool runOnFunction(Function &F);
36 public:
37 static const int ID; // Pass identifcation, replacement for typeid
38 UnreachableBlockElim() : FunctionPass((intptr_t)&ID) {}
3639 };
40 const int UnreachableBlockElim::ID = 0;
3741 RegisterPass
3842 X("unreachableblockelim", "Remove unreachable blocks from the CFG");
3943 }
127127 ARMFunctionInfo *AFI;
128128 bool isThumb;
129129 public:
130 static const int ID;
131 ARMConstantIslands() : MachineFunctionPass((intptr_t)&ID) {}
132
130133 virtual bool runOnMachineFunction(MachineFunction &Fn);
131134
132135 virtual const char *getPassName() const {
170173 void dumpBBs();
171174 void verify(MachineFunction &Fn);
172175 };
176 const int ARMConstantIslands::ID = 0;
173177 }
174178
175179 /// verify - check BBOffsets, BBSizes, alignment of islands
3737
3838 namespace {
3939 struct VISIBILITY_HIDDEN ARMLoadStoreOpt : public MachineFunctionPass {
40 static const int ID;
41 ARMLoadStoreOpt() : MachineFunctionPass((intptr_t)&ID) {}
42
4043 const TargetInstrInfo *TII;
4144 const MRegisterInfo *MRI;
4245 ARMFunctionInfo *AFI;
6972 bool LoadStoreMultipleOpti(MachineBasicBlock &MBB);
7073 bool MergeReturnIntoLDM(MachineBasicBlock &MBB);
7174 };
75 const int ARMLoadStoreOpt::ID = 0;
7276 }
7377
7478 /// createARMLoadStoreOptimizationPass - returns an instance of the load / store
2121
2222 namespace {
2323 struct VISIBILITY_HIDDEN AlphaBSel : public MachineFunctionPass {
24 static const int ID;
25 AlphaBSel() : MachineFunctionPass((intptr_t)&ID) {}
2426
2527 virtual bool runOnMachineFunction(MachineFunction &Fn);
2628
2830 return "Alpha Branch Selection";
2931 }
3032 };
33 const int AlphaBSel::ID = 0;
3134 }
3235
3336 /// createAlphaBranchSelectionPass - returns an instance of the Branch Selection
3535 int getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
3636
3737 public:
38 static const int ID;
3839 explicit AlphaCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce)
39 : II(0), TM(tm), MCE(mce) {}
40 : MachineFunctionPass((intptr_t)&ID), II(0), TM(tm), MCE(mce) {}
4041 AlphaCodeEmitter(TargetMachine &tm, MachineCodeEmitter &mce,
4142 const AlphaInstrInfo& ii)
42 : II(&ii), TM(tm), MCE(mce) {}
43 : MachineFunctionPass((intptr_t)&ID), II(&ii), TM(tm), MCE(mce) {}
4344
4445 bool runOnMachineFunction(MachineFunction &MF);
4546
5960 void emitBasicBlock(MachineBasicBlock &MBB);
6061
6162 };
63 const int AlphaCodeEmitter::ID = 0;
6264 }
6365
6466 /// createAlphaCodeEmitterPass - Return a pass that emits the collected Alpha code
3636 ///
3737 AlphaTargetMachine &TM;
3838
39 AlphaLLRPPass(AlphaTargetMachine &tm) : TM(tm) { }
39 static const int ID;
40 AlphaLLRPPass(AlphaTargetMachine &tm)
41 : MachineFunctionPass((intptr_t)&ID), TM(tm) { }
4042
4143 virtual const char *getPassName() const {
4244 return "Alpha NOP inserter";
151153 return Changed;
152154 }
153155 };
156 const int AlphaLLRPPass::ID = 0;
154157 } // end of anonymous namespace
155158
156159 FunctionPass *llvm::createAlphaLLRPPass(AlphaTargetMachine &tm) {
5555 /// external functions with the same name.
5656 ///
5757 class CBackendNameAllUsedStructsAndMergeFunctions : public ModulePass {
58 public:
59 static const int ID;
60 CBackendNameAllUsedStructsAndMergeFunctions()
61 : ModulePass((intptr_t)&ID) {}
5862 void getAnalysisUsage(AnalysisUsage &AU) const {
5963 AU.addRequired();
6064 }
6569
6670 virtual bool runOnModule(Module &M);
6771 };
72
73 const int CBackendNameAllUsedStructsAndMergeFunctions::ID = 0;
6874
6975 /// CWriter - This class is the main chunk of code that converts an LLVM
7076 /// module to a C translation unit.
8187 std::set intrinsicPrototypesAlreadyGenerated;
8288
8389 public:
84 CWriter(std::ostream &o) : Out(o), IL(0), Mang(0), LI(0), TheModule(0),
85 TAsm(0), TD(0) {}
90 static const int ID;
91 CWriter(std::ostream &o)
92 : FunctionPass((intptr_t)&ID), Out(o), IL(0), Mang(0), LI(0),
93 TheModule(0), TAsm(0), TD(0) {}
8694
8795 virtual const char *getPassName() const { return "C backend"; }
8896
254262 std::string GetValueName(const Value *Operand);
255263 };
256264 }
265
266 const int CWriter::ID = 0;
257267
258268 /// This method inserts names for any unnamed structure types that are used by
259269 /// the program, and removes names from structure types that are not used by the
3535
3636 namespace {
3737 struct IA64BundlingPass : public MachineFunctionPass {
38 static const int ID;
3839 /// Target machine description which we query for reg. names, data
3940 /// layout, etc.
4041 ///
4142 IA64TargetMachine &TM;
4243
43 IA64BundlingPass(IA64TargetMachine &tm) : TM(tm) { }
44 IA64BundlingPass(IA64TargetMachine &tm)
45 : MachineFunctionPass((intptr_t)&ID), TM(tm) { }
4446
4547 virtual const char *getPassName() const {
4648 return "IA64 (Itanium) Bundling Pass";
6062 // 'fallthrough' code
6163 std::set PendingRegWrites;
6264 };
65 const int IA64BundlingPass::ID = 0;
6366 } // end of anonymous namespace
6467
6568 /// createIA64BundlingPass - Returns a pass that adds STOP (;;) instructions
7979 return Changed;
8080 }
8181
82 const int MSILModule::ID = 0;
83 const int MSILWriter::ID = 0;
8284
8385 bool MSILWriter::runOnFunction(Function &F) {
8486 if (F.isDeclaration()) return false;
3636 const TargetData*& TD;
3737
3838 public:
39 static const int ID;
3940 MSILModule(const std::set*& _UsedTypes,
4041 const TargetData*& _TD)
41 : UsedTypes(_UsedTypes), TD(_TD) {}
42 : ModulePass((intptr_t)&ID), UsedTypes(_UsedTypes), TD(_TD) {}
4243
4344 void getAnalysisUsage(AnalysisUsage &AU) const {
4445 AU.addRequired();
8182 std::map >
8283 StaticInitList;
8384 const std::set* UsedTypes;
84
85 MSILWriter(std::ostream &o) : Out(o) {
85 static const int ID;
86 MSILWriter(std::ostream &o) : FunctionPass((intptr_t)&ID), Out(o) {
8687 UniqID = 0;
8788 }
8889
3131
3232 namespace {
3333 struct VISIBILITY_HIDDEN PPCBSel : public MachineFunctionPass {
34 static const int ID;
35 PPCBSel() : MachineFunctionPass((intptr_t)&ID) {}
36
3437 /// BlockSizes - The sizes of the basic blocks in the function.
3538 std::vector BlockSizes;
3639
4043 return "PowerPC Branch Selector";
4144 }
4245 };
46 const int PPCBSel::ID = 0;
4347 }
4448
4549 /// createPPCBranchSelectionPass - returns an instance of the Branch Selection
3939 int getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
4040
4141 public:
42 static const int ID;
4243 PPCCodeEmitter(TargetMachine &T, MachineCodeEmitter &M)
43 : TM(T), MCE(M) {}
44 : MachineFunctionPass((intptr_t)&ID), TM(T), MCE(M) {}
4445
4546 const char *getPassName() const { return "PowerPC Machine Code Emitter"; }
4647
6263 ///
6364 unsigned getBinaryCodeForInstr(MachineInstr &MI);
6465 };
66 const int PPCCodeEmitter::ID = 0;
6567 }
6668
6769 /// createPPCCodeEmitterPass - Return a pass that emits the collected PPC code
2929 TargetMachine &TM;
3030 const TargetInstrInfo *TII;
3131
32 Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { }
32 static const int ID;
33 Filler(TargetMachine &tm)
34 : MachineFunctionPass((intptr_t)&ID), TM(tm), TII(tm.getInstrInfo()) { }
3335
3436 virtual const char *getPassName() const {
3537 return "SPARC Delay Slot Filler";
4547 }
4648
4749 };
50 const int Filler::ID = 0;
4851 } // end of anonymous namespace
4952
5053 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
3030 /// layout, etc.
3131 ///
3232 TargetMachine &TM;
33
34 FPMover(TargetMachine &tm) : TM(tm) { }
33
34 static const int ID;
35 FPMover(TargetMachine &tm)
36 : MachineFunctionPass((intptr_t)&ID), TM(tm) { }
3537
3638 virtual const char *getPassName() const {
3739 return "Sparc Double-FP Move Fixer";
4042 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
4143 bool runOnMachineFunction(MachineFunction &F);
4244 };
45 const int FPMover::ID = 0;
4346 } // end of anonymous namespace
4447
4548 /// createSparcFPMoverPass - Returns a pass that turns FpMOVD
3232 // Handle the Pass registration stuff necessary to use TargetData's.
3333 namespace {
3434 // Register the default SparcV9 implementation...
35 const int TargetData::ID = 0;
3536 RegisterPass X("targetdata", "Target Data Layout");
3637 }
3738
220221 }
221222 }
222223
223 TargetData::TargetData(const Module *M) {
224 TargetData::TargetData(const Module *M)
225 : ImmutablePass((intptr_t)&ID) {
224226 init(M->getDataLayout());
225227 }
226228
3838 MachineCodeEmitter &MCE;
3939 bool Is64BitMode;
4040 public:
41 static const int ID;
4142 explicit Emitter(TargetMachine &tm, MachineCodeEmitter &mce)
42 : II(0), TD(0), TM(tm), MCE(mce), Is64BitMode(false) {}
43 : MachineFunctionPass((intptr_t)&ID), II(0), TD(0), TM(tm),
44 MCE(mce), Is64BitMode(false) {}
4345 Emitter(TargetMachine &tm, MachineCodeEmitter &mce,
4446 const X86InstrInfo &ii, const TargetData &td, bool is64)
45 : II(&ii), TD(&td), TM(tm), MCE(mce), Is64BitMode(is64) {}
47 : MachineFunctionPass((intptr_t)&ID), II(&ii), TD(&td), TM(tm),
48 MCE(mce), Is64BitMode(is64) {}
4649
4750 bool runOnMachineFunction(MachineFunction &MF);
4851
7881 bool isX86_64ExtendedReg(const MachineOperand &MO);
7982 unsigned determineREX(const MachineInstr &MI);
8083 };
84 const int Emitter::ID = 0;
8185 }
8286
8387 /// createX86CodeEmitterPass - Return a pass that emits the collected X86 code
5151
5252 namespace {
5353 struct VISIBILITY_HIDDEN FPS : public MachineFunctionPass {
54 static const int ID;
55 FPS() : MachineFunctionPass((intptr_t)&ID) {}
56
5457 virtual bool runOnMachineFunction(MachineFunction &MF);
5558
5659 virtual const char *getPassName() const { return "X86 FP Stackifier"; }
150153 void handleCondMovFP(MachineBasicBlock::iterator &I);
151154 void handleSpecialFP(MachineBasicBlock::iterator &I);
152155 };
156 const int FPS::ID = 0;
153157 }
154158
155159 FunctionPass *llvm::createX86FloatingPointStackifierPass() { return new FPS(); }
2424 namespace {
2525 // Hello - The first implementation, without getAnalysisUsage.
2626 struct Hello : public FunctionPass {
27 static const int ID; // Pass identifcation, replacement for typeid
28 Hello() : FunctionPass((intptr_t)&ID) {}
29
2730 virtual bool runOnFunction(Function &F) {
2831 HelloCounter++;
2932 std::string fname = F.getName();
3235 return false;
3336 }
3437 };
38
39 const int Hello::ID = 0;
3540 RegisterPass X("hello", "Hello World Pass");
3641
3742 // Hello2 - The second implementation with getAnalysisUsage implemented.
3843 struct Hello2 : public FunctionPass {
44 static const int ID; // Pass identifcation, replacement for typeid
45 Hello2() : FunctionPass((intptr_t)&ID) {}
46
3947 virtual bool runOnFunction(Function &F) {
4048 HelloCounter++;
4149 std::string fname = F.getName();
4957 AU.setPreservesAll();
5058 };
5159 };
60 const int Hello2::ID = 0;
5261 RegisterPass Y("hello2",
5362 "Hello World Pass (with getAnalysisUsage implemented)");
5463 }
6262 }
6363
6464 virtual bool runOnSCC(const std::vector &SCC);
65 static const int ID; // Pass identifcation, replacement for typeid
66 ArgPromotion() : CallGraphSCCPass((intptr_t)&ID) {}
67
6568 private:
6669 bool PromoteArguments(CallGraphNode *CGN);
6770 bool isSafeToPromoteArgument(Argument *Arg) const;
6871 Function *DoPromotion(Function *F, std::vector &ArgsToPromote);
6972 };
7073
74 const int ArgPromotion::ID = 0;
7175 RegisterPass X("argpromotion",
7276 "Promote 'by reference' arguments to scalars");
7377 }
2828
2929 namespace {
3030 struct VISIBILITY_HIDDEN ConstantMerge : public ModulePass {
31 static const int ID; // Pass identifcation, replacement for typeid
32 ConstantMerge() : ModulePass((intptr_t)&ID) {}
33
3134 // run - For this pass, process all of the globals in the module,
3235 // eliminating duplicate constants.
3336 //
3437 bool runOnModule(Module &M);
3538 };
3639
40 const int ConstantMerge::ID = 0;
3741 RegisterPassX("constmerge","Merge Duplicate Global Constants");
3842 }
3943
7575 std::multimap CallSites;
7676
7777 public:
78 static const int ID; // Pass identifcation, replacement for typeid
79 DAE() : ModulePass((intptr_t)&ID) {}
7880 bool runOnModule(Module &M);
7981
8082 virtual bool ShouldHackArguments() const { return false; }
9294
9395 void RemoveDeadArgumentsFromFunction(Function *F);
9496 };
97 const int DAE::ID = 0;
9598 RegisterPass X("deadargelim", "Dead Argument Elimination");
9699
97100 /// DAH - DeadArgumentHacking pass - Same as dead argument elimination, but
98101 /// deletes arguments to functions which are external. This is only for use
99102 /// by bugpoint.
100103 struct DAH : public DAE {
104 static const int ID;
101105 virtual bool ShouldHackArguments() const { return true; }
102106 };
107 const int DAH::ID = 0;
103108 RegisterPass Y("deadarghaX0r",
104109 "Dead Argument Hacking (BUGPOINT USE ONLY; DO NOT USE)");
105110 }
2525
2626 namespace {
2727 struct VISIBILITY_HIDDEN DTE : public ModulePass {
28 static const int ID; // Pass identifcation, replacement for typeid
29 DTE() : ModulePass((intptr_t)&ID) {}
30
2831 // doPassInitialization - For this pass, it removes global symbol table
2932 // entries for primitive types. These are never used for linking in GCC and
3033 // they make the output uglier to look at, so we nuke them.
3942 AU.addRequired();
4043 }
4144 };
45 const int DTE::ID = 0;
4246 RegisterPass X("deadtypeelim", "Dead Type Elimination");
4347 }
4448
2424 bool deleteFunc;
2525 bool reLink;
2626 public:
27 static const int ID; // Pass identifcation, replacement for typeid
28
2729 /// FunctionExtractorPass - If deleteFn is true, this pass deletes as the
2830 /// specified function. Otherwise, it deletes as much of the module as
2931 /// possible, except for the function specified.
3032 ///
3133 FunctionExtractorPass(Function *F = 0, bool deleteFn = true,
3234 bool relinkCallees = false)
33 : Named(F), deleteFunc(deleteFn), reLink(relinkCallees) {}
35 : ModulePass((intptr_t)&ID), Named(F), deleteFunc(deleteFn),
36 reLink(relinkCallees) {}
3437
3538 bool runOnModule(Module &M) {
3639 if (Named == 0) {
130133 }
131134 };
132135
136 const int FunctionExtractorPass::ID = 0;
133137 RegisterPass X("extract", "Function Extractor");
134138 }
135139
2929
3030 namespace {
3131 struct VISIBILITY_HIDDEN GlobalDCE : public ModulePass {
32 static const int ID; // Pass identifcation, replacement for typeid
33 GlobalDCE() : ModulePass((intptr_t)&ID) {}
34
3235 // run - Do the GlobalDCE pass on the specified module, optionally updating
3336 // the specified callgraph to reflect the changes.
3437 //
4548 bool SafeToDestroyConstant(Constant* C);
4649 bool RemoveUnusedGlobalValue(GlobalValue &GV);
4750 };
51 const int GlobalDCE::ID = 0;
4852 RegisterPass X("globaldce", "Dead Global Elimination");
4953 }
5054
4949 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
5050 AU.addRequired();
5151 }
52 static const int ID; // Pass identifcation, replacement for typeid
53 GlobalOpt() : ModulePass((intptr_t)&ID) {}
5254
5355 bool runOnModule(Module &M);
5456
6062 bool ProcessInternalGlobal(GlobalVariable *GV,Module::global_iterator &GVI);
6163 };
6264
65 const int GlobalOpt::ID = 0;
6366 RegisterPass X("globalopt", "Global Variable Optimizer");
6467 }
6568
3232 /// IPCP - The interprocedural constant propagation pass
3333 ///
3434 struct VISIBILITY_HIDDEN IPCP : public ModulePass {
35 static const int ID; // Pass identifcation, replacement for typeid
36 IPCP() : ModulePass((intptr_t)&ID) {}
37
3538 bool runOnModule(Module &M);
3639 private:
3740 bool PropagateConstantsIntoArguments(Function &F);
3841 bool PropagateConstantReturn(Function &F);
3942 };
43 const int IPCP::ID = 0;
4044 RegisterPass X("ipconstprop", "Interprocedural constant propagation");
4145 }
4246
3131 namespace {
3232 class VISIBILITY_HIDDEN IndMemRemPass : public ModulePass {
3333 public:
34 static const int ID; // Pass identifcation, replacement for typeid
35 IndMemRemPass() : ModulePass((intptr_t)&ID) {}
36
3437 virtual bool runOnModule(Module &M);
3538 };
39 const int IndMemRemPass::ID = 0;
3640 RegisterPass X("indmemrem","Indirect Malloc and Free Removal");
3741 } // end anonymous namespace
3842
5353 class VISIBILITY_HIDDEN SimpleInliner : public Inliner {
5454 std::map CachedFunctionInfo;
5555 public:
56 static const int ID; // Pass identifcation, replacement for typeid
5657 int getInlineCost(CallSite CS);
5758 };
59 const int SimpleInliner::ID = 0;
5860 RegisterPass X("inline", "Function Integration/Inlining");
5961 }
6062
3535 cl::desc("Control the amount of inlining to perform (default = 200)"));
3636 }
3737
38 Inliner::Inliner() : InlineThreshold(InlineLimit) {}
38 const int Inliner::ID = 0;
39 Inliner::Inliner()
40 : CallGraphSCCPass((intptr_t)&ID), InlineThreshold(InlineLimit) {}
3941
4042 /// getAnalysisUsage - For this class, we declare that we require and preserve
4143 /// the call graph. If the derived class implements this method, it should
2626 /// perform the inlining operations that does not depend on the policy.
2727 ///
2828 struct Inliner : public CallGraphSCCPass {
29 static const int ID;
2930 Inliner();
3031
3132 /// getAnalysisUsage - For this class, we declare that we require and preserve
4545 std::set ExternalNames;
4646 bool DontInternalize;
4747 public:
48 static const int ID; // Pass identifcation, replacement for typeid
4849 InternalizePass(bool InternalizeEverything = true);
4950 InternalizePass(const std::vector & exportList);
5051 void LoadFile(const char *Filename);
5152 virtual bool runOnModule(Module &M);
5253 };
54 const int InternalizePass::ID = 0;
5355 RegisterPass X("internalize", "Internalize Global Symbols");
5456 } // end anonymous namespace
5557
5658 InternalizePass::InternalizePass(bool InternalizeEverything)
57 : DontInternalize(false){
59 : ModulePass((intptr_t)&ID), DontInternalize(false){
5860 if (!APIFile.empty()) // If a filename is specified, use it
5961 LoadFile(APIFile.c_str());
6062 else if (!APIList.empty()) // Else, if a list is specified, use it.
6567 }
6668
6769 InternalizePass::InternalizePass(const std::vector&exportList)
68 : DontInternalize(false){
70 : ModulePass((intptr_t)&ID), DontInternalize(false){
6971 for(std::vector::const_iterator itr = exportList.begin();
7072 itr != exportList.end(); itr++) {
7173 ExternalNames.insert(*itr);
3333 // Module passes to require FunctionPasses, so we can't get loop info if we're
3434 // not a function pass.
3535 struct VISIBILITY_HIDDEN LoopExtractor : public FunctionPass {
36 static const int ID; // Pass identifcation, replacement for typeid
3637 unsigned NumLoops;
3738
38 LoopExtractor(unsigned numLoops = ~0) : NumLoops(numLoops) {}
39 LoopExtractor(unsigned numLoops = ~0)
40 : FunctionPass((intptr_t)&ID), NumLoops(numLoops) {}
3941
4042 virtual bool runOnFunction(Function &F);
4143
4850 }
4951 };
5052
53 const int LoopExtractor::ID = 0;
5154 RegisterPass
5255 X("loop-extract", "Extract loops into new functions");
5356
5457 /// SingleLoopExtractor - For bugpoint.
5558 struct SingleLoopExtractor : public LoopExtractor {
59 static const int ID; // Pass identifcation, replacement for typeid
5660 SingleLoopExtractor() : LoopExtractor(1) {}
5761 };
5862
63 const int SingleLoopExtractor::ID = 0;
5964 RegisterPass
6065 Y("loop-extract-single", "Extract at most one loop into a new function");
6166 } // End anonymous namespace
146151 class BlockExtractorPass : public ModulePass {
147152 std::vector BlocksToNotExtract;
148153 public:
149 BlockExtractorPass(std::vector &B) : BlocksToNotExtract(B) {}
150 BlockExtractorPass() {}
154 static const int ID; // Pass identifcation, replacement for typeid
155 BlockExtractorPass(std::vector &B)
156 : ModulePass((intptr_t)&ID), BlocksToNotExtract(B) {}
157 BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
151158
152159 bool runOnModule(Module &M);
153160 };
161
162 const int BlockExtractorPass::ID = 0;
154163 RegisterPass
155164 XX("extract-blocks", "Extract Basic Blocks From Module (for bugpoint use)");
156165 }
108108
109109 bool IsTransformableFunction(const std::string& Name);
110110 public:
111 static const int ID; // Pass identifcation, replacement for typeid
112 LowerSetJmp() : ModulePass((intptr_t)&ID) {}
113
111114 void visitCallInst(CallInst& CI);
112115 void visitInvokeInst(InvokeInst& II);
113116 void visitReturnInst(ReturnInst& RI);
117120 bool doInitialization(Module& M);
118121 };
119122
123 const int LowerSetJmp::ID = 0;
120124 RegisterPass X("lowersetjmp", "Lower Set Jump");
121125 } // end anonymous namespace
122126
3434
3535 namespace {
3636 struct VISIBILITY_HIDDEN PruneEH : public CallGraphSCCPass {
37 static const int ID; // Pass identifcation, replacement for typeid
38 PruneEH() : CallGraphSCCPass((intptr_t)&ID) {}
39
3740 /// DoesNotUnwind - This set contains all of the functions which we have
3841 /// determined cannot unwind.
3942 std::set DoesNotUnwind;
4851 bool SimplifyFunction(Function *F);
4952 void DeleteBasicBlock(BasicBlock *BB);
5053 };
54
55 const int PruneEH::ID = 0;
5156 RegisterPass X("prune-eh", "Remove unused exception handling info");
5257 }
5358
3434 Function *MallocFunc; // Functions in the module we are processing
3535 Function *FreeFunc; // Initialized by doPassInitializationVirt
3636 public:
37 RaiseAllocations() : MallocFunc(0), FreeFunc(0) {}
37 static const int ID; // Pass identifcation, replacement for typeid
38 RaiseAllocations()
39 : ModulePass((intptr_t)&ID), MallocFunc(0), FreeFunc(0) {}
3840
3941 // doPassInitialization - For the raise allocations pass, this finds a
4042 // declaration for malloc and free if they exist.
4648 bool runOnModule(Module &M);
4749 };
4850
51 const int RaiseAllocations::ID = 0;
4952 RegisterPass
5053 X("raiseallocs", "Raise allocations from calls to instructions");
5154 } // end anonymous namespace
151151 /// @brief A ModulePass for optimizing well-known function calls.
152152 class VISIBILITY_HIDDEN SimplifyLibCalls : public ModulePass {
153153 public:
154 static const int ID; // Pass identifcation, replacement for typeid
155 SimplifyLibCalls() : ModulePass((intptr_t)&ID) {}
156
154157 /// We need some target data for accurate signature details that are
155158 /// target dependent. So we require target data in our AnalysisUsage.
156159 /// @brief Require TargetData from AnalysisUsage.
372375 TargetData *TD; ///< Cached TargetData
373376 };
374377
378 const int SimplifyLibCalls::ID = 0;
375379 // Register the pass
376380 RegisterPass
377381 X("simplify-libcalls", "Simplify well-known library calls");
2626 /// @brief Pass to remove unused function declarations.
2727 class VISIBILITY_HIDDEN StripDeadPrototypesPass : public ModulePass {
2828 public:
29 StripDeadPrototypesPass() { }
29 static const int ID; // Pass identifcation, replacement for typeid
30 StripDeadPrototypesPass() : ModulePass((intptr_t)&ID) { }
3031 virtual bool runOnModule(Module &M);
3132 };
33
34 const int StripDeadPrototypesPass::ID = 0;
3235 RegisterPass X("strip-dead-prototypes",
3336 "Strip Unused Function Prototypes");
3437
3636 class VISIBILITY_HIDDEN StripSymbols : public ModulePass {
3737 bool OnlyDebugInfo;
3838 public:
39 StripSymbols(bool ODI = false) : OnlyDebugInfo(ODI) {}
39 static const int ID; // Pass identifcation, replacement for typeid
40 StripSymbols(bool ODI = false)
41 : ModulePass((intptr_t)&ID), OnlyDebugInfo(ODI) {}
4042
4143 virtual bool runOnModule(Module &M);
4244
4446 AU.setPreservesAll();
4547 }
4648 };
49
50 const int StripSymbols::ID = 0;
4751 RegisterPass X("strip", "Strip all symbols from a module");
4852 }
4953
3131
3232 namespace {
3333 class VISIBILITY_HIDDEN FunctionProfiler : public RSProfilers_std {
34 public:
35 static const int ID;
3436 bool runOnModule(Module &M);
3537 };
38
39 const int FunctionProfiler::ID = 0;
3640
3741 RegisterPass X("insert-function-profiling",
3842 "Insert instrumentation for function profiling");
7882 namespace {
7983 class BlockProfiler : public RSProfilers_std {
8084 bool runOnModule(Module &M);
85 public:
86 static const int ID;
8187 };
8288
89 const int BlockProfiler::ID = 0;
8390 RegisterPass Y("insert-block-profiling",
8491 "Insert instrumentation for block profiling");
8592 RegisterAnalysisGroup YG(Y);
3131 namespace {
3232 class VISIBILITY_HIDDEN EdgeProfiler : public ModulePass {
3333 bool runOnModule(Module &M);
34 public:
35 static const int ID; // Pass identifcation, replacement for typeid
36 EdgeProfiler() : ModulePass((intptr_t)&ID) {}
3437 };
3538
39 const int EdgeProfiler::ID = 0;
3640 RegisterPass X("insert-edge-profiling",
3741 "Insert instrumentation for edge profiling");
3842 }
6868 /// measuring framework overhead
6969 class VISIBILITY_HIDDEN NullProfilerRS : public RSProfilers {
7070 public:
71 static const int ID; // Pass identifcation, replacement for typeid
7172 bool isProfiling(Value* v) {
7273 return false;
7374 }
7980 }
8081 };
8182
83 const int RSProfilers::ID = 0;
8284 static RegisterAnalysisGroup A("Profiling passes");
85 const int NullProfilerRS::ID = 0;
8386 static RegisterPass NP("insert-null-profiling-rs",
8487 "Measure profiling framework overhead");
8588 static RegisterAnalysisGroup NPT(NP);
137140
138141 /// ProfilerRS - Insert the random sampling framework
139142 struct VISIBILITY_HIDDEN ProfilerRS : public FunctionPass {
143 static const int ID; // Pass identifcation, replacement for typeid
144 ProfilerRS() : FunctionPass((intptr_t)&ID) {}
145
140146 std::map TransCache;
141147 std::set ChoicePoints;
142148 Chooser* c;
153159 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
154160 };
155161
162 const int ProfilerRS::ID = 0;
156163 RegisterPass X("insert-rs-profiling-framework",
157164 "Insert random sampling instrumentation framework");
158165 }
1616 /// RSProfilers_std - a simple support class for profilers that handles most
1717 /// of the work of chaining and tracking inserted code.
1818 struct RSProfilers_std : public RSProfilers {
19 static const int ID;
1920 std::set profcode;
2021 // Lookup up values in profcode
2122 virtual bool isProfiling(Value* v);
5151 // The public interface for this class
5252 //
5353 public:
54 static const int ID; // Pass identifcation, replacement for typeid
55 ADCE() : FunctionPass((intptr_t)&ID) {}
56
5457 // Execute the Aggressive Dead Code Elimination Algorithm
5558 //
5659 virtual bool runOnFunction(Function &F) {
103106 }
104107 };
105108
109 const int ADCE::ID = 0;
106110 RegisterPass X("adce", "Aggressive Dead Code Elimination");
107111 } // End of anonymous namespace
108112
4040
4141 namespace {
4242 struct VISIBILITY_HIDDEN BlockPlacement : public FunctionPass {
43 static const int ID; // Pass identifcation, replacement for typeid
44 BlockPlacement() : FunctionPass((intptr_t)&ID) {}
45
4346 virtual bool runOnFunction(Function &F);
4447
4548 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
6972 void PlaceBlocks(BasicBlock *BB);
7073 };
7174
75 const int BlockPlacement::ID = 0;
7276 RegisterPass X("block-placement",
7377 "Profile Guided Basic Block Placement");
7478 }
3838 /// transformation profitability.
3939 const TargetLowering *TLI;
4040 public:
41 CodeGenPrepare(const TargetLowering *tli = 0) : TLI(tli) {}
41 static const int ID; // Pass identifcation, replacement for typeid
42 CodeGenPrepare(const TargetLowering *tli = 0) : FunctionPass((intptr_t)&ID),
43 TLI(tli) {}
4244 bool runOnFunction(Function &F);
4345
4446 private:
5153 DenseMap &SunkAddrs);
5254 };
5355 }
56
57 const int CodeGenPrepare::ID = 0;
5458 static RegisterPass X("codegenprepare",
5559 "Optimize for code generation");
5660
3030
3131 namespace {
3232 struct VISIBILITY_HIDDEN CondProp : public FunctionPass {
33 static const int ID; // Pass identifcation, replacement for typeid
34 CondProp() : FunctionPass((intptr_t)&ID) {}
35
3336 virtual bool runOnFunction(Function &F);
3437
3538 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
4447 void SimplifyPredecessors(SwitchInst *SI);
4548 void RevectorBlockTo(BasicBlock *FromBB, BasicBlock *ToBB);
4649 };
50
51 const int CondProp::ID = 0;
4752 RegisterPass X("condprop", "Conditional Propagation");
4853 }
4954
3333
3434 namespace {
3535 struct VISIBILITY_HIDDEN ConstantPropagation : public FunctionPass {
36 static const int ID; // Pass identifcation, replacement for typeid
37 ConstantPropagation() : FunctionPass((intptr_t)&ID) {}
38
3639 bool runOnFunction(Function &F);
3740
3841 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
4043 }
4144 };
4245
46 const int ConstantPropagation::ID = 0;
4347 RegisterPass X("constprop",
4448 "Simple constant propagation");
4549 }
224224 std::map RegionInfoMap;
225225 ETForest *EF;
226226 public:
227 static const int ID; // Pass identifcation, replacement for typeid
228 CEE() : FunctionPass((intptr_t)&ID) {}
229
227230 virtual bool runOnFunction(Function &F);
228231
229232 // We don't modify the program, so we preserve all analyses
283286 bool SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI);
284287 bool SimplifyInstruction(Instruction *Inst, const RegionInfo &RI);
285288 };
289
290 const int CEE::ID = 0;
286291 RegisterPass X("cee", "Correlated Expression Elimination");
287292 }
288293
3434 // DeadInstElimination pass implementation
3535 //
3636 struct VISIBILITY_HIDDEN DeadInstElimination : public BasicBlockPass {
37 static const int ID; // Pass identifcation, replacement for typeid
38 DeadInstElimination() : BasicBlockPass(intptr_t(&ID)) {}
3739 virtual bool runOnBasicBlock(BasicBlock &BB) {
3840 bool Changed = false;
3941 for (BasicBlock::iterator DI = BB.begin(); DI != BB.end(); )
5052 }
5153 };
5254
55 const int DeadInstElimination::ID = 0;
5356 RegisterPass X("die", "Dead Instruction Elimination");
5457 }
5558
6366 // DeadCodeElimination pass implementation
6467 //
6568 struct DCE : public FunctionPass {
69 static const int ID; // Pass identifcation, replacement for typeid
70 DCE() : FunctionPass((intptr_t)&ID) {}
71
6672 virtual bool runOnFunction(Function &F);
6773
6874 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
7076 }
7177 };
7278
79 const int DCE::ID = 0;
7380 RegisterPass Y("dce", "Dead Code Elimination");
7481 }
7582
3333
3434 namespace {
3535 struct VISIBILITY_HIDDEN DSE : public FunctionPass {
36 static const int ID; // Pass identifcation, replacement for typeid
37 DSE() : FunctionPass((intptr_t)&ID) {}
3638
3739 virtual bool runOnFunction(Function &F) {
3840 bool Changed = false;
5557 AU.addPreserved();
5658 }
5759 };
60 const int DSE::ID = 0;
5861 RegisterPass X("dse", "Dead Store Elimination");
5962 }
6063
3636 "with constant values");
3737 namespace {
3838 struct VISIBILITY_HIDDEN GCSE : public FunctionPass {
39 static const int ID; // Pass identifcation, replacement for typeid
40 GCSE() : FunctionPass((intptr_t)&ID) {}
41
3942 virtual bool runOnFunction(Function &F);
4043
4144 private:
5053 }
5154 };
5255
56 const int GCSE::ID = 0;
5357 RegisterPass X("gcse", "Global Common Subexpression Elimination");
5458 }
5559
6767 ScalarEvolution *SE;
6868 bool Changed;
6969 public:
70
70
71 static const int ID; // Pass identifcation, replacement for typeid
72 IndVarSimplify() : LoopPass((intptr_t)&ID) {}
73
7174 bool runOnLoop(Loop *L, LPPassManager &LPM);
7275 bool doInitialization(Loop *L, LPPassManager &LPM);
7376 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
9093
9194 void DeleteTriviallyDeadInstructions(std::set &Insts);
9295 };
96
97 const int IndVarSimplify::ID = 0;
9398 RegisterPass X("indvars", "Canonicalize Induction Variables");
9499 }
95100
7575 TargetData *TD;
7676 bool MustPreserveLCSSA;
7777 public:
78 static const int ID; // Pass identifcation, replacement for typeid
79 InstCombiner() : FunctionPass((intptr_t)&ID) {}
80
7881 /// AddToWorkList - Add the specified instruction to the worklist if it
7982 /// isn't already in it.
8083 void AddToWorkList(Instruction *I) {
357360 Value *EvaluateInDifferentType(Value *V, const Type *Ty, bool isSigned);
358361 };
359362
363 const int InstCombiner::ID = 0;
360364 RegisterPass X("instcombine", "Combine redundant instructions");
361365 }
362366
6262 cl::desc("Disable memory promotion in LICM pass"));
6363
6464 struct VISIBILITY_HIDDEN LICM : public LoopPass {
65 static const int ID; // Pass identifcation, replacement for typeid
66 LICM() : LoopPass((intptr_t)&ID) {}
67
6568 virtual bool runOnLoop(Loop *L, LPPassManager &LPM);
6669
6770 /// This transformation requires natural loop information & requires that
200203 std::map &Val2AlMap);
201204 };
202205
206 const int LICM::ID = 0;
203207 RegisterPass X("licm", "Loop Invariant Code Motion");
204208 }
205209
4343 class VISIBILITY_HIDDEN LoopRotate : public LoopPass {
4444
4545 public:
46
46 static const int ID; // Pass ID, replacement for typeid
47 LoopRotate() : LoopPass((intptr_t)&ID) {}
48
4749 // Rotate Loop L as many times as possible. Return true if
4850 // loop is rotated at least once.
4951 bool runOnLoop(Loop *L, LPPassManager &LPM);
9193 SmallVector LoopHeaderInfo;
9294 };
9395
96 const int LoopRotate::ID = 0;
9497 RegisterPass X ("loop-rotate", "Rotate Loops");
9598 }
9699
142142 const TargetLowering *TLI;
143143
144144 public:
145 LoopStrengthReduce(const TargetLowering *tli = NULL) : TLI(tli) {
145 static const int ID; // Pass ID, replacement for typeid
146 LoopStrengthReduce(const TargetLowering *tli = NULL) :
147 LoopPass((intptr_t)&ID), TLI(tli) {
146148 }
147149
148150 bool runOnLoop(Loop *L, LPPassManager &LPM);
185187 Loop *L, bool isOnlyStride);
186188 void DeleteTriviallyDeadInstructions(std::set &Insts);
187189 };
190 const int LoopStrengthReduce::ID = 0;
188191 RegisterPass X("loop-reduce", "Loop Strength Reduction");
189192 }
190193
4848 class VISIBILITY_HIDDEN LoopUnroll : public LoopPass {
4949 LoopInfo *LI; // The current loop information
5050 public:
51 static const int ID; // Pass ID, replacement for typeid
52 LoopUnroll() : LoopPass((intptr_t)&ID) {}
53
5154 bool runOnLoop(Loop *L, LPPassManager &LPM);
5255 BasicBlock* FoldBlockIntoPredecessor(BasicBlock* BB);
5356
6265 AU.addPreserved();
6366 }
6467 };
68 const int LoopUnroll::ID = 0;
6569 RegisterPass X("loop-unroll", "Unroll loops");
6670 }
6771
6868 SmallPtrSet UnswitchedVals;
6969
7070 public:
71 static const int ID; // Pass ID, replacement for typeid
72 LoopUnswitch() : LoopPass((intptr_t)&ID) {}
73
7174 bool runOnLoop(Loop *L, LPPassManager &LPM);
7275
7376 /// This transformation requires natural loop information & requires that
108111 std::vector &Worklist);
109112 void RemoveLoopFromHierarchy(Loop *L);
110113 };
114 const int LoopUnswitch::ID = 0;
111115 RegisterPass X("loop-unswitch", "Unswitch loops");
112116 }
113117
4646 /// had zero roots.
4747 const Type *MainRootRecordType;
4848 public:
49 LowerGC() : GCRootInt(0), GCReadInt(0), GCWriteInt(0),
49 static const int ID; // Pass identifcation, replacement for typeid
50 LowerGC() : FunctionPass((intptr_t)&ID),
51 GCRootInt(0), GCReadInt(0), GCWriteInt(0),
5052 GCRead(0), GCWrite(0), RootChain(0), MainRootRecordType(0) {}
5153 virtual bool doInitialization(Module &M);
5254 virtual bool runOnFunction(Function &F);
5557 const StructType *getRootRecordType(unsigned NumRoots);
5658 };
5759
60 const int LowerGC::ID = 0;
5861 RegisterPass
5962 X("lowergc", "Lower GC intrinsics, for GCless code generators");
6063 }
3939 class VISIBILITY_HIDDEN LowerPacked
4040 : public FunctionPass, public InstVisitor {
4141 public:
42 static const int ID; // Pass identifcation, replacement for typeid
43 LowerPacked() : FunctionPass((intptr_t)&ID) {}
44
4245 /// @brief Lowers packed operations to scalar operations.
4346 /// @param F The fuction to process
4447 virtual bool runOnFunction(Function &F);
103106 std::vector instrsToRemove;
104107 };
105108
109 const int LowerPacked::ID = 0;
106110 RegisterPass
107111 X("lower-packed",
108112 "lowers packed operations to operations on smaller packed datatypes");
19881988 std::vector WorkList;
19891989
19901990 public:
1991 static const int ID; // Pass identifcation, replacement for typeid
1992 PredicateSimplifier() : FunctionPass((intptr_t)&ID) {}
1993
19911994 bool runOnFunction(Function &F);
19921995
19931996 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
23732376 }
23742377 }
23752378
2379 const int PredicateSimplifier::ID = 0;
23762380 RegisterPass X("predsimplify",
23772381 "Predicate Simplifier");
23782382 }
6868 std::map ValueRankMap;
6969 bool MadeChange;
7070 public:
71 static const int ID; // Pass identifcation, replacement for typeid
72 Reassociate() : FunctionPass((intptr_t)&ID) {}
73
7174 bool runOnFunction(Function &F);
7275
7376 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
8891 void RemoveDeadBinaryOp(Value *V);
8992 };
9093
94 const int Reassociate::ID = 0;
9195 RegisterPass X("reassociate", "Reassociate expressions");
9296 }
9397
3232
3333 namespace {
3434 struct VISIBILITY_HIDDEN RegToMem : public FunctionPass {
35 static const int ID; // Pass identifcation, replacement for typeid
36 RegToMem() : FunctionPass((intptr_t)&ID) {}
3537
3638 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
3739 AU.addRequiredID(BreakCriticalEdgesID);
7577 }
7678 };
7779
80 const int RegToMem::ID = 0;
7881 RegisterPass X("reg2mem", "Demote all values to stack slots");
7982 }
8083
13331333 /// Sparse Conditional Constant Propagator.
13341334 ///
13351335 struct VISIBILITY_HIDDEN SCCP : public FunctionPass {
1336 static const int ID; // Pass identifcation, replacement for typeid
1337 SCCP() : FunctionPass((intptr_t)&ID) {}
1338
13361339 // runOnFunction - Run the Sparse Conditional Constant Propagation
13371340 // algorithm, and return true if the function was modified.
13381341 //
13431346 }
13441347 };
13451348
1349 const int SCCP::ID = 0;
13461350 RegisterPass X("sccp", "Sparse Conditional Constant Propagation");
13471351 } // end anonymous namespace
13481352
14421446 /// Constant Propagation.
14431447 ///
14441448 struct VISIBILITY_HIDDEN IPSCCP : public ModulePass {
1449 static const int ID;
1450 IPSCCP() : ModulePass((intptr_t)&ID) {}
14451451 bool runOnModule(Module &M);
14461452 };
14471453
1454 const int IPSCCP::ID = 0;
14481455 RegisterPass
14491456 Y("ipsccp", "Interprocedural Sparse Conditional Constant Propagation");
14501457 } // end anonymous namespace
4646
4747 namespace {
4848 struct VISIBILITY_HIDDEN SROA : public FunctionPass {
49 static const int ID; // Pass identifcation, replacement for typeid
50 SROA() : FunctionPass((intptr_t)&ID) {}
51
4952 bool runOnFunction(Function &F);
5053
5154 bool performScalarRepl(Function &F);
8083 static Instruction *isOnlyCopiedFromConstantGlobal(AllocationInst *AI);
8184 };
8285
86 const int SROA::ID = 0;
8387 RegisterPass X("scalarrepl", "Scalar Replacement of Aggregates");
8488 }
8589
3434
3535 namespace {
3636 struct VISIBILITY_HIDDEN CFGSimplifyPass : public FunctionPass {
37 static const int ID; // Pass identifcation, replacement for typeid
38 CFGSimplifyPass() : FunctionPass((intptr_t)&ID) {}
39
3740 virtual bool runOnFunction(Function &F);
3841 };
42 const int CFGSimplifyPass::ID = 0;
3943 RegisterPass X("simplifycfg", "Simplify the CFG");
4044 }
4145
4141 cl::init(6), cl::Hidden);
4242 class VISIBILITY_HIDDEN TailDup : public FunctionPass {
4343 bool runOnFunction(Function &F);
44 public:
45 static const int ID; // Pass identifcation, replacement for typeid
46 TailDup() : FunctionPass((intptr_t)&ID) {}
47
4448 private:
4549 inline bool shouldEliminateUnconditionalBranch(TerminatorInst *TI);
4650 inline void eliminateUnconditionalBranch(BranchInst *BI);
4751 };
52 const int TailDup::ID = 0;
4853 RegisterPass X("tailduplicate", "Tail Duplication");
4954 }
5055
6666
6767 namespace {
6868 struct VISIBILITY_HIDDEN TailCallElim : public FunctionPass {
69 static const int ID; // Pass identifcation, replacement for typeid
70 TailCallElim() : FunctionPass((intptr_t)&ID) {}
71
6972 virtual bool runOnFunction(Function &F);
7073
7174 private:
7679 bool CanMoveAboveCall(Instruction *I, CallInst *CI);
7780 Value *CanTransformAccumulatorRecursion(Instruction *I, CallInst *CI);
7881 };
82 const int TailCallElim::ID = 0;
7983 RegisterPass X("tailcallelim", "Tail Call Elimination");
8084 }
8185
3333
3434 namespace {
3535 struct VISIBILITY_HIDDEN BreakCriticalEdges : public FunctionPass {
36 static const int ID; // Pass identifcation, replacement for typeid
37 BreakCriticalEdges() : FunctionPass((intptr_t)&ID) {}
38
3639 virtual bool runOnFunction(Function &F);
3740
3841 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
4649 }
4750 };
4851
52 const int BreakCriticalEdges::ID = 0;
4953 RegisterPass X("break-crit-edges",
5054 "Break critical edges in CFG");
5155 }
4646
4747 namespace {
4848 struct VISIBILITY_HIDDEN LCSSA : public FunctionPass {
49 static const int ID; // Pass identifcation, replacement for typeid
50 LCSSA() : FunctionPass((intptr_t)&ID) {}
51
4952 // Cached analysis information for the current function.
5053 LoopInfo *LI;
5154 DominatorTree *DT;
8083 }
8184 };
8285
86 const int LCSSA::ID = 0;
8387 RegisterPass X("lcssa", "Loop-Closed SSA Form Pass");
8488 }
8589
5353
5454 namespace {
5555 struct VISIBILITY_HIDDEN LoopSimplify : public FunctionPass {
56 static const int ID; // Pass identifcation, replacement for typeid
57 LoopSimplify() : FunctionPass((intptr_t)&ID) {}
58
5659 // AA - If we have an alias analysis object to update, this is it, otherwise
5760 // this is null.
5861 AliasAnalysis *AA;
8891 std::vector &PredBlocks);
8992 };
9093
94 const int LoopSimplify::ID = 0;
9195 RegisterPass
9296 X("loopsimplify", "Canonicalize natural loops", true);
9397 }
3535 Constant *FreeFunc; // Initialized by doInitialization
3636 bool LowerMallocArgToInteger;
3737 public:
38 static const int ID; // Pass ID, replacement for typeid
3839 LowerAllocations(bool LowerToInt = false)
39 : MallocFunc(0), FreeFunc(0), LowerMallocArgToInteger(LowerToInt) {}
40 : BasicBlockPass((intptr_t)&ID), MallocFunc(0), FreeFunc(0),
41 LowerMallocArgToInteger(LowerToInt) {}
4042
4143 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
4244 AU.addRequired();
6567 bool runOnBasicBlock(BasicBlock &BB);
6668 };
6769
70 const int LowerAllocations::ID = 0;
6871 RegisterPass
6972 X("lowerallocs", "Lower allocations from instructions to calls");
7073 }
7474 const TargetLowering *TLI;
7575
7676 public:
77 LowerInvoke(const TargetLowering *tli = NULL) : TLI(tli) { }
77 static const int ID; // Pass identifcation, replacement for typeid
78 LowerInvoke(const TargetLowering *tli = NULL) : FunctionPass((intptr_t)&ID),
79 TLI(tli) { }
7880 bool doInitialization(Module &M);
7981 bool runOnFunction(Function &F);
8082
9698 bool insertExpensiveEHSupport(Function &F);
9799 };
98100
101 const int LowerInvoke::ID = 0;
99102 RegisterPass
100103 X("lowerinvoke", "Lower invoke and unwind, for unwindless code generators");
101104 }
3232 class VISIBILITY_HIDDEN LowerSelect : public FunctionPass {
3333 bool OnlyFP; // Only lower FP select instructions?
3434 public:
35 LowerSelect(bool onlyfp = false) : OnlyFP(onlyfp) {}
35 static const int ID; // Pass identifcation, replacement for typeid
36 LowerSelect(bool onlyfp = false) : FunctionPass((intptr_t)&ID),
37 OnlyFP(onlyfp) {}
3638
3739 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
3840 // This certainly destroys the CFG.
4749 bool runOnFunction(Function &F);
4850 };
4951
52 const int LowerSelect::ID = 0;
5053 RegisterPass
5154 X("lowerselect", "Lower select instructions to branches");
5255 }
2929 /// modifies the CFG!
3030 class VISIBILITY_HIDDEN LowerSwitch : public FunctionPass {
3131 public:
32 static const int ID; // Pass identifcation, replacement for typeid
33 LowerSwitch() : FunctionPass((intptr_t) &ID) {}
34
3235 virtual bool runOnFunction(Function &F);
3336
3437 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
7477 }
7578 };
7679
80 const int LowerSwitch::ID = 0;
7781 RegisterPass
7882 X("lowerswitch", "Lower SwitchInst's to branches");
7983 }
2626
2727 namespace {
2828 struct VISIBILITY_HIDDEN PromotePass : public FunctionPass {
29 static const int ID; // Pass identifcation, replacement for typeid
30 PromotePass() : FunctionPass((intptr_t)&ID) {}
31
2932 // runOnFunction - To run this pass, first we calculate the alloca
3033 // instructions that are safe for promotion, then we promote each one.
3134 //
4649 }
4750 };
4851
52 const int PromotePass::ID = 0;
4953 RegisterPass X("mem2reg", "Promote Memory to Register");
5054 } // end of anonymous namespace
5155
2121 #include "llvm/Type.h"
2222 using namespace llvm;
2323
24 const int UnifyFunctionExitNodes::ID = 0;
2425 static RegisterPass
2526 X("mergereturn", "Unify function exit nodes");
2627
134134
135135 } // end namespace llvm
136136
137 const int PrintModulePass::ID = 0;
137138 static RegisterPass
138139 X("printm", "Print module to stderr");
140 const int PrintFunctionPass::ID = 0;
139141 static RegisterPass
140142 Y("print","Print function to stderr");
141143
5757 //
5858 //===----------------------------------------------------------------------===//
5959
60 const int DominatorTree::ID = 0;
6061 static RegisterPass
6162 E("domtree", "Dominator Tree Construction", true);
6263
352353 // DominanceFrontier Implementation
353354 //===----------------------------------------------------------------------===//
354355
356 const int DominanceFrontier::ID = 0;
355357 static RegisterPass
356358 G("domfrontier", "Dominance Frontier Construction", true);
357359
832834 // ETForest implementation
833835 //===----------------------------------------------------------------------===//
834836
837 const int ETForest::ID = 0;
835838 static RegisterPass
836839 D("etforest", "ET Forest Construction", true);
837840
132132 class PassRegistrar {
133133 /// PassInfoMap - Keep track of the passinfo object for each registered llvm
134134 /// pass.
135 std::map<TypeInfo, PassInfo*> PassInfoMap;
135 std::map<intptr_t, PassInfo*> PassInfoMap;
136136
137137 /// AnalysisGroupInfo - Keep track of information for each analysis group.
138138 struct AnalysisGroupInfo {
146146
147147 public:
148148
149 const PassInfo *GetPassInfo(const std::type_info &TI) const {
150 std::map::const_iterator I = PassInfoMap.find(TI);
149 const PassInfo *GetPassInfo(intptr_t TI) const {
150 std::map::const_iterator I = PassInfoMap.find(TI);
151151 return I != PassInfoMap.end() ? I->second : 0;
152152 }
153153
154154 void RegisterPass(PassInfo &PI) {
155155 bool Inserted =
156 PassInfoMap.insert(std::make_pair(TypeInfo(PI.getTypeInfo()),&PI)).second;
156 PassInfoMap.insert(std::make_pair(PI.getTypeInfo(),&PI)).second;
157157 assert(Inserted && "Pass registered multiple times!");
158158 }
159159
160160 void UnregisterPass(PassInfo &PI) {
161 std::map<TypeInfo, PassInfo*>::iterator I =
161 std::map<intptr_t, PassInfo*>::iterator I =
162162 PassInfoMap.find(PI.getTypeInfo());
163163 assert(I != PassInfoMap.end() && "Pass registered but not in map!");
164164
167167 }
168168
169169 void EnumerateWith(PassRegistrationListener *L) {
170 for (std::map<TypeInfo, PassInfo*>::const_iterator I = PassInfoMap.begin(),
170 for (std::map<intptr_t, PassInfo*>::const_iterator I = PassInfoMap.begin(),
171171 E = PassInfoMap.end(); I != E; ++I)
172172 L->passEnumerate(I->second);
173173 }
209209 // getPassInfo - Return the PassInfo data structure that corresponds to this
210210 // pass...
211211 const PassInfo *Pass::getPassInfo() const {
212 if (PassInfoCache) return PassInfoCache;
213 return lookupPassInfo(typeid(*this));
214 }
215
216 const PassInfo *Pass::lookupPassInfo(const std::type_info &TI) {
212 return lookupPassInfo(PassID);
213 }
214
215 const PassInfo *Pass::lookupPassInfo(intptr_t TI) {
217216 return getPassRegistrar()->GetPassInfo(TI);
218217 }
219218
237236
238237 // RegisterAGBase implementation
239238 //
240 RegisterAGBase::RegisterAGBase(const std::type_info &Interface,
241 const std::type_info *Pass, bool isDefault)
242 : RegisterPassBase(Interface),
239 RegisterAGBase::RegisterAGBase(intptr_t InterfaceID,
240 intptr_t PassID, bool isDefault)
241 : RegisterPassBase(InterfaceID),
243242 ImplementationInfo(0), isDefaultImplementation(isDefault) {
244243
245 InterfaceInfo = const_cast(Pass::lookupPassInfo(Interface));
244 InterfaceInfo = const_cast(Pass::lookupPassInfo(InterfaceID));
246245 if (InterfaceInfo == 0) {
247246 // First reference to Interface, register it now.
248247 registerPass();
251250 assert(PIObj.isAnalysisGroup() &&
252251 "Trying to join an analysis group that is a normal pass!");
253252
254 if (Pass) {
255 ImplementationInfo = Pass::lookupPassInfo(*Pass);
253 if (PassID) {
254 ImplementationInfo = Pass::lookupPassInfo(PassID);
256255 assert(ImplementationInfo &&
257256 "Must register pass before adding to AnalysisGroup!");
258257
6262 public FunctionPass {
6363
6464 public:
65 BBPassManager(int Depth) : PMDataManager(Depth) { }
65 static const int ID;
66 BBPassManager(int Depth)
67 : PMDataManager(Depth), FunctionPass((intptr_t)&ID) {}
6668
6769 /// Execute all of the passes scheduled for execution. Keep track of
6870 /// whether any of the passes modifies the function, and if so, return true.
103105 }
104106 };
105107
108 const int BBPassManager::ID = 0;
106109 }
107110
108111 namespace llvm {
115118 public PMDataManager,
116119 public PMTopLevelManager {
117120 public:
118
119 FunctionPassManagerImpl(int Depth) : PMDataManager(Depth),
120 PMTopLevelManager(TLM_Function) { }
121 static const int ID;
122 FunctionPassManagerImpl(int Depth) :
123 Pass((intptr_t)&ID), PMDataManager(Depth),
124 PMTopLevelManager(TLM_Function) { }
121125
122126 /// add - Add a pass to the queue of passes to run. This passes ownership of
123127 /// the Pass to the PassManager. When the PassManager is destroyed, the pass
166170 FPPassManager *FP = static_cast(PassManagers[N]);
167171 return FP;
168172 }
169
170173 };
171174
175 const int FunctionPassManagerImpl::ID = 0;
172176 //===----------------------------------------------------------------------===//
173177 // MPPassManager
174178 //
178182 class MPPassManager : public Pass, public PMDataManager {
179183
180184 public:
181 MPPassManager(int Depth) : PMDataManager(Depth) { }
185 static const int ID;
186 MPPassManager(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth) { }
182187
183188 // Delete on the fly managers.
184189 virtual ~MPPassManager() {
241246 std::map OnTheFlyManagers;
242247 };
243248
249 const int MPPassManager::ID = 0;
244250 //===----------------------------------------------------------------------===//
245251 // PassManagerImpl
246252 //
253
247254 /// PassManagerImpl manages MPPassManagers
248255 class PassManagerImpl : public Pass,
249256 public PMDataManager,
250257 public PMTopLevelManager {
251258
252259 public:
253
254 PassManagerImpl(int Depth) : PMDataManager(Depth),
260 static const int ID;
261 PassManagerImpl(int Depth) : Pass((intptr_t)&ID), PMDataManager(Depth),
255262 PMTopLevelManager(TLM_Pass) { }
256263
257264 /// add - Add a pass to the queue of passes to run. This passes ownership of
296303
297304 };
298305
306 const int PassManagerImpl::ID = 0;
299307 } // End of llvm namespace
300308
301309 namespace {
10991107 //===----------------------------------------------------------------------===//
11001108 // FPPassManager implementation
11011109
1110 const int FPPassManager::ID = 0;
11021111 /// Print passes managed by this manager
11031112 void FPPassManager::dumpPassStructure(unsigned Offset) {
11041113 llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
6868
6969 struct VISIBILITY_HIDDEN
7070 Verifier : public FunctionPass, InstVisitor {
71 static const int ID; // Pass ID, replacement for typeid
7172 bool Broken; // Is this module found to be broken?
7273 bool RealPass; // Are we not being run by a PassManager?
7374 VerifierFailureAction action;
8384 SmallPtrSet InstsInThisBlock;
8485
8586 Verifier()
86 : Broken(false), RealPass(true), action(AbortProcessAction),
87 EF(0), msgs( std::ios::app | std::ios::out ) {}
87 : FunctionPass((intptr_t)&ID),
88 Broken(false), RealPass(true), action(AbortProcessAction),
89 EF(0), msgs( std::ios::app | std::ios::out ) {}
8890 Verifier( VerifierFailureAction ctn )
89 : Broken(false), RealPass(true), action(ctn), EF(0),
90 msgs( std::ios::app | std::ios::out ) {}
91 : FunctionPass((intptr_t)&ID),
92 Broken(false), RealPass(true), action(ctn), EF(0),
93 msgs( std::ios::app | std::ios::out ) {}
9194 Verifier(bool AB )
92 : Broken(false), RealPass(true),
93 action( AB ? AbortProcessAction : PrintMessageAction), EF(0),
94 msgs( std::ios::app | std::ios::out ) {}
95 : FunctionPass((intptr_t)&ID),
96 Broken(false), RealPass(true),
97 action( AB ? AbortProcessAction : PrintMessageAction), EF(0),
98 msgs( std::ios::app | std::ios::out ) {}
9599 Verifier(ETForest &ef)
96 : Broken(false), RealPass(false), action(PrintMessageAction),
97 EF(&ef), msgs( std::ios::app | std::ios::out ) {}
100 : FunctionPass((intptr_t)&ID),
101 Broken(false), RealPass(false), action(PrintMessageAction),
102 EF(&ef), msgs( std::ios::app | std::ios::out ) {}
98103
99104
100105 bool doInitialization(Module &M) {
260265 }
261266 };
262267
268 const int Verifier::ID = 0;
263269 RegisterPass X("verify", "Module Verifier");
264270 } // End anonymous namespace
265271
304304 /// BlocksToNotExtract list.
305305 class BlockExtractorPass : public ModulePass {
306306 bool runOnModule(Module &M);
307 public:
308 static const int ID; // Pass ID, replacement for typeid
309 BlockExtractorPass() : ModulePass((intptr_t)&ID) {}
307310 };
311 const int BlockExtractorPass::ID = 0;
308312 RegisterPass
309313 XX("extract-bbs", "Extract Basic Blocks From Module (for bugpoint use)");
310314 }
2424 /// CrashOnCalls - This pass is used to test bugpoint. It intentionally
2525 /// crashes on any call instructions.
2626 class CrashOnCalls : public BasicBlockPass {
27 public:
28 static const int ID; // Pass ID, replacement for typeid
29 CrashOnCalls() : BasicBlockPass((intptr_t)&ID) {}
30 private:
2731 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
2832 AU.setPreservesAll();
2933 }
3741 }
3842 };
3943
44 const int CrashOnCalls::ID = 0;
4045 RegisterPass
4146 X("bugpoint-crashcalls",
4247 "BugPoint Test Pass - Intentionally crash on CallInsts");
4651 /// DeleteCalls - This pass is used to test bugpoint. It intentionally
4752 /// deletes some call instructions, "misoptimizing" the program.
4853 class DeleteCalls : public BasicBlockPass {
54 public:
55 static const int ID; // Pass ID, replacement for typeid
56 DeleteCalls() : BasicBlockPass((intptr_t)&ID) {}
57 private:
4958 bool runOnBasicBlock(BasicBlock &BB) {
5059 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I)
5160 if (CallInst *CI = dyn_cast(I)) {
5766 return false;
5867 }
5968 };
60
69
70 const int DeleteCalls::ID = 0;
6171 RegisterPass
6272 Y("bugpoint-deletecalls",
6373 "BugPoint Test Pass - Intentionally 'misoptimize' CallInsts");
2929 /// useful when looking for standard library functions we should constant fold
3030 /// or handle in alias analyses.
3131 struct ExternalFunctionsPassedConstants : public ModulePass {
32 static const int ID; // Pass ID, replacement for typeid
33 ExternalFunctionsPassedConstants() : ModulePass((intptr_t)&ID) {}
3234 virtual bool runOnModule(Module &M) {
3335 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
3436 if (I->isDeclaration()) {
6062 }
6163 };
6264
65 const int ExternalFunctionsPassedConstants::ID = 0;
6366 RegisterPass
6467 P1("externalfnconstants", "Print external fn callsites passed constants");
6568
6669 struct CallGraphPrinter : public ModulePass {
70 static const int ID; // Pass ID, replacement for typeid
71 CallGraphPrinter() : ModulePass((intptr_t)&ID) {}
72
6773 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
6874 AU.setPreservesAll();
6975 AU.addRequiredTransitive();
7581 }
7682 };
7783
84 const int CallGraphPrinter::ID = 0;
7885 RegisterPass
7986 P2("callgraph", "Print a call graph");
8087 }
5959
6060 namespace {
6161 struct CallGraphPrinter : public ModulePass {
62 static const int ID; // Pass ID, replacement for typeid
63 CallGraphPrinter() : ModulePass((intptr_t)&ID) {}
64
6265 virtual bool runOnModule(Module &M) {
6366 WriteGraphToFile(std::cerr, "callgraph", &getAnalysis());
6467 return false;
7376 }
7477 };
7578
79 const int CallGraphPrinter::ID = 0;
7680 RegisterPass P2("print-callgraph",
7781 "Print Call Graph to 'dot' file");
7882 }
3434
3535 namespace {
3636 struct CFGSCC : public FunctionPass {
37 static const int ID; // Pass identification, replacement for typeid
38 CFGSCC() : FunctionPass((intptr_t)&ID) {}
3739 bool runOnFunction(Function& func);
3840
3941 void print(std::ostream &O, const Module* = 0) const { }
4446 };
4547
4648 struct CallGraphSCC : public ModulePass {
49 static const int ID; // Pass identification, replacement for typeid
50 CallGraphSCC() : ModulePass((intptr_t)&ID) {}
51
4752 // run - Print out SCCs in the call graph for the specified module.
4853 bool runOnModule(Module &M);
4954
5661 }
5762 };
5863
64 const int CFGSCC::ID = 0;
5965 RegisterPass
6066 Y("cfgscc", "Print SCCs of each function CFG");
6167
68 const int CallGraphSCC::ID = 0;
6269 RegisterPass
6370 Z("callscc", "Print SCCs of the Call Graph");
6471 }
9797 namespace {
9898
9999 struct ModulePassPrinter : public ModulePass {
100 static const int ID;
100101 const PassInfo *PassToPrint;
101 ModulePassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
102 ModulePassPrinter(const PassInfo *PI) : ModulePass((intptr_t)&ID),
103 PassToPrint(PI) {}
102104
103105 virtual bool runOnModule(Module &M) {
104106 if (!Quiet) {
118120 }
119121 };
120122
123 const int ModulePassPrinter::ID = 0;
121124 struct FunctionPassPrinter : public FunctionPass {
122125 const PassInfo *PassToPrint;
123 FunctionPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
126 static const int ID;
127 FunctionPassPrinter(const PassInfo *PI) : FunctionPass((intptr_t)&ID),
128 PassToPrint(PI) {}
124129
125130 virtual bool runOnFunction(Function &F) {
126 if (!Quiet) {
131 if (!Quiet) {
127132 cout << "Printing analysis '" << PassToPrint->getPassName()
128133 << "' for function '" << F.getName() << "':\n";
129134 }
140145 }
141146 };
142147
148 const int FunctionPassPrinter::ID = 0;
143149 struct BasicBlockPassPrinter : public BasicBlockPass {
144150 const PassInfo *PassToPrint;
145 BasicBlockPassPrinter(const PassInfo *PI) : PassToPrint(PI) {}
151 static const int ID;