llvm.org GIT mirror llvm / 3e74d6f
Move TargetRegistry and TargetSelect from Target to Support where they belong. These are strictly utilities for registering targets and components. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@138450 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 8 years ago
123 changed file(s) with 1523 addition(s) and 1529 deletion(s). Raw diff Collapse all Expand all
3030 #include "llvm/Bitcode/ReaderWriter.h"
3131 #include "llvm/ExecutionEngine/GenericValue.h"
3232 #include "llvm/ExecutionEngine/JIT.h"
33 #include "llvm/Target/TargetSelect.h"
3433 #include "llvm/Support/CommandLine.h"
3534 #include "llvm/Support/ManagedStatic.h"
35 #include "llvm/Support/TargetSelect.h"
3636 #include "llvm/Support/raw_ostream.h"
3737 #include
3838 #include
5555 #include "llvm/Intrinsics.h"
5656 #include "llvm/Analysis/Verifier.h"
5757 #include "llvm/Target/TargetData.h"
58 #include "llvm/Target/TargetSelect.h"
5958 #include "llvm/Target/TargetOptions.h"
6059 #include "llvm/Transforms/Scalar.h"
6160 #include "llvm/Support/IRBuilder.h"
6261 #include "llvm/Support/Dwarf.h"
62 #include "llvm/Support/TargetSelect.h"
6363
6464 // FIXME: Although all systems tested with (Linux, OS X), do not need this
6565 // header file included. A user on ubuntu reported, undefined symbols
3232 #include "llvm/ExecutionEngine/Interpreter.h"
3333 #include "llvm/ExecutionEngine/GenericValue.h"
3434 #include "llvm/Support/raw_ostream.h"
35 #include "llvm/Target/TargetSelect.h"
35 #include "llvm/Support/TargetSelect.h"
3636 using namespace llvm;
3737
3838 static Function *CreateFibFunction(Module *M, LLVMContext &Context) {
4141 #include "llvm/ExecutionEngine/JIT.h"
4242 #include "llvm/ExecutionEngine/Interpreter.h"
4343 #include "llvm/ExecutionEngine/GenericValue.h"
44 #include "llvm/Target/TargetSelect.h"
44 #include "llvm/Support/TargetSelect.h"
4545 #include "llvm/Support/ManagedStatic.h"
4646 #include "llvm/Support/raw_ostream.h"
4747 #include "llvm/Support/IRBuilder.h"
66 #include "llvm/Analysis/Verifier.h"
77 #include "llvm/Analysis/Passes.h"
88 #include "llvm/Target/TargetData.h"
9 #include "llvm/Target/TargetSelect.h"
109 #include "llvm/Transforms/Scalar.h"
1110 #include "llvm/Support/IRBuilder.h"
11 #include "llvm/Support/TargetSelect.h"
1212 #include
1313 #include
1414 #include
66 #include "llvm/Analysis/Verifier.h"
77 #include "llvm/Analysis/Passes.h"
88 #include "llvm/Target/TargetData.h"
9 #include "llvm/Target/TargetSelect.h"
109 #include "llvm/Transforms/Scalar.h"
1110 #include "llvm/Support/IRBuilder.h"
11 #include "llvm/Support/TargetSelect.h"
1212 #include
1313 #include
1414 #include
66 #include "llvm/Analysis/Verifier.h"
77 #include "llvm/Analysis/Passes.h"
88 #include "llvm/Target/TargetData.h"
9 #include "llvm/Target/TargetSelect.h"
109 #include "llvm/Transforms/Scalar.h"
1110 #include "llvm/Support/IRBuilder.h"
11 #include "llvm/Support/TargetSelect.h"
1212 #include
1313 #include
1414 #include
66 #include "llvm/Analysis/Verifier.h"
77 #include "llvm/Analysis/Passes.h"
88 #include "llvm/Target/TargetData.h"
9 #include "llvm/Target/TargetSelect.h"
109 #include "llvm/Transforms/Scalar.h"
1110 #include "llvm/Support/IRBuilder.h"
11 #include "llvm/Support/TargetSelect.h"
1212 #include
1313 #include
1414 #include
2525 #include "llvm/ExecutionEngine/JIT.h"
2626 #include "llvm/ExecutionEngine/Interpreter.h"
2727 #include "llvm/ExecutionEngine/GenericValue.h"
28 #include "llvm/Target/TargetSelect.h"
28 #include "llvm/Support/TargetSelect.h"
2929 #include
3030 using namespace llvm;
3131
0 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file exposes the TargetRegistry interface, which tools can use to access
10 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
11 // which have been registered.
12 //
13 // Target specific class implementations should register themselves using the
14 // appropriate TargetRegistry interfaces.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
19 #define LLVM_SUPPORT_TARGETREGISTRY_H
20
21 #include "llvm/Support/CodeGen.h"
22 #include "llvm/ADT/Triple.h"
23 #include
24 #include
25
26 namespace llvm {
27 class AsmPrinter;
28 class Module;
29 class MCAssembler;
30 class MCAsmBackend;
31 class MCAsmInfo;
32 class MCAsmParser;
33 class MCCodeEmitter;
34 class MCCodeGenInfo;
35 class MCContext;
36 class MCDisassembler;
37 class MCInstrAnalysis;
38 class MCInstPrinter;
39 class MCInstrInfo;
40 class MCRegisterInfo;
41 class MCStreamer;
42 class MCSubtargetInfo;
43 class MCTargetAsmLexer;
44 class MCTargetAsmParser;
45 class TargetMachine;
46 class raw_ostream;
47 class formatted_raw_ostream;
48
49 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
50 bool isVerboseAsm,
51 bool useLoc, bool useCFI,
52 MCInstPrinter *InstPrint,
53 MCCodeEmitter *CE,
54 MCAsmBackend *TAB,
55 bool ShowInst);
56
57 /// Target - Wrapper for Target specific information.
58 ///
59 /// For registration purposes, this is a POD type so that targets can be
60 /// registered without the use of static constructors.
61 ///
62 /// Targets should implement a single global instance of this class (which
63 /// will be zero initialized), and pass that instance to the TargetRegistry as
64 /// part of their initialization.
65 class Target {
66 public:
67 friend struct TargetRegistry;
68
69 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
70
71 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
72 StringRef TT);
73 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
74 Reloc::Model RM,
75 CodeModel::Model CM);
76 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
77 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
78 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
79 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
80 StringRef CPU,
81 StringRef Features);
82 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
83 StringRef TT,
84 StringRef CPU,
85 StringRef Features,
86 Reloc::Model RM,
87 CodeModel::Model CM);
88 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
89 MCStreamer &Streamer);
90 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
91 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
92 const MCRegisterInfo &MRI,
93 const MCAsmInfo &MAI);
94 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
95 MCAsmParser &P);
96 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
97 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
98 unsigned SyntaxVariant,
99 const MCAsmInfo &MAI);
100 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
101 const MCSubtargetInfo &STI,
102 MCContext &Ctx);
103 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
104 StringRef TT,
105 MCContext &Ctx,
106 MCAsmBackend &TAB,
107 raw_ostream &_OS,
108 MCCodeEmitter *_Emitter,
109 bool RelaxAll,
110 bool NoExecStack);
111 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
112 formatted_raw_ostream &OS,
113 bool isVerboseAsm,
114 bool useLoc,
115 bool useCFI,
116 MCInstPrinter *InstPrint,
117 MCCodeEmitter *CE,
118 MCAsmBackend *TAB,
119 bool ShowInst);
120
121 private:
122 /// Next - The next registered target in the linked list, maintained by the
123 /// TargetRegistry.
124 Target *Next;
125
126 /// TripleMatchQualityFn - The target function for rating the match quality
127 /// of a triple.
128 TripleMatchQualityFnTy TripleMatchQualityFn;
129
130 /// Name - The target name.
131 const char *Name;
132
133 /// ShortDesc - A short description of the target.
134 const char *ShortDesc;
135
136 /// HasJIT - Whether this target supports the JIT.
137 bool HasJIT;
138
139 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
140 /// registered.
141 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
142
143 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
144 /// if registered.
145 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
146
147 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
148 /// if registered.
149 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
150
151 /// MCInstrAnalysisCtorFn - Constructor function for this target's
152 /// MCInstrAnalysis, if registered.
153 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
154
155 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
156 /// if registered.
157 MCRegInfoCtorFnTy MCRegInfoCtorFn;
158
159 /// MCSubtargetInfoCtorFn - Constructor function for this target's
160 /// MCSubtargetInfo, if registered.
161 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
162
163 /// TargetMachineCtorFn - Construction function for this target's
164 /// TargetMachine, if registered.
165 TargetMachineCtorTy TargetMachineCtorFn;
166
167 /// MCAsmBackendCtorFn - Construction function for this target's
168 /// MCAsmBackend, if registered.
169 MCAsmBackendCtorTy MCAsmBackendCtorFn;
170
171 /// MCAsmLexerCtorFn - Construction function for this target's
172 /// MCTargetAsmLexer, if registered.
173 MCAsmLexerCtorTy MCAsmLexerCtorFn;
174
175 /// MCAsmParserCtorFn - Construction function for this target's
176 /// MCTargetAsmParser, if registered.
177 MCAsmParserCtorTy MCAsmParserCtorFn;
178
179 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
180 /// if registered.
181 AsmPrinterCtorTy AsmPrinterCtorFn;
182
183 /// MCDisassemblerCtorFn - Construction function for this target's
184 /// MCDisassembler, if registered.
185 MCDisassemblerCtorTy MCDisassemblerCtorFn;
186
187 /// MCInstPrinterCtorFn - Construction function for this target's
188 /// MCInstPrinter, if registered.
189 MCInstPrinterCtorTy MCInstPrinterCtorFn;
190
191 /// MCCodeEmitterCtorFn - Construction function for this target's
192 /// CodeEmitter, if registered.
193 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
194
195 /// MCObjectStreamerCtorFn - Construction function for this target's
196 /// MCObjectStreamer, if registered.
197 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
198
199 /// AsmStreamerCtorFn - Construction function for this target's
200 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
201 AsmStreamerCtorTy AsmStreamerCtorFn;
202
203 public:
204 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
205
206 /// @name Target Information
207 /// @{
208
209 // getNext - Return the next registered target.
210 const Target *getNext() const { return Next; }
211
212 /// getName - Get the target name.
213 const char *getName() const { return Name; }
214
215 /// getShortDescription - Get a short description of the target.
216 const char *getShortDescription() const { return ShortDesc; }
217
218 /// @}
219 /// @name Feature Predicates
220 /// @{
221
222 /// hasJIT - Check if this targets supports the just-in-time compilation.
223 bool hasJIT() const { return HasJIT; }
224
225 /// hasTargetMachine - Check if this target supports code generation.
226 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
227
228 /// hasMCAsmBackend - Check if this target supports .o generation.
229 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
230
231 /// hasMCAsmLexer - Check if this target supports .s lexing.
232 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
233
234 /// hasAsmParser - Check if this target supports .s parsing.
235 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
236
237 /// hasAsmPrinter - Check if this target supports .s printing.
238 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
239
240 /// hasMCDisassembler - Check if this target has a disassembler.
241 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
242
243 /// hasMCInstPrinter - Check if this target has an instruction printer.
244 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
245
246 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
247 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
248
249 /// hasMCObjectStreamer - Check if this target supports streaming to files.
250 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
251
252 /// hasAsmStreamer - Check if this target supports streaming to files.
253 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
254
255 /// @}
256 /// @name Feature Constructors
257 /// @{
258
259 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
260 /// target triple.
261 ///
262 /// \arg Triple - This argument is used to determine the target machine
263 /// feature set; it should always be provided. Generally this should be
264 /// either the target triple from the module, or the target triple of the
265 /// host if that does not exist.
266 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
267 if (!MCAsmInfoCtorFn)
268 return 0;
269 return MCAsmInfoCtorFn(*this, Triple);
270 }
271
272 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
273 ///
274 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
275 CodeModel::Model CM) const {
276 if (!MCCodeGenInfoCtorFn)
277 return 0;
278 return MCCodeGenInfoCtorFn(Triple, RM, CM);
279 }
280
281 /// createMCInstrInfo - Create a MCInstrInfo implementation.
282 ///
283 MCInstrInfo *createMCInstrInfo() const {
284 if (!MCInstrInfoCtorFn)
285 return 0;
286 return MCInstrInfoCtorFn();
287 }
288
289 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
290 ///
291 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
292 if (!MCInstrAnalysisCtorFn)
293 return 0;
294 return MCInstrAnalysisCtorFn(Info);
295 }
296
297 /// createMCRegInfo - Create a MCRegisterInfo implementation.
298 ///
299 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
300 if (!MCRegInfoCtorFn)
301 return 0;
302 return MCRegInfoCtorFn(Triple);
303 }
304
305 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
306 ///
307 /// \arg Triple - This argument is used to determine the target machine
308 /// feature set; it should always be provided. Generally this should be
309 /// either the target triple from the module, or the target triple of the
310 /// host if that does not exist.
311 /// \arg CPU - This specifies the name of the target CPU.
312 /// \arg Features - This specifies the string representation of the
313 /// additional target features.
314 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
315 StringRef Features) const {
316 if (!MCSubtargetInfoCtorFn)
317 return 0;
318 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
319 }
320
321 /// createTargetMachine - Create a target specific machine implementation
322 /// for the specified \arg Triple.
323 ///
324 /// \arg Triple - This argument is used to determine the target machine
325 /// feature set; it should always be provided. Generally this should be
326 /// either the target triple from the module, or the target triple of the
327 /// host if that does not exist.
328 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
329 StringRef Features,
330 Reloc::Model RM = Reloc::Default,
331 CodeModel::Model CM = CodeModel::Default) const {
332 if (!TargetMachineCtorFn)
333 return 0;
334 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
335 }
336
337 /// createMCAsmBackend - Create a target specific assembly parser.
338 ///
339 /// \arg Triple - The target triple string.
340 /// \arg Backend - The target independent assembler object.
341 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
342 if (!MCAsmBackendCtorFn)
343 return 0;
344 return MCAsmBackendCtorFn(*this, Triple);
345 }
346
347 /// createMCAsmLexer - Create a target specific assembly lexer.
348 ///
349 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
350 const MCAsmInfo &MAI) const {
351 if (!MCAsmLexerCtorFn)
352 return 0;
353 return MCAsmLexerCtorFn(*this, MRI, MAI);
354 }
355
356 /// createMCAsmParser - Create a target specific assembly parser.
357 ///
358 /// \arg Parser - The target independent parser implementation to use for
359 /// parsing and lexing.
360 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
361 MCAsmParser &Parser) const {
362 if (!MCAsmParserCtorFn)
363 return 0;
364 return MCAsmParserCtorFn(STI, Parser);
365 }
366
367 /// createAsmPrinter - Create a target specific assembly printer pass. This
368 /// takes ownership of the MCStreamer object.
369 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
370 if (!AsmPrinterCtorFn)
371 return 0;
372 return AsmPrinterCtorFn(TM, Streamer);
373 }
374
375 MCDisassembler *createMCDisassembler() const {
376 if (!MCDisassemblerCtorFn)
377 return 0;
378 return MCDisassemblerCtorFn(*this);
379 }
380
381 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
382 const MCAsmInfo &MAI) const {
383 if (!MCInstPrinterCtorFn)
384 return 0;
385 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
386 }
387
388
389 /// createMCCodeEmitter - Create a target specific code emitter.
390 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
391 const MCSubtargetInfo &STI,
392 MCContext &Ctx) const {
393 if (!MCCodeEmitterCtorFn)
394 return 0;
395 return MCCodeEmitterCtorFn(II, STI, Ctx);
396 }
397
398 /// createMCObjectStreamer - Create a target specific MCStreamer.
399 ///
400 /// \arg TT - The target triple.
401 /// \arg Ctx - The target context.
402 /// \arg TAB - The target assembler backend object. Takes ownership.
403 /// \arg _OS - The stream object.
404 /// \arg _Emitter - The target independent assembler object.Takes ownership.
405 /// \arg RelaxAll - Relax all fixups?
406 /// \arg NoExecStack - Mark file as not needing a executable stack.
407 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
408 MCAsmBackend &TAB,
409 raw_ostream &_OS,
410 MCCodeEmitter *_Emitter,
411 bool RelaxAll,
412 bool NoExecStack) const {
413 if (!MCObjectStreamerCtorFn)
414 return 0;
415 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
416 RelaxAll, NoExecStack);
417 }
418
419 /// createAsmStreamer - Create a target specific MCStreamer.
420 MCStreamer *createAsmStreamer(MCContext &Ctx,
421 formatted_raw_ostream &OS,
422 bool isVerboseAsm,
423 bool useLoc,
424 bool useCFI,
425 MCInstPrinter *InstPrint,
426 MCCodeEmitter *CE,
427 MCAsmBackend *TAB,
428 bool ShowInst) const {
429 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
430 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
431 InstPrint, CE, TAB, ShowInst);
432 }
433
434 /// @}
435 };
436
437 /// TargetRegistry - Generic interface to target specific features.
438 struct TargetRegistry {
439 class iterator {
440 const Target *Current;
441 explicit iterator(Target *T) : Current(T) {}
442 friend struct TargetRegistry;
443 public:
444 iterator(const iterator &I) : Current(I.Current) {}
445 iterator() : Current(0) {}
446
447 bool operator==(const iterator &x) const {
448 return Current == x.Current;
449 }
450 bool operator!=(const iterator &x) const {
451 return !operator==(x);
452 }
453
454 // Iterator traversal: forward iteration only
455 iterator &operator++() { // Preincrement
456 assert(Current && "Cannot increment end iterator!");
457 Current = Current->getNext();
458 return *this;
459 }
460 iterator operator++(int) { // Postincrement
461 iterator tmp = *this;
462 ++*this;
463 return tmp;
464 }
465
466 const Target &operator*() const {
467 assert(Current && "Cannot dereference end iterator!");
468 return *Current;
469 }
470
471 const Target *operator->() const {
472 return &operator*();
473 }
474 };
475
476 /// printRegisteredTargetsForVersion - Print the registered targets
477 /// appropriately for inclusion in a tool's version output.
478 static void printRegisteredTargetsForVersion();
479
480 /// @name Registry Access
481 /// @{
482
483 static iterator begin();
484
485 static iterator end() { return iterator(); }
486
487 /// lookupTarget - Lookup a target based on a target triple.
488 ///
489 /// \param Triple - The triple to use for finding a target.
490 /// \param Error - On failure, an error string describing why no target was
491 /// found.
492 static const Target *lookupTarget(const std::string &Triple,
493 std::string &Error);
494
495 /// getClosestTargetForJIT - Pick the best target that is compatible with
496 /// the current host. If no close target can be found, this returns null
497 /// and sets the Error string to a reason.
498 ///
499 /// Maintained for compatibility through 2.6.
500 static const Target *getClosestTargetForJIT(std::string &Error);
501
502 /// @}
503 /// @name Target Registration
504 /// @{
505
506 /// RegisterTarget - Register the given target. Attempts to register a
507 /// target which has already been registered will be ignored.
508 ///
509 /// Clients are responsible for ensuring that registration doesn't occur
510 /// while another thread is attempting to access the registry. Typically
511 /// this is done by initializing all targets at program startup.
512 ///
513 /// @param T - The target being registered.
514 /// @param Name - The target name. This should be a static string.
515 /// @param ShortDesc - A short target description. This should be a static
516 /// string.
517 /// @param TQualityFn - The triple match quality computation function for
518 /// this target.
519 /// @param HasJIT - Whether the target supports JIT code
520 /// generation.
521 static void RegisterTarget(Target &T,
522 const char *Name,
523 const char *ShortDesc,
524 Target::TripleMatchQualityFnTy TQualityFn,
525 bool HasJIT = false);
526
527 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
528 /// given target.
529 ///
530 /// Clients are responsible for ensuring that registration doesn't occur
531 /// while another thread is attempting to access the registry. Typically
532 /// this is done by initializing all targets at program startup.
533 ///
534 /// @param T - The target being registered.
535 /// @param Fn - A function to construct a MCAsmInfo for the target.
536 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
537 // Ignore duplicate registration.
538 if (!T.MCAsmInfoCtorFn)
539 T.MCAsmInfoCtorFn = Fn;
540 }
541
542 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
543 /// given target.
544 ///
545 /// Clients are responsible for ensuring that registration doesn't occur
546 /// while another thread is attempting to access the registry. Typically
547 /// this is done by initializing all targets at program startup.
548 ///
549 /// @param T - The target being registered.
550 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
551 static void RegisterMCCodeGenInfo(Target &T,
552 Target::MCCodeGenInfoCtorFnTy Fn) {
553 // Ignore duplicate registration.
554 if (!T.MCCodeGenInfoCtorFn)
555 T.MCCodeGenInfoCtorFn = Fn;
556 }
557
558 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
559 /// given target.
560 ///
561 /// Clients are responsible for ensuring that registration doesn't occur
562 /// while another thread is attempting to access the registry. Typically
563 /// this is done by initializing all targets at program startup.
564 ///
565 /// @param T - The target being registered.
566 /// @param Fn - A function to construct a MCInstrInfo for the target.
567 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
568 // Ignore duplicate registration.
569 if (!T.MCInstrInfoCtorFn)
570 T.MCInstrInfoCtorFn = Fn;
571 }
572
573 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
574 /// the given target.
575 static void RegisterMCInstrAnalysis(Target &T,
576 Target::MCInstrAnalysisCtorFnTy Fn) {
577 // Ignore duplicate registration.
578 if (!T.MCInstrAnalysisCtorFn)
579 T.MCInstrAnalysisCtorFn = Fn;
580 }
581
582 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
583 /// given target.
584 ///
585 /// Clients are responsible for ensuring that registration doesn't occur
586 /// while another thread is attempting to access the registry. Typically
587 /// this is done by initializing all targets at program startup.
588 ///
589 /// @param T - The target being registered.
590 /// @param Fn - A function to construct a MCRegisterInfo for the target.
591 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
592 // Ignore duplicate registration.
593 if (!T.MCRegInfoCtorFn)
594 T.MCRegInfoCtorFn = Fn;
595 }
596
597 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
598 /// the given target.
599 ///
600 /// Clients are responsible for ensuring that registration doesn't occur
601 /// while another thread is attempting to access the registry. Typically
602 /// this is done by initializing all targets at program startup.
603 ///
604 /// @param T - The target being registered.
605 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
606 static void RegisterMCSubtargetInfo(Target &T,
607 Target::MCSubtargetInfoCtorFnTy Fn) {
608 // Ignore duplicate registration.
609 if (!T.MCSubtargetInfoCtorFn)
610 T.MCSubtargetInfoCtorFn = Fn;
611 }
612
613 /// RegisterTargetMachine - Register a TargetMachine implementation for the
614 /// given target.
615 ///
616 /// Clients are responsible for ensuring that registration doesn't occur
617 /// while another thread is attempting to access the registry. Typically
618 /// this is done by initializing all targets at program startup.
619 ///
620 /// @param T - The target being registered.
621 /// @param Fn - A function to construct a TargetMachine for the target.
622 static void RegisterTargetMachine(Target &T,
623 Target::TargetMachineCtorTy Fn) {
624 // Ignore duplicate registration.
625 if (!T.TargetMachineCtorFn)
626 T.TargetMachineCtorFn = Fn;
627 }
628
629 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
630 /// given target.
631 ///
632 /// Clients are responsible for ensuring that registration doesn't occur
633 /// while another thread is attempting to access the registry. Typically
634 /// this is done by initializing all targets at program startup.
635 ///
636 /// @param T - The target being registered.
637 /// @param Fn - A function to construct an AsmBackend for the target.
638 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
639 if (!T.MCAsmBackendCtorFn)
640 T.MCAsmBackendCtorFn = Fn;
641 }
642
643 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
644 /// given target.
645 ///
646 /// Clients are responsible for ensuring that registration doesn't occur
647 /// while another thread is attempting to access the registry. Typically
648 /// this is done by initializing all targets at program startup.
649 ///
650 /// @param T - The target being registered.
651 /// @param Fn - A function to construct an MCAsmLexer for the target.
652 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
653 if (!T.MCAsmLexerCtorFn)
654 T.MCAsmLexerCtorFn = Fn;
655 }
656
657 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
658 /// the given target.
659 ///
660 /// Clients are responsible for ensuring that registration doesn't occur
661 /// while another thread is attempting to access the registry. Typically
662 /// this is done by initializing all targets at program startup.
663 ///
664 /// @param T - The target being registered.
665 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
666 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
667 if (!T.MCAsmParserCtorFn)
668 T.MCAsmParserCtorFn = Fn;
669 }
670
671 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
672 /// target.
673 ///
674 /// Clients are responsible for ensuring that registration doesn't occur
675 /// while another thread is attempting to access the registry. Typically
676 /// this is done by initializing all targets at program startup.
677 ///
678 /// @param T - The target being registered.
679 /// @param Fn - A function to construct an AsmPrinter for the target.
680 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
681 // Ignore duplicate registration.
682 if (!T.AsmPrinterCtorFn)
683 T.AsmPrinterCtorFn = Fn;
684 }
685
686 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
687 /// the given target.
688 ///
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
692 ///
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct an MCDisassembler for the target.
695 static void RegisterMCDisassembler(Target &T,
696 Target::MCDisassemblerCtorTy Fn) {
697 if (!T.MCDisassemblerCtorFn)
698 T.MCDisassemblerCtorFn = Fn;
699 }
700
701 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
702 /// given target.
703 ///
704 /// Clients are responsible for ensuring that registration doesn't occur
705 /// while another thread is attempting to access the registry. Typically
706 /// this is done by initializing all targets at program startup.
707 ///
708 /// @param T - The target being registered.
709 /// @param Fn - A function to construct an MCInstPrinter for the target.
710 static void RegisterMCInstPrinter(Target &T,
711 Target::MCInstPrinterCtorTy Fn) {
712 if (!T.MCInstPrinterCtorFn)
713 T.MCInstPrinterCtorFn = Fn;
714 }
715
716 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
717 /// given target.
718 ///
719 /// Clients are responsible for ensuring that registration doesn't occur
720 /// while another thread is attempting to access the registry. Typically
721 /// this is done by initializing all targets at program startup.
722 ///
723 /// @param T - The target being registered.
724 /// @param Fn - A function to construct an MCCodeEmitter for the target.
725 static void RegisterMCCodeEmitter(Target &T,
726 Target::MCCodeEmitterCtorTy Fn) {
727 if (!T.MCCodeEmitterCtorFn)
728 T.MCCodeEmitterCtorFn = Fn;
729 }
730
731 /// RegisterMCObjectStreamer - Register a object code MCStreamer
732 /// implementation for the given target.
733 ///
734 /// Clients are responsible for ensuring that registration doesn't occur
735 /// while another thread is attempting to access the registry. Typically
736 /// this is done by initializing all targets at program startup.
737 ///
738 /// @param T - The target being registered.
739 /// @param Fn - A function to construct an MCStreamer for the target.
740 static void RegisterMCObjectStreamer(Target &T,
741 Target::MCObjectStreamerCtorTy Fn) {
742 if (!T.MCObjectStreamerCtorFn)
743 T.MCObjectStreamerCtorFn = Fn;
744 }
745
746 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
747 /// for the given target.
748 ///
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
752 ///
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an MCStreamer for the target.
755 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
756 if (T.AsmStreamerCtorFn == createAsmStreamer)
757 T.AsmStreamerCtorFn = Fn;
758 }
759
760 /// @}
761 };
762
763
764 //===--------------------------------------------------------------------===//
765
766 /// RegisterTarget - Helper template for registering a target, for use in the
767 /// target's initialization function. Usage:
768 ///
769 ///
770 /// Target TheFooTarget; // The global target instance.
771 ///
772 /// extern "C" void LLVMInitializeFooTargetInfo() {
773 /// RegisterTarget X(TheFooTarget, "foo", "Foo description");
774 /// }
775 template
776 bool HasJIT = false>
777 struct RegisterTarget {
778 RegisterTarget(Target &T, const char *Name, const char *Desc) {
779 TargetRegistry::RegisterTarget(T, Name, Desc,
780 &getTripleMatchQuality,
781 HasJIT);
782 }
783
784 static unsigned getTripleMatchQuality(const std::string &TT) {
785 if (Triple(TT).getArch() == TargetArchType)
786 return 20;
787 return 0;
788 }
789 };
790
791 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
792 /// implementation. This invokes the static "Create" method on the class to
793 /// actually do the construction. Usage:
794 ///
795 /// extern "C" void LLVMInitializeFooTarget() {
796 /// extern Target TheFooTarget;
797 /// RegisterMCAsmInfo X(TheFooTarget);
798 /// }
799 template
800 struct RegisterMCAsmInfo {
801 RegisterMCAsmInfo(Target &T) {
802 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
803 }
804 private:
805 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
806 return new MCAsmInfoImpl(T, TT);
807 }
808
809 };
810
811 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
812 /// implementation. This invokes the specified function to do the
813 /// construction. Usage:
814 ///
815 /// extern "C" void LLVMInitializeFooTarget() {
816 /// extern Target TheFooTarget;
817 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
818 /// }
819 struct RegisterMCAsmInfoFn {
820 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
821 TargetRegistry::RegisterMCAsmInfo(T, Fn);
822 }
823 };
824
825 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
826 /// implementation. This invokes the static "Create" method on the class
827 /// to actually do the construction. Usage:
828 ///
829 /// extern "C" void LLVMInitializeFooTarget() {
830 /// extern Target TheFooTarget;
831 /// RegisterMCCodeGenInfo X(TheFooTarget);
832 /// }
833 template
834 struct RegisterMCCodeGenInfo {
835 RegisterMCCodeGenInfo(Target &T) {
836 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
837 }
838 private:
839 static MCCodeGenInfo *Allocator(StringRef TT,
840 Reloc::Model RM, CodeModel::Model CM) {
841 return new MCCodeGenInfoImpl();
842 }
843 };
844
845 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
846 /// info implementation. This invokes the specified function to do the
847 /// construction. Usage:
848 ///
849 /// extern "C" void LLVMInitializeFooTarget() {
850 /// extern Target TheFooTarget;
851 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
852 /// }
853 struct RegisterMCCodeGenInfoFn {
854 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
855 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
856 }
857 };
858
859 /// RegisterMCInstrInfo - Helper template for registering a target instruction
860 /// info implementation. This invokes the static "Create" method on the class
861 /// to actually do the construction. Usage:
862 ///
863 /// extern "C" void LLVMInitializeFooTarget() {
864 /// extern Target TheFooTarget;
865 /// RegisterMCInstrInfo X(TheFooTarget);
866 /// }
867 template
868 struct RegisterMCInstrInfo {
869 RegisterMCInstrInfo(Target &T) {
870 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
871 }
872 private:
873 static MCInstrInfo *Allocator() {
874 return new MCInstrInfoImpl();
875 }
876 };
877
878 /// RegisterMCInstrInfoFn - Helper template for registering a target
879 /// instruction info implementation. This invokes the specified function to
880 /// do the construction. Usage:
881 ///
882 /// extern "C" void LLVMInitializeFooTarget() {
883 /// extern Target TheFooTarget;
884 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
885 /// }
886 struct RegisterMCInstrInfoFn {
887 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
888 TargetRegistry::RegisterMCInstrInfo(T, Fn);
889 }
890 };
891
892 /// RegisterMCInstrAnalysis - Helper template for registering a target
893 /// instruction analyzer implementation. This invokes the static "Create"
894 /// method on the class to actually do the construction. Usage:
895 ///
896 /// extern "C" void LLVMInitializeFooTarget() {
897 /// extern Target TheFooTarget;
898 /// RegisterMCInstrAnalysis X(TheFooTarget);
899 /// }
900 template
901 struct RegisterMCInstrAnalysis {
902 RegisterMCInstrAnalysis(Target &T) {
903 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
904 }
905 private:
906 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
907 return new MCInstrAnalysisImpl(Info);
908 }
909 };
910
911 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
912 /// instruction analyzer implementation. This invokes the specified function
913 /// to do the construction. Usage:
914 ///
915 /// extern "C" void LLVMInitializeFooTarget() {
916 /// extern Target TheFooTarget;
917 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
918 /// }
919 struct RegisterMCInstrAnalysisFn {
920 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
921 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
922 }
923 };
924
925 /// RegisterMCRegInfo - Helper template for registering a target register info
926 /// implementation. This invokes the static "Create" method on the class to
927 /// actually do the construction. Usage:
928 ///
929 /// extern "C" void LLVMInitializeFooTarget() {
930 /// extern Target TheFooTarget;
931 /// RegisterMCRegInfo X(TheFooTarget);
932 /// }
933 template
934 struct RegisterMCRegInfo {
935 RegisterMCRegInfo(Target &T) {
936 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
937 }
938 private:
939 static MCRegisterInfo *Allocator(StringRef TT) {
940 return new MCRegisterInfoImpl();
941 }
942 };
943
944 /// RegisterMCRegInfoFn - Helper template for registering a target register
945 /// info implementation. This invokes the specified function to do the
946 /// construction. Usage:
947 ///
948 /// extern "C" void LLVMInitializeFooTarget() {
949 /// extern Target TheFooTarget;
950 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
951 /// }
952 struct RegisterMCRegInfoFn {
953 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
954 TargetRegistry::RegisterMCRegInfo(T, Fn);
955 }
956 };
957
958 /// RegisterMCSubtargetInfo - Helper template for registering a target
959 /// subtarget info implementation. This invokes the static "Create" method
960 /// on the class to actually do the construction. Usage:
961 ///
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCSubtargetInfo X(TheFooTarget);
965 /// }
966 template
967 struct RegisterMCSubtargetInfo {
968 RegisterMCSubtargetInfo(Target &T) {
969 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
970 }
971 private:
972 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
973 StringRef FS) {
974 return new MCSubtargetInfoImpl();
975 }
976 };
977
978 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
979 /// subtarget info implementation. This invokes the specified function to
980 /// do the construction. Usage:
981 ///
982 /// extern "C" void LLVMInitializeFooTarget() {
983 /// extern Target TheFooTarget;
984 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
985 /// }
986 struct RegisterMCSubtargetInfoFn {
987 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
988 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
989 }
990 };
991
992 /// RegisterTargetMachine - Helper template for registering a target machine
993 /// implementation, for use in the target machine initialization
994 /// function. Usage:
995 ///
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterTargetMachine X(TheFooTarget);
999 /// }
1000 template
1001 struct RegisterTargetMachine {
1002 RegisterTargetMachine(Target &T) {
1003 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1004 }
1005
1006 private:
1007 static TargetMachine *Allocator(const Target &T, StringRef TT,
1008 StringRef CPU, StringRef FS,
1009 Reloc::Model RM,
1010 CodeModel::Model CM) {
1011 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
1012 }
1013 };
1014
1015 /// RegisterMCAsmBackend - Helper template for registering a target specific
1016 /// assembler backend. Usage:
1017 ///
1018 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCAsmBackend X(TheFooTarget);
1021 /// }
1022 template
1023 struct RegisterMCAsmBackend {
1024 RegisterMCAsmBackend(Target &T) {
1025 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1026 }
1027
1028 private:
1029 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1030 return new MCAsmBackendImpl(T, Triple);
1031 }
1032 };
1033
1034 /// RegisterMCAsmLexer - Helper template for registering a target specific
1035 /// assembly lexer, for use in the target machine initialization
1036 /// function. Usage:
1037 ///
1038 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1039 /// extern Target TheFooTarget;
1040 /// RegisterMCAsmLexer X(TheFooTarget);
1041 /// }
1042 template
1043 struct RegisterMCAsmLexer {
1044 RegisterMCAsmLexer(Target &T) {
1045 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1046 }
1047
1048 private:
1049 static MCTargetAsmLexer *Allocator(const Target &T,
1050 const MCRegisterInfo &MRI,
1051 const MCAsmInfo &MAI) {
1052 return new MCAsmLexerImpl(T, MRI, MAI);
1053 }
1054 };
1055
1056 /// RegisterMCAsmParser - Helper template for registering a target specific
1057 /// assembly parser, for use in the target machine initialization
1058 /// function. Usage:
1059 ///
1060 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1061 /// extern Target TheFooTarget;
1062 /// RegisterMCAsmParser X(TheFooTarget);
1063 /// }
1064 template
1065 struct RegisterMCAsmParser {
1066 RegisterMCAsmParser(Target &T) {
1067 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1068 }
1069
1070 private:
1071 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1072 return new MCAsmParserImpl(STI, P);
1073 }
1074 };
1075
1076 /// RegisterAsmPrinter - Helper template for registering a target specific
1077 /// assembly printer, for use in the target machine initialization
1078 /// function. Usage:
1079 ///
1080 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1081 /// extern Target TheFooTarget;
1082 /// RegisterAsmPrinter X(TheFooTarget);
1083 /// }
1084 template
1085 struct RegisterAsmPrinter {
1086 RegisterAsmPrinter(Target &T) {
1087 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1088 }
1089
1090 private:
1091 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1092 return new AsmPrinterImpl(TM, Streamer);
1093 }
1094 };
1095
1096 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1097 /// machine code emitter, for use in the target initialization
1098 /// function. Usage:
1099 ///
1100 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1101 /// extern Target TheFooTarget;
1102 /// RegisterMCCodeEmitter X(TheFooTarget);
1103 /// }
1104 template
1105 struct RegisterMCCodeEmitter {
1106 RegisterMCCodeEmitter(Target &T) {
1107 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1108 }
1109
1110 private:
1111 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1112 const MCSubtargetInfo &STI,
1113 MCContext &Ctx) {
1114 return new MCCodeEmitterImpl();
1115 }
1116 };
1117
1118 }
1119
1120 #endif
0 //===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides utilities to make sure that certain classes of targets are
10 // linked into the main application executable, and initialize them as
11 // appropriate.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_SUPPORT_TARGETSELECT_H
16 #define LLVM_SUPPORT_TARGETSELECT_H
17
18 #include "llvm/Config/llvm-config.h"
19
20 extern "C" {
21 // Declare all of the target-initialization functions that are available.
22 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
23 #include "llvm/Config/Targets.def"
24
25 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
26 #include "llvm/Config/Targets.def"
27
28 // Declare all of the target-MC-initialization functions that are available.
29 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
30 #include "llvm/Config/Targets.def"
31
32 // Declare all of the available assembly printer initialization functions.
33 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
34 #include "llvm/Config/AsmPrinters.def"
35
36 // Declare all of the available assembly parser initialization functions.
37 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
38 #include "llvm/Config/AsmParsers.def"
39
40 // Declare all of the available disassembler initialization functions.
41 #define LLVM_DISASSEMBLER(TargetName) \
42 void LLVMInitialize##TargetName##Disassembler();
43 #include "llvm/Config/Disassemblers.def"
44 }
45
46 namespace llvm {
47 /// InitializeAllTargetInfos - The main program should call this function if
48 /// it wants access to all available targets that LLVM is configured to
49 /// support, to make them available via the TargetRegistry.
50 ///
51 /// It is legal for a client to make multiple calls to this function.
52 inline void InitializeAllTargetInfos() {
53 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54 #include "llvm/Config/Targets.def"
55 }
56
57 /// InitializeAllTargets - The main program should call this function if it
58 /// wants access to all available target machines that LLVM is configured to
59 /// support, to make them available via the TargetRegistry.
60 ///
61 /// It is legal for a client to make multiple calls to this function.
62 inline void InitializeAllTargets() {
63 // FIXME: Remove this, clients should do it.
64 InitializeAllTargetInfos();
65
66 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
67 #include "llvm/Config/Targets.def"
68 }
69
70 /// InitializeAllTargetMCs - The main program should call this function if it
71 /// wants access to all available target MC that LLVM is configured to
72 /// support, to make them available via the TargetRegistry.
73 ///
74 /// It is legal for a client to make multiple calls to this function.
75 inline void InitializeAllTargetMCs() {
76 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
77 #include "llvm/Config/Targets.def"
78 }
79
80 /// InitializeAllAsmPrinters - The main program should call this function if
81 /// it wants all asm printers that LLVM is configured to support, to make them
82 /// available via the TargetRegistry.
83 ///
84 /// It is legal for a client to make multiple calls to this function.
85 inline void InitializeAllAsmPrinters() {
86 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
87 #include "llvm/Config/AsmPrinters.def"
88 }
89
90 /// InitializeAllAsmParsers - The main program should call this function if it
91 /// wants all asm parsers that LLVM is configured to support, to make them
92 /// available via the TargetRegistry.
93 ///
94 /// It is legal for a client to make multiple calls to this function.
95 inline void InitializeAllAsmParsers() {
96 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
97 #include "llvm/Config/AsmParsers.def"
98 }
99
100 /// InitializeAllDisassemblers - The main program should call this function if
101 /// it wants all disassemblers that LLVM is configured to support, to make
102 /// them available via the TargetRegistry.
103 ///
104 /// It is legal for a client to make multiple calls to this function.
105 inline void InitializeAllDisassemblers() {
106 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
107 #include "llvm/Config/Disassemblers.def"
108 }
109
110 /// InitializeNativeTarget - The main program should call this function to
111 /// initialize the native target corresponding to the host. This is useful
112 /// for JIT applications to ensure that the target gets linked in correctly.
113 ///
114 /// It is legal for a client to make multiple calls to this function.
115 inline bool InitializeNativeTarget() {
116 // If we have a native target, initialize it to ensure it is linked in.
117 #ifdef LLVM_NATIVE_TARGET
118 LLVM_NATIVE_TARGETINFO();
119 LLVM_NATIVE_TARGET();
120 LLVM_NATIVE_TARGETMC();
121 return false;
122 #else
123 return true;
124 #endif
125 }
126
127 /// InitializeNativeTargetAsmPrinter - The main program should call
128 /// this function to initialize the native target asm printer.
129 inline bool InitializeNativeTargetAsmPrinter() {
130 // If we have a native target, initialize the corresponding asm printer.
131 #ifdef LLVM_NATIVE_ASMPRINTER
132 LLVM_NATIVE_ASMPRINTER();
133 return false;
134 #else
135 return true;
136 #endif
137 }
138
139 /// InitializeNativeTargetAsmParser - The main program should call
140 /// this function to initialize the native target asm parser.
141 inline bool InitializeNativeTargetAsmParser() {
142 // If we have a native target, initialize the corresponding asm parser.
143 #ifdef LLVM_NATIVE_ASMPARSER
144 LLVM_NATIVE_ASMPARSER();
145 return false;
146 #else
147 return true;
148 #endif
149 }
150
151 }
152
153 #endif
+0
-1121
include/llvm/Target/TargetRegistry.h less more
None //===-- Target/TargetRegistry.h - Target Registration -----------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file exposes the TargetRegistry interface, which tools can use to access
10 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
11 // which have been registered.
12 //
13 // Target specific class implementations should register themselves using the
14 // appropriate TargetRegistry interfaces.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_TARGET_TARGETREGISTRY_H
19 #define LLVM_TARGET_TARGETREGISTRY_H
20
21 #include "llvm/Support/CodeGen.h"
22 #include "llvm/ADT/Triple.h"
23 #include
24 #include
25
26 namespace llvm {
27 class AsmPrinter;
28 class Module;
29 class MCAssembler;
30 class MCAsmBackend;
31 class MCAsmInfo;
32 class MCAsmParser;
33 class MCCodeEmitter;
34 class MCCodeGenInfo;
35 class MCContext;
36 class MCDisassembler;
37 class MCInstrAnalysis;
38 class MCInstPrinter;
39 class MCInstrInfo;
40 class MCRegisterInfo;
41 class MCStreamer;
42 class MCSubtargetInfo;
43 class MCTargetAsmLexer;
44 class MCTargetAsmParser;
45 class TargetMachine;
46 class raw_ostream;
47 class formatted_raw_ostream;
48
49 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
50 bool isVerboseAsm,
51 bool useLoc, bool useCFI,
52 MCInstPrinter *InstPrint,
53 MCCodeEmitter *CE,
54 MCAsmBackend *TAB,
55 bool ShowInst);
56
57 /// Target - Wrapper for Target specific information.
58 ///
59 /// For registration purposes, this is a POD type so that targets can be
60 /// registered without the use of static constructors.
61 ///
62 /// Targets should implement a single global instance of this class (which
63 /// will be zero initialized), and pass that instance to the TargetRegistry as
64 /// part of their initialization.
65 class Target {
66 public:
67 friend struct TargetRegistry;
68
69 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
70
71 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
72 StringRef TT);
73 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
74 Reloc::Model RM,
75 CodeModel::Model CM);
76 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
77 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
78 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
79 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
80 StringRef CPU,
81 StringRef Features);
82 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
83 StringRef TT,
84 StringRef CPU,
85 StringRef Features,
86 Reloc::Model RM,
87 CodeModel::Model CM);
88 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
89 MCStreamer &Streamer);
90 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
91 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
92 const MCRegisterInfo &MRI,
93 const MCAsmInfo &MAI);
94 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
95 MCAsmParser &P);
96 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
97 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
98 unsigned SyntaxVariant,
99 const MCAsmInfo &MAI);
100 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
101 const MCSubtargetInfo &STI,
102 MCContext &Ctx);
103 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
104 StringRef TT,
105 MCContext &Ctx,
106 MCAsmBackend &TAB,
107 raw_ostream &_OS,
108 MCCodeEmitter *_Emitter,
109 bool RelaxAll,
110 bool NoExecStack);
111 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
112 formatted_raw_ostream &OS,
113 bool isVerboseAsm,
114 bool useLoc,
115 bool useCFI,
116 MCInstPrinter *InstPrint,
117 MCCodeEmitter *CE,
118 MCAsmBackend *TAB,
119 bool ShowInst);
120
121 private:
122 /// Next - The next registered target in the linked list, maintained by the
123 /// TargetRegistry.
124 Target *Next;
125
126 /// TripleMatchQualityFn - The target function for rating the match quality
127 /// of a triple.
128 TripleMatchQualityFnTy TripleMatchQualityFn;
129
130 /// Name - The target name.
131 const char *Name;
132
133 /// ShortDesc - A short description of the target.
134 const char *ShortDesc;
135
136 /// HasJIT - Whether this target supports the JIT.
137 bool HasJIT;
138
139 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
140 /// registered.
141 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
142
143 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
144 /// if registered.
145 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
146
147 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
148 /// if registered.
149 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
150
151 /// MCInstrAnalysisCtorFn - Constructor function for this target's
152 /// MCInstrAnalysis, if registered.
153 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
154
155 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
156 /// if registered.
157 MCRegInfoCtorFnTy MCRegInfoCtorFn;
158
159 /// MCSubtargetInfoCtorFn - Constructor function for this target's
160 /// MCSubtargetInfo, if registered.
161 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
162
163 /// TargetMachineCtorFn - Construction function for this target's
164 /// TargetMachine, if registered.
165 TargetMachineCtorTy TargetMachineCtorFn;
166
167 /// MCAsmBackendCtorFn - Construction function for this target's
168 /// MCAsmBackend, if registered.
169 MCAsmBackendCtorTy MCAsmBackendCtorFn;
170
171 /// MCAsmLexerCtorFn - Construction function for this target's
172 /// MCTargetAsmLexer, if registered.
173 MCAsmLexerCtorTy MCAsmLexerCtorFn;
174
175 /// MCAsmParserCtorFn - Construction function for this target's
176 /// MCTargetAsmParser, if registered.
177 MCAsmParserCtorTy MCAsmParserCtorFn;
178
179 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
180 /// if registered.
181 AsmPrinterCtorTy AsmPrinterCtorFn;
182
183 /// MCDisassemblerCtorFn - Construction function for this target's
184 /// MCDisassembler, if registered.
185 MCDisassemblerCtorTy MCDisassemblerCtorFn;
186
187 /// MCInstPrinterCtorFn - Construction function for this target's
188 /// MCInstPrinter, if registered.
189 MCInstPrinterCtorTy MCInstPrinterCtorFn;
190
191 /// MCCodeEmitterCtorFn - Construction function for this target's
192 /// CodeEmitter, if registered.
193 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
194
195 /// MCObjectStreamerCtorFn - Construction function for this target's
196 /// MCObjectStreamer, if registered.
197 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
198
199 /// AsmStreamerCtorFn - Construction function for this target's
200 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
201 AsmStreamerCtorTy AsmStreamerCtorFn;
202
203 public:
204 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
205
206 /// @name Target Information
207 /// @{
208
209 // getNext - Return the next registered target.
210 const Target *getNext() const { return Next; }
211
212 /// getName - Get the target name.
213 const char *getName() const { return Name; }
214
215 /// getShortDescription - Get a short description of the target.
216 const char *getShortDescription() const { return ShortDesc; }
217
218 /// @}
219 /// @name Feature Predicates
220 /// @{
221
222 /// hasJIT - Check if this targets supports the just-in-time compilation.
223 bool hasJIT() const { return HasJIT; }
224
225 /// hasTargetMachine - Check if this target supports code generation.
226 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
227
228 /// hasMCAsmBackend - Check if this target supports .o generation.
229 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
230
231 /// hasMCAsmLexer - Check if this target supports .s lexing.
232 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
233
234 /// hasAsmParser - Check if this target supports .s parsing.
235 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
236
237 /// hasAsmPrinter - Check if this target supports .s printing.
238 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
239
240 /// hasMCDisassembler - Check if this target has a disassembler.
241 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
242
243 /// hasMCInstPrinter - Check if this target has an instruction printer.
244 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
245
246 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
247 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
248
249 /// hasMCObjectStreamer - Check if this target supports streaming to files.
250 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
251
252 /// hasAsmStreamer - Check if this target supports streaming to files.
253 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
254
255 /// @}
256 /// @name Feature Constructors
257 /// @{
258
259 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
260 /// target triple.
261 ///
262 /// \arg Triple - This argument is used to determine the target machine
263 /// feature set; it should always be provided. Generally this should be
264 /// either the target triple from the module, or the target triple of the
265 /// host if that does not exist.
266 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
267 if (!MCAsmInfoCtorFn)
268 return 0;
269 return MCAsmInfoCtorFn(*this, Triple);
270 }
271
272 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
273 ///
274 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
275 CodeModel::Model CM) const {
276 if (!MCCodeGenInfoCtorFn)
277 return 0;
278 return MCCodeGenInfoCtorFn(Triple, RM, CM);
279 }
280
281 /// createMCInstrInfo - Create a MCInstrInfo implementation.
282 ///
283 MCInstrInfo *createMCInstrInfo() const {
284 if (!MCInstrInfoCtorFn)
285 return 0;
286 return MCInstrInfoCtorFn();
287 }
288
289 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
290 ///
291 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
292 if (!MCInstrAnalysisCtorFn)
293 return 0;
294 return MCInstrAnalysisCtorFn(Info);
295 }
296
297 /// createMCRegInfo - Create a MCRegisterInfo implementation.
298 ///
299 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
300 if (!MCRegInfoCtorFn)
301 return 0;
302 return MCRegInfoCtorFn(Triple);
303 }
304
305 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
306 ///
307 /// \arg Triple - This argument is used to determine the target machine
308 /// feature set; it should always be provided. Generally this should be
309 /// either the target triple from the module, or the target triple of the
310 /// host if that does not exist.
311 /// \arg CPU - This specifies the name of the target CPU.
312 /// \arg Features - This specifies the string representation of the
313 /// additional target features.
314 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
315 StringRef Features) const {
316 if (!MCSubtargetInfoCtorFn)
317 return 0;
318 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
319 }
320
321 /// createTargetMachine - Create a target specific machine implementation
322 /// for the specified \arg Triple.
323 ///
324 /// \arg Triple - This argument is used to determine the target machine
325 /// feature set; it should always be provided. Generally this should be
326 /// either the target triple from the module, or the target triple of the
327 /// host if that does not exist.
328 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
329 StringRef Features,
330 Reloc::Model RM = Reloc::Default,
331 CodeModel::Model CM = CodeModel::Default) const {
332 if (!TargetMachineCtorFn)
333 return 0;
334 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
335 }
336
337 /// createMCAsmBackend - Create a target specific assembly parser.
338 ///
339 /// \arg Triple - The target triple string.
340 /// \arg Backend - The target independent assembler object.
341 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
342 if (!MCAsmBackendCtorFn)
343 return 0;
344 return MCAsmBackendCtorFn(*this, Triple);
345 }
346
347 /// createMCAsmLexer - Create a target specific assembly lexer.
348 ///
349 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
350 const MCAsmInfo &MAI) const {
351 if (!MCAsmLexerCtorFn)
352 return 0;
353 return MCAsmLexerCtorFn(*this, MRI, MAI);
354 }
355
356 /// createMCAsmParser - Create a target specific assembly parser.
357 ///
358 /// \arg Parser - The target independent parser implementation to use for
359 /// parsing and lexing.
360 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
361 MCAsmParser &Parser) const {
362 if (!MCAsmParserCtorFn)
363 return 0;
364 return MCAsmParserCtorFn(STI, Parser);
365 }
366
367 /// createAsmPrinter - Create a target specific assembly printer pass. This
368 /// takes ownership of the MCStreamer object.
369 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
370 if (!AsmPrinterCtorFn)
371 return 0;
372 return AsmPrinterCtorFn(TM, Streamer);
373 }
374
375 MCDisassembler *createMCDisassembler() const {
376 if (!MCDisassemblerCtorFn)
377 return 0;
378 return MCDisassemblerCtorFn(*this);
379 }
380
381 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
382 const MCAsmInfo &MAI) const {
383 if (!MCInstPrinterCtorFn)
384 return 0;
385 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
386 }
387
388
389 /// createMCCodeEmitter - Create a target specific code emitter.
390 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
391 const MCSubtargetInfo &STI,
392 MCContext &Ctx) const {
393 if (!MCCodeEmitterCtorFn)
394 return 0;
395 return MCCodeEmitterCtorFn(II, STI, Ctx);
396 }
397
398 /// createMCObjectStreamer - Create a target specific MCStreamer.
399 ///
400 /// \arg TT - The target triple.
401 /// \arg Ctx - The target context.
402 /// \arg TAB - The target assembler backend object. Takes ownership.
403 /// \arg _OS - The stream object.
404 /// \arg _Emitter - The target independent assembler object.Takes ownership.
405 /// \arg RelaxAll - Relax all fixups?
406 /// \arg NoExecStack - Mark file as not needing a executable stack.
407 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
408 MCAsmBackend &TAB,
409 raw_ostream &_OS,
410 MCCodeEmitter *_Emitter,
411 bool RelaxAll,
412 bool NoExecStack) const {
413 if (!MCObjectStreamerCtorFn)
414 return 0;
415 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
416 RelaxAll, NoExecStack);
417 }
418
419 /// createAsmStreamer - Create a target specific MCStreamer.
420 MCStreamer *createAsmStreamer(MCContext &Ctx,
421 formatted_raw_ostream &OS,
422 bool isVerboseAsm,
423 bool useLoc,
424 bool useCFI,
425 MCInstPrinter *InstPrint,
426 MCCodeEmitter *CE,
427 MCAsmBackend *TAB,
428 bool ShowInst) const {
429 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
430 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
431 InstPrint, CE, TAB, ShowInst);
432 }
433
434 /// @}
435 };
436
437 /// TargetRegistry - Generic interface to target specific features.
438 struct TargetRegistry {
439 class iterator {
440 const Target *Current;
441 explicit iterator(Target *T) : Current(T) {}
442 friend struct TargetRegistry;
443 public:
444 iterator(const iterator &I) : Current(I.Current) {}
445 iterator() : Current(0) {}
446
447 bool operator==(const iterator &x) const {
448 return Current == x.Current;
449 }
450 bool operator!=(const iterator &x) const {
451 return !operator==(x);
452 }
453
454 // Iterator traversal: forward iteration only
455 iterator &operator++() { // Preincrement
456 assert(Current && "Cannot increment end iterator!");
457 Current = Current->getNext();
458 return *this;
459 }
460 iterator operator++(int) { // Postincrement
461 iterator tmp = *this;
462 ++*this;
463 return tmp;
464 }
465
466 const Target &operator*() const {
467 assert(Current && "Cannot dereference end iterator!");
468 return *Current;
469 }
470
471 const Target *operator->() const {
472 return &operator*();
473 }
474 };
475
476 /// printRegisteredTargetsForVersion - Print the registered targets
477 /// appropriately for inclusion in a tool's version output.
478 static void printRegisteredTargetsForVersion();
479
480 /// @name Registry Access
481 /// @{
482
483 static iterator begin();
484
485 static iterator end() { return iterator(); }
486
487 /// lookupTarget - Lookup a target based on a target triple.
488 ///
489 /// \param Triple - The triple to use for finding a target.
490 /// \param Error - On failure, an error string describing why no target was
491 /// found.
492 static const Target *lookupTarget(const std::string &Triple,
493 std::string &Error);
494
495 /// getClosestTargetForJIT - Pick the best target that is compatible with
496 /// the current host. If no close target can be found, this returns null
497 /// and sets the Error string to a reason.
498 ///
499 /// Maintained for compatibility through 2.6.
500 static const Target *getClosestTargetForJIT(std::string &Error);
501
502 /// @}
503 /// @name Target Registration
504 /// @{
505
506 /// RegisterTarget - Register the given target. Attempts to register a
507 /// target which has already been registered will be ignored.
508 ///
509 /// Clients are responsible for ensuring that registration doesn't occur
510 /// while another thread is attempting to access the registry. Typically
511 /// this is done by initializing all targets at program startup.
512 ///
513 /// @param T - The target being registered.
514 /// @param Name - The target name. This should be a static string.
515 /// @param ShortDesc - A short target description. This should be a static
516 /// string.
517 /// @param TQualityFn - The triple match quality computation function for
518 /// this target.
519 /// @param HasJIT - Whether the target supports JIT code
520 /// generation.
521 static void RegisterTarget(Target &T,
522 const char *Name,
523 const char *ShortDesc,
524 Target::TripleMatchQualityFnTy TQualityFn,
525 bool HasJIT = false);
526
527 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
528 /// given target.
529 ///
530 /// Clients are responsible for ensuring that registration doesn't occur
531 /// while another thread is attempting to access the registry. Typically
532 /// this is done by initializing all targets at program startup.
533 ///
534 /// @param T - The target being registered.
535 /// @param Fn - A function to construct a MCAsmInfo for the target.
536 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
537 // Ignore duplicate registration.
538 if (!T.MCAsmInfoCtorFn)
539 T.MCAsmInfoCtorFn = Fn;
540 }
541
542 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
543 /// given target.
544 ///
545 /// Clients are responsible for ensuring that registration doesn't occur
546 /// while another thread is attempting to access the registry. Typically
547 /// this is done by initializing all targets at program startup.
548 ///
549 /// @param T - The target being registered.
550 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
551 static void RegisterMCCodeGenInfo(Target &T,
552 Target::MCCodeGenInfoCtorFnTy Fn) {
553 // Ignore duplicate registration.
554 if (!T.MCCodeGenInfoCtorFn)
555 T.MCCodeGenInfoCtorFn = Fn;
556 }
557
558 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
559 /// given target.
560 ///
561 /// Clients are responsible for ensuring that registration doesn't occur
562 /// while another thread is attempting to access the registry. Typically
563 /// this is done by initializing all targets at program startup.
564 ///
565 /// @param T - The target being registered.
566 /// @param Fn - A function to construct a MCInstrInfo for the target.
567 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
568 // Ignore duplicate registration.
569 if (!T.MCInstrInfoCtorFn)
570 T.MCInstrInfoCtorFn = Fn;
571 }
572
573 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
574 /// the given target.
575 static void RegisterMCInstrAnalysis(Target &T,
576 Target::MCInstrAnalysisCtorFnTy Fn) {
577 // Ignore duplicate registration.
578 if (!T.MCInstrAnalysisCtorFn)
579 T.MCInstrAnalysisCtorFn = Fn;
580 }
581
582 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
583 /// given target.
584 ///
585 /// Clients are responsible for ensuring that registration doesn't occur
586 /// while another thread is attempting to access the registry. Typically
587 /// this is done by initializing all targets at program startup.
588 ///
589 /// @param T - The target being registered.
590 /// @param Fn - A function to construct a MCRegisterInfo for the target.
591 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
592 // Ignore duplicate registration.
593 if (!T.MCRegInfoCtorFn)
594 T.MCRegInfoCtorFn = Fn;
595 }
596
597 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
598 /// the given target.
599 ///
600 /// Clients are responsible for ensuring that registration doesn't occur
601 /// while another thread is attempting to access the registry. Typically
602 /// this is done by initializing all targets at program startup.
603 ///
604 /// @param T - The target being registered.
605 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
606 static void RegisterMCSubtargetInfo(Target &T,
607 Target::MCSubtargetInfoCtorFnTy Fn) {
608 // Ignore duplicate registration.
609 if (!T.MCSubtargetInfoCtorFn)
610 T.MCSubtargetInfoCtorFn = Fn;
611 }
612
613 /// RegisterTargetMachine - Register a TargetMachine implementation for the
614 /// given target.
615 ///
616 /// Clients are responsible for ensuring that registration doesn't occur
617 /// while another thread is attempting to access the registry. Typically
618 /// this is done by initializing all targets at program startup.
619 ///
620 /// @param T - The target being registered.
621 /// @param Fn - A function to construct a TargetMachine for the target.
622 static void RegisterTargetMachine(Target &T,
623 Target::TargetMachineCtorTy Fn) {
624 // Ignore duplicate registration.
625 if (!T.TargetMachineCtorFn)
626 T.TargetMachineCtorFn = Fn;
627 }
628
629 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
630 /// given target.
631 ///
632 /// Clients are responsible for ensuring that registration doesn't occur
633 /// while another thread is attempting to access the registry. Typically
634 /// this is done by initializing all targets at program startup.
635 ///
636 /// @param T - The target being registered.
637 /// @param Fn - A function to construct an AsmBackend for the target.
638 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
639 if (!T.MCAsmBackendCtorFn)
640 T.MCAsmBackendCtorFn = Fn;
641 }
642
643 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
644 /// given target.
645 ///
646 /// Clients are responsible for ensuring that registration doesn't occur
647 /// while another thread is attempting to access the registry. Typically
648 /// this is done by initializing all targets at program startup.
649 ///
650 /// @param T - The target being registered.
651 /// @param Fn - A function to construct an MCAsmLexer for the target.
652 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
653 if (!T.MCAsmLexerCtorFn)
654 T.MCAsmLexerCtorFn = Fn;
655 }
656
657 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
658 /// the given target.
659 ///
660 /// Clients are responsible for ensuring that registration doesn't occur
661 /// while another thread is attempting to access the registry. Typically
662 /// this is done by initializing all targets at program startup.
663 ///
664 /// @param T - The target being registered.
665 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
666 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
667 if (!T.MCAsmParserCtorFn)
668 T.MCAsmParserCtorFn = Fn;
669 }
670
671 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
672 /// target.
673 ///
674 /// Clients are responsible for ensuring that registration doesn't occur
675 /// while another thread is attempting to access the registry. Typically
676 /// this is done by initializing all targets at program startup.
677 ///
678 /// @param T - The target being registered.
679 /// @param Fn - A function to construct an AsmPrinter for the target.
680 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
681 // Ignore duplicate registration.
682 if (!T.AsmPrinterCtorFn)
683 T.AsmPrinterCtorFn = Fn;
684 }
685
686 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
687 /// the given target.
688 ///
689 /// Clients are responsible for ensuring that registration doesn't occur
690 /// while another thread is attempting to access the registry. Typically
691 /// this is done by initializing all targets at program startup.
692 ///
693 /// @param T - The target being registered.
694 /// @param Fn - A function to construct an MCDisassembler for the target.
695 static void RegisterMCDisassembler(Target &T,
696 Target::MCDisassemblerCtorTy Fn) {
697 if (!T.MCDisassemblerCtorFn)
698 T.MCDisassemblerCtorFn = Fn;
699 }
700
701 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
702 /// given target.
703 ///
704 /// Clients are responsible for ensuring that registration doesn't occur
705 /// while another thread is attempting to access the registry. Typically
706 /// this is done by initializing all targets at program startup.
707 ///
708 /// @param T - The target being registered.
709 /// @param Fn - A function to construct an MCInstPrinter for the target.
710 static void RegisterMCInstPrinter(Target &T,
711 Target::MCInstPrinterCtorTy Fn) {
712 if (!T.MCInstPrinterCtorFn)
713 T.MCInstPrinterCtorFn = Fn;
714 }
715
716 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
717 /// given target.
718 ///
719 /// Clients are responsible for ensuring that registration doesn't occur
720 /// while another thread is attempting to access the registry. Typically
721 /// this is done by initializing all targets at program startup.
722 ///
723 /// @param T - The target being registered.
724 /// @param Fn - A function to construct an MCCodeEmitter for the target.
725 static void RegisterMCCodeEmitter(Target &T,
726 Target::MCCodeEmitterCtorTy Fn) {
727 if (!T.MCCodeEmitterCtorFn)
728 T.MCCodeEmitterCtorFn = Fn;
729 }
730
731 /// RegisterMCObjectStreamer - Register a object code MCStreamer
732 /// implementation for the given target.
733 ///
734 /// Clients are responsible for ensuring that registration doesn't occur
735 /// while another thread is attempting to access the registry. Typically
736 /// this is done by initializing all targets at program startup.
737 ///
738 /// @param T - The target being registered.
739 /// @param Fn - A function to construct an MCStreamer for the target.
740 static void RegisterMCObjectStreamer(Target &T,
741 Target::MCObjectStreamerCtorTy Fn) {
742 if (!T.MCObjectStreamerCtorFn)
743 T.MCObjectStreamerCtorFn = Fn;
744 }
745
746 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
747 /// for the given target.
748 ///
749 /// Clients are responsible for ensuring that registration doesn't occur
750 /// while another thread is attempting to access the registry. Typically
751 /// this is done by initializing all targets at program startup.
752 ///
753 /// @param T - The target being registered.
754 /// @param Fn - A function to construct an MCStreamer for the target.
755 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
756 if (T.AsmStreamerCtorFn == createAsmStreamer)
757 T.AsmStreamerCtorFn = Fn;
758 }
759
760 /// @}
761 };
762
763
764 //===--------------------------------------------------------------------===//
765
766 /// RegisterTarget - Helper template for registering a target, for use in the
767 /// target's initialization function. Usage:
768 ///
769 ///
770 /// Target TheFooTarget; // The global target instance.
771 ///
772 /// extern "C" void LLVMInitializeFooTargetInfo() {
773 /// RegisterTarget X(TheFooTarget, "foo", "Foo description");
774 /// }
775 template
776 bool HasJIT = false>
777 struct RegisterTarget {
778 RegisterTarget(Target &T, const char *Name, const char *Desc) {
779 TargetRegistry::RegisterTarget(T, Name, Desc,
780 &getTripleMatchQuality,
781 HasJIT);
782 }
783
784 static unsigned getTripleMatchQuality(const std::string &TT) {
785 if (Triple(TT).getArch() == TargetArchType)
786 return 20;
787 return 0;
788 }
789 };
790
791 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
792 /// implementation. This invokes the static "Create" method on the class to
793 /// actually do the construction. Usage:
794 ///
795 /// extern "C" void LLVMInitializeFooTarget() {
796 /// extern Target TheFooTarget;
797 /// RegisterMCAsmInfo X(TheFooTarget);
798 /// }
799 template
800 struct RegisterMCAsmInfo {
801 RegisterMCAsmInfo(Target &T) {
802 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
803 }
804 private:
805 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
806 return new MCAsmInfoImpl(T, TT);
807 }
808
809 };
810
811 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
812 /// implementation. This invokes the specified function to do the
813 /// construction. Usage:
814 ///
815 /// extern "C" void LLVMInitializeFooTarget() {
816 /// extern Target TheFooTarget;
817 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
818 /// }
819 struct RegisterMCAsmInfoFn {
820 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
821 TargetRegistry::RegisterMCAsmInfo(T, Fn);
822 }
823 };
824
825 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
826 /// implementation. This invokes the static "Create" method on the class
827 /// to actually do the construction. Usage:
828 ///
829 /// extern "C" void LLVMInitializeFooTarget() {
830 /// extern Target TheFooTarget;
831 /// RegisterMCCodeGenInfo X(TheFooTarget);
832 /// }
833 template
834 struct RegisterMCCodeGenInfo {
835 RegisterMCCodeGenInfo(Target &T) {
836 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
837 }
838 private:
839 static MCCodeGenInfo *Allocator(StringRef TT,
840 Reloc::Model RM, CodeModel::Model CM) {
841 return new MCCodeGenInfoImpl();
842 }
843 };
844
845 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
846 /// info implementation. This invokes the specified function to do the
847 /// construction. Usage:
848 ///
849 /// extern "C" void LLVMInitializeFooTarget() {
850 /// extern Target TheFooTarget;
851 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
852 /// }
853 struct RegisterMCCodeGenInfoFn {
854 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
855 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
856 }
857 };
858
859 /// RegisterMCInstrInfo - Helper template for registering a target instruction
860 /// info implementation. This invokes the static "Create" method on the class
861 /// to actually do the construction. Usage:
862 ///
863 /// extern "C" void LLVMInitializeFooTarget() {
864 /// extern Target TheFooTarget;
865 /// RegisterMCInstrInfo X(TheFooTarget);
866 /// }
867 template
868 struct RegisterMCInstrInfo {
869 RegisterMCInstrInfo(Target &T) {
870 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
871 }
872 private:
873 static MCInstrInfo *Allocator() {
874 return new MCInstrInfoImpl();
875 }
876 };
877
878 /// RegisterMCInstrInfoFn - Helper template for registering a target
879 /// instruction info implementation. This invokes the specified function to
880 /// do the construction. Usage:
881 ///
882 /// extern "C" void LLVMInitializeFooTarget() {
883 /// extern Target TheFooTarget;
884 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
885 /// }
886 struct RegisterMCInstrInfoFn {
887 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
888 TargetRegistry::RegisterMCInstrInfo(T, Fn);
889 }
890 };
891
892 /// RegisterMCInstrAnalysis - Helper template for registering a target
893 /// instruction analyzer implementation. This invokes the static "Create"
894 /// method on the class to actually do the construction. Usage:
895 ///
896 /// extern "C" void LLVMInitializeFooTarget() {
897 /// extern Target TheFooTarget;
898 /// RegisterMCInstrAnalysis X(TheFooTarget);
899 /// }
900 template
901 struct RegisterMCInstrAnalysis {
902 RegisterMCInstrAnalysis(Target &T) {
903 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
904 }
905 private:
906 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
907 return new MCInstrAnalysisImpl(Info);
908 }
909 };
910
911 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
912 /// instruction analyzer implementation. This invokes the specified function
913 /// to do the construction. Usage:
914 ///
915 /// extern "C" void LLVMInitializeFooTarget() {
916 /// extern Target TheFooTarget;
917 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
918 /// }
919 struct RegisterMCInstrAnalysisFn {
920 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
921 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
922 }
923 };
924
925 /// RegisterMCRegInfo - Helper template for registering a target register info
926 /// implementation. This invokes the static "Create" method on the class to
927 /// actually do the construction. Usage:
928 ///
929 /// extern "C" void LLVMInitializeFooTarget() {
930 /// extern Target TheFooTarget;
931 /// RegisterMCRegInfo X(TheFooTarget);
932 /// }
933 template
934 struct RegisterMCRegInfo {
935 RegisterMCRegInfo(Target &T) {
936 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
937 }
938 private:
939 static MCRegisterInfo *Allocator(StringRef TT) {
940 return new MCRegisterInfoImpl();
941 }
942 };
943
944 /// RegisterMCRegInfoFn - Helper template for registering a target register
945 /// info implementation. This invokes the specified function to do the
946 /// construction. Usage:
947 ///
948 /// extern "C" void LLVMInitializeFooTarget() {
949 /// extern Target TheFooTarget;
950 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
951 /// }
952 struct RegisterMCRegInfoFn {
953 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
954 TargetRegistry::RegisterMCRegInfo(T, Fn);
955 }
956 };
957
958 /// RegisterMCSubtargetInfo - Helper template for registering a target
959 /// subtarget info implementation. This invokes the static "Create" method
960 /// on the class to actually do the construction. Usage:
961 ///
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCSubtargetInfo X(TheFooTarget);
965 /// }
966 template
967 struct RegisterMCSubtargetInfo {
968 RegisterMCSubtargetInfo(Target &T) {
969 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
970 }
971 private:
972 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
973 StringRef FS) {
974 return new MCSubtargetInfoImpl();
975 }
976 };
977
978 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
979 /// subtarget info implementation. This invokes the specified function to
980 /// do the construction. Usage:
981 ///
982 /// extern "C" void LLVMInitializeFooTarget() {
983 /// extern Target TheFooTarget;
984 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
985 /// }
986 struct RegisterMCSubtargetInfoFn {
987 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
988 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
989 }
990 };
991
992 /// RegisterTargetMachine - Helper template for registering a target machine
993 /// implementation, for use in the target machine initialization
994 /// function. Usage:
995 ///
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterTargetMachine X(TheFooTarget);
999 /// }
1000 template
1001 struct RegisterTargetMachine {
1002 RegisterTargetMachine(Target &T) {
1003 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1004 }
1005
1006 private:
1007 static TargetMachine *Allocator(const Target &T, StringRef TT,
1008 StringRef CPU, StringRef FS,
1009 Reloc::Model RM,
1010 CodeModel::Model CM) {
1011 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
1012 }
1013 };
1014
1015 /// RegisterMCAsmBackend - Helper template for registering a target specific
1016 /// assembler backend. Usage:
1017 ///
1018 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1019 /// extern Target TheFooTarget;
1020 /// RegisterMCAsmBackend X(TheFooTarget);
1021 /// }
1022 template
1023 struct RegisterMCAsmBackend {
1024 RegisterMCAsmBackend(Target &T) {
1025 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1026 }
1027
1028 private:
1029 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1030 return new MCAsmBackendImpl(T, Triple);
1031 }
1032 };
1033
1034 /// RegisterMCAsmLexer - Helper template for registering a target specific
1035 /// assembly lexer, for use in the target machine initialization
1036 /// function. Usage:
1037 ///
1038 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1039 /// extern Target TheFooTarget;
1040 /// RegisterMCAsmLexer X(TheFooTarget);
1041 /// }
1042 template
1043 struct RegisterMCAsmLexer {
1044 RegisterMCAsmLexer(Target &T) {
1045 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1046 }
1047
1048 private:
1049 static MCTargetAsmLexer *Allocator(const Target &T,
1050 const MCRegisterInfo &MRI,
1051 const MCAsmInfo &MAI) {
1052 return new MCAsmLexerImpl(T, MRI, MAI);
1053 }
1054 };
1055
1056 /// RegisterMCAsmParser - Helper template for registering a target specific
1057 /// assembly parser, for use in the target machine initialization
1058 /// function. Usage:
1059 ///
1060 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1061 /// extern Target TheFooTarget;
1062 /// RegisterMCAsmParser X(TheFooTarget);
1063 /// }
1064 template
1065 struct RegisterMCAsmParser {
1066 RegisterMCAsmParser(Target &T) {
1067 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1068 }
1069
1070 private:
1071 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1072 return new MCAsmParserImpl(STI, P);
1073 }
1074 };
1075
1076 /// RegisterAsmPrinter - Helper template for registering a target specific
1077 /// assembly printer, for use in the target machine initialization
1078 /// function. Usage:
1079 ///
1080 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1081 /// extern Target TheFooTarget;
1082 /// RegisterAsmPrinter X(TheFooTarget);
1083 /// }
1084 template
1085 struct RegisterAsmPrinter {
1086 RegisterAsmPrinter(Target &T) {
1087 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1088 }
1089
1090 private:
1091 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1092 return new AsmPrinterImpl(TM, Streamer);
1093 }
1094 };
1095
1096 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1097 /// machine code emitter, for use in the target initialization
1098 /// function. Usage:
1099 ///
1100 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1101 /// extern Target TheFooTarget;
1102 /// RegisterMCCodeEmitter X(TheFooTarget);
1103 /// }
1104 template
1105 struct RegisterMCCodeEmitter {
1106 RegisterMCCodeEmitter(Target &T) {
1107 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1108 }
1109
1110 private:
1111 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1112 const MCSubtargetInfo &STI,
1113 MCContext &Ctx) {
1114 return new MCCodeEmitterImpl();
1115 }
1116 };
1117
1118 }
1119
1120 #endif
+0
-154
include/llvm/Target/TargetSelect.h less more
None //===- TargetSelect.h - Target Selection & Registration ---------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides utilities to make sure that certain classes of targets are
10 // linked into the main application executable, and initialize them as
11 // appropriate.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGETSELECT_H
16 #define LLVM_TARGET_TARGETSELECT_H
17
18 #include "llvm/Config/llvm-config.h"
19
20 extern "C" {
21 // Declare all of the target-initialization functions that are available.
22 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
23 #include "llvm/Config/Targets.def"
24
25 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
26 #include "llvm/Config/Targets.def"
27
28 // Declare all of the target-MC-initialization functions that are available.
29 #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetMC();
30 #include "llvm/Config/Targets.def"
31
32 // Declare all of the available assembly printer initialization functions.
33 #define LLVM_ASM_PRINTER(TargetName) void LLVMInitialize##TargetName##AsmPrinter();
34 #include "llvm/Config/AsmPrinters.def"
35
36 // Declare all of the available assembly parser initialization functions.
37 #define LLVM_ASM_PARSER(TargetName) void LLVMInitialize##TargetName##AsmParser();
38 #include "llvm/Config/AsmParsers.def"
39
40 // Declare all of the available disassembler initialization functions.
41 #define LLVM_DISASSEMBLER(TargetName) \
42 void LLVMInitialize##TargetName##Disassembler();
43 #include "llvm/Config/Disassemblers.def"
44 }
45
46 namespace llvm {
47 /// InitializeAllTargetInfos - The main program should call this function if
48 /// it wants access to all available targets that LLVM is configured to
49 /// support, to make them available via the TargetRegistry.
50 ///
51 /// It is legal for a client to make multiple calls to this function.
52 inline void InitializeAllTargetInfos() {
53 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
54 #include "llvm/Config/Targets.def"
55 }
56
57 /// InitializeAllTargets - The main program should call this function if it
58 /// wants access to all available target machines that LLVM is configured to
59 /// support, to make them available via the TargetRegistry.
60 ///
61 /// It is legal for a client to make multiple calls to this function.
62 inline void InitializeAllTargets() {
63 // FIXME: Remove this, clients should do it.
64 InitializeAllTargetInfos();
65
66 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
67 #include "llvm/Config/Targets.def"
68 }
69
70 /// InitializeAllTargetMCs - The main program should call this function if it
71 /// wants access to all available target MC that LLVM is configured to
72 /// support, to make them available via the TargetRegistry.
73 ///
74 /// It is legal for a client to make multiple calls to this function.
75 inline void InitializeAllTargetMCs() {
76 #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC();
77 #include "llvm/Config/Targets.def"
78 }
79
80 /// InitializeAllAsmPrinters - The main program should call this function if
81 /// it wants all asm printers that LLVM is configured to support, to make them
82 /// available via the TargetRegistry.
83 ///
84 /// It is legal for a client to make multiple calls to this function.
85 inline void InitializeAllAsmPrinters() {
86 #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter();
87 #include "llvm/Config/AsmPrinters.def"
88 }
89
90 /// InitializeAllAsmParsers - The main program should call this function if it
91 /// wants all asm parsers that LLVM is configured to support, to make them
92 /// available via the TargetRegistry.
93 ///
94 /// It is legal for a client to make multiple calls to this function.
95 inline void InitializeAllAsmParsers() {
96 #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser();
97 #include "llvm/Config/AsmParsers.def"
98 }
99
100 /// InitializeAllDisassemblers - The main program should call this function if
101 /// it wants all disassemblers that LLVM is configured to support, to make
102 /// them available via the TargetRegistry.
103 ///
104 /// It is legal for a client to make multiple calls to this function.
105 inline void InitializeAllDisassemblers() {
106 #define LLVM_DISASSEMBLER(TargetName) LLVMInitialize##TargetName##Disassembler();
107 #include "llvm/Config/Disassemblers.def"
108 }
109
110 /// InitializeNativeTarget - The main program should call this function to
111 /// initialize the native target corresponding to the host. This is useful
112 /// for JIT applications to ensure that the target gets linked in correctly.
113 ///
114 /// It is legal for a client to make multiple calls to this function.
115 inline bool InitializeNativeTarget() {
116 // If we have a native target, initialize it to ensure it is linked in.
117 #ifdef LLVM_NATIVE_TARGET
118 LLVM_NATIVE_TARGETINFO();
119 LLVM_NATIVE_TARGET();
120 LLVM_NATIVE_TARGETMC();
121 return false;
122 #else
123 return true;
124 #endif
125 }
126
127 /// InitializeNativeTargetAsmPrinter - The main program should call
128 /// this function to initialize the native target asm printer.
129 inline bool InitializeNativeTargetAsmPrinter() {
130 // If we have a native target, initialize the corresponding asm printer.
131 #ifdef LLVM_NATIVE_ASMPRINTER
132 LLVM_NATIVE_ASMPRINTER();
133 return false;
134 #else
135 return true;
136 #endif
137 }
138
139 /// InitializeNativeTargetAsmParser - The main program should call
140 /// this function to initialize the native target asm parser.
141 inline bool InitializeNativeTargetAsmParser() {
142 // If we have a native target, initialize the corresponding asm parser.
143 #ifdef LLVM_NATIVE_ASMPARSER
144 LLVM_NATIVE_ASMPARSER();
145 return false;
146 #else
147 return true;
148 #endif
149 }
150
151 }
152
153 #endif
2424 #include "llvm/MC/MCSymbol.h"
2525 #include "llvm/MC/MCTargetAsmParser.h"
2626 #include "llvm/Target/TargetMachine.h"
27 #include "llvm/Target/TargetRegistry.h"
2827 #include "llvm/ADT/OwningPtr.h"
2928 #include "llvm/ADT/SmallString.h"
3029 #include "llvm/ADT/Twine.h"
3130 #include "llvm/Support/ErrorHandling.h"
3231 #include "llvm/Support/MemoryBuffer.h"
3332 #include "llvm/Support/SourceMgr.h"
33 #include "llvm/Support/TargetRegistry.h"
3434 #include "llvm/Support/raw_ostream.h"
3535 using namespace llvm;
3636
3131 #include "llvm/Target/TargetLowering.h"
3232 #include "llvm/Target/TargetLoweringObjectFile.h"
3333 #include "llvm/Target/TargetRegisterInfo.h"
34 #include "llvm/Target/TargetRegistry.h"
3534 #include "llvm/Target/TargetSubtargetInfo.h"
3635 #include "llvm/Transforms/Scalar.h"
3736 #include "llvm/ADT/OwningPtr.h"
3837 #include "llvm/Support/CommandLine.h"
3938 #include "llvm/Support/Debug.h"
4039 #include "llvm/Support/FormattedStream.h"
40 #include "llvm/Support/TargetRegistry.h"
4141 using namespace llvm;
4242
4343 namespace llvm {
1616 #include "llvm/Module.h"
1717 #include "llvm/ADT/Triple.h"
1818 #include "llvm/MC/SubtargetFeature.h"
19 #include "llvm/Target/TargetMachine.h"
1920 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/Host.h"
22 #include "llvm/Support/TargetRegistry.h"
2023 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/Support/Host.h"
22 #include "llvm/Target/TargetMachine.h"
23 #include "llvm/Target/TargetRegistry.h"
2424 using namespace llvm;
2525
2626 /// selectTarget - Pick a target either via -march or by guessing the native
2525 #include "llvm/Support/Debug.h"
2626 #include "llvm/Support/ErrorHandling.h"
2727 #include "llvm/Support/raw_ostream.h"
28 #include "llvm/Target/TargetRegistry.h"
28 #include "llvm/Support/TargetRegistry.h"
2929
3030 using namespace llvm;
3131
1515 #include "llvm/MC/MCInst.h"
1616 #include "llvm/MC/MCInstPrinter.h"
1717 #include "llvm/MC/MCRegisterInfo.h"
18 #include "llvm/Target/TargetRegistry.h"
19 #include "llvm/Target/TargetSelect.h"
2018 #include "llvm/Support/MemoryObject.h"
19 #include "llvm/Support/TargetRegistry.h"
20 #include "llvm/Support/TargetSelect.h"
2121
2222 namespace llvm {
2323 class Target;
3232 #include "llvm/Support/MemoryBuffer.h"
3333 #include "llvm/Support/MemoryObject.h"
3434 #include "llvm/Support/SourceMgr.h"
35 #include "llvm/Target/TargetRegistry.h"
36 #include "llvm/Target/TargetSelect.h"
35 #include "llvm/Support/TargetRegistry.h"
36 #include "llvm/Support/TargetSelect.h"
3737 using namespace llvm;
3838
3939 bool EDDisassembler::sInitialized = false;
2424 #include "llvm/MC/MCSectionCOFF.h"
2525 #include "llvm/MC/MCWin64EH.h"
2626 #include "llvm/MC/MCAsmBackend.h"
27 #include "llvm/Target/TargetRegistry.h"
2827 #include "llvm/ADT/StringMap.h"
2928
3029 #include "llvm/Support/COFF.h"
3130 #include "llvm/Support/Debug.h"
3231 #include "llvm/Support/ErrorHandling.h"
32 #include "llvm/Support/TargetRegistry.h"
3333 #include "llvm/Support/raw_ostream.h"
3434 using namespace llvm;
3535
7171 SearchForAddressOfSpecialSymbol.cpp
7272 Signals.cpp
7373 system_error.cpp
74 TargetRegistry.cpp
7475 ThreadLocal.cpp
7576 Threading.cpp
7677 TimeValue.cpp
0 //===--- TargetRegistry.cpp - Target registration -------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Support/TargetRegistry.h"
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/Support/Host.h"
13 #include "llvm/Support/raw_ostream.h"
14 #include
15 #include
16 using namespace llvm;
17
18 // Clients are responsible for avoid race conditions in registration.
19 static Target *FirstTarget = 0;
20
21 TargetRegistry::iterator TargetRegistry::begin() {
22 return iterator(FirstTarget);
23 }
24
25 const Target *TargetRegistry::lookupTarget(const std::string &TT,
26 std::string &Error) {
27 // Provide special warning when no targets are initialized.
28 if (begin() == end()) {
29 Error = "Unable to find target for this triple (no targets are registered)";
30 return 0;
31 }
32 const Target *Best = 0, *EquallyBest = 0;
33 unsigned BestQuality = 0;
34 for (iterator it = begin(), ie = end(); it != ie; ++it) {
35 if (unsigned Qual = it->TripleMatchQualityFn(TT)) {
36 if (!Best || Qual > BestQuality) {
37 Best = &*it;
38 EquallyBest = 0;
39 BestQuality = Qual;
40 } else if (Qual == BestQuality)
41 EquallyBest = &*it;
42 }
43 }
44
45 if (!Best) {
46 Error = "No available targets are compatible with this triple, "
47 "see -version for the available targets.";
48 return 0;
49 }
50
51 // Otherwise, take the best target, but make sure we don't have two equally
52 // good best targets.
53 if (EquallyBest) {
54 Error = std::string("Cannot choose between targets \"") +
55 Best->Name + "\" and \"" + EquallyBest->Name + "\"";
56 return 0;
57 }
58
59 return Best;
60 }
61
62 void TargetRegistry::RegisterTarget(Target &T,
63 const char *Name,
64 const char *ShortDesc,
65 Target::TripleMatchQualityFnTy TQualityFn,
66 bool HasJIT) {
67 assert(Name && ShortDesc && TQualityFn &&
68 "Missing required target information!");
69
70 // Check if this target has already been initialized, we allow this as a
71 // convenience to some clients.
72 if (T.Name)
73 return;
74
75 // Add to the list of targets.
76 T.Next = FirstTarget;
77 FirstTarget = &T;
78
79 T.Name = Name;
80 T.ShortDesc = ShortDesc;
81 T.TripleMatchQualityFn = TQualityFn;
82 T.HasJIT = HasJIT;
83 }
84
85 const Target *TargetRegistry::getClosestTargetForJIT(std::string &Error) {
86 const Target *TheTarget = lookupTarget(sys::getHostTriple(), Error);
87
88 if (TheTarget && !TheTarget->hasJIT()) {
89 Error = "No JIT compatible target available for this host";
90 return 0;
91 }
92
93 return TheTarget;
94 }
95
96 static int TargetArraySortFn(const void *LHS, const void *RHS) {
97 typedef std::pair pair_ty;
98 return ((const pair_ty*)LHS)->first.compare(((const pair_ty*)RHS)->first);
99 }
100
101 void TargetRegistry::printRegisteredTargetsForVersion() {
102 std::vector > Targets;
103 size_t Width = 0;
104 for (TargetRegistry::iterator I = TargetRegistry::begin(),
105 E = TargetRegistry::end();
106 I != E; ++I) {
107 Targets.push_back(std::make_pair(I->getName(), &*I));
108 Width = std::max(Width, Targets.back().first.size());
109 }
110 array_pod_sort(Targets.begin(), Targets.end(), TargetArraySortFn);
111
112 raw_ostream &OS = outs();
113 OS << " Registered Targets:\n";
114 for (unsigned i = 0, e = Targets.size(); i != e; ++i) {
115 OS << " " << Targets[i].first;
116 OS.indent(Width - Targets[i].first.size()) << " - "
117 << Targets[i].second->getShortDescription() << '\n';
118 }
119 if (Targets.empty())
120 OS << " (none)\n";
121 }
4444 #include "llvm/Target/TargetData.h"
4545 #include "llvm/Target/TargetMachine.h"
4646 #include "llvm/Target/TargetOptions.h"
47 #include "llvm/Target/TargetRegistry.h"
4847 #include "llvm/ADT/SmallPtrSet.h"
4948 #include "llvm/ADT/SmallString.h"
5049 #include "llvm/ADT/StringExtras.h"
5150 #include "llvm/Support/CommandLine.h"
5251 #include "llvm/Support/Debug.h"
5352 #include "llvm/Support/ErrorHandling.h"
53 #include "llvm/Support/TargetRegistry.h"
5454 #include "llvm/Support/raw_ostream.h"
5555 #include
5656 using namespace llvm;
1616 #include "llvm/CodeGen/Passes.h"
1717 #include "llvm/Support/CommandLine.h"
1818 #include "llvm/Support/FormattedStream.h"
19 #include "llvm/Support/TargetRegistry.h"
1920 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/Target/TargetRegistry.h"
2121 using namespace llvm;
2222
2323 extern "C" void LLVMInitializeARMTarget() {
1414 #include "llvm/MC/MCRegisterInfo.h"
1515 #include "llvm/MC/MCTargetAsmLexer.h"
1616
17 #include "llvm/Target/TargetRegistry.h"
17 #include "llvm/Support/TargetRegistry.h"
1818
1919 #include "llvm/ADT/OwningPtr.h"
2020 #include "llvm/ADT/SmallVector.h"
2121 #include "llvm/MC/MCRegisterInfo.h"
2222 #include "llvm/MC/MCSubtargetInfo.h"
2323 #include "llvm/MC/MCTargetAsmParser.h"
24 #include "llvm/Target/TargetRegistry.h"
2524 #include "llvm/Support/SourceMgr.h"
25 #include "llvm/Support/TargetRegistry.h"
2626 #include "llvm/Support/raw_ostream.h"
2727 #include "llvm/ADT/BitVector.h"
2828 #include "llvm/ADT/OwningPtr.h"
1717 #include "llvm/MC/MCInst.h"
1818 #include "llvm/MC/MCExpr.h"
1919 #include "llvm/MC/MCContext.h"
20 #include "llvm/Target/TargetRegistry.h"
2120 #include "llvm/Support/Debug.h"
2221 #include "llvm/Support/MemoryObject.h"
2322 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
2424 #include "llvm/Support/raw_ostream.h"
2525
2626 // Pull DecodeStatus and its enum values into the global namespace.
2020 #include "llvm/MC/MCRegisterInfo.h"
2121 #include "llvm/MC/MCStreamer.h"
2222 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/Target/TargetRegistry.h"
2423 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/TargetRegistry.h"
2525
2626 #define GET_REGINFO_MC_DESC
2727 #include "ARMGenRegisterInfo.inc"
88
99 #include "ARM.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheARMTarget, llvm::TheThumbTarget;
2525 #include "llvm/Target/Mangler.h"
2626 #include "llvm/Target/TargetLoweringObjectFile.h"
2727 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Target/TargetRegistry.h"
2928 #include "llvm/ADT/SmallString.h"
29 #include "llvm/Support/TargetRegistry.h"
3030 #include "llvm/Support/raw_ostream.h"
3131 using namespace llvm;
3232
1515 #include "AlphaMachineFunctionInfo.h"
1616 #include "llvm/CodeGen/MachineInstrBuilder.h"
1717 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #include "llvm/Target/TargetRegistry.h"
1918 #include "llvm/ADT/STLExtras.h"
2019 #include "llvm/ADT/SmallVector.h"
2120 #include "llvm/Support/ErrorHandling.h"
1212
1313 #include "AlphaSubtarget.h"
1414 #include "Alpha.h"
15 #include "llvm/Target/TargetRegistry.h"
1615
1716 #define GET_SUBTARGETINFO_TARGET_DESC
1817 #define GET_SUBTARGETINFO_CTOR
1313 #include "AlphaTargetMachine.h"
1414 #include "llvm/PassManager.h"
1515 #include "llvm/Support/FormattedStream.h"
16 #include "llvm/Target/TargetRegistry.h"
16 #include "llvm/Support/TargetRegistry.h"
1717 using namespace llvm;
1818
1919 extern "C" void LLVMInitializeAlphaTarget() {
1616 #include "llvm/MC/MCInstrInfo.h"
1717 #include "llvm/MC/MCRegisterInfo.h"
1818 #include "llvm/MC/MCSubtargetInfo.h"
19 #include "llvm/Target/TargetRegistry.h"
19 #include "llvm/Support/TargetRegistry.h"
2020
2121 #define GET_INSTRINFO_MC_DESC
2222 #include "AlphaGenInstrInfo.inc"
88
99 #include "Alpha.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 llvm::Target llvm::TheAlphaTarget;
2828 #include "llvm/Target/Mangler.h"
2929 #include "llvm/Target/TargetData.h"
3030 #include "llvm/Target/TargetLoweringObjectFile.h"
31 #include "llvm/Target/TargetRegistry.h"
3231 #include "llvm/ADT/SmallString.h"
3332 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/TargetRegistry.h"
3434 #include "llvm/Support/raw_ostream.h"
3535 using namespace llvm;
3636
1515 #include "Blackfin.h"
1616 #include "llvm/CodeGen/MachineRegisterInfo.h"
1717 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/Target/TargetRegistry.h"
1918 #include "llvm/ADT/STLExtras.h"
2019 #include "llvm/ADT/SmallVector.h"
2120 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/TargetRegistry.h"
2222
2323 #define GET_INSTRINFO_CTOR
2424 #include "BlackfinGenInstrInfo.inc"
1212
1313 #include "BlackfinSubtarget.h"
1414 #include "Blackfin.h"
15 #include "llvm/Target/TargetRegistry.h"
15 #include "llvm/Support/TargetRegistry.h"
1616
1717 #define GET_SUBTARGETINFO_TARGET_DESC
1818 #define GET_SUBTARGETINFO_CTOR
1212 #include "BlackfinTargetMachine.h"
1313 #include "Blackfin.h"
1414 #include "llvm/PassManager.h"
15 #include "llvm/Target/TargetRegistry.h"
15 #include "llvm/Support/TargetRegistry.h"
1616
1717 using namespace llvm;
1818
1616 #include "llvm/MC/MCInstrInfo.h"
1717 #include "llvm/MC/MCRegisterInfo.h"
1818 #include "llvm/MC/MCSubtargetInfo.h"
19 #include "llvm/Target/TargetRegistry.h"
19 #include "llvm/Support/TargetRegistry.h"
2020
2121 #define GET_INSTRINFO_MC_DESC
2222 #include "BlackfinGenInstrInfo.inc"
88
99 #include "Blackfin.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212
1313 using namespace llvm;
1414
4141 #include "llvm/MC/MCSubtargetInfo.h"
4242 #include "llvm/MC/MCSymbol.h"
4343 #include "llvm/Target/TargetData.h"
44 #include "llvm/Target/TargetRegistry.h"
4544 #include "llvm/Support/CallSite.h"
4645 #include "llvm/Support/CFG.h"
4746 #include "llvm/Support/ErrorHandling.h"
4948 #include "llvm/Support/GetElementPtrTypeIterator.h"
5049 #include "llvm/Support/InstVisitor.h"
5150 #include "llvm/Support/MathExtras.h"
51 #include "llvm/Support/TargetRegistry.h"
5252 #include "llvm/Support/Host.h"
5353 #include "llvm/Config/config.h"
5454 #include
88
99 #include "CTargetMachine.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheCBackendTarget;
99 TargetLoweringObjectFile.cpp
1010 TargetMachine.cpp
1111 TargetRegisterInfo.cpp
12 TargetRegistry.cpp
1312 TargetSubtargetInfo.cpp
1413 )
1514
1717 #include "llvm/MC/MCInstrInfo.h"
1818 #include "llvm/MC/MCRegisterInfo.h"
1919 #include "llvm/MC/MCSubtargetInfo.h"
20 #include "llvm/Target/TargetRegistry.h"
20 #include "llvm/Support/TargetRegistry.h"
2121
2222 #define GET_INSTRINFO_MC_DESC
2323 #include "SPUGenInstrInfo.inc"
2828 #include "llvm/Target/TargetInstrInfo.h"
2929 #include "llvm/Target/TargetOptions.h"
3030 #include "llvm/Target/TargetRegisterInfo.h"
31 #include "llvm/Target/TargetRegistry.h"
3231 #include "llvm/ADT/SmallString.h"
3332 #include "llvm/ADT/StringExtras.h"
3433 #include "llvm/Support/ErrorHandling.h"
34 #include "llvm/Support/TargetRegistry.h"
3535 #include "llvm/Support/raw_ostream.h"
3636 using namespace llvm;
3737
1616 #include "SPUHazardRecognizers.h"
1717 #include "llvm/CodeGen/MachineInstrBuilder.h"
1818 #include "llvm/MC/MCContext.h"
19 #include "llvm/Target/TargetRegistry.h"
2019 #include "llvm/Support/Debug.h"
2120 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/TargetRegistry.h"
2222 #include "llvm/Support/raw_ostream.h"
2323
2424 #define GET_INSTRINFO_CTOR
1313 #include "SPUSubtarget.h"
1414 #include "SPU.h"
1515 #include "SPURegisterInfo.h"
16 #include "llvm/Target/TargetRegistry.h"
16 #include "llvm/Support/TargetRegistry.h"
1717 #include "llvm/ADT/SmallVector.h"
1818
1919 #define GET_SUBTARGETINFO_TARGET_DESC
1515 #include "llvm/PassManager.h"
1616 #include "llvm/CodeGen/RegAllocRegistry.h"
1717 #include "llvm/CodeGen/SchedulerRegistry.h"
18 #include "llvm/Target/TargetRegistry.h"
1918 #include "llvm/Support/DynamicLibrary.h"
19 #include "llvm/Support/TargetRegistry.h"
2020
2121 using namespace llvm;
2222
88
99 #include "SPU.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheCellSPUTarget;
2828 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/Support/ErrorHandling.h"
3030 #include "llvm/Support/FormattedStream.h"
31 #include "llvm/Target/TargetRegistry.h"
31 #include "llvm/Support/TargetRegistry.h"
3232 #include "llvm/ADT/StringExtras.h"
3333 #include "llvm/Config/config.h"
3434 #include
88
99 #include "CPPTargetMachine.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheCppBackendTarget;
1818 #include "llvm/MC/MCRegisterInfo.h"
1919 #include "llvm/MC/MCTargetAsmLexer.h"
2020
21 #include "llvm/Target/TargetRegistry.h"
21 #include "llvm/Support/TargetRegistry.h"
2222
2323 #include
2424 #include
1414 #include "llvm/MC/MCExpr.h"
1515 #include "llvm/MC/MCInst.h"
1616 #include "llvm/MC/MCTargetAsmParser.h"
17 #include "llvm/Target/TargetRegistry.h"
1817 #include "llvm/Support/SourceMgr.h"
18 #include "llvm/Support/TargetRegistry.h"
1919 #include "llvm/Support/raw_ostream.h"
2020 #include "llvm/ADT/OwningPtr.h"
2121 #include "llvm/ADT/SmallVector.h"
1919 #include "llvm/MC/MCDisassembler.h"
2020 #include "llvm/MC/MCDisassembler.h"
2121 #include "llvm/MC/MCInst.h"
22 #include "llvm/Target/TargetRegistry.h"
2322 #include "llvm/Support/Debug.h"
2423 #include "llvm/Support/MemoryObject.h"
24 #include "llvm/Support/TargetRegistry.h"
2525 #include "llvm/Support/raw_ostream.h"
2626
2727 // #include "MBlazeGenDecoderTables.inc"
3737 #include "llvm/Target/TargetLoweringObjectFile.h"
3838 #include "llvm/Target/TargetMachine.h"
3939 #include "llvm/Target/TargetOptions.h"
40 #include "llvm/Target/TargetRegistry.h"
4140 #include "llvm/ADT/SmallString.h"
4241 #include "llvm/ADT/StringExtras.h"
4342 #include "llvm/Support/ErrorHandling.h"
43 #include "llvm/Support/TargetRegistry.h"
4444 #include "llvm/Support/raw_ostream.h"
4545 #include
4646
1616 #include "llvm/CodeGen/MachineInstrBuilder.h"
1717 #include "llvm/CodeGen/MachineRegisterInfo.h"
1818 #include "llvm/CodeGen/ScoreboardHazardRecognizer.h"
19 #include "llvm/Target/TargetRegistry.h"
2019 #include "llvm/Support/CommandLine.h"
2120 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/TargetRegistry.h"
2222 #include "llvm/ADT/STLExtras.h"
2323
2424 #define GET_INSTRINFO_CTOR
1414 #include "MBlaze.h"
1515 #include "MBlazeRegisterInfo.h"
1616 #include "llvm/Support/CommandLine.h"
17 #include "llvm/Target/TargetRegistry.h"
17 #include "llvm/Support/TargetRegistry.h"
1818
1919 #define GET_SUBTARGETINFO_TARGET_DESC
2020 #define GET_SUBTARGETINFO_CTOR
1515 #include "llvm/PassManager.h"
1616 #include "llvm/CodeGen/Passes.h"
1717 #include "llvm/Support/FormattedStream.h"
18 #include "llvm/Support/TargetRegistry.h"
1819 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Target/TargetRegistry.h"
2020 using namespace llvm;
2121
2222 extern "C" void LLVMInitializeMBlazeTarget() {
2020 #include "llvm/ADT/Twine.h"
2121 #include "llvm/Support/ELF.h"
2222 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
2324 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Target/TargetRegistry.h"
2525 using namespace llvm;
2626
2727 static unsigned getFixupKindSize(unsigned Kind) {
1818 #include "llvm/MC/MCRegisterInfo.h"
1919 #include "llvm/MC/MCStreamer.h"
2020 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Target/TargetRegistry.h"
2221 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/TargetRegistry.h"
2323
2424 #define GET_INSTRINFO_MC_DESC
2525 #include "MBlazeGenInstrInfo.inc"
88
99 #include "MBlaze.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheMBlazeTarget;
1717 #include "llvm/MC/MCInstrInfo.h"
1818 #include "llvm/MC/MCRegisterInfo.h"
1919 #include "llvm/MC/MCSubtargetInfo.h"
20 #include "llvm/Target/TargetRegistry.h"
20 #include "llvm/Support/TargetRegistry.h"
2121
2222 #define GET_INSTRINFO_MC_DESC
2323 #include "MSP430GenInstrInfo.inc"
3131 #include "llvm/MC/MCStreamer.h"
3232 #include "llvm/MC/MCSymbol.h"
3333 #include "llvm/Target/Mangler.h"
34 #include "llvm/Target/TargetData.h"
35 #include "llvm/Target/TargetLoweringObjectFile.h"
36 #include "llvm/Target/TargetRegistry.h"
34 #include "llvm/Support/TargetRegistry.h"
3735 #include "llvm/Support/raw_ostream.h"
3836 using namespace llvm;
3937
1919 #include "llvm/CodeGen/MachineInstrBuilder.h"
2020 #include "llvm/CodeGen/MachineRegisterInfo.h"
2121 #include "llvm/CodeGen/PseudoSourceValue.h"
22 #include "llvm/Target/TargetRegistry.h"
2322 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/TargetRegistry.h"
2424
2525 #define GET_INSTRINFO_CTOR
2626 #include "MSP430GenInstrInfo.inc"
1212
1313 #include "MSP430Subtarget.h"
1414 #include "MSP430.h"
15 #include "llvm/Target/TargetRegistry.h"
15 #include "llvm/Support/TargetRegistry.h"
1616
1717 #define GET_SUBTARGETINFO_TARGET_DESC
1818 #define GET_SUBTARGETINFO_CTOR
1515 #include "llvm/PassManager.h"
1616 #include "llvm/CodeGen/Passes.h"
1717 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/Target/TargetRegistry.h"
18 #include "llvm/Support/TargetRegistry.h"
1919 using namespace llvm;
2020
2121 extern "C" void LLVMInitializeMSP430Target() {
88
99 #include "MSP430.h"
1010 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
11 #include "llvm/Support/TargetRegistry.h"
1212 using namespace llvm;
1313
1414 Target llvm::TheMSP430Target;
1818 #include "llvm/MC/MCInstrInfo.h"
1919 #include "llvm/MC/MCRegisterInfo.h"
2020 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Target/TargetRegistry.h"
21 #include "llvm/Support/TargetRegistry.h"
2222
2323 #define GET_INSTRINFO_MC_DESC
2424 #include "MipsGenInstrInfo.inc"
3434 #include "llvm/Target/TargetData.h"
3535 #include "llvm/Target/TargetLoweringObjectFile.h"
3636 #include "llvm/Target/TargetOptions.h"
37 #include "llvm/Target/TargetRegistry.h"
3837 #include "llvm/ADT/SmallString.h"
3938 #include "llvm/ADT/SmallVector.h"
4039 #include "llvm/ADT/StringExtras.h"
4140 #include "llvm/ADT/Twine.h"
41 #include "llvm/Support/TargetRegistry.h"
4242 #include "llvm/Support/raw_ostream.h"
4343 #include "llvm/Analysis/DebugInfo.h"
4444
1616 #include "InstPrinter/MipsInstPrinter.h"
1717 #include "llvm/CodeGen/MachineInstrBuilder.h"
1818 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/Target/TargetRegistry.h"
2019 #include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/TargetRegistry.h"
2121 #include "llvm/ADT/STLExtras.h"
2222
2323 #define GET_INSTRINFO_CTOR
1212
1313 #include "MipsSubtarget.h"
1414 #include "Mips.h"
15 #include "llvm/Target/TargetRegistry.h"
15 #include "llvm/Support/TargetRegistry.h"
1616
1717 #define GET_SUBTARGETINFO_TARGET_DESC
1818 #define GET_SUBTARGETINFO_CTOR
1313 #include "Mips.h"
1414 #include "MipsTargetMachine.h"
1515 #include "llvm/PassManager.h"
16 #include "llvm/Target/TargetRegistry.h"
16 #include "llvm/Support/TargetRegistry.h"
1717 using namespace llvm;
1818
1919 extern "C" void LLVMInitializeMipsTarget() {