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