1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the TargetRegistry interface, which tools can use to access
11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
12 // which have been registered.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm/Support/CodeGen.h"
23 #include "llvm/ADT/Triple.h"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCTargetAsmLexer;
45 class MCTargetAsmParser;
48 class formatted_raw_ostream;
50 MCStreamer *createAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
52 bool useLoc, bool useCFI,
53 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 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
79 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
80 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
81 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
84 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
90 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
91 MCStreamer &Streamer);
92 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T, StringRef TT);
93 typedef MCTargetAsmLexer *(*MCAsmLexerCtorTy)(const Target &T,
94 const MCRegisterInfo &MRI,
95 const MCAsmInfo &MAI);
96 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
98 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
99 const MCSubtargetInfo &STI);
100 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
101 unsigned SyntaxVariant,
102 const MCAsmInfo &MAI,
103 const MCSubtargetInfo &STI);
104 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
105 const MCSubtargetInfo &STI,
107 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
112 MCCodeEmitter *_Emitter,
115 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
116 formatted_raw_ostream &OS,
120 bool useDwarfDirectory,
121 MCInstPrinter *InstPrint,
127 /// Next - The next registered target in the linked list, maintained by the
131 /// TripleMatchQualityFn - The target function for rating the match quality
133 TripleMatchQualityFnTy TripleMatchQualityFn;
135 /// Name - The target name.
138 /// ShortDesc - A short description of the target.
139 const char *ShortDesc;
141 /// HasJIT - Whether this target supports the JIT.
144 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
146 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
148 /// MCCodeGenInfoCtorFn - Constructor function for this target's MCCodeGenInfo,
150 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
152 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
154 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
156 /// MCInstrAnalysisCtorFn - Constructor function for this target's
157 /// MCInstrAnalysis, if registered.
158 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
160 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
162 MCRegInfoCtorFnTy MCRegInfoCtorFn;
164 /// MCSubtargetInfoCtorFn - Constructor function for this target's
165 /// MCSubtargetInfo, if registered.
166 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
168 /// TargetMachineCtorFn - Construction function for this target's
169 /// TargetMachine, if registered.
170 TargetMachineCtorTy TargetMachineCtorFn;
172 /// MCAsmBackendCtorFn - Construction function for this target's
173 /// MCAsmBackend, if registered.
174 MCAsmBackendCtorTy MCAsmBackendCtorFn;
176 /// MCAsmLexerCtorFn - Construction function for this target's
177 /// MCTargetAsmLexer, if registered.
178 MCAsmLexerCtorTy MCAsmLexerCtorFn;
180 /// MCAsmParserCtorFn - Construction function for this target's
181 /// MCTargetAsmParser, if registered.
182 MCAsmParserCtorTy MCAsmParserCtorFn;
184 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
186 AsmPrinterCtorTy AsmPrinterCtorFn;
188 /// MCDisassemblerCtorFn - Construction function for this target's
189 /// MCDisassembler, if registered.
190 MCDisassemblerCtorTy MCDisassemblerCtorFn;
192 /// MCInstPrinterCtorFn - Construction function for this target's
193 /// MCInstPrinter, if registered.
194 MCInstPrinterCtorTy MCInstPrinterCtorFn;
196 /// MCCodeEmitterCtorFn - Construction function for this target's
197 /// CodeEmitter, if registered.
198 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
200 /// MCObjectStreamerCtorFn - Construction function for this target's
201 /// MCObjectStreamer, if registered.
202 MCObjectStreamerCtorTy MCObjectStreamerCtorFn;
204 /// AsmStreamerCtorFn - Construction function for this target's
205 /// AsmStreamer, if registered (default = llvm::createAsmStreamer).
206 AsmStreamerCtorTy AsmStreamerCtorFn;
209 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
211 /// @name Target Information
214 // getNext - Return the next registered target.
215 const Target *getNext() const { return Next; }
217 /// getName - Get the target name.
218 const char *getName() const { return Name; }
220 /// getShortDescription - Get a short description of the target.
221 const char *getShortDescription() const { return ShortDesc; }
224 /// @name Feature Predicates
227 /// hasJIT - Check if this targets supports the just-in-time compilation.
228 bool hasJIT() const { return HasJIT; }
230 /// hasTargetMachine - Check if this target supports code generation.
231 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
233 /// hasMCAsmBackend - Check if this target supports .o generation.
234 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
236 /// hasMCAsmLexer - Check if this target supports .s lexing.
237 bool hasMCAsmLexer() const { return MCAsmLexerCtorFn != 0; }
239 /// hasAsmParser - Check if this target supports .s parsing.
240 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
242 /// hasAsmPrinter - Check if this target supports .s printing.
243 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
245 /// hasMCDisassembler - Check if this target has a disassembler.
246 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
248 /// hasMCInstPrinter - Check if this target has an instruction printer.
249 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
251 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
252 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
254 /// hasMCObjectStreamer - Check if this target supports streaming to files.
255 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
257 /// hasAsmStreamer - Check if this target supports streaming to files.
258 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
261 /// @name Feature Constructors
264 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
267 /// \arg Triple - This argument is used to determine the target machine
268 /// feature set; it should always be provided. Generally this should be
269 /// either the target triple from the module, or the target triple of the
270 /// host if that does not exist.
271 MCAsmInfo *createMCAsmInfo(StringRef Triple) const {
272 if (!MCAsmInfoCtorFn)
274 return MCAsmInfoCtorFn(*this, Triple);
277 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
279 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
280 CodeModel::Model CM) const {
281 if (!MCCodeGenInfoCtorFn)
283 return MCCodeGenInfoCtorFn(Triple, RM, CM);
286 /// createMCInstrInfo - Create a MCInstrInfo implementation.
288 MCInstrInfo *createMCInstrInfo() const {
289 if (!MCInstrInfoCtorFn)
291 return MCInstrInfoCtorFn();
294 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
296 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
297 if (!MCInstrAnalysisCtorFn)
299 return MCInstrAnalysisCtorFn(Info);
302 /// createMCRegInfo - Create a MCRegisterInfo implementation.
304 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
305 if (!MCRegInfoCtorFn)
307 return MCRegInfoCtorFn(Triple);
310 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
312 /// \arg Triple - This argument is used to determine the target machine
313 /// feature set; it should always be provided. Generally this should be
314 /// either the target triple from the module, or the target triple of the
315 /// host if that does not exist.
316 /// \arg CPU - This specifies the name of the target CPU.
317 /// \arg Features - This specifies the string representation of the
318 /// additional target features.
319 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
320 StringRef Features) const {
321 if (!MCSubtargetInfoCtorFn)
323 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
326 /// createTargetMachine - Create a target specific machine implementation
327 /// for the specified \arg Triple.
329 /// \arg Triple - This argument is used to determine the target machine
330 /// feature set; it should always be provided. Generally this should be
331 /// either the target triple from the module, or the target triple of the
332 /// host if that does not exist.
333 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
335 Reloc::Model RM = Reloc::Default,
336 CodeModel::Model CM = CodeModel::Default) const {
337 if (!TargetMachineCtorFn)
339 return TargetMachineCtorFn(*this, Triple, CPU, Features, RM, CM);
342 /// createMCAsmBackend - Create a target specific assembly parser.
344 /// \arg Triple - The target triple string.
345 /// \arg Backend - The target independent assembler object.
346 MCAsmBackend *createMCAsmBackend(StringRef Triple) const {
347 if (!MCAsmBackendCtorFn)
349 return MCAsmBackendCtorFn(*this, Triple);
352 /// createMCAsmLexer - Create a target specific assembly lexer.
354 MCTargetAsmLexer *createMCAsmLexer(const MCRegisterInfo &MRI,
355 const MCAsmInfo &MAI) const {
356 if (!MCAsmLexerCtorFn)
358 return MCAsmLexerCtorFn(*this, MRI, MAI);
361 /// createMCAsmParser - Create a target specific assembly parser.
363 /// \arg Parser - The target independent parser implementation to use for
364 /// parsing and lexing.
365 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
366 MCAsmParser &Parser) const {
367 if (!MCAsmParserCtorFn)
369 return MCAsmParserCtorFn(STI, Parser);
372 /// createAsmPrinter - Create a target specific assembly printer pass. This
373 /// takes ownership of the MCStreamer object.
374 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
375 if (!AsmPrinterCtorFn)
377 return AsmPrinterCtorFn(TM, Streamer);
380 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
381 if (!MCDisassemblerCtorFn)
383 return MCDisassemblerCtorFn(*this, STI);
386 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
387 const MCAsmInfo &MAI,
388 const MCSubtargetInfo &STI) const {
389 if (!MCInstPrinterCtorFn)
391 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, STI);
395 /// createMCCodeEmitter - Create a target specific code emitter.
396 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
397 const MCSubtargetInfo &STI,
398 MCContext &Ctx) const {
399 if (!MCCodeEmitterCtorFn)
401 return MCCodeEmitterCtorFn(II, STI, Ctx);
404 /// createMCObjectStreamer - Create a target specific MCStreamer.
406 /// \arg TT - The target triple.
407 /// \arg Ctx - The target context.
408 /// \arg TAB - The target assembler backend object. Takes ownership.
409 /// \arg _OS - The stream object.
410 /// \arg _Emitter - The target independent assembler object.Takes ownership.
411 /// \arg RelaxAll - Relax all fixups?
412 /// \arg NoExecStack - Mark file as not needing a executable stack.
413 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
416 MCCodeEmitter *_Emitter,
418 bool NoExecStack) const {
419 if (!MCObjectStreamerCtorFn)
421 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
422 RelaxAll, NoExecStack);
425 /// createAsmStreamer - Create a target specific MCStreamer.
426 MCStreamer *createAsmStreamer(MCContext &Ctx,
427 formatted_raw_ostream &OS,
431 bool useDwarfDirectory,
432 MCInstPrinter *InstPrint,
435 bool ShowInst) const {
436 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
437 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
438 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
444 /// TargetRegistry - Generic interface to target specific features.
445 struct TargetRegistry {
447 const Target *Current;
448 explicit iterator(Target *T) : Current(T) {}
449 friend struct TargetRegistry;
451 iterator(const iterator &I) : Current(I.Current) {}
452 iterator() : Current(0) {}
454 bool operator==(const iterator &x) const {
455 return Current == x.Current;
457 bool operator!=(const iterator &x) const {
458 return !operator==(x);
461 // Iterator traversal: forward iteration only
462 iterator &operator++() { // Preincrement
463 assert(Current && "Cannot increment end iterator!");
464 Current = Current->getNext();
467 iterator operator++(int) { // Postincrement
468 iterator tmp = *this;
473 const Target &operator*() const {
474 assert(Current && "Cannot dereference end iterator!");
478 const Target *operator->() const {
483 /// printRegisteredTargetsForVersion - Print the registered targets
484 /// appropriately for inclusion in a tool's version output.
485 static void printRegisteredTargetsForVersion();
487 /// @name Registry Access
490 static iterator begin();
492 static iterator end() { return iterator(); }
494 /// lookupTarget - Lookup a target based on a target triple.
496 /// \param Triple - The triple to use for finding a target.
497 /// \param Error - On failure, an error string describing why no target was
499 static const Target *lookupTarget(const std::string &Triple,
502 /// getClosestTargetForJIT - Pick the best target that is compatible with
503 /// the current host. If no close target can be found, this returns null
504 /// and sets the Error string to a reason.
506 /// Maintained for compatibility through 2.6.
507 static const Target *getClosestTargetForJIT(std::string &Error);
510 /// @name Target Registration
513 /// RegisterTarget - Register the given target. Attempts to register a
514 /// target which has already been registered will be ignored.
516 /// Clients are responsible for ensuring that registration doesn't occur
517 /// while another thread is attempting to access the registry. Typically
518 /// this is done by initializing all targets at program startup.
520 /// @param T - The target being registered.
521 /// @param Name - The target name. This should be a static string.
522 /// @param ShortDesc - A short target description. This should be a static
524 /// @param TQualityFn - The triple match quality computation function for
526 /// @param HasJIT - Whether the target supports JIT code
528 static void RegisterTarget(Target &T,
530 const char *ShortDesc,
531 Target::TripleMatchQualityFnTy TQualityFn,
532 bool HasJIT = false);
534 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
537 /// Clients are responsible for ensuring that registration doesn't occur
538 /// while another thread is attempting to access the registry. Typically
539 /// this is done by initializing all targets at program startup.
541 /// @param T - The target being registered.
542 /// @param Fn - A function to construct a MCAsmInfo for the target.
543 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
544 // Ignore duplicate registration.
545 if (!T.MCAsmInfoCtorFn)
546 T.MCAsmInfoCtorFn = Fn;
549 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
552 /// Clients are responsible for ensuring that registration doesn't occur
553 /// while another thread is attempting to access the registry. Typically
554 /// this is done by initializing all targets at program startup.
556 /// @param T - The target being registered.
557 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
558 static void RegisterMCCodeGenInfo(Target &T,
559 Target::MCCodeGenInfoCtorFnTy Fn) {
560 // Ignore duplicate registration.
561 if (!T.MCCodeGenInfoCtorFn)
562 T.MCCodeGenInfoCtorFn = Fn;
565 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
568 /// Clients are responsible for ensuring that registration doesn't occur
569 /// while another thread is attempting to access the registry. Typically
570 /// this is done by initializing all targets at program startup.
572 /// @param T - The target being registered.
573 /// @param Fn - A function to construct a MCInstrInfo for the target.
574 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
575 // Ignore duplicate registration.
576 if (!T.MCInstrInfoCtorFn)
577 T.MCInstrInfoCtorFn = Fn;
580 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
581 /// the given target.
582 static void RegisterMCInstrAnalysis(Target &T,
583 Target::MCInstrAnalysisCtorFnTy Fn) {
584 // Ignore duplicate registration.
585 if (!T.MCInstrAnalysisCtorFn)
586 T.MCInstrAnalysisCtorFn = Fn;
589 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
592 /// Clients are responsible for ensuring that registration doesn't occur
593 /// while another thread is attempting to access the registry. Typically
594 /// this is done by initializing all targets at program startup.
596 /// @param T - The target being registered.
597 /// @param Fn - A function to construct a MCRegisterInfo for the target.
598 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
599 // Ignore duplicate registration.
600 if (!T.MCRegInfoCtorFn)
601 T.MCRegInfoCtorFn = Fn;
604 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
605 /// the given target.
607 /// Clients are responsible for ensuring that registration doesn't occur
608 /// while another thread is attempting to access the registry. Typically
609 /// this is done by initializing all targets at program startup.
611 /// @param T - The target being registered.
612 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
613 static void RegisterMCSubtargetInfo(Target &T,
614 Target::MCSubtargetInfoCtorFnTy Fn) {
615 // Ignore duplicate registration.
616 if (!T.MCSubtargetInfoCtorFn)
617 T.MCSubtargetInfoCtorFn = Fn;
620 /// RegisterTargetMachine - Register a TargetMachine implementation for the
623 /// Clients are responsible for ensuring that registration doesn't occur
624 /// while another thread is attempting to access the registry. Typically
625 /// this is done by initializing all targets at program startup.
627 /// @param T - The target being registered.
628 /// @param Fn - A function to construct a TargetMachine for the target.
629 static void RegisterTargetMachine(Target &T,
630 Target::TargetMachineCtorTy Fn) {
631 // Ignore duplicate registration.
632 if (!T.TargetMachineCtorFn)
633 T.TargetMachineCtorFn = Fn;
636 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
639 /// Clients are responsible for ensuring that registration doesn't occur
640 /// while another thread is attempting to access the registry. Typically
641 /// this is done by initializing all targets at program startup.
643 /// @param T - The target being registered.
644 /// @param Fn - A function to construct an AsmBackend for the target.
645 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
646 if (!T.MCAsmBackendCtorFn)
647 T.MCAsmBackendCtorFn = Fn;
650 /// RegisterMCAsmLexer - Register a MCTargetAsmLexer implementation for the
653 /// Clients are responsible for ensuring that registration doesn't occur
654 /// while another thread is attempting to access the registry. Typically
655 /// this is done by initializing all targets at program startup.
657 /// @param T - The target being registered.
658 /// @param Fn - A function to construct an MCAsmLexer for the target.
659 static void RegisterMCAsmLexer(Target &T, Target::MCAsmLexerCtorTy Fn) {
660 if (!T.MCAsmLexerCtorFn)
661 T.MCAsmLexerCtorFn = Fn;
664 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
665 /// the given target.
667 /// Clients are responsible for ensuring that registration doesn't occur
668 /// while another thread is attempting to access the registry. Typically
669 /// this is done by initializing all targets at program startup.
671 /// @param T - The target being registered.
672 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
673 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
674 if (!T.MCAsmParserCtorFn)
675 T.MCAsmParserCtorFn = Fn;
678 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
681 /// Clients are responsible for ensuring that registration doesn't occur
682 /// while another thread is attempting to access the registry. Typically
683 /// this is done by initializing all targets at program startup.
685 /// @param T - The target being registered.
686 /// @param Fn - A function to construct an AsmPrinter for the target.
687 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
688 // Ignore duplicate registration.
689 if (!T.AsmPrinterCtorFn)
690 T.AsmPrinterCtorFn = Fn;
693 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
694 /// the given target.
696 /// Clients are responsible for ensuring that registration doesn't occur
697 /// while another thread is attempting to access the registry. Typically
698 /// this is done by initializing all targets at program startup.
700 /// @param T - The target being registered.
701 /// @param Fn - A function to construct an MCDisassembler for the target.
702 static void RegisterMCDisassembler(Target &T,
703 Target::MCDisassemblerCtorTy Fn) {
704 if (!T.MCDisassemblerCtorFn)
705 T.MCDisassemblerCtorFn = Fn;
708 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
711 /// Clients are responsible for ensuring that registration doesn't occur
712 /// while another thread is attempting to access the registry. Typically
713 /// this is done by initializing all targets at program startup.
715 /// @param T - The target being registered.
716 /// @param Fn - A function to construct an MCInstPrinter for the target.
717 static void RegisterMCInstPrinter(Target &T,
718 Target::MCInstPrinterCtorTy Fn) {
719 if (!T.MCInstPrinterCtorFn)
720 T.MCInstPrinterCtorFn = Fn;
723 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
726 /// Clients are responsible for ensuring that registration doesn't occur
727 /// while another thread is attempting to access the registry. Typically
728 /// this is done by initializing all targets at program startup.
730 /// @param T - The target being registered.
731 /// @param Fn - A function to construct an MCCodeEmitter for the target.
732 static void RegisterMCCodeEmitter(Target &T,
733 Target::MCCodeEmitterCtorTy Fn) {
734 if (!T.MCCodeEmitterCtorFn)
735 T.MCCodeEmitterCtorFn = Fn;
738 /// RegisterMCObjectStreamer - Register a object code MCStreamer
739 /// implementation for the given target.
741 /// Clients are responsible for ensuring that registration doesn't occur
742 /// while another thread is attempting to access the registry. Typically
743 /// this is done by initializing all targets at program startup.
745 /// @param T - The target being registered.
746 /// @param Fn - A function to construct an MCStreamer for the target.
747 static void RegisterMCObjectStreamer(Target &T,
748 Target::MCObjectStreamerCtorTy Fn) {
749 if (!T.MCObjectStreamerCtorFn)
750 T.MCObjectStreamerCtorFn = Fn;
753 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
754 /// for the given target.
756 /// Clients are responsible for ensuring that registration doesn't occur
757 /// while another thread is attempting to access the registry. Typically
758 /// this is done by initializing all targets at program startup.
760 /// @param T - The target being registered.
761 /// @param Fn - A function to construct an MCStreamer for the target.
762 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
763 if (T.AsmStreamerCtorFn == createAsmStreamer)
764 T.AsmStreamerCtorFn = Fn;
771 //===--------------------------------------------------------------------===//
773 /// RegisterTarget - Helper template for registering a target, for use in the
774 /// target's initialization function. Usage:
777 /// Target TheFooTarget; // The global target instance.
779 /// extern "C" void LLVMInitializeFooTargetInfo() {
780 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
782 template<Triple::ArchType TargetArchType = Triple::InvalidArch,
784 struct RegisterTarget {
785 RegisterTarget(Target &T, const char *Name, const char *Desc) {
786 TargetRegistry::RegisterTarget(T, Name, Desc,
787 &getTripleMatchQuality,
791 static unsigned getTripleMatchQuality(const std::string &TT) {
792 if (Triple(TT).getArch() == TargetArchType)
798 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
799 /// implementation. This invokes the static "Create" method on the class to
800 /// actually do the construction. Usage:
802 /// extern "C" void LLVMInitializeFooTarget() {
803 /// extern Target TheFooTarget;
804 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
806 template<class MCAsmInfoImpl>
807 struct RegisterMCAsmInfo {
808 RegisterMCAsmInfo(Target &T) {
809 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
812 static MCAsmInfo *Allocator(const Target &T, StringRef TT) {
813 return new MCAsmInfoImpl(T, TT);
818 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
819 /// implementation. This invokes the specified function to do the
820 /// construction. Usage:
822 /// extern "C" void LLVMInitializeFooTarget() {
823 /// extern Target TheFooTarget;
824 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
826 struct RegisterMCAsmInfoFn {
827 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
828 TargetRegistry::RegisterMCAsmInfo(T, Fn);
832 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
833 /// implementation. This invokes the static "Create" method on the class
834 /// to actually do the construction. Usage:
836 /// extern "C" void LLVMInitializeFooTarget() {
837 /// extern Target TheFooTarget;
838 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
840 template<class MCCodeGenInfoImpl>
841 struct RegisterMCCodeGenInfo {
842 RegisterMCCodeGenInfo(Target &T) {
843 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
846 static MCCodeGenInfo *Allocator(StringRef TT,
847 Reloc::Model RM, CodeModel::Model CM) {
848 return new MCCodeGenInfoImpl();
852 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
853 /// info implementation. This invokes the specified function to do the
854 /// construction. Usage:
856 /// extern "C" void LLVMInitializeFooTarget() {
857 /// extern Target TheFooTarget;
858 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
860 struct RegisterMCCodeGenInfoFn {
861 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
862 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
866 /// RegisterMCInstrInfo - Helper template for registering a target instruction
867 /// info implementation. This invokes the static "Create" method on the class
868 /// to actually do the construction. Usage:
870 /// extern "C" void LLVMInitializeFooTarget() {
871 /// extern Target TheFooTarget;
872 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
874 template<class MCInstrInfoImpl>
875 struct RegisterMCInstrInfo {
876 RegisterMCInstrInfo(Target &T) {
877 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
880 static MCInstrInfo *Allocator() {
881 return new MCInstrInfoImpl();
885 /// RegisterMCInstrInfoFn - Helper template for registering a target
886 /// instruction info implementation. This invokes the specified function to
887 /// do the construction. Usage:
889 /// extern "C" void LLVMInitializeFooTarget() {
890 /// extern Target TheFooTarget;
891 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
893 struct RegisterMCInstrInfoFn {
894 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
895 TargetRegistry::RegisterMCInstrInfo(T, Fn);
899 /// RegisterMCInstrAnalysis - Helper template for registering a target
900 /// instruction analyzer implementation. This invokes the static "Create"
901 /// method on the class to actually do the construction. Usage:
903 /// extern "C" void LLVMInitializeFooTarget() {
904 /// extern Target TheFooTarget;
905 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
907 template<class MCInstrAnalysisImpl>
908 struct RegisterMCInstrAnalysis {
909 RegisterMCInstrAnalysis(Target &T) {
910 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
913 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
914 return new MCInstrAnalysisImpl(Info);
918 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
919 /// instruction analyzer implementation. This invokes the specified function
920 /// to do the construction. Usage:
922 /// extern "C" void LLVMInitializeFooTarget() {
923 /// extern Target TheFooTarget;
924 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
926 struct RegisterMCInstrAnalysisFn {
927 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
928 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
932 /// RegisterMCRegInfo - Helper template for registering a target register info
933 /// implementation. This invokes the static "Create" method on the class to
934 /// actually do the construction. Usage:
936 /// extern "C" void LLVMInitializeFooTarget() {
937 /// extern Target TheFooTarget;
938 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
940 template<class MCRegisterInfoImpl>
941 struct RegisterMCRegInfo {
942 RegisterMCRegInfo(Target &T) {
943 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
946 static MCRegisterInfo *Allocator(StringRef TT) {
947 return new MCRegisterInfoImpl();
951 /// RegisterMCRegInfoFn - Helper template for registering a target register
952 /// info implementation. This invokes the specified function to do the
953 /// construction. Usage:
955 /// extern "C" void LLVMInitializeFooTarget() {
956 /// extern Target TheFooTarget;
957 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
959 struct RegisterMCRegInfoFn {
960 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
961 TargetRegistry::RegisterMCRegInfo(T, Fn);
965 /// RegisterMCSubtargetInfo - Helper template for registering a target
966 /// subtarget info implementation. This invokes the static "Create" method
967 /// on the class to actually do the construction. Usage:
969 /// extern "C" void LLVMInitializeFooTarget() {
970 /// extern Target TheFooTarget;
971 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
973 template<class MCSubtargetInfoImpl>
974 struct RegisterMCSubtargetInfo {
975 RegisterMCSubtargetInfo(Target &T) {
976 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
979 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
981 return new MCSubtargetInfoImpl();
985 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
986 /// subtarget info implementation. This invokes the specified function to
987 /// do the construction. Usage:
989 /// extern "C" void LLVMInitializeFooTarget() {
990 /// extern Target TheFooTarget;
991 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
993 struct RegisterMCSubtargetInfoFn {
994 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
995 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
999 /// RegisterTargetMachine - Helper template for registering a target machine
1000 /// implementation, for use in the target machine initialization
1001 /// function. Usage:
1003 /// extern "C" void LLVMInitializeFooTarget() {
1004 /// extern Target TheFooTarget;
1005 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1007 template<class TargetMachineImpl>
1008 struct RegisterTargetMachine {
1009 RegisterTargetMachine(Target &T) {
1010 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1014 static TargetMachine *Allocator(const Target &T, StringRef TT,
1015 StringRef CPU, StringRef FS,
1017 CodeModel::Model CM) {
1018 return new TargetMachineImpl(T, TT, CPU, FS, RM, CM);
1022 /// RegisterMCAsmBackend - Helper template for registering a target specific
1023 /// assembler backend. Usage:
1025 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1026 /// extern Target TheFooTarget;
1027 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1029 template<class MCAsmBackendImpl>
1030 struct RegisterMCAsmBackend {
1031 RegisterMCAsmBackend(Target &T) {
1032 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1036 static MCAsmBackend *Allocator(const Target &T, StringRef Triple) {
1037 return new MCAsmBackendImpl(T, Triple);
1041 /// RegisterMCAsmLexer - Helper template for registering a target specific
1042 /// assembly lexer, for use in the target machine initialization
1043 /// function. Usage:
1045 /// extern "C" void LLVMInitializeFooMCAsmLexer() {
1046 /// extern Target TheFooTarget;
1047 /// RegisterMCAsmLexer<FooMCAsmLexer> X(TheFooTarget);
1049 template<class MCAsmLexerImpl>
1050 struct RegisterMCAsmLexer {
1051 RegisterMCAsmLexer(Target &T) {
1052 TargetRegistry::RegisterMCAsmLexer(T, &Allocator);
1056 static MCTargetAsmLexer *Allocator(const Target &T,
1057 const MCRegisterInfo &MRI,
1058 const MCAsmInfo &MAI) {
1059 return new MCAsmLexerImpl(T, MRI, MAI);
1063 /// RegisterMCAsmParser - Helper template for registering a target specific
1064 /// assembly parser, for use in the target machine initialization
1065 /// function. Usage:
1067 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1068 /// extern Target TheFooTarget;
1069 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1071 template<class MCAsmParserImpl>
1072 struct RegisterMCAsmParser {
1073 RegisterMCAsmParser(Target &T) {
1074 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1078 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1079 return new MCAsmParserImpl(STI, P);
1083 /// RegisterAsmPrinter - Helper template for registering a target specific
1084 /// assembly printer, for use in the target machine initialization
1085 /// function. Usage:
1087 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1088 /// extern Target TheFooTarget;
1089 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1091 template<class AsmPrinterImpl>
1092 struct RegisterAsmPrinter {
1093 RegisterAsmPrinter(Target &T) {
1094 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1098 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1099 return new AsmPrinterImpl(TM, Streamer);
1103 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1104 /// machine code emitter, for use in the target initialization
1105 /// function. Usage:
1107 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1108 /// extern Target TheFooTarget;
1109 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1111 template<class MCCodeEmitterImpl>
1112 struct RegisterMCCodeEmitter {
1113 RegisterMCCodeEmitter(Target &T) {
1114 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1118 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1119 const MCSubtargetInfo &STI,
1121 return new MCCodeEmitterImpl();