Coverage Report

Created: 2025-12-27 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/include/llvm/Support/TargetRegistry.h
Line
Count
Source
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/ADT/Triple.h"
23
#include "llvm/Support/FormattedStream.h"
24
#include <cassert>
25
#include <memory>
26
#include <string>
27
28
namespace llvm_ks {
29
class AsmPrinter;
30
class MCAsmBackend;
31
class MCAsmInfo;
32
class MCAsmParser;
33
class MCCodeEmitter;
34
class MCContext;
35
class MCInstrAnalysis;
36
class MCInstrInfo;
37
class MCRegisterInfo;
38
class MCStreamer;
39
class MCSubtargetInfo;
40
class MCSymbolizer;
41
class MCRelocationInfo;
42
class MCTargetAsmParser;
43
class MCTargetOptions;
44
class MCTargetStreamer;
45
class TargetMachine;
46
class TargetOptions;
47
class raw_ostream;
48
class raw_pwrite_stream;
49
class formatted_raw_ostream;
50
51
MCStreamer *createNullStreamer(MCContext &Ctx);
52
MCStreamer *createAsmStreamer(MCContext &Ctx,
53
                              std::unique_ptr<formatted_raw_ostream> OS,
54
                              MCCodeEmitter *CE,
55
                              MCAsmBackend *TAB);
56
57
/// Takes ownership of \p TAB and \p CE.
58
MCStreamer *createELFStreamer(MCContext &Ctx, MCAsmBackend &TAB,
59
                              raw_pwrite_stream &OS, MCCodeEmitter *CE,
60
                              bool RelaxAll);
61
MCRelocationInfo *createMCRelocationInfo(const Triple &TT, MCContext &Ctx);
62
63
/// Target - Wrapper for Target specific information.
64
///
65
/// For registration purposes, this is a POD type so that targets can be
66
/// registered without the use of static constructors.
67
///
68
/// Targets should implement a single global instance of this class (which
69
/// will be zero initialized), and pass that instance to the TargetRegistry as
70
/// part of their initialization.
71
class Target {
72
public:
73
  friend struct TargetRegistry;
74
75
  typedef bool (*ArchMatchFnTy)(Triple::ArchType Arch);
76
77
  typedef MCAsmInfo *(*MCAsmInfoCtorFnTy)(const MCRegisterInfo &MRI,
78
                                          const Triple &TT);
79
  typedef MCInstrInfo *(*MCInstrInfoCtorFnTy)(void);
80
  typedef MCInstrAnalysis *(*MCInstrAnalysisCtorFnTy)(const MCInstrInfo *Info);
81
  typedef MCRegisterInfo *(*MCRegInfoCtorFnTy)(const Triple &TT);
82
  typedef MCSubtargetInfo *(*MCSubtargetInfoCtorFnTy)(const Triple &TT,
83
                                                      StringRef CPU,
84
                                                      StringRef Features);
85
  typedef TargetMachine *(*TargetMachineCtorTy)(
86
      const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
87
      const TargetOptions &Options);
88
  // If it weren't for layering issues (this header is in llvm/Support, but
89
  // depends on MC?) this should take the Streamer by value rather than rvalue
90
  // reference.
91
  typedef AsmPrinter *(*AsmPrinterCtorTy)(
92
      TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
93
  typedef MCAsmBackend *(*MCAsmBackendCtorTy)(const Target &T,
94
                                              const MCRegisterInfo &MRI,
95
                                              const Triple &TT, StringRef CPU);
96
  typedef MCAsmBackend *(*MCAsmBackendCtorTy2)(const Target &T,
97
                                              const MCRegisterInfo &MRI,
98
                                              const Triple &TT, StringRef CPU, const MCSubtargetInfo &STI, const MCTargetOptions &Options);
99
  typedef MCTargetAsmParser *(*MCAsmParserCtorTy)(
100
      const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
101
      const MCTargetOptions &Options);
102
  typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
103
                                                const MCRegisterInfo &MRI,
104
                                                MCContext &Ctx);
105
  typedef MCStreamer *(*ELFStreamerCtorTy)(const Triple &T, MCContext &Ctx,
106
                                           MCAsmBackend &TAB,
107
                                           raw_pwrite_stream &OS,
108
                                           MCCodeEmitter *Emitter,
109
                                           bool RelaxAll);
110
  typedef MCStreamer *(*MachOStreamerCtorTy)(MCContext &Ctx, MCAsmBackend &TAB,
111
                                             raw_pwrite_stream &OS,
112
                                             MCCodeEmitter *Emitter,
113
                                             bool RelaxAll,
114
                                             bool DWARFMustBeAtTheEnd);
115
  typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S);
116
  typedef MCTargetStreamer *(*AsmTargetStreamerCtorTy)(
117
      MCStreamer &S, formatted_raw_ostream &OS);
118
  typedef MCTargetStreamer *(*ObjectTargetStreamerCtorTy)(
119
      MCStreamer &S, const MCSubtargetInfo &STI);
120
  typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(const Triple &TT,
121
                                                      MCContext &Ctx);
122
private:
123
  /// Next - The next registered target in the linked list, maintained by the
124
  /// TargetRegistry.
125
  Target *Next;
126
127
  /// The target function for checking if an architecture is supported.
128
  ArchMatchFnTy ArchMatchFn;
129
130
  /// Name - The target name.
131
  const char *Name;
132
133
  /// ShortDesc - A short description of the target.
134
  const char *ShortDesc;
135
136
  /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
137
  /// registered.
138
  MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
139
140
  /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
141
  /// if registered.
142
  MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
143
144
  /// MCInstrAnalysisCtorFn - Constructor function for this target's
145
  /// MCInstrAnalysis, if registered.
146
  MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
147
148
  /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
149
  /// if registered.
150
  MCRegInfoCtorFnTy MCRegInfoCtorFn;
151
152
  /// MCSubtargetInfoCtorFn - Constructor function for this target's
153
  /// MCSubtargetInfo, if registered.
154
  MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
155
156
  /// TargetMachineCtorFn - Construction function for this target's
157
  /// TargetMachine, if registered.
158
  TargetMachineCtorTy TargetMachineCtorFn;
159
160
  /// MCAsmBackendCtorFn - Construction function for this target's
161
  /// MCAsmBackend, if registered.
162
  MCAsmBackendCtorTy MCAsmBackendCtorFn;
163
  MCAsmBackendCtorTy2 MCAsmBackendCtorFn2;
164
165
  /// MCAsmParserCtorFn - Construction function for this target's
166
  /// MCTargetAsmParser, if registered.
167
  MCAsmParserCtorTy MCAsmParserCtorFn;
168
169
  /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
170
  /// if registered.
171
  AsmPrinterCtorTy AsmPrinterCtorFn;
172
173
  /// MCCodeEmitterCtorFn - Construction function for this target's
174
  /// CodeEmitter, if registered.
175
  MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
176
177
  // Construction functions for the various object formats, if registered.
178
  ELFStreamerCtorTy ELFStreamerCtorFn;
179
180
  /// Construction function for this target's null TargetStreamer, if
181
  /// registered (default = nullptr).
182
  NullTargetStreamerCtorTy NullTargetStreamerCtorFn;
183
184
  /// Construction function for this target's asm TargetStreamer, if
185
  /// registered (default = nullptr).
186
  AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn;
187
188
  /// Construction function for this target's obj TargetStreamer, if
189
  /// registered (default = nullptr).
190
  ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn;
191
192
  /// MCRelocationInfoCtorFn - Construction function for this target's
193
  /// MCRelocationInfo, if registered (default = llvm_ks::createMCRelocationInfo)
194
  MCRelocationInfoCtorTy MCRelocationInfoCtorFn;
195
196
public:
197
  Target()
198
1.21k
      : ELFStreamerCtorFn(nullptr), NullTargetStreamerCtorFn(nullptr),
199
1.21k
        AsmTargetStreamerCtorFn(nullptr), ObjectTargetStreamerCtorFn(nullptr),
200
1.21k
        MCRelocationInfoCtorFn(nullptr) {}
201
202
  /// @name Target Information
203
  /// @{
204
205
  // getNext - Return the next registered target.
206
2.94M
  const Target *getNext() const { return Next; }
207
208
  /// getName - Get the target name.
209
28.2k
  const char *getName() const { return Name; }
210
211
  /// getShortDescription - Get a short description of the target.
212
0
  const char *getShortDescription() const { return ShortDesc; }
213
214
  /// @}
215
  /// @name Feature Predicates
216
  /// @{
217
218
  /// hasTargetMachine - Check if this target supports code generation.
219
0
  bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
220
221
  /// hasMCAsmBackend - Check if this target supports .o generation.
222
0
  bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
223
224
  /// @}
225
  /// @name Feature Constructors
226
  /// @{
227
228
  /// createMCAsmInfo - Create a MCAsmInfo implementation for the specified
229
  /// target triple.
230
  ///
231
  /// \param TheTriple This argument is used to determine the target machine
232
  /// feature set; it should always be provided. Generally this should be
233
  /// either the target triple from the module, or the target triple of the
234
  /// host if that does not exist.
235
  MCAsmInfo *createMCAsmInfo(const MCRegisterInfo &MRI,
236
128k
                             StringRef TheTriple) const {
237
128k
    if (!MCAsmInfoCtorFn)
238
0
      return nullptr;
239
128k
    return MCAsmInfoCtorFn(MRI, Triple(TheTriple));
240
128k
  }
241
242
  /// createMCInstrInfo - Create a MCInstrInfo implementation.
243
  ///
244
131k
  MCInstrInfo *createMCInstrInfo() const {
245
131k
    if (!MCInstrInfoCtorFn)
246
0
      return nullptr;
247
131k
    return MCInstrInfoCtorFn();
248
131k
  }
249
250
  /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
251
  ///
252
0
  MCInstrAnalysis *createMCInstrAnalysis(const MCInstrInfo *Info) const {
253
0
    if (!MCInstrAnalysisCtorFn)
254
0
      return nullptr;
255
0
    return MCInstrAnalysisCtorFn(Info);
256
0
  }
257
258
  /// createMCRegInfo - Create a MCRegisterInfo implementation.
259
  ///
260
128k
  MCRegisterInfo *createMCRegInfo(StringRef TT) const {
261
128k
    if (!MCRegInfoCtorFn)
262
0
      return nullptr;
263
128k
    return MCRegInfoCtorFn(Triple(TT));
264
128k
  }
265
266
  /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
267
  ///
268
  /// \param TheTriple This argument is used to determine the target machine
269
  /// feature set; it should always be provided. Generally this should be
270
  /// either the target triple from the module, or the target triple of the
271
  /// host if that does not exist.
272
  /// \param CPU This specifies the name of the target CPU.
273
  /// \param Features This specifies the string representation of the
274
  /// additional target features.
275
  MCSubtargetInfo *createMCSubtargetInfo(StringRef TheTriple, StringRef CPU,
276
128k
                                         StringRef Features) const {
277
128k
    if (!MCSubtargetInfoCtorFn)
278
0
      return nullptr;
279
128k
    return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
280
128k
  }
281
282
  /// createTargetMachine - Create a target specific machine implementation
283
  /// for the specified \p Triple.
284
  ///
285
  /// \param TT This argument is used to determine the target machine
286
  /// feature set; it should always be provided. Generally this should be
287
  /// either the target triple from the module, or the target triple of the
288
  /// host if that does not exist.
289
  TargetMachine *
290
  createTargetMachine(StringRef TT, StringRef CPU, StringRef Features,
291
0
                      const TargetOptions &Options) const {
292
0
    if (!TargetMachineCtorFn)
293
0
      return nullptr;
294
0
    return TargetMachineCtorFn(*this, Triple(TT), CPU, Features, Options);
295
0
  }
296
297
  /// createMCAsmBackend - Create a target specific assembly parser.
298
  ///
299
  /// \param TheTriple The target triple string.
300
  MCAsmBackend *createMCAsmBackend(const MCRegisterInfo &MRI,
301
102k
                                   StringRef TheTriple, StringRef CPU) const {
302
102k
    if (!MCAsmBackendCtorFn)
303
0
      return nullptr;
304
102k
    return MCAsmBackendCtorFn(*this, MRI, Triple(TheTriple), CPU);
305
102k
  }
306
307
  MCAsmBackend *createMCAsmBackend2(const MCRegisterInfo &MRI,
308
25.4k
                                   StringRef TheTriple, StringRef CPU, const MCSubtargetInfo &STI, const MCTargetOptions &Options) const {
309
25.4k
    if (!MCAsmBackendCtorFn2)
310
0
      return nullptr;
311
25.4k
    return MCAsmBackendCtorFn2(*this, MRI, Triple(TheTriple), CPU, STI, Options);
312
25.4k
  }
313
  /// createMCAsmParser - Create a target specific assembly parser.
314
  ///
315
  /// \param Parser The target independent parser implementation to use for
316
  /// parsing and lexing.
317
  MCTargetAsmParser *createMCAsmParser(const MCSubtargetInfo &STI,
318
                                       MCAsmParser &Parser,
319
                                       const MCInstrInfo &MII,
320
128k
                                       const MCTargetOptions &Options) const {
321
128k
    if (!MCAsmParserCtorFn)
322
0
      return nullptr;
323
128k
    return MCAsmParserCtorFn(STI, Parser, MII, Options);
324
128k
  }
325
326
  /// createAsmPrinter - Create a target specific assembly printer pass.  This
327
  /// takes ownership of the MCStreamer object.
328
  AsmPrinter *createAsmPrinter(TargetMachine &TM,
329
0
                               std::unique_ptr<MCStreamer> &&Streamer) const {
330
0
    if (!AsmPrinterCtorFn)
331
0
      return nullptr;
332
0
    return AsmPrinterCtorFn(TM, std::move(Streamer));
333
0
  }
334
335
  /// createMCCodeEmitter - Create a target specific code emitter.
336
  MCCodeEmitter *createMCCodeEmitter(const MCInstrInfo &II,
337
                                     const MCRegisterInfo &MRI,
338
128k
                                     MCContext &Ctx) const {
339
128k
    if (!MCCodeEmitterCtorFn)
340
0
      return nullptr;
341
128k
    return MCCodeEmitterCtorFn(II, MRI, Ctx);
342
128k
  }
343
344
  /// Create a target specific MCStreamer.
345
  ///
346
  /// \param T The target triple.
347
  /// \param Ctx The target context.
348
  /// \param TAB The target assembler backend object. Takes ownership.
349
  /// \param OS The stream object.
350
  /// \param Emitter The target independent assembler object.Takes ownership.
351
  /// \param RelaxAll Relax all fixups?
352
  MCStreamer *createMCObjectStreamer(const Triple &T, MCContext &Ctx,
353
                                     MCAsmBackend &TAB, raw_pwrite_stream &OS,
354
                                     MCCodeEmitter *Emitter,
355
                                     const MCSubtargetInfo &STI, bool RelaxAll,
356
128k
                                     bool DWARFMustBeAtTheEnd) const {
357
128k
    MCStreamer *S;
358
128k
    switch (T.getObjectFormat()) {
359
0
    default:
360
0
      llvm_unreachable("Unknown object format");
361
128k
    case Triple::ELF:
362
128k
      if (ELFStreamerCtorFn)
363
0
        S = ELFStreamerCtorFn(T, Ctx, TAB, OS, Emitter, RelaxAll);
364
128k
      else
365
128k
        S = createELFStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
366
128k
      break;
367
128k
    }
368
128k
    if (ObjectTargetStreamerCtorFn)
369
25.4k
      ObjectTargetStreamerCtorFn(*S, STI);
370
128k
    return S;
371
128k
  }
372
373
  MCStreamer *createAsmStreamer(MCContext &Ctx,
374
                                std::unique_ptr<formatted_raw_ostream> OS,
375
                                MCCodeEmitter *CE,
376
0
                                MCAsmBackend *TAB) const {
377
0
    formatted_raw_ostream &OSRef = *OS;
378
0
    MCStreamer *S = llvm_ks::createAsmStreamer(Ctx, std::move(OS), CE, TAB);
379
0
    createAsmTargetStreamer(*S, OSRef);
380
0
    return S;
381
0
  }
382
383
  MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
384
0
                                            formatted_raw_ostream &OS) const {
385
0
    if (AsmTargetStreamerCtorFn)
386
0
      return AsmTargetStreamerCtorFn(S, OS);
387
0
    return nullptr;
388
0
  }
