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