Readdress r236990, use of static members on a non-static variable.
[oota-llvm.git] / include / llvm / Support / TargetRegistry.h
1 //===-- Support/TargetRegistry.h - Target Registration ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 // Target specific class implementations should register themselves using the
15 // appropriate TargetRegistry interfaces.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_SUPPORT_TARGETREGISTRY_H
20 #define LLVM_SUPPORT_TARGETREGISTRY_H
21
22 #include "llvm-c/Disassembler.h"
23 #include "llvm/ADT/Triple.h"
24 #include "llvm/Support/CodeGen.h"
25 #include "llvm/Support/FormattedStream.h"
26 #include <cassert>
27 #include <memory>
28 #include <string>
29
30 namespace llvm {
31   class AsmPrinter;
32   class MCAsmBackend;
33   class MCAsmInfo;
34   class MCAsmParser;
35   class MCCodeEmitter;
36   class MCCodeGenInfo;
37   class MCContext;
38   class MCDisassembler;
39   class MCInstrAnalysis;
40   class MCInstPrinter;
41   class MCInstrInfo;
42   class MCRegisterInfo;
43   class MCStreamer;
44   class MCSubtargetInfo;
45   class MCSymbolizer;
46   class MCRelocationInfo;
47   class MCTargetAsmParser;
48   class MCTargetOptions;
49   class MCTargetStreamer;
50   class TargetMachine;
51   class TargetOptions;
52   class raw_ostream;
53   class raw_pwrite_stream;
54   class formatted_raw_ostream;
55
56   MCStreamer *createNullStreamer(MCContext &Ctx);
57   MCStreamer *createAsmStreamer(MCContext &Ctx,
58                                 std::unique_ptr<formatted_raw_ostream> OS,
59                                 bool isVerboseAsm, bool useDwarfDirectory,
60                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
61                                 MCAsmBackend *TAB, bool ShowInst);
62
63   /// Takes ownership of \p TAB and \p CE.
64   MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
65                                 raw_pwrite_stream &OS, MCCodeEmitter *CE,
66                                 bool RelaxAll);
67   MCStreamer *createMachOStreamer(MCContext &Ctx, MCAsmBackend &TAB,
68                                   raw_pwrite_stream &OS, MCCodeEmitter *CE,
69                                   bool RelaxAll, bool DWARFMustBeAtTheEnd,
70                                   bool LabelSections = false);
71
72   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx);
73
74   MCSymbolizer *createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
75                                    LLVMSymbolLookupCallback SymbolLookUp,
76                                    void *DisInfo, MCContext *Ctx,
77                                    std::unique_ptr<MCRelocationInfo> &&RelInfo);
78
79   /// Target - Wrapper for Target specific information.
80   ///
81   /// For registration purposes, this is a POD type so that targets can be
82   /// registered without the use of static constructors.
83   ///
84   /// Targets should implement a single global instance of this class (which
85   /// will be zero initialized), and pass that instance to the TargetRegistry as
86   /// part of their initialization.
87   class Target {
88   public:
89     friend struct TargetRegistry;
90
91     typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
92
93     typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
94                                             StringRef TT);
95     typedef MCCodeGenInfo *(*MCCodeGenInfoCtorFnTy)(StringRef TT,
96                                                     Reloc::Model RM,
97                                                     CodeModel::Model CM,
98                                                     CodeGenOpt::Level OL);
99     typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
100     typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo*Info);
101     typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(StringRef TT);
102     typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(StringRef TT,
103                                                         StringRef CPU,
104                                                         StringRef Features);
105     typedef TargetMachine *(*TargetMachineCtorTy)(const Target &T,
106                                                   StringRef TT,
107                                                   StringRef CPU,
108                                                   StringRef Features,
109                                                   const TargetOptions &Options,
110                                                   Reloc::Model RM,
111                                                   CodeModel::Model CM,
112                                                   CodeGenOpt::Level OL);
113     // If it weren't for layering issues (this header is in llvm/Support, but
114     // depends on MC?) this should take the Streamer by value rather than rvalue
115     // reference.
116     typedef AsmPrinter *(*AsmPrinterCtorTy)(
117         TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
118     typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
119                                                 const MCRegisterInfo &MRI,
120                                                 StringRef TT,
121                                                 StringRef CPU);
122     typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
123         MCSubtargetInfo &STI,
124         MCAsmParser &P,
125         const MCInstrInfo &MII,
126         const MCTargetOptions &Options);
127     typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
128                                                     const MCSubtargetInfo &STI,
129                                                     MCContext &Ctx);
130     typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
131                                                   unsigned SyntaxVariant,
132                                                   const MCAsmInfo &MAI,
133                                                   const MCInstrInfo &MII,
134                                                   const MCRegisterInfo &MRI);
135     typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
136                                                   const MCRegisterInfo &MRI,
137                                                   MCContext &Ctx);
138     typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
139                                              MCAsmBackend &TAB,
140                                              raw_pwrite_stream &OS,
141                                              MCCodeEmitter *Emitter,
142                                              bool RelaxAll);
143     typedef MCStreamer *(*MachOStreamerCtorTy)(
144         MCContext &Ctx, MCAsmBackend &TAB, raw_pwrite_stream &OS,
145         MCCodeEmitter *Emitter, bool RelaxAll, bool DWARFMustBeAtTheEnd);
146     typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
147                                               raw_pwrite_stream &OS,
148                                               MCCodeEmitter *Emitter,
149                                               bool RelaxAll);
150     typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
151     typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
152         MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
153         bool IsVerboseAsm);
154     typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
155         MCStreamer &S, const MCSubtargetInfo &STI);
156     typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT,
157                                                         MCContext &Ctx);
158     typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
159         StringRef TT, LLVMOpInfoCallback GetOpInfo,
160         LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
161         std::unique_ptr<MCRelocationInfo> &&RelInfo);
162
163   private:
164     /// Next - The next registered target in the linked list, maintained by the
165     /// TargetRegistry.
166     Target *Next;
167
168     /// The target function for checking if an architecture is supported.
169     ArchMatchFnTy ArchMatchFn;
170
171     /// Name - The target name.
172     const char *Name;
173
174     /// ShortDesc - A short description of the target.
175     const char *ShortDesc;
176
177     /// HasJIT - Whether this target supports the JIT.
178     bool HasJIT;
179
180     /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
181     /// registered.
182     MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
183
184     /// MCCodeGenInfoCtorFn - Constructor function for this target's
185     /// MCCodeGenInfo, if registered.
186     MCCodeGenInfoCtorFnTy MCCodeGenInfoCtorFn;
187
188     /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
189     /// if registered.
190     MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
191
192     /// MCInstrAnalysisCtorFn - Constructor function for this target's
193     /// MCInstrAnalysis, if registered.
194     MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
195
196     /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
197     /// if registered.
198     MCRegInfoCtorFnTy MCRegInfoCtorFn;
199
200     /// MCSubtargetInfoCtorFn - Constructor function for this target's
201     /// MCSubtargetInfo, if registered.
202     MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
203
204     /// TargetMachineCtorFn - Construction function for this target's
205     /// TargetMachine, if registered.
206     TargetMachineCtorTy TargetMachineCtorFn;
207
208     /// MCAsmBackendCtorFn - Construction function for this target's
209     /// MCAsmBackend, if registered.
210     MCAsmBackendCtorTy MCAsmBackendCtorFn;
211
212     /// MCAsmParserCtorFn - Construction function for this target's
213     /// MCTargetAsmParser, if registered.
214     MCAsmParserCtorTy MCAsmParserCtorFn;
215
216     /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
217     /// if registered.
218     AsmPrinterCtorTy AsmPrinterCtorFn;
219
220     /// MCDisassemblerCtorFn - Construction function for this target's
221     /// MCDisassembler, if registered.
222     MCDisassemblerCtorTy MCDisassemblerCtorFn;
223
224     /// MCInstPrinterCtorFn - Construction function for this target's
225     /// MCInstPrinter, if registered.
226     MCInstPrinterCtorTy MCInstPrinterCtorFn;
227
228     /// MCCodeEmitterCtorFn - Construction function for this target's
229     /// CodeEmitter, if registered.
230     MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
231
232     // Construction functions for the various object formats, if registered.
233     COFFStreamerCtorTy COFFStreamerCtorFn;
234     MachOStreamerCtorTy MachOStreamerCtorFn;
235     ELFStreamerCtorTy ELFStreamerCtorFn;
236
237     /// Construction function for this target's null TargetStreamer, if
238     /// registered (default = nullptr).
239     NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
240
241     /// Construction function for this target's asm TargetStreamer, if
242     /// registered (default = nullptr).
243     AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
244
245     /// Construction function for this target's obj TargetStreamer, if
246     /// registered (default = nullptr).
247     ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
248
249     /// MCRelocationInfoCtorFn - Construction function for this target's
250     /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
251     MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
252
253     /// MCSymbolizerCtorFn - Construction function for this target's
254     /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
255     MCSymbolizerCtorTy MCSymbolizerCtorFn;
256
257   public:
258     Target()
259         : COFFStreamerCtorFn(nullptr), MachOStreamerCtorFn(nullptr),
260           ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
261           AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
262           MCRelocationInfoCtorFn(nullptr), MCSymbolizerCtorFn(nullptr) {}
263
264     /// @name Target Information
265     /// @{
266
267     // getNext - Return the next registered target.
268     const Target *getNext() const { return Next; }
269
270     /// getName - Get the target name.
271     const char *getName() const { return Name; }
272
273     /// getShortDescription - Get a short description of the target.
274     const char *getShortDescription() const { return ShortDesc; }
275
276     /// @}
277     /// @name Feature Predicates
278     /// @{
279
280     /// hasJIT - Check if this targets supports the just-in-time compilation.
281     bool hasJIT() const { return HasJIT; }
282
283     /// hasTargetMachine - Check if this target supports code generation.
284     bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
285
286     /// hasMCAsmBackend - Check if this target supports .o generation.
287     bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
288
289     /// @}
290     /// @name Feature Constructors
291     /// @{
292
293     /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
294     /// target triple.
295     ///
296     /// \param Triple This argument is used to determine the target machine
297     /// feature set; it should always be provided. Generally this should be
298     /// either the target triple from the module, or the target triple of the
299     /// host if that does not exist.
300     MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
301                                StringRef Triple) const {
302       if (!MCAsmInfoCtorFn)
303         return nullptr;
304       return MCAsmInfoCtorFn(MRI, Triple);
305     }
306
307     /// createMCCodeGenInfo - Create a MCCodeGenInfo implementation.
308     ///
309     MCCodeGenInfo *createMCCodeGenInfo(StringRef Triple, Reloc::Model RM,
310                                        CodeModel::Model CM,
311                                        CodeGenOpt::Level OL) const {
312       if (!MCCodeGenInfoCtorFn)
313         return nullptr;
314       return MCCodeGenInfoCtorFn(Triple, RM, CM, OL);
315     }
316
317     /// createMCInstrInfo - Create a MCInstrInfo implementation.
318     ///
319     MCInstrInfo *createMCInstrInfo() const {
320       if (!MCInstrInfoCtorFn)
321         return nullptr;
322       return MCInstrInfoCtorFn();
323     }
324
325     /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
326     ///
327     MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
328       if (!MCInstrAnalysisCtorFn)
329         return nullptr;
330       return MCInstrAnalysisCtorFn(Info);
331     }
332
333     /// createMCRegInfo - Create a MCRegisterInfo implementation.
334     ///
335     MCRegisterInfo *createMCRegInfo(StringRef Triple) const {
336       if (!MCRegInfoCtorFn)
337         return nullptr;
338       return MCRegInfoCtorFn(Triple);
339     }
340
341     /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
342     ///
343     /// \param Triple This argument is used to determine the target machine
344     /// feature set; it should always be provided. Generally this should be
345     /// either the target triple from the module, or the target triple of the
346     /// host if that does not exist.
347     /// \param CPU This specifies the name of the target CPU.
348     /// \param Features This specifies the string representation of the
349     /// additional target features.
350     MCSubtargetInfo *createMCSubtargetInfo(StringRef Triple, StringRef CPU,
351                                            StringRef Features) const {
352       if (!MCSubtargetInfoCtorFn)
353         return nullptr;
354       return MCSubtargetInfoCtorFn(Triple, CPU, Features);
355     }
356
357     /// createTargetMachine - Create a target specific machine implementation
358     /// for the specified \p Triple.
359     ///
360     /// \param Triple This argument is used to determine the target machine
361     /// feature set; it should always be provided. Generally this should be
362     /// either the target triple from the module, or the target triple of the
363     /// host if that does not exist.
364     TargetMachine *createTargetMachine(StringRef Triple, StringRef CPU,
365                              StringRef Features, const TargetOptions &Options,
366                              Reloc::Model RM = Reloc::Default,
367                              CodeModel::Model CM = CodeModel::Default,
368                              CodeGenOpt::Level OL = CodeGenOpt::Default) const {
369       if (!TargetMachineCtorFn)
370         return nullptr;
371       return TargetMachineCtorFn(*this, Triple, CPU, Features, Options,
372                                  RM, CM, OL);
373     }
374
375     /// createMCAsmBackend - Create a target specific assembly parser.
376     ///
377     /// \param Triple The target triple string.
378     MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
379                                      StringRef Triple, StringRef CPU) const {
380       if (!MCAsmBackendCtorFn)
381         return nullptr;
382       return MCAsmBackendCtorFn(*this, MRI, Triple, CPU);
383     }
384
385     /// createMCAsmParser - Create a target specific assembly parser.
386     ///
387     /// \param Parser The target independent parser implementation to use for
388     /// parsing and lexing.
389     MCTargetAsmParser *createMCAsmParser(
390         MCSubtargetInfo &STI,
391         MCAsmParser &Parser,
392         const MCInstrInfo &MII,
393         const MCTargetOptions &Options) const {
394       if (!MCAsmParserCtorFn)
395         return nullptr;
396       return MCAsmParserCtorFn(STI, Parser, MII, Options);
397     }
398
399     /// createAsmPrinter - Create a target specific assembly printer pass.  This
400     /// takes ownership of the MCStreamer object.
401     AsmPrinter *createAsmPrinter(TargetMachine &TM,
402                                  std::unique_ptr<MCStreamer> &&Streamer) const {
403       if (!AsmPrinterCtorFn)
404         return nullptr;
405       return AsmPrinterCtorFn(TM, std::move(Streamer));
406     }
407
408     MCDisassembler *createMCDisassembler(const MCSubtargetInfo &STI,
409                                          MCContext &Ctx) const {
410       if (!MCDisassemblerCtorFn)
411         return nullptr;
412       return MCDisassemblerCtorFn(*this, STI, Ctx);
413     }
414
415     MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
416                                        const MCAsmInfo &MAI,
417                                        const MCInstrInfo &MII,
418                                        const MCRegisterInfo &MRI) const {
419       if (!MCInstPrinterCtorFn)
420         return nullptr;
421       return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
422     }
423
424
425     /// createMCCodeEmitter - Create a target specific code emitter.
426     MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
427                                        const MCRegisterInfo &MRI,
428                                        MCContext &Ctx) const {
429       if (!MCCodeEmitterCtorFn)
430         return nullptr;
431       return MCCodeEmitterCtorFn(II, MRI, Ctx);
432     }
433
434     /// Create a target specific MCStreamer.
435     ///
436     /// \param T The target triple.
437     /// \param Ctx The target context.
438     /// \param TAB The target assembler backend object. Takes ownership.
439     /// \param OS The stream object.
440     /// \param Emitter The target independent assembler object.Takes ownership.
441     /// \param RelaxAll Relax all fixups?
442     MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
443                                        MCAsmBackend &TAB, raw_pwrite_stream &OS,
444                                        MCCodeEmitter *Emitter,
445                                        const MCSubtargetInfo &STI,
446                                        bool RelaxAll,
447                                        bool DWARFMustBeAtTheEnd) const {
448       MCStreamer *S;
449       switch (T.getObjectFormat()) {
450       default:
451         llvm_unreachable("Unknown object format");
452       case Triple::COFF:
453         assert(T.isOSWindows() && "only Windows COFF is supported");
454         S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll);
455         break;
456       case Triple::MachO:
457         if (MachOStreamerCtorFn)
458           S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
459                                   DWARFMustBeAtTheEnd);
460         else
461           S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
462                                   DWARFMustBeAtTheEnd);
463         break;
464       case Triple::ELF:
465         if (ELFStreamerCtorFn)
466           S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
467         else
468           S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
469         break;
470       }
471       if (ObjectTargetStreamerCtorFn)
472         ObjectTargetStreamerCtorFn(*S, STI);
473       return S;
474     }
475
476     MCStreamer *createAsmStreamer(MCContext &Ctx,
477                                   std::unique_ptr<formatted_raw_ostream> OS,
478                                   bool IsVerboseAsm, bool UseDwarfDirectory,
479                                   MCInstPrinter *InstPrint, MCCodeEmitter *CE,
480                                   MCAsmBackend *TAB, bool ShowInst) const {
481       formatted_raw_ostream &OSRef = *OS;
482       MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
483                                               UseDwarfDirectory, InstPrint, CE,
484                                               TAB, ShowInst);
485       createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
486       return S;
487     }
488
489     MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
490                                               formatted_raw_ostream &OS,
491                                               MCInstPrinter *InstPrint,
492                                               bool IsVerboseAsm) const {
493       if (AsmTargetStreamerCtorFn)
494         return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
495       return nullptr;
496     }
497
498     MCStreamer *createNullStreamer(MCContext &Ctx) const {
499       MCStreamer *S = llvm::createNullStreamer(Ctx);
500       createNullTargetStreamer(*S);
501       return S;
502     }
503
504     MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
505       if (NullTargetStreamerCtorFn)
506         return NullTargetStreamerCtorFn(S);
507       return nullptr;
508     }
509
510     /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
511     ///
512     /// \param TT The target triple.
513     /// \param Ctx The target context.
514     MCRelocationInfo *
515       createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
516       MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
517                                       ? MCRelocationInfoCtorFn
518                                       : llvm::createMCRelocationInfo;
519       return Fn(TT, Ctx);
520     }
521
522     /// createMCSymbolizer - Create a target specific MCSymbolizer.
523     ///
524     /// \param TT The target triple.
525     /// \param GetOpInfo The function to get the symbolic information for operands.
526     /// \param SymbolLookUp The function to lookup a symbol name.
527     /// \param DisInfo The pointer to the block of symbolic information for above call
528     /// back.
529     /// \param Ctx The target context.
530     /// \param RelInfo The relocation information for this target. Takes ownership.
531     MCSymbolizer *
532     createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
533                        LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
534                        MCContext *Ctx,
535                        std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
536       MCSymbolizerCtorTy Fn =
537           MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
538       return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
539     }
540
541     /// @}
542   };
543
544   /// TargetRegistry - Generic interface to target specific features.
545   struct TargetRegistry {
546     // FIXME: Make this a namespace, probably just move all the Register*
547     // functions into Target (currently they all just set members on the Target
548     // anyway, and Target friends this class so those functions can...
549     // function).
550     TargetRegistry() = delete;
551
552     class iterator
553         : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
554       const Target *Current;
555       explicit iterator(Target *T) : Current(T) {}
556       friend struct TargetRegistry;
557     public:
558       iterator() : Current(nullptr) {}
559
560       bool operator==(const iterator &x) const {
561         return Current == x.Current;
562       }
563       bool operator!=(const iterator &x) const {
564         return !operator==(x);
565       }
566
567       // Iterator traversal: forward iteration only
568       iterator &operator++() {          // Preincrement
569         assert(Current && "Cannot increment end iterator!");
570         Current = Current->getNext();
571         return *this;
572       }
573       iterator operator++(int) {        // Postincrement
574         iterator tmp = *this;
575         ++*this;
576         return tmp;
577       }
578
579       const Target &operator*() const {
580         assert(Current && "Cannot dereference end iterator!");
581         return *Current;
582       }
583
584       const Target *operator->() const {
585         return &operator*();
586       }
587     };
588
589     /// printRegisteredTargetsForVersion - Print the registered targets
590     /// appropriately for inclusion in a tool's version output.
591     static void printRegisteredTargetsForVersion();
592
593     /// @name Registry Access
594     /// @{
595
596     static iterator_range<iterator> targets();
597
598     /// lookupTarget - Lookup a target based on a target triple.
599     ///
600     /// \param Triple - The triple to use for finding a target.
601     /// \param Error - On failure, an error string describing why no target was
602     /// found.
603     static const Target *lookupTarget(const std::string &Triple,
604                                       std::string &Error);
605
606     /// lookupTarget - Lookup a target based on an architecture name
607     /// and a target triple.  If the architecture name is non-empty,
608     /// then the lookup is done by architecture.  Otherwise, the target
609     /// triple is used.
610     ///
611     /// \param ArchName - The architecture to use for finding a target.
612     /// \param TheTriple - The triple to use for finding a target.  The
613     /// triple is updated with canonical architecture name if a lookup
614     /// by architecture is done.
615     /// \param Error - On failure, an error string describing why no target was
616     /// found.
617     static const Target *lookupTarget(const std::string &ArchName,
618                                       Triple &TheTriple,
619                                       std::string &Error);
620
621     /// @}
622     /// @name Target Registration
623     /// @{
624
625     /// RegisterTarget - Register the given target. Attempts to register a
626     /// target which has already been registered will be ignored.
627     ///
628     /// Clients are responsible for ensuring that registration doesn't occur
629     /// while another thread is attempting to access the registry. Typically
630     /// this is done by initializing all targets at program startup.
631     ///
632     /// @param T - The target being registered.
633     /// @param Name - The target name. This should be a static string.
634     /// @param ShortDesc - A short target description. This should be a static
635     /// string.
636     /// @param ArchMatchFn - The arch match checking function for this target.
637     /// @param HasJIT - Whether the target supports JIT code
638     /// generation.
639     static void RegisterTarget(Target &T,
640                                const char *Name,
641                                const char *ShortDesc,
642                                Target::ArchMatchFnTy ArchMatchFn,
643                                bool HasJIT = false);
644
645     /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
646     /// given target.
647     ///
648     /// Clients are responsible for ensuring that registration doesn't occur
649     /// while another thread is attempting to access the registry. Typically
650     /// this is done by initializing all targets at program startup.
651     ///
652     /// @param T - The target being registered.
653     /// @param Fn - A function to construct a MCAsmInfo for the target.
654     static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
655       T.MCAsmInfoCtorFn = Fn;
656     }
657
658     /// RegisterMCCodeGenInfo - Register a MCCodeGenInfo implementation for the
659     /// given target.
660     ///
661     /// Clients are responsible for ensuring that registration doesn't occur
662     /// while another thread is attempting to access the registry. Typically
663     /// this is done by initializing all targets at program startup.
664     ///
665     /// @param T - The target being registered.
666     /// @param Fn - A function to construct a MCCodeGenInfo for the target.
667     static void RegisterMCCodeGenInfo(Target &T,
668                                      Target::MCCodeGenInfoCtorFnTy Fn) {
669       T.MCCodeGenInfoCtorFn = Fn;
670     }
671
672     /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
673     /// given target.
674     ///
675     /// Clients are responsible for ensuring that registration doesn't occur
676     /// while another thread is attempting to access the registry. Typically
677     /// this is done by initializing all targets at program startup.
678     ///
679     /// @param T - The target being registered.
680     /// @param Fn - A function to construct a MCInstrInfo for the target.
681     static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
682       T.MCInstrInfoCtorFn = Fn;
683     }
684
685     /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
686     /// the given target.
687     static void RegisterMCInstrAnalysis(Target &T,
688                                         Target::MCInstrAnalysisCtorFnTy Fn) {
689       T.MCInstrAnalysisCtorFn = Fn;
690     }
691
692     /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
693     /// given target.
694     ///
695     /// Clients are responsible for ensuring that registration doesn't occur
696     /// while another thread is attempting to access the registry. Typically
697     /// this is done by initializing all targets at program startup.
698     ///
699     /// @param T - The target being registered.
700     /// @param Fn - A function to construct a MCRegisterInfo for the target.
701     static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
702       T.MCRegInfoCtorFn = Fn;
703     }
704
705     /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
706     /// the given target.
707     ///
708     /// Clients are responsible for ensuring that registration doesn't occur
709     /// while another thread is attempting to access the registry. Typically
710     /// this is done by initializing all targets at program startup.
711     ///
712     /// @param T - The target being registered.
713     /// @param Fn - A function to construct a MCSubtargetInfo for the target.
714     static void RegisterMCSubtargetInfo(Target &T,
715                                         Target::MCSubtargetInfoCtorFnTy Fn) {
716       T.MCSubtargetInfoCtorFn = Fn;
717     }
718
719     /// RegisterTargetMachine - Register a TargetMachine implementation for the
720     /// given target.
721     ///
722     /// Clients are responsible for ensuring that registration doesn't occur
723     /// while another thread is attempting to access the registry. Typically
724     /// this is done by initializing all targets at program startup.
725     ///
726     /// @param T - The target being registered.
727     /// @param Fn - A function to construct a TargetMachine for the target.
728     static void RegisterTargetMachine(Target &T,
729                                       Target::TargetMachineCtorTy Fn) {
730       T.TargetMachineCtorFn = Fn;
731     }
732
733     /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
734     /// given target.
735     ///
736     /// Clients are responsible for ensuring that registration doesn't occur
737     /// while another thread is attempting to access the registry. Typically
738     /// this is done by initializing all targets at program startup.
739     ///
740     /// @param T - The target being registered.
741     /// @param Fn - A function to construct an AsmBackend for the target.
742     static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
743       T.MCAsmBackendCtorFn = Fn;
744     }
745
746     /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
747     /// the given target.
748     ///
749     /// Clients are responsible for ensuring that registration doesn't occur
750     /// while another thread is attempting to access the registry. Typically
751     /// this is done by initializing all targets at program startup.
752     ///
753     /// @param T - The target being registered.
754     /// @param Fn - A function to construct an MCTargetAsmParser for the target.
755     static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
756       T.MCAsmParserCtorFn = Fn;
757     }
758
759     /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
760     /// target.
761     ///
762     /// Clients are responsible for ensuring that registration doesn't occur
763     /// while another thread is attempting to access the registry. Typically
764     /// this is done by initializing all targets at program startup.
765     ///
766     /// @param T - The target being registered.
767     /// @param Fn - A function to construct an AsmPrinter for the target.
768     static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
769       T.AsmPrinterCtorFn = Fn;
770     }
771
772     /// RegisterMCDisassembler - Register a MCDisassembler implementation for
773     /// the given target.
774     ///
775     /// Clients are responsible for ensuring that registration doesn't occur
776     /// while another thread is attempting to access the registry. Typically
777     /// this is done by initializing all targets at program startup.
778     ///
779     /// @param T - The target being registered.
780     /// @param Fn - A function to construct an MCDisassembler for the target.
781     static void RegisterMCDisassembler(Target &T,
782                                        Target::MCDisassemblerCtorTy Fn) {
783       T.MCDisassemblerCtorFn = Fn;
784     }
785
786     /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
787     /// given target.
788     ///
789     /// Clients are responsible for ensuring that registration doesn't occur
790     /// while another thread is attempting to access the registry. Typically
791     /// this is done by initializing all targets at program startup.
792     ///
793     /// @param T - The target being registered.
794     /// @param Fn - A function to construct an MCInstPrinter for the target.
795     static void RegisterMCInstPrinter(Target &T,
796                                       Target::MCInstPrinterCtorTy Fn) {
797       T.MCInstPrinterCtorFn = Fn;
798     }
799
800     /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
801     /// given target.
802     ///
803     /// Clients are responsible for ensuring that registration doesn't occur
804     /// while another thread is attempting to access the registry. Typically
805     /// this is done by initializing all targets at program startup.
806     ///
807     /// @param T - The target being registered.
808     /// @param Fn - A function to construct an MCCodeEmitter for the target.
809     static void RegisterMCCodeEmitter(Target &T,
810                                       Target::MCCodeEmitterCtorTy Fn) {
811       T.MCCodeEmitterCtorFn = Fn;
812     }
813
814     static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
815       T.COFFStreamerCtorFn = Fn;
816     }
817
818     static void RegisterMachOStreamer(Target &T,
819                                       Target::MachOStreamerCtorTy Fn) {
820       T.MachOStreamerCtorFn = Fn;
821     }
822
823     static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
824       T.ELFStreamerCtorFn = Fn;
825     }
826
827     static void
828     RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) {
829       T.NullTargetStreamerCtorFn = Fn;
830     }
831
832     static void RegisterAsmTargetStreamer(Target &T,
833                                           Target::AsmTargetStreamerCtorTy Fn) {
834       T.AsmTargetStreamerCtorFn = Fn;
835     }
836
837     static void
838     RegisterObjectTargetStreamer(Target &T,
839                                  Target::ObjectTargetStreamerCtorTy Fn) {
840       T.ObjectTargetStreamerCtorFn = Fn;
841     }
842
843     /// RegisterMCRelocationInfo - Register an MCRelocationInfo
844     /// implementation for the given target.
845     ///
846     /// Clients are responsible for ensuring that registration doesn't occur
847     /// while another thread is attempting to access the registry. Typically
848     /// this is done by initializing all targets at program startup.
849     ///
850     /// @param T - The target being registered.
851     /// @param Fn - A function to construct an MCRelocationInfo for the target.
852     static void RegisterMCRelocationInfo(Target &T,
853                                          Target::MCRelocationInfoCtorTy Fn) {
854       T.MCRelocationInfoCtorFn = Fn;
855     }
856
857     /// RegisterMCSymbolizer - Register an MCSymbolizer
858     /// implementation for the given target.
859     ///
860     /// Clients are responsible for ensuring that registration doesn't occur
861     /// while another thread is attempting to access the registry. Typically
862     /// this is done by initializing all targets at program startup.
863     ///
864     /// @param T - The target being registered.
865     /// @param Fn - A function to construct an MCSymbolizer for the target.
866     static void RegisterMCSymbolizer(Target &T,
867                                      Target::MCSymbolizerCtorTy Fn) {
868       T.MCSymbolizerCtorFn = Fn;
869     }
870
871     /// @}
872   };
873
874
875   //===--------------------------------------------------------------------===//
876
877   /// RegisterTarget - Helper template for registering a target, for use in the
878   /// target's initialization function. Usage:
879   ///
880   ///
881   /// Target TheFooTarget; // The global target instance.
882   ///
883   /// extern "C" void LLVMInitializeFooTargetInfo() {
884   ///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
885   /// }
886   template<Triple::ArchType TargetArchType = Triple::UnknownArch,
887            bool HasJIT = false>
888   struct RegisterTarget {
889     RegisterTarget(Target &T, const char *Name, const char *Desc) {
890       TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
891     }
892
893     static bool getArchMatch(Triple::ArchType Arch) {
894       return Arch == TargetArchType;
895     }
896   };
897
898   /// RegisterMCAsmInfo - Helper template for registering a target assembly info
899   /// implementation.  This invokes the static "Create" method on the class to
900   /// actually do the construction.  Usage:
901   ///
902   /// extern "C" void LLVMInitializeFooTarget() {
903   ///   extern Target TheFooTarget;
904   ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
905   /// }
906   template<class MCAsmInfoImpl>
907   struct RegisterMCAsmInfo {
908     RegisterMCAsmInfo(Target &T) {
909       TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
910     }
911   private:
912     static MCAsmInfo *Allocator(const MCRegisterInfo &/*MRI*/, StringRef TT) {
913       return new MCAsmInfoImpl(TT);
914     }
915
916   };
917
918   /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
919   /// implementation.  This invokes the specified function to do the
920   /// construction.  Usage:
921   ///
922   /// extern "C" void LLVMInitializeFooTarget() {
923   ///   extern Target TheFooTarget;
924   ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
925   /// }
926   struct RegisterMCAsmInfoFn {
927     RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
928       TargetRegistry::RegisterMCAsmInfo(T, Fn);
929     }
930   };
931
932   /// RegisterMCCodeGenInfo - Helper template for registering a target codegen info
933   /// implementation.  This invokes the static "Create" method on the class
934   /// to actually do the construction.  Usage:
935   ///
936   /// extern "C" void LLVMInitializeFooTarget() {
937   ///   extern Target TheFooTarget;
938   ///   RegisterMCCodeGenInfo<FooMCCodeGenInfo> X(TheFooTarget);
939   /// }
940   template<class MCCodeGenInfoImpl>
941   struct RegisterMCCodeGenInfo {
942     RegisterMCCodeGenInfo(Target &T) {
943       TargetRegistry::RegisterMCCodeGenInfo(T, &Allocator);
944     }
945   private:
946     static MCCodeGenInfo *Allocator(StringRef /*TT*/, Reloc::Model /*RM*/,
947                                     CodeModel::Model /*CM*/,
948                                     CodeGenOpt::Level /*OL*/) {
949       return new MCCodeGenInfoImpl();
950     }
951   };
952
953   /// RegisterMCCodeGenInfoFn - Helper template for registering a target codegen
954   /// info implementation.  This invokes the specified function to do the
955   /// construction.  Usage:
956   ///
957   /// extern "C" void LLVMInitializeFooTarget() {
958   ///   extern Target TheFooTarget;
959   ///   RegisterMCCodeGenInfoFn X(TheFooTarget, TheFunction);
960   /// }
961   struct RegisterMCCodeGenInfoFn {
962     RegisterMCCodeGenInfoFn(Target &T, Target::MCCodeGenInfoCtorFnTy Fn) {
963       TargetRegistry::RegisterMCCodeGenInfo(T, Fn);
964     }
965   };
966
967   /// RegisterMCInstrInfo - Helper template for registering a target instruction
968   /// info implementation.  This invokes the static "Create" method on the class
969   /// to actually do the construction.  Usage:
970   ///
971   /// extern "C" void LLVMInitializeFooTarget() {
972   ///   extern Target TheFooTarget;
973   ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
974   /// }
975   template<class MCInstrInfoImpl>
976   struct RegisterMCInstrInfo {
977     RegisterMCInstrInfo(Target &T) {
978       TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
979     }
980   private:
981     static MCInstrInfo *Allocator() {
982       return new MCInstrInfoImpl();
983     }
984   };
985
986   /// RegisterMCInstrInfoFn - Helper template for registering a target
987   /// instruction info implementation.  This invokes the specified function to
988   /// do the construction.  Usage:
989   ///
990   /// extern "C" void LLVMInitializeFooTarget() {
991   ///   extern Target TheFooTarget;
992   ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
993   /// }
994   struct RegisterMCInstrInfoFn {
995     RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
996       TargetRegistry::RegisterMCInstrInfo(T, Fn);
997     }
998   };
999
1000   /// RegisterMCInstrAnalysis - Helper template for registering a target
1001   /// instruction analyzer implementation.  This invokes the static "Create"
1002   /// method on the class to actually do the construction.  Usage:
1003   ///
1004   /// extern "C" void LLVMInitializeFooTarget() {
1005   ///   extern Target TheFooTarget;
1006   ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1007   /// }
1008   template<class MCInstrAnalysisImpl>
1009   struct RegisterMCInstrAnalysis {
1010     RegisterMCInstrAnalysis(Target &T) {
1011       TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
1012     }
1013   private:
1014     static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1015       return new MCInstrAnalysisImpl(Info);
1016     }
1017   };
1018
1019   /// RegisterMCInstrAnalysisFn - Helper template for registering a target
1020   /// instruction analyzer implementation.  This invokes the specified function
1021   /// to do the construction.  Usage:
1022   ///
1023   /// extern "C" void LLVMInitializeFooTarget() {
1024   ///   extern Target TheFooTarget;
1025   ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1026   /// }
1027   struct RegisterMCInstrAnalysisFn {
1028     RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
1029       TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
1030     }
1031   };
1032
1033   /// RegisterMCRegInfo - Helper template for registering a target register info
1034   /// implementation.  This invokes the static "Create" method on the class to
1035   /// actually do the construction.  Usage:
1036   ///
1037   /// extern "C" void LLVMInitializeFooTarget() {
1038   ///   extern Target TheFooTarget;
1039   ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1040   /// }
1041   template<class MCRegisterInfoImpl>
1042   struct RegisterMCRegInfo {
1043     RegisterMCRegInfo(Target &T) {
1044       TargetRegistry::RegisterMCRegInfo(T, &Allocator);
1045     }
1046   private:
1047     static MCRegisterInfo *Allocator(StringRef /*TT*/) {
1048       return new MCRegisterInfoImpl();
1049     }
1050   };
1051
1052   /// RegisterMCRegInfoFn - Helper template for registering a target register
1053   /// info implementation.  This invokes the specified function to do the
1054   /// construction.  Usage:
1055   ///
1056   /// extern "C" void LLVMInitializeFooTarget() {
1057   ///   extern Target TheFooTarget;
1058   ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1059   /// }
1060   struct RegisterMCRegInfoFn {
1061     RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1062       TargetRegistry::RegisterMCRegInfo(T, Fn);
1063     }
1064   };
1065
1066   /// RegisterMCSubtargetInfo - Helper template for registering a target
1067   /// subtarget info implementation.  This invokes the static "Create" method
1068   /// on the class to actually do the construction.  Usage:
1069   ///
1070   /// extern "C" void LLVMInitializeFooTarget() {
1071   ///   extern Target TheFooTarget;
1072   ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1073   /// }
1074   template<class MCSubtargetInfoImpl>
1075   struct RegisterMCSubtargetInfo {
1076     RegisterMCSubtargetInfo(Target &T) {
1077       TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1078     }
1079   private:
1080     static MCSubtargetInfo *Allocator(StringRef /*TT*/, StringRef /*CPU*/,
1081                                       StringRef /*FS*/) {
1082       return new MCSubtargetInfoImpl();
1083     }
1084   };
1085
1086   /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1087   /// subtarget info implementation.  This invokes the specified function to
1088   /// do the construction.  Usage:
1089   ///
1090   /// extern "C" void LLVMInitializeFooTarget() {
1091   ///   extern Target TheFooTarget;
1092   ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1093   /// }
1094   struct RegisterMCSubtargetInfoFn {
1095     RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1096       TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1097     }
1098   };
1099
1100   /// RegisterTargetMachine - Helper template for registering a target machine
1101   /// implementation, for use in the target machine initialization
1102   /// function. Usage:
1103   ///
1104   /// extern "C" void LLVMInitializeFooTarget() {
1105   ///   extern Target TheFooTarget;
1106   ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1107   /// }
1108   template<class TargetMachineImpl>
1109   struct RegisterTargetMachine {
1110     RegisterTargetMachine(Target &T) {
1111       TargetRegistry::RegisterTargetMachine(T, &Allocator);
1112     }
1113
1114   private:
1115     static TargetMachine *Allocator(const Target &T, StringRef TT,
1116                                     StringRef CPU, StringRef FS,
1117                                     const TargetOptions &Options,
1118                                     Reloc::Model RM,
1119                                     CodeModel::Model CM,
1120                                     CodeGenOpt::Level OL) {
1121       return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1122     }
1123   };
1124
1125   /// RegisterMCAsmBackend - Helper template for registering a target specific
1126   /// assembler backend. Usage:
1127   ///
1128   /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1129   ///   extern Target TheFooTarget;
1130   ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1131   /// }
1132   template<class MCAsmBackendImpl>
1133   struct RegisterMCAsmBackend {
1134     RegisterMCAsmBackend(Target &T) {
1135       TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1136     }
1137
1138   private:
1139     static MCAsmBackend *Allocator(const Target &T,
1140                                    const MCRegisterInfo &MRI,
1141                                    StringRef Triple, StringRef CPU) {
1142       return new MCAsmBackendImpl(T, MRI, Triple, CPU);
1143     }
1144   };
1145
1146   /// RegisterMCAsmParser - Helper template for registering a target specific
1147   /// assembly parser, for use in the target machine initialization
1148   /// function. Usage:
1149   ///
1150   /// extern "C" void LLVMInitializeFooMCAsmParser() {
1151   ///   extern Target TheFooTarget;
1152   ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1153   /// }
1154   template<class MCAsmParserImpl>
1155   struct RegisterMCAsmParser {
1156     RegisterMCAsmParser(Target &T) {
1157       TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1158     }
1159
1160   private:
1161     static MCTargetAsmParser *Allocator(MCSubtargetInfo &STI, MCAsmParser &P,
1162                                         const MCInstrInfo &MII,
1163                                         const MCTargetOptions &Options) {
1164       return new MCAsmParserImpl(STI, P, MII, Options);
1165     }
1166   };
1167
1168   /// RegisterAsmPrinter - Helper template for registering a target specific
1169   /// assembly printer, for use in the target machine initialization
1170   /// function. Usage:
1171   ///
1172   /// extern "C" void LLVMInitializeFooAsmPrinter() {
1173   ///   extern Target TheFooTarget;
1174   ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1175   /// }
1176   template<class AsmPrinterImpl>
1177   struct RegisterAsmPrinter {
1178     RegisterAsmPrinter(Target &T) {
1179       TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1180     }
1181
1182   private:
1183     static AsmPrinter *Allocator(TargetMachine &TM,
1184                                  std::unique_ptr<MCStreamer> &&Streamer) {
1185       return new AsmPrinterImpl(TM, std::move(Streamer));
1186     }
1187   };
1188
1189   /// RegisterMCCodeEmitter - Helper template for registering a target specific
1190   /// machine code emitter, for use in the target initialization
1191   /// function. Usage:
1192   ///
1193   /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1194   ///   extern Target TheFooTarget;
1195   ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1196   /// }
1197   template<class MCCodeEmitterImpl>
1198   struct RegisterMCCodeEmitter {
1199     RegisterMCCodeEmitter(Target &T) {
1200       TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1201     }
1202
1203   private:
1204     static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1205                                     const MCRegisterInfo & /*MRI*/,
1206                                     MCContext & /*Ctx*/) {
1207       return new MCCodeEmitterImpl();
1208     }
1209   };
1210
1211 }
1212
1213 #endif