389
390
0
  MCStreamer *createNullStreamer(MCContext &Ctx) const {
391
0
    MCStreamer *S = llvm_ks::createNullStreamer(Ctx);
392
0
    return S;
393
0
  }
394
395
  /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
396
  ///
397
  /// \param TT The target triple.
398
  /// \param Ctx The target context.
399
0
  MCRelocationInfo *createMCRelocationInfo(StringRef TT, MCContext &Ctx) const {
400
0
    MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
401
0
                                    ? MCRelocationInfoCtorFn
402
0
                                    : llvm_ks::createMCRelocationInfo;
403
0
    return Fn(Triple(TT), Ctx);
404
0
  }
405
406
  /// @}
407
};
408
409
/// TargetRegistry - Generic interface to target specific features.
410
struct TargetRegistry {
411
  // FIXME: Make this a namespace, probably just move all the Register*
412
  // functions into Target (currently they all just set members on the Target
413
  // anyway, and Target friends this class so those functions can...
414
  // function).
415
  TargetRegistry() = delete;
416
417
  class iterator
418
      : public std::iterator<std::forward_iterator_tag, Target, ptrdiff_t> {
419
    const Target *Current;
420
896k
    explicit iterator(Target *T) : Current(T) {}
421
    friend struct TargetRegistry;
422
423
  public:
424
896k
    iterator() : Current(nullptr) {}
425
426
3.45M
    bool operator==(const iterator &x) const { return Current == x.Current; }
427
3.20M
    bool operator!=(const iterator &x) const { return !operator==(x); }
428
429
    // Iterator traversal: forward iteration only
430
2.94M
    iterator &operator++() { // Preincrement
431
2.94M
      assert(Current && "Cannot increment end iterator!");
432
2.94M
      Current = Current->getNext();
433
2.94M
      return *this;
434
2.94M
    }
435
0
    iterator operator++(int) { // Postincrement
436
0
      iterator tmp = *this;
437
0
      ++*this;
438
0
      return tmp;
439
0
    }
440
441
3.07M
    const Target &operator*() const {
442
3.07M
      assert(Current && "Cannot dereference end iterator!");
443
3.07M
      return *Current;
444
3.07M
    }
445
446
0
    const Target *operator->() const { return &operator*(); }
447
  };
448
449
  /// printRegisteredTargetsForVersion - Print the registered targets
450
  /// appropriately for inclusion in a tool's version output.
451
  static void printRegisteredTargetsForVersion();
452
453
  /// @name Registry Access
454
  /// @{
455
456
  static iterator_range<iterator> targets();
457
458
  /// lookupTarget - Lookup a target based on a target triple.
459
  ///
460
  /// \param Triple - The triple to use for finding a target.
461
  /// \param Error - On failure, an error string describing why no target was
462
  /// found.
463
  static const Target *lookupTarget(const std::string &Triple,
464
                                    std::string &Error);
465
466
  /// lookupTarget - Lookup a target based on an architecture name
467
  /// and a target triple.  If the architecture name is non-empty,
468
  /// then the lookup is done by architecture.  Otherwise, the target
469
  /// triple is used.
470
  ///
471
  /// \param ArchName - The architecture to use for finding a target.
472
  /// \param TheTriple - The triple to use for finding a target.  The
473
  /// triple is updated with canonical architecture name if a lookup
474
  /// by architecture is done.
475
  /// \param Error - On failure, an error string describing why no target was
476
  /// found.
477
  static const Target *lookupTarget(const std::string &ArchName,
478
                                    Triple &TheTriple, std::string &Error);
479
480
  /// @}
481
  /// @name Target Registration
482
  /// @{
483
484
  /// RegisterTarget - Register the given target. Attempts to register a
485
  /// target which has already been registered will be ignored.
486
  ///
487
  /// Clients are responsible for ensuring that registration doesn't occur
488
  /// while another thread is attempting to access the registry. Typically
489
  /// this is done by initializing all targets at program startup.
490
  ///
491
  /// @param T - The target being registered.
492
  /// @param Name - The target name. This should be a static string.
493
  /// @param ShortDesc - A short target description. This should be a static
494
  /// string.
495
  /// @param ArchMatchFn - The arch match checking function for this target.
496
  static void RegisterTarget(Target &T, const char *Name, const char *ShortDesc,
497
                             Target::ArchMatchFnTy ArchMatchFn);
498
499
  /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
500
  /// given target.
501
  ///
502
  /// Clients are responsible for ensuring that registration doesn't occur
503
  /// while another thread is attempting to access the registry. Typically
504
  /// this is done by initializing all targets at program startup.
505
  ///
506
  /// @param T - The target being registered.
507
  /// @param Fn - A function to construct a MCAsmInfo for the target.
508
598
  static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
509
598
    T.MCAsmInfoCtorFn = Fn;
510
598
  }
