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;
49 class formatted_raw_ostream;
51 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
53 bool useLoc, bool useCFI,
54 bool useDwarfDirectory,
55 MCInstPrinter *InstPrint,
60 /// Target - Wrapper for Target specific information.
62 /// For registration purposes, this is a POD type so that targets can be
63 /// registered without the use of static constructors.
65 /// Targets should implement a single global instance of this class (which
66 /// will be zero initialized), and pass that instance to the TargetRegistry as
67 /// part of their initialization.
70 friend struct TargetRegistry;
72 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
74 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const Target &T,
76 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
79 CodeGenOpt::Level OL);
80 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
81 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
82 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
83 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
86 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
90 const TargetOptions &Options,
93 CodeGenOpt::Level OL);
94 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
95 MCStreamer &Streamer);
96 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
97 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
98 const MCRegisterInfo &MRI,
99 const MCAsmInfo &MAI);
100 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
102 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
103 const MCSubtargetInfo &STI);
104 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
105 unsigned SyntaxVariant,
106 const MCAsmInfo &MAI,
107 const MCInstrInfo &MII,
108 const MCRegisterInfo &MRI,
109 const MCSubtargetInfo &STI);
110 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
111 const MCSubtargetInfo &STI,
113 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
118 MCCodeEmitter *_Emitter,
121 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
122 formatted_raw_ostream &OS,
126 bool useDwarfDirectory,
127 MCInstPrinter *InstPrint,
133 /// Next - The next registered target in the linked list, maintained by the
137 /// TripleMatchQualityFn - The target function for rating the match quality
139 TripleMatchQualityFnTy TripleMatchQualityFn;
141 /// Name - The target name.
144 /// ShortDesc - A short description of the target.
145 const char *ShortDesc;
147 /// HasJIT - Whether this target supports the JIT.
150 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
152 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
154 /// MCCodeGenInfoCtorFn - Constructor function for this target's
155 /// MCCodeGenInfo, if registered.
156 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
158 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
160 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
162 /// MCInstrAnalysisCtorFn - Constructor function for this target's
163 /// MCInstrAnalysis, if registered.
164 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
166 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
168 MCRegInfoCtorFnTy MCRegInfoCtorFn;
170 /// MCSubtargetInfoCtorFn - Constructor function for this target's
171 /// MCSubtargetInfo, if registered.
172 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
174 /// TargetMachineCtorFn - Construction function for this target's
175 /// TargetMachine, if registered.
176 TargetMachineCtorTy TargetMachineCtorFn;
178 /// MCAsmBackendCtorFn - Construction function for this target's
179 /// MCAsmBackend, if registered.
180 MCAsmBackendCtorTy MCAsmBackendCtorFn;
182 /// MCAsmLexerCtorFn - Construction function for this target's
183 /// MCTargetAsmLexer, if registered.
184 MCAsmLexerCtorTy MCAsmLexerCtorFn;
186 /// MCAsmParserCtorFn - Construction function for this target's
187 /// MCTargetAsmParser, if registered.
188 MCAsmParserCtorTy MCAsmParserCtorFn;
190 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
192 AsmPrinterCtorTy AsmPrinterCtorFn;
194 /// MCDisassemblerCtorFn - Construction function for this target's
195 /// MCDisassembler, if registered.
196 MCDisassemblerCtorTy MCDisassemblerCtorFn;
198 /// MCInstPrinterCtorFn - Construction function for this target's
199 /// MCInstPrinter, if registered.
200 MCInstPrinterCtorTy MCInstPrinterCtorFn;
202 /// MCCodeEmitterCtorFn - Construction function for this target's
203 /// CodeEmitter, if registered.
204 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
206 /// MCObjectStreamerCtorFn - Construction function for this target's
207 /// MCObjectStreamer, if registered.
208 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
210 /// AsmStreamerCtorFn - Construction function for this target's
211 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
212 AsmStreamerCtorTy AsmStreamerCtorFn;
215 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
217 /// @name Target Information
220 // getNext - Return the next registered target.
221 const Target *getNext() const { return Next; }
223 /// getName - Get the target name.
224 const char *getName() const { return Name; }
226 /// getShortDescription - Get a short description of the target.
227 const char *getShortDescription() const { return ShortDesc; }
230 /// @name Feature Predicates
233 /// hasJIT - Check if this targets supports the just-in-time compilation.
234 bool hasJIT() const { return HasJIT; }
236 /// hasTargetMachine - Check if this target supports code generation.
237 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
239 /// hasMCAsmBackend - Check if this target supports .o generation.
240 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
242 /// hasMCAsmLexer - Check if this target supports .s lexing.
243 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
245 /// hasAsmParser - Check if this target supports .s parsing.
246 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
248 /// hasAsmPrinter - Check if this target supports .s printing.
249 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
251 /// hasMCDisassembler - Check if this target has a disassembler.
252 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
254 /// hasMCInstPrinter - Check if this target has an instruction printer.
255 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
257 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
258 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
260 /// hasMCObjectStreamer - Check if this target supports streaming to files.
261 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
263 /// hasAsmStreamer - Check if this target supports streaming to files.
264 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
267 /// @name Feature Constructors
270 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
273 /// \arg Triple - This argument is used to determine the target machine
274 /// feature set; it should always be provided. Generally this should be
275 /// either the target triple from the module, or the target triple of the
276 /// host if that does not exist.
277 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
278 if (!MCAsmInfoCtorFn)
280 return MCAsmInfoCtorFn(*this, Triple);
283 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
285 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
287 CodeGenOpt::Level OL) const {
288 if (!MCCodeGenInfoCtorFn)
290 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
293 /// createMCInstrInfo - Create a MCInstrInfo implementation.
295 MCInstrInfo *createMCInstrInfo() const {
296 if (!MCInstrInfoCtorFn)
298 return MCInstrInfoCtorFn();
301 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
303 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
304 if (!MCInstrAnalysisCtorFn)
306 return MCInstrAnalysisCtorFn(Info);
309 /// createMCRegInfo - Create a MCRegisterInfo implementation.
311 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
312 if (!MCRegInfoCtorFn)
314 return MCRegInfoCtorFn(Triple);
317 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
319 /// \arg Triple - This argument is used to determine the target machine
320 /// feature set; it should always be provided. Generally this should be
321 /// either the target triple from the module, or the target triple of the
322 /// host if that does not exist.
323 /// \arg CPU - This specifies the name of the target CPU.
324 /// \arg Features - This specifies the string representation of the
325 /// additional target features.
326 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
327 StringRef Features) const {
328 if (!MCSubtargetInfoCtorFn)
330 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
333 /// createTargetMachine - Create a target specific machine implementation
334 /// for the specified \arg Triple.
336 /// \arg Triple - This argument is used to determine the target machine
337 /// feature set; it should always be provided. Generally this should be
338 /// either the target triple from the module, or the target triple of the
339 /// host if that does not exist.
340 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
341 StringRef Features, const TargetOptions &Options,
342 Reloc::Model RM = Reloc::Default,
343 CodeModel::Model CM = CodeModel::Default,
344 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
345 if (!TargetMachineCtorFn)
347 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
351 /// createMCAsmBackend - Create a target specific assembly parser.
353 /// \arg Triple - The target triple string.
354 /// \arg Backend - The target independent assembler object.
355 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
356 if (!MCAsmBackendCtorFn)
358 return MCAsmBackendCtorFn(*this, Triple);
361 /// createMCAsmLexer - Create a target specific assembly lexer.
363 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
364 const MCAsmInfo &MAI) const {
365 if (!MCAsmLexerCtorFn)
367 return MCAsmLexerCtorFn(*this, MRI, MAI);
370 /// createMCAsmParser - Create a target specific assembly parser.
372 /// \arg Parser - The target independent parser implementation to use for
373 /// parsing and lexing.
374 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
375 MCAsmParser &Parser) const {
376 if (!MCAsmParserCtorFn)
378 return MCAsmParserCtorFn(STI, Parser);
381 /// createAsmPrinter - Create a target specific assembly printer pass. This
382 /// takes ownership of the MCStreamer object.
383 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
384 if (!AsmPrinterCtorFn)
386 return AsmPrinterCtorFn(TM, Streamer);
389 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
390 if (!MCDisassemblerCtorFn)
392 return MCDisassemblerCtorFn(*this, STI);
395 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
396 const MCAsmInfo &MAI,
397 const MCInstrInfo &MII,
398 const MCRegisterInfo &MRI,
399 const MCSubtargetInfo &STI) const {
400 if (!MCInstPrinterCtorFn)
402 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
406 /// createMCCodeEmitter - Create a target specific code emitter.
407 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
408 const MCSubtargetInfo &STI,
409 MCContext &Ctx) const {
410 if (!MCCodeEmitterCtorFn)
412 return MCCodeEmitterCtorFn(II, STI, Ctx);
415 /// createMCObjectStreamer - Create a target specific MCStreamer.
417 /// \arg TT - The target triple.
418 /// \arg Ctx - The target context.
419 /// \arg TAB - The target assembler backend object. Takes ownership.
420 /// \arg _OS - The stream object.
421 /// \arg _Emitter - The target independent assembler object.Takes ownership.
422 /// \arg RelaxAll - Relax all fixups?
423 /// \arg NoExecStack - Mark file as not needing a executable stack.
424 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
427 MCCodeEmitter *_Emitter,
429 bool NoExecStack) const {
430 if (!MCObjectStreamerCtorFn)
432 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
433 RelaxAll, NoExecStack);
436 /// createAsmStreamer - Create a target specific MCStreamer.
437 MCStreamer *createAsmStreamer(MCContext &Ctx,
438 formatted_raw_ostream &OS,
442 bool useDwarfDirectory,
443 MCInstPrinter *InstPrint,
446 bool ShowInst) const {
447 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
448 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
449 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
455 /// TargetRegistry - Generic interface to target specific features.
456 struct TargetRegistry {
458 const Target *Current;
459 explicit iterator(Target *T) : Current(T) {}
460 friend struct TargetRegistry;
462 iterator(const iterator &I) : Current(I.Current) {}
463 iterator() : Current(0) {}
465 bool operator==(const iterator &x) const {
466 return Current == x.Current;
468 bool operator!=(const iterator &x) const {
469 return !operator==(x);
472 // Iterator traversal: forward iteration only
473 iterator &operator++() { // Preincrement
474 assert(Current && "Cannot increment end iterator!");
475 Current = Current->getNext();
478 iterator operator++(int) { // Postincrement
479 iterator tmp = *this;
484 const Target &operator*() const {
485 assert(Current && "Cannot dereference end iterator!");
489 const Target *operator->() const {
494 /// printRegisteredTargetsForVersion - Print the registered targets
495 /// appropriately for inclusion in a tool's version output.
496 static void printRegisteredTargetsForVersion();
498 /// @name Registry Access
501 static iterator begin();
503 static iterator end() { return iterator(); }
505 /// lookupTarget - Lookup a target based on a target triple.
507 /// \param Triple - The triple to use for finding a target.
508 /// \param Error - On failure, an error string describing why no target was
510 static const Target *lookupTarget(const std::string &Triple,
513 /// getClosestTargetForJIT - Pick the best target that is compatible with
514 /// the current host. If no close target can be found, this returns null
515 /// and sets the Error string to a reason.
517 /// Maintained for compatibility through 2.6.
518 static const Target *getClosestTargetForJIT(std::string &Error);
521 /// @name Target Registration
524 /// RegisterTarget - Register the given target. Attempts to register a
525 /// target which has already been registered will be ignored.
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 Name - The target name. This should be a static string.
533 /// @param ShortDesc - A short target description. This should be a static
535 /// @param TQualityFn - The triple match quality computation function for
537 /// @param HasJIT - Whether the target supports JIT code
539 static void RegisterTarget(Target &T,
541 const char *ShortDesc,
542 Target::TripleMatchQualityFnTy TQualityFn,
543 bool HasJIT = false);
545 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
548 /// Clients are responsible for ensuring that registration doesn't occur
549 /// while another thread is attempting to access the registry. Typically
550 /// this is done by initializing all targets at program startup.
552 /// @param T - The target being registered.
553 /// @param Fn - A function to construct a MCAsmInfo for the target.
554 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
555 // Ignore duplicate registration.
556 if (!T.MCAsmInfoCtorFn)
557 T.MCAsmInfoCtorFn = Fn;
560 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
563 /// Clients are responsible for ensuring that registration doesn't occur
564 /// while another thread is attempting to access the registry. Typically
565 /// this is done by initializing all targets at program startup.
567 /// @param T - The target being registered.
568 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
569 static void RegisterMCCodeGenInfo(Target &T,
570 Target::MCCodeGenInfoCtorFnTy Fn) {
571 // Ignore duplicate registration.
572 if (!T.MCCodeGenInfoCtorFn)
573 T.MCCodeGenInfoCtorFn = Fn;
576 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
579 /// Clients are responsible for ensuring that registration doesn't occur
580 /// while another thread is attempting to access the registry. Typically
581 /// this is done by initializing all targets at program startup.
583 /// @param T - The target being registered.
584 /// @param Fn - A function to construct a MCInstrInfo for the target.
585 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
586 // Ignore duplicate registration.
587 if (!T.MCInstrInfoCtorFn)
588 T.MCInstrInfoCtorFn = Fn;
591 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
592 /// the given target.
593 static void RegisterMCInstrAnalysis(Target &T,
594 Target::MCInstrAnalysisCtorFnTy Fn) {
595 // Ignore duplicate registration.
596 if (!T.MCInstrAnalysisCtorFn)
597 T.MCInstrAnalysisCtorFn = Fn;
600 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
603 /// Clients are responsible for ensuring that registration doesn't occur
604 /// while another thread is attempting to access the registry. Typically
605 /// this is done by initializing all targets at program startup.
607 /// @param T - The target being registered.
608 /// @param Fn - A function to construct a MCRegisterInfo for the target.
609 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
610 // Ignore duplicate registration.
611 if (!T.MCRegInfoCtorFn)
612 T.MCRegInfoCtorFn = Fn;
615 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
616 /// the given target.
618 /// Clients are responsible for ensuring that registration doesn't occur
619 /// while another thread is attempting to access the registry. Typically
620 /// this is done by initializing all targets at program startup.
622 /// @param T - The target being registered.
623 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
624 static void RegisterMCSubtargetInfo(Target &T,
625 Target::MCSubtargetInfoCtorFnTy Fn) {
626 // Ignore duplicate registration.
627 if (!T.MCSubtargetInfoCtorFn)
628 T.MCSubtargetInfoCtorFn = Fn;
631 /// RegisterTargetMachine - Register a TargetMachine implementation for the
634 /// Clients are responsible for ensuring that registration doesn't occur
635 /// while another thread is attempting to access the registry. Typically
636 /// this is done by initializing all targets at program startup.
638 /// @param T - The target being registered.
639 /// @param Fn - A function to construct a TargetMachine for the target.
640 static void RegisterTargetMachine(Target &T,
641 Target::TargetMachineCtorTy Fn) {
642 // Ignore duplicate registration.
643 if (!T.TargetMachineCtorFn)
644 T.TargetMachineCtorFn = Fn;
647 /// RegisterMCAsmBackend - Register a MCAsmBackend 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 AsmBackend for the target.
656 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
657 if (!T.MCAsmBackendCtorFn)
658 T.MCAsmBackendCtorFn = Fn;
661 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
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 MCAsmLexer for the target.
670 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
671 if (!T.MCAsmLexerCtorFn)
672 T.MCAsmLexerCtorFn = Fn;
675 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
676 /// the given target.
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 MCTargetAsmParser for the target.
684 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
685 if (!T.MCAsmParserCtorFn)
686 T.MCAsmParserCtorFn = Fn;
689 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
698 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
699 // Ignore duplicate registration.
700 if (!T.AsmPrinterCtorFn)
701 T.AsmPrinterCtorFn = Fn;
704 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
705 /// the given target.
707 /// Clients are responsible for ensuring that registration doesn't occur
708 /// while another thread is attempting to access the registry. Typically
709 /// this is done by initializing all targets at program startup.
711 /// @param T - The target being registered.
712 /// @param Fn - A function to construct an MCDisassembler for the target.
713 static void RegisterMCDisassembler(Target &T,
714 Target::MCDisassemblerCtorTy Fn) {
715 if (!T.MCDisassemblerCtorFn)
716 T.MCDisassemblerCtorFn = Fn;
719 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
722 /// Clients are responsible for ensuring that registration doesn't occur
723 /// while another thread is attempting to access the registry. Typically
724 /// this is done by initializing all targets at program startup.
726 /// @param T - The target being registered.
727 /// @param Fn - A function to construct an MCInstPrinter for the target.
728 static void RegisterMCInstPrinter(Target &T,
729 Target::MCInstPrinterCtorTy Fn) {
730 if (!T.MCInstPrinterCtorFn)
731 T.MCInstPrinterCtorFn = Fn;
734 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
737 /// Clients are responsible for ensuring that registration doesn't occur
738 /// while another thread is attempting to access the registry. Typically
739 /// this is done by initializing all targets at program startup.
741 /// @param T - The target being registered.
742 /// @param Fn - A function to construct an MCCodeEmitter for the target.
743 static void RegisterMCCodeEmitter(Target &T,
744 Target::MCCodeEmitterCtorTy Fn) {
745 if (!T.MCCodeEmitterCtorFn)
746 T.MCCodeEmitterCtorFn = Fn;
749 /// RegisterMCObjectStreamer - Register a object code MCStreamer
750 /// implementation for the given target.
752 /// Clients are responsible for ensuring that registration doesn't occur
753 /// while another thread is attempting to access the registry. Typically
754 /// this is done by initializing all targets at program startup.
756 /// @param T - The target being registered.
757 /// @param Fn - A function to construct an MCStreamer for the target.
758 static void RegisterMCObjectStreamer(Target &T,
759 Target::MCObjectStreamerCtorTy Fn) {
760 if (!T.MCObjectStreamerCtorFn)
761 T.MCObjectStreamerCtorFn = Fn;
764 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
765 /// for the given target.
767 /// Clients are responsible for ensuring that registration doesn't occur
768 /// while another thread is attempting to access the registry. Typically
769 /// this is done by initializing all targets at program startup.
771 /// @param T - The target being registered.
772 /// @param Fn - A function to construct an MCStreamer for the target.
773 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
774 if (T.AsmStreamerCtorFn == createAsmStreamer)
775 T.AsmStreamerCtorFn = Fn;
782 //===--------------------------------------------------------------------===//
784 /// RegisterTarget - Helper template for registering a target, for use in the
785 /// target's initialization function. Usage:
788 /// Target TheFooTarget; // The global target instance.
790 /// extern "C" void LLVMInitializeFooTargetInfo() {
791 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
793 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
795 struct RegisterTarget {
796 RegisterTarget(Target &T, const char *Name, const char *Desc) {
797 TargetRegistry::RegisterTarget(T, Name, Desc,
798 &getTripleMatchQuality,
802 static unsigned getTripleMatchQuality(const std::string &TT) {
803 if (Triple(TT).getArch() == TargetArchType)
809 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
810 /// implementation. This invokes the static "Create" method on the class to
811 /// actually do the construction. Usage:
813 /// extern "C" void LLVMInitializeFooTarget() {
814 /// extern Target TheFooTarget;
815 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
817 template<class MCAsmInfoImpl>
818 struct RegisterMCAsmInfo {
819 RegisterMCAsmInfo(Target &T) {
820 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
823 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
824 return new MCAsmInfoImpl(T, TT);
829 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
830 /// implementation. This invokes the specified function to do the
831 /// construction. Usage:
833 /// extern "C" void LLVMInitializeFooTarget() {
834 /// extern Target TheFooTarget;
835 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
837 struct RegisterMCAsmInfoFn {
838 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
839 TargetRegistry::RegisterMCAsmInfo(T, Fn);
843 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
844 /// implementation. This invokes the static "Create" method on the class
845 /// to actually do the construction. Usage:
847 /// extern "C" void LLVMInitializeFooTarget() {
848 /// extern Target TheFooTarget;
849 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
851 template<class MCCodeGenInfoImpl>
852 struct RegisterMCCodeGenInfo {
853 RegisterMCCodeGenInfo(Target &T) {
854 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
857 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
858 CodeModel::Model CM, CodeGenOpt::Level OL) {
859 return new MCCodeGenInfoImpl();
863 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
864 /// info implementation. This invokes the specified function to do the
865 /// construction. Usage:
867 /// extern "C" void LLVMInitializeFooTarget() {
868 /// extern Target TheFooTarget;
869 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
871 struct RegisterMCCodeGenInfoFn {
872 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
873 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
877 /// RegisterMCInstrInfo - Helper template for registering a target instruction
878 /// info implementation. This invokes the static "Create" method on the class
879 /// to actually do the construction. Usage:
881 /// extern "C" void LLVMInitializeFooTarget() {
882 /// extern Target TheFooTarget;
883 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
885 template<class MCInstrInfoImpl>
886 struct RegisterMCInstrInfo {
887 RegisterMCInstrInfo(Target &T) {
888 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
891 static MCInstrInfo *Allocator() {
892 return new MCInstrInfoImpl();
896 /// RegisterMCInstrInfoFn - Helper template for registering a target
897 /// instruction info implementation. This invokes the specified function to
898 /// do the construction. Usage:
900 /// extern "C" void LLVMInitializeFooTarget() {
901 /// extern Target TheFooTarget;
902 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
904 struct RegisterMCInstrInfoFn {
905 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
906 TargetRegistry::RegisterMCInstrInfo(T, Fn);
910 /// RegisterMCInstrAnalysis - Helper template for registering a target
911 /// instruction analyzer implementation. This invokes the static "Create"
912 /// method on the class to actually do the construction. Usage:
914 /// extern "C" void LLVMInitializeFooTarget() {
915 /// extern Target TheFooTarget;
916 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
918 template<class MCInstrAnalysisImpl>
919 struct RegisterMCInstrAnalysis {
920 RegisterMCInstrAnalysis(Target &T) {
921 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
924 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
925 return new MCInstrAnalysisImpl(Info);
929 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
930 /// instruction analyzer implementation. This invokes the specified function
931 /// to do the construction. Usage:
933 /// extern "C" void LLVMInitializeFooTarget() {
934 /// extern Target TheFooTarget;
935 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
937 struct RegisterMCInstrAnalysisFn {
938 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
939 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
943 /// RegisterMCRegInfo - Helper template for registering a target register info
944 /// implementation. This invokes the static "Create" method on the class to
945 /// actually do the construction. Usage:
947 /// extern "C" void LLVMInitializeFooTarget() {
948 /// extern Target TheFooTarget;
949 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
951 template<class MCRegisterInfoImpl>
952 struct RegisterMCRegInfo {
953 RegisterMCRegInfo(Target &T) {
954 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
957 static MCRegisterInfo *Allocator(StringRef TT) {
958 return new MCRegisterInfoImpl();
962 /// RegisterMCRegInfoFn - Helper template for registering a target register
963 /// info implementation. This invokes the specified function to do the
964 /// construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
970 struct RegisterMCRegInfoFn {
971 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
972 TargetRegistry::RegisterMCRegInfo(T, Fn);
976 /// RegisterMCSubtargetInfo - Helper template for registering a target
977 /// subtarget info implementation. This invokes the static "Create" method
978 /// on the class to actually do the construction. Usage:
980 /// extern "C" void LLVMInitializeFooTarget() {
981 /// extern Target TheFooTarget;
982 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
984 template<class MCSubtargetInfoImpl>
985 struct RegisterMCSubtargetInfo {
986 RegisterMCSubtargetInfo(Target &T) {
987 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
990 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
992 return new MCSubtargetInfoImpl();
996 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
997 /// subtarget info implementation. This invokes the specified function to
998 /// do the construction. Usage:
1000 /// extern "C" void LLVMInitializeFooTarget() {
1001 /// extern Target TheFooTarget;
1002 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1004 struct RegisterMCSubtargetInfoFn {
1005 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1006 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1010 /// RegisterTargetMachine - Helper template for registering a target machine
1011 /// implementation, for use in the target machine initialization
1012 /// function. Usage:
1014 /// extern "C" void LLVMInitializeFooTarget() {
1015 /// extern Target TheFooTarget;
1016 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1018 template<class TargetMachineImpl>
1019 struct RegisterTargetMachine {
1020 RegisterTargetMachine(Target &T) {
1021 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1025 static TargetMachine *Allocator(const Target &T, StringRef TT,
1026 StringRef CPU, StringRef FS,
1027 const TargetOptions &Options,
1029 CodeModel::Model CM,
1030 CodeGenOpt::Level OL) {
1031 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1035 /// RegisterMCAsmBackend - Helper template for registering a target specific
1036 /// assembler backend. Usage:
1038 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1039 /// extern Target TheFooTarget;
1040 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1042 template<class MCAsmBackendImpl>
1043 struct RegisterMCAsmBackend {
1044 RegisterMCAsmBackend(Target &T) {
1045 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1049 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1050 return new MCAsmBackendImpl(T, Triple);
1054 /// RegisterMCAsmLexer - Helper template for registering a target specific
1055 /// assembly lexer, for use in the target machine initialization
1056 /// function. Usage:
1058 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1059 /// extern Target TheFooTarget;
1060 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1062 template<class MCAsmLexerImpl>
1063 struct RegisterMCAsmLexer {
1064 RegisterMCAsmLexer(Target &T) {
1065 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1069 static MCTargetAsmLexer *Allocator(const Target &T,
1070 const MCRegisterInfo &MRI,
1071 const MCAsmInfo &MAI) {
1072 return new MCAsmLexerImpl(T, MRI, MAI);
1076 /// RegisterMCAsmParser - Helper template for registering a target specific
1077 /// assembly parser, for use in the target machine initialization
1078 /// function. Usage:
1080 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1081 /// extern Target TheFooTarget;
1082 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1084 template<class MCAsmParserImpl>
1085 struct RegisterMCAsmParser {
1086 RegisterMCAsmParser(Target &T) {
1087 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1091 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1092 return new MCAsmParserImpl(STI, P);
1096 /// RegisterAsmPrinter - Helper template for registering a target specific
1097 /// assembly printer, for use in the target machine initialization
1098 /// function. Usage:
1100 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1101 /// extern Target TheFooTarget;
1102 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1104 template<class AsmPrinterImpl>
1105 struct RegisterAsmPrinter {
1106 RegisterAsmPrinter(Target &T) {
1107 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1111 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1112 return new AsmPrinterImpl(TM, Streamer);
1116 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1117 /// machine code emitter, for use in the target initialization
1118 /// function. Usage:
1120 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1121 /// extern Target TheFooTarget;
1122 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1124 template<class MCCodeEmitterImpl>
1125 struct RegisterMCCodeEmitter {
1126 RegisterMCCodeEmitter(Target &T) {
1127 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1131 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1132 const MCSubtargetInfo &STI,
1134 return new MCCodeEmitterImpl();