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 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
393 [[deprecated("Use overload accepting Triple instead")]]
395 const MCTargetOptions &Options) const {
396 if (!MCAsmInfoCtorFn)
397 return nullptr;
398 return MCAsmInfoCtorFn(MRI, Triple(TheTriple), Options);
399 }
400
401 /// Create a MCAsmInfo implementation for the specified
402 /// target triple.
403 ///
404 /// \param TheTriple This argument is used to determine the target machine
405 /// feature set; it should always be provided. Generally this should be
406 /// either the target triple from the module, or the target triple of the
407 /// host if that does not exist.
409 const MCTargetOptions &Options) const {
410 if (!MCAsmInfoCtorFn)
411 return nullptr;
412 return MCAsmInfoCtorFn(MRI, TheTriple, Options);
413 }
414
415 /// Create a MCObjectFileInfo implementation for the specified target
416 /// triple.
417 ///
419 bool LargeCodeModel = false) const {
420 if (!MCObjectFileInfoCtorFn) {
422 MOFI->initMCObjectFileInfo(Ctx, PIC, LargeCodeModel);
423 return MOFI;
424 }
425 return MCObjectFileInfoCtorFn(Ctx, PIC, LargeCodeModel);
426 }
427
428 /// createMCInstrInfo - Create a MCInstrInfo implementation.
429 ///
431 if (!MCInstrInfoCtorFn)
432 return nullptr;
433 return MCInstrInfoCtorFn();
434 }
435
436 /// createMCInstrAnalysis - Create a MCInstrAnalysis implementation.
437 ///
439 if (!MCInstrAnalysisCtorFn)
440 return nullptr;
441 return MCInstrAnalysisCtorFn(Info);
442 }
443
444 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
445 [[deprecated("Use overload accepting Triple instead")]]
447 if (!MCRegInfoCtorFn)
448 return nullptr;
449 return MCRegInfoCtorFn(Triple(TT));
450 }
451
452 /// Create a MCRegisterInfo implementation.
454 if (!MCRegInfoCtorFn)
455 return nullptr;
456 return MCRegInfoCtorFn(TT);
457 }
458
459 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
460 [[deprecated("Use overload accepting Triple instead")]]
462 StringRef Features) const {
463 if (!MCSubtargetInfoCtorFn)
464 return nullptr;
465 return MCSubtargetInfoCtorFn(Triple(TheTriple), CPU, Features);
466 }
467
468 /// createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
469 ///
470 /// \param TheTriple This argument is used to determine the target machine
471 /// feature set; it should always be provided. Generally this should be
472 /// either the target triple from the module, or the target triple of the
473 /// host if that does not exist.
474 /// \param CPU This specifies the name of the target CPU.
475 /// \param Features This specifies the string representation of the
476 /// additional target features.
478 StringRef Features) const {
479 if (!MCSubtargetInfoCtorFn)
480 return nullptr;
481 return MCSubtargetInfoCtorFn(TheTriple, CPU, Features);
482 }
483
484 /// createTargetMachine - Create a target specific machine implementation
485 /// for the specified \p Triple.
486 ///
487 /// \param TT This argument is used to determine the target machine
488 /// feature set; it should always be provided. Generally this should be
489 /// either the target triple from the module, or the target triple of the
490 /// host if that does not exist.
492 const Triple &TT, StringRef CPU, StringRef Features,
493 const TargetOptions &Options, std::optional<Reloc::Model> RM,
494 std::optional<CodeModel::Model> CM = std::nullopt,
495 CodeGenOptLevel OL = CodeGenOptLevel::Default, bool JIT = false) const {
496 if (!TargetMachineCtorFn)
497 return nullptr;
498 return TargetMachineCtorFn(*this, TT, CPU, Features, Options, RM, CM, OL,
499 JIT);
500 }
501
502 /// createMCAsmBackend - Create a target specific assembly parser.
504 const MCRegisterInfo &MRI,
505 const MCTargetOptions &Options) const {
506 if (!MCAsmBackendCtorFn)
507 return nullptr;
508 return MCAsmBackendCtorFn(*this, STI, MRI, Options);
509 }
510
511 /// createMCAsmParser - Create a target specific assembly parser.
512 ///
513 /// \param Parser The target independent parser implementation to use for
514 /// parsing and lexing.
516 MCAsmParser &Parser,
517 const MCInstrInfo &MII,
518 const MCTargetOptions &Options) const {
519 if (!MCAsmParserCtorFn)
520 return nullptr;
521 return MCAsmParserCtorFn(STI, Parser, MII, Options);
522 }
523
524 /// createAsmPrinter - Create a target specific assembly printer pass. This
525 /// takes ownership of the MCStreamer object.
527 std::unique_ptr<MCStreamer> &&Streamer) const {
528 if (!AsmPrinterCtorFn)
529 return nullptr;
530 return AsmPrinterCtorFn(TM, std::move(Streamer));
531 }
532
534 MCContext &Ctx) const {
535 if (!MCDisassemblerCtorFn)
536 return nullptr;
537 return MCDisassemblerCtorFn(*this, STI, Ctx);
538 }
539
540 MCInstPrinter *createMCInstPrinter(const Triple &T, unsigned SyntaxVariant,
541 const MCAsmInfo &MAI,
542 const MCInstrInfo &MII,
543 const MCRegisterInfo &MRI) const {
544 if (!MCInstPrinterCtorFn)
545 return nullptr;
546 return MCInstPrinterCtorFn(T, SyntaxVariant, MAI, MII, MRI);
547 }
548
549 /// createMCCodeEmitter - Create a target specific code emitter.
551 MCContext &Ctx) const {
552 if (!MCCodeEmitterCtorFn)
553 return nullptr;
554 return MCCodeEmitterCtorFn(II, Ctx);
555 }
556
557 /// Create a target specific MCStreamer.
558 ///
559 /// \param T The target triple.
560 /// \param Ctx The target context.
561 /// \param TAB The target assembler backend object. Takes ownership.
562 /// \param OW The stream object.
563 /// \param Emitter The target independent assembler object.Takes ownership.
565 const Triple &T, MCContext &Ctx, std::unique_ptr<MCAsmBackend> TAB,
566 std::unique_ptr<MCObjectWriter> OW,
567 std::unique_ptr<MCCodeEmitter> Emitter, const MCSubtargetInfo &STI) const;
568
570 createAsmStreamer(MCContext &Ctx, std::unique_ptr<formatted_raw_ostream> OS,
571 std::unique_ptr<MCInstPrinter> IP,
572 std::unique_ptr<MCCodeEmitter> CE,
573 std::unique_ptr<MCAsmBackend> TAB) const;
574
577 MCInstPrinter *InstPrint) const {
578 if (AsmTargetStreamerCtorFn)
579 return AsmTargetStreamerCtorFn(S, OS, InstPrint);
580 return nullptr;
581 }
582
586 return S;
587 }
588
590 if (NullTargetStreamerCtorFn)
591 return NullTargetStreamerCtorFn(S);
592 return nullptr;
593 }
594
595 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
596 [[deprecated("Use overload accepting Triple instead")]]
600
601 /// createMCRelocationInfo - Create a target specific MCRelocationInfo.
602 ///
603 /// \param TT The target triple.
604 /// \param Ctx The target context.
606 MCContext &Ctx) const {
607 MCRelocationInfoCtorTy Fn = MCRelocationInfoCtorFn
608 ? MCRelocationInfoCtorFn
610 return Fn(TT, Ctx);
611 }
612
613 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
614 [[deprecated("Use overload accepting Triple instead")]]
617 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
618 MCContext *Ctx,
619 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
620 return createMCSymbolizer(Triple(TT), GetOpInfo, SymbolLookUp, DisInfo, Ctx,
621 std::move(RelInfo));
622 }
623
624 /// createMCSymbolizer - Create a target specific MCSymbolizer.
625 ///
626 /// \param TT The target triple.
627 /// \param GetOpInfo The function to get the symbolic information for
628 /// operands.
629 /// \param SymbolLookUp The function to lookup a symbol name.
630 /// \param DisInfo The pointer to the block of symbolic information for above
631 /// call
632 /// back.
633 /// \param Ctx The target context.
634 /// \param RelInfo The relocation information for this target. Takes
635 /// ownership.
638 LLVMSymbolLookupCallback SymbolLookUp, void *DisInfo,
639 MCContext *Ctx,
640 std::unique_ptr<MCRelocationInfo> &&RelInfo) const {
642 MCSymbolizerCtorFn ? MCSymbolizerCtorFn : llvm::createMCSymbolizer;
643 return Fn(TT, GetOpInfo, SymbolLookUp, DisInfo, Ctx, std::move(RelInfo));
644 }
645
646 /// createCustomBehaviour - Create a target specific CustomBehaviour.
647 /// This class is used by llvm-mca and requires backend functionality.
649 const mca::SourceMgr &SrcMgr,
650 const MCInstrInfo &MCII) const {
651 if (CustomBehaviourCtorFn)
652 return CustomBehaviourCtorFn(STI, SrcMgr, MCII);
653 return nullptr;
654 }
655
656 /// createInstrPostProcess - Create a target specific InstrPostProcess.
657 /// This class is used by llvm-mca and requires backend functionality.
659 const MCInstrInfo &MCII) const {
660 if (InstrPostProcessCtorFn)
661 return InstrPostProcessCtorFn(STI, MCII);
662 return nullptr;
663 }
664
665 /// createInstrumentManager - Create a target specific
666 /// InstrumentManager. This class is used by llvm-mca and requires
667 /// backend functionality.
670 const MCInstrInfo &MCII) const {
671 if (InstrumentManagerCtorFn)
672 return InstrumentManagerCtorFn(STI, MCII);
673 return nullptr;
674 }
675
676 /// @}
677};
678
679/// TargetRegistry - Generic interface to target specific features.
681 // FIXME: Make this a namespace, probably just move all the Register*
682 // functions into Target (currently they all just set members on the Target
683 // anyway, and Target friends this class so those functions can...
684 // function).
685 TargetRegistry() = delete;
686
687 class iterator {
688 friend struct TargetRegistry;
689
690 const Target *Current = nullptr;
691
692 explicit iterator(Target *T) : Current(T) {}
693
694 public:
695 using iterator_category = std::forward_iterator_tag;
697 using difference_type = std::ptrdiff_t;
700
701 iterator() = default;
702
703 bool operator==(const iterator &x) const { return Current == x.Current; }
704 bool operator!=(const iterator &x) const { return !operator==(x); }
705
706 // Iterator traversal: forward iteration only
707 iterator &operator++() { // Preincrement
708 assert(Current && "Cannot increment end iterator!");
709 Current = Current->getNext();
710 return *this;
711 }
712 iterator operator++(int) { // Postincrement
713 iterator tmp = *this;
714 ++*this;
715 return tmp;
716 }
717
718 const Target &operator*() const {
719 assert(Current && "Cannot dereference end iterator!");
720 return *Current;
721 }
722
723 const Target *operator->() const { return &operator*(); }
724 };
725
726 /// printRegisteredTargetsForVersion - Print the registered targets
727 /// appropriately for inclusion in a tool's version output.
729
730 /// @name Registry Access
731 /// @{
732
734
735 /// lookupTarget - Lookup a target based on a target triple.
736 ///
737 /// \param TripleStr - The triple to use for finding a target.
738 /// \param Error - On failure, an error string describing why no target was
739 /// found.
740 // TODO(boomanaiden154): Remove this function after LLVM 22 branches.
741 [[deprecated("Use overload accepting Triple instead")]]
742 static const Target *lookupTarget(StringRef TripleStr, std::string &Error) {
743 return lookupTarget(Triple(TripleStr), Error);
744 }
745
746 /// lookupTarget - Lookup a target based on a target triple.
747 ///
748 /// \param Triple - The triple to use for finding a target.
749 /// \param Error - On failure, an error string describing why no target was
750 /// found.
751 LLVM_ABI static const Target *lookupTarget(const Triple &TheTriple,
752 std::string &Error);
753
754 /// lookupTarget - Lookup a target based on an architecture name
755 /// and a target triple. If the architecture name is non-empty,
756 /// then the lookup is done by architecture. Otherwise, the target
757 /// triple is used.
758 ///
759 /// \param ArchName - The architecture to use for finding a target.
760 /// \param TheTriple - The triple to use for finding a target. The
761 /// triple is updated with canonical architecture name if a lookup
762 /// by architecture is done.
763 /// \param Error - On failure, an error string describing why no target was
764 /// found.
765 LLVM_ABI static const Target *
766 lookupTarget(StringRef ArchName, Triple &TheTriple, std::string &Error);
767
768 /// @}
769 /// @name Target Registration
770 /// @{
771
772 /// RegisterTarget - Register the given target. Attempts to register a
773 /// target which has already been registered will be ignored.
774 ///
775 /// Clients are responsible for ensuring that registration doesn't occur
776 /// while another thread is attempting to access the registry. Typically
777 /// this is done by initializing all targets at program startup.
778 ///
779 /// @param T - The target being registered.
780 /// @param Name - The target name. This should be a static string.
781 /// @param ShortDesc - A short target description. This should be a static
782 /// string.
783 /// @param BackendName - The name of the backend. This should be a static
784 /// string that is the same for all targets that share a backend
785 /// implementation and must match the name used in the 'def X : Target ...' in
786 /// TableGen.
787 /// @param ArchMatchFn - The arch match checking function for this target.
788 /// @param HasJIT - Whether the target supports JIT code
789 /// generation.
790 LLVM_ABI static void RegisterTarget(Target &T, const char *Name,
791 const char *ShortDesc,
792 const char *BackendName,
793 Target::ArchMatchFnTy ArchMatchFn,
794 bool HasJIT = false);
795
796 /// RegisterMCAsmInfo - Register a MCAsmInfo implementation for the
797 /// given target.
798 ///
799 /// Clients are responsible for ensuring that registration doesn't occur
800 /// while another thread is attempting to access the registry. Typically
801 /// this is done by initializing all targets at program startup.
802 ///
803 /// @param T - The target being registered.
804 /// @param Fn - A function to construct a MCAsmInfo for the target.
806 T.MCAsmInfoCtorFn = Fn;
807 }
808
809 /// Register a MCObjectFileInfo implementation for the given target.
810 ///
811 /// Clients are responsible for ensuring that registration doesn't occur
812 /// while another thread is attempting to access the registry. Typically
813 /// this is done by initializing all targets at program startup.
814 ///
815 /// @param T - The target being registered.
816 /// @param Fn - A function to construct a MCObjectFileInfo for the target.
819 T.MCObjectFileInfoCtorFn = Fn;
820 }
821
822 /// RegisterMCInstrInfo - Register a MCInstrInfo implementation for the
823 /// given target.
824 ///
825 /// Clients are responsible for ensuring that registration doesn't occur
826 /// while another thread is attempting to access the registry. Typically
827 /// this is done by initializing all targets at program startup.
828 ///
829 /// @param T - The target being registered.
830 /// @param Fn - A function to construct a MCInstrInfo for the target.
832 T.MCInstrInfoCtorFn = Fn;
833 }
834
835 /// RegisterMCInstrAnalysis - Register a MCInstrAnalysis implementation for
836 /// the given target.
839 T.MCInstrAnalysisCtorFn = Fn;
840 }
841
842 /// RegisterMCRegInfo - Register a MCRegisterInfo implementation for the
843 /// given target.
844 ///
845 /// Clients are responsible for ensuring that registration doesn't occur
846 /// while another thread is attempting to access the registry. Typically
847 /// this is done by initializing all targets at program startup.
848 ///
849 /// @param T - The target being registered.
850 /// @param Fn - A function to construct a MCRegisterInfo for the target.
852 T.MCRegInfoCtorFn = Fn;
853 }
854
855 /// RegisterMCSubtargetInfo - Register a MCSubtargetInfo implementation for
856 /// the given target.
857 ///
858 /// Clients are responsible for ensuring that registration doesn't occur
859 /// while another thread is attempting to access the registry. Typically
860 /// this is done by initializing all targets at program startup.
861 ///
862 /// @param T - The target being registered.
863 /// @param Fn - A function to construct a MCSubtargetInfo for the target.
866 T.MCSubtargetInfoCtorFn = Fn;
867 }
868
869 /// RegisterTargetMachine - Register a TargetMachine implementation for the
870 /// given target.
871 ///
872 /// Clients are responsible for ensuring that registration doesn't occur
873 /// while another thread is attempting to access the registry. Typically
874 /// this is done by initializing all targets at program startup.
875 ///
876 /// @param T - The target being registered.
877 /// @param Fn - A function to construct a TargetMachine for the target.
879 T.TargetMachineCtorFn = Fn;
880 }
881
882 /// RegisterMCAsmBackend - Register a MCAsmBackend implementation for the
883 /// given target.
884 ///
885 /// Clients are responsible for ensuring that registration doesn't occur
886 /// while another thread is attempting to access the registry. Typically
887 /// this is done by initializing all targets at program startup.
888 ///
889 /// @param T - The target being registered.
890 /// @param Fn - A function to construct an AsmBackend for the target.
892 T.MCAsmBackendCtorFn = Fn;
893 }
894
895 /// RegisterMCAsmParser - Register a MCTargetAsmParser implementation for
896 /// the given target.
897 ///
898 /// Clients are responsible for ensuring that registration doesn't occur
899 /// while another thread is attempting to access the registry. Typically
900 /// this is done by initializing all targets at program startup.
901 ///
902 /// @param T - The target being registered.
903 /// @param Fn - A function to construct an MCTargetAsmParser for the target.
905 T.MCAsmParserCtorFn = Fn;
906 }
907
908 /// RegisterAsmPrinter - Register an AsmPrinter implementation for the given
909 /// target.
910 ///
911 /// Clients are responsible for ensuring that registration doesn't occur
912 /// while another thread is attempting to access the registry. Typically
913 /// this is done by initializing all targets at program startup.
914 ///
915 /// @param T - The target being registered.
916 /// @param Fn - A function to construct an AsmPrinter for the target.
918 T.AsmPrinterCtorFn = Fn;
919 }
920
921 /// RegisterMCDisassembler - Register a MCDisassembler implementation for
922 /// the given target.
923 ///
924 /// Clients are responsible for ensuring that registration doesn't occur
925 /// while another thread is attempting to access the registry. Typically
926 /// this is done by initializing all targets at program startup.
927 ///
928 /// @param T - The target being registered.
929 /// @param Fn - A function to construct an MCDisassembler for the target.
932 T.MCDisassemblerCtorFn = Fn;
933 }
934
935 /// RegisterMCInstPrinter - Register a MCInstPrinter implementation for the
936 /// given target.
937 ///
938 /// Clients are responsible for ensuring that registration doesn't occur
939 /// while another thread is attempting to access the registry. Typically
940 /// this is done by initializing all targets at program startup.
941 ///
942 /// @param T - The target being registered.
943 /// @param Fn - A function to construct an MCInstPrinter for the target.
945 T.MCInstPrinterCtorFn = Fn;
946 }
947
948 /// RegisterMCCodeEmitter - Register a MCCodeEmitter implementation for the
949 /// given target.
950 ///
951 /// Clients are responsible for ensuring that registration doesn't occur
952 /// while another thread is attempting to access the registry. Typically
953 /// this is done by initializing all targets at program startup.
954 ///
955 /// @param T - The target being registered.
956 /// @param Fn - A function to construct an MCCodeEmitter for the target.
958 T.MCCodeEmitterCtorFn = Fn;
959 }
960
962 T.COFFStreamerCtorFn = Fn;
963 }
964
966 T.MachOStreamerCtorFn = Fn;
967 }
968
970 T.ELFStreamerCtorFn = Fn;
971 }
972
974 T.XCOFFStreamerCtorFn = Fn;
975 }
976
979 T.NullTargetStreamerCtorFn = Fn;
980 }
981
983 T.AsmStreamerCtorFn = Fn;
984 }
985
988 T.AsmTargetStreamerCtorFn = Fn;
989 }
990
991 static void
994 T.ObjectTargetStreamerCtorFn = Fn;
995 }
996
997 /// RegisterMCRelocationInfo - Register an MCRelocationInfo
998 /// implementation for the given target.
999 ///
1000 /// Clients are responsible for ensuring that registration doesn't occur
1001 /// while another thread is attempting to access the registry. Typically
1002 /// this is done by initializing all targets at program startup.
1003 ///
1004 /// @param T - The target being registered.
1005 /// @param Fn - A function to construct an MCRelocationInfo for the target.
1008 T.MCRelocationInfoCtorFn = Fn;
1009 }
1010
1011 /// RegisterMCSymbolizer - Register an MCSymbolizer
1012 /// implementation for the given target.
1013 ///
1014 /// Clients are responsible for ensuring that registration doesn't occur
1015 /// while another thread is attempting to access the registry. Typically
1016 /// this is done by initializing all targets at program startup.
1017 ///
1018 /// @param T - The target being registered.
1019 /// @param Fn - A function to construct an MCSymbolizer for the target.
1021 T.MCSymbolizerCtorFn = Fn;
1022 }
1023
1024 /// RegisterCustomBehaviour - Register a CustomBehaviour
1025 /// implementation for the given target.
1026 ///
1027 /// Clients are responsible for ensuring that registration doesn't occur
1028 /// while another thread is attempting to access the registry. Typically
1029 /// this is done by initializing all targets at program startup.
1030 ///
1031 /// @param T - The target being registered.
1032 /// @param Fn - A function to construct a CustomBehaviour for the target.
1035 T.CustomBehaviourCtorFn = Fn;
1036 }
1037
1038 /// RegisterInstrPostProcess - Register an InstrPostProcess
1039 /// implementation for the given target.
1040 ///
1041 /// Clients are responsible for ensuring that registration doesn't occur
1042 /// while another thread is attempting to access the registry. Typically
1043 /// this is done by initializing all targets at program startup.
1044 ///
1045 /// @param T - The target being registered.
1046 /// @param Fn - A function to construct an InstrPostProcess for the target.
1049 T.InstrPostProcessCtorFn = Fn;
1050 }
1051
1052 /// RegisterInstrumentManager - Register an InstrumentManager
1053 /// implementation for the given target.
1054 ///
1055 /// Clients are responsible for ensuring that registration doesn't occur
1056 /// while another thread is attempting to access the registry. Typically
1057 /// this is done by initializing all targets at program startup.
1058 ///
1059 /// @param T - The target being registered.
1060 /// @param Fn - A function to construct an InstrumentManager for the
1061 /// target.
1064 T.InstrumentManagerCtorFn = Fn;
1065 }
1066
1067 /// @}
1068};
1069
1070//===--------------------------------------------------------------------===//
1071
1072/// RegisterTarget - Helper template for registering a target, for use in the
1073/// target's initialization function. Usage:
1074///
1075///
1076/// Target &getTheFooTarget() { // The global target instance.
1077/// static Target TheFooTarget;
1078/// return TheFooTarget;
1079/// }
1080/// extern "C" void LLVMInitializeFooTargetInfo() {
1081/// RegisterTarget<Triple::foo> X(getTheFooTarget(), "foo", "Foo
1082/// description", "Foo" /* Backend Name */);
1083/// }
1084template <Triple::ArchType TargetArchType = Triple::UnknownArch,
1085 bool HasJIT = false>
1087 RegisterTarget(Target &T, const char *Name, const char *Desc,
1088 const char *BackendName) {
1089 TargetRegistry::RegisterTarget(T, Name, Desc, BackendName, &getArchMatch,
1090 HasJIT);
1091 }
1092
1093 static bool getArchMatch(Triple::ArchType Arch) {
1094 return Arch == TargetArchType;
1095 }
1096};
1097
1098/// RegisterMCAsmInfo - Helper template for registering a target assembly info
1099/// implementation. This invokes the static "Create" method on the class to
1100/// actually do the construction. Usage:
1101///
1102/// extern "C" void LLVMInitializeFooTarget() {
1103/// extern Target TheFooTarget;
1104/// RegisterMCAsmInfo<FooMCAsmInfo> X(TheFooTarget);
1105/// }
1106template <class MCAsmInfoImpl> struct RegisterMCAsmInfo {
1110
1111private:
1112 static MCAsmInfo *Allocator(const MCRegisterInfo & /*MRI*/, const Triple &TT,
1113 const MCTargetOptions &Options) {
1114 return new MCAsmInfoImpl(TT, Options);
1115 }
1116};
1117
1118/// RegisterMCAsmInfoFn - Helper template for registering a target assembly info
1119/// implementation. This invokes the specified function to do the
1120/// construction. Usage:
1121///
1122/// extern "C" void LLVMInitializeFooTarget() {
1123/// extern Target TheFooTarget;
1124/// RegisterMCAsmInfoFn X(TheFooTarget, TheFunction);
1125/// }
1131
1132/// Helper template for registering a target object file info implementation.
1133/// This invokes the static "Create" method on the class to actually do the
1134/// construction. Usage:
1135///
1136/// extern "C" void LLVMInitializeFooTarget() {
1137/// extern Target TheFooTarget;
1138/// RegisterMCObjectFileInfo<FooMCObjectFileInfo> X(TheFooTarget);
1139/// }
1140template <class MCObjectFileInfoImpl> struct RegisterMCObjectFileInfo {
1144
1145private:
1146 static MCObjectFileInfo *Allocator(MCContext &Ctx, bool PIC,
1147 bool LargeCodeModel = false) {
1148 return new MCObjectFileInfoImpl(Ctx, PIC, LargeCodeModel);
1149 }
1150};
1151
1152/// Helper template for registering a target object file info implementation.
1153/// This invokes the specified function to do the construction. Usage:
1154///
1155/// extern "C" void LLVMInitializeFooTarget() {
1156/// extern Target TheFooTarget;
1157/// RegisterMCObjectFileInfoFn X(TheFooTarget, TheFunction);
1158/// }
1164
1165/// RegisterMCInstrInfo - Helper template for registering a target instruction
1166/// info implementation. This invokes the static "Create" method on the class
1167/// to actually do the construction. Usage:
1168///
1169/// extern "C" void LLVMInitializeFooTarget() {
1170/// extern Target TheFooTarget;
1171/// RegisterMCInstrInfo<FooMCInstrInfo> X(TheFooTarget);
1172/// }
1173template <class MCInstrInfoImpl> struct RegisterMCInstrInfo {
1177
1178private:
1179 static MCInstrInfo *Allocator() { return new MCInstrInfoImpl(); }
1180};
1181
1182/// RegisterMCInstrInfoFn - Helper template for registering a target
1183/// instruction info implementation. This invokes the specified function to
1184/// do the construction. Usage:
1185///
1186/// extern "C" void LLVMInitializeFooTarget() {
1187/// extern Target TheFooTarget;
1188/// RegisterMCInstrInfoFn X(TheFooTarget, TheFunction);
1189/// }
1195
1196/// RegisterMCInstrAnalysis - Helper template for registering a target
1197/// instruction analyzer implementation. This invokes the static "Create"
1198/// method on the class to actually do the construction. Usage:
1199///
1200/// extern "C" void LLVMInitializeFooTarget() {
1201/// extern Target TheFooTarget;
1202/// RegisterMCInstrAnalysis<FooMCInstrAnalysis> X(TheFooTarget);
1203/// }
1204template <class MCInstrAnalysisImpl> struct RegisterMCInstrAnalysis {
1208
1209private:
1210 static MCInstrAnalysis *Allocator(const MCInstrInfo *Info) {
1211 return new MCInstrAnalysisImpl(Info);
1212 }
1213};
1214
1215/// RegisterMCInstrAnalysisFn - Helper template for registering a target
1216/// instruction analyzer implementation. This invokes the specified function
1217/// to do the construction. Usage:
1218///
1219/// extern "C" void LLVMInitializeFooTarget() {
1220/// extern Target TheFooTarget;
1221/// RegisterMCInstrAnalysisFn X(TheFooTarget, TheFunction);
1222/// }
1228
1229/// RegisterMCRegInfo - Helper template for registering a target register info
1230/// implementation. This invokes the static "Create" method on the class to
1231/// actually do the construction. Usage:
1232///
1233/// extern "C" void LLVMInitializeFooTarget() {
1234/// extern Target TheFooTarget;
1235/// RegisterMCRegInfo<FooMCRegInfo> X(TheFooTarget);
1236/// }
1237template <class MCRegisterInfoImpl> struct RegisterMCRegInfo {
1241
1242private:
1243 static MCRegisterInfo *Allocator(const Triple & /*TT*/) {
1244 return new MCRegisterInfoImpl();
1245 }
1246};
1247
1248/// RegisterMCRegInfoFn - Helper template for registering a target register
1249/// info implementation. This invokes the specified function to do the
1250/// construction. Usage:
1251///
1252/// extern "C" void LLVMInitializeFooTarget() {
1253/// extern Target TheFooTarget;
1254/// RegisterMCRegInfoFn X(TheFooTarget, TheFunction);
1255/// }
1261
1262/// RegisterMCSubtargetInfo - Helper template for registering a target
1263/// subtarget info implementation. This invokes the static "Create" method
1264/// on the class to actually do the construction. Usage:
1265///
1266/// extern "C" void LLVMInitializeFooTarget() {
1267/// extern Target TheFooTarget;
1268/// RegisterMCSubtargetInfo<FooMCSubtargetInfo> X(TheFooTarget);
1269/// }
1270template <class MCSubtargetInfoImpl> struct RegisterMCSubtargetInfo {
1274
1275private:
1276 static MCSubtargetInfo *Allocator(const Triple & /*TT*/, StringRef /*CPU*/,
1277 StringRef /*FS*/) {
1278 return new MCSubtargetInfoImpl();
1279 }
1280};
1281
1282/// RegisterMCSubtargetInfoFn - Helper template for registering a target
1283/// subtarget info implementation. This invokes the specified function to
1284/// do the construction. Usage:
1285///
1286/// extern "C" void LLVMInitializeFooTarget() {
1287/// extern Target TheFooTarget;
1288/// RegisterMCSubtargetInfoFn X(TheFooTarget, TheFunction);
1289/// }
1295
1296/// RegisterTargetMachine - Helper template for registering a target machine
1297/// implementation, for use in the target machine initialization
1298/// function. Usage:
1299///
1300/// extern "C" void LLVMInitializeFooTarget() {
1301/// extern Target TheFooTarget;
1302/// RegisterTargetMachine<FooTargetMachine> X(TheFooTarget);
1303/// }
1304template <class TargetMachineImpl> struct RegisterTargetMachine {
1308
1309private:
1310 static TargetMachine *
1311 Allocator(const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
1312 const TargetOptions &Options, std::optional<Reloc::Model> RM,
1313 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT) {
1314 return new TargetMachineImpl(T, TT, CPU, FS, Options, RM, CM, OL, JIT);
1315 }
1316};
1317
1318/// RegisterMCAsmBackend - Helper template for registering a target specific
1319/// assembler backend. Usage:
1320///
1321/// extern "C" void LLVMInitializeFooMCAsmBackend() {
1322/// extern Target TheFooTarget;
1323/// RegisterMCAsmBackend<FooAsmLexer> X(TheFooTarget);
1324/// }
1325template <class MCAsmBackendImpl> struct RegisterMCAsmBackend {
1329
1330private:
1331 static MCAsmBackend *Allocator(const Target &T, const MCSubtargetInfo &STI,
1332 const MCRegisterInfo &MRI,
1333 const MCTargetOptions &Options) {
1334 return new MCAsmBackendImpl(T, STI, MRI);
1335 }
1336};
1337
1338/// RegisterMCAsmParser - Helper template for registering a target specific
1339/// assembly parser, for use in the target machine initialization
1340/// function. Usage:
1341///
1342/// extern "C" void LLVMInitializeFooMCAsmParser() {
1343/// extern Target TheFooTarget;
1344/// RegisterMCAsmParser<FooAsmParser> X(TheFooTarget);
1345/// }
1346template <class MCAsmParserImpl> struct RegisterMCAsmParser {
1350
1351private:
1352 static MCTargetAsmParser *Allocator(const MCSubtargetInfo &STI,
1353 MCAsmParser &P, const MCInstrInfo &MII,
1354 const MCTargetOptions &Options) {
1355 return new MCAsmParserImpl(STI, P, MII, Options);
1356 }
1357};
1358
1359/// RegisterAsmPrinter - Helper template for registering a target specific
1360/// assembly printer, for use in the target machine initialization
1361/// function. Usage:
1362///
1363/// extern "C" void LLVMInitializeFooAsmPrinter() {
1364/// extern Target TheFooTarget;
1365/// RegisterAsmPrinter<FooAsmPrinter> X(TheFooTarget);
1366/// }
1367template <class AsmPrinterImpl> struct RegisterAsmPrinter {
1371
1372private:
1374 std::unique_ptr<MCStreamer> &&Streamer) {
1375 return new AsmPrinterImpl(TM, std::move(Streamer));
1376 }
1377};
1378
1379/// RegisterMCCodeEmitter - Helper template for registering a target specific
1380/// machine code emitter, for use in the target initialization
1381/// function. Usage:
1382///
1383/// extern "C" void LLVMInitializeFooMCCodeEmitter() {
1384/// extern Target TheFooTarget;
1385/// RegisterMCCodeEmitter<FooCodeEmitter> X(TheFooTarget);
1386/// }
1387template <class MCCodeEmitterImpl> struct RegisterMCCodeEmitter {
1391
1392private:
1393 static MCCodeEmitter *Allocator(const MCInstrInfo & /*II*/,
1394 MCContext & /*Ctx*/) {
1395 return new MCCodeEmitterImpl();
1396 }
1397};
1398
1399} // end namespace llvm
1400
1401#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:91
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
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