511
512
  /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
513
  /// given target.
514
  ///
515
  /// Clients are responsible for ensuring that registration doesn't occur
516
  /// while another thread is attempting to access the registry. Typically
517
  /// this is done by initializing all targets at program startup.
518
  ///
519
  /// @param T - The target being registered.
520
  /// @param Fn - A function to construct a MCInstrInfo for the target.
521
598
  static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
522
598
    T.MCInstrInfoCtorFn = Fn;
523
598
  }
524
525
  /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
526
  /// the given target.
527
  static void RegisterMCInstrAnalysis(Target &T,
528
0
                                      Target::MCInstrAnalysisCtorFnTy Fn) {
529
0
    T.MCInstrAnalysisCtorFn = Fn;
530
0
  }
531
532
  /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
533
  /// given target.
534
  ///
535
  /// Clients are responsible for ensuring that registration doesn't occur
536
  /// while another thread is attempting to access the registry. Typically
537
  /// this is done by initializing all targets at program startup.
538
  ///
539
  /// @param T - The target being registered.
540
  /// @param Fn - A function to construct a MCRegisterInfo for the target.
541
598
  static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn) {
542
598
    T.MCRegInfoCtorFn = Fn;
543
598
  }
544
545
  /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
546
  /// the given target.
547
  ///
