1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file exposes the TargetRegistry interface, which tools can use to access
11 // the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
12 // which have been registered.
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
22 #include "llvm/ADT/Triple.h"
23 #include "llvm/Support/CodeGen.h"
38 class MCInstrAnalysis;
43 class MCSubtargetInfo;
44 class MCRelocationInfo;
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 MCRelocationInfo *createMCRelocationInfo(MCContext &Ctx);
62 /// Target - Wrapper for Target specific information.
64 /// For registration purposes, this is a POD type so that targets can be
65 /// registered without the use of static constructors.
67 /// Targets should implement a single global instance of this class (which
68 /// will be zero initialized), and pass that instance to the TargetRegistry as
69 /// part of their initialization.
72 friend struct TargetRegistry;
74 typedef unsigned (*TripleMatchQualityFnTy)(const std::string &TT);
76 typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
78 typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
81 CodeGenOpt::Level OL);
82 typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
83 typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
84 typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
85 typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
88 typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
92 const TargetOptions &Options,
95 CodeGenOpt::Level OL);
96 typedef AsmPrinter *(*AsmPrinterCtorTy)(TargetMachine &TM,
97 MCStreamer &Streamer);
98 typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
101 typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(MCSubtargetInfo &STI,
103 typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
104 const MCSubtargetInfo &STI);
105 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
106 unsigned SyntaxVariant,
107 const MCAsmInfo &MAI,
108 const MCInstrInfo &MII,
109 const MCRegisterInfo &MRI,
110 const MCSubtargetInfo &STI);
111 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
112 const MCRegisterInfo &MRI,
113 const MCSubtargetInfo &STI,
115 typedef MCStreamer *(*MCObjectStreamerCtorTy)(const Target &T,
120 MCCodeEmitter *_Emitter,
123 typedef MCStreamer *(*AsmStreamerCtorTy)(MCContext &Ctx,
124 formatted_raw_ostream &OS,
128 bool useDwarfDirectory,
129 MCInstPrinter *InstPrint,
133 typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
137 /// Next - The next registered target in the linked list, maintained by the
141 /// TripleMatchQualityFn - The target function for rating the match quality
143 TripleMatchQualityFnTy TripleMatchQualityFn;
145 /// Name - The target name.
148 /// ShortDesc - A short description of the target.
149 const char *ShortDesc;
151 /// HasJIT - Whether this target supports the JIT.
154 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
156 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
158 /// MCCodeGenInfoCtorFn - Constructor function for this target's
159 /// MCCodeGenInfo, if registered.
160 MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
162 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
164 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
166 /// MCInstrAnalysisCtorFn - Constructor function for this target's
167 /// MCInstrAnalysis, if registered.
168 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
170 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
172 MCRegInfoCtorFnTy MCRegInfoCtorFn;
174 /// MCSubtargetInfoCtorFn - Constructor function for this target's
175 /// MCSubtargetInfo, if registered.
176 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
178 /// TargetMachineCtorFn - Construction function for this target's
179 /// TargetMachine, if registered.
180 TargetMachineCtorTy TargetMachineCtorFn;
182 /// MCAsmBackendCtorFn - Construction function for this target's
183 /// MCAsmBackend, if registered.
184 MCAsmBackendCtorTy MCAsmBackendCtorFn;
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;
214 /// MCRelocationInfoCtorFn - Construction function for this target's
215 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
216 MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
219 Target() : AsmStreamerCtorFn(llvm::createAsmStreamer) {}
221 /// @name Target Information
224 // getNext - Return the next registered target.
225 const Target *getNext() const { return Next; }
227 /// getName - Get the target name.
228 const char *getName() const { return Name; }
230 /// getShortDescription - Get a short description of the target.
231 const char *getShortDescription() const { return ShortDesc; }
234 /// @name Feature Predicates
237 /// hasJIT - Check if this targets supports the just-in-time compilation.
238 bool hasJIT() const { return HasJIT; }
240 /// hasTargetMachine - Check if this target supports code generation.
241 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
243 /// hasMCAsmBackend - Check if this target supports .o generation.
244 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != 0; }
246 /// hasAsmParser - Check if this target supports .s parsing.
247 bool hasMCAsmParser() const { return MCAsmParserCtorFn != 0; }
249 /// hasAsmPrinter - Check if this target supports .s printing.
250 bool hasAsmPrinter() const { return AsmPrinterCtorFn != 0; }
252 /// hasMCDisassembler - Check if this target has a disassembler.
253 bool hasMCDisassembler() const { return MCDisassemblerCtorFn != 0; }
255 /// hasMCInstPrinter - Check if this target has an instruction printer.
256 bool hasMCInstPrinter() const { return MCInstPrinterCtorFn != 0; }
258 /// hasMCCodeEmitter - Check if this target supports instruction encoding.
259 bool hasMCCodeEmitter() const { return MCCodeEmitterCtorFn != 0; }
261 /// hasMCObjectStreamer - Check if this target supports streaming to files.
262 bool hasMCObjectStreamer() const { return MCObjectStreamerCtorFn != 0; }
264 /// hasAsmStreamer - Check if this target supports streaming to files.
265 bool hasAsmStreamer() const { return AsmStreamerCtorFn != 0; }
268 /// @name Feature Constructors
271 /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
274 /// \param Triple This argument is used to determine the target machine
275 /// feature set; it should always be provided. Generally this should be
276 /// either the target triple from the module, or the target triple of the
277 /// host if that does not exist.
278 MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
279 StringRef Triple) const {
280 if (!MCAsmInfoCtorFn)
282 return MCAsmInfoCtorFn(MRI, Triple);
285 /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
287 MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
289 CodeGenOpt::Level OL) const {
290 if (!MCCodeGenInfoCtorFn)
292 return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
295 /// createMCInstrInfo - Create a MCInstrInfo implementation.
297 MCInstrInfo *createMCInstrInfo() const {
298 if (!MCInstrInfoCtorFn)
300 return MCInstrInfoCtorFn();
303 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
305 MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
306 if (!MCInstrAnalysisCtorFn)
308 return MCInstrAnalysisCtorFn(Info);
311 /// createMCRegInfo - Create a MCRegisterInfo implementation.
313 MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
314 if (!MCRegInfoCtorFn)
316 return MCRegInfoCtorFn(Triple);
319 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
321 /// \param Triple This argument is used to determine the target machine
322 /// feature set; it should always be provided. Generally this should be
323 /// either the target triple from the module, or the target triple of the
324 /// host if that does not exist.
325 /// \param CPU This specifies the name of the target CPU.
326 /// \param Features This specifies the string representation of the
327 /// additional target features.
328 MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
329 StringRef Features) const {
330 if (!MCSubtargetInfoCtorFn)
332 return MCSubtargetInfoCtorFn(Triple, CPU, Features);
335 /// createTargetMachine - Create a target specific machine implementation
336 /// for the specified \p Triple.
338 /// \param Triple This argument is used to determine the target machine
339 /// feature set; it should always be provided. Generally this should be
340 /// either the target triple from the module, or the target triple of the
341 /// host if that does not exist.
342 TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
343 StringRef Features, const TargetOptions &Options,
344 Reloc::Model RM = Reloc::Default,
345 CodeModel::Model CM = CodeModel::Default,
346 CodeGenOpt::Level OL = CodeGenOpt::Default) const {
347 if (!TargetMachineCtorFn)
349 return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
353 /// createMCAsmBackend - Create a target specific assembly parser.
355 /// \param Triple The target triple string.
356 MCAsmBackend *createMCAsmBackend(StringRef Triple, StringRef CPU) const {
357 if (!MCAsmBackendCtorFn)
359 return MCAsmBackendCtorFn(*this, Triple, CPU);
362 /// createMCAsmParser - Create a target specific assembly parser.
364 /// \param Parser The target independent parser implementation to use for
365 /// parsing and lexing.
366 MCTargetAsmParser *createMCAsmParser(MCSubtargetInfo &STI,
367 MCAsmParser &Parser) const {
368 if (!MCAsmParserCtorFn)
370 return MCAsmParserCtorFn(STI, Parser);
373 /// createAsmPrinter - Create a target specific assembly printer pass. This
374 /// takes ownership of the MCStreamer object.
375 AsmPrinter *createAsmPrinter(TargetMachine &TM, MCStreamer &Streamer) const{
376 if (!AsmPrinterCtorFn)
378 return AsmPrinterCtorFn(TM, Streamer);
381 MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI) const {
382 if (!MCDisassemblerCtorFn)
384 return MCDisassemblerCtorFn(*this, STI);
387 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
388 const MCAsmInfo &MAI,
389 const MCInstrInfo &MII,
390 const MCRegisterInfo &MRI,
391 const MCSubtargetInfo &STI) const {
392 if (!MCInstPrinterCtorFn)
394 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
398 /// createMCCodeEmitter - Create a target specific code emitter.
399 MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
400 const MCRegisterInfo &MRI,
401 const MCSubtargetInfo &STI,
402 MCContext &Ctx) const {
403 if (!MCCodeEmitterCtorFn)
405 return MCCodeEmitterCtorFn(II, MRI, STI, Ctx);
408 /// createMCObjectStreamer - Create a target specific MCStreamer.
410 /// \param TT The target triple.
411 /// \param Ctx The target context.
412 /// \param TAB The target assembler backend object. Takes ownership.
413 /// \param _OS The stream object.
414 /// \param _Emitter The target independent assembler object.Takes ownership.
415 /// \param RelaxAll Relax all fixups?
416 /// \param NoExecStack Mark file as not needing a executable stack.
417 MCStreamer *createMCObjectStreamer(StringRef TT, MCContext &Ctx,
420 MCCodeEmitter *_Emitter,
422 bool NoExecStack) const {
423 if (!MCObjectStreamerCtorFn)
425 return MCObjectStreamerCtorFn(*this, TT, Ctx, TAB, _OS, _Emitter,
426 RelaxAll, NoExecStack);
429 /// createAsmStreamer - Create a target specific MCStreamer.
430 MCStreamer *createAsmStreamer(MCContext &Ctx,
431 formatted_raw_ostream &OS,
435 bool useDwarfDirectory,
436 MCInstPrinter *InstPrint,
439 bool ShowInst) const {
440 // AsmStreamerCtorFn is default to llvm::createAsmStreamer
441 return AsmStreamerCtorFn(Ctx, OS, isVerboseAsm, useLoc, useCFI,
442 useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
445 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
447 /// \param TT The target triple.
448 /// \param Ctx The target context.
450 createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
451 // MCRelocationInfoCtorFn defaults to createMCRelocationInfo
452 return MCRelocationInfoCtorFn(TT, Ctx);
458 /// TargetRegistry - Generic interface to target specific features.
459 struct TargetRegistry {
461 const Target *Current;
462 explicit iterator(Target *T) : Current(T) {}
463 friend struct TargetRegistry;
465 iterator(const iterator &I) : Current(I.Current) {}
466 iterator() : Current(0) {}
468 bool operator==(const iterator &x) const {
469 return Current == x.Current;
471 bool operator!=(const iterator &x) const {
472 return !operator==(x);
475 // Iterator traversal: forward iteration only
476 iterator &operator++() { // Preincrement
477 assert(Current && "Cannot increment end iterator!");
478 Current = Current->getNext();
481 iterator operator++(int) { // Postincrement
482 iterator tmp = *this;
487 const Target &operator*() const {
488 assert(Current && "Cannot dereference end iterator!");
492 const Target *operator->() const {
497 /// printRegisteredTargetsForVersion - Print the registered targets
498 /// appropriately for inclusion in a tool's version output.
499 static void printRegisteredTargetsForVersion();
501 /// @name Registry Access
504 static iterator begin();
506 static iterator end() { return iterator(); }
508 /// lookupTarget - Lookup a target based on a target triple.
510 /// \param Triple - The triple to use for finding a target.
511 /// \param Error - On failure, an error string describing why no target was
513 static const Target *lookupTarget(const std::string &Triple,
516 /// lookupTarget - Lookup a target based on an architecture name
517 /// and a target triple. If the architecture name is non-empty,
518 /// then the lookup is done by architecture. Otherwise, the target
521 /// \param ArchName - The architecture to use for finding a target.
522 /// \param TheTriple - The triple to use for finding a target. The
523 /// triple is updated with canonical architecture name if a lookup
524 /// by architecture is done.
525 /// \param Error - On failure, an error string describing why no target was
527 static const Target *lookupTarget(const std::string &ArchName,
531 /// getClosestTargetForJIT - Pick the best target that is compatible with
532 /// the current host. If no close target can be found, this returns null
533 /// and sets the Error string to a reason.
535 /// Maintained for compatibility through 2.6.
536 static const Target *getClosestTargetForJIT(std::string &Error);
539 /// @name Target Registration
542 /// RegisterTarget - Register the given target. Attempts to register a
543 /// target which has already been registered will be ignored.
545 /// Clients are responsible for ensuring that registration doesn't occur
546 /// while another thread is attempting to access the registry. Typically
547 /// this is done by initializing all targets at program startup.
549 /// @param T - The target being registered.
550 /// @param Name - The target name. This should be a static string.
551 /// @param ShortDesc - A short target description. This should be a static
553 /// @param TQualityFn - The triple match quality computation function for
555 /// @param HasJIT - Whether the target supports JIT code
557 static void RegisterTarget(Target &T,
559 const char *ShortDesc,
560 Target::TripleMatchQualityFnTy TQualityFn,
561 bool HasJIT = false);
563 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
566 /// Clients are responsible for ensuring that registration doesn't occur
567 /// while another thread is attempting to access the registry. Typically
568 /// this is done by initializing all targets at program startup.
570 /// @param T - The target being registered.
571 /// @param Fn - A function to construct a MCAsmInfo for the target.
572 static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
573 // Ignore duplicate registration.
574 if (!T.MCAsmInfoCtorFn)
575 T.MCAsmInfoCtorFn = Fn;
578 /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
581 /// Clients are responsible for ensuring that registration doesn't occur
582 /// while another thread is attempting to access the registry. Typically
583 /// this is done by initializing all targets at program startup.
585 /// @param T - The target being registered.
586 /// @param Fn - A function to construct a MCCodeGenInfo for the target.
587 static void RegisterMCCodeGenInfo(Target &T,
588 Target::MCCodeGenInfoCtorFnTy Fn) {
589 // Ignore duplicate registration.
590 if (!T.MCCodeGenInfoCtorFn)
591 T.MCCodeGenInfoCtorFn = Fn;
594 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
597 /// Clients are responsible for ensuring that registration doesn't occur
598 /// while another thread is attempting to access the registry. Typically
599 /// this is done by initializing all targets at program startup.
601 /// @param T - The target being registered.
602 /// @param Fn - A function to construct a MCInstrInfo for the target.
603 static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
604 // Ignore duplicate registration.
605 if (!T.MCInstrInfoCtorFn)
606 T.MCInstrInfoCtorFn = Fn;
609 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
610 /// the given target.
611 static void RegisterMCInstrAnalysis(Target &T,
612 Target::MCInstrAnalysisCtorFnTy Fn) {
613 // Ignore duplicate registration.
614 if (!T.MCInstrAnalysisCtorFn)
615 T.MCInstrAnalysisCtorFn = Fn;
618 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
621 /// Clients are responsible for ensuring that registration doesn't occur
622 /// while another thread is attempting to access the registry. Typically
623 /// this is done by initializing all targets at program startup.
625 /// @param T - The target being registered.
626 /// @param Fn - A function to construct a MCRegisterInfo for the target.
627 static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
628 // Ignore duplicate registration.
629 if (!T.MCRegInfoCtorFn)
630 T.MCRegInfoCtorFn = Fn;
633 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
634 /// the given target.
636 /// Clients are responsible for ensuring that registration doesn't occur
637 /// while another thread is attempting to access the registry. Typically
638 /// this is done by initializing all targets at program startup.
640 /// @param T - The target being registered.
641 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
642 static void RegisterMCSubtargetInfo(Target &T,
643 Target::MCSubtargetInfoCtorFnTy Fn) {
644 // Ignore duplicate registration.
645 if (!T.MCSubtargetInfoCtorFn)
646 T.MCSubtargetInfoCtorFn = Fn;
649 /// RegisterTargetMachine - Register a TargetMachine implementation for the
652 /// Clients are responsible for ensuring that registration doesn't occur
653 /// while another thread is attempting to access the registry. Typically
654 /// this is done by initializing all targets at program startup.
656 /// @param T - The target being registered.
657 /// @param Fn - A function to construct a TargetMachine for the target.
658 static void RegisterTargetMachine(Target &T,
659 Target::TargetMachineCtorTy Fn) {
660 // Ignore duplicate registration.
661 if (!T.TargetMachineCtorFn)
662 T.TargetMachineCtorFn = Fn;
665 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
668 /// Clients are responsible for ensuring that registration doesn't occur
669 /// while another thread is attempting to access the registry. Typically
670 /// this is done by initializing all targets at program startup.
672 /// @param T - The target being registered.
673 /// @param Fn - A function to construct an AsmBackend for the target.
674 static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
675 if (!T.MCAsmBackendCtorFn)
676 T.MCAsmBackendCtorFn = Fn;
679 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
680 /// the given target.
682 /// Clients are responsible for ensuring that registration doesn't occur
683 /// while another thread is attempting to access the registry. Typically
684 /// this is done by initializing all targets at program startup.
686 /// @param T - The target being registered.
687 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
688 static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
689 if (!T.MCAsmParserCtorFn)
690 T.MCAsmParserCtorFn = Fn;
693 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
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 AsmPrinter for the target.
702 static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
703 // Ignore duplicate registration.
704 if (!T.AsmPrinterCtorFn)
705 T.AsmPrinterCtorFn = Fn;
708 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
709 /// the given target.
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 MCDisassembler for the target.
717 static void RegisterMCDisassembler(Target &T,
718 Target::MCDisassemblerCtorTy Fn) {
719 if (!T.MCDisassemblerCtorFn)
720 T.MCDisassemblerCtorFn = Fn;
723 /// RegisterMCInstPrinter - Register a MCInstPrinter 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 MCInstPrinter for the target.
732 static void RegisterMCInstPrinter(Target &T,
733 Target::MCInstPrinterCtorTy Fn) {
734 if (!T.MCInstPrinterCtorFn)
735 T.MCInstPrinterCtorFn = Fn;
738 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
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 MCCodeEmitter for the target.
747 static void RegisterMCCodeEmitter(Target &T,
748 Target::MCCodeEmitterCtorTy Fn) {
749 if (!T.MCCodeEmitterCtorFn)
750 T.MCCodeEmitterCtorFn = Fn;
753 /// RegisterMCObjectStreamer - Register a object code MCStreamer
754 /// implementation 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 RegisterMCObjectStreamer(Target &T,
763 Target::MCObjectStreamerCtorTy Fn) {
764 if (!T.MCObjectStreamerCtorFn)
765 T.MCObjectStreamerCtorFn = Fn;
768 /// RegisterAsmStreamer - Register an assembly MCStreamer implementation
769 /// for the given target.
771 /// Clients are responsible for ensuring that registration doesn't occur
772 /// while another thread is attempting to access the registry. Typically
773 /// this is done by initializing all targets at program startup.
775 /// @param T - The target being registered.
776 /// @param Fn - A function to construct an MCStreamer for the target.
777 static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn) {
778 if (T.AsmStreamerCtorFn == createAsmStreamer)
779 T.AsmStreamerCtorFn = Fn;
782 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
783 /// implementation for the given target.
785 /// Clients are responsible for ensuring that registration doesn't occur
786 /// while another thread is attempting to access the registry. Typically
787 /// this is done by initializing all targets at program startup.
789 /// @param T - The target being registered.
790 /// @param Fn - A function to construct an MCRelocationInfo for the target.
791 static void RegisterMCRelocationInfo(Target &T,
792 Target::MCRelocationInfoCtorTy Fn) {
793 if (!T.MCRelocationInfoCtorFn)
794 T.MCRelocationInfoCtorFn = Fn;
801 //===--------------------------------------------------------------------===//
803 /// RegisterTarget - Helper template for registering a target, for use in the
804 /// target's initialization function. Usage:
807 /// Target TheFooTarget; // The global target instance.
809 /// extern "C" void LLVMInitializeFooTargetInfo() {
810 /// RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
812 template<Triple::ArchType TargetArchType = Triple::UnknownArch,
814 struct RegisterTarget {
815 RegisterTarget(Target &T, const char *Name, const char *Desc) {
816 TargetRegistry::RegisterTarget(T, Name, Desc,
817 &getTripleMatchQuality,
821 static unsigned getTripleMatchQuality(const std::string &TT) {
822 if (Triple(TT).getArch() == TargetArchType)
828 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
829 /// implementation. This invokes the static "Create" method on the class to
830 /// actually do the construction. Usage:
832 /// extern "C" void LLVMInitializeFooTarget() {
833 /// extern Target TheFooTarget;
834 /// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
836 template<class MCAsmInfoImpl>
837 struct RegisterMCAsmInfo {
838 RegisterMCAsmInfo(Target &T) {
839 TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
842 static MCAsmInfo *Allocator(const MCRegisterInfo &MRI, StringRef TT) {
843 return new MCAsmInfoImpl(TT);
848 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
849 /// implementation. This invokes the specified function to do the
850 /// construction. Usage:
852 /// extern "C" void LLVMInitializeFooTarget() {
853 /// extern Target TheFooTarget;
854 /// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
856 struct RegisterMCAsmInfoFn {
857 RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
858 TargetRegistry::RegisterMCAsmInfo(T, Fn);
862 /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
863 /// implementation. This invokes the static "Create" method on the class
864 /// to actually do the construction. Usage:
866 /// extern "C" void LLVMInitializeFooTarget() {
867 /// extern Target TheFooTarget;
868 /// RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
870 template<class MCCodeGenInfoImpl>
871 struct RegisterMCCodeGenInfo {
872 RegisterMCCodeGenInfo(Target &T) {
873 TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
876 static MCCodeGenInfo *Allocator(StringRef TT, Reloc::Model RM,
877 CodeModel::Model CM, CodeGenOpt::Level OL) {
878 return new MCCodeGenInfoImpl();
882 /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
883 /// info implementation. This invokes the specified function to do the
884 /// construction. Usage:
886 /// extern "C" void LLVMInitializeFooTarget() {
887 /// extern Target TheFooTarget;
888 /// RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
890 struct RegisterMCCodeGenInfoFn {
891 RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
892 TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
896 /// RegisterMCInstrInfo - Helper template for registering a target instruction
897 /// info implementation. This invokes the static "Create" method on the class
898 /// to actually do the construction. Usage:
900 /// extern "C" void LLVMInitializeFooTarget() {
901 /// extern Target TheFooTarget;
902 /// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
904 template<class MCInstrInfoImpl>
905 struct RegisterMCInstrInfo {
906 RegisterMCInstrInfo(Target &T) {
907 TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
910 static MCInstrInfo *Allocator() {
911 return new MCInstrInfoImpl();
915 /// RegisterMCInstrInfoFn - Helper template for registering a target
916 /// instruction info implementation. This invokes the specified function to
917 /// do the construction. Usage:
919 /// extern "C" void LLVMInitializeFooTarget() {
920 /// extern Target TheFooTarget;
921 /// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
923 struct RegisterMCInstrInfoFn {
924 RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
925 TargetRegistry::RegisterMCInstrInfo(T, Fn);
929 /// RegisterMCInstrAnalysis - Helper template for registering a target
930 /// instruction analyzer implementation. This invokes the static "Create"
931 /// method on the class to actually do the construction. Usage:
933 /// extern "C" void LLVMInitializeFooTarget() {
934 /// extern Target TheFooTarget;
935 /// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
937 template<class MCInstrAnalysisImpl>
938 struct RegisterMCInstrAnalysis {
939 RegisterMCInstrAnalysis(Target &T) {
940 TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
943 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
944 return new MCInstrAnalysisImpl(Info);
948 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
949 /// instruction analyzer implementation. This invokes the specified function
950 /// to do the construction. Usage:
952 /// extern "C" void LLVMInitializeFooTarget() {
953 /// extern Target TheFooTarget;
954 /// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
956 struct RegisterMCInstrAnalysisFn {
957 RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
958 TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
962 /// RegisterMCRegInfo - Helper template for registering a target register info
963 /// implementation. This invokes the static "Create" method on the class to
964 /// actually do the construction. Usage:
966 /// extern "C" void LLVMInitializeFooTarget() {
967 /// extern Target TheFooTarget;
968 /// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
970 template<class MCRegisterInfoImpl>
971 struct RegisterMCRegInfo {
972 RegisterMCRegInfo(Target &T) {
973 TargetRegistry::RegisterMCRegInfo(T, &Allocator);
976 static MCRegisterInfo *Allocator(StringRef TT) {
977 return new MCRegisterInfoImpl();
981 /// RegisterMCRegInfoFn - Helper template for registering a target register
982 /// info implementation. This invokes the specified function to do the
983 /// construction. Usage:
985 /// extern "C" void LLVMInitializeFooTarget() {
986 /// extern Target TheFooTarget;
987 /// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
989 struct RegisterMCRegInfoFn {
990 RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
991 TargetRegistry::RegisterMCRegInfo(T, Fn);
995 /// RegisterMCSubtargetInfo - Helper template for registering a target
996 /// subtarget info implementation. This invokes the static "Create" method
997 /// on the class to actually do the construction. Usage:
999 /// extern "C" void LLVMInitializeFooTarget() {
1000 /// extern Target TheFooTarget;
1001 /// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1003 template<class MCSubtargetInfoImpl>
1004 struct RegisterMCSubtargetInfo {
1005 RegisterMCSubtargetInfo(Target &T) {
1006 TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1009 static MCSubtargetInfo *Allocator(StringRef TT, StringRef CPU,
1011 return new MCSubtargetInfoImpl();
1015 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1016 /// subtarget info implementation. This invokes the specified function to
1017 /// do the construction. Usage:
1019 /// extern "C" void LLVMInitializeFooTarget() {
1020 /// extern Target TheFooTarget;
1021 /// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1023 struct RegisterMCSubtargetInfoFn {
1024 RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1025 TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1029 /// RegisterTargetMachine - Helper template for registering a target machine
1030 /// implementation, for use in the target machine initialization
1031 /// function. Usage:
1033 /// extern "C" void LLVMInitializeFooTarget() {
1034 /// extern Target TheFooTarget;
1035 /// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1037 template<class TargetMachineImpl>
1038 struct RegisterTargetMachine {
1039 RegisterTargetMachine(Target &T) {
1040 TargetRegistry::RegisterTargetMachine(T, &Allocator);
1044 static TargetMachine *Allocator(const Target &T, StringRef TT,
1045 StringRef CPU, StringRef FS,
1046 const TargetOptions &Options,
1048 CodeModel::Model CM,
1049 CodeGenOpt::Level OL) {
1050 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1054 /// RegisterMCAsmBackend - Helper template for registering a target specific
1055 /// assembler backend. Usage:
1057 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1058 /// extern Target TheFooTarget;
1059 /// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1061 template<class MCAsmBackendImpl>
1062 struct RegisterMCAsmBackend {
1063 RegisterMCAsmBackend(Target &T) {
1064 TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1068 static MCAsmBackend *Allocator(const Target &T, StringRef Triple,
1070 return new MCAsmBackendImpl(T, Triple, CPU);
1074 /// RegisterMCAsmParser - Helper template for registering a target specific
1075 /// assembly parser, for use in the target machine initialization
1076 /// function. Usage:
1078 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1079 /// extern Target TheFooTarget;
1080 /// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1082 template<class MCAsmParserImpl>
1083 struct RegisterMCAsmParser {
1084 RegisterMCAsmParser(Target &T) {
1085 TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1089 static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P) {
1090 return new MCAsmParserImpl(STI, P);
1094 /// RegisterAsmPrinter - Helper template for registering a target specific
1095 /// assembly printer, for use in the target machine initialization
1096 /// function. Usage:
1098 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1099 /// extern Target TheFooTarget;
1100 /// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1102 template<class AsmPrinterImpl>
1103 struct RegisterAsmPrinter {
1104 RegisterAsmPrinter(Target &T) {
1105 TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1109 static AsmPrinter *Allocator(TargetMachine &TM, MCStreamer &Streamer) {
1110 return new AsmPrinterImpl(TM, Streamer);
1114 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1115 /// machine code emitter, for use in the target initialization
1116 /// function. Usage:
1118 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1119 /// extern Target TheFooTarget;
1120 /// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1122 template<class MCCodeEmitterImpl>
1123 struct RegisterMCCodeEmitter {
1124 RegisterMCCodeEmitter(Target &T) {
1125 TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1129 static MCCodeEmitter *Allocator(const MCInstrInfo &II,
1130 const MCRegisterInfo &MRI,
1131 const MCSubtargetInfo &STI,
1133 return new MCCodeEmitterImpl();