]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Support/TargetRegistry.h
Update lldb to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / 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/Optional.h"
24 #include "llvm/ADT/Triple.h"
25 #include "llvm/Support/CodeGen.h"
26 #include "llvm/Support/FormattedStream.h"
27 #include <cassert>
28 #include <memory>
29 #include <string>
30
31 namespace llvm {
32 class AsmPrinter;
33 class MCAsmBackend;
34 class MCAsmInfo;
35 class MCAsmParser;
36 class MCCodeEmitter;
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(const Triple &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 void (*MCAdjustCodeGenOptsFnTy)(const Triple &TT, Reloc::Model RM,
96                                           CodeModel::Model &CM);
97
98   typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
99   typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
100   typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
101   typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
102                                                       StringRef CPU,
103                                                       StringRef Features);
104   typedef TargetMachine *(*TargetMachineCtorTy)(
105       const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
106       const TargetOptions &Options, Optional<Reloc::Model> RM,
107       CodeModel::Model CM, 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                                               const MCTargetOptions &Options);
117   typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
118       const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
119       const MCTargetOptions &Options);
120   typedef MCDisassembler *(*MCDisassemblerCtorTy)(const Target &T,
121                                                   const MCSubtargetInfo &STI,
122                                                   MCContext &Ctx);
123   typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Triple &T,
124                                                 unsigned SyntaxVariant,
125                                                 const MCAsmInfo &MAI,
126                                                 const MCInstrInfo &MII,
127                                                 const MCRegisterInfo &MRI);
128   typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
129                                                 const MCRegisterInfo &MRI,
130                                                 MCContext &Ctx);
131   typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
132                                            MCAsmBackend &TAB,
133                                            raw_pwrite_stream &OS,
134                                            MCCodeEmitter *Emitter,
135                                            bool RelaxAll);
136   typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
137                                              raw_pwrite_stream &OS,
138                                              MCCodeEmitter *Emitter,
139                                              bool RelaxAll,
140                                              bool DWARFMustBeAtTheEnd);
141   typedef MCStreamer *(*COFFStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
142                                             raw_pwrite_stream &OS,
143                                             MCCodeEmitter *Emitter,
144                                             bool RelaxAll,
145                                             bool IncrementalLinkerCompatible);
146   typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
147   typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
148       MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint,
149       bool IsVerboseAsm);
150   typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
151       MCStreamer &S, const MCSubtargetInfo &STI);
152   typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
153                                                       MCContext &Ctx);
154   typedef MCSymbolizer *(*MCSymbolizerCtorTy)(
155       const Triple &TT, LLVMOpInfoCallback GetOpInfo,
156       LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx,
157       std::unique_ptr<MCRelocationInfo> &&RelInfo);
158
159 private:
160   /// Next - The next registered target in the linked list, maintained by the
161   /// TargetRegistry.
162   Target *Next;
163
164   /// The target function for checking if an architecture is supported.
165   ArchMatchFnTy ArchMatchFn;
166
167   /// Name - The target name.
168   const char *Name;
169
170   /// ShortDesc - A short description of the target.
171   const char *ShortDesc;
172
173   /// HasJIT - Whether this target supports the JIT.
174   bool HasJIT;
175
176   /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
177   /// registered.
178   MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
179
180   MCAdjustCodeGenOptsFnTy MCAdjustCodeGenOptsFn;
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   /// hasMCAsmParser - Check if this target supports assembly parsing.
284   bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
285
286   /// @}
287   /// @name Feature Constructors
288   /// @{
289
290   /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
291   /// target triple.
292   ///
293   /// \param TheTriple This argument is used to determine the target machine
294   /// feature set; it should always be provided. Generally this should be
295   /// either the target triple from the module, or the target triple of the
296   /// host if that does not exist.
297   MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
298                              StringRef TheTriple) const {
299     if (!MCAsmInfoCtorFn)
300       return nullptr;
301     return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
302   }
303
304   void adjustCodeGenOpts(const Triple &TT, Reloc::Model RM,
305                          CodeModel::Model &CM) const {
306     if (MCAdjustCodeGenOptsFn)
307       MCAdjustCodeGenOptsFn(TT, RM, CM);
308   }
309
310   /// createMCInstrInfo - Create a MCInstrInfo implementation.
311   ///
312   MCInstrInfo *createMCInstrInfo() const {
313     if (!MCInstrInfoCtorFn)
314       return nullptr;
315     return MCInstrInfoCtorFn();
316   }
317
318   /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
319   ///
320   MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
321     if (!MCInstrAnalysisCtorFn)
322       return nullptr;
323     return MCInstrAnalysisCtorFn(Info);
324   }
325
326   /// createMCRegInfo - Create a MCRegisterInfo implementation.
327   ///
328   MCRegisterInfo *createMCRegInfo(StringRef TT) const {
329     if (!MCRegInfoCtorFn)
330       return nullptr;
331     return MCRegInfoCtorFn(Triple(TT));
332   }
333
334   /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
335   ///
336   /// \param TheTriple This argument is used to determine the target machine
337   /// feature set; it should always be provided. Generally this should be
338   /// either the target triple from the module, or the target triple of the
339   /// host if that does not exist.
340   /// \param CPU This specifies the name of the target CPU.
341   /// \param Features This specifies the string representation of the
342   /// additional target features.
343   MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
344                                          StringRef Features) const {
345     if (!MCSubtargetInfoCtorFn)
346       return nullptr;
347     return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
348   }
349
350   /// createTargetMachine - Create a target specific machine implementation
351   /// for the specified \p Triple.
352   ///
353   /// \param TT This argument is used to determine the target machine
354   /// feature set; it should always be provided. Generally this should be
355   /// either the target triple from the module, or the target triple of the
356   /// host if that does not exist.
357   TargetMachine *
358   createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
359                       const TargetOptions &Options, Optional<Reloc::Model> RM,
360                       CodeModel::Model CM = CodeModel::Default,
361                       CodeGenOpt::Level OL = CodeGenOpt::Default) const {
362     if (!TargetMachineCtorFn)
363       return nullptr;
364     return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options, RM,
365                                CM, OL);
366   }
367
368   /// createMCAsmBackend - Create a target specific assembly parser.
369   ///
370   /// \param TheTriple The target triple string.
371   MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
372                                    StringRef TheTriple, StringRef CPU,
373                                    const MCTargetOptions &Options)
374                                    const {
375     if (!MCAsmBackendCtorFn)
376       return nullptr;
377     return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU, Options);
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(const 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 IncrementalLinkerCompatible,
440                                      bool DWARFMustBeAtTheEnd) const {
441     MCStreamer *S;
442     switch (T.getObjectFormat()) {
443     default:
444       llvm_unreachable("Unknown object format");
445     case Triple::COFF:
446       assert(T.isOSWindows() && "only Windows COFF is supported");
447       S = COFFStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
448                              IncrementalLinkerCompatible);
449       break;
450     case Triple::MachO:
451       if (MachOStreamerCtorFn)
452         S = MachOStreamerCtorFn(Ctx, TAB, OS, Emitter, RelaxAll,
453                                 DWARFMustBeAtTheEnd);
454       else
455         S = createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll,
456                                 DWARFMustBeAtTheEnd);
457       break;
458     case Triple::ELF:
459       if (ELFStreamerCtorFn)
460         S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
461       else
462         S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
463       break;
464     }
465     if (ObjectTargetStreamerCtorFn)
466       ObjectTargetStreamerCtorFn(*S, STI);
467     return S;
468   }
469
470   MCStreamer *createAsmStreamer(MCContext &Ctx,
471                                 std::unique_ptr<formatted_raw_ostream> OS,
472                                 bool IsVerboseAsm, bool UseDwarfDirectory,
473                                 MCInstPrinter *InstPrint, MCCodeEmitter *CE,
474                                 MCAsmBackend *TAB, bool ShowInst) const {
475     formatted_raw_ostream &OSRef = *OS;
476     MCStreamer *S = llvm::createAsmStreamer(Ctx, std::move(OS), IsVerboseAsm,
477                                             UseDwarfDirectory, InstPrint, CE,
478                                             TAB, ShowInst);
479     createAsmTargetStreamer(*S, OSRef, InstPrint, IsVerboseAsm);
480     return S;
481   }
482
483   MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
484                                             formatted_raw_ostream &OS,
485                                             MCInstPrinter *InstPrint,
486                                             bool IsVerboseAsm) const {
487     if (AsmTargetStreamerCtorFn)
488       return AsmTargetStreamerCtorFn(S, OS, InstPrint, IsVerboseAsm);
489     return nullptr;
490   }
491
492   MCStreamer *createNullStreamer(MCContext &Ctx) const {
493     MCStreamer *S = llvm::createNullStreamer(Ctx);
494     createNullTargetStreamer(*S);
495     return S;
496   }
497
498   MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const {
499     if (NullTargetStreamerCtorFn)
500       return NullTargetStreamerCtorFn(S);
501     return nullptr;
502   }
503
504   /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
505   ///
506   /// \param TT The target triple.
507   /// \param Ctx The target context.
508   MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
509     MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
510                                     ? MCRelocationInfoCtorFn
511                                     : llvm::createMCRelocationInfo;
512     return Fn(Triple(TT), Ctx);
513   }
514
515   /// createMCSymbolizer - Create a target specific MCSymbolizer.
516   ///
517   /// \param TT The target triple.
518   /// \param GetOpInfo The function to get the symbolic information for
519   /// operands.
520   /// \param SymbolLookUp The function to lookup a symbol name.
521   /// \param DisInfo The pointer to the block of symbolic information for above
522   /// call
523   /// back.
524   /// \param Ctx The target context.
525   /// \param RelInfo The relocation information for this target. Takes
526   /// ownership.
527   MCSymbolizer *
528   createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo,
529                      LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
530                      MCContext *Ctx,
531                      std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
532     MCSymbolizerCtorTy Fn =
533         MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
534     return Fn(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
535               std::move(RelInfo));
536   }
537
538   /// @}
539 };
540
541 /// TargetRegistry - Generic interface to target specific features.
542 struct TargetRegistry {
543   // FIXME: Make this a namespace, probably just move all the Register*
544   // functions into Target (currently they all just set members on the Target
545   // anyway, and Target friends this class so those functions can...
546   // function).
547   TargetRegistry() = delete;
548
549   class iterator
550       : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
551     const Target *Current;
552     explicit iterator(Target *T) : Current(T) {}
553     friend struct TargetRegistry;
554
555   public:
556     iterator() : Current(nullptr) {}
557
558     bool operator==(const iterator &x) const { return Current == x.Current; }
559     bool operator!=(const iterator &x) const { return !operator==(x); }
560
561     // Iterator traversal: forward iteration only
562     iterator &operator++() { // Preincrement
563       assert(Current && "Cannot increment end iterator!");
564       Current = Current->getNext();
565       return *this;
566     }
567     iterator operator++(int) { // Postincrement
568       iterator tmp = *this;
569       ++*this;
570       return tmp;
571     }
572
573     const Target &operator*() const {
574       assert(Current && "Cannot dereference end iterator!");
575       return *Current;
576     }
577
578     const Target *operator->() const { return &operator*(); }
579   };
580
581   /// printRegisteredTargetsForVersion - Print the registered targets
582   /// appropriately for inclusion in a tool's version output.
583   static void printRegisteredTargetsForVersion();
584
585   /// @name Registry Access
586   /// @{
587
588   static iterator_range<iterator> targets();
589
590   /// lookupTarget - Lookup a target based on a target triple.
591   ///
592   /// \param Triple - The triple to use for finding a target.
593   /// \param Error - On failure, an error string describing why no target was
594   /// found.
595   static const Target *lookupTarget(const std::string &Triple,
596                                     std::string &Error);
597
598   /// lookupTarget - Lookup a target based on an architecture name
599   /// and a target triple.  If the architecture name is non-empty,
600   /// then the lookup is done by architecture.  Otherwise, the target
601   /// triple is used.
602   ///
603   /// \param ArchName - The architecture to use for finding a target.
604   /// \param TheTriple - The triple to use for finding a target.  The
605   /// triple is updated with canonical architecture name if a lookup
606   /// by architecture is done.
607   /// \param Error - On failure, an error string describing why no target was
608   /// found.
609   static const Target *lookupTarget(const std::string &ArchName,
610                                     Triple &TheTriple, std::string &Error);
611
612   /// @}
613   /// @name Target Registration
614   /// @{
615
616   /// RegisterTarget - Register the given target. Attempts to register a
617   /// target which has already been registered will be ignored.
618   ///
619   /// Clients are responsible for ensuring that registration doesn't occur
620   /// while another thread is attempting to access the registry. Typically
621   /// this is done by initializing all targets at program startup.
622   ///
623   /// @param T - The target being registered.
624   /// @param Name - The target name. This should be a static string.
625   /// @param ShortDesc - A short target description. This should be a static
626   /// string.
627   /// @param ArchMatchFn - The arch match checking function for this target.
628   /// @param HasJIT - Whether the target supports JIT code
629   /// generation.
630   static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
631                              Target::ArchMatchFnTy ArchMatchFn,
632                              bool HasJIT = false);
633
634   /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
635   /// given target.
636   ///
637   /// Clients are responsible for ensuring that registration doesn't occur
638   /// while another thread is attempting to access the registry. Typically
639   /// this is done by initializing all targets at program startup.
640   ///
641   /// @param T - The target being registered.
642   /// @param Fn - A function to construct a MCAsmInfo for the target.
643   static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
644     T.MCAsmInfoCtorFn = Fn;
645   }
646
647   static void registerMCAdjustCodeGenOpts(Target &T,
648                                           Target::MCAdjustCodeGenOptsFnTy Fn) {
649     T.MCAdjustCodeGenOptsFn = Fn;
650   }
651
652   /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
653   /// given target.
654   ///
655   /// Clients are responsible for ensuring that registration doesn't occur
656   /// while another thread is attempting to access the registry. Typically
657   /// this is done by initializing all targets at program startup.
658   ///
659   /// @param T - The target being registered.
660   /// @param Fn - A function to construct a MCInstrInfo for the target.
661   static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
662     T.MCInstrInfoCtorFn = Fn;
663   }
664
665   /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
666   /// the given target.
667   static void RegisterMCInstrAnalysis(Target &T,
668                                       Target::MCInstrAnalysisCtorFnTy Fn) {
669     T.MCInstrAnalysisCtorFn = Fn;
670   }
671
672   /// RegisterMCRegInfo - Register a MCRegisterInfo 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 MCRegisterInfo for the target.
681   static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
682     T.MCRegInfoCtorFn = Fn;
683   }
684
685   /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
686   /// the given target.
687   ///
688   /// Clients are responsible for ensuring that registration doesn't occur
689   /// while another thread is attempting to access the registry. Typically
690   /// this is done by initializing all targets at program startup.
691   ///
692   /// @param T - The target being registered.
693   /// @param Fn - A function to construct a MCSubtargetInfo for the target.
694   static void RegisterMCSubtargetInfo(Target &T,
695                                       Target::MCSubtargetInfoCtorFnTy Fn) {
696     T.MCSubtargetInfoCtorFn = Fn;
697   }
698
699   /// RegisterTargetMachine - Register a TargetMachine implementation for the
700   /// given target.
701   ///
702   /// Clients are responsible for ensuring that registration doesn't occur
703   /// while another thread is attempting to access the registry. Typically
704   /// this is done by initializing all targets at program startup.
705   ///
706   /// @param T - The target being registered.
707   /// @param Fn - A function to construct a TargetMachine for the target.
708   static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
709     T.TargetMachineCtorFn = Fn;
710   }
711
712   /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
713   /// given target.
714   ///
715   /// Clients are responsible for ensuring that registration doesn't occur
716   /// while another thread is attempting to access the registry. Typically
717   /// this is done by initializing all targets at program startup.
718   ///
719   /// @param T - The target being registered.
720   /// @param Fn - A function to construct an AsmBackend for the target.
721   static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
722     T.MCAsmBackendCtorFn = Fn;
723   }
724
725   /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
726   /// the given target.
727   ///
728   /// Clients are responsible for ensuring that registration doesn't occur
729   /// while another thread is attempting to access the registry. Typically
730   /// this is done by initializing all targets at program startup.
731   ///
732   /// @param T - The target being registered.
733   /// @param Fn - A function to construct an MCTargetAsmParser for the target.
734   static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
735     T.MCAsmParserCtorFn = Fn;
736   }
737
738   /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
739   /// target.
740   ///
741   /// Clients are responsible for ensuring that registration doesn't occur
742   /// while another thread is attempting to access the registry. Typically
743   /// this is done by initializing all targets at program startup.
744   ///
745   /// @param T - The target being registered.
746   /// @param Fn - A function to construct an AsmPrinter for the target.
747   static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
748     T.AsmPrinterCtorFn = Fn;
749   }
750
751   /// RegisterMCDisassembler - Register a MCDisassembler implementation for
752   /// the given target.
753   ///
754   /// Clients are responsible for ensuring that registration doesn't occur
755   /// while another thread is attempting to access the registry. Typically
756   /// this is done by initializing all targets at program startup.
757   ///
758   /// @param T - The target being registered.
759   /// @param Fn - A function to construct an MCDisassembler for the target.
760   static void RegisterMCDisassembler(Target &T,
761                                      Target::MCDisassemblerCtorTy Fn) {
762     T.MCDisassemblerCtorFn = Fn;
763   }
764
765   /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
766   /// given target.
767   ///
768   /// Clients are responsible for ensuring that registration doesn't occur
769   /// while another thread is attempting to access the registry. Typically
770   /// this is done by initializing all targets at program startup.
771   ///
772   /// @param T - The target being registered.
773   /// @param Fn - A function to construct an MCInstPrinter for the target.
774   static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn) {
775     T.MCInstPrinterCtorFn = Fn;
776   }
777
778   /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
779   /// given target.
780   ///
781   /// Clients are responsible for ensuring that registration doesn't occur
782   /// while another thread is attempting to access the registry. Typically
783   /// this is done by initializing all targets at program startup.
784   ///
785   /// @param T - The target being registered.
786   /// @param Fn - A function to construct an MCCodeEmitter for the target.
787   static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
788     T.MCCodeEmitterCtorFn = Fn;
789   }
790
791   static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn) {
792     T.COFFStreamerCtorFn = Fn;
793   }
794
795   static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn) {
796     T.MachOStreamerCtorFn = Fn;
797   }
798
799   static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
800     T.ELFStreamerCtorFn = Fn;
801   }
802
803   static void RegisterNullTargetStreamer(Target &T,
804                                          Target::NullTargetStreamerCtorTy Fn) {
805     T.NullTargetStreamerCtorFn = Fn;
806   }
807
808   static void RegisterAsmTargetStreamer(Target &T,
809                                         Target::AsmTargetStreamerCtorTy Fn) {
810     T.AsmTargetStreamerCtorFn = Fn;
811   }
812
813   static void
814   RegisterObjectTargetStreamer(Target &T,
815                                Target::ObjectTargetStreamerCtorTy Fn) {
816     T.ObjectTargetStreamerCtorFn = Fn;
817   }
818
819   /// RegisterMCRelocationInfo - Register an MCRelocationInfo
820   /// implementation for the given target.
821   ///
822   /// Clients are responsible for ensuring that registration doesn't occur
823   /// while another thread is attempting to access the registry. Typically
824   /// this is done by initializing all targets at program startup.
825   ///
826   /// @param T - The target being registered.
827   /// @param Fn - A function to construct an MCRelocationInfo for the target.
828   static void RegisterMCRelocationInfo(Target &T,
829                                        Target::MCRelocationInfoCtorTy Fn) {
830     T.MCRelocationInfoCtorFn = Fn;
831   }
832
833   /// RegisterMCSymbolizer - Register an MCSymbolizer
834   /// implementation for the given target.
835   ///
836   /// Clients are responsible for ensuring that registration doesn't occur
837   /// while another thread is attempting to access the registry. Typically
838   /// this is done by initializing all targets at program startup.
839   ///
840   /// @param T - The target being registered.
841   /// @param Fn - A function to construct an MCSymbolizer for the target.
842   static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn) {
843     T.MCSymbolizerCtorFn = Fn;
844   }
845
846   /// @}
847 };
848
849 //===--------------------------------------------------------------------===//
850
851 /// RegisterTarget - Helper template for registering a target, for use in the
852 /// target's initialization function. Usage:
853 ///
854 ///
855 /// Target &getTheFooTarget() { // The global target instance.
856 ///   static Target TheFooTarget;
857 ///   return TheFooTarget;
858 /// }
859 /// extern "C" void LLVMInitializeFooTargetInfo() {
860 ///   RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
861 ///   description");
862 /// }
863 template <Triple::ArchType TargetArchType = Triple::UnknownArch,
864           bool HasJIT = false>
865 struct RegisterTarget {
866   RegisterTarget(Target &T, const char *Name, const char *Desc) {
867     TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch, HasJIT);
868   }
869
870   static bool getArchMatch(Triple::ArchType Arch) {
871     return Arch == TargetArchType;
872   }
873 };
874
875 /// RegisterMCAsmInfo - Helper template for registering a target assembly info
876 /// implementation.  This invokes the static "Create" method on the class to
877 /// actually do the construction.  Usage:
878 ///
879 /// extern "C" void LLVMInitializeFooTarget() {
880 ///   extern Target TheFooTarget;
881 ///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
882 /// }
883 template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
884   RegisterMCAsmInfo(Target &T) {
885     TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
886   }
887
888 private:
889   static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
890                               const Triple &TT) {
891     return new MCAsmInfoImpl(TT);
892   }
893 };
894
895 /// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
896 /// implementation.  This invokes the specified function to do the
897 /// construction.  Usage:
898 ///
899 /// extern "C" void LLVMInitializeFooTarget() {
900 ///   extern Target TheFooTarget;
901 ///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
902 /// }
903 struct RegisterMCAsmInfoFn {
904   RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
905     TargetRegistry::RegisterMCAsmInfo(T, Fn);
906   }
907 };
908
909 struct RegisterMCAdjustCodeGenOptsFn {
910   RegisterMCAdjustCodeGenOptsFn(Target &T, Target::MCAdjustCodeGenOptsFnTy Fn) {
911     TargetRegistry::registerMCAdjustCodeGenOpts(T, Fn);
912   }
913 };
914
915 /// RegisterMCInstrInfo - Helper template for registering a target instruction
916 /// info implementation.  This invokes the static "Create" method on the class
917 /// to actually do the construction.  Usage:
918 ///
919 /// extern "C" void LLVMInitializeFooTarget() {
920 ///   extern Target TheFooTarget;
921 ///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
922 /// }
923 template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
924   RegisterMCInstrInfo(Target &T) {
925     TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
926   }
927
928 private:
929   static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
930 };
931
932 /// RegisterMCInstrInfoFn - Helper template for registering a target
933 /// instruction info implementation.  This invokes the specified function to
934 /// do the construction.  Usage:
935 ///
936 /// extern "C" void LLVMInitializeFooTarget() {
937 ///   extern Target TheFooTarget;
938 ///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
939 /// }
940 struct RegisterMCInstrInfoFn {
941   RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
942     TargetRegistry::RegisterMCInstrInfo(T, Fn);
943   }
944 };
945
946 /// RegisterMCInstrAnalysis - Helper template for registering a target
947 /// instruction analyzer implementation.  This invokes the static "Create"
948 /// method on the class to actually do the construction.  Usage:
949 ///
950 /// extern "C" void LLVMInitializeFooTarget() {
951 ///   extern Target TheFooTarget;
952 ///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
953 /// }
954 template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
955   RegisterMCInstrAnalysis(Target &T) {
956     TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
957   }
958
959 private:
960   static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
961     return new MCInstrAnalysisImpl(Info);
962   }
963 };
964
965 /// RegisterMCInstrAnalysisFn - Helper template for registering a target
966 /// instruction analyzer implementation.  This invokes the specified function
967 /// to do the construction.  Usage:
968 ///
969 /// extern "C" void LLVMInitializeFooTarget() {
970 ///   extern Target TheFooTarget;
971 ///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
972 /// }
973 struct RegisterMCInstrAnalysisFn {
974   RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
975     TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
976   }
977 };
978
979 /// RegisterMCRegInfo - Helper template for registering a target register info
980 /// implementation.  This invokes the static "Create" method on the class to
981 /// actually do the construction.  Usage:
982 ///
983 /// extern "C" void LLVMInitializeFooTarget() {
984 ///   extern Target TheFooTarget;
985 ///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
986 /// }
987 template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
988   RegisterMCRegInfo(Target &T) {
989     TargetRegistry::RegisterMCRegInfo(T, &Allocator);
990   }
991
992 private:
993   static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
994     return new MCRegisterInfoImpl();
995   }
996 };
997
998 /// RegisterMCRegInfoFn - Helper template for registering a target register
999 /// info implementation.  This invokes the specified function to do the
1000 /// construction.  Usage:
1001 ///
1002 /// extern "C" void LLVMInitializeFooTarget() {
1003 ///   extern Target TheFooTarget;
1004 ///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1005 /// }
1006 struct RegisterMCRegInfoFn {
1007   RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
1008     TargetRegistry::RegisterMCRegInfo(T, Fn);
1009   }
1010 };
1011
1012 /// RegisterMCSubtargetInfo - Helper template for registering a target
1013 /// subtarget info implementation.  This invokes the static "Create" method
1014 /// on the class to actually do the construction.  Usage:
1015 ///
1016 /// extern "C" void LLVMInitializeFooTarget() {
1017 ///   extern Target TheFooTarget;
1018 ///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1019 /// }
1020 template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1021   RegisterMCSubtargetInfo(Target &T) {
1022     TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
1023   }
1024
1025 private:
1026   static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1027                                     StringRef /*FS*/) {
1028     return new MCSubtargetInfoImpl();
1029   }
1030 };
1031
1032 /// RegisterMCSubtargetInfoFn - Helper template for registering a target
1033 /// subtarget info implementation.  This invokes the specified function to
1034 /// do the construction.  Usage:
1035 ///
1036 /// extern "C" void LLVMInitializeFooTarget() {
1037 ///   extern Target TheFooTarget;
1038 ///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1039 /// }
1040 struct RegisterMCSubtargetInfoFn {
1041   RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
1042     TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
1043   }
1044 };
1045
1046 /// RegisterTargetMachine - Helper template for registering a target machine
1047 /// implementation, for use in the target machine initialization
1048 /// function. Usage:
1049 ///
1050 /// extern "C" void LLVMInitializeFooTarget() {
1051 ///   extern Target TheFooTarget;
1052 ///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1053 /// }
1054 template <class TargetMachineImpl> struct RegisterTargetMachine {
1055   RegisterTargetMachine(Target &T) {
1056     TargetRegistry::RegisterTargetMachine(T, &Allocator);
1057   }
1058
1059 private:
1060   static TargetMachine *Allocator(const Target &T, const Triple &TT,
1061                                   StringRef CPU, StringRef FS,
1062                                   const TargetOptions &Options,
1063                                   Optional<Reloc::Model> RM,
1064                                   CodeModel::Model CM, CodeGenOpt::Level OL) {
1065     return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL);
1066   }
1067 };
1068
1069 /// RegisterMCAsmBackend - Helper template for registering a target specific
1070 /// assembler backend. Usage:
1071 ///
1072 /// extern "C" void LLVMInitializeFooMCAsmBackend() {
1073 ///   extern Target TheFooTarget;
1074 ///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1075 /// }
1076 template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1077   RegisterMCAsmBackend(Target &T) {
1078     TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
1079   }
1080
1081 private:
1082   static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
1083                                  const Triple &TheTriple, StringRef CPU,
1084                                  const MCTargetOptions &Options) {
1085     return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
1086   }
1087 };
1088
1089 /// RegisterMCAsmParser - Helper template for registering a target specific
1090 /// assembly parser, for use in the target machine initialization
1091 /// function. Usage:
1092 ///
1093 /// extern "C" void LLVMInitializeFooMCAsmParser() {
1094 ///   extern Target TheFooTarget;
1095 ///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1096 /// }
1097 template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1098   RegisterMCAsmParser(Target &T) {
1099     TargetRegistry::RegisterMCAsmParser(T, &Allocator);
1100   }
1101
1102 private:
1103   static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1104                                       MCAsmParser &P, const MCInstrInfo &MII,
1105                                       const MCTargetOptions &Options) {
1106     return new MCAsmParserImpl(STI, P, MII, Options);
1107   }
1108 };
1109
1110 /// RegisterAsmPrinter - Helper template for registering a target specific
1111 /// assembly printer, for use in the target machine initialization
1112 /// function. Usage:
1113 ///
1114 /// extern "C" void LLVMInitializeFooAsmPrinter() {
1115 ///   extern Target TheFooTarget;
1116 ///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1117 /// }
1118 template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1119   RegisterAsmPrinter(Target &T) {
1120     TargetRegistry::RegisterAsmPrinter(T, &Allocator);
1121   }
1122
1123 private:
1124   static AsmPrinter *Allocator(TargetMachine &TM,
1125                                std::unique_ptr<MCStreamer> &&Streamer) {
1126     return new AsmPrinterImpl(TM, std::move(Streamer));
1127   }
1128 };
1129
1130 /// RegisterMCCodeEmitter - Helper template for registering a target specific
1131 /// machine code emitter, for use in the target initialization
1132 /// function. Usage:
1133 ///
1134 /// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1135 ///   extern Target TheFooTarget;
1136 ///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1137 /// }
1138 template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1139   RegisterMCCodeEmitter(Target &T) {
1140     TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
1141   }
1142
1143 private:
1144   static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1145                                   const MCRegisterInfo & /*MRI*/,
1146                                   MCContext & /*Ctx*/) {
1147     return new MCCodeEmitterImpl();
1148   }
1149 };
1150 }
1151
1152 #endif