548
  /// Clients are responsible for ensuring that registration doesn't occur
549
  /// while another thread is attempting to access the registry. Typically
550
  /// this is done by initializing all targets at program startup.
551
  ///
552
  /// @param T - The target being registered.
553
  /// @param Fn - A function to construct a MCSubtargetInfo for the target.
554
  static void RegisterMCSubtargetInfo(Target &T,
555
598
                                      Target::MCSubtargetInfoCtorFnTy Fn) {
556
598
    T.MCSubtargetInfoCtorFn = Fn;
557
598
  }
558
559
  /// RegisterTargetMachine - Register a TargetMachine implementation for the
560
  /// given target.
561
  ///
562
  /// Clients are responsible for ensuring that registration doesn't occur
563
  /// while another thread is attempting to access the registry. Typically
564
  /// this is done by initializing all targets at program startup.
565
  ///
566
  /// @param T - The target being registered.
567
  /// @param Fn - A function to construct a TargetMachine for the target.
568
0
  static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn) {
569
0
    T.TargetMachineCtorFn = Fn;
570
0
  }
571
572
  /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
573
  /// given target.
574
  ///
575
  /// Clients are responsible for ensuring that registration doesn't occur
576
  /// while another thread is attempting to access the registry. Typically
577
  /// this is done by initializing all targets at program startup.
