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