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