578
  ///
579
  /// @param T - The target being registered.
580
  /// @param Fn - A function to construct an AsmBackend for the target.
581
546
  static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn) {
582
546
    T.MCAsmBackendCtorFn = Fn;
583
546
  }
584
52
  static void RegisterMCAsmBackend2(Target &T, Target::MCAsmBackendCtorTy2 Fn) {
585
52
    T.MCAsmBackendCtorFn2 = Fn;
586
52
  }
587
588
  /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
589
  /// the given target.
590
  ///
591
  /// Clients are responsible for ensuring that registration doesn't occur
592
  /// while another thread is attempting to access the registry. Typically
593
  /// this is done by initializing all targets at program startup.
594
  ///
595
  /// @param T - The target being registered.
596
  /// @param Fn - A function to construct an MCTargetAsmParser for the target.
597
598
  static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn) {
598
598
    T.MCAsmParserCtorFn = Fn;
599
598
  }
600
601
  /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
602
  /// target.
603
  ///
604
  /// Clients are responsible for ensuring that registration doesn't occur
605
  /// while another thread is attempting to access the registry. Typically
606
  /// this is done by initializing all targets at program startup.
607
  ///
608
  /// @param T - The target being registered.
609
  /// @param Fn - A function to construct an AsmPrinter for the target.
610
0
  static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn) {
611
0
    T.AsmPrinterCtorFn = Fn;
612
0
  }
613
614
  /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
615
  /// given target.
616
  ///
617
  /// Clients are responsible for ensuring that registration doesn't occur
618
  /// while another thread is attempting to access the registry. Typically
619
  /// this is done by initializing all targets at program startup.
620
  ///
621
  /// @param T - The target being registered.
622
  /// @param Fn - A function to construct an MCCodeEmitter for the target.
