Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file declares the MCStreamer class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCSTREAMER_H
0014 #define LLVM_MC_MCSTREAMER_H
0015 
0016 #include "llvm/ADT/ArrayRef.h"
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/ADT/SmallVector.h"
0019 #include "llvm/ADT/StringRef.h"
0020 #include "llvm/MC/MCDirectives.h"
0021 #include "llvm/MC/MCDwarf.h"
0022 #include "llvm/MC/MCFragment.h"
0023 #include "llvm/MC/MCLinkerOptimizationHint.h"
0024 #include "llvm/MC/MCPseudoProbe.h"
0025 #include "llvm/MC/MCWinEH.h"
0026 #include "llvm/Support/Error.h"
0027 #include "llvm/Support/MD5.h"
0028 #include "llvm/Support/SMLoc.h"
0029 #include "llvm/Support/VersionTuple.h"
0030 #include "llvm/TargetParser/ARMTargetParser.h"
0031 #include <cassert>
0032 #include <cstdint>
0033 #include <memory>
0034 #include <optional>
0035 #include <string>
0036 #include <utility>
0037 #include <vector>
0038 
0039 namespace llvm {
0040 
0041 class APInt;
0042 class AssemblerConstantPools;
0043 class MCAsmBackend;
0044 class MCAssembler;
0045 class MCContext;
0046 class MCExpr;
0047 class MCFragment;
0048 class MCInst;
0049 class MCInstPrinter;
0050 class MCRegister;
0051 class MCSection;
0052 class MCStreamer;
0053 class MCSubtargetInfo;
0054 class MCSymbol;
0055 class MCSymbolRefExpr;
0056 class Triple;
0057 class Twine;
0058 class raw_ostream;
0059 
0060 namespace codeview {
0061 struct DefRangeRegisterRelHeader;
0062 struct DefRangeSubfieldRegisterHeader;
0063 struct DefRangeRegisterHeader;
0064 struct DefRangeFramePointerRelHeader;
0065 }
0066 
0067 using MCSectionSubPair = std::pair<MCSection *, uint32_t>;
0068 
0069 /// Target specific streamer interface. This is used so that targets can
0070 /// implement support for target specific assembly directives.
0071 ///
0072 /// If target foo wants to use this, it should implement 3 classes:
0073 /// * FooTargetStreamer : public MCTargetStreamer
0074 /// * FooTargetAsmStreamer : public FooTargetStreamer
0075 /// * FooTargetELFStreamer : public FooTargetStreamer
0076 ///
0077 /// FooTargetStreamer should have a pure virtual method for each directive. For
0078 /// example, for a ".bar symbol_name" directive, it should have
0079 /// virtual emitBar(const MCSymbol &Symbol) = 0;
0080 ///
0081 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
0082 /// method. The assembly streamer just prints ".bar symbol_name". The object
0083 /// streamer does whatever is needed to implement .bar in the object file.
0084 ///
0085 /// In the assembly printer and parser the target streamer can be used by
0086 /// calling getTargetStreamer and casting it to FooTargetStreamer:
0087 ///
0088 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
0089 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
0090 ///
0091 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
0092 /// *never* be treated differently. Callers should always talk to a
0093 /// FooTargetStreamer.
0094 class MCTargetStreamer {
0095 protected:
0096   MCStreamer &Streamer;
0097 
0098 public:
0099   MCTargetStreamer(MCStreamer &S);
0100   virtual ~MCTargetStreamer();
0101 
0102   MCStreamer &getStreamer() { return Streamer; }
0103 
0104   // Allow a target to add behavior to the EmitLabel of MCStreamer.
0105   virtual void emitLabel(MCSymbol *Symbol);
0106   // Allow a target to add behavior to the emitAssignment of MCStreamer.
0107   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
0108 
0109   virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
0110                               const MCInst &Inst, const MCSubtargetInfo &STI,
0111                               raw_ostream &OS);
0112 
0113   virtual void emitDwarfFileDirective(StringRef Directive);
0114 
0115   /// Update streamer for a new active section.
0116   ///
0117   /// This is called by popSection and switchSection, if the current
0118   /// section changes.
0119   virtual void changeSection(const MCSection *CurSection, MCSection *Section,
0120                              uint32_t SubSection, raw_ostream &OS);
0121 
0122   virtual void emitValue(const MCExpr *Value);
0123 
0124   /// Emit the bytes in \p Data into the output.
0125   ///
0126   /// This is used to emit bytes in \p Data as sequence of .byte directives.
0127   virtual void emitRawBytes(StringRef Data);
0128 
0129   virtual void emitConstantPools();
0130 
0131   virtual void finish();
0132 };
0133 
0134 // FIXME: declared here because it is used from
0135 // lib/CodeGen/AsmPrinter/ARMException.cpp.
0136 class ARMTargetStreamer : public MCTargetStreamer {
0137 public:
0138   ARMTargetStreamer(MCStreamer &S);
0139   ~ARMTargetStreamer() override;
0140 
0141   virtual void emitFnStart();
0142   virtual void emitFnEnd();
0143   virtual void emitCantUnwind();
0144   virtual void emitPersonality(const MCSymbol *Personality);
0145   virtual void emitPersonalityIndex(unsigned Index);
0146   virtual void emitHandlerData();
0147   virtual void emitSetFP(MCRegister FpReg, MCRegister SpReg,
0148                          int64_t Offset = 0);
0149   virtual void emitMovSP(MCRegister Reg, int64_t Offset = 0);
0150   virtual void emitPad(int64_t Offset);
0151   virtual void emitRegSave(const SmallVectorImpl<MCRegister> &RegList,
0152                            bool isVector);
0153   virtual void emitUnwindRaw(int64_t StackOffset,
0154                              const SmallVectorImpl<uint8_t> &Opcodes);
0155 
0156   virtual void switchVendor(StringRef Vendor);
0157   virtual void emitAttribute(unsigned Attribute, unsigned Value);
0158   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
0159   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
0160                                     StringRef StringValue = "");
0161   virtual void emitFPU(ARM::FPUKind FPU);
0162   virtual void emitArch(ARM::ArchKind Arch);
0163   virtual void emitArchExtension(uint64_t ArchExt);
0164   virtual void emitObjectArch(ARM::ArchKind Arch);
0165   void emitTargetAttributes(const MCSubtargetInfo &STI);
0166   virtual void finishAttributeSection();
0167   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
0168 
0169   virtual void annotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
0170 
0171   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
0172 
0173   void emitConstantPools() override;
0174 
0175   virtual void emitARMWinCFIAllocStack(unsigned Size, bool Wide);
0176   virtual void emitARMWinCFISaveRegMask(unsigned Mask, bool Wide);
0177   virtual void emitARMWinCFISaveSP(unsigned Reg);
0178   virtual void emitARMWinCFISaveFRegs(unsigned First, unsigned Last);
0179   virtual void emitARMWinCFISaveLR(unsigned Offset);
0180   virtual void emitARMWinCFIPrologEnd(bool Fragment);
0181   virtual void emitARMWinCFINop(bool Wide);
0182   virtual void emitARMWinCFIEpilogStart(unsigned Condition);
0183   virtual void emitARMWinCFIEpilogEnd();
0184   virtual void emitARMWinCFICustom(unsigned Opcode);
0185 
0186   /// Reset any state between object emissions, i.e. the equivalent of
0187   /// MCStreamer's reset method.
0188   virtual void reset();
0189 
0190   /// Callback used to implement the ldr= pseudo.
0191   /// Add a new entry to the constant pool for the current section and return an
0192   /// MCExpr that can be used to refer to the constant pool location.
0193   const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
0194 
0195   /// Callback used to implement the .ltorg directive.
0196   /// Emit contents of constant pool for the current section.
0197   void emitCurrentConstantPool();
0198 
0199 private:
0200   std::unique_ptr<AssemblerConstantPools> ConstantPools;
0201 };
0202 
0203 /// Streaming machine code generation interface.
0204 ///
0205 /// This interface is intended to provide a programmatic interface that is very
0206 /// similar to the level that an assembler .s file provides.  It has callbacks
0207 /// to emit bytes, handle directives, etc.  The implementation of this interface
0208 /// retains state to know what the current section is etc.
0209 ///
0210 /// There are multiple implementations of this interface: one for writing out
0211 /// a .s file, and implementations that write out .o files of various formats.
0212 ///
0213 class MCStreamer {
0214   MCContext &Context;
0215   std::unique_ptr<MCTargetStreamer> TargetStreamer;
0216 
0217   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
0218   // This is a pair of index into DwarfFrameInfos and the MCSection associated
0219   // with the frame. Note, we use an index instead of an iterator because they
0220   // can be invalidated in std::vector.
0221   SmallVector<std::pair<size_t, MCSection *>, 1> FrameInfoStack;
0222   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
0223 
0224   /// Similar to DwarfFrameInfos, but for SEH unwind info. Chained frames may
0225   /// refer to each other, so use std::unique_ptr to provide pointer stability.
0226   std::vector<std::unique_ptr<WinEH::FrameInfo>> WinFrameInfos;
0227 
0228   WinEH::FrameInfo *CurrentWinFrameInfo;
0229   size_t CurrentProcWinFrameInfoStartIndex;
0230 
0231   /// This is stack of current and previous section values saved by
0232   /// pushSection.
0233   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
0234 
0235   /// Pointer to the parser's SMLoc if available. This is used to provide
0236   /// locations for diagnostics.
0237   const SMLoc *StartTokLocPtr = nullptr;
0238 
0239   /// The next unique ID to use when creating a WinCFI-related section (.pdata
0240   /// or .xdata). This ID ensures that we have a one-to-one mapping from
0241   /// code section to unwind info section, which MSVC's incremental linker
0242   /// requires.
0243   unsigned NextWinCFIID = 0;
0244 
0245   bool UseAssemblerInfoForParsing = true;
0246 
0247   /// Is the assembler allowed to insert padding automatically?  For
0248   /// correctness reasons, we sometimes need to ensure instructions aren't
0249   /// separated in unexpected ways.  At the moment, this feature is only
0250   /// useable from an integrated assembler, but assembly syntax is under
0251   /// discussion for future inclusion.
0252   bool AllowAutoPadding = false;
0253 
0254 protected:
0255   MCFragment *CurFrag = nullptr;
0256 
0257   MCStreamer(MCContext &Ctx);
0258 
0259   /// This is called by popSection and switchSection, if the current
0260   /// section changes.
0261   virtual void changeSection(MCSection *, uint32_t);
0262 
0263   virtual void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
0264   virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
0265 
0266   WinEH::FrameInfo *getCurrentWinFrameInfo() {
0267     return CurrentWinFrameInfo;
0268   }
0269 
0270   virtual void emitWindowsUnwindTables(WinEH::FrameInfo *Frame);
0271 
0272   virtual void emitWindowsUnwindTables();
0273 
0274   virtual void emitRawTextImpl(StringRef String);
0275 
0276   /// Returns true if the .cv_loc directive is in the right section.
0277   bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc);
0278 
0279 public:
0280   MCStreamer(const MCStreamer &) = delete;
0281   MCStreamer &operator=(const MCStreamer &) = delete;
0282   virtual ~MCStreamer();
0283 
0284   void visitUsedExpr(const MCExpr &Expr);
0285   virtual void visitUsedSymbol(const MCSymbol &Sym);
0286 
0287   void setTargetStreamer(MCTargetStreamer *TS) {
0288     TargetStreamer.reset(TS);
0289   }
0290 
0291   void setStartTokLocPtr(const SMLoc *Loc) { StartTokLocPtr = Loc; }
0292   SMLoc getStartTokLoc() const {
0293     return StartTokLocPtr ? *StartTokLocPtr : SMLoc();
0294   }
0295 
0296   /// State management
0297   ///
0298   virtual void reset();
0299 
0300   MCContext &getContext() const { return Context; }
0301 
0302   // MCObjectStreamer has an MCAssembler and allows more expression folding at
0303   // parse time.
0304   virtual MCAssembler *getAssemblerPtr() { return nullptr; }
0305 
0306   void setUseAssemblerInfoForParsing(bool v) { UseAssemblerInfoForParsing = v; }
0307   bool getUseAssemblerInfoForParsing() { return UseAssemblerInfoForParsing; }
0308 
0309   MCTargetStreamer *getTargetStreamer() {
0310     return TargetStreamer.get();
0311   }
0312 
0313   void setAllowAutoPadding(bool v) { AllowAutoPadding = v; }
0314   bool getAllowAutoPadding() const { return AllowAutoPadding; }
0315 
0316   MCSymbol *emitLineTableLabel();
0317 
0318   /// When emitting an object file, create and emit a real label. When emitting
0319   /// textual assembly, this should do nothing to avoid polluting our output.
0320   virtual MCSymbol *emitCFILabel();
0321 
0322   /// Retrieve the current frame info if one is available and it is not yet
0323   /// closed. Otherwise, issue an error and return null.
0324   WinEH::FrameInfo *EnsureValidWinFrameInfo(SMLoc Loc);
0325 
0326   unsigned getNumFrameInfos();
0327   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const;
0328 
0329   bool hasUnfinishedDwarfFrameInfo();
0330 
0331   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
0332   ArrayRef<std::unique_ptr<WinEH::FrameInfo>> getWinFrameInfos() const {
0333     return WinFrameInfos;
0334   }
0335 
0336   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
0337 
0338   /// \name Assembly File Formatting.
0339   /// @{
0340 
0341   /// Return true if this streamer supports verbose assembly and if it is
0342   /// enabled.
0343   virtual bool isVerboseAsm() const { return false; }
0344 
0345   /// Return true if this asm streamer supports emitting unformatted text
0346   /// to the .s file with EmitRawText.
0347   virtual bool hasRawTextSupport() const { return false; }
0348 
0349   /// Is the integrated assembler required for this streamer to function
0350   /// correctly?
0351   virtual bool isIntegratedAssemblerRequired() const { return false; }
0352 
0353   /// Add a textual comment.
0354   ///
0355   /// Typically for comments that can be emitted to the generated .s
0356   /// file if applicable as a QoI issue to make the output of the compiler
0357   /// more readable.  This only affects the MCAsmStreamer, and only when
0358   /// verbose assembly output is enabled.
0359   ///
0360   /// If the comment includes embedded \n's, they will each get the comment
0361   /// prefix as appropriate.  The added comment should not end with a \n.
0362   /// By default, each comment is terminated with an end of line, i.e. the
0363   /// EOL param is set to true by default. If one prefers not to end the
0364   /// comment with a new line then the EOL param should be passed
0365   /// with a false value.
0366   virtual void AddComment(const Twine &T, bool EOL = true) {}
0367 
0368   /// Return a raw_ostream that comments can be written to. Unlike
0369   /// AddComment, you are required to terminate comments with \n if you use this
0370   /// method.
0371   virtual raw_ostream &getCommentOS();
0372 
0373   /// Print T and prefix it with the comment string (normally #) and
0374   /// optionally a tab. This prints the comment immediately, not at the end of
0375   /// the current line. It is basically a safe version of EmitRawText: since it
0376   /// only prints comments, the object streamer ignores it instead of asserting.
0377   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
0378 
0379   /// Add explicit comment T. T is required to be a valid
0380   /// comment in the output and does not need to be escaped.
0381   virtual void addExplicitComment(const Twine &T);
0382 
0383   /// Emit added explicit comments.
0384   virtual void emitExplicitComments();
0385 
0386   /// Emit a blank line to a .s file to pretty it up.
0387   virtual void addBlankLine() {}
0388 
0389   /// @}
0390 
0391   /// \name Symbol & Section Management
0392   /// @{
0393 
0394   /// Return the current section that the streamer is emitting code to.
0395   MCSectionSubPair getCurrentSection() const {
0396     if (!SectionStack.empty())
0397       return SectionStack.back().first;
0398     return MCSectionSubPair();
0399   }
0400   MCSection *getCurrentSectionOnly() const {
0401     return CurFrag->getParent();
0402   }
0403 
0404   /// Return the previous section that the streamer is emitting code to.
0405   MCSectionSubPair getPreviousSection() const {
0406     if (!SectionStack.empty())
0407       return SectionStack.back().second;
0408     return MCSectionSubPair();
0409   }
0410 
0411   MCFragment *getCurrentFragment() const {
0412     assert(!getCurrentSection().first ||
0413            CurFrag->getParent() == getCurrentSection().first);
0414     return CurFrag;
0415   }
0416 
0417   /// Save the current and previous section on the section stack.
0418   void pushSection() {
0419     SectionStack.push_back(
0420         std::make_pair(getCurrentSection(), getPreviousSection()));
0421   }
0422 
0423   /// Restore the current and previous section from the section stack.
0424   /// Calls changeSection as needed.
0425   ///
0426   /// Returns false if the stack was empty.
0427   virtual bool popSection();
0428 
0429   /// Set the current section where code is being emitted to \p Section.  This
0430   /// is required to update CurSection.
0431   ///
0432   /// This corresponds to assembler directives like .section, .text, etc.
0433   virtual void switchSection(MCSection *Section, uint32_t Subsec = 0);
0434   bool switchSection(MCSection *Section, const MCExpr *);
0435 
0436   /// Similar to switchSection, but does not print the section directive.
0437   virtual void switchSectionNoPrint(MCSection *Section);
0438 
0439   /// Create the default sections and set the initial one.
0440   virtual void initSections(bool NoExecStack, const MCSubtargetInfo &STI);
0441 
0442   MCSymbol *endSection(MCSection *Section);
0443 
0444   /// Returns the mnemonic for \p MI, if the streamer has access to a
0445   /// instruction printer and returns an empty string otherwise.
0446   virtual StringRef getMnemonic(const MCInst &MI) const { return ""; }
0447 
0448   /// Emit a label for \p Symbol into the current section.
0449   ///
0450   /// This corresponds to an assembler statement such as:
0451   ///   foo:
0452   ///
0453   /// \param Symbol - The symbol to emit. A given symbol should only be
0454   /// emitted as a label once, and symbols emitted as a label should never be
0455   /// used in an assignment.
0456   // FIXME: These emission are non-const because we mutate the symbol to
0457   // add the section we're emitting it to later.
0458   virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc());
0459 
0460   virtual void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
0461 
0462   /// Note in the output the specified \p Flag.
0463   virtual void emitAssemblerFlag(MCAssemblerFlag Flag);
0464 
0465   /// Emit the given list \p Options of strings as linker
0466   /// options into the output.
0467   virtual void emitLinkerOptions(ArrayRef<std::string> Kind) {}
0468 
0469   /// Note in the output the specified region \p Kind.
0470   virtual void emitDataRegion(MCDataRegionType Kind) {}
0471 
0472   /// Specify the Mach-O minimum deployment target version.
0473   virtual void emitVersionMin(MCVersionMinType Type, unsigned Major,
0474                               unsigned Minor, unsigned Update,
0475                               VersionTuple SDKVersion) {}
0476 
0477   /// Emit/Specify Mach-O build version command.
0478   /// \p Platform should be one of MachO::PlatformType.
0479   virtual void emitBuildVersion(unsigned Platform, unsigned Major,
0480                                 unsigned Minor, unsigned Update,
0481                                 VersionTuple SDKVersion) {}
0482 
0483   virtual void emitDarwinTargetVariantBuildVersion(unsigned Platform,
0484                                                    unsigned Major,
0485                                                    unsigned Minor,
0486                                                    unsigned Update,
0487                                                    VersionTuple SDKVersion) {}
0488 
0489   void emitVersionForTarget(const Triple &Target,
0490                             const VersionTuple &SDKVersion,
0491                             const Triple *DarwinTargetVariantTriple,
0492                             const VersionTuple &DarwinTargetVariantSDKVersion);
0493 
0494   /// Note in the output that the specified \p Func is a Thumb mode
0495   /// function (ARM target only).
0496   virtual void emitThumbFunc(MCSymbol *Func);
0497 
0498   /// Emit an assignment of \p Value to \p Symbol.
0499   ///
0500   /// This corresponds to an assembler statement such as:
0501   ///  symbol = value
0502   ///
0503   /// The assignment generates no code, but has the side effect of binding the
0504   /// value in the current context. For the assembly streamer, this prints the
0505   /// binding into the .s file.
0506   ///
0507   /// \param Symbol - The symbol being assigned to.
0508   /// \param Value - The value for the symbol.
0509   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
0510 
0511   /// Emit an assignment of \p Value to \p Symbol, but only if \p Value is also
0512   /// emitted.
0513   virtual void emitConditionalAssignment(MCSymbol *Symbol, const MCExpr *Value);
0514 
0515   /// Emit an weak reference from \p Alias to \p Symbol.
0516   ///
0517   /// This corresponds to an assembler statement such as:
0518   ///  .weakref alias, symbol
0519   ///
0520   /// \param Alias - The alias that is being created.
0521   /// \param Symbol - The symbol being aliased.
0522   virtual void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
0523 
0524   /// Add the given \p Attribute to \p Symbol.
0525   virtual bool emitSymbolAttribute(MCSymbol *Symbol,
0526                                    MCSymbolAttr Attribute) = 0;
0527 
0528   /// Set the \p DescValue for the \p Symbol.
0529   ///
0530   /// \param Symbol - The symbol to have its n_desc field set.
0531   /// \param DescValue - The value to set into the n_desc field.
0532   virtual void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
0533 
0534   /// Start emitting COFF symbol definition
0535   ///
0536   /// \param Symbol - The symbol to have its External & Type fields set.
0537   virtual void beginCOFFSymbolDef(const MCSymbol *Symbol);
0538 
0539   /// Emit the storage class of the symbol.
0540   ///
0541   /// \param StorageClass - The storage class the symbol should have.
0542   virtual void emitCOFFSymbolStorageClass(int StorageClass);
0543 
0544   /// Emit the type of the symbol.
0545   ///
0546   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
0547   virtual void emitCOFFSymbolType(int Type);
0548 
0549   /// Marks the end of the symbol definition.
0550   virtual void endCOFFSymbolDef();
0551 
0552   virtual void emitCOFFSafeSEH(MCSymbol const *Symbol);
0553 
0554   /// Emits the symbol table index of a Symbol into the current section.
0555   virtual void emitCOFFSymbolIndex(MCSymbol const *Symbol);
0556 
0557   /// Emits a COFF section index.
0558   ///
0559   /// \param Symbol - Symbol the section number relocation should point to.
0560   virtual void emitCOFFSectionIndex(MCSymbol const *Symbol);
0561 
0562   /// Emits a COFF section relative relocation.
0563   ///
0564   /// \param Symbol - Symbol the section relative relocation should point to.
0565   virtual void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset);
0566 
0567   /// Emits a COFF image relative relocation.
0568   ///
0569   /// \param Symbol - Symbol the image relative relocation should point to.
0570   virtual void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset);
0571 
0572   /// Emits the physical number of the section containing the given symbol as
0573   /// assigned during object writing (i.e., this is not a runtime relocation).
0574   virtual void emitCOFFSecNumber(MCSymbol const *Symbol);
0575 
0576   /// Emits the offset of the symbol from the beginning of the section during
0577   /// object writing (i.e., this is not a runtime relocation).
0578   virtual void emitCOFFSecOffset(MCSymbol const *Symbol);
0579 
0580   /// Emits an lcomm directive with XCOFF csect information.
0581   ///
0582   /// \param LabelSym - Label on the block of storage.
0583   /// \param Size - The size of the block of storage.
0584   /// \param CsectSym - Csect name for the block of storage.
0585   /// \param Alignment - The alignment of the symbol in bytes.
0586   virtual void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size,
0587                                           MCSymbol *CsectSym, Align Alignment);
0588 
0589   /// Emit a symbol's linkage and visibility with a linkage directive for XCOFF.
0590   ///
0591   /// \param Symbol - The symbol to emit.
0592   /// \param Linkage - The linkage of the symbol to emit.
0593   /// \param Visibility - The visibility of the symbol to emit or MCSA_Invalid
0594   /// if the symbol does not have an explicit visibility.
0595   virtual void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
0596                                                     MCSymbolAttr Linkage,
0597                                                     MCSymbolAttr Visibility);
0598 
0599   /// Emit a XCOFF .rename directive which creates a synonym for an illegal or
0600   /// undesirable name.
0601   ///
0602   /// \param Name - The name used internally in the assembly for references to
0603   /// the symbol.
0604   /// \param Rename - The value to which the Name parameter is
0605   /// changed at the end of assembly.
0606   virtual void emitXCOFFRenameDirective(const MCSymbol *Name, StringRef Rename);
0607 
0608   /// Emit an XCOFF .except directive which adds information about
0609   /// a trap instruction to the object file exception section
0610   ///
0611   /// \param Symbol - The function containing the trap.
0612   /// \param Lang - The language code for the exception entry.
0613   /// \param Reason - The reason code for the exception entry.
0614   virtual void emitXCOFFExceptDirective(const MCSymbol *Symbol,
0615                                         const MCSymbol *Trap,
0616                                         unsigned Lang, unsigned Reason,
0617                                         unsigned FunctionSize, bool hasDebug);
0618 
0619   /// Emit a XCOFF .ref directive which creates R_REF type entry in the
0620   /// relocation table for one or more symbols.
0621   ///
0622   /// \param Sym - The symbol on the .ref directive.
0623   virtual void emitXCOFFRefDirective(const MCSymbol *Symbol);
0624 
0625   /// Emit a C_INFO symbol with XCOFF embedded metadata to the .info section.
0626   ///
0627   /// \param Name - The embedded metadata name
0628   /// \param Metadata - The embedded metadata
0629   virtual void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata);
0630 
0631   /// Emit an ELF .size directive.
0632   ///
0633   /// This corresponds to an assembler statement such as:
0634   ///  .size symbol, expression
0635   virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value);
0636 
0637   /// Emit an ELF .symver directive.
0638   ///
0639   /// This corresponds to an assembler statement such as:
0640   ///  .symver _start, foo@@SOME_VERSION
0641   virtual void emitELFSymverDirective(const MCSymbol *OriginalSym,
0642                                       StringRef Name, bool KeepOriginalSym);
0643 
0644   /// Emit a Linker Optimization Hint (LOH) directive.
0645   /// \param Args - Arguments of the LOH.
0646   virtual void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
0647 
0648   /// Emit a .gnu_attribute directive.
0649   virtual void emitGNUAttribute(unsigned Tag, unsigned Value) {}
0650 
0651   /// Emit a common symbol.
0652   ///
0653   /// \param Symbol - The common symbol to emit.
0654   /// \param Size - The size of the common symbol.
0655   /// \param ByteAlignment - The alignment of the symbol.
0656   virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
0657                                 Align ByteAlignment) = 0;
0658 
0659   /// Emit a local common (.lcomm) symbol.
0660   ///
0661   /// \param Symbol - The common symbol to emit.
0662   /// \param Size - The size of the common symbol.
0663   /// \param ByteAlignment - The alignment of the common symbol in bytes.
0664   virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
0665                                      Align ByteAlignment);
0666 
0667   /// Emit the zerofill section and an optional symbol.
0668   ///
0669   /// \param Section - The zerofill section to create and or to put the symbol
0670   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
0671   /// \param Size - The size of the zerofill symbol.
0672   /// \param ByteAlignment - The alignment of the zerofill symbol.
0673   virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
0674                             uint64_t Size = 0, Align ByteAlignment = Align(1),
0675                             SMLoc Loc = SMLoc()) = 0;
0676 
0677   /// Emit a thread local bss (.tbss) symbol.
0678   ///
0679   /// \param Section - The thread local common section.
0680   /// \param Symbol - The thread local common symbol to emit.
0681   /// \param Size - The size of the symbol.
0682   /// \param ByteAlignment - The alignment of the thread local common symbol.
0683   virtual void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
0684                               uint64_t Size, Align ByteAlignment = Align(1));
0685 
0686   /// @}
0687   /// \name Generating Data
0688   /// @{
0689 
0690   /// Emit the bytes in \p Data into the output.
0691   ///
0692   /// This is used to implement assembler directives such as .byte, .ascii,
0693   /// etc.
0694   virtual void emitBytes(StringRef Data);
0695 
0696   /// Functionally identical to EmitBytes. When emitting textual assembly, this
0697   /// method uses .byte directives instead of .ascii or .asciz for readability.
0698   virtual void emitBinaryData(StringRef Data);
0699 
0700   /// Emit the expression \p Value into the output as a native
0701   /// integer of the given \p Size bytes.
0702   ///
0703   /// This is used to implement assembler directives such as .word, .quad,
0704   /// etc.
0705   ///
0706   /// \param Value - The value to emit.
0707   /// \param Size - The size of the integer (in bytes) to emit. This must
0708   /// match a native machine width.
0709   /// \param Loc - The location of the expression for error reporting.
0710   virtual void emitValueImpl(const MCExpr *Value, unsigned Size,
0711                              SMLoc Loc = SMLoc());
0712 
0713   void emitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
0714 
0715   /// Special case of EmitValue that avoids the client having
0716   /// to pass in a MCExpr for constant integers.
0717   virtual void emitIntValue(uint64_t Value, unsigned Size);
0718   virtual void emitIntValue(const APInt &Value);
0719 
0720   /// Special case of EmitValue that avoids the client having to pass
0721   /// in a MCExpr for constant integers & prints in Hex format for certain
0722   /// modes.
0723   virtual void emitIntValueInHex(uint64_t Value, unsigned Size) {
0724     emitIntValue(Value, Size);
0725   }
0726 
0727   void emitInt8(uint64_t Value) { emitIntValue(Value, 1); }
0728   void emitInt16(uint64_t Value) { emitIntValue(Value, 2); }
0729   void emitInt32(uint64_t Value) { emitIntValue(Value, 4); }
0730   void emitInt64(uint64_t Value) { emitIntValue(Value, 8); }
0731 
0732   /// Special case of EmitValue that avoids the client having to pass
0733   /// in a MCExpr for constant integers & prints in Hex format for certain
0734   /// modes, pads the field with leading zeros to Size width
0735   virtual void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) {
0736     emitIntValue(Value, Size);
0737   }
0738 
0739   virtual void emitULEB128Value(const MCExpr *Value);
0740 
0741   virtual void emitSLEB128Value(const MCExpr *Value);
0742 
0743   /// Special case of EmitULEB128Value that avoids the client having to
0744   /// pass in a MCExpr for constant integers.
0745   unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo = 0);
0746 
0747   /// Special case of EmitSLEB128Value that avoids the client having to
0748   /// pass in a MCExpr for constant integers.
0749   unsigned emitSLEB128IntValue(int64_t Value);
0750 
0751   /// Special case of EmitValue that avoids the client having to pass in
0752   /// a MCExpr for MCSymbols.
0753   void emitSymbolValue(const MCSymbol *Sym, unsigned Size,
0754                        bool IsSectionRelative = false);
0755 
0756   /// Emit the expression \p Value into the output as a dtprel
0757   /// (64-bit DTP relative) value.
0758   ///
0759   /// This is used to implement assembler directives such as .dtpreldword on
0760   /// targets that support them.
0761   virtual void emitDTPRel64Value(const MCExpr *Value);
0762 
0763   /// Emit the expression \p Value into the output as a dtprel
0764   /// (32-bit DTP relative) value.
0765   ///
0766   /// This is used to implement assembler directives such as .dtprelword on
0767   /// targets that support them.
0768   virtual void emitDTPRel32Value(const MCExpr *Value);
0769 
0770   /// Emit the expression \p Value into the output as a tprel
0771   /// (64-bit TP relative) value.
0772   ///
0773   /// This is used to implement assembler directives such as .tpreldword on
0774   /// targets that support them.
0775   virtual void emitTPRel64Value(const MCExpr *Value);
0776 
0777   /// Emit the expression \p Value into the output as a tprel
0778   /// (32-bit TP relative) value.
0779   ///
0780   /// This is used to implement assembler directives such as .tprelword on
0781   /// targets that support them.
0782   virtual void emitTPRel32Value(const MCExpr *Value);
0783 
0784   /// Emit the expression \p Value into the output as a gprel64 (64-bit
0785   /// GP relative) value.
0786   ///
0787   /// This is used to implement assembler directives such as .gpdword on
0788   /// targets that support them.
0789   virtual void emitGPRel64Value(const MCExpr *Value);
0790 
0791   /// Emit the expression \p Value into the output as a gprel32 (32-bit
0792   /// GP relative) value.
0793   ///
0794   /// This is used to implement assembler directives such as .gprel32 on
0795   /// targets that support them.
0796   virtual void emitGPRel32Value(const MCExpr *Value);
0797 
0798   /// Emit NumBytes bytes worth of the value specified by FillValue.
0799   /// This implements directives such as '.space'.
0800   void emitFill(uint64_t NumBytes, uint8_t FillValue);
0801 
0802   /// Emit \p Size bytes worth of the value specified by \p FillValue.
0803   ///
0804   /// This is used to implement assembler directives such as .space or .skip.
0805   ///
0806   /// \param NumBytes - The number of bytes to emit.
0807   /// \param FillValue - The value to use when filling bytes.
0808   /// \param Loc - The location of the expression for error reporting.
0809   virtual void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
0810                         SMLoc Loc = SMLoc());
0811 
0812   /// Emit \p NumValues copies of \p Size bytes. Each \p Size bytes is
0813   /// taken from the lowest order 4 bytes of \p Expr expression.
0814   ///
0815   /// This is used to implement assembler directives such as .fill.
0816   ///
0817   /// \param NumValues - The number of copies of \p Size bytes to emit.
0818   /// \param Size - The size (in bytes) of each repeated value.
0819   /// \param Expr - The expression from which \p Size bytes are used.
0820   virtual void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
0821                         SMLoc Loc = SMLoc());
0822 
0823   virtual void emitNops(int64_t NumBytes, int64_t ControlledNopLength,
0824                         SMLoc Loc, const MCSubtargetInfo& STI);
0825 
0826   /// Emit NumBytes worth of zeros.
0827   /// This function properly handles data in virtual sections.
0828   void emitZeros(uint64_t NumBytes);
0829 
0830   /// Emit some number of copies of \p Value until the byte alignment \p
0831   /// ByteAlignment is reached.
0832   ///
0833   /// If the number of bytes need to emit for the alignment is not a multiple
0834   /// of \p ValueSize, then the contents of the emitted fill bytes is
0835   /// undefined.
0836   ///
0837   /// This used to implement the .align assembler directive.
0838   ///
0839   /// \param Alignment - The alignment to reach.
0840   /// \param Value - The value to use when filling bytes.
0841   /// \param ValueSize - The size of the integer (in bytes) to emit for
0842   /// \p Value. This must match a native machine width.
0843   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
0844   /// the alignment cannot be reached in this many bytes, no bytes are
0845   /// emitted.
0846   virtual void emitValueToAlignment(Align Alignment, int64_t Value = 0,
0847                                     unsigned ValueSize = 1,
0848                                     unsigned MaxBytesToEmit = 0);
0849 
0850   /// Emit nops until the byte alignment \p ByteAlignment is reached.
0851   ///
0852   /// This used to align code where the alignment bytes may be executed.  This
0853   /// can emit different bytes for different sizes to optimize execution.
0854   ///
0855   /// \param Alignment - The alignment to reach.
0856   /// \param STI - The MCSubtargetInfo in operation when padding is emitted.
0857   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
0858   /// the alignment cannot be reached in this many bytes, no bytes are
0859   /// emitted.
0860   virtual void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI,
0861                                  unsigned MaxBytesToEmit = 0);
0862 
0863   /// Emit some number of copies of \p Value until the byte offset \p
0864   /// Offset is reached.
0865   ///
0866   /// This is used to implement assembler directives such as .org.
0867   ///
0868   /// \param Offset - The offset to reach. This may be an expression, but the
0869   /// expression must be associated with the current section.
0870   /// \param Value - The value to use when filling bytes.
0871   virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
0872                                  SMLoc Loc);
0873 
0874   /// @}
0875 
0876   /// Switch to a new logical file.  This is used to implement the '.file
0877   /// "foo.c"' assembler directive.
0878   virtual void emitFileDirective(StringRef Filename);
0879 
0880   /// Emit ".file assembler diretive with additioal info.
0881   virtual void emitFileDirective(StringRef Filename, StringRef CompilerVersion,
0882                                  StringRef TimeStamp, StringRef Description);
0883 
0884   /// Emit the "identifiers" directive.  This implements the
0885   /// '.ident "version foo"' assembler directive.
0886   virtual void emitIdent(StringRef IdentString) {}
0887 
0888   /// Associate a filename with a specified logical file number.  This
0889   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
0890   unsigned emitDwarfFileDirective(
0891       unsigned FileNo, StringRef Directory, StringRef Filename,
0892       std::optional<MD5::MD5Result> Checksum = std::nullopt,
0893       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0) {
0894     return cantFail(
0895         tryEmitDwarfFileDirective(FileNo, Directory, Filename, Checksum,
0896                                   Source, CUID));
0897   }
0898 
0899   /// Associate a filename with a specified logical file number.
0900   /// Also associate a directory, optional checksum, and optional source
0901   /// text with the logical file.  This implements the DWARF2
0902   /// '.file 4 "dir/foo.c"' assembler directive, and the DWARF5
0903   /// '.file 4 "dir/foo.c" md5 "..." source "..."' assembler directive.
0904   virtual Expected<unsigned> tryEmitDwarfFileDirective(
0905       unsigned FileNo, StringRef Directory, StringRef Filename,
0906       std::optional<MD5::MD5Result> Checksum = std::nullopt,
0907       std::optional<StringRef> Source = std::nullopt, unsigned CUID = 0);
0908 
0909   /// Specify the "root" file of the compilation, using the ".file 0" extension.
0910   virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
0911                                        std::optional<MD5::MD5Result> Checksum,
0912                                        std::optional<StringRef> Source,
0913                                        unsigned CUID = 0);
0914 
0915   virtual void emitCFIBKeyFrame();
0916   virtual void emitCFIMTETaggedFrame();
0917 
0918   /// This implements the DWARF2 '.loc fileno lineno ...' assembler
0919   /// directive.
0920   virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line,
0921                                      unsigned Column, unsigned Flags,
0922                                      unsigned Isa, unsigned Discriminator,
0923                                      StringRef FileName);
0924 
0925   /// This implements the '.loc_label Name' directive.
0926   virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name);
0927 
0928   /// Associate a filename with a specified logical file number, and also
0929   /// specify that file's checksum information.  This implements the '.cv_file 4
0930   /// "foo.c"' assembler directive. Returns true on success.
0931   virtual bool emitCVFileDirective(unsigned FileNo, StringRef Filename,
0932                                    ArrayRef<uint8_t> Checksum,
0933                                    unsigned ChecksumKind);
0934 
0935   /// Introduces a function id for use with .cv_loc.
0936   virtual bool emitCVFuncIdDirective(unsigned FunctionId);
0937 
0938   /// Introduces an inline call site id for use with .cv_loc. Includes
0939   /// extra information for inline line table generation.
0940   virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc,
0941                                            unsigned IAFile, unsigned IALine,
0942                                            unsigned IACol, SMLoc Loc);
0943 
0944   /// This implements the CodeView '.cv_loc' assembler directive.
0945   virtual void emitCVLocDirective(unsigned FunctionId, unsigned FileNo,
0946                                   unsigned Line, unsigned Column,
0947                                   bool PrologueEnd, bool IsStmt,
0948                                   StringRef FileName, SMLoc Loc);
0949 
0950   /// This implements the CodeView '.cv_linetable' assembler directive.
0951   virtual void emitCVLinetableDirective(unsigned FunctionId,
0952                                         const MCSymbol *FnStart,
0953                                         const MCSymbol *FnEnd);
0954 
0955   /// This implements the CodeView '.cv_inline_linetable' assembler
0956   /// directive.
0957   virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
0958                                               unsigned SourceFileId,
0959                                               unsigned SourceLineNum,
0960                                               const MCSymbol *FnStartSym,
0961                                               const MCSymbol *FnEndSym);
0962 
0963   /// This implements the CodeView '.cv_def_range' assembler
0964   /// directive.
0965   virtual void emitCVDefRangeDirective(
0966       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
0967       StringRef FixedSizePortion);
0968 
0969   virtual void emitCVDefRangeDirective(
0970       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
0971       codeview::DefRangeRegisterRelHeader DRHdr);
0972 
0973   virtual void emitCVDefRangeDirective(
0974       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
0975       codeview::DefRangeSubfieldRegisterHeader DRHdr);
0976 
0977   virtual void emitCVDefRangeDirective(
0978       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
0979       codeview::DefRangeRegisterHeader DRHdr);
0980 
0981   virtual void emitCVDefRangeDirective(
0982       ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
0983       codeview::DefRangeFramePointerRelHeader DRHdr);
0984 
0985   /// This implements the CodeView '.cv_stringtable' assembler directive.
0986   virtual void emitCVStringTableDirective() {}
0987 
0988   /// This implements the CodeView '.cv_filechecksums' assembler directive.
0989   virtual void emitCVFileChecksumsDirective() {}
0990 
0991   /// This implements the CodeView '.cv_filechecksumoffset' assembler
0992   /// directive.
0993   virtual void emitCVFileChecksumOffsetDirective(unsigned FileNo) {}
0994 
0995   /// This implements the CodeView '.cv_fpo_data' assembler directive.
0996   virtual void emitCVFPOData(const MCSymbol *ProcSym, SMLoc Loc = {}) {}
0997 
0998   /// Emit the absolute difference between two symbols.
0999   ///
1000   /// \pre Offset of \c Hi is greater than the offset \c Lo.
1001   virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
1002                                       unsigned Size);
1003 
1004   /// Emit the absolute difference between two symbols encoded with ULEB128.
1005   virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi,
1006                                                const MCSymbol *Lo);
1007 
1008   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
1009   virtual void emitCFISections(bool EH, bool Debug);
1010   void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
1011   void emitCFIEndProc();
1012   virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc = {});
1013   virtual void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc = {});
1014   virtual void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc = {});
1015   virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset,
1016                                        int64_t AddressSpace, SMLoc Loc = {});
1017   virtual void emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc = {});
1018   virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
1019   virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding);
1020   virtual void emitCFIRememberState(SMLoc Loc);
1021   virtual void emitCFIRestoreState(SMLoc Loc);
1022   virtual void emitCFISameValue(int64_t Register, SMLoc Loc = {});
1023   virtual void emitCFIRestore(int64_t Register, SMLoc Loc = {});
1024   virtual void emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc);
1025   virtual void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc = {});
1026   virtual void emitCFIEscape(StringRef Values, SMLoc Loc = {});
1027   virtual void emitCFIReturnColumn(int64_t Register);
1028   virtual void emitCFIGnuArgsSize(int64_t Size, SMLoc Loc = {});
1029   virtual void emitCFISignalFrame();
1030   virtual void emitCFIUndefined(int64_t Register, SMLoc Loc = {});
1031   virtual void emitCFIRegister(int64_t Register1, int64_t Register2,
1032                                SMLoc Loc = {});
1033   virtual void emitCFIWindowSave(SMLoc Loc = {});
1034   virtual void emitCFINegateRAState(SMLoc Loc = {});
1035   virtual void emitCFINegateRAStateWithPC(SMLoc Loc = {});
1036   virtual void emitCFILabelDirective(SMLoc Loc, StringRef Name);
1037   virtual void emitCFIValOffset(int64_t Register, int64_t Offset,
1038                                 SMLoc Loc = {});
1039 
1040   virtual void emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc = SMLoc());
1041   virtual void emitWinCFIEndProc(SMLoc Loc = SMLoc());
1042   /// This is used on platforms, such as Windows on ARM64, that require function
1043   /// or funclet sizes to be emitted in .xdata before the End marker is emitted
1044   /// for the frame.  We cannot use the End marker, as it is not set at the
1045   /// point of emitting .xdata, in order to indicate that the frame is active.
1046   virtual void emitWinCFIFuncletOrFuncEnd(SMLoc Loc = SMLoc());
1047   virtual void emitWinCFIStartChained(SMLoc Loc = SMLoc());
1048   virtual void emitWinCFIEndChained(SMLoc Loc = SMLoc());
1049   virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc = SMLoc());
1050   virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset,
1051                                   SMLoc Loc = SMLoc());
1052   virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc = SMLoc());
1053   virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset,
1054                                  SMLoc Loc = SMLoc());
1055   virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset,
1056                                  SMLoc Loc = SMLoc());
1057   virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc = SMLoc());
1058   virtual void emitWinCFIEndProlog(SMLoc Loc = SMLoc());
1059   virtual void emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
1060                                 SMLoc Loc = SMLoc());
1061   virtual void emitWinEHHandlerData(SMLoc Loc = SMLoc());
1062 
1063   virtual void emitCGProfileEntry(const MCSymbolRefExpr *From,
1064                                   const MCSymbolRefExpr *To, uint64_t Count);
1065 
1066   /// Get the .pdata section used for the given section. Typically the given
1067   /// section is either the main .text section or some other COMDAT .text
1068   /// section, but it may be any section containing code.
1069   MCSection *getAssociatedPDataSection(const MCSection *TextSec);
1070 
1071   /// Get the .xdata section used for the given section.
1072   MCSection *getAssociatedXDataSection(const MCSection *TextSec);
1073 
1074   virtual void emitSyntaxDirective();
1075 
1076   /// Record a relocation described by the .reloc directive. Return std::nullopt
1077   /// if succeeded. Otherwise, return a pair (Name is invalid, error message).
1078   virtual std::optional<std::pair<bool, std::string>>
1079   emitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr,
1080                      SMLoc Loc, const MCSubtargetInfo &STI) {
1081     return std::nullopt;
1082   }
1083 
1084   virtual void emitAddrsig() {}
1085   virtual void emitAddrsigSym(const MCSymbol *Sym) {}
1086 
1087   /// Emit the given \p Instruction into the current section.
1088   virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
1089 
1090   /// Emit the a pseudo probe into the current section.
1091   virtual void emitPseudoProbe(uint64_t Guid, uint64_t Index, uint64_t Type,
1092                                uint64_t Attr, uint64_t Discriminator,
1093                                const MCPseudoProbeInlineStack &InlineStack,
1094                                MCSymbol *FnSym);
1095 
1096   /// Set the bundle alignment mode from now on in the section.
1097   /// The value 1 means turn the bundle alignment off.
1098   virtual void emitBundleAlignMode(Align Alignment);
1099 
1100   /// The following instructions are a bundle-locked group.
1101   ///
1102   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
1103   ///                     the end of a bundle.
1104   virtual void emitBundleLock(bool AlignToEnd);
1105 
1106   /// Ends a bundle-locked group.
1107   virtual void emitBundleUnlock();
1108 
1109   /// If this file is backed by a assembly streamer, this dumps the
1110   /// specified string in the output .s file.  This capability is indicated by
1111   /// the hasRawTextSupport() predicate.  By default this aborts.
1112   void emitRawText(const Twine &String);
1113 
1114   /// Streamer specific finalization.
1115   virtual void finishImpl();
1116   /// Finish emission of machine code.
1117   void finish(SMLoc EndLoc = SMLoc());
1118 
1119   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
1120 
1121   /// Emit a special value of 0xffffffff if producing 64-bit debugging info.
1122   void maybeEmitDwarf64Mark();
1123 
1124   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1125   /// according to the settings.
1126   virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment);
1127 
1128   /// Emit a unit length field. The actual format, DWARF32 or DWARF64, is chosen
1129   /// according to the settings.
1130   /// Return the end symbol generated inside, the caller needs to emit it.
1131   virtual MCSymbol *emitDwarfUnitLength(const Twine &Prefix,
1132                                         const Twine &Comment);
1133 
1134   /// Emit the debug line start label.
1135   virtual void emitDwarfLineStartLabel(MCSymbol *StartSym);
1136 
1137   /// Emit the debug line end entry.
1138   virtual void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
1139                                      MCSymbol *EndLabel = nullptr) {}
1140 
1141   /// If targets does not support representing debug line section by .loc/.file
1142   /// directives in assembly output, we need to populate debug line section with
1143   /// raw debug line contents.
1144   virtual void emitDwarfAdvanceLineAddr(int64_t LineDelta,
1145                                         const MCSymbol *LastLabel,
1146                                         const MCSymbol *Label,
1147                                         unsigned PointerSize) {}
1148 };
1149 
1150 /// Create a dummy machine code streamer, which does nothing. This is useful for
1151 /// timing the assembler front end.
1152 MCStreamer *createNullStreamer(MCContext &Ctx);
1153 
1154 } // end namespace llvm
1155 
1156 #endif // LLVM_MC_MCSTREAMER_H