xref: /freebsd/contrib/llvm-project/llvm/include/llvm/MC/MCStreamer.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- 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 declares the MCStreamer class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_MC_MCSTREAMER_H
14 #define LLVM_MC_MCSTREAMER_H
15 
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/MC/MCDirectives.h"
21 #include "llvm/MC/MCDwarf.h"
22 #include "llvm/MC/MCLinkerOptimizationHint.h"
23 #include "llvm/MC/MCPseudoProbe.h"
24 #include "llvm/MC/MCSection.h"
25 #include "llvm/MC/MCWinEH.h"
26 #include "llvm/Support/Compiler.h"
27 #include "llvm/Support/Error.h"
28 #include "llvm/Support/MD5.h"
29 #include "llvm/Support/SMLoc.h"
30 #include "llvm/Support/VersionTuple.h"
31 #include "llvm/TargetParser/ARMTargetParser.h"
32 #include <cassert>
33 #include <cstdint>
34 #include <memory>
35 #include <optional>
36 #include <string>
37 #include <utility>
38 #include <vector>
39 
40 namespace llvm {
41 
42 class APInt;
43 class AssemblerConstantPools;
44 class MCAsmBackend;
45 class MCAssembler;
46 class MCContext;
47 class MCExpr;
48 class MCInst;
49 class MCInstPrinter;
50 class MCRegister;
51 class MCStreamer;
52 class MCSubtargetInfo;
53 class MCSymbol;
54 class MCSymbolRefExpr;
55 class Triple;
56 class Twine;
57 class raw_ostream;
58 
59 namespace codeview {
60 struct DefRangeRegisterRelHeader;
61 struct DefRangeSubfieldRegisterHeader;
62 struct DefRangeRegisterHeader;
63 struct DefRangeFramePointerRelHeader;
64 }
65 
66 using MCSectionSubPair = std::pair<MCSection *, uint32_t>;
67 
68 /// Target specific streamer interface. This is used so that targets can
69 /// implement support for target specific assembly directives.
70 ///
71 /// If target foo wants to use this, it should implement 3 classes:
72 /// * FooTargetStreamer : public MCTargetStreamer
73 /// * FooTargetAsmStreamer : public FooTargetStreamer
74 /// * FooTargetELFStreamer : public FooTargetStreamer
75 ///
76 /// FooTargetStreamer should have a pure virtual method for each directive. For
77 /// example, for a ".bar symbol_name" directive, it should have
78 /// virtual emitBar(const MCSymbol &Symbol) = 0;
79 ///
80 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
81 /// method. The assembly streamer just prints ".bar symbol_name". The object
82 /// streamer does whatever is needed to implement .bar in the object file.
83 ///
84 /// In the assembly printer and parser the target streamer can be used by
85 /// calling getTargetStreamer and casting it to FooTargetStreamer:
86 ///
87 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
88 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
89 ///
90 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
91 /// *never* be treated differently. Callers should always talk to a
92 /// FooTargetStreamer.
93 class LLVM_ABI MCTargetStreamer {
94 protected:
95   MCStreamer &Streamer;
96 
97 public:
98   MCTargetStreamer(MCStreamer &S);
99   virtual ~MCTargetStreamer();
100 
getStreamer()101   MCStreamer &getStreamer() { return Streamer; }
102   MCContext &getContext();
103 
104   // Allow a target to add behavior to the EmitLabel of MCStreamer.
105   virtual void emitLabel(MCSymbol *Symbol);
106   // Allow a target to add behavior to the emitAssignment of MCStreamer.
107   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
108 
109   virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
110                               const MCInst &Inst, const MCSubtargetInfo &STI,
111                               raw_ostream &OS);
112 
113   virtual void emitDwarfFileDirective(StringRef Directive);
114 
115   /// Update streamer for a new active section.
116   ///
117   /// This is called by popSection and switchSection, if the current
118   /// section changes.
119   virtual void changeSection(const MCSection *CurSection, MCSection *Section,
120                              uint32_t SubSection, raw_ostream &OS);
121 
122   virtual void emitValue(const MCExpr *Value);
123 
124   /// Emit the bytes in \p Data into the output.
125   ///
126   /// This is used to emit bytes in \p Data as sequence of .byte directives.
127   virtual void emitRawBytes(StringRef Data);
128 
129   virtual void emitConstantPools();
130 
131   virtual void finish();
132 };
133 
134 // FIXME: declared here because it is used from
135 // lib/CodeGen/AsmPrinter/ARMException.cpp.
136 class LLVM_ABI ARMTargetStreamer : public MCTargetStreamer {
137 public:
138   ARMTargetStreamer(MCStreamer &S);
139   ~ARMTargetStreamer() override;
140 
141   virtual void emitFnStart();
142   virtual void emitFnEnd();
143   virtual void emitCantUnwind();
144   virtual void emitPersonality(const MCSymbol *Personality);
145   virtual void emitPersonalityIndex(unsigned Index);
146   virtual void emitHandlerData();
147   virtual void emitSetFP(MCRegister FpReg, MCRegister SpReg,
148                          int64_t Offset = 0);
149   virtual void emitMovSP(MCRegister Reg, int64_t Offset = 0);
150   virtual void emitPad(int64_t Offset);
151   virtual void emitRegSave(const SmallVectorImpl<MCRegister> &RegList,
152                            bool isVector);
153   virtual void emitUnwindRaw(int64_t StackOffset,
154                              const SmallVectorImpl<uint8_t> &Opcodes);
155 
156   virtual void switchVendor(StringRef Vendor);
157   virtual void emitAttribute(unsigned Attribute, unsigned Value);
158   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
159   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
160                                     StringRef StringValue = "");
161   virtual void emitFPU(ARM::FPUKind FPU);
162   virtual void emitArch(ARM::ArchKind Arch);
163   virtual void emitArchExtension(uint64_t ArchExt);
164   virtual void emitObjectArch(ARM::ArchKind Arch);
165   void emitTargetAttributes(const MCSubtargetInfo &STI);
166   virtual void finishAttributeSection();
167   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
168 
169   virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
170 
171   virtual void emitSyntaxUnified();
172 
173   virtual void emitCode16();
174   virtual void emitCode32();
175 
176   // Note in the output that the specified \p Symbol is a Thumb mode function.
177   virtual void emitThumbFunc(MCSymbol *Symbol);
178   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
179 
180   void emitConstantPools() override;
181 
182   virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide);
183   virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide);
184   virtual void emitARMWinCFISaveSP(unsigned Reg);
185   virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last);
186   virtual void emitARMWinCFISaveLR(unsigned Offset);
187   virtual void emitARMWinCFIPrologEnd(bool Fragment);
188   virtual void emitARMWinCFINop(bool Wide);
189   virtual void emitARMWinCFIEpilogStart(unsigned Condition);
190   virtual void emitARMWinCFIEpilogEnd();
191   virtual void emitARMWinCFICustom(unsigned Opcode);
192 
193   /// Reset any state between object emissions, i.e. the equivalent of
194   /// MCStreamer's reset method.
195   virtual void reset();
196 
197   /// Callback used to implement the ldr= pseudo.
198   /// Add a new entry to the constant pool for the current section and return an
199   /// MCExpr that can be used to refer to the constant pool location.
200   const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
201 
202   /// Callback used to implement the .ltorg directive.
203   /// Emit contents of constant pool for the current section.
204   void emitCurrentConstantPool();
205 
206 private:
207   std::unique_ptr<AssemblerConstantPools> ConstantPools;
208 };
209 
210 /// Streaming machine code generation interface.
211 ///
212 /// This interface is intended to provide a programmatic interface that is very
213 /// similar to the level that an assembler .s file provides.  It has callbacks
214 /// to emit bytes, handle directives, etc.  The implementation of this interface
215 /// retains state to know what the current section is etc.
216 ///
217 /// There are multiple implementations of this interface: one for writing out
218 /// a .s file, and implementations that write out .o files of various formats.
219 ///
220 class LLVM_ABI MCStreamer {
221   MCContext &Context;
222   std::unique_ptr<MCTargetStreamer> TargetStreamer;
223 
224   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
225   // This is a pair of index into DwarfFrameInfos and the MCSection associated
226   // with the frame. Note, we use an index instead of an iterator because they
227   // can be invalidated in std::vector.
228   SmallVector<std::pair<size_t, MCSection *>, 1> FrameInfoStack;
229   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
230 
231   /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
232   /// refer to each other, so use std::unique_ptr to provide pointer stability.
233   std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
234 
235   WinEH::FrameInfo *CurrentWinFrameInfo;
236   size_t CurrentProcWinFrameInfoStartIndex;
237 
238   /// This is stack of current and previous section values saved by
239   /// pushSection.
240   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
241 
242   /// Pointer to the parser's SMLoc if available. This is used to provide
243   /// locations for diagnostics.
244   const SMLoc *StartTokLocPtr = nullptr;
245 
246   /// The next unique ID to use when creating a WinCFI-related section (.pdata
247   /// or .xdata). This ID ensures that we have a one-to-one mapping from
248   /// code section to unwind info section, which MSVC's incremental linker
249   /// requires.
250   unsigned NextWinCFIID = 0;
251 
252   bool UseAssemblerInfoForParsing = true;
253 
254   /// Is the assembler allowed to insert padding automatically?  For
255   /// correctness reasons, we sometimes need to ensure instructions aren't
256   /// separated in unexpected ways.  At the moment, this feature is only
257   /// useable from an integrated assembler, but assembly syntax is under
258   /// discussion for future inclusion.
259   bool AllowAutoPadding = false;
260 
261 protected:
262   // Symbol of the current epilog for which we are processing SEH directives.
263   WinEH::FrameInfo::Epilog *CurrentWinEpilog = nullptr;
264 
265   MCFragment *CurFrag = nullptr;
266 
267   MCStreamer(MCContext &Ctx);
268 
269   /// This is called by popSection and switchSection, if the current
270   /// section changes.
271   virtual void changeSection(MCSection *, uint32_t);
272 
273   virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
274   virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
275 
getCurrentWinFrameInfo()276   WinEH::FrameInfo *getCurrentWinFrameInfo() {
277     return CurrentWinFrameInfo;
278   }
279 
280   virtual void emitWindowsUnwindTables(WinEH::FrameInfo *Frame);
281 
282   virtual void emitWindowsUnwindTables();
283 
284   virtual void emitRawTextImpl(StringRef String);
285 
286   /// Returns true if the .cv_loc directive is in the right section.
287   bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
288 
289 public:
290   MCStreamer(const MCStreamer &) = delete;
291   MCStreamer &operator=(const MCStreamer &) = delete;
292   virtual ~MCStreamer();
293 
294   void visitUsedExpr(const MCExpr &Expr);
295   virtual void visitUsedSymbol(const MCSymbol &Sym);
296 
setTargetStreamer(MCTargetStreamer * TS)297   void setTargetStreamer(MCTargetStreamer *TS) {
298     TargetStreamer.reset(TS);
299   }
300 
setStartTokLocPtr(const SMLoc * Loc)301   void setStartTokLocPtr(const SMLoc *Loc) { StartTokLocPtr = Loc; }
getStartTokLoc()302   SMLoc getStartTokLoc() const {
303     return StartTokLocPtr ? *StartTokLocPtr : SMLoc();
304   }
305 
306   /// State management
307   ///
308   virtual void reset();
309 
getContext()310   MCContext &getContext() const { return Context; }
311 
312   // MCObjectStreamer has an MCAssembler and allows more expression folding at
313   // parse time.
getAssemblerPtr()314   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
315 
setUseAssemblerInfoForParsing(bool v)316   void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
getUseAssemblerInfoForParsing()317   bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
318 
getTargetStreamer()319   MCTargetStreamer *getTargetStreamer() {
320     return TargetStreamer.get();
321   }
322 
setAllowAutoPadding(bool v)323   void setAllowAutoPadding(bool v) { AllowAutoPadding = v; }
getAllowAutoPadding()324   bool getAllowAutoPadding() const { return AllowAutoPadding; }
325 
326   MCSymbol *emitLineTableLabel();
327 
328   /// When emitting an object file, create and emit a real label. When emitting
329   /// textual assembly, this should do nothing to avoid polluting our output.
330   virtual MCSymbol *emitCFILabel();
331 
332   /// Retrieve the current frame info if one is available and it is not yet
333   /// closed. Otherwise, issue an error and return null.
334   WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
335 
336   unsigned getNumFrameInfos();
337   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const;
338 
339   bool hasUnfinishedDwarfFrameInfo();
340 
getNumWinFrameInfos()341   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
getWinFrameInfos()342   ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
343     return WinFrameInfos;
344   }
345 
getCurrentWinEpilog()346   WinEH::FrameInfo::Epilog *getCurrentWinEpilog() const {
347     return CurrentWinEpilog;
348   }
349 
isInEpilogCFI()350   bool isInEpilogCFI() const { return CurrentWinEpilog; }
351 
352   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
353 
354   /// \name Assembly File Formatting.
355   /// @{
356 
357   /// Return true if this streamer supports verbose assembly and if it is
358   /// enabled.
isVerboseAsm()359   virtual bool isVerboseAsm() const { return false; }
360 
361   /// Return true if this asm streamer supports emitting unformatted text
362   /// to the .s file with EmitRawText.
hasRawTextSupport()363   virtual bool hasRawTextSupport() const { return false; }
364 
365   /// Is the integrated assembler required for this streamer to function
366   /// correctly?
isIntegratedAssemblerRequired()367   virtual bool isIntegratedAssemblerRequired() const { return false; }
368 
369   /// Add a textual comment.
370   ///
371   /// Typically for comments that can be emitted to the generated .s
372   /// file if applicable as a QoI issue to make the output of the compiler
373   /// more readable.  This only affects the MCAsmStreamer, and only when
374   /// verbose assembly output is enabled.
375   ///
376   /// If the comment includes embedded \n's, they will each get the comment
377   /// prefix as appropriate.  The added comment should not end with a \n.
378   /// By default, each comment is terminated with an end of line, i.e. the
379   /// EOL param is set to true by default. If one prefers not to end the
380   /// comment with a new line then the EOL param should be passed
381   /// with a false value.
382   virtual void AddComment(const Twine &T, bool EOL = true) {}
383 
384   /// Return a raw_ostream that comments can be written to. Unlike
385   /// AddComment, you are required to terminate comments with \n if you use this
386   /// method.
387   virtual raw_ostream &getCommentOS();
388 
389   /// Print T and prefix it with the comment string (normally #) and
390   /// optionally a tab. This prints the comment immediately, not at the end of
391   /// the current line. It is basically a safe version of EmitRawText: since it
392   /// only prints comments, the object streamer ignores it instead of asserting.
393   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
394 
395   /// Add explicit comment T. T is required to be a valid
396   /// comment in the output and does not need to be escaped.
397   virtual void addExplicitComment(const Twine &T);
398 
399   /// Emit added explicit comments.
400   virtual void emitExplicitComments();
401 
402   /// Emit a blank line to a .s file to pretty it up.
addBlankLine()403   virtual void addBlankLine() {}
404 
405   /// @}
406 
407   /// \name Symbol & Section Management
408   /// @{
409 
410   /// Return the current section that the streamer is emitting code to.
getCurrentSection()411   MCSectionSubPair getCurrentSection() const {
412     if (!SectionStack.empty())
413       return SectionStack.back().first;
414     return MCSectionSubPair();
415   }
getCurrentSectionOnly()416   MCSection *getCurrentSectionOnly() const {
417     return CurFrag->getParent();
418   }
419 
420   /// Return the previous section that the streamer is emitting code to.
getPreviousSection()421   MCSectionSubPair getPreviousSection() const {
422     if (!SectionStack.empty())
423       return SectionStack.back().second;
424     return MCSectionSubPair();
425   }
426 
getCurrentFragment()427   MCFragment *getCurrentFragment() const {
428     assert(!getCurrentSection().first ||
429            CurFrag->getParent() == getCurrentSection().first);
430     return CurFrag;
431   }
432 
433   /// Save the current and previous section on the section stack.
pushSection()434   void pushSection() {
435     SectionStack.push_back(
436         std::make_pair(getCurrentSection(), getPreviousSection()));
437   }
438 
439   /// Restore the current and previous section from the section stack.
440   /// Calls changeSection as needed.
441   ///
442   /// Returns false if the stack was empty.
443   virtual bool popSection();
444 
445   /// Set the current section where code is being emitted to \p Section.  This
446   /// is required to update CurSection.
447   ///
448   /// This corresponds to assembler directives like .section, .text, etc.
449   virtual void switchSection(MCSection *Section, uint32_t Subsec = 0);
450   bool switchSection(MCSection *Section, const MCExpr *);
451 
452   /// Similar to switchSection, but does not print the section directive.
453   virtual void switchSectionNoPrint(MCSection *Section);
454 
455   /// Create the default sections and set the initial one.
456   virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI);
457 
458   MCSymbol *endSection(MCSection *Section);
459 
460   /// Returns the mnemonic for \p MI, if the streamer has access to a
461   /// instruction printer and returns an empty string otherwise.
getMnemonic(const MCInst & MI)462   virtual StringRef getMnemonic(const MCInst &MI) const { return ""; }
463 
464   /// Emit a label for \p Symbol into the current section.
465   ///
466   /// This corresponds to an assembler statement such as:
467   ///   foo:
468   ///
469   /// \param Symbol - The symbol to emit. A given symbol should only be
470   /// emitted as a label once, and symbols emitted as a label should never be
471   /// used in an assignment.
472   // FIXME: These emission are non-const because we mutate the symbol to
473   // add the section we're emitting it to later.
474   virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
475 
476   virtual void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
477 
478   /// Emit a .subsection_via_symbols directive.
479   virtual void emitSubsectionsViaSymbols();
480 
481   /// Emit the given list \p Options of strings as linker
482   /// options into the output.
emitLinkerOptions(ArrayRef<std::string> Kind)483   virtual void emitLinkerOptions(ArrayRef<std::string> Kind) {}
484 
485   /// Note in the output the specified region \p Kind.
emitDataRegion(MCDataRegionType Kind)486   virtual void emitDataRegion(MCDataRegionType Kind) {}
487 
488   /// Specify the Mach-O minimum deployment target version.
emitVersionMin(MCVersionMinType Type,unsigned Major,unsigned Minor,unsigned Update,VersionTuple SDKVersion)489   virtual void emitVersionMin(MCVersionMinType Type, unsigned Major,
490                               unsigned Minor, unsigned Update,
491                               VersionTuple SDKVersion) {}
492 
493   /// Emit/Specify Mach-O build version command.
494   /// \p Platform should be one of MachO::PlatformType.
emitBuildVersion(unsigned Platform,unsigned Major,unsigned Minor,unsigned Update,VersionTuple SDKVersion)495   virtual void emitBuildVersion(unsigned Platform, unsigned Major,
496                                 unsigned Minor, unsigned Update,
497                                 VersionTuple SDKVersion) {}
498 
emitDarwinTargetVariantBuildVersion(unsigned Platform,unsigned Major,unsigned Minor,unsigned Update,VersionTuple SDKVersion)499   virtual void emitDarwinTargetVariantBuildVersion(unsigned Platform,
500                                                    unsigned Major,
501                                                    unsigned Minor,
502                                                    unsigned Update,
503                                                    VersionTuple SDKVersion) {}
504 
505   void emitVersionForTarget(const Triple &Target,
506                             const VersionTuple &SDKVersion,
507                             const Triple *DarwinTargetVariantTriple,
508                             const VersionTuple &DarwinTargetVariantSDKVersion);
509 
510   /// Emit an assignment of \p Value to \p Symbol.
511   ///
512   /// This corresponds to an assembler statement such as:
513   ///  symbol = value
514   ///
515   /// The assignment generates no code, but has the side effect of binding the
516   /// value in the current context. For the assembly streamer, this prints the
517   /// binding into the .s file.
518   ///
519   /// \param Symbol - The symbol being assigned to.
520   /// \param Value - The value for the symbol.
521   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
522 
523   /// Emit an assignment of \p Value to \p Symbol, but only if \p Value is also
524   /// emitted.
525   virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value);
526 
527   /// Emit an weak reference from \p Alias to \p Symbol.
528   ///
529   /// This corresponds to an assembler statement such as:
530   ///  .weakref alias, symbol
531   ///
532   /// \param Alias - The alias that is being created.
533   /// \param Symbol - The symbol being aliased.
534   virtual void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
535 
536   /// Add the given \p Attribute to \p Symbol.
537   virtual bool emitSymbolAttribute(MCSymbol *Symbol,
538                                    MCSymbolAttr Attribute) = 0;
539 
540   /// Set the \p DescValue for the \p Symbol.
541   ///
542   /// \param Symbol - The symbol to have its n_desc field set.
543   /// \param DescValue - The value to set into the n_desc field.
544   virtual void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
545 
546   /// Start emitting COFF symbol definition
547   ///
548   /// \param Symbol - The symbol to have its External & Type fields set.
549   virtual void beginCOFFSymbolDef(const MCSymbol *Symbol);
550 
551   /// Emit the storage class of the symbol.
552   ///
553   /// \param StorageClass - The storage class the symbol should have.
554   virtual void emitCOFFSymbolStorageClass(int StorageClass);
555 
556   /// Emit the type of the symbol.
557   ///
558   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
559   virtual void emitCOFFSymbolType(int Type);
560 
561   /// Marks the end of the symbol definition.
562   virtual void endCOFFSymbolDef();
563 
564   virtual void emitCOFFSafeSEH(MCSymbol const *Symbol);
565 
566   /// Emits the symbol table index of a Symbol into the current section.
567   virtual void emitCOFFSymbolIndex(MCSymbol const *Symbol);
568 
569   /// Emits a COFF section index.
570   ///
571   /// \param Symbol - Symbol the section number relocation should point to.
572   virtual void emitCOFFSectionIndex(MCSymbol const *Symbol);
573 
574   /// Emits a COFF section relative relocation.
575   ///
576   /// \param Symbol - Symbol the section relative relocation should point to.
577   virtual void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
578 
579   /// Emits a COFF image relative relocation.
580   ///
581   /// \param Symbol - Symbol the image relative relocation should point to.
582   virtual void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
583 
584   /// Emits the physical number of the section containing the given symbol as
585   /// assigned during object writing (i.e., this is not a runtime relocation).
586   virtual void emitCOFFSecNumber(MCSymbol const *Symbol);
587 
588   /// Emits the offset of the symbol from the beginning of the section during
589   /// object writing (i.e., this is not a runtime relocation).
590   virtual void emitCOFFSecOffset(MCSymbol const *Symbol);
591 
592   /// Emits an lcomm directive with XCOFF csect information.
593   ///
594   /// \param LabelSym - Label on the block of storage.
595   /// \param Size - The size of the block of storage.
596   /// \param CsectSym - Csect name for the block of storage.
597   /// \param Alignment - The alignment of the symbol in bytes.
598   virtual void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
599                                           MCSymbol *CsectSym, Align Alignment);
600 
601   /// Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
602   ///
603   /// \param Symbol - The symbol to emit.
604   /// \param Linkage - The linkage of the symbol to emit.
605   /// \param Visibility - The visibility of the symbol to emit or MCSA_Invalid
606   /// if the symbol does not have an explicit visibility.
607   virtual void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
608                                                     MCSymbolAttr Linkage,
609                                                     MCSymbolAttr Visibility);
610 
611   /// Emit a XCOFF .rename directive which creates a synonym for an illegal or
612   /// undesirable name.
613   ///
614   /// \param Name - The name used internally in the assembly for references to
615   /// the symbol.
616   /// \param Rename - The value to which the Name parameter is
617   /// changed at the end of assembly.
618   virtual void emitXCOFFRenameDirective(const MCSymbol *Name, StringRef Rename);
619 
620   /// Emit an XCOFF .except directive which adds information about
621   /// a trap instruction to the object file exception section
622   ///
623   /// \param Symbol - The function containing the trap.
624   /// \param Lang - The language code for the exception entry.
625   /// \param Reason - The reason code for the exception entry.
626   virtual void emitXCOFFExceptDirective(const MCSymbol *Symbol,
627                                         const MCSymbol *Trap,
628                                         unsigned Lang, unsigned Reason,
629                                         unsigned FunctionSize, bool hasDebug);
630 
631   /// Emit a XCOFF .ref directive which creates R_REF type entry in the
632   /// relocation table for one or more symbols.
633   ///
634   /// \param Sym - The symbol on the .ref directive.
635   virtual void emitXCOFFRefDirective(const MCSymbol *Symbol);
636 
637   /// Emit a C_INFO symbol with XCOFF embedded metadata to the .info section.
638   ///
639   /// \param Name - The embedded metadata name
640   /// \param Metadata - The embedded metadata
641   virtual void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata);
642 
643   /// Emit an ELF .size directive.
644   ///
645   /// This corresponds to an assembler statement such as:
646   ///  .size symbol, expression
647   virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
648 
649   /// Emit an ELF .symver directive.
650   ///
651   /// This corresponds to an assembler statement such as:
652   ///  .symver _start, foo@@SOME_VERSION
653   virtual void emitELFSymverDirective(const MCSymbol *OriginalSym,
654                                       StringRef Name, bool KeepOriginalSym);
655 
656   /// Emit a Linker Optimization Hint (LOH) directive.
657   /// \param Args - Arguments of the LOH.
emitLOHDirective(MCLOHType Kind,const MCLOHArgs & Args)658   virtual void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
659 
660   /// Emit a .gnu_attribute directive.
emitGNUAttribute(unsigned Tag,unsigned Value)661   virtual void emitGNUAttribute(unsigned Tag, unsigned Value) {}
662 
663   /// Emit a common symbol.
664   ///
665   /// \param Symbol - The common symbol to emit.
666   /// \param Size - The size of the common symbol.
667   /// \param ByteAlignment - The alignment of the symbol.
668   virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
669                                 Align ByteAlignment) = 0;
670 
671   /// Emit a local common (.lcomm) symbol.
672   ///
673   /// \param Symbol - The common symbol to emit.
674   /// \param Size - The size of the common symbol.
675   /// \param ByteAlignment - The alignment of the common symbol in bytes.
676   virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
677                                      Align ByteAlignment);
678 
679   /// Emit the zerofill section and an optional symbol.
680   ///
681   /// \param Section - The zerofill section to create and or to put the symbol
682   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
683   /// \param Size - The size of the zerofill symbol.
684   /// \param ByteAlignment - The alignment of the zerofill symbol.
685   virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
686                             uint64_t Size = 0, Align ByteAlignment = Align(1),
687                             SMLoc Loc = SMLoc());
688 
689   /// Emit a thread local bss (.tbss) symbol.
690   ///
691   /// \param Section - The thread local common section.
692   /// \param Symbol - The thread local common symbol to emit.
693   /// \param Size - The size of the symbol.
694   /// \param ByteAlignment - The alignment of the thread local common symbol.
695   virtual void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
696                               uint64_t Size, Align ByteAlignment = Align(1));
697 
698   /// @}
699   /// \name Generating Data
700   /// @{
701 
702   /// Emit the bytes in \p Data into the output.
703   ///
704   /// This is used to implement assembler directives such as .byte, .ascii,
705   /// etc.
706   virtual void emitBytes(StringRef Data);
707 
708   /// Functionally identical to EmitBytes. When emitting textual assembly, this
709   /// method uses .byte directives instead of .ascii or .asciz for readability.
710   virtual void emitBinaryData(StringRef Data);
711 
712   /// Emit the expression \p Value into the output as a native
713   /// integer of the given \p Size bytes.
714   ///
715   /// This is used to implement assembler directives such as .word, .quad,
716   /// etc.
717   ///
718   /// \param Value - The value to emit.
719   /// \param Size - The size of the integer (in bytes) to emit. This must
720   /// match a native machine width.
721   /// \param Loc - The location of the expression for error reporting.
722   virtual void emitValueImpl(const MCExpr *Value, unsigned Size,
723                              SMLoc Loc = SMLoc());
724 
725   void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
726 
727   /// Special case of EmitValue that avoids the client having
728   /// to pass in a MCExpr for constant integers.
729   virtual void emitIntValue(uint64_t Value, unsigned Size);
730   virtual void emitIntValue(const APInt &Value);
731 
732   /// Special case of EmitValue that avoids the client having to pass
733   /// in a MCExpr for constant integers & prints in Hex format for certain
734   /// modes.
emitIntValueInHex(uint64_t Value,unsigned Size)735   virtual void emitIntValueInHex(uint64_t Value, unsigned Size) {
736     emitIntValue(Value, Size);
737   }
738 
emitInt8(uint64_t Value)739   void emitInt8(uint64_t Value) { emitIntValue(Value, 1); }
emitInt16(uint64_t Value)740   void emitInt16(uint64_t Value) { emitIntValue(Value, 2); }
emitInt32(uint64_t Value)741   void emitInt32(uint64_t Value) { emitIntValue(Value, 4); }
emitInt64(uint64_t Value)742   void emitInt64(uint64_t Value) { emitIntValue(Value, 8); }
743 
744   /// Special case of EmitValue that avoids the client having to pass
745   /// in a MCExpr for constant integers & prints in Hex format for certain
746   /// modes, pads the field with leading zeros to Size width
emitIntValueInHexWithPadding(uint64_t Value,unsigned Size)747   virtual void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) {
748     emitIntValue(Value, Size);
749   }
750 
751   virtual void emitULEB128Value(const MCExpr *Value);
752 
753   virtual void emitSLEB128Value(const MCExpr *Value);
754 
755   /// Special case of EmitULEB128Value that avoids the client having to
756   /// pass in a MCExpr for constant integers.
757   unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
758 
759   /// Special case of EmitSLEB128Value that avoids the client having to
760   /// pass in a MCExpr for constant integers.
761   unsigned emitSLEB128IntValue(int64_t Value);
762 
763   /// Special case of EmitValue that avoids the client having to pass in
764   /// a MCExpr for MCSymbols.
765   void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
766                        bool IsSectionRelative = false);
767 
768   /// Emit NumBytes bytes worth of the value specified by FillValue.
769   /// This implements directives such as '.space'.
770   void emitFill(uint64_t NumBytes, uint8_t FillValue);
771 
772   /// Emit \p Size bytes worth of the value specified by \p FillValue.
773   ///
774   /// This is used to implement assembler directives such as .space or .skip.
775   ///
776   /// \param NumBytes - The number of bytes to emit.
777   /// \param FillValue - The value to use when filling bytes.
778   /// \param Loc - The location of the expression for error reporting.
779   virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
780                         SMLoc Loc = SMLoc());
781 
782   /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
783   /// taken from the lowest order 4 bytes of \p Expr expression.
784   ///
785   /// This is used to implement assembler directives such as .fill.
786   ///
787   /// \param NumValues - The number of copies of \p Size bytes to emit.
788   /// \param Size - The size (in bytes) of each repeated value.
789   /// \param Expr - The expression from which \p Size bytes are used.
790   virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
791                         SMLoc Loc = SMLoc());
792 
793   virtual void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
794                         SMLoc Loc, const MCSubtargetInfo& STI);
795 
796   /// Emit NumBytes worth of zeros.
797   /// This function properly handles data in virtual sections.
798   void emitZeros(uint64_t NumBytes);
799 
800   /// Emit some number of copies of \p Value until the byte alignment \p
801   /// ByteAlignment is reached.
802   ///
803   /// If the number of bytes need to emit for the alignment is not a multiple
804   /// of \p ValueSize, then the contents of the emitted fill bytes is
805   /// undefined.
806   ///
807   /// This used to implement the .align assembler directive.
808   ///
809   /// \param Alignment - The alignment to reach.
810   /// \param Fill - The value to use when filling bytes.
811   /// \param FillLen - The size of the integer (in bytes) to emit for
812   /// \p Value. This must match a native machine width.
813   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
814   /// the alignment cannot be reached in this many bytes, no bytes are
815   /// emitted.
816   virtual void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
817                                     uint8_t FillLen = 1,
818                                     unsigned MaxBytesToEmit = 0);
819 
820   /// Emit nops until the byte alignment \p ByteAlignment is reached.
821   ///
822   /// This used to align code where the alignment bytes may be executed.  This
823   /// can emit different bytes for different sizes to optimize execution.
824   ///
825   /// \param Alignment - The alignment to reach.
826   /// \param STI - The MCSubtargetInfo in operation when padding is emitted.
827   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
828   /// the alignment cannot be reached in this many bytes, no bytes are
829   /// emitted.
830   virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
831                                  unsigned MaxBytesToEmit = 0);
832 
833   /// Emit some number of copies of \p Value until the byte offset \p
834   /// Offset is reached.
835   ///
836   /// This is used to implement assembler directives such as .org.
837   ///
838   /// \param Offset - The offset to reach. This may be an expression, but the
839   /// expression must be associated with the current section.
840   /// \param Value - The value to use when filling bytes.
841   virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
842                                  SMLoc Loc);
843 
844   /// @}
845 
846   /// Switch to a new logical file.  This is used to implement the '.file
847   /// "foo.c"' assembler directive.
848   virtual void emitFileDirective(StringRef Filename);
849 
850   /// Emit ".file assembler diretive with additioal info.
851   virtual void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
852                                  StringRef TimeStamp, StringRef Description);
853 
854   /// Emit the "identifiers" directive.  This implements the
855   /// '.ident "version foo"' assembler directive.
emitIdent(StringRef IdentString)856   virtual void emitIdent(StringRef IdentString) {}
857 
858   /// Associate a filename with a specified logical file number.  This
859   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
860   unsigned emitDwarfFileDirective(
861       unsigned FileNo, StringRef Directory, StringRef Filename,
862       std::optional<MD5::MD5Result> Checksum = std::nullopt,
863       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0) {
864     return cantFail(
865         tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
866                                   Source, CUID));
867   }
868 
869   /// Associate a filename with a specified logical file number.
870   /// Also associate a directory, optional checksum, and optional source
871   /// text with the logical file.  This implements the DWARF2
872   /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
873   /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
874   virtual Expected<unsigned> tryEmitDwarfFileDirective(
875       unsigned FileNo, StringRef Directory, StringRef Filename,
876       std::optional<MD5::MD5Result> Checksum = std::nullopt,
877       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0);
878 
879   /// Specify the "root" file of the compilation, using the ".file 0" extension.
880   virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
881                                        std::optional<MD5::MD5Result> Checksum,
882                                        std::optional<StringRef> Source,
883                                        unsigned CUID = 0);
884 
885   virtual void emitCFIBKeyFrame();
886   virtual void emitCFIMTETaggedFrame();
887 
888   /// This implements the DWARF2 '.loc fileno lineno ...' assembler
889   /// directive.
890   virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
891                                      unsigned Column, unsigned Flags,
892                                      unsigned Isa, unsigned Discriminator,
893                                      StringRef FileName,
894                                      StringRef Comment = {});
895 
896   /// This implements the '.loc_label Name' directive.
897   virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name);
898 
899   /// Associate a filename with a specified logical file number, and also
900   /// specify that file's checksum information.  This implements the '.cv_file 4
901   /// "foo.c"' assembler directive. Returns true on success.
902   virtual bool emitCVFileDirective(unsigned FileNo, StringRef Filename,
903                                    ArrayRef<uint8_t> Checksum,
904                                    unsigned ChecksumKind);
905 
906   /// Introduces a function id for use with .cv_loc.
907   virtual bool emitCVFuncIdDirective(unsigned FunctionId);
908 
909   /// Introduces an inline call site id for use with .cv_loc. Includes
910   /// extra information for inline line table generation.
911   virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
912                                            unsigned IAFile, unsigned IALine,
913                                            unsigned IACol, SMLoc Loc);
914 
915   /// This implements the CodeView '.cv_loc' assembler directive.
916   virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
917                                   unsigned Line, unsigned Column,
918                                   bool PrologueEnd, bool IsStmt,
919                                   StringRef FileName, SMLoc Loc);
920 
921   /// This implements the CodeView '.cv_linetable' assembler directive.
922   virtual void emitCVLinetableDirective(unsigned FunctionId,
923                                         const MCSymbol *FnStart,
924                                         const MCSymbol *FnEnd);
925 
926   /// This implements the CodeView '.cv_inline_linetable' assembler
927   /// directive.
928   virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
929                                               unsigned SourceFileId,
930                                               unsigned SourceLineNum,
931                                               const MCSymbol *FnStartSym,
932                                               const MCSymbol *FnEndSym);
933 
934   /// This implements the CodeView '.cv_def_range' assembler
935   /// directive.
936   virtual void emitCVDefRangeDirective(
937       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
938       StringRef FixedSizePortion);
939 
940   virtual void emitCVDefRangeDirective(
941       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
942       codeview::DefRangeRegisterRelHeader DRHdr);
943 
944   virtual void emitCVDefRangeDirective(
945       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
946       codeview::DefRangeSubfieldRegisterHeader DRHdr);
947 
948   virtual void emitCVDefRangeDirective(
949       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
950       codeview::DefRangeRegisterHeader DRHdr);
951 
952   virtual void emitCVDefRangeDirective(
953       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
954       codeview::DefRangeFramePointerRelHeader DRHdr);
955 
956   /// This implements the CodeView '.cv_stringtable' assembler directive.
emitCVStringTableDirective()957   virtual void emitCVStringTableDirective() {}
958 
959   /// This implements the CodeView '.cv_filechecksums' assembler directive.
emitCVFileChecksumsDirective()960   virtual void emitCVFileChecksumsDirective() {}
961 
962   /// This implements the CodeView '.cv_filechecksumoffset' assembler
963   /// directive.
emitCVFileChecksumOffsetDirective(unsigned FileNo)964   virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo) {}
965 
966   /// This implements the CodeView '.cv_fpo_data' assembler directive.
967   virtual void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
968 
969   /// Emit the absolute difference between two symbols.
970   ///
971   /// \pre Offset of \c Hi is greater than the offset \c Lo.
972   virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
973                                       unsigned Size);
974 
975   /// Emit the absolute difference between two symbols encoded with ULEB128.
976   virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
977                                                const MCSymbol *Lo);
978 
979   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
980   virtual void emitCFISections(bool EH, bool Debug);
981   void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
982   void emitCFIEndProc();
983   virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc = {});
984   virtual void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc = {});
985   virtual void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc = {});
986   virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
987                                        int64_t AddressSpace, SMLoc Loc = {});
988   virtual void emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc = {});
989   virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
990   virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding);
991   virtual void emitCFIRememberState(SMLoc Loc);
992   virtual void emitCFIRestoreState(SMLoc Loc);
993   virtual void emitCFISameValue(int64_t Register, SMLoc Loc = {});
994   virtual void emitCFIRestore(int64_t Register, SMLoc Loc = {});
995   virtual void emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc);
996   virtual void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc = {});
997   virtual void emitCFIEscape(StringRef Values, SMLoc Loc = {});
998   virtual void emitCFIReturnColumn(int64_t Register);
999   virtual void emitCFIGnuArgsSize(int64_t Size, SMLoc Loc = {});
1000   virtual void emitCFISignalFrame();
1001   virtual void emitCFIUndefined(int64_t Register, SMLoc Loc = {});
1002   virtual void emitCFIRegister(int64_t Register1, int64_t Register2,
1003                                SMLoc Loc = {});
1004   virtual void emitCFIWindowSave(SMLoc Loc = {});
1005   virtual void emitCFINegateRAState(SMLoc Loc = {});
1006   virtual void emitCFINegateRAStateWithPC(SMLoc Loc = {});
1007   virtual void emitCFILabelDirective(SMLoc Loc, StringRef Name);
1008   virtual void emitCFIValOffset(int64_t Register, int64_t Offset,
1009                                 SMLoc Loc = {});
1010 
1011   virtual void emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
1012   virtual void emitWinCFIEndProc(SMLoc Loc = SMLoc());
1013   /// This is used on platforms, such as Windows on ARM64, that require function
1014   /// or funclet sizes to be emitted in .xdata before the End marker is emitted
1015   /// for the frame.  We cannot use the End marker, as it is not set at the
1016   /// point of emitting .xdata, in order to indicate that the frame is active.
1017   virtual void emitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
1018   virtual void emitWinCFIStartChained(SMLoc Loc = SMLoc());
1019   virtual void emitWinCFIEndChained(SMLoc Loc = SMLoc());
1020   virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc = SMLoc());
1021   virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset,
1022                                   SMLoc Loc = SMLoc());
1023   virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
1024   virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset,
1025                                  SMLoc Loc = SMLoc());
1026   virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
1027                                  SMLoc Loc = SMLoc());
1028   virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
1029   virtual void emitWinCFIEndProlog(SMLoc Loc = SMLoc());
1030   virtual void emitWinCFIBeginEpilogue(SMLoc Loc = SMLoc());
1031   virtual void emitWinCFIEndEpilogue(SMLoc Loc = SMLoc());
1032   virtual void emitWinCFIUnwindV2Start(SMLoc Loc = SMLoc());
1033   virtual void emitWinCFIUnwindVersion(uint8_t Version, SMLoc Loc = SMLoc());
1034   virtual void emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
1035                                 SMLoc Loc = SMLoc());
1036   virtual void emitWinEHHandlerData(SMLoc Loc = SMLoc());
1037 
1038   virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
1039                                   const MCSymbolRefExpr *To, uint64_t Count);
1040 
1041   /// Get the .pdata section used for the given section. Typically the given
1042   /// section is either the main .text section or some other COMDAT .text
1043   /// section, but it may be any section containing code.
1044   MCSection *getAssociatedPDataSection(const MCSection *TextSec);
1045 
1046   /// Get the .xdata section used for the given section.
1047   MCSection *getAssociatedXDataSection(const MCSection *TextSec);
1048 
1049   virtual void emitSyntaxDirective();
1050 
1051   /// Record a relocation described by the .reloc directive. Return std::nullopt
1052   /// if succeeded. Otherwise, return a pair (Name is invalid, error message).
1053   virtual std::optional<std::pair<bool, std::string>>
emitRelocDirective(const MCExpr & Offset,StringRef Name,const MCExpr * Expr,SMLoc Loc,const MCSubtargetInfo & STI)1054   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
1055                      SMLoc Loc, const MCSubtargetInfo &STI) {
1056     return std::nullopt;
1057   }
1058 
emitAddrsig()1059   virtual void emitAddrsig() {}
emitAddrsigSym(const MCSymbol * Sym)1060   virtual void emitAddrsigSym(const MCSymbol *Sym) {}
1061 
1062   /// Emit the given \p Instruction into the current section.
1063   virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
1064 
1065   /// Emit the a pseudo probe into the current section.
1066   virtual void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
1067                                uint64_t Attr, uint64_t Discriminator,
1068                                const MCPseudoProbeInlineStack &InlineStack,
1069                                MCSymbol *FnSym);
1070 
1071   /// Set the bundle alignment mode from now on in the section.
1072   /// The value 1 means turn the bundle alignment off.
1073   virtual void emitBundleAlignMode(Align Alignment);
1074 
1075   /// The following instructions are a bundle-locked group.
1076   ///
1077   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
1078   ///                     the end of a bundle.
1079   virtual void emitBundleLock(bool AlignToEnd);
1080 
1081   /// Ends a bundle-locked group.
1082   virtual void emitBundleUnlock();
1083 
1084   /// If this file is backed by a assembly streamer, this dumps the
1085   /// specified string in the output .s file.  This capability is indicated by
1086   /// the hasRawTextSupport() predicate.  By default this aborts.
1087   void emitRawText(const Twine &String);
1088 
1089   /// Streamer specific finalization.
1090   virtual void finishImpl();
1091   /// Finish emission of machine code.
1092   void finish(SMLoc EndLoc = SMLoc());
1093 
mayHaveInstructions(MCSection & Sec)1094   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
1095 
1096   /// Emit a special value of 0xffffffff if producing 64-bit debugging info.
1097   void maybeEmitDwarf64Mark();
1098 
1099   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1100   /// according to the settings.
1101   virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment);
1102 
1103   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1104   /// according to the settings.
1105   /// Return the end symbol generated inside, the caller needs to emit it.
1106   virtual MCSymbol *emitDwarfUnitLength(const Twine &Prefix,
1107                                         const Twine &Comment);
1108 
1109   /// Emit the debug line start label.
1110   virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
1111 
1112   /// Emit the debug line end entry.
1113   virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
1114                                      MCSymbol *EndLabel = nullptr) {}
1115 
1116   /// If targets does not support representing debug line section by .loc/.file
1117   /// directives in assembly output, we need to populate debug line section with
1118   /// raw debug line contents.
emitDwarfAdvanceLineAddr(int64_t LineDelta,const MCSymbol * LastLabel,const MCSymbol * Label,unsigned PointerSize)1119   virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta,
1120                                         const MCSymbol *LastLabel,
1121                                         const MCSymbol *Label,
1122                                         unsigned PointerSize) {}
1123 };
1124 
getContext()1125 inline MCContext &MCTargetStreamer::getContext() {
1126   return Streamer.getContext();
1127 }
1128 
1129 /// Create a dummy machine code streamer, which does nothing. This is useful for
1130 /// timing the assembler front end.
1131 LLVM_ABI MCStreamer *createNullStreamer(MCContext &Ctx);
1132 
1133 } // end namespace llvm
1134 
1135 #endif // LLVM_MC_MCSTREAMER_H
1136