MCStreamer.h 47 KB

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