llvm.org GIT mirror llvm / c6a0a11
Forgot the added files for plugable machine passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29436 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 14 years ago
3 changed file(s) with 389 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- llvm/Codegen/LinkAllCodegenComponents.h ------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under the
5 // University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This header file pulls in all codegen related passes for tools like lli and
10 // llc that need this functionality.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H
15 #define LLVM_CODEGEN_LINKALLCODEGENCOMPONENTS_H
16
17 #include "llvm/CodeGen/Passes.h"
18 #include "llvm/CodeGen/ScheduleDAG.h"
19
20 namespace {
21 struct ForceCodegenLinking {
22 ForceCodegenLinking() {
23 // We must reference the passes in such a way that compilers will not
24 // delete it all as dead code, even with whole program optimization,
25 // yet is effectively a NO-OP. As the compiler isn't smart enough
26 // to know that getenv() never returns -1, this will do the job.
27 if (std::getenv("bar") != (char*) -1)
28 return;
29
30 (void) llvm::createSimpleRegisterAllocator();
31 (void) llvm::createLocalRegisterAllocator();
32 (void) llvm::createLinearScanRegisterAllocator();
33
34 (void) llvm::createBFS_DAGScheduler(NULL, NULL);
35 (void) llvm::createSimpleDAGScheduler(NULL, NULL);
36 (void) llvm::createNoItinsDAGScheduler(NULL, NULL);
37 (void) llvm::createBURRListDAGScheduler(NULL, NULL);
38 (void) llvm::createTDRRListDAGScheduler(NULL, NULL);
39 (void) llvm::createTDListDAGScheduler(NULL, NULL);
40
41 }
42 } ForceCodegenLinking; // Force link by creating a global definition.
43 }
44
45 #endif
0 //===-- llvm/CodeGen/MachinePassRegistry.h ----------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by the LLVM research group and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CODEGEN_MACHINEPASSREGISTRY_H
10 #define LLVM_CODEGEN_MACHINEPASSREGISTRY_H
11
12 #include "llvm/CodeGen/Passes.h"
13 #include "llvm/CodeGen/ScheduleDAG.h"
14 #include "llvm/Support/CommandLine.h"
15
16 #include
17
18 namespace llvm {
19
20
21 //===----------------------------------------------------------------------===//
22 ///
23 /// MachinePassRegistryListener - Listener to adds and removals of nodes in
24 /// registration list.
25 ///
26 //===----------------------------------------------------------------------===//
27 class MachinePassRegistryListener {
28 public:
29 MachinePassRegistryListener() {}
30 virtual ~MachinePassRegistryListener() {}
31 virtual void NotifyAdd(const char *N, const char *D) = 0;
32 virtual void NotifyRemove(const char *N, const char *D) = 0;
33 };
34
35
36 //===----------------------------------------------------------------------===//
37 ///
38 /// MachinePassRegistryNode - Machine pass node stored in registration list.
39 ///
40 //===----------------------------------------------------------------------===//
41 template
42 class MachinePassRegistryNode {
43
44 private:
45
46 MachinePassRegistryNode *Next;// Next function pass in list.
47 const char *Name; // Name of function pass.
48 const char *Description; // Description string.
49 FunctionPassCtor Ctor; // Function pass creator.
50
51 public:
52
53 MachinePassRegistryNode(const char *N, const char *D, FunctionPassCtor C)
54 : Next(NULL)
55 , Name(N)
56 , Description(D)
57 , Ctor(C)
58 {}
59
60 // Accessors
61 MachinePassRegistryNode *getNext()
62 const { return Next; }
63 MachinePassRegistryNode **getNextAddress()
64 { return &Next; }
65 const char *getName() const { return Name; }
66 const char *getDescription() const { return Description; }
67 FunctionPassCtor getCtor() const { return Ctor; }
68 void setNext(MachinePassRegistryNode *N) { Next = N; }
69
70 };
71
72
73 //===----------------------------------------------------------------------===//
74 ///
75 /// MachinePassRegistry - Track the registration of machine passes.
76 ///
77 //===----------------------------------------------------------------------===//
78 template
79 class MachinePassRegistry {
80
81 private:
82
83 MachinePassRegistryNode *List;
84 // List of registry nodes.
85 FunctionPassCtor Cache; // Cached function pass creator.
86 MachinePassRegistryListener* Listener;// Listener for list adds are removes.
87
88 public:
89
90 // NO CONSTRUCTOR - we don't want static constructor ordering to mess
91 // with the registry.
92
93 // Accessors.
94 //
95 MachinePassRegistryNode *getList() { return List; }
96 FunctionPassCtor getCache() { return Cache; }
97 void setCache(FunctionPassCtor C) { Cache = C; }
98 void setListener(MachinePassRegistryListener *L) { Listener = L; }
99
100 /// Add - Adds a function pass to the registration list.
101 ///
102 void Add(MachinePassRegistryNode *Node) {
103 Node->setNext(List);
104 List = Node;
105 if (Listener) Listener->NotifyAdd(Node->getName(), Node->getDescription());
106 }
107
108
109 /// Remove - Removes a function pass from the registration list.
110 ///
111 void Remove(MachinePassRegistryNode *Node) {
112 for (MachinePassRegistryNode **I = &List;
113 *I; I = (*I)->getNextAddress()) {
114 if (*I == Node) {
115 #if 0 // FIXME: Command opt needs to call a termination routine.
116 if (Listener) Listener->NotifyRemove(Node->getName(),
117 Node->getDescription());
118 #endif
119 *I = (*I)->getNext();
120 break;
121 }
122 }
123 }
124
125
126 /// FInd - Finds and returns a function pass in registration list, otherwise
127 /// returns NULL.
128 MachinePassRegistryNode *Find(const char *Name) {
129 for (MachinePassRegistryNode *I = List;
130 I; I = I->getNext()) {
131 if (std::string(Name) == std::string(I->getName())) return I;
132 }
133 return NULL;
134 }
135
136
137 };
138
139
140 //===----------------------------------------------------------------------===//
141 ///
142 /// RegisterRegAlloc class - Track the registration of register allocators.
143 ///
144 //===----------------------------------------------------------------------===//
145 class RegisterRegAlloc : public MachinePassRegistryNode {
146
147 public:
148
149 typedef FunctionPass *(*FunctionPassCtor)();
150
151 static MachinePassRegistry Registry;
152
153 RegisterRegAlloc(const char *N, const char *D, FunctionPassCtor C)
154 : MachinePassRegistryNode(N, D, C)
155 { Registry.Add(this); }
156 ~RegisterRegAlloc() { Registry.Remove(this); }
157
158
159 // Accessors.
160 //
161 RegisterRegAlloc *getNext() const {
162 return (RegisterRegAlloc *)
163 MachinePassRegistryNode::getNext();
164 }
165 static RegisterRegAlloc *getList() {
166 return (RegisterRegAlloc *)Registry.getList();
167 }
168 static FunctionPassCtor getCache() {
169 return Registry.getCache();
170 }
171 static void setCache(FunctionPassCtor C) {
172 Registry.setCache(C);
173 }
174 static void setListener(MachinePassRegistryListener *L) {
175 Registry.setListener(L);
176 }
177
178
179 /// FirstCtor - Finds the first register allocator in registration
180 /// list and returns its creator function, otherwise return NULL.
181 static FunctionPassCtor FirstCtor() {
182 MachinePassRegistryNode *Node = Registry.getList();
183 return Node ? Node->getCtor() : NULL;
184 }
185
186 /// FindCtor - Finds a register allocator in registration list and returns
187 /// its creator function, otherwise return NULL.
188 static FunctionPassCtor FindCtor(const char *N) {
189 MachinePassRegistryNode *Node = Registry.Find(N);
190 return Node ? Node->getCtor() : NULL;
191 }
192
193 };
194
195
196 //===----------------------------------------------------------------------===//
197 ///
198 /// RegisterScheduler class - Track the registration of instruction schedulers.
199 ///
200 //===----------------------------------------------------------------------===//
201
202 class ScheduleDAG;
203 class SelectionDAG;
204 class MachineBasicBlock;
205
206 class RegisterScheduler : public
207 MachinePassRegistryNode {
208
209 public:
210
211 typedef ScheduleDAG *(*FunctionPassCtor)(SelectionDAG*, MachineBasicBlock*);
212
213 static MachinePassRegistry Registry;
214
215 RegisterScheduler(const char *N, const char *D, FunctionPassCtor C)
216 : MachinePassRegistryNode(N, D, C)
217 { Registry.Add(this); }
218 ~RegisterScheduler() { Registry.Remove(this); }
219
220
221 // Accessors.
222 //
223 RegisterScheduler *getNext() const {
224 return (RegisterScheduler *)
225 MachinePassRegistryNode::getNext();
226 }
227 static RegisterScheduler *getList() {
228 return (RegisterScheduler *)Registry.getList();
229 }
230 static FunctionPassCtor getCache() {
231 return Registry.getCache();
232 }
233 static void setCache(FunctionPassCtor C) {
234 Registry.setCache(C);
235 }
236 static void setListener(MachinePassRegistryListener *L) {
237 Registry.setListener(L);
238 }
239
240
241 /// FirstCtor - Finds the first instruction scheduler in registration
242 /// list and returns its creator function, otherwise return NULL.
243 static FunctionPassCtor FirstCtor() {
244 MachinePassRegistryNode *Node = Registry.getList();
245 return Node ? Node->getCtor() : NULL;
246 }
247
248
249 /// FindCtor - Finds a instruction scheduler in registration list and returns
250 /// its creator function, otherwise return NULL.
251 static FunctionPassCtor FindCtor(const char *N) {
252 MachinePassRegistryNode *Node = Registry.Find(N);
253 return Node ? Node->getCtor() : NULL;
254 }
255
256 };
257
258
259 //===----------------------------------------------------------------------===//
260 ///
261 /// RegisterPassParser class - Handle the addition of new machine passes.
262 ///
263 //===----------------------------------------------------------------------===//
264 template
265 class RegisterPassParser : public MachinePassRegistryListener,
266 public cl::parser {
267 public:
268 RegisterPassParser() {}
269
270 void initialize(cl::Option &O) {
271 cl::parser::initialize(O);
272
273 // Add existing passes to option.
274 for (RegistryClass *Node = RegistryClass::getList();
275 Node; Node = Node->getNext()) {
276 addLiteralOption(Node->getName(), Node->getName(),
277 Node->getDescription());
278 }
279
280 // Make sure we listen for list changes.
281 RegistryClass::setListener(this);
282 }
283
284 // Implement the MachinePassRegistryListener callbacks.
285 //
286 virtual void NotifyAdd(const char *N, const char *D) {
287 addLiteralOption(N, N, D);
288 }
289 virtual void NotifyRemove(const char *N, const char *D) {
290 removeLiteralOption(N);
291 }
292
293 // ValLessThan - Provide a sorting comparator for Values elements...
294 typedef std::pair > ValType;
295 static bool ValLessThan(const ValType &VT1, const ValType &VT2) {
296 return std::string(VT1.first) < std::string(VT2.first);
297 }
298
299 // printOptionInfo - Print out information about this option. Override the
300 // default implementation to sort the table before we print...
301 virtual void printOptionInfo(const cl::Option &O, unsigned GlobalWidth) const{
302 RegisterPassParser *PNP = const_cast(this);
303 std::sort(PNP->Values.begin(), PNP->Values.end(), ValLessThan);
304 cl::parser::printOptionInfo(O, GlobalWidth);
305 }
306 };
307
308
309 } // end namespace llvm
310
311 #endif
0 //===-- MachineInstr.cpp --------------------------------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by James M. Laskey and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/CodeGen/MachinePassRegistry.h"
10 #include
11
12 using namespace llvm;
13
14
15 //===---------------------------------------------------------------------===//
16 ///
17 /// RegisterRegAlloc class - Track the registration of register allocators.
18 ///
19 //===---------------------------------------------------------------------===//
20 MachinePassRegistry
21 RegisterRegAlloc::Registry;
22
23
24 //===---------------------------------------------------------------------===//
25 ///
26 /// RegisterScheduler class - Track the registration of instruction schedulers.
27 ///
28 //===---------------------------------------------------------------------===//
29 MachinePassRegistry
30 RegisterScheduler::Registry;