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 MCSubtargetInfo &STI);
108 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
109 const MCSubtargetInfo &STI,
111 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
116 MCCodeEmitter *_Emitter,
119 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
120 formatted_raw_ostream &OS,
124 bool useDwarfDirectory,
125 MCInstPrinter *InstPrint,
131 /// Next - The next registered target in the linked list, maintained by the
135 /// TripleMatchQualityFn - The target function for rating the match quality
137 TripleMatchQualityFnTy TripleMatchQualityFn;
139 /// Name - The target name.
142 /// ShortDesc - A short description of the target.
143 const char *ShortDesc;
145 /// HasJIT - Whether this target supports the JIT.
148 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
150 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
152 /// MCCodeGenInfoCtorFn - Constructor function for this target's
153 /// MCCodeGenInfo, if registered.
154 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
156 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
158 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
160 /// MCInstrAnalysisCtorFn - Constructor function for this target's
161 /// MCInstrAnalysis, if registered.
162 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
164 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
166 MCRegInfoCtorFnTy MCRegInfoCtorFn;
168 /// MCSubtargetInfoCtorFn - Constructor function for this target's
169 /// MCSubtargetInfo, if registered.
170 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
172 /// TargetMachineCtorFn - Construction function for this target's
173 /// TargetMachine, if registered.
174 TargetMachineCtorTy TargetMachineCtorFn;
176 /// MCAsmBackendCtorFn - Construction function for this target's
177 /// MCAsmBackend, if registered.
178 MCAsmBackendCtorTy MCAsmBackendCtorFn;
180 /// MCAsmLexerCtorFn - Construction function for this target's
181 /// MCTargetAsmLexer, if registered.
182 MCAsmLexerCtorTy MCAsmLexerCtorFn;
184 /// MCAsmParserCtorFn - Construction function for this target's
185 /// MCTargetAsmParser, if registered.
186 MCAsmParserCtorTy MCAsmParserCtorFn;
188 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
190 AsmPrinterCtorTy AsmPrinterCtorFn;
192 /// MCDisassemblerCtorFn - Construction function for this target's
193 /// MCDisassembler, if registered.
194 MCDisassemblerCtorTy MCDisassemblerCtorFn;
196 /// MCInstPrinterCtorFn - Construction function for this target's
197 /// MCInstPrinter, if registered.
198 MCInstPrinterCtorTy MCInstPrinterCtorFn;
200 /// MCCodeEmitterCtorFn - Construction function for this target's
201 /// CodeEmitter, if registered.
202 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
204 /// MCObjectStreamerCtorFn - Construction function for this target's
205 /// MCObjectStreamer, if registered.
206 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
208 /// AsmStreamerCtorFn - Construction function for this target's
209 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
210 AsmStreamerCtorTy AsmStreamerCtorFn;
213 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
215 /// @name Target Information
218 // getNext - Return the next registered target.
219 const Target *getNext() const { return Next; }
221 /// getName - Get the target name.
222 const char *getName() const { return Name; }
224 /// getShortDescription - Get a short description of the target.
225 const char *getShortDescription() const { return ShortDesc; }
228 /// @name Feature Predicates
231 /// hasJIT - Check if this targets supports the just-in-time compilation.
232 bool hasJIT() const { return HasJIT; }
234 /// hasTargetMachine - Check if this target supports code generation.
235 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
237 /// hasMCAsmBackend - Check if this target supports .o generation.
238 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
240 /// hasMCAsmLexer - Check if this target supports .s lexing.
241 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
243 /// hasAsmParser - Check if this target supports .s parsing.
244 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
246 /// hasAsmPrinter - Check if this target supports .s printing.
247 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
249 /// hasMCDisassembler - Check if this target has a disassembler.
250 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
252 /// hasMCInstPrinter - Check if this target has an instruction printer.
253 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
255 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
256 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
258 /// hasMCObjectStreamer - Check if this target supports streaming to files.
259 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
261 /// hasAsmStreamer - Check if this target supports streaming to files.
262 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
265 /// @name Feature Constructors
268 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
271 /// \arg Triple - This argument is used to determine the target machine
272 /// feature set; it should always be provided. Generally this should be
273 /// either the target triple from the module, or the target triple of the
274 /// host if that does not exist.
275 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
276 if (!MCAsmInfoCtorFn)
278 return MCAsmInfoCtorFn(*this, Triple);
281 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
283 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
285 CodeGenOpt::Level OL) const {
286 if (!MCCodeGenInfoCtorFn)
288 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
291 /// createMCInstrInfo - Create a MCInstrInfo implementation.
293 MCInstrInfo *createMCInstrInfo() const {
294 if (!MCInstrInfoCtorFn)
296 return MCInstrInfoCtorFn();
299 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
301 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
302 if (!MCInstrAnalysisCtorFn)
304 return MCInstrAnalysisCtorFn(Info);
307 /// createMCRegInfo - Create a MCRegisterInfo implementation.
309 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
310 if (!MCRegInfoCtorFn)
312 return MCRegInfoCtorFn(Triple);
315 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
317 /// \arg Triple - This argument is used to determine the target machine
318 /// feature set; it should always be provided. Generally this should be
319 /// either the target triple from the module, or the target triple of the
320 /// host if that does not exist.
321 /// \arg CPU - This specifies the name of the target CPU.
322 /// \arg Features - This specifies the string representation of the
323 /// additional target features.
324 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
325 StringRef Features) const {
326 if (!MCSubtargetInfoCtorFn)
328 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
331 /// createTargetMachine - Create a target specific machine implementation
332 /// for the specified \arg Triple.
334 /// \arg Triple - This argument is used to determine the target machine
335 /// feature set; it should always be provided. Generally this should be
336 /// either the target triple from the module, or the target triple of the
337 /// host if that does not exist.
338 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
339 StringRef Features, const TargetOptions &Options,
340 Reloc::Model RM = Reloc::Default,
341 CodeModel::Model CM = CodeModel::Default,
342 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
343 if (!TargetMachineCtorFn)
345 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
349 /// createMCAsmBackend - Create a target specific assembly parser.
351 /// \arg Triple - The target triple string.
352 /// \arg Backend - The target independent assembler object.
353 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
354 if (!MCAsmBackendCtorFn)
356 return MCAsmBackendCtorFn(*this, Triple);
359 /// createMCAsmLexer - Create a target specific assembly lexer.
361 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
362 const MCAsmInfo &MAI) const {
363 if (!MCAsmLexerCtorFn)
365 return MCAsmLexerCtorFn(*this, MRI, MAI);
368 /// createMCAsmParser - Create a target specific assembly parser.
370 /// \arg Parser - The target independent parser implementation to use for
371 /// parsing and lexing.
372 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
373 MCAsmParser &Parser) const {
374 if (!MCAsmParserCtorFn)
376 return MCAsmParserCtorFn(STI, Parser);
379 /// createAsmPrinter - Create a target specific assembly printer pass. This
380 /// takes ownership of the MCStreamer object.
381 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
382 if (!AsmPrinterCtorFn)
384 return AsmPrinterCtorFn(TM, Streamer);
387 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
388 if (!MCDisassemblerCtorFn)
390 return MCDisassemblerCtorFn(*this, STI);
393 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
394 const MCAsmInfo &MAI,
395 const MCSubtargetInfo &STI) const {
396 if (!MCInstPrinterCtorFn)
398 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, STI);
402 /// createMCCodeEmitter - Create a target specific code emitter.
403 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
404 const MCSubtargetInfo &STI,
405 MCContext &Ctx) const {
406 if (!MCCodeEmitterCtorFn)
408 return MCCodeEmitterCtorFn(II, STI, Ctx);
411 /// createMCObjectStreamer - Create a target specific MCStreamer.
413 /// \arg TT - The target triple.
414 /// \arg Ctx - The target context.
415 /// \arg TAB - The target assembler backend object. Takes ownership.
416 /// \arg _OS - The stream object.
417 /// \arg _Emitter - The target independent assembler object.Takes ownership.
418 /// \arg RelaxAll - Relax all fixups?
419 /// \arg NoExecStack - Mark file as not needing a executable stack.
420 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
423 MCCodeEmitter *_Emitter,
425 bool NoExecStack) const {
426 if (!MCObjectStreamerCtorFn)
428 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
429 RelaxAll, NoExecStack);
432 /// createAsmStreamer - Create a target specific MCStreamer.
433 MCStreamer *createAsmStreamer(MCContext &Ctx,
434 formatted_raw_ostream &OS,
438 bool useDwarfDirectory,
439 MCInstPrinter *InstPrint,
442 bool ShowInst) const {
443 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
444 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
445 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
451 /// TargetRegistry - Generic interface to target specific features.
452 struct TargetRegistry {
454 const Target *Current;
455 explicit iterator(Target *T) : Current(T) {}
456 friend struct TargetRegistry;
458 iterator(const iterator &I) : Current(I.Current) {}
459 iterator() : Current(0) {}
461 bool operator==(const iterator &x) const {
462 return Current == x.Current;
464 bool operator!=(const iterator &x) const {
465 return !operator==(x);
468 // Iterator traversal: forward iteration only
469 iterator &operator++() { // Preincrement
470 assert(Current && "Cannot increment end iterator!");
471 Current = Current->getNext();
474 iterator operator++(int) { // Postincrement
475 iterator tmp = *this;
480 const Target &operator*() const {
481 assert(Current && "Cannot dereference end iterator!");
485 const Target *operator->() const {
490 /// printRegisteredTargetsForVersion - Print the registered targets
491 /// appropriately for inclusion in a tool's version output.
492 static void printRegisteredTargetsForVersion();
494 /// @name Registry Access
497 static iterator begin();
499 static iterator end() { return iterator(); }
501 /// lookupTarget - Lookup a target based on a target triple.
503 /// \param Triple - The triple to use for finding a target.
504 /// \param Error - On failure, an error string describing why no target was
506 static const Target *lookupTarget(const std::string &Triple,
509 /// getClosestTargetForJIT - Pick the best target that is compatible with
510 /// the current host. If no close target can be found, this returns null
511 /// and sets the Error string to a reason.
513 /// Maintained for compatibility through 2.6.
514 static const Target *getClosestTargetForJIT(std::string &Error);
517 /// @name Target Registration
520 /// RegisterTarget - Register the given target. Attempts to register a
521 /// target which has already been registered will be ignored.
523 /// Clients are responsible for ensuring that registration doesn't occur
524 /// while another thread is attempting to access the registry. Typically
525 /// this is done by initializing all targets at program startup.
527 /// @param T - The target being registered.
528 /// @param Name - The target name. This should be a static string.
529 /// @param ShortDesc - A short target description. This should be a static
531 /// @param TQualityFn - The triple match quality computation function for
533 /// @param HasJIT - Whether the target supports JIT code
535 static void RegisterTarget(Target &T,
537 const char *ShortDesc,
538 Target::TripleMatchQualityFnTy TQualityFn,
539 bool HasJIT = false);
541 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
544 /// Clients are responsible for ensuring that registration doesn't occur
545 /// while another thread is attempting to access the registry. Typically
546 /// this is done by initializing all targets at program startup.
548 /// @param T - The target being registered.
549 /// @param Fn - A function to construct a MCAsmInfo for the target.
550 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
551 // Ignore duplicate registration.
552 if (!T.MCAsmInfoCtorFn)
553 T.MCAsmInfoCtorFn = Fn;
556 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
559 /// Clients are responsible for ensuring that registration doesn't occur
560 /// while another thread is attempting to access the registry. Typically
561 /// this is done by initializing all targets at program startup.
563 /// @param T - The target being registered.
564 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
565 static void RegisterMCCodeGenInfo(Target &T,
566 Target::MCCodeGenInfoCtorFnTy Fn) {
567 // Ignore duplicate registration.
568 if (!T.MCCodeGenInfoCtorFn)
569 T.MCCodeGenInfoCtorFn = Fn;
572 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
575 /// Clients are responsible for ensuring that registration doesn't occur
576 /// while another thread is attempting to access the registry. Typically
577 /// this is done by initializing all targets at program startup.
579 /// @param T - The target being registered.
580 /// @param Fn - A function to construct a MCInstrInfo for the target.
581 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
582 // Ignore duplicate registration.
583 if (!T.MCInstrInfoCtorFn)
584 T.MCInstrInfoCtorFn = Fn;
587 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
588 /// the given target.
589 static void RegisterMCInstrAnalysis(Target &T,
590 Target::MCInstrAnalysisCtorFnTy Fn) {
591 // Ignore duplicate registration.
592 if (!T.MCInstrAnalysisCtorFn)
593 T.MCInstrAnalysisCtorFn = Fn;
596 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
599 /// Clients are responsible for ensuring that registration doesn't occur
600 /// while another thread is attempting to access the registry. Typically
601 /// this is done by initializing all targets at program startup.
603 /// @param T - The target being registered.
604 /// @param Fn - A function to construct a MCRegisterInfo for the target.
605 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
606 // Ignore duplicate registration.
607 if (!T.MCRegInfoCtorFn)
608 T.MCRegInfoCtorFn = Fn;
611 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
612 /// the given target.
614 /// Clients are responsible for ensuring that registration doesn't occur
615 /// while another thread is attempting to access the registry. Typically
616 /// this is done by initializing all targets at program startup.
618 /// @param T - The target being registered.
619 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
620 static void RegisterMCSubtargetInfo(Target &T,
621 Target::MCSubtargetInfoCtorFnTy Fn) {
622 // Ignore duplicate registration.
623 if (!T.MCSubtargetInfoCtorFn)
624 T.MCSubtargetInfoCtorFn = Fn;
627 /// RegisterTargetMachine - Register a TargetMachine implementation for the
630 /// Clients are responsible for ensuring that registration doesn't occur
631 /// while another thread is attempting to access the registry. Typically
632 /// this is done by initializing all targets at program startup.
634 /// @param T - The target being registered.
635 /// @param Fn - A function to construct a TargetMachine for the target.
636 static void RegisterTargetMachine(Target &T,
637 Target::TargetMachineCtorTy Fn) {
638 // Ignore duplicate registration.
639 if (!T.TargetMachineCtorFn)
640 T.TargetMachineCtorFn = Fn;
643 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
646 /// Clients are responsible for ensuring that registration doesn't occur
647 /// while another thread is attempting to access the registry. Typically
648 /// this is done by initializing all targets at program startup.
650 /// @param T - The target being registered.
651 /// @param Fn - A function to construct an AsmBackend for the target.
652 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
653 if (!T.MCAsmBackendCtorFn)
654 T.MCAsmBackendCtorFn = Fn;
657 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
660 /// Clients are responsible for ensuring that registration doesn't occur
661 /// while another thread is attempting to access the registry. Typically
662 /// this is done by initializing all targets at program startup.
664 /// @param T - The target being registered.
665 /// @param Fn - A function to construct an MCAsmLexer for the target.
666 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
667 if (!T.MCAsmLexerCtorFn)
668 T.MCAsmLexerCtorFn = Fn;
671 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
672 /// the given target.
674 /// Clients are responsible for ensuring that registration doesn't occur
675 /// while another thread is attempting to access the registry. Typically
676 /// this is done by initializing all targets at program startup.
678 /// @param T - The target being registered.
679 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
680 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
681 if (!T.MCAsmParserCtorFn)
682 T.MCAsmParserCtorFn = Fn;
685 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
688 /// Clients are responsible for ensuring that registration doesn't occur
689 /// while another thread is attempting to access the registry. Typically
690 /// this is done by initializing all targets at program startup.
692 /// @param T - The target being registered.
693 /// @param Fn - A function to construct an AsmPrinter for the target.
694 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
695 // Ignore duplicate registration.
696 if (!T.AsmPrinterCtorFn)
697 T.AsmPrinterCtorFn = Fn;
700 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
701 /// the given target.
703 /// Clients are responsible for ensuring that registration doesn't occur
704 /// while another thread is attempting to access the registry. Typically
705 /// this is done by initializing all targets at program startup.
707 /// @param T - The target being registered.
708 /// @param Fn - A function to construct an MCDisassembler for the target.
709 static void RegisterMCDisassembler(Target &T,
710 Target::MCDisassemblerCtorTy Fn) {
711 if (!T.MCDisassemblerCtorFn)
712 T.MCDisassemblerCtorFn = Fn;
715 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
718 /// Clients are responsible for ensuring that registration doesn't occur
719 /// while another thread is attempting to access the registry. Typically
720 /// this is done by initializing all targets at program startup.
722 /// @param T - The target being registered.
723 /// @param Fn - A function to construct an MCInstPrinter for the target.
724 static void RegisterMCInstPrinter(Target &T,
725 Target::MCInstPrinterCtorTy Fn) {
726 if (!T.MCInstPrinterCtorFn)
727 T.MCInstPrinterCtorFn = Fn;
730 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
733 /// Clients are responsible for ensuring that registration doesn't occur
734 /// while another thread is attempting to access the registry. Typically
735 /// this is done by initializing all targets at program startup.
737 /// @param T - The target being registered.
738 /// @param Fn - A function to construct an MCCodeEmitter for the target.
739 static void RegisterMCCodeEmitter(Target &T,
740 Target::MCCodeEmitterCtorTy Fn) {
741 if (!T.MCCodeEmitterCtorFn)
742 T.MCCodeEmitterCtorFn = Fn;
745 /// RegisterMCObjectStreamer - Register a object code MCStreamer
746 /// implementation for the given target.
748 /// Clients are responsible for ensuring that registration doesn't occur
749 /// while another thread is attempting to access the registry. Typically
750 /// this is done by initializing all targets at program startup.
752 /// @param T - The target being registered.
753 /// @param Fn - A function to construct an MCStreamer for the target.
754 static void RegisterMCObjectStreamer(Target &T,
755 Target::MCObjectStreamerCtorTy Fn) {
756 if (!T.MCObjectStreamerCtorFn)
757 T.MCObjectStreamerCtorFn = Fn;
760 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
761 /// for the given target.
763 /// Clients are responsible for ensuring that registration doesn't occur
764 /// while another thread is attempting to access the registry. Typically
765 /// this is done by initializing all targets at program startup.
767 /// @param T - The target being registered.
768 /// @param Fn - A function to construct an MCStreamer for the target.
769 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
770 if (T.AsmStreamerCtorFn == createAsmStreamer)
771 T.AsmStreamerCtorFn = Fn;
778 //===--------------------------------------------------------------------===//
780 /// RegisterTarget - Helper template for registering a target, for use in the
781 /// target's initialization function. Usage:
784 /// Target TheFooTarget; // The global target instance.
786 /// extern "C" void LLVMInitializeFooTargetInfo() {
787 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
789 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
791 struct RegisterTarget {
792 RegisterTarget(Target &T, const char *Name, const char *Desc) {
793 TargetRegistry::RegisterTarget(T, Name, Desc,
794 &getTripleMatchQuality,
798 static unsigned getTripleMatchQuality(const std::string &TT) {
799 if (Triple(TT).getArch() == TargetArchType)
805 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
806 /// implementation. This invokes the static "Create" method on the class to
807 /// actually do the construction. Usage:
809 /// extern "C" void LLVMInitializeFooTarget() {
810 /// extern Target TheFooTarget;
811 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
813 template<class MCAsmInfoImpl>
814 struct RegisterMCAsmInfo {
815 RegisterMCAsmInfo(Target &T) {
816 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
819 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
820 return new MCAsmInfoImpl(T, TT);
825 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
826 /// implementation. This invokes the specified function to do the
827 /// construction. Usage:
829 /// extern "C" void LLVMInitializeFooTarget() {
830 /// extern Target TheFooTarget;
831 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
833 struct RegisterMCAsmInfoFn {
834 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
835 TargetRegistry::RegisterMCAsmInfo(T, Fn);
839 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
840 /// implementation. This invokes the static "Create" method on the class
841 /// to actually do the construction. Usage:
843 /// extern "C" void LLVMInitializeFooTarget() {
844 /// extern Target TheFooTarget;
845 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
847 template<class MCCodeGenInfoImpl>
848 struct RegisterMCCodeGenInfo {
849 RegisterMCCodeGenInfo(Target &T) {
850 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
853 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
854 CodeModel::Model CM, CodeGenOpt::Level OL) {
855 return new MCCodeGenInfoImpl();
859 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
860 /// info implementation. This invokes the specified function to do the
861 /// construction. Usage:
863 /// extern "C" void LLVMInitializeFooTarget() {
864 /// extern Target TheFooTarget;
865 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
867 struct RegisterMCCodeGenInfoFn {
868 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
869 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
873 /// RegisterMCInstrInfo - Helper template for registering a target instruction
874 /// info implementation. This invokes the static "Create" method on the class
875 /// to actually do the construction. Usage:
877 /// extern "C" void LLVMInitializeFooTarget() {
878 /// extern Target TheFooTarget;
879 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
881 template<class MCInstrInfoImpl>
882 struct RegisterMCInstrInfo {
883 RegisterMCInstrInfo(Target &T) {
884 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
887 static MCInstrInfo *Allocator() {
888 return new MCInstrInfoImpl();
892 /// RegisterMCInstrInfoFn - Helper template for registering a target
893 /// instruction info implementation. This invokes the specified function to
894 /// do the construction. Usage:
896 /// extern "C" void LLVMInitializeFooTarget() {
897 /// extern Target TheFooTarget;
898 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
900 struct RegisterMCInstrInfoFn {
901 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
902 TargetRegistry::RegisterMCInstrInfo(T, Fn);
906 /// RegisterMCInstrAnalysis - Helper template for registering a target
907 /// instruction analyzer implementation. This invokes the static "Create"
908 /// method on the class to actually do the construction. Usage:
910 /// extern "C" void LLVMInitializeFooTarget() {
911 /// extern Target TheFooTarget;
912 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
914 template<class MCInstrAnalysisImpl>
915 struct RegisterMCInstrAnalysis {
916 RegisterMCInstrAnalysis(Target &T) {
917 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
920 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
921 return new MCInstrAnalysisImpl(Info);
925 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
926 /// instruction analyzer implementation. This invokes the specified function
927 /// to do the construction. Usage:
929 /// extern "C" void LLVMInitializeFooTarget() {
930 /// extern Target TheFooTarget;
931 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
933 struct RegisterMCInstrAnalysisFn {
934 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
935 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
939 /// RegisterMCRegInfo - Helper template for registering a target register info
940 /// implementation. This invokes the static "Create" method on the class to
941 /// actually do the construction. Usage:
943 /// extern "C" void LLVMInitializeFooTarget() {
944 /// extern Target TheFooTarget;
945 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
947 template<class MCRegisterInfoImpl>
948 struct RegisterMCRegInfo {
949 RegisterMCRegInfo(Target &T) {
950 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
953 static MCRegisterInfo *Allocator(StringRef TT) {
954 return new MCRegisterInfoImpl();
958 /// RegisterMCRegInfoFn - Helper template for registering a target register
959 /// info implementation. This invokes the specified function to do the
960 /// construction. Usage:
962 /// extern "C" void LLVMInitializeFooTarget() {
963 /// extern Target TheFooTarget;
964 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
966 struct RegisterMCRegInfoFn {
967 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
968 TargetRegistry::RegisterMCRegInfo(T, Fn);
972 /// RegisterMCSubtargetInfo - Helper template for registering a target
973 /// subtarget info implementation. This invokes the static "Create" method
974 /// on the class to actually do the construction. Usage:
976 /// extern "C" void LLVMInitializeFooTarget() {
977 /// extern Target TheFooTarget;
978 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
980 template<class MCSubtargetInfoImpl>
981 struct RegisterMCSubtargetInfo {
982 RegisterMCSubtargetInfo(Target &T) {
983 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
986 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
988 return new MCSubtargetInfoImpl();
992 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
993 /// subtarget info implementation. This invokes the specified function to
994 /// do the construction. Usage:
996 /// extern "C" void LLVMInitializeFooTarget() {
997 /// extern Target TheFooTarget;
998 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1000 struct RegisterMCSubtargetInfoFn {
1001 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1002 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1006 /// RegisterTargetMachine - Helper template for registering a target machine
1007 /// implementation, for use in the target machine initialization
1008 /// function. Usage:
1010 /// extern "C" void LLVMInitializeFooTarget() {
1011 /// extern Target TheFooTarget;
1012 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1014 template<class TargetMachineImpl>
1015 struct RegisterTargetMachine {
1016 RegisterTargetMachine(Target &T) {
1017 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1021 static TargetMachine *Allocator(const Target &T, StringRef TT,
1022 StringRef CPU, StringRef FS,
1023 const TargetOptions &Options,
1025 CodeModel::Model CM,
1026 CodeGenOpt::Level OL) {
1027 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1031 /// RegisterMCAsmBackend - Helper template for registering a target specific
1032 /// assembler backend. Usage:
1034 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1035 /// extern Target TheFooTarget;
1036 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1038 template<class MCAsmBackendImpl>
1039 struct RegisterMCAsmBackend {
1040 RegisterMCAsmBackend(Target &T) {
1041 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1045 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1046 return new MCAsmBackendImpl(T, Triple);
1050 /// RegisterMCAsmLexer - Helper template for registering a target specific
1051 /// assembly lexer, for use in the target machine initialization
1052 /// function. Usage:
1054 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1055 /// extern Target TheFooTarget;
1056 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1058 template<class MCAsmLexerImpl>
1059 struct RegisterMCAsmLexer {
1060 RegisterMCAsmLexer(Target &T) {
1061 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1065 static MCTargetAsmLexer *Allocator(const Target &T,
1066 const MCRegisterInfo &MRI,
1067 const MCAsmInfo &MAI) {
1068 return new MCAsmLexerImpl(T, MRI, MAI);
1072 /// RegisterMCAsmParser - Helper template for registering a target specific
1073 /// assembly parser, for use in the target machine initialization
1074 /// function. Usage:
1076 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1077 /// extern Target TheFooTarget;
1078 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1080 template<class MCAsmParserImpl>
1081 struct RegisterMCAsmParser {
1082 RegisterMCAsmParser(Target &T) {
1083 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1087 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1088 return new MCAsmParserImpl(STI, P);
1092 /// RegisterAsmPrinter - Helper template for registering a target specific
1093 /// assembly printer, for use in the target machine initialization
1094 /// function. Usage:
1096 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1097 /// extern Target TheFooTarget;
1098 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1100 template<class AsmPrinterImpl>
1101 struct RegisterAsmPrinter {
1102 RegisterAsmPrinter(Target &T) {
1103 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1107 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1108 return new AsmPrinterImpl(TM, Streamer);
1112 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1113 /// machine code emitter, for use in the target initialization
1114 /// function. Usage:
1116 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1117 /// extern Target TheFooTarget;
1118 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1120 template<class MCCodeEmitterImpl>
1121 struct RegisterMCCodeEmitter {
1122 RegisterMCCodeEmitter(Target &T) {
1123 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1127 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1128 const MCSubtargetInfo &STI,
1130 return new MCCodeEmitterImpl();