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/ADT/Triple.h"
23 #include "llvm/Support/CodeGen.h"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCTargetAsmParser;
48 class formatted_raw_ostream;
50 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
52 bool useLoc, bool useCFI,
53 bool useDwarfDirectory,
54 MCInstPrinter *InstPrint,
59 /// Target - Wrapper for Target specific information.
61 /// For registration purposes, this is a POD type so that targets can be
62 /// registered without the use of static constructors.
64 /// Targets should implement a single global instance of this class (which
65 /// will be zero initialized), and pass that instance to the TargetRegistry as
66 /// part of their initialization.
69 friend struct TargetRegistry;
71 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
73 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
75 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
78 CodeGenOpt::Level OL);
79 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
80 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
81 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
82 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
85 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
89 const TargetOptions &Options,
92 CodeGenOpt::Level OL);
93 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
94 MCStreamer &Streamer);
95 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
98 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
100 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
101 const MCSubtargetInfo &STI);
102 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
103 unsigned SyntaxVariant,
104 const MCAsmInfo &MAI,
105 const MCInstrInfo &MII,
106 const MCRegisterInfo &MRI,
107 const MCSubtargetInfo &STI);
108 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
109 const MCRegisterInfo &MRI,
110 const MCSubtargetInfo &STI,
112 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
117 MCCodeEmitter *_Emitter,
120 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
121 formatted_raw_ostream &OS,
125 bool useDwarfDirectory,
126 MCInstPrinter *InstPrint,
132 /// Next - The next registered target in the linked list, maintained by the
136 /// TripleMatchQualityFn - The target function for rating the match quality
138 TripleMatchQualityFnTy TripleMatchQualityFn;
140 /// Name - The target name.
143 /// ShortDesc - A short description of the target.
144 const char *ShortDesc;
146 /// HasJIT - Whether this target supports the JIT.
149 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
151 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
153 /// MCCodeGenInfoCtorFn - Constructor function for this target's
154 /// MCCodeGenInfo, if registered.
155 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
157 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
159 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
161 /// MCInstrAnalysisCtorFn - Constructor function for this target's
162 /// MCInstrAnalysis, if registered.
163 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
165 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
167 MCRegInfoCtorFnTy MCRegInfoCtorFn;
169 /// MCSubtargetInfoCtorFn - Constructor function for this target's
170 /// MCSubtargetInfo, if registered.
171 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
173 /// TargetMachineCtorFn - Construction function for this target's
174 /// TargetMachine, if registered.
175 TargetMachineCtorTy TargetMachineCtorFn;
177 /// MCAsmBackendCtorFn - Construction function for this target's
178 /// MCAsmBackend, if registered.
179 MCAsmBackendCtorTy MCAsmBackendCtorFn;
181 /// MCAsmParserCtorFn - Construction function for this target's
182 /// MCTargetAsmParser, if registered.
183 MCAsmParserCtorTy MCAsmParserCtorFn;
185 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
187 AsmPrinterCtorTy AsmPrinterCtorFn;
189 /// MCDisassemblerCtorFn - Construction function for this target's
190 /// MCDisassembler, if registered.
191 MCDisassemblerCtorTy MCDisassemblerCtorFn;
193 /// MCInstPrinterCtorFn - Construction function for this target's
194 /// MCInstPrinter, if registered.
195 MCInstPrinterCtorTy MCInstPrinterCtorFn;
197 /// MCCodeEmitterCtorFn - Construction function for this target's
198 /// CodeEmitter, if registered.
199 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
201 /// MCObjectStreamerCtorFn - Construction function for this target's
202 /// MCObjectStreamer, if registered.
203 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
205 /// AsmStreamerCtorFn - Construction function for this target's
206 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
207 AsmStreamerCtorTy AsmStreamerCtorFn;
210 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
212 /// @name Target Information
215 // getNext - Return the next registered target.
216 const Target *getNext() const { return Next; }
218 /// getName - Get the target name.
219 const char *getName() const { return Name; }
221 /// getShortDescription - Get a short description of the target.
222 const char *getShortDescription() const { return ShortDesc; }
225 /// @name Feature Predicates
228 /// hasJIT - Check if this targets supports the just-in-time compilation.
229 bool hasJIT() const { return HasJIT; }
231 /// hasTargetMachine - Check if this target supports code generation.
232 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
234 /// hasMCAsmBackend - Check if this target supports .o generation.
235 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 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 /// \param 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,
279 CodeGenOpt::Level OL) const {
280 if (!MCCodeGenInfoCtorFn)
282 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
285 /// createMCInstrInfo - Create a MCInstrInfo implementation.
287 MCInstrInfo *createMCInstrInfo() const {
288 if (!MCInstrInfoCtorFn)
290 return MCInstrInfoCtorFn();
293 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
295 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
296 if (!MCInstrAnalysisCtorFn)
298 return MCInstrAnalysisCtorFn(Info);
301 /// createMCRegInfo - Create a MCRegisterInfo implementation.
303 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
304 if (!MCRegInfoCtorFn)
306 return MCRegInfoCtorFn(Triple);
309 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
311 /// \param 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 /// \param CPU This specifies the name of the target CPU.
316 /// \param Features This specifies the string representation of the
317 /// additional target features.
318 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
319 StringRef Features) const {
320 if (!MCSubtargetInfoCtorFn)
322 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
325 /// createTargetMachine - Create a target specific machine implementation
326 /// for the specified \p Triple.
328 /// \param Triple This argument is used to determine the target machine
329 /// feature set; it should always be provided. Generally this should be
330 /// either the target triple from the module, or the target triple of the
331 /// host if that does not exist.
332 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
333 StringRef Features, const TargetOptions &Options,
334 Reloc::Model RM = Reloc::Default,
335 CodeModel::Model CM = CodeModel::Default,
336 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
337 if (!TargetMachineCtorFn)
339 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
343 /// createMCAsmBackend - Create a target specific assembly parser.
345 /// \param Triple The target triple string.
346 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
347 if (!MCAsmBackendCtorFn)
349 return MCAsmBackendCtorFn(*this, Triple, CPU);
352 /// createMCAsmParser - Create a target specific assembly parser.
354 /// \param Parser The target independent parser implementation to use for
355 /// parsing and lexing.
356 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
357 MCAsmParser &Parser) const {
358 if (!MCAsmParserCtorFn)
360 return MCAsmParserCtorFn(STI, Parser);
363 /// createAsmPrinter - Create a target specific assembly printer pass. This
364 /// takes ownership of the MCStreamer object.
365 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
366 if (!AsmPrinterCtorFn)
368 return AsmPrinterCtorFn(TM, Streamer);
371 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
372 if (!MCDisassemblerCtorFn)
374 return MCDisassemblerCtorFn(*this, STI);
377 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
378 const MCAsmInfo &MAI,
379 const MCInstrInfo &MII,
380 const MCRegisterInfo &MRI,
381 const MCSubtargetInfo &STI) const {
382 if (!MCInstPrinterCtorFn)
384 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
388 /// createMCCodeEmitter - Create a target specific code emitter.
389 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
390 const MCRegisterInfo &MRI,
391 const MCSubtargetInfo &STI,
392 MCContext &Ctx) const {
393 if (!MCCodeEmitterCtorFn)
395 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
398 /// createMCObjectStreamer - Create a target specific MCStreamer.
400 /// \param TT The target triple.
401 /// \param Ctx The target context.
402 /// \param TAB The target assembler backend object. Takes ownership.
403 /// \param _OS The stream object.
404 /// \param _Emitter The target independent assembler object.Takes ownership.
405 /// \param RelaxAll Relax all fixups?
406 /// \param NoExecStack Mark file as not needing a executable stack.
407 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
410 MCCodeEmitter *_Emitter,
412 bool NoExecStack) const {
413 if (!MCObjectStreamerCtorFn)
415 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
416 RelaxAll, NoExecStack);
419 /// createAsmStreamer - Create a target specific MCStreamer.
420 MCStreamer *createAsmStreamer(MCContext &Ctx,
421 formatted_raw_ostream &OS,
425 bool useDwarfDirectory,
426 MCInstPrinter *InstPrint,
429 bool ShowInst) const {
430 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
431 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
432 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
438 /// TargetRegistry - Generic interface to target specific features.
439 struct TargetRegistry {
441 const Target *Current;
442 explicit iterator(Target *T) : Current(T) {}
443 friend struct TargetRegistry;
445 iterator(const iterator &I) : Current(I.Current) {}
446 iterator() : Current(0) {}
448 bool operator==(const iterator &x) const {
449 return Current == x.Current;
451 bool operator!=(const iterator &x) const {
452 return !operator==(x);
455 // Iterator traversal: forward iteration only
456 iterator &operator++() { // Preincrement
457 assert(Current && "Cannot increment end iterator!");
458 Current = Current->getNext();
461 iterator operator++(int) { // Postincrement
462 iterator tmp = *this;
467 const Target &operator*() const {
468 assert(Current && "Cannot dereference end iterator!");
472 const Target *operator->() const {
477 /// printRegisteredTargetsForVersion - Print the registered targets
478 /// appropriately for inclusion in a tool's version output.
479 static void printRegisteredTargetsForVersion();
481 /// @name Registry Access
484 static iterator begin();
486 static iterator end() { return iterator(); }
488 /// lookupTarget - Lookup a target based on a target triple.
490 /// \param Triple - The triple to use for finding a target.
491 /// \param Error - On failure, an error string describing why no target was
493 static const Target *lookupTarget(const std::string &Triple,
496 /// lookupTarget - Lookup a target based on an architecture name
497 /// and a target triple. If the architecture name is non-empty,
498 /// then the lookup is done by architecture. Otherwise, the target
501 /// \param ArchName - The architecture to use for finding a target.
502 /// \param TheTriple - The triple to use for finding a target. The
503 /// triple is updated with canonical architecture name if a lookup
504 /// by architecture is done.
505 /// \param Error - On failure, an error string describing why no target was
507 static const Target *lookupTarget(const std::string &ArchName,
511 /// getClosestTargetForJIT - Pick the best target that is compatible with
512 /// the current host. If no close target can be found, this returns null
513 /// and sets the Error string to a reason.
515 /// Maintained for compatibility through 2.6.
516 static const Target *getClosestTargetForJIT(std::string &Error);
519 /// @name Target Registration
522 /// RegisterTarget - Register the given target. Attempts to register a
523 /// target which has already been registered will be ignored.
525 /// Clients are responsible for ensuring that registration doesn't occur
526 /// while another thread is attempting to access the registry. Typically
527 /// this is done by initializing all targets at program startup.
529 /// @param T - The target being registered.
530 /// @param Name - The target name. This should be a static string.
531 /// @param ShortDesc - A short target description. This should be a static
533 /// @param TQualityFn - The triple match quality computation function for
535 /// @param HasJIT - Whether the target supports JIT code
537 static void RegisterTarget(Target &T,
539 const char *ShortDesc,
540 Target::TripleMatchQualityFnTy TQualityFn,
541 bool HasJIT = false);
543 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
546 /// Clients are responsible for ensuring that registration doesn't occur
547 /// while another thread is attempting to access the registry. Typically
548 /// this is done by initializing all targets at program startup.
550 /// @param T - The target being registered.
551 /// @param Fn - A function to construct a MCAsmInfo for the target.
552 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
553 // Ignore duplicate registration.
554 if (!T.MCAsmInfoCtorFn)
555 T.MCAsmInfoCtorFn = Fn;
558 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
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.
565 /// @param T - The target being registered.
566 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
567 static void RegisterMCCodeGenInfo(Target &T,
568 Target::MCCodeGenInfoCtorFnTy Fn) {
569 // Ignore duplicate registration.
570 if (!T.MCCodeGenInfoCtorFn)
571 T.MCCodeGenInfoCtorFn = Fn;
574 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
577 /// Clients are responsible for ensuring that registration doesn't occur
578 /// while another thread is attempting to access the registry. Typically
579 /// this is done by initializing all targets at program startup.
581 /// @param T - The target being registered.
582 /// @param Fn - A function to construct a MCInstrInfo for the target.
583 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
584 // Ignore duplicate registration.
585 if (!T.MCInstrInfoCtorFn)
586 T.MCInstrInfoCtorFn = Fn;
589 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
590 /// the given target.
591 static void RegisterMCInstrAnalysis(Target &T,
592 Target::MCInstrAnalysisCtorFnTy Fn) {
593 // Ignore duplicate registration.
594 if (!T.MCInstrAnalysisCtorFn)
595 T.MCInstrAnalysisCtorFn = Fn;
598 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
601 /// Clients are responsible for ensuring that registration doesn't occur
602 /// while another thread is attempting to access the registry. Typically
603 /// this is done by initializing all targets at program startup.
605 /// @param T - The target being registered.
606 /// @param Fn - A function to construct a MCRegisterInfo for the target.
607 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
608 // Ignore duplicate registration.
609 if (!T.MCRegInfoCtorFn)
610 T.MCRegInfoCtorFn = Fn;
613 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
614 /// the given target.
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.
620 /// @param T - The target being registered.
621 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
622 static void RegisterMCSubtargetInfo(Target &T,
623 Target::MCSubtargetInfoCtorFnTy Fn) {
624 // Ignore duplicate registration.
625 if (!T.MCSubtargetInfoCtorFn)
626 T.MCSubtargetInfoCtorFn = Fn;
629 /// RegisterTargetMachine - Register a TargetMachine implementation for the
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.
636 /// @param T - The target being registered.
637 /// @param Fn - A function to construct a TargetMachine for the target.
638 static void RegisterTargetMachine(Target &T,
639 Target::TargetMachineCtorTy Fn) {
640 // Ignore duplicate registration.
641 if (!T.TargetMachineCtorFn)
642 T.TargetMachineCtorFn = Fn;
645 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
648 /// Clients are responsible for ensuring that registration doesn't occur
649 /// while another thread is attempting to access the registry. Typically
650 /// this is done by initializing all targets at program startup.
652 /// @param T - The target being registered.
653 /// @param Fn - A function to construct an AsmBackend for the target.
654 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
655 if (!T.MCAsmBackendCtorFn)
656 T.MCAsmBackendCtorFn = Fn;
659 /// RegisterMCAsmParser - Register a MCTargetAsmParser 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 MCTargetAsmParser for the target.
668 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
669 if (!T.MCAsmParserCtorFn)
670 T.MCAsmParserCtorFn = Fn;
673 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
676 /// Clients are responsible for ensuring that registration doesn't occur
677 /// while another thread is attempting to access the registry. Typically
678 /// this is done by initializing all targets at program startup.
680 /// @param T - The target being registered.
681 /// @param Fn - A function to construct an AsmPrinter for the target.
682 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
683 // Ignore duplicate registration.
684 if (!T.AsmPrinterCtorFn)
685 T.AsmPrinterCtorFn = Fn;
688 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
689 /// the given target.
691 /// Clients are responsible for ensuring that registration doesn't occur
692 /// while another thread is attempting to access the registry. Typically
693 /// this is done by initializing all targets at program startup.
695 /// @param T - The target being registered.
696 /// @param Fn - A function to construct an MCDisassembler for the target.
697 static void RegisterMCDisassembler(Target &T,
698 Target::MCDisassemblerCtorTy Fn) {
699 if (!T.MCDisassemblerCtorFn)
700 T.MCDisassemblerCtorFn = Fn;
703 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
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 MCInstPrinter for the target.
712 static void RegisterMCInstPrinter(Target &T,
713 Target::MCInstPrinterCtorTy Fn) {
714 if (!T.MCInstPrinterCtorFn)
715 T.MCInstPrinterCtorFn = Fn;
718 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
721 /// Clients are responsible for ensuring that registration doesn't occur
722 /// while another thread is attempting to access the registry. Typically
723 /// this is done by initializing all targets at program startup.
725 /// @param T - The target being registered.
726 /// @param Fn - A function to construct an MCCodeEmitter for the target.
727 static void RegisterMCCodeEmitter(Target &T,
728 Target::MCCodeEmitterCtorTy Fn) {
729 if (!T.MCCodeEmitterCtorFn)
730 T.MCCodeEmitterCtorFn = Fn;
733 /// RegisterMCObjectStreamer - Register a object code MCStreamer
734 /// implementation for the given target.
736 /// Clients are responsible for ensuring that registration doesn't occur
737 /// while another thread is attempting to access the registry. Typically
738 /// this is done by initializing all targets at program startup.
740 /// @param T - The target being registered.
741 /// @param Fn - A function to construct an MCStreamer for the target.
742 static void RegisterMCObjectStreamer(Target &T,
743 Target::MCObjectStreamerCtorTy Fn) {
744 if (!T.MCObjectStreamerCtorFn)
745 T.MCObjectStreamerCtorFn = Fn;
748 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
749 /// for the given target.
751 /// Clients are responsible for ensuring that registration doesn't occur
752 /// while another thread is attempting to access the registry. Typically
753 /// this is done by initializing all targets at program startup.
755 /// @param T - The target being registered.
756 /// @param Fn - A function to construct an MCStreamer for the target.
757 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
758 if (T.AsmStreamerCtorFn == createAsmStreamer)
759 T.AsmStreamerCtorFn = Fn;
766 //===--------------------------------------------------------------------===//
768 /// RegisterTarget - Helper template for registering a target, for use in the
769 /// target's initialization function. Usage:
772 /// Target TheFooTarget; // The global target instance.
774 /// extern "C" void LLVMInitializeFooTargetInfo() {
775 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
777 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
779 struct RegisterTarget {
780 RegisterTarget(Target &T, const char *Name, const char *Desc) {
781 TargetRegistry::RegisterTarget(T, Name, Desc,
782 &getTripleMatchQuality,
786 static unsigned getTripleMatchQuality(const std::string &TT) {
787 if (Triple(TT).getArch() == TargetArchType)
793 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
794 /// implementation. This invokes the static "Create" method on the class to
795 /// actually do the construction. Usage:
797 /// extern "C" void LLVMInitializeFooTarget() {
798 /// extern Target TheFooTarget;
799 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
801 template<class MCAsmInfoImpl>
802 struct RegisterMCAsmInfo {
803 RegisterMCAsmInfo(Target &T) {
804 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
807 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
808 return new MCAsmInfoImpl(T, TT);
813 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
814 /// implementation. This invokes the specified function to do the
815 /// construction. Usage:
817 /// extern "C" void LLVMInitializeFooTarget() {
818 /// extern Target TheFooTarget;
819 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
821 struct RegisterMCAsmInfoFn {
822 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
823 TargetRegistry::RegisterMCAsmInfo(T, Fn);
827 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
828 /// implementation. This invokes the static "Create" method on the class
829 /// to actually do the construction. Usage:
831 /// extern "C" void LLVMInitializeFooTarget() {
832 /// extern Target TheFooTarget;
833 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
835 template<class MCCodeGenInfoImpl>
836 struct RegisterMCCodeGenInfo {
837 RegisterMCCodeGenInfo(Target &T) {
838 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
841 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
842 CodeModel::Model CM, CodeGenOpt::Level OL) {
843 return new MCCodeGenInfoImpl();
847 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
848 /// info implementation. This invokes the specified function to do the
849 /// construction. Usage:
851 /// extern "C" void LLVMInitializeFooTarget() {
852 /// extern Target TheFooTarget;
853 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
855 struct RegisterMCCodeGenInfoFn {
856 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
857 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
861 /// RegisterMCInstrInfo - Helper template for registering a target instruction
862 /// info implementation. This invokes the static "Create" method on the class
863 /// to actually do the construction. Usage:
865 /// extern "C" void LLVMInitializeFooTarget() {
866 /// extern Target TheFooTarget;
867 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
869 template<class MCInstrInfoImpl>
870 struct RegisterMCInstrInfo {
871 RegisterMCInstrInfo(Target &T) {
872 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
875 static MCInstrInfo *Allocator() {
876 return new MCInstrInfoImpl();
880 /// RegisterMCInstrInfoFn - Helper template for registering a target
881 /// instruction info implementation. This invokes the specified function to
882 /// do the construction. Usage:
884 /// extern "C" void LLVMInitializeFooTarget() {
885 /// extern Target TheFooTarget;
886 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
888 struct RegisterMCInstrInfoFn {
889 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
890 TargetRegistry::RegisterMCInstrInfo(T, Fn);
894 /// RegisterMCInstrAnalysis - Helper template for registering a target
895 /// instruction analyzer implementation. This invokes the static "Create"
896 /// method on the class to actually do the construction. Usage:
898 /// extern "C" void LLVMInitializeFooTarget() {
899 /// extern Target TheFooTarget;
900 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
902 template<class MCInstrAnalysisImpl>
903 struct RegisterMCInstrAnalysis {
904 RegisterMCInstrAnalysis(Target &T) {
905 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
908 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
909 return new MCInstrAnalysisImpl(Info);
913 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
914 /// instruction analyzer implementation. This invokes the specified function
915 /// to do the construction. Usage:
917 /// extern "C" void LLVMInitializeFooTarget() {
918 /// extern Target TheFooTarget;
919 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
921 struct RegisterMCInstrAnalysisFn {
922 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
923 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
927 /// RegisterMCRegInfo - Helper template for registering a target register info
928 /// implementation. This invokes the static "Create" method on the class to
929 /// actually do the construction. Usage:
931 /// extern "C" void LLVMInitializeFooTarget() {
932 /// extern Target TheFooTarget;
933 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
935 template<class MCRegisterInfoImpl>
936 struct RegisterMCRegInfo {
937 RegisterMCRegInfo(Target &T) {
938 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
941 static MCRegisterInfo *Allocator(StringRef TT) {
942 return new MCRegisterInfoImpl();
946 /// RegisterMCRegInfoFn - Helper template for registering a target register
947 /// info implementation. This invokes the specified function to do the
948 /// construction. Usage:
950 /// extern "C" void LLVMInitializeFooTarget() {
951 /// extern Target TheFooTarget;
952 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
954 struct RegisterMCRegInfoFn {
955 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
956 TargetRegistry::RegisterMCRegInfo(T, Fn);
960 /// RegisterMCSubtargetInfo - Helper template for registering a target
961 /// subtarget info implementation. This invokes the static "Create" method
962 /// on the class to actually do the construction. Usage:
964 /// extern "C" void LLVMInitializeFooTarget() {
965 /// extern Target TheFooTarget;
966 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
968 template<class MCSubtargetInfoImpl>
969 struct RegisterMCSubtargetInfo {
970 RegisterMCSubtargetInfo(Target &T) {
971 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
974 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
976 return new MCSubtargetInfoImpl();
980 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
981 /// subtarget info implementation. This invokes the specified function to
982 /// do the construction. Usage:
984 /// extern "C" void LLVMInitializeFooTarget() {
985 /// extern Target TheFooTarget;
986 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
988 struct RegisterMCSubtargetInfoFn {
989 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
990 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
994 /// RegisterTargetMachine - Helper template for registering a target machine
995 /// implementation, for use in the target machine initialization
998 /// extern "C" void LLVMInitializeFooTarget() {
999 /// extern Target TheFooTarget;
1000 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1002 template<class TargetMachineImpl>
1003 struct RegisterTargetMachine {
1004 RegisterTargetMachine(Target &T) {
1005 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1009 static TargetMachine *Allocator(const Target &T, StringRef TT,
1010 StringRef CPU, StringRef FS,
1011 const TargetOptions &Options,
1013 CodeModel::Model CM,
1014 CodeGenOpt::Level OL) {
1015 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
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,
1035 return new MCAsmBackendImpl(T, Triple, CPU);
1039 /// RegisterMCAsmParser - Helper template for registering a target specific
1040 /// assembly parser, for use in the target machine initialization
1041 /// function. Usage:
1043 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1044 /// extern Target TheFooTarget;
1045 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1047 template<class MCAsmParserImpl>
1048 struct RegisterMCAsmParser {
1049 RegisterMCAsmParser(Target &T) {
1050 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1054 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1055 return new MCAsmParserImpl(STI, P);
1059 /// RegisterAsmPrinter - Helper template for registering a target specific
1060 /// assembly printer, for use in the target machine initialization
1061 /// function. Usage:
1063 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1064 /// extern Target TheFooTarget;
1065 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1067 template<class AsmPrinterImpl>
1068 struct RegisterAsmPrinter {
1069 RegisterAsmPrinter(Target &T) {
1070 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1074 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1075 return new AsmPrinterImpl(TM, Streamer);
1079 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1080 /// machine code emitter, for use in the target initialization
1081 /// function. Usage:
1083 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1084 /// extern Target TheFooTarget;
1085 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1087 template<class MCCodeEmitterImpl>
1088 struct RegisterMCCodeEmitter {
1089 RegisterMCCodeEmitter(Target &T) {
1090 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1094 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1095 const MCRegisterInfo &MRI,
1096 const MCSubtargetInfo &STI,
1098 return new MCCodeEmitterImpl();