LLVM 22.0.0git
TargetRegistry.h
Go to the documentation of this file.
1//===- MC/TargetRegistry.h - Target Registration ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file exposes the TargetRegistry interface, which tools can use to access
10// the appropriate target specific classes (TargetMachine, AsmPrinter, etc.)
11// which have been registered.
12//
13// Target specific class implementations should register themselves using the
14// appropriate TargetRegistry interfaces.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_MC_TARGETREGISTRY_H
19#define LLVM_MC_TARGETREGISTRY_H
20
22#include "llvm/ADT/StringRef.h"
30#include <cassert>
31#include <cstddef>
32#include <iterator>
33#include <memory>
34#include <optional>
35#include <string>
36
37namespace llvm {
38
39class AsmPrinter;
40class MCAsmBackend;
41class MCAsmInfo;
42class MCAsmParser;
43class MCCodeEmitter;
44class MCContext;
45class MCDisassembler;
46class MCInstPrinter;
47class MCInstrAnalysis;
48class MCInstrInfo;
49class MCObjectWriter;
50class MCRegisterInfo;
52class MCStreamer;
53class MCSubtargetInfo;
54class MCSymbolizer;
56class MCTargetOptions;
58class raw_ostream;
59class TargetMachine;
60class TargetOptions;
61namespace mca {
62class CustomBehaviour;
65struct SourceMgr;
66} // namespace mca
67
69// Takes ownership of \p TAB and \p CE.
70
71/// Create a machine code streamer which will print out assembly for the native
72/// target, suitable for compiling with a native assembler.
73///
74/// \param InstPrint - If given, the instruction printer to use. If not given
75/// the MCInst representation will be printed. This method takes ownership of
76/// InstPrint.
77///
78/// \param CE - If given, a code emitter to use to show the instruction
79/// encoding inline with the assembly. This method takes ownership of \p CE.
80///
81/// \param TAB - If given, a target asm backend to use to show the fixup
82/// information in conjunction with encoding information. This method takes
83/// ownership of \p TAB.
84///
85/// \param ShowInst - Whether to show the MCInst representation inline with
86/// the assembly.
88createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
89 std::unique_ptr<MCInstPrinter> InstPrint,
90 std::unique_ptr<MCCodeEmitter> CE,
91 std::unique_ptr<MCAsmBackend> TAB);
92
94 std::unique_ptr<MCAsmBackend> &&TAB,
95 std::unique_ptr<MCObjectWriter> &&OW,
96 std::unique_ptr<MCCodeEmitter> &&CE);
98 std::unique_ptr<MCAsmBackend> &&TAB,
99 std::unique_ptr<MCObjectWriter> &&OW,
100 std::unique_ptr<MCCodeEmitter> &&CE);
102 std::unique_ptr<MCAsmBackend> &&TAB,
103 std::unique_ptr<MCObjectWriter> &&OW,
104 std::unique_ptr<MCCodeEmitter> &&CE,
105 bool DWARFMustBeAtTheEnd,
106 bool LabelSections = false);
108 std::unique_ptr<MCAsmBackend> &&TAB,
109 std::unique_ptr<MCObjectWriter> &&OW,
110 std::unique_ptr<MCCodeEmitter> &&CE);
112 std::unique_ptr<MCAsmBackend> &&TAB,
113 std::unique_ptr<MCObjectWriter> &&OW,
114 std::unique_ptr<MCCodeEmitter> &&CE);
116createDXContainerStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
117 std::unique_ptr<MCObjectWriter> &&OW,
118 std::unique_ptr<MCCodeEmitter> &&CE);
119
121 MCContext &Ctx);
122
124createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
125 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
126 MCContext *Ctx, std::unique_ptr<MCRelocationInfo> &&RelInfo);
127
130 const MCInstrInfo &MCII);
131
134
137
138/// Target - Wrapper for Target specific information.
139///
140/// For registration purposes, this is a POD type so that targets can be
141/// registered without the use of static constructors.
142///
143/// Targets should implement a single global instance of this class (which
144/// will be zero initialized), and pass that instance to the TargetRegistry as
145/// part of their initialization.
146class Target {
147public:
148 friend struct TargetRegistry;
149
151
153 const Triple &TT,
154 const MCTargetOptions &Options);
156 bool PIC,
157 bool LargeCodeModel);
160 using MCRegInfoCtorFnTy = MCRegisterInfo *(*)(const Triple &TT);
162 StringRef CPU,
163 StringRef Features);
165 *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features,
166 const TargetOptions &Options, std::optional<Reloc::Model> RM,
167 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT);
168 // If it weren't for layering issues (this header is in llvm/Support, but
169 // depends on MC?) this should take the Streamer by value rather than rvalue
170 // reference.
172 TargetMachine &TM, std::unique_ptr<MCStreamer> &&Streamer);
174 const MCSubtargetInfo &STI,
175 const MCRegisterInfo &MRI,
176 const MCTargetOptions &Options);
178 const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII,
179 const MCTargetOptions &Options);
181 const MCSubtargetInfo &STI,
182 MCContext &Ctx);
184 unsigned SyntaxVariant,
185 const MCAsmInfo &MAI,
186 const MCInstrInfo &MII,
187 const MCRegisterInfo &MRI);
189 MCContext &Ctx);
191 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
192 std::unique_ptr<MCAsmBackend> &&TAB,
193 std::unique_ptr<MCObjectWriter> &&OW,
194 std::unique_ptr<MCCodeEmitter> &&Emitter);
196 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
197 std::unique_ptr<MCObjectWriter> &&OW,
198 std::unique_ptr<MCCodeEmitter> &&Emitter);
200 MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
201 std::unique_ptr<MCObjectWriter> &&OW,
202 std::unique_ptr<MCCodeEmitter> &&Emitter);
204 MCStreamer *(*)(const Triple &T, MCContext &Ctx,
205 std::unique_ptr<MCAsmBackend> &&TAB,
206 std::unique_ptr<MCObjectWriter> &&OW,
207 std::unique_ptr<MCCodeEmitter> &&Emitter);
208
212 MCInstPrinter *InstPrint);
214 *(*)(MCContext & Ctx, std::unique_ptr<formatted_raw_ostream> OS,
215 std::unique_ptr<MCInstPrinter> IP, std::unique_ptr<MCCodeEmitter> CE,
216 std::unique_ptr<MCAsmBackend> TAB);
218 MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI);
220 MCContext &Ctx);
222 MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo,
223 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
224 MCContext *Ctx,
225 std::unique_ptr<MCRelocationInfo> &&RelInfo);
226
229 const mca::SourceMgr &SrcMgr,
230 const MCInstrInfo &MCII);
231
234 const MCInstrInfo &MCII);
235
238 const MCInstrInfo &MCII);
239
240private:
241 /// Next - The next registered target in the linked list, maintained by the
242 /// TargetRegistry.
243 Target *Next;
244
245 /// The target function for checking if an architecture is supported.
246 ArchMatchFnTy ArchMatchFn;
247
248 /// Name - The target name.
249 const char *Name;
250
251 /// ShortDesc - A short description of the target.
252 const char *ShortDesc;
253
254 /// BackendName - The name of the backend implementation. This must match the
255 /// name of the 'def X : Target ...' in TableGen.
256 const char *BackendName;
257
258 /// HasJIT - Whether this target supports the JIT.
259 bool HasJIT;
260
261 /// MCAsmInfoCtorFn - Constructor function for this target's MCAsmInfo, if
262 /// registered.
263 MCAsmInfoCtorFnTy MCAsmInfoCtorFn;
264
265 /// Constructor function for this target's MCObjectFileInfo, if registered.
266 MCObjectFileInfoCtorFnTy MCObjectFileInfoCtorFn;
267
268 /// MCInstrInfoCtorFn - Constructor function for this target's MCInstrInfo,
269 /// if registered.
270 MCInstrInfoCtorFnTy MCInstrInfoCtorFn;
271
272 /// MCInstrAnalysisCtorFn - Constructor function for this target's
273 /// MCInstrAnalysis, if registered.
274 MCInstrAnalysisCtorFnTy MCInstrAnalysisCtorFn;
275
276 /// MCRegInfoCtorFn - Constructor function for this target's MCRegisterInfo,
277 /// if registered.
278 MCRegInfoCtorFnTy MCRegInfoCtorFn;
279
280 /// MCSubtargetInfoCtorFn - Constructor function for this target's
281 /// MCSubtargetInfo, if registered.
282 MCSubtargetInfoCtorFnTy MCSubtargetInfoCtorFn;
283
284 /// TargetMachineCtorFn - Construction function for this target's
285 /// TargetMachine, if registered.
286 TargetMachineCtorTy TargetMachineCtorFn;
287
288 /// MCAsmBackendCtorFn - Construction function for this target's
289 /// MCAsmBackend, if registered.
290 MCAsmBackendCtorTy MCAsmBackendCtorFn;
291
292 /// MCAsmParserCtorFn - Construction function for this target's
293 /// MCTargetAsmParser, if registered.
294 MCAsmParserCtorTy MCAsmParserCtorFn;
295
296 /// AsmPrinterCtorFn - Construction function for this target's AsmPrinter,
297 /// if registered.
298 AsmPrinterCtorTy AsmPrinterCtorFn;
299
300 /// MCDisassemblerCtorFn - Construction function for this target's
301 /// MCDisassembler, if registered.
302 MCDisassemblerCtorTy MCDisassemblerCtorFn;
303
304 /// MCInstPrinterCtorFn - Construction function for this target's
305 /// MCInstPrinter, if registered.
306 MCInstPrinterCtorTy MCInstPrinterCtorFn;
307
308 /// MCCodeEmitterCtorFn - Construction function for this target's
309 /// CodeEmitter, if registered.
310 MCCodeEmitterCtorTy MCCodeEmitterCtorFn;
311
312 // Construction functions for the various object formats, if registered.
313 COFFStreamerCtorTy COFFStreamerCtorFn = nullptr;
314 MachOStreamerCtorTy MachOStreamerCtorFn = nullptr;
315 ELFStreamerCtorTy ELFStreamerCtorFn = nullptr;
316 XCOFFStreamerCtorTy XCOFFStreamerCtorFn = nullptr;
317
318 /// Construction function for this target's null TargetStreamer, if
319 /// registered (default = nullptr).
320 NullTargetStreamerCtorTy NullTargetStreamerCtorFn = nullptr;
321
322 /// Construction function for this target's asm TargetStreamer, if
323 /// registered (default = nullptr).
324 AsmTargetStreamerCtorTy AsmTargetStreamerCtorFn = nullptr;
325
326 /// Construction function for this target's AsmStreamer, if
327 /// registered (default = nullptr).
328 AsmStreamerCtorTy AsmStreamerCtorFn = nullptr;
329
330 /// Construction function for this target's obj TargetStreamer, if
331 /// registered (default = nullptr).
332 ObjectTargetStreamerCtorTy ObjectTargetStreamerCtorFn = nullptr;
333
334 /// MCRelocationInfoCtorFn - Construction function for this target's
335 /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo)
336 MCRelocationInfoCtorTy MCRelocationInfoCtorFn = nullptr;
337
338 /// MCSymbolizerCtorFn - Construction function for this target's
339 /// MCSymbolizer, if registered (default = llvm::createMCSymbolizer)
340 MCSymbolizerCtorTy MCSymbolizerCtorFn = nullptr;
341
342 /// CustomBehaviourCtorFn - Construction function for this target's
343 /// CustomBehaviour, if registered (default = nullptr).
344 CustomBehaviourCtorTy CustomBehaviourCtorFn = nullptr;
345
346 /// InstrPostProcessCtorFn - Construction function for this target's
347 /// InstrPostProcess, if registered (default = nullptr).
348 InstrPostProcessCtorTy InstrPostProcessCtorFn = nullptr;
349
350 /// InstrumentManagerCtorFn - Construction function for this target's
351 /// InstrumentManager, if registered (default = nullptr).
352 InstrumentManagerCtorTy InstrumentManagerCtorFn = nullptr;
353
354public:
355 Target() = default;
356
357 /// @name Target Information
358 /// @{
359
360 // getNext - Return the next registered target.
361 const Target *getNext() const { return Next; }
362
363 /// getName - Get the target name.
364 const char *getName() const { return Name; }
365
366 /// getShortDescription - Get a short description of the target.
367 const char *getShortDescription() const { return ShortDesc; }
368
369 /// getBackendName - Get the backend name.
370 const char *getBackendName() const { return BackendName; }
371
372 /// @}
373 /// @name Feature Predicates
374 /// @{
375
376 /// hasJIT - Check if this targets supports the just-in-time compilation.
377 bool hasJIT() const { return HasJIT; }
378
379 /// hasTargetMachine - Check if this target supports code generation.
380 bool hasTargetMachine() const { return TargetMachineCtorFn != nullptr; }
381
382 /// hasMCAsmBackend - Check if this target supports .o generation.
383 bool hasMCAsmBackend() const { return MCAsmBackendCtorFn != nullptr; }
384
385 /// hasMCAsmParser - Check if this target supports assembly parsing.
386 bool hasMCAsmParser() const { return MCAsmParserCtorFn != nullptr; }
387
388 /// @}
389 /// @name Feature Constructors
390 /// @{
391
392 [[deprecated("Use overload accepting Triple instead")]]
394 const MCTargetOptions &Options) const {
395 if (!MCAsmInfoCtorFn)
396 return nullptr;
397 return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
398 }
399
400 /// Create a MCAsmInfo implementation for the specified
401 /// target triple.
402 ///
403 /// \param TheTriple This argument is used to determine the target machine
404 /// feature set; it should always be provided. Generally this should be
405 /// either the target triple from the module, or the target triple of the
406 /// host if that does not exist.
408 const MCTargetOptions &Options) const {
409 if (!MCAsmInfoCtorFn)
410 return nullptr;
411 return MCAsmInfoCtorFn(MRI, TheTriple, Options);
412 }
413
414 /// Create a MCObjectFileInfo implementation for the specified target
415 /// triple.
416 ///
418 bool LargeCodeModel = false) const {
419 if (!MCObjectFileInfoCtorFn) {
421 MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
422 return MOFI;
423 }
424 return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
425 }
426
427 /// createMCInstrInfo - Create a MCInstrInfo implementation.
428 ///
430 if (!MCInstrInfoCtorFn)
431 return nullptr;
432 return MCInstrInfoCtorFn();
433 }
434
435 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
436 ///
438 if (!MCInstrAnalysisCtorFn)
439 return nullptr;
440 return MCInstrAnalysisCtorFn(Info);
441 }
442
443 [[deprecated("Use overload accepting Triple instead")]]
445 if (!MCRegInfoCtorFn)
446 return nullptr;
447 return MCRegInfoCtorFn(Triple(TT));
448 }
449
450 /// Create a MCRegisterInfo implementation.
452 if (!MCRegInfoCtorFn)
453 return nullptr;
454 return MCRegInfoCtorFn(TT);
455 }
456
457 [[deprecated("Use overload accepting Triple instead")]]
459 StringRef Features) const {
460 if (!MCSubtargetInfoCtorFn)
461 return nullptr;
462 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
463 }
464
465 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
466 ///
467 /// \param TheTriple This argument is used to determine the target machine
468 /// feature set; it should always be provided. Generally this should be
469 /// either the target triple from the module, or the target triple of the
470 /// host if that does not exist.
471 /// \param CPU This specifies the name of the target CPU.
472 /// \param Features This specifies the string representation of the
473 /// additional target features.
475 StringRef Features) const {
476 if (!MCSubtargetInfoCtorFn)
477 return nullptr;
478 return MCSubtargetInfoCtorFn(TheTriple, CPU, Features);
479 }
480
481 /// createTargetMachine - Create a target specific machine implementation
482 /// for the specified \p Triple.
483 ///
484 /// \param TT This argument is used to determine the target machine
485 /// feature set; it should always be provided. Generally this should be
486 /// either the target triple from the module, or the target triple of the
487 /// host if that does not exist.
489 const Triple &TT, StringRef CPU, StringRef Features,
490 const TargetOptions &Options, std::optional<Reloc::Model> RM,
491 std::optional<CodeModel::Model> CM = std::nullopt,
492 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
493 if (!TargetMachineCtorFn)
494 return nullptr;
495 return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
496 JIT);
497 }
498
499 [[deprecated("Use overload accepting Triple instead")]]
501 StringRef TT, StringRef CPU, StringRef Features,
502 const TargetOptions &Options, std::optional<Reloc::Model> RM,
503 std::optional<CodeModel::Model> CM = std::nullopt,
504 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
505 return createTargetMachine(Triple(TT), CPU, Features, Options, RM, CM, OL,
506 JIT);
507 }
508
509 /// createMCAsmBackend - Create a target specific assembly parser.
511 const MCRegisterInfo &MRI,
512 const MCTargetOptions &Options) const {
513 if (!MCAsmBackendCtorFn)
514 return nullptr;
515 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
516 }
517
518 /// createMCAsmParser - Create a target specific assembly parser.
519 ///
520 /// \param Parser The target independent parser implementation to use for
521 /// parsing and lexing.
523 MCAsmParser &Parser,
524 const MCInstrInfo &MII,
525 const MCTargetOptions &Options) const {
526 if (!MCAsmParserCtorFn)
527 return nullptr;
528 return MCAsmParserCtorFn(STI, Parser, MII, Options);
529 }
530
531 /// createAsmPrinter - Create a target specific assembly printer pass. This
532 /// takes ownership of the MCStreamer object.
534 std::unique_ptr<MCStreamer> &&Streamer) const {
535 if (!AsmPrinterCtorFn)
536 return nullptr;
537 return AsmPrinterCtorFn(TM, std::move(Streamer));
538 }
539
541 MCContext &Ctx) const {
542 if (!MCDisassemblerCtorFn)
543 return nullptr;
544 return MCDisassemblerCtorFn(*this, STI, Ctx);
545 }
546
547 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
548 const MCAsmInfo &MAI,
549 const MCInstrInfo &MII,
550 const MCRegisterInfo &MRI) const {
551 if (!MCInstPrinterCtorFn)
552 return nullptr;
553 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
554 }
555
556 /// createMCCodeEmitter - Create a target specific code emitter.
558 MCContext &Ctx) const {
559 if (!MCCodeEmitterCtorFn)
560 return nullptr;
561 return MCCodeEmitterCtorFn(II, Ctx);
562 }
563
564 /// Create a target specific MCStreamer.
565 ///
566 /// \param T The target triple.
567 /// \param Ctx The target context.
568 /// \param TAB The target assembler backend object. Takes ownership.
569 /// \param OW The stream object.
570 /// \param Emitter The target independent assembler object.Takes ownership.
572 const Triple &T, MCContext &Ctx, std::unique_ptr<MCAsmBackend> TAB,
573 std::unique_ptr<MCObjectWriter> OW,
574 std::unique_ptr<MCCodeEmitter> Emitter, const MCSubtargetInfo &STI) const;
575
577 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
578 std::unique_ptr<MCInstPrinter> IP,
579 std::unique_ptr<MCCodeEmitter> CE,
580 std::unique_ptr<MCAsmBackend> TAB) const;
581
584 MCInstPrinter *InstPrint) const {
585 if (AsmTargetStreamerCtorFn)
586 return AsmTargetStreamerCtorFn(S, OS, InstPrint);
587 return nullptr;
588 }
589
593 return S;
594 }
595
597 if (NullTargetStreamerCtorFn)
598 return NullTargetStreamerCtorFn(S);
599 return nullptr;
600 }
601
602 [[deprecated("Use overload accepting Triple instead")]]
606
607 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
608 ///
609 /// \param TT The target triple.
610 /// \param Ctx The target context.
612 MCContext &Ctx) const {
613 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
614 ? MCRelocationInfoCtorFn
616 return Fn(TT, Ctx);
617 }
618
619 [[deprecated("Use overload accepting Triple instead")]]
622 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
623 MCContext *Ctx,
624 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
625 return createMCSymbolizer(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
626 std::move(RelInfo));
627 }
628
629 /// createMCSymbolizer - Create a target specific MCSymbolizer.
630 ///
631 /// \param TT The target triple.
632 /// \param GetOpInfo The function to get the symbolic information for
633 /// operands.
634 /// \param SymbolLookUp The function to lookup a symbol name.
635 /// \param DisInfo The pointer to the block of symbolic information for above
636 /// call
637 /// back.
638 /// \param Ctx The target context.
639 /// \param RelInfo The relocation information for this target. Takes
640 /// ownership.
643 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
644 MCContext *Ctx,
645 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
647 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
648 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
649 }
650
651 /// createCustomBehaviour - Create a target specific CustomBehaviour.
652 /// This class is used by llvm-mca and requires backend functionality.
654 const mca::SourceMgr &SrcMgr,
655 const MCInstrInfo &MCII) const {
656 if (CustomBehaviourCtorFn)
657 return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
658 return nullptr;
659 }
660
661 /// createInstrPostProcess - Create a target specific InstrPostProcess.
662 /// This class is used by llvm-mca and requires backend functionality.
664 const MCInstrInfo &MCII) const {
665 if (InstrPostProcessCtorFn)
666 return InstrPostProcessCtorFn(STI, MCII);
667 return nullptr;
668 }
669
670 /// createInstrumentManager - Create a target specific
671 /// InstrumentManager. This class is used by llvm-mca and requires
672 /// backend functionality.
675 const MCInstrInfo &MCII) const {
676 if (InstrumentManagerCtorFn)
677 return InstrumentManagerCtorFn(STI, MCII);
678 return nullptr;
679 }
680
681 /// @}
682};
683
684/// TargetRegistry - Generic interface to target specific features.
686 // FIXME: Make this a namespace, probably just move all the Register*
687 // functions into Target (currently they all just set members on the Target
688 // anyway, and Target friends this class so those functions can...
689 // function).
690 TargetRegistry() = delete;
691
692 class iterator {
693 friend struct TargetRegistry;
694
695 const Target *Current = nullptr;
696
697 explicit iterator(Target *T) : Current(T) {}
698
699 public:
700 using iterator_category = std::forward_iterator_tag;
702 using difference_type = std::ptrdiff_t;
705
706 iterator() = default;
707
708 bool operator==(const iterator &x) const { return Current == x.Current; }
709 bool operator!=(const iterator &x) const { return !operator==(x); }
710
711 // Iterator traversal: forward iteration only
712 iterator &operator++() { // Preincrement
713 assert(Current && "Cannot increment end iterator!");
714 Current = Current->getNext();
715 return *this;
716 }
717 iterator operator++(int) { // Postincrement
718 iterator tmp = *this;
719 ++*this;
720 return tmp;
721 }
722
723 const Target &operator*() const {
724 assert(Current && "Cannot dereference end iterator!");
725 return *Current;
726 }
727
728 const Target *operator->() const { return &operator*(); }
729 };
730
731 /// printRegisteredTargetsForVersion - Print the registered targets
732 /// appropriately for inclusion in a tool's version output.
734
735 /// @name Registry Access
736 /// @{
737
739
740 /// lookupTarget - Lookup a target based on a target triple.
741 ///
742 /// \param TripleStr - The triple to use for finding a target.
743 /// \param Error - On failure, an error string describing why no target was
744 /// found.
745 // TODO: Drop this in favor of the method accepting Triple.
746 static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
747 return lookupTarget(Triple(TripleStr), Error);
748 }
749
750 /// lookupTarget - Lookup a target based on a target triple.
751 ///
752 /// \param Triple - The triple to use for finding a target.
753 /// \param Error - On failure, an error string describing why no target was
754 /// found.
755 LLVM_ABI static const Target *lookupTarget(const Triple &TheTriple,
756 std::string &Error);
757
758 /// lookupTarget - Lookup a target based on an architecture name
759 /// and a target triple. If the architecture name is non-empty,
760 /// then the lookup is done by architecture. Otherwise, the target
761 /// triple is used.
762 ///
763 /// \param ArchName - The architecture to use for finding a target.
764 /// \param TheTriple - The triple to use for finding a target. The
765 /// triple is updated with canonical architecture name if a lookup
766 /// by architecture is done.
767 /// \param Error - On failure, an error string describing why no target was
768 /// found.
769 LLVM_ABI static const Target *
770 lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error);
771
772 /// @}
773 /// @name Target Registration
774 /// @{
775
776 /// RegisterTarget - Register the given target. Attempts to register a
777 /// target which has already been registered will be ignored.
778 ///
779 /// Clients are responsible for ensuring that registration doesn't occur
780 /// while another thread is attempting to access the registry. Typically
781 /// this is done by initializing all targets at program startup.
782 ///
783 /// @param T - The target being registered.
784 /// @param Name - The target name. This should be a static string.
785 /// @param ShortDesc - A short target description. This should be a static
786 /// string.
787 /// @param BackendName - The name of the backend. This should be a static
788 /// string that is the same for all targets that share a backend
789 /// implementation and must match the name used in the 'def X : Target ...' in
790 /// TableGen.
791 /// @param ArchMatchFn - The arch match checking function for this target.
792 /// @param HasJIT - Whether the target supports JIT code
793 /// generation.
794 LLVM_ABI static void RegisterTarget(Target &T, const char *Name,
795 const char *ShortDesc,
796 const char *BackendName,
797 Target::ArchMatchFnTy ArchMatchFn,
798 bool HasJIT = false);
799
800 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
801 /// given target.
802 ///
803 /// Clients are responsible for ensuring that registration doesn't occur
804 /// while another thread is attempting to access the registry. Typically
805 /// this is done by initializing all targets at program startup.
806 ///
807 /// @param T - The target being registered.
808 /// @param Fn - A function to construct a MCAsmInfo for the target.
810 T.MCAsmInfoCtorFn = Fn;
811 }
812
813 /// Register a MCObjectFileInfo implementation for the given target.
814 ///
815 /// Clients are responsible for ensuring that registration doesn't occur
816 /// while another thread is attempting to access the registry. Typically
817 /// this is done by initializing all targets at program startup.
818 ///
819 /// @param T - The target being registered.
820 /// @param Fn - A function to construct a MCObjectFileInfo for the target.
823 T.MCObjectFileInfoCtorFn = Fn;
824 }
825
826 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
827 /// given target.
828 ///
829 /// Clients are responsible for ensuring that registration doesn't occur
830 /// while another thread is attempting to access the registry. Typically
831 /// this is done by initializing all targets at program startup.
832 ///
833 /// @param T - The target being registered.
834 /// @param Fn - A function to construct a MCInstrInfo for the target.
836 T.MCInstrInfoCtorFn = Fn;
837 }
838
839 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
840 /// the given target.
843 T.MCInstrAnalysisCtorFn = Fn;
844 }
845
846 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
847 /// given target.
848 ///
849 /// Clients are responsible for ensuring that registration doesn't occur
850 /// while another thread is attempting to access the registry. Typically
851 /// this is done by initializing all targets at program startup.
852 ///
853 /// @param T - The target being registered.
854 /// @param Fn - A function to construct a MCRegisterInfo for the target.
856 T.MCRegInfoCtorFn = Fn;
857 }
858
859 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
860 /// the given target.
861 ///
862 /// Clients are responsible for ensuring that registration doesn't occur
863 /// while another thread is attempting to access the registry. Typically
864 /// this is done by initializing all targets at program startup.
865 ///
866 /// @param T - The target being registered.
867 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
870 T.MCSubtargetInfoCtorFn = Fn;
871 }
872
873 /// RegisterTargetMachine - Register a TargetMachine implementation for the
874 /// given target.
875 ///
876 /// Clients are responsible for ensuring that registration doesn't occur
877 /// while another thread is attempting to access the registry. Typically
878 /// this is done by initializing all targets at program startup.
879 ///
880 /// @param T - The target being registered.
881 /// @param Fn - A function to construct a TargetMachine for the target.
883 T.TargetMachineCtorFn = Fn;
884 }
885
886 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
887 /// given target.
888 ///
889 /// Clients are responsible for ensuring that registration doesn't occur
890 /// while another thread is attempting to access the registry. Typically
891 /// this is done by initializing all targets at program startup.
892 ///
893 /// @param T - The target being registered.
894 /// @param Fn - A function to construct an AsmBackend for the target.
896 T.MCAsmBackendCtorFn = Fn;
897 }
898
899 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
900 /// the given target.
901 ///
902 /// Clients are responsible for ensuring that registration doesn't occur
903 /// while another thread is attempting to access the registry. Typically
904 /// this is done by initializing all targets at program startup.
905 ///
906 /// @param T - The target being registered.
907 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
909 T.MCAsmParserCtorFn = Fn;
910 }
911
912 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
913 /// target.
914 ///
915 /// Clients are responsible for ensuring that registration doesn't occur
916 /// while another thread is attempting to access the registry. Typically
917 /// this is done by initializing all targets at program startup.
918 ///
919 /// @param T - The target being registered.
920 /// @param Fn - A function to construct an AsmPrinter for the target.
922 T.AsmPrinterCtorFn = Fn;
923 }
924
925 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
926 /// the given target.
927 ///
928 /// Clients are responsible for ensuring that registration doesn't occur
929 /// while another thread is attempting to access the registry. Typically
930 /// this is done by initializing all targets at program startup.
931 ///
932 /// @param T - The target being registered.
933 /// @param Fn - A function to construct an MCDisassembler for the target.
936 T.MCDisassemblerCtorFn = Fn;
937 }
938
939 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
940 /// given target.
941 ///
942 /// Clients are responsible for ensuring that registration doesn't occur
943 /// while another thread is attempting to access the registry. Typically
944 /// this is done by initializing all targets at program startup.
945 ///
946 /// @param T - The target being registered.
947 /// @param Fn - A function to construct an MCInstPrinter for the target.
949 T.MCInstPrinterCtorFn = Fn;
950 }
951
952 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
953 /// given target.
954 ///
955 /// Clients are responsible for ensuring that registration doesn't occur
956 /// while another thread is attempting to access the registry. Typically
957 /// this is done by initializing all targets at program startup.
958 ///
959 /// @param T - The target being registered.
960 /// @param Fn - A function to construct an MCCodeEmitter for the target.
962 T.MCCodeEmitterCtorFn = Fn;
963 }
964
966 T.COFFStreamerCtorFn = Fn;
967 }
968
970 T.MachOStreamerCtorFn = Fn;
971 }
972
974 T.ELFStreamerCtorFn = Fn;
975 }
976
978 T.XCOFFStreamerCtorFn = Fn;
979 }
980
983 T.NullTargetStreamerCtorFn = Fn;
984 }
985
987 T.AsmStreamerCtorFn = Fn;
988 }
989
992 T.AsmTargetStreamerCtorFn = Fn;
993 }
994
995 static void
998 T.ObjectTargetStreamerCtorFn = Fn;
999 }
1000
1001 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
1002 /// implementation for the given target.
1003 ///
1004 /// Clients are responsible for ensuring that registration doesn't occur
1005 /// while another thread is attempting to access the registry. Typically
1006 /// this is done by initializing all targets at program startup.
1007 ///
1008 /// @param T - The target being registered.
1009 /// @param Fn - A function to construct an MCRelocationInfo for the target.
1012 T.MCRelocationInfoCtorFn = Fn;
1013 }
1014
1015 /// RegisterMCSymbolizer - Register an MCSymbolizer
1016 /// implementation for the given target.
1017 ///
1018 /// Clients are responsible for ensuring that registration doesn't occur
1019 /// while another thread is attempting to access the registry. Typically
1020 /// this is done by initializing all targets at program startup.
1021 ///
1022 /// @param T - The target being registered.
1023 /// @param Fn - A function to construct an MCSymbolizer for the target.
1025 T.MCSymbolizerCtorFn = Fn;
1026 }
1027
1028 /// RegisterCustomBehaviour - Register a CustomBehaviour
1029 /// implementation for the given target.
1030 ///
1031 /// Clients are responsible for ensuring that registration doesn't occur
1032 /// while another thread is attempting to access the registry. Typically
1033 /// this is done by initializing all targets at program startup.
1034 ///
1035 /// @param T - The target being registered.
1036 /// @param Fn - A function to construct a CustomBehaviour for the target.
1039 T.CustomBehaviourCtorFn = Fn;
1040 }
1041
1042 /// RegisterInstrPostProcess - Register an InstrPostProcess
1043 /// implementation for the given target.
1044 ///
1045 /// Clients are responsible for ensuring that registration doesn't occur
1046 /// while another thread is attempting to access the registry. Typically
1047 /// this is done by initializing all targets at program startup.
1048 ///
1049 /// @param T - The target being registered.
1050 /// @param Fn - A function to construct an InstrPostProcess for the target.
1053 T.InstrPostProcessCtorFn = Fn;
1054 }
1055
1056 /// RegisterInstrumentManager - Register an InstrumentManager
1057 /// implementation for the given target.
1058 ///
1059 /// Clients are responsible for ensuring that registration doesn't occur
1060 /// while another thread is attempting to access the registry. Typically
1061 /// this is done by initializing all targets at program startup.
1062 ///
1063 /// @param T - The target being registered.
1064 /// @param Fn - A function to construct an InstrumentManager for the
1065 /// target.
1068 T.InstrumentManagerCtorFn = Fn;
1069 }
1070
1071 /// @}
1072};
1073
1074//===--------------------------------------------------------------------===//
1075
1076/// RegisterTarget - Helper template for registering a target, for use in the
1077/// target's initialization function. Usage:
1078///
1079///
1080/// Target &getTheFooTarget() { // The global target instance.
1081/// static Target TheFooTarget;
1082/// return TheFooTarget;
1083/// }
1084/// extern "C" void LLVMInitializeFooTargetInfo() {
1085/// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
1086/// description", "Foo" /* Backend Name */);
1087/// }
1088template <Triple::ArchType TargetArchType = Triple::UnknownArch,
1089 bool HasJIT = false>
1091 RegisterTarget(Target &T, const char *Name, const char *Desc,
1092 const char *BackendName) {
1093 TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
1094 HasJIT);
1095 }
1096
1097 static bool getArchMatch(Triple::ArchType Arch) {
1098 return Arch == TargetArchType;
1099 }
1100};
1101
1102/// RegisterMCAsmInfo - Helper template for registering a target assembly info
1103/// implementation. This invokes the static "Create" method on the class to
1104/// actually do the construction. Usage:
1105///
1106/// extern "C" void LLVMInitializeFooTarget() {
1107/// extern Target TheFooTarget;
1108/// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
1109/// }
1110template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
1114
1115private:
1116 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
1117 const MCTargetOptions &Options) {
1118 return new MCAsmInfoImpl(TT, Options);
1119 }
1120};
1121
1122/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
1123/// implementation. This invokes the specified function to do the
1124/// construction. Usage:
1125///
1126/// extern "C" void LLVMInitializeFooTarget() {
1127/// extern Target TheFooTarget;
1128/// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
1129/// }
1135
1136/// Helper template for registering a target object file info implementation.
1137/// This invokes the static "Create" method on the class to actually do the
1138/// construction. Usage:
1139///
1140/// extern "C" void LLVMInitializeFooTarget() {
1141/// extern Target TheFooTarget;
1142/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
1143/// }
1144template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
1148
1149private:
1150 static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
1151 bool LargeCodeModel = false) {
1152 return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
1153 }
1154};
1155
1156/// Helper template for registering a target object file info implementation.
1157/// This invokes the specified function to do the construction. Usage:
1158///
1159/// extern "C" void LLVMInitializeFooTarget() {
1160/// extern Target TheFooTarget;
1161/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
1162/// }
1168
1169/// RegisterMCInstrInfo - Helper template for registering a target instruction
1170/// info implementation. This invokes the static "Create" method on the class
1171/// to actually do the construction. Usage:
1172///
1173/// extern "C" void LLVMInitializeFooTarget() {
1174/// extern Target TheFooTarget;
1175/// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
1176/// }
1177template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
1181
1182private:
1183 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
1184};
1185
1186/// RegisterMCInstrInfoFn - Helper template for registering a target
1187/// instruction info implementation. This invokes the specified function to
1188/// do the construction. Usage:
1189///
1190/// extern "C" void LLVMInitializeFooTarget() {
1191/// extern Target TheFooTarget;
1192/// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
1193/// }
1199
1200/// RegisterMCInstrAnalysis - Helper template for registering a target
1201/// instruction analyzer implementation. This invokes the static "Create"
1202/// method on the class to actually do the construction. Usage:
1203///
1204/// extern "C" void LLVMInitializeFooTarget() {
1205/// extern Target TheFooTarget;
1206/// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1207/// }
1208template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1212
1213private:
1214 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1215 return new MCInstrAnalysisImpl(Info);
1216 }
1217};
1218
1219/// RegisterMCInstrAnalysisFn - Helper template for registering a target
1220/// instruction analyzer implementation. This invokes the specified function
1221/// to do the construction. Usage:
1222///
1223/// extern "C" void LLVMInitializeFooTarget() {
1224/// extern Target TheFooTarget;
1225/// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1226/// }
1232
1233/// RegisterMCRegInfo - Helper template for registering a target register info
1234/// implementation. This invokes the static "Create" method on the class to
1235/// actually do the construction. Usage:
1236///
1237/// extern "C" void LLVMInitializeFooTarget() {
1238/// extern Target TheFooTarget;
1239/// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1240/// }
1241template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1245
1246private:
1247 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1248 return new MCRegisterInfoImpl();
1249 }
1250};
1251
1252/// RegisterMCRegInfoFn - Helper template for registering a target register
1253/// info implementation. This invokes the specified function to do the
1254/// construction. Usage:
1255///
1256/// extern "C" void LLVMInitializeFooTarget() {
1257/// extern Target TheFooTarget;
1258/// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1259/// }
1265
1266/// RegisterMCSubtargetInfo - Helper template for registering a target
1267/// subtarget info implementation. This invokes the static "Create" method
1268/// on the class to actually do the construction. Usage:
1269///
1270/// extern "C" void LLVMInitializeFooTarget() {
1271/// extern Target TheFooTarget;
1272/// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1273/// }
1274template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1278
1279private:
1280 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1281 StringRef /*FS*/) {
1282 return new MCSubtargetInfoImpl();
1283 }
1284};
1285
1286/// RegisterMCSubtargetInfoFn - Helper template for registering a target
1287/// subtarget info implementation. This invokes the specified function to
1288/// do the construction. Usage:
1289///
1290/// extern "C" void LLVMInitializeFooTarget() {
1291/// extern Target TheFooTarget;
1292/// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1293/// }
1299
1300/// RegisterTargetMachine - Helper template for registering a target machine
1301/// implementation, for use in the target machine initialization
1302/// function. Usage:
1303///
1304/// extern "C" void LLVMInitializeFooTarget() {
1305/// extern Target TheFooTarget;
1306/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1307/// }
1308template <class TargetMachineImpl> struct RegisterTargetMachine {
1312
1313private:
1314 static TargetMachine *
1315 Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1316 const TargetOptions &Options, std::optional<Reloc::Model> RM,
1317 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) {
1318 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1319 }
1320};
1321
1322/// RegisterMCAsmBackend - Helper template for registering a target specific
1323/// assembler backend. Usage:
1324///
1325/// extern "C" void LLVMInitializeFooMCAsmBackend() {
1326/// extern Target TheFooTarget;
1327/// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1328/// }
1329template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1333
1334private:
1335 static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1336 const MCRegisterInfo &MRI,
1337 const MCTargetOptions &Options) {
1338 return new MCAsmBackendImpl(T, STI, MRI);
1339 }
1340};
1341
1342/// RegisterMCAsmParser - Helper template for registering a target specific
1343/// assembly parser, for use in the target machine initialization
1344/// function. Usage:
1345///
1346/// extern "C" void LLVMInitializeFooMCAsmParser() {
1347/// extern Target TheFooTarget;
1348/// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1349/// }
1350template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1354
1355private:
1356 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1357 MCAsmParser &P, const MCInstrInfo &MII,
1358 const MCTargetOptions &Options) {
1359 return new MCAsmParserImpl(STI, P, MII, Options);
1360 }
1361};
1362
1363/// RegisterAsmPrinter - Helper template for registering a target specific
1364/// assembly printer, for use in the target machine initialization
1365/// function. Usage:
1366///
1367/// extern "C" void LLVMInitializeFooAsmPrinter() {
1368/// extern Target TheFooTarget;
1369/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1370/// }
1371template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1375
1376private:
1378 std::unique_ptr<MCStreamer> &&Streamer) {
1379 return new AsmPrinterImpl(TM, std::move(Streamer));
1380 }
1381};
1382
1383/// RegisterMCCodeEmitter - Helper template for registering a target specific
1384/// machine code emitter, for use in the target initialization
1385/// function. Usage:
1386///
1387/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1388/// extern Target TheFooTarget;
1389/// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1390/// }
1391template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1395
1396private:
1397 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1398 MCContext & /*Ctx*/) {
1399 return new MCCodeEmitterImpl();
1400 }
1401};
1402
1403} // end namespace llvm
1404
1405#endif // LLVM_MC_TARGETREGISTRY_H
unsigned const MachineRegisterInfo * MRI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition CSEInfo.cpp:27
#define LLVM_ABI
Definition Compiler.h:213
dxil DXContainer Global Emitter
static LVOptions Options
Definition LVOptions.cpp:25
#define T
uint64_t IntrinsicInst * II
#define P(N)
PassInstrumentationCallbacks PIC
Basic Register Allocator
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:90
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Generic interface to target specific assembler backends.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:64
Generic assembler parser interface, for use by target specific assembly parsers.
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
Definition MCContext.h:83
Superclass for all disassemblers.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel=false)
Defines the object file and target independent interfaces used by the assembler backend to write nati...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Create MCExprs from relocations found in an object file.
Streaming machine code generation interface.
Definition MCStreamer.h:220
Generic base class for all target subtargets.
Symbolize and annotate disassembled instructions.
MCTargetAsmParser - Generic interface to target specific assembly parsers.
Target specific streamer interface.
Definition MCStreamer.h:93
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Primary interface to the complete machine description for the target machine.
bool operator!=(const iterator &x) const
const Target * operator->() const
bool operator==(const iterator &x) const
const Target & operator*() const
std::forward_iterator_tag iterator_category
Target - Wrapper for Target specific information.
TargetMachine * createTargetMachine(const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
createTargetMachine - Create a target specific machine implementation for the specified Triple.
MCRelocationInfo *(*)(const Triple &TT, MCContext &Ctx) MCRelocationInfoCtorTy
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) XCOFFStreamerCtorTy
MCRegisterInfo * createMCRegInfo(const Triple &TT) const
Create a MCRegisterInfo implementation.
MCTargetStreamer *(*)(MCStreamer &S) NullTargetStreamerCtorTy
MCAsmInfo *(*)(const MCRegisterInfo &MRI, const Triple &TT, const MCTargetOptions &Options) MCAsmInfoCtorFnTy
mca::InstrPostProcess *(*)(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) InstrPostProcessCtorTy
mca::InstrumentManager *(*)(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) InstrumentManagerCtorTy
MCSubtargetInfo *(*)(const Triple &TT, StringRef CPU, StringRef Features) MCSubtargetInfoCtorFnTy
Target()=default
MCCodeEmitter *(*)(const MCInstrInfo &II, MCContext &Ctx) MCCodeEmitterCtorTy
MCTargetStreamer *(*)(MCStreamer &S, const MCSubtargetInfo &STI) ObjectTargetStreamerCtorTy
bool hasTargetMachine() const
hasTargetMachine - Check if this target supports code generation.
MCCodeEmitter * createMCCodeEmitter(const MCInstrInfo &II, MCContext &Ctx) const
createMCCodeEmitter - Create a target specific code emitter.
const char * getName() const
getName - Get the target name.
MCObjectFileInfo * createMCObjectFileInfo(MCContext &Ctx, bool PIC, bool LargeCodeModel=false) const
Create a MCObjectFileInfo implementation for the specified target triple.
const Target * getNext() const
MCObjectFileInfo *(*)(MCContext &Ctx, bool PIC, bool LargeCodeModel) MCObjectFileInfoCtorFnTy
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, const Triple &TheTriple, const MCTargetOptions &Options) const
Create a MCAsmInfo implementation for the specified target triple.
MCDisassembler *(*)(const Target &T, const MCSubtargetInfo &STI, MCContext &Ctx) MCDisassemblerCtorTy
MCSymbolizer * createMCSymbolizer(StringRef TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const
MCAsmBackend *(*)(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) MCAsmBackendCtorTy
MCAsmBackend * createMCAsmBackend(const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options) const
createMCAsmBackend - Create a target specific assembly parser.
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) COFFStreamerCtorTy
MCTargetStreamer *(*)(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) AsmTargetStreamerCtorTy
bool hasMCAsmParser() const
hasMCAsmParser - Check if this target supports assembly parsing.
MCStreamer * createNullStreamer(MCContext &Ctx) const
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) const
MCRelocationInfo * createMCRelocationInfo(StringRef TT, MCContext &Ctx) const
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) MachOStreamerCtorTy
MCTargetStreamer * createAsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint) const
MCInstrAnalysis *(*)(const MCInstrInfo *Info) MCInstrAnalysisCtorFnTy
MCRegisterInfo * createMCRegInfo(StringRef TT) const
MCRegisterInfo *(*)(const Triple &TT) MCRegInfoCtorFnTy
MCInstrInfo *(*)() MCInstrInfoCtorFnTy
LLVM_ABI MCStreamer * createMCObjectStreamer(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > TAB, std::unique_ptr< MCObjectWriter > OW, std::unique_ptr< MCCodeEmitter > Emitter, const MCSubtargetInfo &STI) const
Create a target specific MCStreamer.
mca::CustomBehaviour * createCustomBehaviour(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII) const
createCustomBehaviour - Create a target specific CustomBehaviour.
friend struct TargetRegistry
mca::CustomBehaviour *(*)(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII) CustomBehaviourCtorTy
bool(*)(Triple::ArchType Arch) ArchMatchFnTy
MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) const
createMCSymbolizer - Create a target specific MCSymbolizer.
MCDisassembler * createMCDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx) const
TargetMachine * createTargetMachine(StringRef TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM=std::nullopt, CodeGenOptLevel OL=CodeGenOptLevel::Default, bool JIT=false) const
bool hasMCAsmBackend() const
hasMCAsmBackend - Check if this target supports .o generation.
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple, const MCTargetOptions &Options) const
MCInstPrinter * createMCInstPrinter(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) const
mca::InstrPostProcess * createInstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) const
createInstrPostProcess - Create a target specific InstrPostProcess.
const char * getBackendName() const
getBackendName - Get the backend name.
MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx) const
createMCRelocationInfo - Create a target specific MCRelocationInfo.
MCTargetAsmParser * createMCAsmParser(const MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
MCInstrAnalysis * createMCInstrAnalysis(const MCInstrInfo *Info) const
createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
MCSubtargetInfo * createMCSubtargetInfo(const Triple &TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
const char * getShortDescription() const
getShortDescription - Get a short description of the target.
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > IP, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB) AsmStreamerCtorTy
MCSymbolizer *(*)(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo) MCSymbolizerCtorTy
bool hasJIT() const
hasJIT - Check if this targets supports the just-in-time compilation.
AsmPrinter *(*)( TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) AsmPrinterCtorTy
TargetMachine *(*)(const Target &T, const Triple &TT, StringRef CPU, StringRef Features, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT) TargetMachineCtorTy
MCTargetStreamer * createNullTargetStreamer(MCStreamer &S) const
MCInstPrinter *(*)(const Triple &T, unsigned SyntaxVariant, const MCAsmInfo &MAI, const MCInstrInfo &MII, const MCRegisterInfo &MRI) MCInstPrinterCtorTy
AsmPrinter * createAsmPrinter(TargetMachine &TM, std::unique_ptr< MCStreamer > &&Streamer) const
createAsmPrinter - Create a target specific assembly printer pass.
MCTargetAsmParser *(*)( const MCSubtargetInfo &STI, MCAsmParser &P, const MCInstrInfo &MII, const MCTargetOptions &Options) MCAsmParserCtorTy
MCStreamer *(*)(const Triple &T, MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&Emitter) ELFStreamerCtorTy
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
mca::InstrumentManager * createInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII) const
createInstrumentManager - Create a target specific InstrumentManager.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
@ UnknownArch
Definition Triple.h:50
formatted_raw_ostream - A raw_ostream that wraps another one and keeps track of line and column posit...
A range adaptor for a pair of iterators.
Class which can be overriden by targets to enforce instruction dependencies and behaviours that aren'...
Class which can be overriden by targets to modify the mca::Instruction objects before the pipeline st...
This class allows targets to optionally customize the logic that resolves scheduling class IDs.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
const char *(* LLVMSymbolLookupCallback)(void *DisInfo, uint64_t ReferenceValue, uint64_t *ReferenceType, uint64_t ReferencePC, const char **ReferenceName)
The type for the symbol lookup function.
int(* LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, uint64_t Offset, uint64_t OpSize, uint64_t InstSize, int TagType, void *TagBuf)
The type for the operand information call back function.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI mca::InstrumentManager * createInstrumentManager(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
LLVM_ABI MCStreamer * createELFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > InstPrint, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB)
Create a machine code streamer which will print out assembly for the native target,...
Op::Description Desc
LLVM_ABI MCStreamer * createNullStreamer(MCContext &Ctx)
Create a dummy machine code streamer, which does nothing.
LLVM_ABI MCSymbolizer * createMCSymbolizer(const Triple &TT, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo, MCContext *Ctx, std::unique_ptr< MCRelocationInfo > &&RelInfo)
LLVM_ABI MCStreamer * createMachOStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE, bool DWARFMustBeAtTheEnd, bool LabelSections=false)
SourceMgr SrcMgr
Definition Error.cpp:24
LLVM_ABI MCRelocationInfo * createMCRelocationInfo(const Triple &TT, MCContext &Ctx)
LLVM_ABI mca::CustomBehaviour * createCustomBehaviour(const MCSubtargetInfo &STI, const mca::SourceMgr &SrcMgr, const MCInstrInfo &MCII)
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
@ Default
-O2, -Os
Definition CodeGen.h:85
LLVM_ABI MCStreamer * createDXContainerStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createWasmStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createGOFFStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI MCStreamer * createSPIRVStreamer(MCContext &Ctx, std::unique_ptr< MCAsmBackend > &&TAB, std::unique_ptr< MCObjectWriter > &&OW, std::unique_ptr< MCCodeEmitter > &&CE)
LLVM_ABI mca::InstrPostProcess * createInstrPostProcess(const MCSubtargetInfo &STI, const MCInstrInfo &MCII)
RegisterMCAsmInfoFn(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCInstrAnalysisFn(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrInfoFn(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCObjectFileInfoFn(Target &T, Target::MCObjectFileInfoCtorFnTy Fn)
RegisterMCRegInfoFn(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCSubtargetInfoFn(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
static bool getArchMatch(Triple::ArchType Arch)
RegisterTarget(Target &T, const char *Name, const char *Desc, const char *BackendName)
static const Target * lookupTarget(StringRef TripleStr, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
static void RegisterMCSymbolizer(Target &T, Target::MCSymbolizerCtorTy Fn)
RegisterMCSymbolizer - Register an MCSymbolizer implementation for the given target.
static void RegisterMCRegInfo(Target &T, Target::MCRegInfoCtorFnTy Fn)
RegisterMCRegInfo - Register a MCRegisterInfo implementation for the given target.
static void RegisterAsmPrinter(Target &T, Target::AsmPrinterCtorTy Fn)
RegisterAsmPrinter - Register an AsmPrinter implementation for the given target.
static void RegisterMCAsmBackend(Target &T, Target::MCAsmBackendCtorTy Fn)
RegisterMCAsmBackend - Register a MCAsmBackend implementation for the given target.
static void RegisterXCOFFStreamer(Target &T, Target::XCOFFStreamerCtorTy Fn)
static void RegisterMCCodeEmitter(Target &T, Target::MCCodeEmitterCtorTy Fn)
RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the given target.
static void RegisterMCAsmInfo(Target &T, Target::MCAsmInfoCtorFnTy Fn)
RegisterMCAsmInfo - Register a MCAsmInfo implementation for the given target.
static void RegisterMCSubtargetInfo(Target &T, Target::MCSubtargetInfoCtorFnTy Fn)
RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for the given target.
static void RegisterObjectTargetStreamer(Target &T, Target::ObjectTargetStreamerCtorTy Fn)
static void RegisterMCInstrAnalysis(Target &T, Target::MCInstrAnalysisCtorFnTy Fn)
RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for the given target.
static void RegisterAsmStreamer(Target &T, Target::AsmStreamerCtorTy Fn)
static void RegisterELFStreamer(Target &T, Target::ELFStreamerCtorTy Fn)
static void RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn)
static void RegisterInstrPostProcess(Target &T, Target::InstrPostProcessCtorTy Fn)
RegisterInstrPostProcess - Register an InstrPostProcess implementation for the given target.
static void RegisterMCDisassembler(Target &T, Target::MCDisassemblerCtorTy Fn)
RegisterMCDisassembler - Register a MCDisassembler implementation for the given target.
static void RegisterMCAsmParser(Target &T, Target::MCAsmParserCtorTy Fn)
RegisterMCAsmParser - Register a MCTargetAsmParser implementation for the given target.
static LLVM_ABI void printRegisteredTargetsForVersion(raw_ostream &OS)
printRegisteredTargetsForVersion - Print the registered targets appropriately for inclusion in a tool...
static void RegisterTargetMachine(Target &T, Target::TargetMachineCtorTy Fn)
RegisterTargetMachine - Register a TargetMachine implementation for the given target.
static void RegisterMCInstPrinter(Target &T, Target::MCInstPrinterCtorTy Fn)
RegisterMCInstPrinter - Register a MCInstPrinter implementation for the given target.
static void RegisterCOFFStreamer(Target &T, Target::COFFStreamerCtorTy Fn)
static LLVM_ABI void RegisterTarget(Target &T, const char *Name, const char *ShortDesc, const char *BackendName, Target::ArchMatchFnTy ArchMatchFn, bool HasJIT=false)
RegisterTarget - Register the given target.
static void RegisterMCInstrInfo(Target &T, Target::MCInstrInfoCtorFnTy Fn)
RegisterMCInstrInfo - Register a MCInstrInfo implementation for the given target.
static LLVM_ABI iterator_range< iterator > targets()
static void RegisterInstrumentManager(Target &T, Target::InstrumentManagerCtorTy Fn)
RegisterInstrumentManager - Register an InstrumentManager implementation for the given target.
static void RegisterCustomBehaviour(Target &T, Target::CustomBehaviourCtorTy Fn)
RegisterCustomBehaviour - Register a CustomBehaviour implementation for the given target.
static void RegisterMachOStreamer(Target &T, Target::MachOStreamerCtorTy Fn)
static void RegisterMCObjectFileInfo(Target &T, Target::MCObjectFileInfoCtorFnTy Fn)
Register a MCObjectFileInfo implementation for the given target.
static void RegisterAsmTargetStreamer(Target &T, Target::AsmTargetStreamerCtorTy Fn)
static void RegisterMCRelocationInfo(Target &T, Target::MCRelocationInfoCtorTy Fn)
RegisterMCRelocationInfo - Register an MCRelocationInfo implementation for the given target.
Abstracting the input code sequence (a sequence of MCInst) and assigning unique identifiers to every ...
Definition SourceMgr.h:29