1 //===-- Target/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_TARGET_TARGETREGISTRY_H
20 #define LLVM_TARGET_TARGETREGISTRY_H
22 #include "llvm/MC/MCCodeGenInfo.h"
23 #include "llvm/ADT/Triple.h"
40 class MCSubtargetInfo;
42 class TargetAsmBackend;
44 class TargetAsmParser;
47 class formatted_raw_ostream;
49 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
51 bool useLoc, bool useCFI,
52 MCInstPrinter *InstPrint,
54 TargetAsmBackend *TAB,
57 /// Target - Wrapper for Target specific information.
59 /// For registration purposes, this is a POD type so that targets can be
60 /// registered without the use of static constructors.
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.
67 friend struct TargetRegistry;
69 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
71 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
73 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
76 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
77 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
78 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
81 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
87 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
88 MCStreamer &Streamer);
89 typedef TargetAsmBackend *(*AsmBackendCtorTy)(const Target &T,
90 const std::string &TT);
91 typedef TargetAsmLexer *(*AsmLexerCtorTy)(const Target &T,
92 const MCAsmInfo &MAI);
93 typedef TargetAsmParser *(*AsmParserCtorTy)(MCSubtargetInfo &STI,
95 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T);
96 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
97 unsigned SyntaxVariant,
98 const MCAsmInfo &MAI);
99 typedef MCCodeEmitter *(*CodeEmitterCtorTy)(const MCInstrInfo &II,
100 const MCSubtargetInfo &STI,
102 typedef MCStreamer *(*ObjectStreamerCtorTy)(const Target &T,
103 const std::string &TT,
105 TargetAsmBackend &TAB,
107 MCCodeEmitter *_Emitter,
110 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
111 formatted_raw_ostream &OS,
115 MCInstPrinter *InstPrint,
117 TargetAsmBackend *TAB,
121 /// Next - The next registered target in the linked list, maintained by the
125 /// TripleMatchQualityFn - The target function for rating the match quality
127 TripleMatchQualityFnTy TripleMatchQualityFn;
129 /// Name - The target name.
132 /// ShortDesc - A short description of the target.
133 const char *ShortDesc;
135 /// HasJIT - Whether this target supports the JIT.
138 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
140 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
142 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
144 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
146 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
148 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
150 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
152 MCRegInfoCtorFnTy MCRegInfoCtorFn;
154 /// MCSubtargetInfoCtorFn - Constructor function for this target's
155 /// MCSubtargetInfo, if registered.
156 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
158 /// TargetMachineCtorFn - Construction function for this target's
159 /// TargetMachine, if registered.
160 TargetMachineCtorTy TargetMachineCtorFn;
162 /// AsmBackendCtorFn - Construction function for this target's
163 /// TargetAsmBackend, if registered.
164 AsmBackendCtorTy AsmBackendCtorFn;
166 /// AsmLexerCtorFn - Construction function for this target's TargetAsmLexer,
168 AsmLexerCtorTy AsmLexerCtorFn;
170 /// AsmParserCtorFn - Construction function for this target's
171 /// TargetAsmParser, if registered.
172 AsmParserCtorTy AsmParserCtorFn;
174 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
176 AsmPrinterCtorTy AsmPrinterCtorFn;
178 /// MCDisassemblerCtorFn - Construction function for this target's
179 /// MCDisassembler, if registered.
180 MCDisassemblerCtorTy MCDisassemblerCtorFn;
182 /// MCInstPrinterCtorFn - Construction function for this target's
183 /// MCInstPrinter, if registered.
184 MCInstPrinterCtorTy MCInstPrinterCtorFn;
186 /// CodeEmitterCtorFn - Construction function for this target's CodeEmitter,
188 CodeEmitterCtorTy CodeEmitterCtorFn;
190 /// ObjectStreamerCtorFn - Construction function for this target's
191 /// ObjectStreamer, if registered.
192 ObjectStreamerCtorTy ObjectStreamerCtorFn;
194 /// AsmStreamerCtorFn - Construction function for this target's
195 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
196 AsmStreamerCtorTy AsmStreamerCtorFn;
199 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
201 /// @name Target Information
204 // getNext - Return the next registered target.
205 const Target *getNext() const { return Next; }
207 /// getName - Get the target name.
208 const char *getName() const { return Name; }
210 /// getShortDescription - Get a short description of the target.
211 const char *getShortDescription() const { return ShortDesc; }
214 /// @name Feature Predicates
217 /// hasJIT - Check if this targets supports the just-in-time compilation.
218 bool hasJIT() const { return HasJIT; }
220 /// hasTargetMachine - Check if this target supports code generation.
221 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
223 /// hasAsmBackend - Check if this target supports .o generation.
224 bool hasAsmBackend() const { return AsmBackendCtorFn != 0; }
226 /// hasAsmLexer - Check if this target supports .s lexing.
227 bool hasAsmLexer() const { return AsmLexerCtorFn != 0; }
229 /// hasAsmParser - Check if this target supports .s parsing.
230 bool hasAsmParser() const { return AsmParserCtorFn != 0; }
232 /// hasAsmPrinter - Check if this target supports .s printing.
233 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
235 /// hasMCDisassembler - Check if this target has a disassembler.
236 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
238 /// hasMCInstPrinter - Check if this target has an instruction printer.
239 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
241 /// hasCodeEmitter - Check if this target supports instruction encoding.
242 bool hasCodeEmitter() const { return CodeEmitterCtorFn != 0; }
244 /// hasObjectStreamer - Check if this target supports streaming to files.
245 bool hasObjectStreamer() const { return ObjectStreamerCtorFn != 0; }
247 /// hasAsmStreamer - Check if this target supports streaming to files.
248 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
251 /// @name Feature Constructors
254 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
257 /// \arg Triple - This argument is used to determine the target machine
258 /// feature set; it should always be provided. Generally this should be
259 /// either the target triple from the module, or the target triple of the
260 /// host if that does not exist.
261 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
262 if (!MCAsmInfoCtorFn)
264 return MCAsmInfoCtorFn(*this, Triple);
267 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
269 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
270 CodeModel::Model CM) const {
271 if (!MCCodeGenInfoCtorFn)
273 return MCCodeGenInfoCtorFn(Triple, RM, CM);
276 /// createMCInstrInfo - Create a MCInstrInfo implementation.
278 MCInstrInfo *createMCInstrInfo() const {
279 if (!MCInstrInfoCtorFn)
281 return MCInstrInfoCtorFn();
284 /// createMCRegInfo - Create a MCRegisterInfo implementation.
286 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
287 if (!MCRegInfoCtorFn)
289 return MCRegInfoCtorFn(Triple);
292 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
294 /// \arg Triple - This argument is used to determine the target machine
295 /// feature set; it should always be provided. Generally this should be
296 /// either the target triple from the module, or the target triple of the
297 /// host if that does not exist.
298 /// \arg CPU - This specifies the name of the target CPU.
299 /// \arg Features - This specifies the string representation of the
300 /// additional target features.
301 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
302 StringRef Features) const {
303 if (!MCSubtargetInfoCtorFn)
305 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
308 /// createTargetMachine - Create a target specific machine implementation
309 /// for the specified \arg Triple.
311 /// \arg Triple - This argument is used to determine the target machine
312 /// feature set; it should always be provided. Generally this should be
313 /// either the target triple from the module, or the target triple of the
314 /// host if that does not exist.
315 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
317 Reloc::Model RM = Reloc::Default,
318 CodeModel::Model CM = CodeModel::Default) const {
319 if (!TargetMachineCtorFn)
321 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
324 /// createAsmBackend - Create a target specific assembly parser.
326 /// \arg Triple - The target triple string.
327 /// \arg Backend - The target independent assembler object.
328 TargetAsmBackend *createAsmBackend(const std::string &Triple) const {
329 if (!AsmBackendCtorFn)
331 return AsmBackendCtorFn(*this, Triple);
334 /// createAsmLexer - Create a target specific assembly lexer.
336 TargetAsmLexer *createAsmLexer(const MCAsmInfo &MAI) const {
339 return AsmLexerCtorFn(*this, MAI);
342 /// createAsmParser - Create a target specific assembly parser.
344 /// \arg Parser - The target independent parser implementation to use for
345 /// parsing and lexing.
346 TargetAsmParser *createAsmParser(MCSubtargetInfo &STI,
347 MCAsmParser &Parser) const {
348 if (!AsmParserCtorFn)
350 return AsmParserCtorFn(STI, Parser);
353 /// createAsmPrinter - Create a target specific assembly printer pass. This
354 /// takes ownership of the MCStreamer object.
355 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
356 if (!AsmPrinterCtorFn)
358 return AsmPrinterCtorFn(TM, Streamer);
361 MCDisassembler *createMCDisassembler() const {
362 if (!MCDisassemblerCtorFn)
364 return MCDisassemblerCtorFn(*this);
367 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
368 const MCAsmInfo &MAI) const {
369 if (!MCInstPrinterCtorFn)
371 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI);
375 /// createCodeEmitter - Create a target specific code emitter.
376 MCCodeEmitter *createCodeEmitter(const MCInstrInfo &II,
377 const MCSubtargetInfo &STI,
378 MCContext &Ctx) const {
379 if (!CodeEmitterCtorFn)
381 return CodeEmitterCtorFn(II, STI, Ctx);
384 /// createObjectStreamer - Create a target specific MCStreamer.
386 /// \arg TT - The target triple.
387 /// \arg Ctx - The target context.
388 /// \arg TAB - The target assembler backend object. Takes ownership.
389 /// \arg _OS - The stream object.
390 /// \arg _Emitter - The target independent assembler object.Takes ownership.
391 /// \arg RelaxAll - Relax all fixups?
392 /// \arg NoExecStack - Mark file as not needing a executable stack.
393 MCStreamer *createObjectStreamer(const std::string &TT, MCContext &Ctx,
394 TargetAsmBackend &TAB,
396 MCCodeEmitter *_Emitter,
398 bool NoExecStack) const {
399 if (!ObjectStreamerCtorFn)
401 return ObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter, RelaxAll,
405 /// createAsmStreamer - Create a target specific MCStreamer.
406 MCStreamer *createAsmStreamer(MCContext &Ctx,
407 formatted_raw_ostream &OS,
411 MCInstPrinter *InstPrint,
413 TargetAsmBackend *TAB,
414 bool ShowInst) const {
415 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
416 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
417 InstPrint, CE, TAB, ShowInst);
423 /// TargetRegistry - Generic interface to target specific features.
424 struct TargetRegistry {
426 const Target *Current;
427 explicit iterator(Target *T) : Current(T) {}
428 friend struct TargetRegistry;
430 iterator(const iterator &I) : Current(I.Current) {}
431 iterator() : Current(0) {}
433 bool operator==(const iterator &x) const {
434 return Current == x.Current;
436 bool operator!=(const iterator &x) const {
437 return !operator==(x);
440 // Iterator traversal: forward iteration only
441 iterator &operator++() { // Preincrement
442 assert(Current && "Cannot increment end iterator!");
443 Current = Current->getNext();
446 iterator operator++(int) { // Postincrement
447 iterator tmp = *this;
452 const Target &operator*() const {
453 assert(Current && "Cannot dereference end iterator!");
457 const Target *operator->() const {
462 /// @name Registry Access
465 static iterator begin();
467 static iterator end() { return iterator(); }
469 /// lookupTarget - Lookup a target based on a target triple.
471 /// \param Triple - The triple to use for finding a target.
472 /// \param Error - On failure, an error string describing why no target was
474 static const Target *lookupTarget(const std::string &Triple,
477 /// getClosestTargetForJIT - Pick the best target that is compatible with
478 /// the current host. If no close target can be found, this returns null
479 /// and sets the Error string to a reason.
481 /// Maintained for compatibility through 2.6.
482 static const Target *getClosestTargetForJIT(std::string &Error);
485 /// @name Target Registration
488 /// RegisterTarget - Register the given target. Attempts to register a
489 /// target which has already been registered will be ignored.
491 /// Clients are responsible for ensuring that registration doesn't occur
492 /// while another thread is attempting to access the registry. Typically
493 /// this is done by initializing all targets at program startup.
495 /// @param T - The target being registered.
496 /// @param Name - The target name. This should be a static string.
497 /// @param ShortDesc - A short target description. This should be a static
499 /// @param TQualityFn - The triple match quality computation function for
501 /// @param HasJIT - Whether the target supports JIT code
503 static void RegisterTarget(Target &T,
505 const char *ShortDesc,
506 Target::TripleMatchQualityFnTy TQualityFn,
507 bool HasJIT = false);
509 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
512 /// Clients are responsible for ensuring that registration doesn't occur
513 /// while another thread is attempting to access the registry. Typically
514 /// this is done by initializing all targets at program startup.
516 /// @param T - The target being registered.
517 /// @param Fn - A function to construct a MCAsmInfo for the target.
518 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
519 // Ignore duplicate registration.
520 if (!T.MCAsmInfoCtorFn)
521 T.MCAsmInfoCtorFn = Fn;
524 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
527 /// Clients are responsible for ensuring that registration doesn't occur
528 /// while another thread is attempting to access the registry. Typically
529 /// this is done by initializing all targets at program startup.
531 /// @param T - The target being registered.
532 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
533 static void RegisterMCCodeGenInfo(Target &T,
534 Target::MCCodeGenInfoCtorFnTy Fn) {
535 // Ignore duplicate registration.
536 if (!T.MCCodeGenInfoCtorFn)
537 T.MCCodeGenInfoCtorFn = Fn;
540 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
543 /// Clients are responsible for ensuring that registration doesn't occur
544 /// while another thread is attempting to access the registry. Typically
545 /// this is done by initializing all targets at program startup.
547 /// @param T - The target being registered.
548 /// @param Fn - A function to construct a MCInstrInfo for the target.
549 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
550 // Ignore duplicate registration.
551 if (!T.MCInstrInfoCtorFn)
552 T.MCInstrInfoCtorFn = Fn;
555 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
558 /// Clients are responsible for ensuring that registration doesn't occur
559 /// while another thread is attempting to access the registry. Typically
560 /// this is done by initializing all targets at program startup.
562 /// @param T - The target being registered.
563 /// @param Fn - A function to construct a MCRegisterInfo for the target.
564 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
565 // Ignore duplicate registration.
566 if (!T.MCRegInfoCtorFn)
567 T.MCRegInfoCtorFn = Fn;
570 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
571 /// the given target.
573 /// Clients are responsible for ensuring that registration doesn't occur
574 /// while another thread is attempting to access the registry. Typically
575 /// this is done by initializing all targets at program startup.
577 /// @param T - The target being registered.
578 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
579 static void RegisterMCSubtargetInfo(Target &T,
580 Target::MCSubtargetInfoCtorFnTy Fn) {
581 // Ignore duplicate registration.
582 if (!T.MCSubtargetInfoCtorFn)
583 T.MCSubtargetInfoCtorFn = Fn;
586 /// RegisterTargetMachine - Register a TargetMachine 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 TargetMachine for the target.
595 static void RegisterTargetMachine(Target &T,
596 Target::TargetMachineCtorTy Fn) {
597 // Ignore duplicate registration.
598 if (!T.TargetMachineCtorFn)
599 T.TargetMachineCtorFn = Fn;
602 /// RegisterAsmBackend - Register a TargetAsmBackend implementation for the
605 /// Clients are responsible for ensuring that registration doesn't occur
606 /// while another thread is attempting to access the registry. Typically
607 /// this is done by initializing all targets at program startup.
609 /// @param T - The target being registered.
610 /// @param Fn - A function to construct an AsmBackend for the target.
611 static void RegisterAsmBackend(Target &T, Target::AsmBackendCtorTy Fn) {
612 if (!T.AsmBackendCtorFn)
613 T.AsmBackendCtorFn = Fn;
616 /// RegisterAsmLexer - Register a TargetAsmLexer implementation for the
619 /// Clients are responsible for ensuring that registration doesn't occur
620 /// while another thread is attempting to access the registry. Typically
621 /// this is done by initializing all targets at program startup.
623 /// @param T - The target being registered.
624 /// @param Fn - A function to construct an AsmLexer for the target.
625 static void RegisterAsmLexer(Target &T, Target::AsmLexerCtorTy Fn) {
626 if (!T.AsmLexerCtorFn)
627 T.AsmLexerCtorFn = Fn;
630 /// RegisterAsmParser - Register a TargetAsmParser implementation for the
633 /// Clients are responsible for ensuring that registration doesn't occur
634 /// while another thread is attempting to access the registry. Typically
635 /// this is done by initializing all targets at program startup.
637 /// @param T - The target being registered.
638 /// @param Fn - A function to construct an AsmParser for the target.
639 static void RegisterAsmParser(Target &T, Target::AsmParserCtorTy Fn) {
640 if (!T.AsmParserCtorFn)
641 T.AsmParserCtorFn = Fn;
644 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
647 /// Clients are responsible for ensuring that registration doesn't occur
648 /// while another thread is attempting to access the registry. Typically
649 /// this is done by initializing all targets at program startup.
651 /// @param T - The target being registered.
652 /// @param Fn - A function to construct an AsmPrinter for the target.
653 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
654 // Ignore duplicate registration.
655 if (!T.AsmPrinterCtorFn)
656 T.AsmPrinterCtorFn = Fn;
659 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
660 /// the given target.
662 /// Clients are responsible for ensuring that registration doesn't occur
663 /// while another thread is attempting to access the registry. Typically
664 /// this is done by initializing all targets at program startup.
666 /// @param T - The target being registered.
667 /// @param Fn - A function to construct an MCDisassembler for the target.
668 static void RegisterMCDisassembler(Target &T,
669 Target::MCDisassemblerCtorTy Fn) {
670 if (!T.MCDisassemblerCtorFn)
671 T.MCDisassemblerCtorFn = Fn;
674 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
677 /// Clients are responsible for ensuring that registration doesn't occur
678 /// while another thread is attempting to access the registry. Typically
679 /// this is done by initializing all targets at program startup.
681 /// @param T - The target being registered.
682 /// @param Fn - A function to construct an MCInstPrinter for the target.
683 static void RegisterMCInstPrinter(Target &T,
684 Target::MCInstPrinterCtorTy Fn) {
685 if (!T.MCInstPrinterCtorFn)
686 T.MCInstPrinterCtorFn = Fn;
689 /// RegisterCodeEmitter - Register a MCCodeEmitter implementation for the
692 /// Clients are responsible for ensuring that registration doesn't occur
693 /// while another thread is attempting to access the registry. Typically
694 /// this is done by initializing all targets at program startup.
696 /// @param T - The target being registered.
697 /// @param Fn - A function to construct an MCCodeEmitter for the target.
698 static void RegisterCodeEmitter(Target &T, Target::CodeEmitterCtorTy Fn) {
699 if (!T.CodeEmitterCtorFn)
700 T.CodeEmitterCtorFn = Fn;
703 /// RegisterObjectStreamer - Register a object code MCStreamer implementation
704 /// for the given target.
706 /// Clients are responsible for ensuring that registration doesn't occur
707 /// while another thread is attempting to access the registry. Typically
708 /// this is done by initializing all targets at program startup.
710 /// @param T - The target being registered.
711 /// @param Fn - A function to construct an MCStreamer for the target.
712 static void RegisterObjectStreamer(Target &T, Target::ObjectStreamerCtorTy Fn) {
713 if (!T.ObjectStreamerCtorFn)
714 T.ObjectStreamerCtorFn = Fn;
717 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
718 /// for the given target.
720 /// Clients are responsible for ensuring that registration doesn't occur
721 /// while another thread is attempting to access the registry. Typically
722 /// this is done by initializing all targets at program startup.
724 /// @param T - The target being registered.
725 /// @param Fn - A function to construct an MCStreamer for the target.
726 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
727 if (T.AsmStreamerCtorFn == createAsmStreamer)
728 T.AsmStreamerCtorFn = Fn;
735 //===--------------------------------------------------------------------===//
737 /// RegisterTarget - Helper template for registering a target, for use in the
738 /// target's initialization function. Usage:
741 /// Target TheFooTarget; // The global target instance.
743 /// extern "C" void LLVMInitializeFooTargetInfo() {
744 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
746 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
748 struct RegisterTarget {
749 RegisterTarget(Target &T, const char *Name, const char *Desc) {
750 TargetRegistry::RegisterTarget(T, Name, Desc,
751 &getTripleMatchQuality,
755 static unsigned getTripleMatchQuality(const std::string &TT) {
756 if (Triple(TT).getArch() == TargetArchType)
762 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
763 /// implementation. This invokes the static "Create" method on the class to
764 /// actually do the construction. Usage:
766 /// extern "C" void LLVMInitializeFooTarget() {
767 /// extern Target TheFooTarget;
768 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
770 template<class MCAsmInfoImpl>
771 struct RegisterMCAsmInfo {
772 RegisterMCAsmInfo(Target &T) {
773 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
776 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
777 return new MCAsmInfoImpl(T, TT);
782 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
783 /// implementation. This invokes the specified function to do the
784 /// construction. Usage:
786 /// extern "C" void LLVMInitializeFooTarget() {
787 /// extern Target TheFooTarget;
788 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
790 struct RegisterMCAsmInfoFn {
791 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
792 TargetRegistry::RegisterMCAsmInfo(T, Fn);
796 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
797 /// implementation. This invokes the static "Create" method on the class
798 /// to actually do the construction. Usage:
800 /// extern "C" void LLVMInitializeFooTarget() {
801 /// extern Target TheFooTarget;
802 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
804 template<class MCCodeGenInfoImpl>
805 struct RegisterMCCodeGenInfo {
806 RegisterMCCodeGenInfo(Target &T) {
807 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
810 static MCCodeGenInfo *Allocator(StringRef TT,
811 Reloc::Model RM, CodeModel::Model CM) {
812 return new MCCodeGenInfoImpl();
816 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
817 /// info implementation. This invokes the specified function to do the
818 /// construction. Usage:
820 /// extern "C" void LLVMInitializeFooTarget() {
821 /// extern Target TheFooTarget;
822 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
824 struct RegisterMCCodeGenInfoFn {
825 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
826 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
830 /// RegisterMCInstrInfo - Helper template for registering a target instruction
831 /// info implementation. This invokes the static "Create" method on the class
832 /// to actually do the construction. Usage:
834 /// extern "C" void LLVMInitializeFooTarget() {
835 /// extern Target TheFooTarget;
836 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
838 template<class MCInstrInfoImpl>
839 struct RegisterMCInstrInfo {
840 RegisterMCInstrInfo(Target &T) {
841 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
844 static MCInstrInfo *Allocator() {
845 return new MCInstrInfoImpl();
849 /// RegisterMCInstrInfoFn - Helper template for registering a target
850 /// instruction info implementation. This invokes the specified function to
851 /// do the construction. Usage:
853 /// extern "C" void LLVMInitializeFooTarget() {
854 /// extern Target TheFooTarget;
855 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
857 struct RegisterMCInstrInfoFn {
858 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
859 TargetRegistry::RegisterMCInstrInfo(T, Fn);
863 /// RegisterMCRegInfo - Helper template for registering a target register info
864 /// implementation. This invokes the static "Create" method on the class to
865 /// actually do the construction. Usage:
867 /// extern "C" void LLVMInitializeFooTarget() {
868 /// extern Target TheFooTarget;
869 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
871 template<class MCRegisterInfoImpl>
872 struct RegisterMCRegInfo {
873 RegisterMCRegInfo(Target &T) {
874 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
877 static MCRegisterInfo *Allocator(StringRef TT) {
878 return new MCRegisterInfoImpl();
882 /// RegisterMCRegInfoFn - Helper template for registering a target register
883 /// info implementation. This invokes the specified function to do the
884 /// construction. Usage:
886 /// extern "C" void LLVMInitializeFooTarget() {
887 /// extern Target TheFooTarget;
888 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
890 struct RegisterMCRegInfoFn {
891 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
892 TargetRegistry::RegisterMCRegInfo(T, Fn);
896 /// RegisterMCSubtargetInfo - Helper template for registering a target
897 /// subtarget info implementation. This invokes the static "Create" method
898 /// on the class to actually do the construction. Usage:
900 /// extern "C" void LLVMInitializeFooTarget() {
901 /// extern Target TheFooTarget;
902 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
904 template<class MCSubtargetInfoImpl>
905 struct RegisterMCSubtargetInfo {
906 RegisterMCSubtargetInfo(Target &T) {
907 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
910 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
912 return new MCSubtargetInfoImpl();
916 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
917 /// subtarget info implementation. This invokes the specified function to
918 /// do the construction. Usage:
920 /// extern "C" void LLVMInitializeFooTarget() {
921 /// extern Target TheFooTarget;
922 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
924 struct RegisterMCSubtargetInfoFn {
925 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
926 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
930 /// RegisterTargetMachine - Helper template for registering a target machine
931 /// implementation, for use in the target machine initialization
934 /// extern "C" void LLVMInitializeFooTarget() {
935 /// extern Target TheFooTarget;
936 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
938 template<class TargetMachineImpl>
939 struct RegisterTargetMachine {
940 RegisterTargetMachine(Target &T) {
941 TargetRegistry::RegisterTargetMachine(T, &Allocator);
945 static TargetMachine *Allocator(const Target &T, StringRef TT,
946 StringRef CPU, StringRef FS,
948 CodeModel::Model CM) {
949 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
953 /// RegisterAsmBackend - Helper template for registering a target specific
954 /// assembler backend. Usage:
956 /// extern "C" void LLVMInitializeFooAsmBackend() {
957 /// extern Target TheFooTarget;
958 /// RegisterAsmBackend<FooAsmLexer> X(TheFooTarget);
960 template<class AsmBackendImpl>
961 struct RegisterAsmBackend {
962 RegisterAsmBackend(Target &T) {
963 TargetRegistry::RegisterAsmBackend(T, &Allocator);
967 static TargetAsmBackend *Allocator(const Target &T,
968 const std::string &Triple) {
969 return new AsmBackendImpl(T, Triple);
973 /// RegisterAsmLexer - Helper template for registering a target specific
974 /// assembly lexer, for use in the target machine initialization
977 /// extern "C" void LLVMInitializeFooAsmLexer() {
978 /// extern Target TheFooTarget;
979 /// RegisterAsmLexer<FooAsmLexer> X(TheFooTarget);
981 template<class AsmLexerImpl>
982 struct RegisterAsmLexer {
983 RegisterAsmLexer(Target &T) {
984 TargetRegistry::RegisterAsmLexer(T, &Allocator);
988 static TargetAsmLexer *Allocator(const Target &T, const MCAsmInfo &MAI) {
989 return new AsmLexerImpl(T, MAI);
993 /// RegisterAsmParser - Helper template for registering a target specific
994 /// assembly parser, for use in the target machine initialization
997 /// extern "C" void LLVMInitializeFooAsmParser() {
998 /// extern Target TheFooTarget;
999 /// RegisterAsmParser<FooAsmParser> X(TheFooTarget);
1001 template<class AsmParserImpl>
1002 struct RegisterAsmParser {
1003 RegisterAsmParser(Target &T) {
1004 TargetRegistry::RegisterAsmParser(T, &Allocator);
1008 static TargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1009 return new AsmParserImpl(STI, P);
1013 /// RegisterAsmPrinter - Helper template for registering a target specific
1014 /// assembly printer, for use in the target machine initialization
1015 /// function. Usage:
1017 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1018 /// extern Target TheFooTarget;
1019 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1021 template<class AsmPrinterImpl>
1022 struct RegisterAsmPrinter {
1023 RegisterAsmPrinter(Target &T) {
1024 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1028 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1029 return new AsmPrinterImpl(TM, Streamer);
1033 /// RegisterCodeEmitter - Helper template for registering a target specific
1034 /// machine code emitter, for use in the target initialization
1035 /// function. Usage:
1037 /// extern "C" void LLVMInitializeFooCodeEmitter() {
1038 /// extern Target TheFooTarget;
1039 /// RegisterCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1041 template<class CodeEmitterImpl>
1042 struct RegisterCodeEmitter {
1043 RegisterCodeEmitter(Target &T) {
1044 TargetRegistry::RegisterCodeEmitter(T, &Allocator);
1048 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1049 const MCSubtargetInfo &STI,
1051 return new CodeEmitterImpl();