623
598
  static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn) {
624
598
    T.MCCodeEmitterCtorFn = Fn;
625
598
  }
626
627
0
  static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn) {
628
0
    T.ELFStreamerCtorFn = Fn;
629
0
  }
630
631
  static void RegisterNullTargetStreamer(Target &T,
632
0
                                         Target::NullTargetStreamerCtorTy Fn) {
633
0
    T.NullTargetStreamerCtorFn = Fn;
634
0
  }
635
636
  static void RegisterAsmTargetStreamer(Target &T,
637
52
                                        Target::AsmTargetStreamerCtorTy Fn) {
638
52
    T.AsmTargetStreamerCtorFn = Fn;
639
52
  }
640
641
  static void
642
  RegisterObjectTargetStreamer(Target &T,
643
52
                               Target::ObjectTargetStreamerCtorTy Fn) {
644
52
    T.ObjectTargetStreamerCtorFn = Fn;
645
52
  }
646
647
  /// RegisterMCRelocationInfo - Register an MCRelocationInfo
648
  /// implementation for the given target.
649
  ///
650
  /// Clients are responsible for ensuring that registration doesn't occur
651
  /// while another thread is attempting to access the registry. Typically
652
  /// this is done by initializing all targets at program startup.
653
  ///
654
  /// @param T - The target being registered.
655
  /// @param Fn - A function to construct an MCRelocationInfo for the target.
656
  static void RegisterMCRelocationInfo(Target &T,
657
52
                                       Target::MCRelocationInfoCtorTy Fn) {
658
52
    T.MCRelocationInfoCtorFn = Fn;
659
52
  }
660
661
  /// @}
662
};
663
664
//===--------------------------------------------------------------------===//
665
666
/// RegisterTarget - Helper template for registering a target, for use in the
667
/// target's initialization function. Usage:
668
///
669
///
670
/// Target TheFooTarget; // The global target instance.
671
///
672
/// extern "C" void LLVMInitializeFooTargetInfo() {
673
///   RegisterTarget<Triple::foo> X(TheFooTarget, "foo", "Foo description");
674
/// }
675
template <Triple::ArchType TargetArchType = Triple::UnknownArch>
676
struct RegisterTarget {
677
572
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
572
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
572
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)3>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)4>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)1>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)2>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)26>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)27>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)8>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)9>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)10>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)11>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)12>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)14>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)15>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)16>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)21>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)22>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)23>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)24>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)28>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)29>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)18>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)19>::RegisterTarget(llvm_ks::Target&, char const*, char const*)
Line
Count
Source
677
26
  RegisterTarget(Target &T, const char *Name, const char *Desc) {
678
26
    TargetRegistry::RegisterTarget(T, Name, Desc, &getArchMatch);
679
26
  }
680
681
2.81M
  static bool getArchMatch(Triple::ArchType Arch) {
682
2.81M
    return Arch == TargetArchType;
683
2.81M
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)3>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)4>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)1>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)2>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)26>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)27>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)8>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)9>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)10>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)11>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)12>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)14>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)15>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)16>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)21>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)22>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)23>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)24>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)28>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)29>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)18>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
llvm_ks::RegisterTarget<(llvm_ks::Triple::ArchType)19>::getArchMatch(llvm_ks::Triple::ArchType)
Line
Count
Source
681
128k
  static bool getArchMatch(Triple::ArchType Arch) {
682
128k
    return Arch == TargetArchType;
683
128k
  }
684
};
685
686
/// RegisterMCAsmInfo - Helper template for registering a target assembly info
687
/// implementation.  This invokes the static "Create" method on the class to
688
/// actually do the construction.  Usage:
689
///
690
/// extern "C" void LLVMInitializeFooTarget() {
691
///   extern Target TheFooTarget;
692
///   RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
693
/// }
694
template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
695
  RegisterMCAsmInfo(Target &T) {
696
    TargetRegistry::RegisterMCAsmInfo(T, &Allocator);
697
  }
698
699
private:
700
  static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/,
701
                              const Triple &TT) {
702
    return new MCAsmInfoImpl(TT);
703
  }
704
};
705
706
/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
707
/// implementation.  This invokes the specified function to do the
708
/// construction.  Usage:
709
///
710
/// extern "C" void LLVMInitializeFooTarget() {
711
///   extern Target TheFooTarget;
712
///   RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
713
/// }
714
struct RegisterMCAsmInfoFn {
715
520
  RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn) {
716
520
    TargetRegistry::RegisterMCAsmInfo(T, Fn);
717
520
  }
718
};
719
720
/// RegisterMCInstrInfo - Helper template for registering a target instruction
721
/// info implementation.  This invokes the static "Create" method on the class
722
/// to actually do the construction.  Usage:
723
///
724
/// extern "C" void LLVMInitializeFooTarget() {
725
///   extern Target TheFooTarget;
726
///   RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
727
/// }
728
template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
729
  RegisterMCInstrInfo(Target &T) {
730
    TargetRegistry::RegisterMCInstrInfo(T, &Allocator);
731
  }
732
733
private:
734
  static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
