llvm.org GIT mirror llvm / eb577ba
Final polish on machine pass registries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29471 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 14 years ago
10 changed file(s) with 98 addition(s) and 229 deletion(s). Raw diff Collapse all Expand all
2323
2424 namespace llvm {
2525
26 typedef void *(*MachinePassCtor)();
27
2628
2729 //===----------------------------------------------------------------------===//
2830 ///
3436 public:
3537 MachinePassRegistryListener() {}
3638 virtual ~MachinePassRegistryListener() {}
37 virtual void NotifyAdd(const char *N, const char *D) = 0;
38 virtual void NotifyRemove(const char *N, const char *D) = 0;
39 virtual void NotifyAdd(const char *N, MachinePassCtor C, const char *D) = 0;
40 virtual void NotifyRemove(const char *N) = 0;
3941 };
4042
4143
4446 /// MachinePassRegistryNode - Machine pass node stored in registration list.
4547 ///
4648 //===----------------------------------------------------------------------===//
47 template
4849 class MachinePassRegistryNode {
4950
5051 private:
5152
52 MachinePassRegistryNode *Next;// Next function pass in list.
53 MachinePassRegistryNode *Next; // Next function pass in list.
5354 const char *Name; // Name of function pass.
5455 const char *Description; // Description string.
55 FunctionPassCtor Ctor; // Function pass creator.
56 MachinePassCtor Ctor; // Function pass creator.
5657
5758 public:
5859
59 MachinePassRegistryNode(const char *N, const char *D, FunctionPassCtor C)
60 MachinePassRegistryNode(const char *N, const char *D, MachinePassCtor C)
6061 : Next(NULL)
6162 , Name(N)
6263 , Description(D)
6465 {}
6566
6667 // Accessors
67 MachinePassRegistryNode *getNext()
68 const { return Next; }
69 MachinePassRegistryNode **getNextAddress()
70 { return &Next; }
68 MachinePassRegistryNode *getNext() const { return Next; }
69 MachinePassRegistryNode **getNextAddress() { return &Next; }
7170 const char *getName() const { return Name; }
7271 const char *getDescription() const { return Description; }
73 FunctionPassCtor getCtor() const { return Ctor; }
74 void setNext(MachinePassRegistryNode *N) { Next = N; }
72 MachinePassCtor getCtor() const { return Ctor; }
73 void setNext(MachinePassRegistryNode *N) { Next = N; }
7574
7675 };
7776
8180 /// MachinePassRegistry - Track the registration of machine passes.
8281 ///
8382 //===----------------------------------------------------------------------===//
84 template
8583 class MachinePassRegistry {
8684
8785 private:
8886
89 MachinePassRegistryNode *List;
90 // List of registry nodes.
91 FunctionPassCtor Default; // Default function pass creator.
87 MachinePassRegistryNode *List; // List of registry nodes.
88 MachinePassCtor Default; // Default function pass creator.
9289 MachinePassRegistryListener* Listener;// Listener for list adds are removes.
9390
9491 public:
9895
9996 // Accessors.
10097 //
101 MachinePassRegistryNode *getList() { return List; }
102 FunctionPassCtor getDefault() { return Default; }
103 void setDefault(FunctionPassCtor C) { Default = C; }
98 MachinePassRegistryNode *getList() { return List; }
99 MachinePassCtor getDefault() { return Default; }
100 void setDefault(MachinePassCtor C) { Default = C; }
104101 void setListener(MachinePassRegistryListener *L) { Listener = L; }
105102
106103 /// Add - Adds a function pass to the registration list.
107104 ///
108 void Add(MachinePassRegistryNode *Node) {
109 Node->setNext(List);
110 List = Node;
111 if (Listener) Listener->NotifyAdd(Node->getName(), Node->getDescription());
112 }
113
105 void Add(MachinePassRegistryNode *Node);
114106
115107 /// Remove - Removes a function pass from the registration list.
116108 ///
117 void Remove(MachinePassRegistryNode *Node) {
118 for (MachinePassRegistryNode **I = &List;
119 *I; I = (*I)->getNextAddress()) {
120 if (*I == Node) {
121 if (Listener) Listener->NotifyRemove(Node->getName(),
122 Node->getDescription());
123 *I = (*I)->getNext();
124 break;
125 }
126 }
127 }
109 void Remove(MachinePassRegistryNode *Node);
128110
129
130 /// FInd - Finds and returns a function pass in registration list, otherwise
131 /// returns NULL.
132 MachinePassRegistryNode *Find(const char *Name) {
133 for (MachinePassRegistryNode *I = List;
134 I; I = I->getNext()) {
135 if (std::string(Name) == std::string(I->getName())) return I;
136 }
137 return NULL;
138 }
139
140
141 };
142
143
144 //===----------------------------------------------------------------------===//
145 ///
146 /// RegisterRegAlloc class - Track the registration of register allocators.
147 ///
148 //===----------------------------------------------------------------------===//
149 class RegisterRegAlloc : public MachinePassRegistryNode {
150
151 public:
152
153 typedef FunctionPass *(*FunctionPassCtor)();
154
155 static MachinePassRegistry Registry;
156
157 RegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
158 : MachinePassRegistryNode(N, D, C)
159 { Registry.Add(this); }
160 ~RegisterRegAlloc() { Registry.Remove(this); }
161
162
163 // Accessors.
164 //
165 RegisterRegAlloc *getNext() const {
166 return (RegisterRegAlloc *)
167 MachinePassRegistryNode::getNext();
168 }
169 static RegisterRegAlloc *getList() {
170 return (RegisterRegAlloc *)Registry.getList();
171 }
172 static FunctionPassCtor getDefault() {
173 return Registry.getDefault();
174 }
175 static void setDefault(FunctionPassCtor C) {
176 Registry.setDefault(C);
177 }
178 static void setListener(MachinePassRegistryListener *L) {
179 Registry.setListener(L);
180 }
181
182
183 /// FirstCtor - Finds the first register allocator in registration
184 /// list and returns its creator function, otherwise return NULL.
185 static FunctionPassCtor FirstCtor() {
186 MachinePassRegistryNode *Node = Registry.getList();
187 return Node ? Node->getCtor() : NULL;
188 }
189
190 /// FindCtor - Finds a register allocator in registration list and returns
191 /// its creator function, otherwise return NULL.
192 static FunctionPassCtor FindCtor(const char *N) {
193 MachinePassRegistryNode *Node = Registry.Find(N);
194 return Node ? Node->getCtor() : NULL;
195 }
196
197 };
198
199
200 //===----------------------------------------------------------------------===//
201 ///
202 /// RegisterScheduler class - Track the registration of instruction schedulers.
203 ///
204 //===----------------------------------------------------------------------===//
205
206 class SelectionDAGISel;
207 class ScheduleDAG;
208 class SelectionDAG;
209 class MachineBasicBlock;
210
211 class RegisterScheduler : public
212 MachinePassRegistryNode<
213 ScheduleDAG *(*)(SelectionDAGISel*, SelectionDAG*, MachineBasicBlock*)> {
214
215 public:
216
217 typedef ScheduleDAG *(*FunctionPassCtor)(SelectionDAGISel*, SelectionDAG*,
218 MachineBasicBlock*);
219
220 static MachinePassRegistry Registry;
221
222 RegisterScheduler(const char *N, const char *D, FunctionPassCtor C)
223 : MachinePassRegistryNode(N, D, C)
224 { Registry.Add(this); }
225 ~RegisterScheduler() { Registry.Remove(this); }
226
227
228 // Accessors.
229 //
230 RegisterScheduler *getNext() const {
231 return (RegisterScheduler *)
232 MachinePassRegistryNode::getNext();
233 }
234 static RegisterScheduler *getList() {
235 return (RegisterScheduler *)Registry.getList();
236 }
237 static FunctionPassCtor getDefault() {
238 return Registry.getDefault();
239 }
240 static void setDefault(FunctionPassCtor C) {
241 Registry.setDefault(C);
242 }
243 static void setListener(MachinePassRegistryListener *L) {
244 Registry.setListener(L);
245 }
246
247
248 /// FirstCtor - Finds the first instruction scheduler in registration
249 /// list and returns its creator function, otherwise return NULL.
250 static FunctionPassCtor FirstCtor() {
251 MachinePassRegistryNode *Node = Registry.getList();
252 return Node ? Node->getCtor() : NULL;
253 }
254
255
256 /// FindCtor - Finds a instruction scheduler in registration list and returns
257 /// its creator function, otherwise return NULL.
258 static FunctionPassCtor FindCtor(const char *N) {
259 MachinePassRegistryNode *Node = Registry.Find(N);
260 return Node ? Node->getCtor() : NULL;
261 }
262
263111 };
264112
265113
270118 //===----------------------------------------------------------------------===//
271119 template
272120 class RegisterPassParser : public MachinePassRegistryListener,
273 public cl::parser> {
121 public cl::parser> {
274122 public:
275123 RegisterPassParser() {}
276124 ~RegisterPassParser() { RegistryClass::setListener(NULL); }
277125
278126 void initialize(cl::Option &O) {
279 cl::parser<const char *>::initialize(O);
127 cl::parser<typename RegistryClass::FunctionPassCtor>::initialize(O);
280128
281129 // Add existing passes to option.
282130 for (RegistryClass *Node = RegistryClass::getList();
283131 Node; Node = Node->getNext()) {
284 addLiteralOption(Node->getName(), Node->getName(),
285 Node->getDescription());
132 addLiteralOption(Node->getName(),
133 (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
134 Node->getDescription());
286135 }
287136
288137 // Make sure we listen for list changes.
291140
292141 // Implement the MachinePassRegistryListener callbacks.
293142 //
294 virtual void NotifyAdd(const char *N, const char *D) {
295 addLiteralOption(N, N, D);
143 virtual void NotifyAdd(const char *N,
144 MachinePassCtor C,
145 const char *D) {
146 this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
296147 }
297 virtual void NotifyRemove(const char *N, const char *D) {
298 removeLiteralOption(N);
299 }
300
301 // ValLessThan - Provide a sorting comparator for Values elements...
302 typedef std::pair > ValType;
303 static bool ValLessThan(const ValType &VT1, const ValType &VT2) {
304 return std::string(VT1.first) < std::string(VT2.first);
305 }
306
307 // printOptionInfo - Print out information about this option. Override the
308 // default implementation to sort the table before we print...
309 virtual void printOptionInfo(const cl::Option &O, unsigned GlobalWidth) const{
310 RegisterPassParser *PNP = const_cast(this);
311 std::sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
312 cl::parser::printOptionInfo(O, GlobalWidth);
148 virtual void NotifyRemove(const char *N) {
149 this->removeLiteralOption(N);
313150 }
314151 };
315152
1515
1616 using namespace llvm;
1717
18
19 //===---------------------------------------------------------------------===//
18
19 /// Add - Adds a function pass to the registration list.
2020 ///
21 /// RegisterRegAlloc class - Track the registration of register allocators.
22 ///
23 //===---------------------------------------------------------------------===//
24 MachinePassRegistry
25 RegisterRegAlloc::Registry;
21 void MachinePassRegistry::Add(MachinePassRegistryNode *Node) {
22 Node->setNext(List);
23 List = Node;
24 if (Listener) Listener->NotifyAdd(Node->getName(),
25 Node->getCtor(),
26 Node->getDescription());
27 }
2628
2729
28 //===---------------------------------------------------------------------===//
30 /// Remove - Removes a function pass from the registration list.
2931 ///
30 /// RegisterScheduler class - Track the registration of instruction schedulers.
31 ///
32 //===---------------------------------------------------------------------===//
33 MachinePassRegistry
34 RegisterScheduler::Registry;
32 void MachinePassRegistry::Remove(MachinePassRegistryNode *Node) {
33 for (MachinePassRegistryNode **I = &List; *I; I = (*I)->getNextAddress()) {
34 if (*I == Node) {
35 if (Listener) Listener->NotifyRemove(Node->getName());
36 *I = (*I)->getNext();
37 break;
38 }
39 }
40 }
1111 //
1212 //===---------------------------------------------------------------------===//
1313
14 #include "llvm/CodeGen/MachinePassRegistry.h"
14 #include "llvm/CodeGen/RegAllocRegistry.h"
1515 #include "llvm/CodeGen/Passes.h"
16 #include "llvm/Support/CommandLine.h"
1716 #include
1817
1918 using namespace llvm;
2019
20 //===---------------------------------------------------------------------===//
21 ///
22 /// RegisterRegAlloc class - Track the registration of register allocators.
23 ///
24 //===---------------------------------------------------------------------===//
25 MachinePassRegistry RegisterRegAlloc::Registry;
26
27
28 //===---------------------------------------------------------------------===//
29 ///
30 /// RegAlloc command line options.
31 ///
32 //===---------------------------------------------------------------------===//
2133 namespace {
22 cl::opt<const char *, false, RegisterPassParser >
34 cl::opt<RegisterRegAlloc::FunctionPassCtor, false,
35 RegisterPassParser >
2336 RegAlloc("regalloc",
24 cl::init("linearscan"),
37 cl::init(createLinearScanRegisterAllocator),
2538 cl::desc("Register allocator to use: (default = linearscan)"));
2639 }
2740
41
42 //===---------------------------------------------------------------------===//
43 ///
44 /// createRegisterAllocator - choose the appropriate register allocator.
45 ///
46 //===---------------------------------------------------------------------===//
2847 FunctionPass *llvm::createRegisterAllocator() {
2948 RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
3049
3150 if (!Ctor) {
32 Ctor = RegisterRegAlloc::FindCtor(RegAlloc);
33 assert(Ctor && "No register allocator found");
34 if (!Ctor) Ctor = RegisterRegAlloc::FirstCtor();
35 RegisterRegAlloc::setDefault(Ctor);
51 Ctor = RegAlloc;
52 RegisterRegAlloc::setDefault(RegAlloc);
3653 }
37
38 assert(Ctor && "No register allocator found");
3954
4055 return Ctor();
4156 }
1717 #include "llvm/Function.h"
1818 #include "llvm/CodeGen/MachineFunctionPass.h"
1919 #include "llvm/CodeGen/MachineInstr.h"
20 #include "llvm/CodeGen/MachinePassRegistry.h"
2120 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/CodeGen/RegAllocRegistry.h"
2222 #include "llvm/CodeGen/SSARegMap.h"
2323 #include "llvm/Target/MRegisterInfo.h"
2424 #include "llvm/Target/TargetMachine.h"
1717 #include "llvm/CodeGen/MachineInstr.h"
1818 #include "llvm/CodeGen/SSARegMap.h"
1919 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachinePassRegistry.h"
2120 #include "llvm/CodeGen/LiveVariables.h"
21 #include "llvm/CodeGen/RegAllocRegistry.h"
2222 #include "llvm/Target/TargetInstrInfo.h"
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/Support/CommandLine.h"
1919 #include "llvm/CodeGen/MachineInstr.h"
2020 #include "llvm/CodeGen/SSARegMap.h"
2121 #include "llvm/CodeGen/MachineFrameInfo.h"
22 #include "llvm/CodeGen/MachinePassRegistry.h"
22 #include "llvm/CodeGen/RegAllocRegistry.h"
2323 #include "llvm/Target/TargetInstrInfo.h"
2424 #include "llvm/Target/TargetMachine.h"
2525 #include "llvm/Support/Debug.h"
1818 //===----------------------------------------------------------------------===//
1919
2020 #define DEBUG_TYPE "sched"
21 #include "llvm/CodeGen/MachinePassRegistry.h"
2221 #include "llvm/CodeGen/ScheduleDAG.h"
22 #include "llvm/CodeGen/SchedulerRegistry.h"
2323 #include "llvm/CodeGen/SelectionDAGISel.h"
2424 #include "llvm/CodeGen/SSARegMap.h"
2525 #include "llvm/Target/MRegisterInfo.h"
1515 //===----------------------------------------------------------------------===//
1616
1717 #define DEBUG_TYPE "sched"
18 #include "llvm/CodeGen/MachinePassRegistry.h"
1918 #include "llvm/CodeGen/ScheduleDAG.h"
19 #include "llvm/CodeGen/SchedulerRegistry.h"
2020 #include "llvm/CodeGen/SSARegMap.h"
2121 #include "llvm/Target/MRegisterInfo.h"
2222 #include "llvm/Target/TargetData.h"
1313 //===----------------------------------------------------------------------===//
1414
1515 #define DEBUG_TYPE "sched"
16 #include "llvm/CodeGen/MachinePassRegistry.h"
1716 #include "llvm/CodeGen/ScheduleDAG.h"
17 #include "llvm/CodeGen/SchedulerRegistry.h"
1818 #include "llvm/CodeGen/SelectionDAG.h"
1919 #include "llvm/Target/TargetData.h"
2020 #include "llvm/Target/TargetMachine.h"
2828 #include "llvm/CodeGen/MachineFrameInfo.h"
2929 #include "llvm/CodeGen/MachineJumpTableInfo.h"
3030 #include "llvm/CodeGen/MachineInstrBuilder.h"
31 #include "llvm/CodeGen/MachinePassRegistry.h"
31 #include "llvm/CodeGen/SchedulerRegistry.h"
3232 #include "llvm/CodeGen/SelectionDAG.h"
3333 #include "llvm/CodeGen/SSARegMap.h"
3434 #include "llvm/Target/MRegisterInfo.h"
3939 #include "llvm/Target/TargetMachine.h"
4040 #include "llvm/Target/TargetOptions.h"
4141 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
42 #include "llvm/Support/CommandLine.h"
4342 #include "llvm/Support/MathExtras.h"
4443 #include "llvm/Support/Debug.h"
4544 #include "llvm/Support/Visibility.h"
6059 static const bool ViewISelDAGs = 0, ViewSchedDAGs = 0;
6160 #endif
6261
62
63 //===---------------------------------------------------------------------===//
64 ///
65 /// RegisterScheduler class - Track the registration of instruction schedulers.
66 ///
67 //===---------------------------------------------------------------------===//
68 MachinePassRegistry RegisterScheduler::Registry;
69
70 //===---------------------------------------------------------------------===//
71 ///
72 /// ISHeuristic command line option for instruction schedulers.
73 ///
74 //===---------------------------------------------------------------------===//
6375 namespace {
64 cl::opt<const char *, false, RegisterPassParser >
76 cl::opt<RegisterScheduler::FunctionPassCtor, false,
77 RegisterPassParser >
6578 ISHeuristic("sched",
66 cl::init("default"),
79 cl::init(createDefaultScheduler),
6780 cl::desc("Instruction schedulers available:"));
6881
6982 static RegisterScheduler
36283641 void SelectionDAGISel::ScheduleAndEmitDAG(SelectionDAG &DAG) {
36293642 if (ViewSchedDAGs) DAG.viewGraph();
36303643
3631 static RegisterScheduler::FunctionPassCtor Ctor =
3632 RegisterScheduler::getDefault();
3644 RegisterScheduler::FunctionPassCtor Ctor = RegisterScheduler::getDefault();
36333645
36343646 if (!Ctor) {
3635 Ctor = RegisterScheduler::FindCtor(ISHeuristic);
3647 Ctor = ISHeuristic;
36363648 RegisterScheduler::setDefault(Ctor);
36373649 }
36383650
3639 assert(Ctor && "No instruction scheduler found");
36403651 ScheduleDAG *SL = Ctor(this, &DAG, BB);
36413652 BB = SL->Run();
36423653 delete SL;