1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the TargetRegistry interface, which tools can use to access
11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
12 // which have been registered.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm/Support/CodeGen.h"
23 #include "llvm/ADT/Triple.h"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCTargetAsmLexer;
45 class MCTargetAsmParser;
48 class formatted_raw_ostream;
50 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
52 bool useLoc, bool useCFI,
53 MCInstPrinter *InstPrint,
58 /// Target - Wrapper for Target specific information.
60 /// For registration purposes, this is a POD type so that targets can be
61 /// registered without the use of static constructors.
63 /// Targets should implement a single global instance of this class (which
64 /// will be zero initialized), and pass that instance to the TargetRegistry as
65 /// part of their initialization.
68 friend struct TargetRegistry;
70 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
72 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
74 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
77 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
78 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
79 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
80 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
83 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
89 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
90 MCStreamer &Streamer);
91 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
92 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
93 const MCRegisterInfo &MRI,
94 const MCAsmInfo &MAI);
95 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
97 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
98 const MCSubtargetInfo &STI);
99 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
100 unsigned SyntaxVariant,
101 const MCAsmInfo &MAI,
102 const MCSubtargetInfo &STI);
103 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
104 const MCSubtargetInfo &STI,
106 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
111 MCCodeEmitter *_Emitter,
114 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
115 formatted_raw_ostream &OS,
119 MCInstPrinter *InstPrint,
125 /// Next - The next registered target in the linked list, maintained by the
129 /// TripleMatchQualityFn - The target function for rating the match quality
131 TripleMatchQualityFnTy TripleMatchQualityFn;
133 /// Name - The target name.
136 /// ShortDesc - A short description of the target.
137 const char *ShortDesc;
139 /// HasJIT - Whether this target supports the JIT.
142 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
144 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
146 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
148 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
150 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
152 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
154 /// MCInstrAnalysisCtorFn - Constructor function for this target's
155 /// MCInstrAnalysis, if registered.
156 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
158 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
160 MCRegInfoCtorFnTy MCRegInfoCtorFn;
162 /// MCSubtargetInfoCtorFn - Constructor function for this target's
163 /// MCSubtargetInfo, if registered.
164 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
166 /// TargetMachineCtorFn - Construction function for this target's
167 /// TargetMachine, if registered.
168 TargetMachineCtorTy TargetMachineCtorFn;
170 /// MCAsmBackendCtorFn - Construction function for this target's
171 /// MCAsmBackend, if registered.
172 MCAsmBackendCtorTy MCAsmBackendCtorFn;
174 /// MCAsmLexerCtorFn - Construction function for this target's
175 /// MCTargetAsmLexer, if registered.
176 MCAsmLexerCtorTy MCAsmLexerCtorFn;
178 /// MCAsmParserCtorFn - Construction function for this target's
179 /// MCTargetAsmParser, if registered.
180 MCAsmParserCtorTy MCAsmParserCtorFn;
182 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
184 AsmPrinterCtorTy AsmPrinterCtorFn;
186 /// MCDisassemblerCtorFn - Construction function for this target's
187 /// MCDisassembler, if registered.
188 MCDisassemblerCtorTy MCDisassemblerCtorFn;
190 /// MCInstPrinterCtorFn - Construction function for this target's
191 /// MCInstPrinter, if registered.
192 MCInstPrinterCtorTy MCInstPrinterCtorFn;
194 /// MCCodeEmitterCtorFn - Construction function for this target's
195 /// CodeEmitter, if registered.
196 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
198 /// MCObjectStreamerCtorFn - Construction function for this target's
199 /// MCObjectStreamer, if registered.
200 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
202 /// AsmStreamerCtorFn - Construction function for this target's
203 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
204 AsmStreamerCtorTy AsmStreamerCtorFn;
207 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
209 /// @name Target Information
212 // getNext - Return the next registered target.
213 const Target *getNext() const { return Next; }
215 /// getName - Get the target name.
216 const char *getName() const { return Name; }
218 /// getShortDescription - Get a short description of the target.
219 const char *getShortDescription() const { return ShortDesc; }
222 /// @name Feature Predicates
225 /// hasJIT - Check if this targets supports the just-in-time compilation.
226 bool hasJIT() const { return HasJIT; }
228 /// hasTargetMachine - Check if this target supports code generation.
229 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
231 /// hasMCAsmBackend - Check if this target supports .o generation.
232 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
234 /// hasMCAsmLexer - Check if this target supports .s lexing.
235 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
237 /// hasAsmParser - Check if this target supports .s parsing.
238 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
240 /// hasAsmPrinter - Check if this target supports .s printing.
241 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
243 /// hasMCDisassembler - Check if this target has a disassembler.
244 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
246 /// hasMCInstPrinter - Check if this target has an instruction printer.
247 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
249 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
250 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
252 /// hasMCObjectStreamer - Check if this target supports streaming to files.
253 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
255 /// hasAsmStreamer - Check if this target supports streaming to files.
256 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
259 /// @name Feature Constructors
262 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
265 /// \arg Triple - This argument is used to determine the target machine
266 /// feature set; it should always be provided. Generally this should be
267 /// either the target triple from the module, or the target triple of the
268 /// host if that does not exist.
269 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
270 if (!MCAsmInfoCtorFn)
272 return MCAsmInfoCtorFn(*this, Triple);
275 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
277 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
278 CodeModel::Model CM) const {
279 if (!MCCodeGenInfoCtorFn)
281 return MCCodeGenInfoCtorFn(Triple, RM, CM);
284 /// createMCInstrInfo - Create a MCInstrInfo implementation.
286 MCInstrInfo *createMCInstrInfo() const {
287 if (!MCInstrInfoCtorFn)
289 return MCInstrInfoCtorFn();
292 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
294 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
295 if (!MCInstrAnalysisCtorFn)
297 return MCInstrAnalysisCtorFn(Info);
300 /// createMCRegInfo - Create a MCRegisterInfo implementation.
302 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
303 if (!MCRegInfoCtorFn)
305 return MCRegInfoCtorFn(Triple);
308 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
310 /// \arg Triple - This argument is used to determine the target machine
311 /// feature set; it should always be provided. Generally this should be
312 /// either the target triple from the module, or the target triple of the
313 /// host if that does not exist.
314 /// \arg CPU - This specifies the name of the target CPU.
315 /// \arg Features - This specifies the string representation of the
316 /// additional target features.
317 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
318 StringRef Features) const {
319 if (!MCSubtargetInfoCtorFn)
321 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
324 /// createTargetMachine - Create a target specific machine implementation
325 /// for the specified \arg Triple.
327 /// \arg Triple - This argument is used to determine the target machine
328 /// feature set; it should always be provided. Generally this should be
329 /// either the target triple from the module, or the target triple of the
330 /// host if that does not exist.
331 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
333 Reloc::Model RM = Reloc::Default,
334 CodeModel::Model CM = CodeModel::Default) const {
335 if (!TargetMachineCtorFn)
337 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
340 /// createMCAsmBackend - Create a target specific assembly parser.
342 /// \arg Triple - The target triple string.
343 /// \arg Backend - The target independent assembler object.
344 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
345 if (!MCAsmBackendCtorFn)
347 return MCAsmBackendCtorFn(*this, Triple);
350 /// createMCAsmLexer - Create a target specific assembly lexer.
352 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
353 const MCAsmInfo &MAI) const {
354 if (!MCAsmLexerCtorFn)
356 return MCAsmLexerCtorFn(*this, MRI, MAI);
359 /// createMCAsmParser - Create a target specific assembly parser.
361 /// \arg Parser - The target independent parser implementation to use for
362 /// parsing and lexing.
363 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
364 MCAsmParser &Parser) const {
365 if (!MCAsmParserCtorFn)
367 return MCAsmParserCtorFn(STI, Parser);
370 /// createAsmPrinter - Create a target specific assembly printer pass. This
371 /// takes ownership of the MCStreamer object.
372 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
373 if (!AsmPrinterCtorFn)
375 return AsmPrinterCtorFn(TM, Streamer);
378 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
379 if (!MCDisassemblerCtorFn)
381 return MCDisassemblerCtorFn(*this, STI);
384 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
385 const MCAsmInfo &MAI,
386 const MCSubtargetInfo &STI) const {
387 if (!MCInstPrinterCtorFn)
389 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, STI);
393 /// createMCCodeEmitter - Create a target specific code emitter.
394 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
395 const MCSubtargetInfo &STI,
396 MCContext &Ctx) const {
397 if (!MCCodeEmitterCtorFn)
399 return MCCodeEmitterCtorFn(II, STI, Ctx);
402 /// createMCObjectStreamer - Create a target specific MCStreamer.
404 /// \arg TT - The target triple.
405 /// \arg Ctx - The target context.
406 /// \arg TAB - The target assembler backend object. Takes ownership.
407 /// \arg _OS - The stream object.
408 /// \arg _Emitter - The target independent assembler object.Takes ownership.
409 /// \arg RelaxAll - Relax all fixups?
410 /// \arg NoExecStack - Mark file as not needing a executable stack.
411 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
414 MCCodeEmitter *_Emitter,
416 bool NoExecStack) const {
417 if (!MCObjectStreamerCtorFn)
419 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
420 RelaxAll, NoExecStack);
423 /// createAsmStreamer - Create a target specific MCStreamer.
424 MCStreamer *createAsmStreamer(MCContext &Ctx,
425 formatted_raw_ostream &OS,
429 MCInstPrinter *InstPrint,
432 bool ShowInst) const {
433 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
434 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
435 InstPrint, CE, TAB, ShowInst);
441 /// TargetRegistry - Generic interface to target specific features.
442 struct TargetRegistry {
444 const Target *Current;
445 explicit iterator(Target *T) : Current(T) {}
446 friend struct TargetRegistry;
448 iterator(const iterator &I) : Current(I.Current) {}
449 iterator() : Current(0) {}
451 bool operator==(const iterator &x) const {
452 return Current == x.Current;
454 bool operator!=(const iterator &x) const {
455 return !operator==(x);
458 // Iterator traversal: forward iteration only
459 iterator &operator++() { // Preincrement
460 assert(Current && "Cannot increment end iterator!");
461 Current = Current->getNext();
464 iterator operator++(int) { // Postincrement
465 iterator tmp = *this;
470 const Target &operator*() const {
471 assert(Current && "Cannot dereference end iterator!");
475 const Target *operator->() const {
480 /// printRegisteredTargetsForVersion - Print the registered targets
481 /// appropriately for inclusion in a tool's version output.
482 static void printRegisteredTargetsForVersion();
484 /// @name Registry Access
487 static iterator begin();
489 static iterator end() { return iterator(); }
491 /// lookupTarget - Lookup a target based on a target triple.
493 /// \param Triple - The triple to use for finding a target.
494 /// \param Error - On failure, an error string describing why no target was
496 static const Target *lookupTarget(const std::string &Triple,
499 /// getClosestTargetForJIT - Pick the best target that is compatible with
500 /// the current host. If no close target can be found, this returns null
501 /// and sets the Error string to a reason.
503 /// Maintained for compatibility through 2.6.
504 static const Target *getClosestTargetForJIT(std::string &Error);
507 /// @name Target Registration
510 /// RegisterTarget - Register the given target. Attempts to register a
511 /// target which has already been registered will be ignored.
513 /// Clients are responsible for ensuring that registration doesn't occur
514 /// while another thread is attempting to access the registry. Typically
515 /// this is done by initializing all targets at program startup.
517 /// @param T - The target being registered.
518 /// @param Name - The target name. This should be a static string.
519 /// @param ShortDesc - A short target description. This should be a static
521 /// @param TQualityFn - The triple match quality computation function for
523 /// @param HasJIT - Whether the target supports JIT code
525 static void RegisterTarget(Target &T,
527 const char *ShortDesc,
528 Target::TripleMatchQualityFnTy TQualityFn,
529 bool HasJIT = false);
531 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
534 /// Clients are responsible for ensuring that registration doesn't occur
535 /// while another thread is attempting to access the registry. Typically
536 /// this is done by initializing all targets at program startup.
538 /// @param T - The target being registered.
539 /// @param Fn - A function to construct a MCAsmInfo for the target.
540 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
541 // Ignore duplicate registration.
542 if (!T.MCAsmInfoCtorFn)
543 T.MCAsmInfoCtorFn = Fn;
546 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
549 /// Clients are responsible for ensuring that registration doesn't occur
550 /// while another thread is attempting to access the registry. Typically
551 /// this is done by initializing all targets at program startup.
553 /// @param T - The target being registered.
554 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
555 static void RegisterMCCodeGenInfo(Target &T,
556 Target::MCCodeGenInfoCtorFnTy Fn) {
557 // Ignore duplicate registration.
558 if (!T.MCCodeGenInfoCtorFn)
559 T.MCCodeGenInfoCtorFn = Fn;
562 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
565 /// Clients are responsible for ensuring that registration doesn't occur
566 /// while another thread is attempting to access the registry. Typically
567 /// this is done by initializing all targets at program startup.
569 /// @param T - The target being registered.
570 /// @param Fn - A function to construct a MCInstrInfo for the target.
571 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
572 // Ignore duplicate registration.
573 if (!T.MCInstrInfoCtorFn)
574 T.MCInstrInfoCtorFn = Fn;
577 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
578 /// the given target.
579 static void RegisterMCInstrAnalysis(Target &T,
580 Target::MCInstrAnalysisCtorFnTy Fn) {
581 // Ignore duplicate registration.
582 if (!T.MCInstrAnalysisCtorFn)
583 T.MCInstrAnalysisCtorFn = Fn;
586 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
589 /// Clients are responsible for ensuring that registration doesn't occur
590 /// while another thread is attempting to access the registry. Typically
591 /// this is done by initializing all targets at program startup.
593 /// @param T - The target being registered.
594 /// @param Fn - A function to construct a MCRegisterInfo for the target.
595 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
596 // Ignore duplicate registration.
597 if (!T.MCRegInfoCtorFn)
598 T.MCRegInfoCtorFn = Fn;
601 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
602 /// the given target.
604 /// Clients are responsible for ensuring that registration doesn't occur
605 /// while another thread is attempting to access the registry. Typically
606 /// this is done by initializing all targets at program startup.
608 /// @param T - The target being registered.
609 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
610 static void RegisterMCSubtargetInfo(Target &T,
611 Target::MCSubtargetInfoCtorFnTy Fn) {
612 // Ignore duplicate registration.
613 if (!T.MCSubtargetInfoCtorFn)
614 T.MCSubtargetInfoCtorFn = Fn;
617 /// RegisterTargetMachine - Register a TargetMachine implementation for the
620 /// Clients are responsible for ensuring that registration doesn't occur
621 /// while another thread is attempting to access the registry. Typically
622 /// this is done by initializing all targets at program startup.
624 /// @param T - The target being registered.
625 /// @param Fn - A function to construct a TargetMachine for the target.
626 static void RegisterTargetMachine(Target &T,
627 Target::TargetMachineCtorTy Fn) {
628 // Ignore duplicate registration.
629 if (!T.TargetMachineCtorFn)
630 T.TargetMachineCtorFn = Fn;
633 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
636 /// Clients are responsible for ensuring that registration doesn't occur
637 /// while another thread is attempting to access the registry. Typically
638 /// this is done by initializing all targets at program startup.
640 /// @param T - The target being registered.
641 /// @param Fn - A function to construct an AsmBackend for the target.
642 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
643 if (!T.MCAsmBackendCtorFn)
644 T.MCAsmBackendCtorFn = Fn;
647 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
650 /// Clients are responsible for ensuring that registration doesn't occur
651 /// while another thread is attempting to access the registry. Typically
652 /// this is done by initializing all targets at program startup.
654 /// @param T - The target being registered.
655 /// @param Fn - A function to construct an MCAsmLexer for the target.
656 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
657 if (!T.MCAsmLexerCtorFn)
658 T.MCAsmLexerCtorFn = Fn;
661 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
662 /// the given target.
664 /// Clients are responsible for ensuring that registration doesn't occur
665 /// while another thread is attempting to access the registry. Typically
666 /// this is done by initializing all targets at program startup.
668 /// @param T - The target being registered.
669 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
670 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
671 if (!T.MCAsmParserCtorFn)
672 T.MCAsmParserCtorFn = Fn;
675 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
678 /// Clients are responsible for ensuring that registration doesn't occur
679 /// while another thread is attempting to access the registry. Typically
680 /// this is done by initializing all targets at program startup.
682 /// @param T - The target being registered.
683 /// @param Fn - A function to construct an AsmPrinter for the target.
684 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
685 // Ignore duplicate registration.
686 if (!T.AsmPrinterCtorFn)
687 T.AsmPrinterCtorFn = Fn;
690 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
691 /// the given target.
693 /// Clients are responsible for ensuring that registration doesn't occur
694 /// while another thread is attempting to access the registry. Typically
695 /// this is done by initializing all targets at program startup.
697 /// @param T - The target being registered.
698 /// @param Fn - A function to construct an MCDisassembler for the target.
699 static void RegisterMCDisassembler(Target &T,
700 Target::MCDisassemblerCtorTy Fn) {
701 if (!T.MCDisassemblerCtorFn)
702 T.MCDisassemblerCtorFn = Fn;
705 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
708 /// Clients are responsible for ensuring that registration doesn't occur
709 /// while another thread is attempting to access the registry. Typically
710 /// this is done by initializing all targets at program startup.
712 /// @param T - The target being registered.
713 /// @param Fn - A function to construct an MCInstPrinter for the target.
714 static void RegisterMCInstPrinter(Target &T,
715 Target::MCInstPrinterCtorTy Fn) {
716 if (!T.MCInstPrinterCtorFn)
717 T.MCInstPrinterCtorFn = Fn;
720 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
723 /// Clients are responsible for ensuring that registration doesn't occur
724 /// while another thread is attempting to access the registry. Typically
725 /// this is done by initializing all targets at program startup.
727 /// @param T - The target being registered.
728 /// @param Fn - A function to construct an MCCodeEmitter for the target.
729 static void RegisterMCCodeEmitter(Target &T,
730 Target::MCCodeEmitterCtorTy Fn) {
731 if (!T.MCCodeEmitterCtorFn)
732 T.MCCodeEmitterCtorFn = Fn;
735 /// RegisterMCObjectStreamer - Register a object code MCStreamer
736 /// implementation for the given target.
738 /// Clients are responsible for ensuring that registration doesn't occur
739 /// while another thread is attempting to access the registry. Typically
740 /// this is done by initializing all targets at program startup.
742 /// @param T - The target being registered.
743 /// @param Fn - A function to construct an MCStreamer for the target.
744 static void RegisterMCObjectStreamer(Target &T,
745 Target::MCObjectStreamerCtorTy Fn) {
746 if (!T.MCObjectStreamerCtorFn)
747 T.MCObjectStreamerCtorFn = Fn;
750 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
751 /// for the given target.
753 /// Clients are responsible for ensuring that registration doesn't occur
754 /// while another thread is attempting to access the registry. Typically
755 /// this is done by initializing all targets at program startup.
757 /// @param T - The target being registered.
758 /// @param Fn - A function to construct an MCStreamer for the target.
759 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
760 if (T.AsmStreamerCtorFn == createAsmStreamer)
761 T.AsmStreamerCtorFn = Fn;
768 //===--------------------------------------------------------------------===//
770 /// RegisterTarget - Helper template for registering a target, for use in the
771 /// target's initialization function. Usage:
774 /// Target TheFooTarget; // The global target instance.
776 /// extern "C" void LLVMInitializeFooTargetInfo() {
777 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
779 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
781 struct RegisterTarget {
782 RegisterTarget(Target &T, const char *Name, const char *Desc) {
783 TargetRegistry::RegisterTarget(T, Name, Desc,
784 &getTripleMatchQuality,
788 static unsigned getTripleMatchQuality(const std::string &TT) {
789 if (Triple(TT).getArch() == TargetArchType)
795 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
796 /// implementation. This invokes the static "Create" method on the class to
797 /// actually do the construction. Usage:
799 /// extern "C" void LLVMInitializeFooTarget() {
800 /// extern Target TheFooTarget;
801 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
803 template<class MCAsmInfoImpl>
804 struct RegisterMCAsmInfo {
805 RegisterMCAsmInfo(Target &T) {
806 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
809 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
810 return new MCAsmInfoImpl(T, TT);
815 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
816 /// implementation. This invokes the specified function to do the
817 /// construction. Usage:
819 /// extern "C" void LLVMInitializeFooTarget() {
820 /// extern Target TheFooTarget;
821 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
823 struct RegisterMCAsmInfoFn {
824 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
825 TargetRegistry::RegisterMCAsmInfo(T, Fn);
829 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
830 /// implementation. This invokes the static "Create" method on the class
831 /// to actually do the construction. Usage:
833 /// extern "C" void LLVMInitializeFooTarget() {
834 /// extern Target TheFooTarget;
835 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
837 template<class MCCodeGenInfoImpl>
838 struct RegisterMCCodeGenInfo {
839 RegisterMCCodeGenInfo(Target &T) {
840 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
843 static MCCodeGenInfo *Allocator(StringRef TT,
844 Reloc::Model RM, CodeModel::Model CM) {
845 return new MCCodeGenInfoImpl();
849 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
850 /// info implementation. This invokes the specified function to do the
851 /// construction. Usage:
853 /// extern "C" void LLVMInitializeFooTarget() {
854 /// extern Target TheFooTarget;
855 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
857 struct RegisterMCCodeGenInfoFn {
858 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
859 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
863 /// RegisterMCInstrInfo - Helper template for registering a target instruction
864 /// info implementation. This invokes the static "Create" method on the class
865 /// to actually do the construction. Usage:
867 /// extern "C" void LLVMInitializeFooTarget() {
868 /// extern Target TheFooTarget;
869 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
871 template<class MCInstrInfoImpl>
872 struct RegisterMCInstrInfo {
873 RegisterMCInstrInfo(Target &T) {
874 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
877 static MCInstrInfo *Allocator() {
878 return new MCInstrInfoImpl();
882 /// RegisterMCInstrInfoFn - Helper template for registering a target
883 /// instruction info implementation. This invokes the specified function to
884 /// do the construction. Usage:
886 /// extern "C" void LLVMInitializeFooTarget() {
887 /// extern Target TheFooTarget;
888 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
890 struct RegisterMCInstrInfoFn {
891 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
892 TargetRegistry::RegisterMCInstrInfo(T, Fn);
896 /// RegisterMCInstrAnalysis - Helper template for registering a target
897 /// instruction analyzer implementation. This invokes the static "Create"
898 /// method on the class to actually do the construction. Usage:
900 /// extern "C" void LLVMInitializeFooTarget() {
901 /// extern Target TheFooTarget;
902 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
904 template<class MCInstrAnalysisImpl>
905 struct RegisterMCInstrAnalysis {
906 RegisterMCInstrAnalysis(Target &T) {
907 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
910 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
911 return new MCInstrAnalysisImpl(Info);
915 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
916 /// instruction analyzer implementation. This invokes the specified function
917 /// to do the construction. Usage:
919 /// extern "C" void LLVMInitializeFooTarget() {
920 /// extern Target TheFooTarget;
921 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
923 struct RegisterMCInstrAnalysisFn {
924 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
925 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
929 /// RegisterMCRegInfo - Helper template for registering a target register info
930 /// implementation. This invokes the static "Create" method on the class to
931 /// actually do the construction. Usage:
933 /// extern "C" void LLVMInitializeFooTarget() {
934 /// extern Target TheFooTarget;
935 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
937 template<class MCRegisterInfoImpl>
938 struct RegisterMCRegInfo {
939 RegisterMCRegInfo(Target &T) {
940 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
943 static MCRegisterInfo *Allocator(StringRef TT) {
944 return new MCRegisterInfoImpl();
948 /// RegisterMCRegInfoFn - Helper template for registering a target register
949 /// info implementation. This invokes the specified function to do the
950 /// construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
956 struct RegisterMCRegInfoFn {
957 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
958 TargetRegistry::RegisterMCRegInfo(T, Fn);
962 /// RegisterMCSubtargetInfo - Helper template for registering a target
963 /// subtarget info implementation. This invokes the static "Create" method
964 /// on the class to actually do the construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
970 template<class MCSubtargetInfoImpl>
971 struct RegisterMCSubtargetInfo {
972 RegisterMCSubtargetInfo(Target &T) {
973 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
976 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
978 return new MCSubtargetInfoImpl();
982 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
983 /// subtarget info implementation. This invokes the specified function to
984 /// do the construction. Usage:
986 /// extern "C" void LLVMInitializeFooTarget() {
987 /// extern Target TheFooTarget;
988 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
990 struct RegisterMCSubtargetInfoFn {
991 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
992 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
996 /// RegisterTargetMachine - Helper template for registering a target machine
997 /// implementation, for use in the target machine initialization
1000 /// extern "C" void LLVMInitializeFooTarget() {
1001 /// extern Target TheFooTarget;
1002 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1004 template<class TargetMachineImpl>
1005 struct RegisterTargetMachine {
1006 RegisterTargetMachine(Target &T) {
1007 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1011 static TargetMachine *Allocator(const Target &T, StringRef TT,
1012 StringRef CPU, StringRef FS,
1014 CodeModel::Model CM) {
1015 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
1019 /// RegisterMCAsmBackend - Helper template for registering a target specific
1020 /// assembler backend. Usage:
1022 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1023 /// extern Target TheFooTarget;
1024 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1026 template<class MCAsmBackendImpl>
1027 struct RegisterMCAsmBackend {
1028 RegisterMCAsmBackend(Target &T) {
1029 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1033 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1034 return new MCAsmBackendImpl(T, Triple);
1038 /// RegisterMCAsmLexer - Helper template for registering a target specific
1039 /// assembly lexer, for use in the target machine initialization
1040 /// function. Usage:
1042 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1043 /// extern Target TheFooTarget;
1044 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1046 template<class MCAsmLexerImpl>
1047 struct RegisterMCAsmLexer {
1048 RegisterMCAsmLexer(Target &T) {
1049 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1053 static MCTargetAsmLexer *Allocator(const Target &T,
1054 const MCRegisterInfo &MRI,
1055 const MCAsmInfo &MAI) {
1056 return new MCAsmLexerImpl(T, MRI, MAI);
1060 /// RegisterMCAsmParser - Helper template for registering a target specific
1061 /// assembly parser, for use in the target machine initialization
1062 /// function. Usage:
1064 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1065 /// extern Target TheFooTarget;
1066 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1068 template<class MCAsmParserImpl>
1069 struct RegisterMCAsmParser {
1070 RegisterMCAsmParser(Target &T) {
1071 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1075 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1076 return new MCAsmParserImpl(STI, P);
1080 /// RegisterAsmPrinter - Helper template for registering a target specific
1081 /// assembly printer, for use in the target machine initialization
1082 /// function. Usage:
1084 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1085 /// extern Target TheFooTarget;
1086 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1088 template<class AsmPrinterImpl>
1089 struct RegisterAsmPrinter {
1090 RegisterAsmPrinter(Target &T) {
1091 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1095 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1096 return new AsmPrinterImpl(TM, Streamer);
1100 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1101 /// machine code emitter, for use in the target initialization
1102 /// function. Usage:
1104 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1105 /// extern Target TheFooTarget;
1106 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1108 template<class MCCodeEmitterImpl>
1109 struct RegisterMCCodeEmitter {
1110 RegisterMCCodeEmitter(Target &T) {
1111 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1115 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1116 const MCSubtargetInfo &STI,
1118 return new MCCodeEmitterImpl();