735
};
736
737
/// RegisterMCInstrInfoFn - Helper template for registering a target
738
/// instruction info implementation.  This invokes the specified function to
739
/// do the construction.  Usage:
740
///
741
/// extern "C" void LLVMInitializeFooTarget() {
742
///   extern Target TheFooTarget;
743
///   RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
744
/// }
745
struct RegisterMCInstrInfoFn {
746
0
  RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn) {
747
0
    TargetRegistry::RegisterMCInstrInfo(T, Fn);
748
0
  }
749
};
750
751
/// RegisterMCInstrAnalysis - Helper template for registering a target
752
/// instruction analyzer implementation.  This invokes the static "Create"
753
/// method on the class to actually do the construction.  Usage:
754
///
755
/// extern "C" void LLVMInitializeFooTarget() {
756
///   extern Target TheFooTarget;
757
///   RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
758
/// }
759
template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
760
  RegisterMCInstrAnalysis(Target &T) {
761
    TargetRegistry::RegisterMCInstrAnalysis(T, &Allocator);
762
  }
763
764
private:
765
  static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
766
    return new MCInstrAnalysisImpl(Info);
767
  }
768
};
769
770
/// RegisterMCInstrAnalysisFn - Helper template for registering a target
771
/// instruction analyzer implementation.  This invokes the specified function
772
/// to do the construction.  Usage:
773
///
774
/// extern "C" void LLVMInitializeFooTarget() {
775
///   extern Target TheFooTarget;
776
///   RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
777
/// }
778
struct RegisterMCInstrAnalysisFn {
779
0
  RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn) {
780
0
    TargetRegistry::RegisterMCInstrAnalysis(T, Fn);
781
0
  }
782
};
783
784
/// RegisterMCRegInfo - Helper template for registering a target register info
785
/// implementation.  This invokes the static "Create" method on the class to
786
/// actually do the construction.  Usage:
787
///
788
/// extern "C" void LLVMInitializeFooTarget() {
789
///   extern Target TheFooTarget;
790
///   RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
791
/// }
792
template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
793
  RegisterMCRegInfo(Target &T) {
794
    TargetRegistry::RegisterMCRegInfo(T, &Allocator);
795
  }
796
797
private:
798
  static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
799
    return new MCRegisterInfoImpl();
800
  }
801
};
802
803
/// RegisterMCRegInfoFn - Helper template for registering a target register
804
/// info implementation.  This invokes the specified function to do the
805
/// construction.  Usage:
806
///
807
/// extern "C" void LLVMInitializeFooTarget() {
808
///   extern Target TheFooTarget;
809
///   RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
810
/// }
811
struct RegisterMCRegInfoFn {
812
0
  RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn) {
813
0
    TargetRegistry::RegisterMCRegInfo(T, Fn);
814
0
  }
815
};
816
817
/// RegisterMCSubtargetInfo - Helper template for registering a target
818
/// subtarget info implementation.  This invokes the static "Create" method
819
/// on the class to actually do the construction.  Usage:
820
///
821
/// extern "C" void LLVMInitializeFooTarget() {
822
///   extern Target TheFooTarget;
823
///   RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
824
/// }
825
template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
826
  RegisterMCSubtargetInfo(Target &T) {
827
    TargetRegistry::RegisterMCSubtargetInfo(T, &Allocator);
828
  }
829
830
private:
831
  static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
832
                                    StringRef /*FS*/) {
833
    return new MCSubtargetInfoImpl();
834
  }
835
};
836
837
/// RegisterMCSubtargetInfoFn - Helper template for registering a target
838
/// subtarget info implementation.  This invokes the specified function to
839
/// do the construction.  Usage:
840
///
841
/// extern "C" void LLVMInitializeFooTarget() {
842
///   extern Target TheFooTarget;
843
///   RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
844
/// }
845
struct RegisterMCSubtargetInfoFn {
846
0
  RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn) {
847
0
    TargetRegistry::RegisterMCSubtargetInfo(T, Fn);
848
0
  }
849
};
850
851
/// RegisterTargetMachine - Helper template for registering a target machine
852
/// implementation, for use in the target machine initialization
853
/// function. Usage:
854
///
855
/// extern "C" void LLVMInitializeFooTarget() {
856
///   extern Target TheFooTarget;
857
///   RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
858
/// }
859
template <class TargetMachineImpl> struct RegisterTargetMachine {
860
  RegisterTargetMachine(Target &T) {
861
    TargetRegistry::RegisterTargetMachine(T, &Allocator);
862
  }
863
864
private:
865
  static TargetMachine *Allocator(const Target &T, const Triple &TT,
866
                                  StringRef CPU, StringRef FS,
867
                                  const TargetOptions &Options) {
868
    return new TargetMachineImpl(T, TT, CPU, FS, Options);
869
  }
870
};
871
872
/// RegisterMCAsmBackend - Helper template for registering a target specific
873
/// assembler backend. Usage:
874
///
875
/// extern "C" void LLVMInitializeFooMCAsmBackend() {
876
///   extern Target TheFooTarget;
877
///   RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
878
/// }
879
template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
880
  RegisterMCAsmBackend(Target &T) {
881
    TargetRegistry::RegisterMCAsmBackend(T, &Allocator);
882
  }
883
884
private:
885
  static MCAsmBackend *Allocator(const Target &T, const MCRegisterInfo &MRI,
886
                                 const Triple &TheTriple, StringRef CPU) {
887
    return new MCAsmBackendImpl(T, MRI, TheTriple, CPU);
888
  }
889
};
890
891
/// RegisterMCAsmParser - Helper template for registering a target specific
892
/// assembly parser, for use in the target machine initialization
893
/// function. Usage:
894
///
895
/// extern "C" void LLVMInitializeFooMCAsmParser() {
896
///   extern Target TheFooTarget;
897
///   RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
898
/// }
899
template <class MCAsmParserImpl> struct RegisterMCAsmParser {
900
598
  RegisterMCAsmParser(Target &T) {
901
598
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
598
  }
AArch64AsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::AArch64AsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
78
  RegisterMCAsmParser(Target &T) {
901
78
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
78
  }
ARMAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::ARMAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
104
  RegisterMCAsmParser(Target &T) {
901
104
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
104
  }
HexagonAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::HexagonAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
26
  RegisterMCAsmParser(Target &T) {
901
26
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
26
  }
MipsAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::MipsAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
104
  RegisterMCAsmParser(Target &T) {
901
104
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
104
  }
PPCAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::PPCAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
78
  RegisterMCAsmParser(Target &T) {
901
78
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
78
  }
SparcAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::SparcAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
78
  RegisterMCAsmParser(Target &T) {
901
78
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
78
  }
SystemZAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::SystemZAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
26
  RegisterMCAsmParser(Target &T) {
901
26
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
26
  }
X86AsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::X86AsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
52
  RegisterMCAsmParser(Target &T) {
901
52
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
52
  }
llvm_ks::RegisterMCAsmParser<llvm_ks::RISCVAsmParser>::RegisterMCAsmParser(llvm_ks::Target&)
Line
Count
Source
900
52
  RegisterMCAsmParser(Target &T) {
901
52
    TargetRegistry::RegisterMCAsmParser(T, &Allocator);
902
52
  }
903
904
private:
905
  static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
906
                                      MCAsmParser &P, const MCInstrInfo &MII,
907
128k
                                      const MCTargetOptions &Options) {
908
128k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
128k
  }
AArch64AsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::AArch64AsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
1.62k
                                      const MCTargetOptions &Options) {
908
1.62k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
1.62k
  }
ARMAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::ARMAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
60.6k
                                      const MCTargetOptions &Options) {
908
60.6k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
60.6k
  }
HexagonAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::HexagonAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
3.08k
                                      const MCTargetOptions &Options) {
908
3.08k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
3.08k
  }
MipsAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::MipsAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
5.17k
                                      const MCTargetOptions &Options) {
908
5.17k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
5.17k
  }
PPCAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::PPCAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
5.77k
                                      const MCTargetOptions &Options) {
908
5.77k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
5.77k
  }
SparcAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::SparcAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
11.2k
                                      const MCTargetOptions &Options) {
908
11.2k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
11.2k
  }
SystemZAsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::SystemZAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
53
                                      const MCTargetOptions &Options) {
908
53
    return new MCAsmParserImpl(STI, P, MII, Options);
909
53
  }
X86AsmParser.cpp:llvm_ks::RegisterMCAsmParser<(anonymous namespace)::X86AsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
14.9k
                                      const MCTargetOptions &Options) {
908
14.9k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
14.9k
  }
llvm_ks::RegisterMCAsmParser<llvm_ks::RISCVAsmParser>::Allocator(llvm_ks::MCSubtargetInfo const&, llvm_ks::MCAsmParser&, llvm_ks::MCInstrInfo const&, llvm_ks::MCTargetOptions const&)
Line
Count
Source
907
25.4k
                                      const MCTargetOptions &Options) {
908
25.4k
    return new MCAsmParserImpl(STI, P, MII, Options);
909
25.4k
  }
910
};
911
912
/// RegisterAsmPrinter - Helper template for registering a target specific
913
/// assembly printer, for use in the target machine initialization
914
/// function. Usage:
915
///
916
/// extern "C" void LLVMInitializeFooAsmPrinter() {
917
///   extern Target TheFooTarget;
918
///   RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
919
/// }
920
template <class AsmPrinterImpl> struct RegisterAsmPrinter {
921
  RegisterAsmPrinter(Target &T) {
922
    TargetRegistry::RegisterAsmPrinter(T, &Allocator);
923
  }
924
925
private:
926
  static AsmPrinter *Allocator(TargetMachine &TM,
927
                               std::unique_ptr<MCStreamer> &&Streamer) {
928
    return new AsmPrinterImpl(TM, std::move(Streamer));
929
  }
930
};
931
932
/// RegisterMCCodeEmitter - Helper template for registering a target specific
933
/// machine code emitter, for use in the target initialization
934
/// function. Usage:
935
///
936
/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
937
///   extern Target TheFooTarget;
938
///   RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
939
/// }
940
template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
941
  RegisterMCCodeEmitter(Target &T) {
942
    TargetRegistry::RegisterMCCodeEmitter(T, &Allocator);
943
  }
944
945
private:
946
  static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
947
                                  const MCRegisterInfo & /*MRI*/,
948
                                  MCContext & /*Ctx*/) {
949
    return new MCCodeEmitterImpl();
950
  }
951
};
952
}
953
954
#endif