48 std::unique_ptr<formatted_raw_ostream> OSOwner;
49 formatted_raw_ostream &OS;
51 std::unique_ptr<MCInstPrinter> InstPrinter;
52 std::unique_ptr<MCAssembler> Assembler;
54 SmallString<128> ExplicitCommentToEmit;
55 SmallString<128> CommentToEmit;
56 raw_svector_ostream CommentStream;
57 raw_null_ostream NullStream;
59 bool EmittedSectionDirective =
false;
61 bool IsVerboseAsm =
false;
62 bool ShowInst =
false;
63 bool UseDwarfDirectory =
false;
65 void EmitRegisterName(int64_t
Register);
66 void PrintQuotedString(StringRef
Data, raw_ostream &OS)
const;
67 void printDwarfFileDirective(
unsigned FileNo, StringRef Directory,
69 std::optional<MD5::MD5Result> Checksum,
70 std::optional<StringRef> Source,
71 bool UseDwarfDirectory,
72 raw_svector_ostream &OS)
const;
73 void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame)
override;
74 void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame)
override;
77 void emitDwarfLocDirectiveFlags(
unsigned Flags,
unsigned Isa,
78 unsigned Discriminator);
82 void emitDwarfLocDirectiveSuffix(
unsigned FileNo,
unsigned Line,
83 unsigned Column,
unsigned Flags,
84 unsigned Isa,
unsigned Discriminator,
85 StringRef FileName, StringRef Comment);
88 MCAsmStreamer(MCContext &
Context, std::unique_ptr<formatted_raw_ostream> os,
89 std::unique_ptr<MCInstPrinter>
printer,
90 std::unique_ptr<MCCodeEmitter> emitter,
91 std::unique_ptr<MCAsmBackend> asmbackend)
92 : MCAsmBaseStreamer(
Context), OSOwner(std::
move(os)), OS(*OSOwner),
94 Assembler(std::make_unique<MCAssembler>(
96 (asmbackend) ? asmbackend->createObjectWriter(NullStream)
98 CommentStream(CommentToEmit) {
100 if (Assembler->getBackendPtr())
101 setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
103 Context.setUseNamesOnTempLabels(
true);
105 const MCTargetOptions &TO =
Context.getTargetOptions();
108 InstPrinter->setCommentStream(CommentStream);
112 UseDwarfDirectory =
false;
115 UseDwarfDirectory =
true;
119 Context.getAsmInfo().enableDwarfFileDirectoryDefault();
124 MCAssembler &getAssembler() {
return *Assembler; }
125 MCAssembler *getAssemblerPtr()
override {
return nullptr; }
127 inline void EmitEOL() {
129 emitExplicitComments();
135 EmitCommentsAndEOL();
138 void emitSyntaxDirective(StringRef Syntax, StringRef
Options)
override;
140 void EmitCommentsAndEOL();
143 bool isVerboseAsm()
const override {
return IsVerboseAsm; }
146 bool hasRawTextSupport()
const override {
return true; }
151 void AddComment(
const Twine &
T,
bool EOL =
true)
override;
154 void AddEncodingComment(
const MCInst &Inst,
const MCSubtargetInfo &);
159 raw_ostream &getCommentOS()
override {
162 return CommentStream;
165 void emitRawComment(
const Twine &
T,
bool TabPrefix =
true)
override;
167 void addExplicitComment(
const Twine &
T)
override;
168 void emitExplicitComments()
override;
171 void addBlankLine()
override { EmitEOL(); }
176 void switchSection(MCSection *Section, uint32_t Subsection)
override;
177 bool popSection()
override;
179 void emitELFSymverDirective(
const MCSymbol *OriginalSym, StringRef Name,
180 bool KeepOriginalSym)
override;
184 void emitGNUAttribute(
unsigned Tag,
unsigned Value)
override;
187 auto [Ptr,
Bits] = InstPrinter->getMnemonic(
MI);
188 assert((Bits != 0 || Ptr ==
nullptr) &&
189 "Invalid char pointer for instruction with no mnemonic");
193 void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc())
override;
195 void emitSubsectionsViaSymbols()
override;
196 void emitLinkerOptions(ArrayRef<std::string>
Options)
override;
199 unsigned Update, VersionTuple SDKVersion)
override;
200 void emitBuildVersion(
unsigned Platform,
unsigned Major,
unsigned Minor,
201 unsigned Update, VersionTuple SDKVersion)
override;
202 void emitDarwinTargetVariantBuildVersion(
unsigned Platform,
unsigned Major,
203 unsigned Minor,
unsigned Update,
204 VersionTuple SDKVersion)
override;
206 void emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value)
override;
207 void emitConditionalAssignment(MCSymbol *Symbol,
208 const MCExpr *
Value)
override;
209 void emitWeakReference(MCSymbol *Alias,
const MCSymbol *Symbol)
override;
212 void emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue)
override;
213 void beginCOFFSymbolDef(
const MCSymbol *Symbol)
override;
214 void emitCOFFSymbolStorageClass(
int StorageClass)
override;
215 void emitCOFFSymbolType(
int Type)
override;
216 void endCOFFSymbolDef()
override;
217 void emitCOFFSafeSEH(MCSymbol
const *Symbol)
override;
218 void emitCOFFSymbolIndex(MCSymbol
const *Symbol)
override;
219 void emitCOFFSectionIndex(MCSymbol
const *Symbol)
override;
220 void emitCOFFSecRel32(MCSymbol
const *Symbol, uint64_t
Offset)
override;
221 void emitCOFFImgRel32(MCSymbol
const *Symbol, int64_t
Offset)
override;
222 void emitCOFFSecNumber(MCSymbol
const *Symbol)
override;
223 void emitCOFFSecOffset(MCSymbol
const *Symbol)
override;
224 void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t
Size,
225 MCSymbol *CsectSym, Align Alignment)
override;
226 void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol,
229 void emitXCOFFRenameDirective(
const MCSymbol *Name,
230 StringRef Rename)
override;
232 void emitXCOFFRefDirective(
const MCSymbol *Symbol)
override;
234 void emitXCOFFExceptDirective(
const MCSymbol *Symbol,
235 const MCSymbol *
Trap,
236 unsigned Lang,
unsigned Reason,
237 unsigned FunctionSize,
bool hasDebug)
override;
238 void emitXCOFFCInfoSym(StringRef Name, StringRef
Metadata)
override;
240 void emitELFSize(MCSymbol *Symbol,
const MCExpr *
Value)
override;
241 void emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
242 Align ByteAlignment)
override;
249 void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
250 Align ByteAlignment)
override;
252 void emitZerofill(MCSection *Section, MCSymbol *Symbol =
nullptr,
253 uint64_t
Size = 0, Align ByteAlignment =
Align(1),
254 SMLoc Loc = SMLoc())
override;
256 void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t
Size,
257 Align ByteAlignment =
Align(1))
override;
259 void emitBinaryData(StringRef
Data)
override;
261 void emitBytes(StringRef
Data)
override;
263 void emitValueImpl(
const MCExpr *
Value,
unsigned Size,
264 SMLoc Loc = SMLoc())
override;
265 void emitIntValue(uint64_t
Value,
unsigned Size)
override;
266 void emitIntValueInHex(uint64_t
Value,
unsigned Size)
override;
267 void emitIntValueInHexWithPadding(uint64_t
Value,
unsigned Size)
override;
269 void emitULEB128Value(
const MCExpr *
Value)
override;
271 void emitSLEB128Value(
const MCExpr *
Value)
override;
273 void emitFill(
const MCExpr &NumBytes, uint64_t FillValue,
274 SMLoc Loc = SMLoc())
override;
276 void emitFill(
const MCExpr &NumValues, int64_t
Size, int64_t Expr,
277 SMLoc Loc = SMLoc())
override;
279 void emitAlignmentDirective(uint64_t ByteAlignment,
280 std::optional<int64_t>
Value,
unsigned ValueSize,
281 unsigned MaxBytesToEmit);
283 void emitValueToAlignment(Align Alignment, int64_t Fill = 0,
285 unsigned MaxBytesToEmit = 0)
override;
287 void emitCodeAlignment(Align Alignment,
const MCSubtargetInfo *STI,
288 unsigned MaxBytesToEmit = 0)
override;
289 void emitPrefAlign(Align Alignment,
const MCSymbol &End,
bool EmitNops,
290 uint8_t Fill,
const MCSubtargetInfo &STI)
override;
292 void emitValueToOffset(
const MCExpr *
Offset,
296 void emitFileDirective(StringRef
Filename)
override;
297 void emitFileDirective(StringRef
Filename, StringRef CompilerVersion,
298 StringRef TimeStamp, StringRef Description)
override;
299 Expected<unsigned> tryEmitDwarfFileDirective(
300 unsigned FileNo, StringRef Directory, StringRef
Filename,
301 std::optional<MD5::MD5Result> Checksum = std::nullopt,
302 std::optional<StringRef> Source = std::nullopt,
303 unsigned CUID = 0)
override;
304 void emitDwarfFile0Directive(StringRef Directory, StringRef
Filename,
305 std::optional<MD5::MD5Result> Checksum,
306 std::optional<StringRef> Source,
307 unsigned CUID = 0)
override;
308 void emitDwarfLocDirective(
unsigned FileNo,
unsigned Line,
unsigned Column,
309 unsigned Flags,
unsigned Isa,
310 unsigned Discriminator, StringRef FileName,
311 StringRef Location = {})
override;
312 void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name)
override;
316 void emitDwarfLocDirectiveWithInlinedAt(
unsigned FileNo,
unsigned Line,
317 unsigned Column,
unsigned FileIA,
318 unsigned LineIA,
unsigned ColIA,
319 const MCSymbol *Sym,
unsigned Flags,
320 unsigned Isa,
unsigned Discriminator,
322 StringRef Comment = {})
override;
324 MCSymbol *getDwarfLineTableSymbol(
unsigned CUID)
override;
326 bool emitCVFileDirective(
unsigned FileNo, StringRef
Filename,
327 ArrayRef<uint8_t> Checksum,
328 unsigned ChecksumKind)
override;
329 bool emitCVFuncIdDirective(
unsigned FuncId)
override;
330 bool emitCVInlineSiteIdDirective(
unsigned FunctionId,
unsigned IAFunc,
331 unsigned IAFile,
unsigned IALine,
332 unsigned IACol, SMLoc Loc)
override;
333 void emitCVLocDirective(
unsigned FunctionId,
unsigned FileNo,
unsigned Line,
334 unsigned Column,
bool PrologueEnd,
bool IsStmt,
335 StringRef FileName, SMLoc Loc)
override;
336 void emitCVLinetableDirective(
unsigned FunctionId,
const MCSymbol *FnStart,
337 const MCSymbol *FnEnd)
override;
338 void emitCVInlineLinetableDirective(
unsigned PrimaryFunctionId,
339 unsigned SourceFileId,
340 unsigned SourceLineNum,
341 const MCSymbol *FnStartSym,
342 const MCSymbol *FnEndSym)
override;
344 void PrintCVDefRangePrefix(
345 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges);
347 void emitCVDefRangeDirective(
348 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
349 codeview::DefRangeRegisterRelHeader DRHdr)
override;
351 void emitCVDefRangeDirective(
352 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
353 codeview::DefRangeSubfieldRegisterHeader DRHdr)
override;
355 void emitCVDefRangeDirective(
356 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
357 codeview::DefRangeRegisterHeader DRHdr)
override;
359 void emitCVDefRangeDirective(
360 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
361 codeview::DefRangeFramePointerRelHeader DRHdr)
override;
363 void emitCVDefRangeDirective(
364 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
365 codeview::DefRangeRegisterRelIndirHeader DRHdr)
override;
367 void emitCVStringTableDirective()
override;
368 void emitCVFileChecksumsDirective()
override;
369 void emitCVFileChecksumOffsetDirective(
unsigned FileNo)
override;
370 void emitCVFPOData(
const MCSymbol *ProcSym, SMLoc L)
override;
372 void emitIdent(StringRef IdentString)
override;
373 void emitCFIBKeyFrame()
override;
374 void emitCFIMTETaggedFrame()
override;
375 void emitCFISections(
bool EH,
bool Debug,
bool SFrame)
override;
376 void emitCFIDefCfa(int64_t
Register, int64_t
Offset, SMLoc Loc)
override;
377 void emitCFIDefCfaOffset(int64_t
Offset, SMLoc Loc)
override;
378 void emitCFIDefCfaRegister(int64_t
Register, SMLoc Loc)
override;
381 void emitCFIOffset(int64_t
Register, int64_t
Offset, SMLoc Loc)
override;
382 void emitCFIPersonality(
const MCSymbol *Sym,
unsigned Encoding)
override;
383 void emitCFILsda(
const MCSymbol *Sym,
unsigned Encoding)
override;
384 void emitCFIRememberState(SMLoc Loc)
override;
385 void emitCFIRestoreState(SMLoc Loc)
override;
386 void emitCFIRestore(int64_t
Register, SMLoc Loc)
override;
387 void emitCFISameValue(int64_t
Register, SMLoc Loc)
override;
388 void emitCFIRelOffset(int64_t
Register, int64_t
Offset, SMLoc Loc)
override;
389 void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc)
override;
390 void emitCFIEscape(StringRef Values, SMLoc Loc)
override;
391 void emitCFIGnuArgsSize(int64_t
Size, SMLoc Loc)
override;
392 void emitCFISignalFrame()
override;
393 void emitCFIUndefined(int64_t
Register, SMLoc Loc)
override;
394 void emitCFIRegister(int64_t Register1, int64_t Register2,
396 void emitCFIWindowSave(SMLoc Loc)
override;
397 void emitCFINegateRAState(SMLoc Loc)
override;
398 void emitCFINegateRAStateWithPC(SMLoc Loc)
override;
399 void emitCFIReturnColumn(int64_t
Register)
override;
400 void emitCFILLVMRegisterPair(int64_t
Register, int64_t R1, int64_t R1Size,
401 int64_t
R2, int64_t R2Size, SMLoc Loc)
override;
402 void emitCFILLVMVectorRegisters(
405 void emitCFILLVMVectorOffset(int64_t
Register, int64_t RegisterSize,
406 int64_t MaskRegister, int64_t MaskRegisterSize,
407 int64_t
Offset, SMLoc Loc)
override;
408 void emitCFILLVMVectorRegisterMask(int64_t
Register, int64_t SpillRegister,
409 int64_t SpillRegisterLaneSizeInBits,
410 int64_t MaskRegister,
411 int64_t MaskRegisterSizeInBits,
414 void emitCFILabelDirective(SMLoc Loc, StringRef Name)
override;
415 void emitCFIValOffset(int64_t
Register, int64_t
Offset, SMLoc Loc)
override;
417 void emitWinCFIStartProc(
const MCSymbol *Symbol, SMLoc Loc)
override;
418 void emitWinCFIEndProc(SMLoc Loc)
override;
419 void emitWinCFIFuncletOrFuncEnd(SMLoc Loc)
override;
420 void emitWinCFISplitChained(SMLoc Loc)
override;
421 void emitWinCFIPushReg(MCRegister
Register, SMLoc Loc)
override;
424 void emitWinCFIAllocStack(
unsigned Size, SMLoc Loc)
override;
429 void emitWinCFIPushFrame(
bool Code, SMLoc Loc)
override;
430 void emitWinCFIEndProlog(SMLoc Loc)
override;
431 void emitWinCFIBeginEpilogue(SMLoc Loc)
override;
432 void emitWinCFIEndEpilogue(SMLoc Loc)
override;
433 void emitWinCFIUnwindV2Start(SMLoc Loc)
override;
434 void emitWinCFIUnwindVersion(uint8_t
Version, SMLoc Loc)
override;
436 void emitWinEHHandler(
const MCSymbol *Sym,
bool Unwind,
bool Except,
438 void emitWinEHHandlerData(SMLoc Loc)
override;
440 void emitCGProfileEntry(
const MCSymbolRefExpr *From,
441 const MCSymbolRefExpr *To, uint64_t
Count)
override;
443 void emitInstruction(
const MCInst &Inst,
const MCSubtargetInfo &STI)
override;
445 void emitPseudoProbe(uint64_t
Guid, uint64_t Index, uint64_t
Type,
446 uint64_t Attr, uint64_t Discriminator,
448 MCSymbol *FnSym)
override;
450 void emitRelocDirective(
const MCExpr &
Offset, StringRef Name,
451 const MCExpr *Expr, SMLoc Loc)
override;
453 void emitAddrsig()
override;
454 void emitAddrsigSym(
const MCSymbol *Sym)
override;
459 void emitRawTextImpl(StringRef
String)
override;
461 void finishImpl()
override;
463 void emitDwarfUnitLength(uint64_t
Length,
const Twine &Comment)
override;
465 MCSymbol *emitDwarfUnitLength(
const Twine &Prefix,
466 const Twine &Comment)
override;
468 void emitDwarfLineStartLabel(MCSymbol *StartSym)
override;
470 void emitDwarfLineEndEntry(MCSection *Section, MCSymbol *LastLabel,
471 MCSymbol *EndLabel =
nullptr)
override;
473 void emitDwarfAdvanceLineAddr(int64_t LineDelta,
const MCSymbol *LastLabel,
474 const MCSymbol *Label,
475 unsigned PointerSize)
override;
480void MCAsmStreamer::AddComment(
const Twine &
T,
bool EOL) {
481 if (!IsVerboseAsm)
return;
483 T.toVector(CommentToEmit);
489void MCAsmStreamer::EmitCommentsAndEOL() {
495 StringRef Comments = CommentToEmit;
498 "Comment array not newline terminated");
502 size_t Position = Comments.
find(
'\n');
505 Comments = Comments.
substr(Position+1);
506 }
while (!Comments.
empty());
508 CommentToEmit.
clear();
512 assert(Bytes > 0 && Bytes <= 8 &&
"Invalid size!");
513 return Value & ((
uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
516void MCAsmStreamer::emitRawComment(
const Twine &
T,
bool TabPrefix) {
523void MCAsmStreamer::addExplicitComment(
const Twine &
T) {
524 StringRef c =
T.getSingleStringRef();
528 ExplicitCommentToEmit.
append(
"\t");
533 size_t p = 2, len = c.
size() - 2;
537 ExplicitCommentToEmit.
append(
"\t");
542 ExplicitCommentToEmit.
append(
"\n");
546 ExplicitCommentToEmit.
append(
"\t");
548 }
else if (c.
front() ==
'#') {
550 ExplicitCommentToEmit.
append(
"\t");
554 assert(
false &&
"Unexpected Assembly Comment");
556 if (c.
back() ==
'\n')
557 emitExplicitComments();
560void MCAsmStreamer::emitExplicitComments() {
561 StringRef Comments = ExplicitCommentToEmit;
562 if (!Comments.
empty())
564 ExplicitCommentToEmit.
clear();
567void MCAsmStreamer::switchSection(MCSection *Section, uint32_t Subsection) {
569 if (!EmittedSectionDirective ||
571 EmittedSectionDirective =
true;
572 if (MCTargetStreamer *TS = getTargetStreamer()) {
573 TS->changeSection(Cur.first, Section, Subsection, OS);
582bool MCAsmStreamer::popSection() {
585 auto [Sec, Subsec] = getCurrentSection();
590void MCAsmStreamer::emitELFSymverDirective(
const MCSymbol *OriginalSym,
592 bool KeepOriginalSym) {
594 OriginalSym->
print(OS, MAI);
596 if (!KeepOriginalSym && !
Name.contains(
"@@@"))
601void MCAsmStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
606 if (!
Symbol->isVariable() &&
621 assert(NbArgs != -1 && ((
size_t)NbArgs) ==
Args.size() &&
"Malformed LOH!");
622 assert(str !=
"" &&
"Invalid LOH name");
627 for (
const MCSymbol *Arg : Args) {
636void MCAsmStreamer::emitGNUAttribute(
unsigned Tag,
unsigned Value) {
637 OS <<
"\t.gnu_attribute " <<
Tag <<
", " <<
Value <<
"\n";
640void MCAsmStreamer::emitSubsectionsViaSymbols() {
641 OS <<
".subsections_via_symbols\n";
644void MCAsmStreamer::emitLinkerOptions(ArrayRef<std::string>
Options) {
645 assert(!
Options.empty() &&
"At least one option is required!");
646 OS <<
"\t.linker_option \"" <<
Options[0] <<
'"';
648 OS <<
", " <<
'"' << Opt <<
'"';
677 if (SDKVersion.
empty())
679 OS <<
'\t' <<
"sdk_version " << SDKVersion.
getMajor();
680 if (
auto Minor = SDKVersion.
getMinor()) {
681 OS <<
", " << *Minor;
683 OS <<
", " << *Subminor;
689 unsigned Minor,
unsigned Update,
690 VersionTuple SDKVersion) {
693 OS <<
", " << Update;
700#define PLATFORM(platform, id, name, build_name, target, tapi_target, \
702 case MachO::PLATFORM_##platform: \
704#include "llvm/BinaryFormat/MachO.def"
709void MCAsmStreamer::emitBuildVersion(
unsigned Platform,
unsigned Major,
710 unsigned Minor,
unsigned Update,
711 VersionTuple SDKVersion) {
713 OS <<
"\t.build_version " << PlatformName <<
", " << Major <<
", " << Minor;
715 OS <<
", " << Update;
720void MCAsmStreamer::emitDarwinTargetVariantBuildVersion(
721 unsigned Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
722 VersionTuple SDKVersion) {
723 emitBuildVersion(Platform, Major, Minor, Update, SDKVersion);
726void MCAsmStreamer::emitAssignment(MCSymbol *Symbol,
const MCExpr *
Value) {
731 OS << (UseSet ?
", " :
" = ");
738void MCAsmStreamer::emitConditionalAssignment(MCSymbol *Symbol,
739 const MCExpr *
Value) {
740 OS <<
".lto_set_conditional ";
747void MCAsmStreamer::emitWeakReference(MCSymbol *Alias,
const MCSymbol *Symbol) {
749 Alias->
print(OS, MAI);
755bool MCAsmStreamer::emitSymbolAttribute(MCSymbol *Symbol,
772 default:
return false;
795 OS <<
"\t.no_dead_strip\t";
800 OS <<
"\t.private_extern\t";
809 OS <<
"\t.weak_definition\t";
826 OS <<
"\t.weak_anti_dep\t";
836void MCAsmStreamer::emitSymbolDesc(MCSymbol *Symbol,
unsigned DescValue) {
837 OS <<
".desc" <<
' ';
839 OS <<
',' << DescValue;
843void MCAsmStreamer::emitSyntaxDirective(StringRef Syntax, StringRef
Options) {
844 OS <<
"\t." << Syntax <<
"_syntax";
850void MCAsmStreamer::beginCOFFSymbolDef(
const MCSymbol *Symbol) {
857void MCAsmStreamer::emitCOFFSymbolStorageClass(
int StorageClass) {
862void MCAsmStreamer::emitCOFFSymbolType(
int Type) {
863 OS <<
"\t.type\t" <<
Type <<
';';
867void MCAsmStreamer::endCOFFSymbolDef() {
872void MCAsmStreamer::emitCOFFSafeSEH(MCSymbol
const *Symbol) {
873 OS <<
"\t.safeseh\t";
878void MCAsmStreamer::emitCOFFSymbolIndex(MCSymbol
const *Symbol) {
884void MCAsmStreamer::emitCOFFSectionIndex(MCSymbol
const *Symbol) {
890void MCAsmStreamer::emitCOFFSecRel32(MCSymbol
const *Symbol, uint64_t
Offset) {
891 OS <<
"\t.secrel32\t";
898void MCAsmStreamer::emitCOFFImgRel32(MCSymbol
const *Symbol, int64_t
Offset) {
908void MCAsmStreamer::emitCOFFSecNumber(MCSymbol
const *Symbol) {
914void MCAsmStreamer::emitCOFFSecOffset(MCSymbol
const *Symbol) {
915 OS <<
"\t.secoffset\t";
923void MCAsmStreamer::emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym,
928 "We only support writing log base-2 alignment format with XCOFF.");
931 LabelSym->
print(OS, MAI);
932 OS <<
',' <<
Size <<
',';
933 CsectSym->
print(OS, MAI);
934 OS <<
',' <<
Log2(Alignment);
940 auto *XSym =
static_cast<MCSymbolXCOFF *
>(CsectSym);
941 if (XSym->hasRename())
942 emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
945void MCAsmStreamer::emitXCOFFSymbolLinkageWithVisibility(
947 auto &Sym =
static_cast<MCSymbolXCOFF &
>(*Symbol);
967 switch (Visibility) {
988 emitXCOFFRenameDirective(&Sym, Sym.getSymbolTableName());
991void MCAsmStreamer::emitXCOFFRenameDirective(
const MCSymbol *Name,
994 Name->print(OS, MAI);
997 for (
char C : Rename) {
1007void MCAsmStreamer::emitXCOFFRefDirective(
const MCSymbol *Symbol) {
1013void MCAsmStreamer::emitXCOFFExceptDirective(
const MCSymbol *Symbol,
1014 const MCSymbol *
Trap,
1017 unsigned FunctionSize,
1019 OS <<
"\t.except\t";
1021 OS <<
", " << Lang <<
", " << Reason;
1025void MCAsmStreamer::emitXCOFFCInfoSym(StringRef Name, StringRef
Metadata) {
1026 const char InfoDirective[] =
"\t.info ";
1027 const char *Separator =
", ";
1028 constexpr int WordSize =
sizeof(uint32_t);
1031 OS << InfoDirective;
1032 PrintQuotedString(Name, OS);
1035 size_t MetadataSize =
Metadata.size();
1038 OS <<
format_hex(MetadataSize, 10) << Separator;
1041 if (MetadataSize == 0) {
1051 uint32_t PaddedSize =
alignTo(MetadataSize, WordSize);
1052 uint32_t PaddingSize = PaddedSize - MetadataSize;
1059 constexpr int WordsPerDirective = 5;
1062 int WordsBeforeNextDirective = 0;
1063 auto PrintWord = [&](
const uint8_t *WordPtr) {
1064 if (WordsBeforeNextDirective-- == 0) {
1066 OS << InfoDirective;
1067 WordsBeforeNextDirective = WordsPerDirective;
1075 for (;
Index + WordSize <= MetadataSize;
Index += WordSize)
1076 PrintWord(
reinterpret_cast<const uint8_t *
>(
Metadata.data()) + Index);
1081 assert(PaddedSize - Index == WordSize);
1082 std::array<uint8_t, WordSize> LastWord = {0};
1083 ::memcpy(LastWord.data(),
Metadata.data() + Index, MetadataSize - Index);
1084 PrintWord(LastWord.data());
1089void MCAsmStreamer::emitELFSize(MCSymbol *Symbol,
const MCExpr *
Value) {
1098void MCAsmStreamer::emitCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
1099 Align ByteAlignment) {
1107 OS <<
',' <<
Log2(ByteAlignment);
1113 auto *XSym =
static_cast<MCSymbolXCOFF *
>(
Symbol);
1114 if (XSym && XSym->hasRename())
1115 emitXCOFFRenameDirective(XSym, XSym->getSymbolTableName());
1119void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t
Size,
1125 if (ByteAlign > 1) {
1130 OS <<
',' << ByteAlign.
value();
1133 OS <<
',' <<
Log2(ByteAlign);
1140void MCAsmStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol,
1141 uint64_t
Size, Align ByteAlignment,
1150 ".zerofill is a Mach-O specific directive");
1153 const MCSectionMachO *MOSection = ((
const MCSectionMachO*)Section);
1160 OS <<
',' <<
Log2(ByteAlignment);
1168void MCAsmStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
1169 uint64_t
Size, Align ByteAlignment) {
1175 ".zerofill is a Mach-O specific directive");
1184 if (ByteAlignment > 1)
1185 OS <<
", " <<
Log2(ByteAlignment);
1191 const auto BeginPtr =
Data.begin(), EndPtr =
Data.end();
1192 for (
const unsigned char C :
make_range(BeginPtr, EndPtr - 1)) {
1203 assert(!
Data.empty() &&
"Cannot generate an empty list.");
1204 const auto printCharacterInOctal = [&OS](
unsigned char C) {
1210 const auto printOneCharacterFor = [printCharacterInOctal](
1211 auto printOnePrintingCharacter) {
1212 return [printCharacterInOctal, printOnePrintingCharacter](
unsigned char C) {
1214 printOnePrintingCharacter(
static_cast<char>(
C));
1217 printCharacterInOctal(
C);
1220 const auto printCharacterList = [
Data, &OS](
const auto &printOneCharacter) {
1221 const auto BeginPtr =
Data.begin(), EndPtr =
Data.end();
1222 for (
const unsigned char C :
make_range(BeginPtr, EndPtr - 1)) {
1223 printOneCharacter(
C);
1226 printOneCharacter(*(EndPtr - 1));
1230 printCharacterList(printCharacterInOctal);
1233 printCharacterList(printOneCharacterFor([&OS](
char C) {
1234 const char AsmCharLitBuf[2] = {
'\'',
C};
1235 OS <<
StringRef(AsmCharLitBuf,
sizeof(AsmCharLitBuf));
1242void MCAsmStreamer::PrintQuotedString(StringRef
Data, raw_ostream &OS)
const {
1246 for (
unsigned char C :
Data) {
1253 for (
unsigned char C :
Data) {
1254 if (
C ==
'"' ||
C ==
'\\') {
1255 OS <<
'\\' << (char)
C;
1293void MCAsmStreamer::emitBytes(StringRef
Data) {
1294 assert(getCurrentSectionOnly() &&
1295 "Cannot emit contents before setting section!");
1296 if (
Data.empty())
return;
1298 const auto emitAsString = [
this](StringRef
Data) {
1303 if (
Data.back() == 0) {
1304 OS <<
"\t.string\t";
1309 PrintQuotedString(
Data, OS);
1329 PrintQuotedString(
Data, OS);
1334 if (
Data.size() != 1 && emitAsString(
Data))
1339 if (MCTargetStreamer *TS = getTargetStreamer()) {
1340 TS->emitRawBytes(
Data);
1344 for (
const unsigned char C :
Data.bytes()) {
1345 OS << Directive << (unsigned)
C;
1350void MCAsmStreamer::emitBinaryData(StringRef
Data) {
1352 const size_t Cols = 4;
1353 for (
size_t I = 0, EI =
alignTo(
Data.size(), Cols);
I < EI;
I += Cols) {
1354 size_t J =
I, EJ = std::min(
I + Cols,
Data.size());
1357 for (; J < EJ - 1; ++J)
1358 OS <<
format(
"0x%02x", uint8_t(
Data[J])) <<
", ";
1364void MCAsmStreamer::emitIntValue(uint64_t
Value,
unsigned Size) {
1368void MCAsmStreamer::emitIntValueInHex(uint64_t
Value,
unsigned Size) {
1372void MCAsmStreamer::emitIntValueInHexWithPadding(uint64_t
Value,
1377void MCAsmStreamer::emitValueImpl(
const MCExpr *
Value,
unsigned Size,
1380 assert(getCurrentSectionOnly() &&
1381 "Cannot emit contents before setting section!");
1382 const char *Directive =
nullptr;
1393 if (!
Value->evaluateAsAbsolute(IntValue))
1408 unsigned ByteOffset =
1409 IsLittleEndian ?
Emitted : (Remaining - EmissionSize);
1410 uint64_t ValueToEmit = IntValue >> (ByteOffset * 8);
1414 uint64_t Shift = 64 - EmissionSize * 8;
1415 assert(Shift <
static_cast<uint64_t
>(
1416 std::numeric_limits<unsigned long long>::digits) &&
1417 "undefined behavior");
1418 ValueToEmit &= ~0ULL >> Shift;
1419 emitIntValue(ValueToEmit, EmissionSize);
1425 assert(Directive &&
"Invalid size for machine code value!");
1427 if (MCTargetStreamer *TS = getTargetStreamer()) {
1428 TS->emitValue(
Value);
1435void MCAsmStreamer::emitULEB128Value(
const MCExpr *
Value) {
1437 if (
Value->evaluateAsAbsolute(IntValue)) {
1438 emitULEB128IntValue(IntValue);
1441 OS <<
"\t.uleb128 ";
1446void MCAsmStreamer::emitSLEB128Value(
const MCExpr *
Value) {
1448 if (
Value->evaluateAsAbsolute(IntValue)) {
1449 emitSLEB128IntValue(IntValue);
1452 OS <<
"\t.sleb128 ";
1457void MCAsmStreamer::emitFill(
const MCExpr &NumBytes, uint64_t FillValue,
1459 int64_t IntNumBytes;
1460 const bool IsAbsolute = NumBytes.evaluateAsAbsolute(IntNumBytes);
1461 if (IsAbsolute && IntNumBytes == 0)
1465 if (!MAI->
isAIX() || FillValue == 0) {
1467 OS << ZeroDirective;
1470 OS <<
',' << (int)FillValue;
1475 "Cannot emit non-absolute expression lengths of fill.");
1476 for (
int i = 0; i < IntNumBytes; ++i) {
1487void MCAsmStreamer::emitFill(
const MCExpr &NumValues, int64_t
Size,
1488 int64_t Expr, SMLoc Loc) {
1492 OS <<
", " <<
Size <<
", 0x";
1497void MCAsmStreamer::emitAlignmentDirective(uint64_t ByteAlignment,
1498 std::optional<int64_t>
Value,
1500 unsigned MaxBytesToEmit) {
1514 switch (ValueSize) {
1518 OS <<
"\t.p2align\t";
1532 if (
Value.has_value() || MaxBytesToEmit) {
1533 if (
Value.has_value()) {
1541 OS <<
", " << MaxBytesToEmit;
1549 switch (ValueSize) {
1551 case 1: OS <<
".balign";
break;
1552 case 2: OS <<
".balignw";
break;
1553 case 4: OS <<
".balignl";
break;
1558 if (
Value.has_value())
1560 else if (MaxBytesToEmit)
1563 OS <<
", " << MaxBytesToEmit;
1567void MCAsmStreamer::emitValueToAlignment(Align Alignment, int64_t Fill,
1569 unsigned MaxBytesToEmit) {
1570 emitAlignmentDirective(Alignment.
value(), Fill, FillLen, MaxBytesToEmit);
1573void MCAsmStreamer::emitCodeAlignment(Align Alignment,
1574 const MCSubtargetInfo *STI,
1575 unsigned MaxBytesToEmit) {
1581 emitAlignmentDirective(Alignment.
value(), std::nullopt, 1, MaxBytesToEmit);
1584void MCAsmStreamer::emitPrefAlign(Align Alignment,
const MCSymbol &End,
1585 bool EmitNops, uint8_t Fill,
1586 const MCSubtargetInfo &) {
1587 OS <<
"\t.prefalign\t" <<
Log2(Alignment) <<
", ";
1592 OS <<
", " <<
static_cast<unsigned>(Fill);
1596void MCAsmStreamer::emitValueToOffset(
const MCExpr *
Offset,
1597 unsigned char Value,
1602 OS <<
", " << (unsigned)
Value;
1606void MCAsmStreamer::emitFileDirective(StringRef
Filename) {
1613void MCAsmStreamer::emitFileDirective(StringRef
Filename,
1614 StringRef CompilerVersion,
1615 StringRef TimeStamp,
1616 StringRef Description) {
1620 bool useTimeStamp = !TimeStamp.
empty();
1621 bool useCompilerVersion = !CompilerVersion.
empty();
1622 bool useDescription = !Description.
empty();
1623 if (useTimeStamp || useCompilerVersion || useDescription) {
1626 PrintQuotedString(TimeStamp, OS);
1627 if (useCompilerVersion || useDescription) {
1629 if (useCompilerVersion)
1630 PrintQuotedString(CompilerVersion, OS);
1631 if (useDescription) {
1633 PrintQuotedString(Description, OS);
1640void MCAsmStreamer::printDwarfFileDirective(
1641 unsigned FileNo, StringRef Directory, StringRef
Filename,
1642 std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
1643 bool UseDwarfDirectory, raw_svector_ostream &OS)
const {
1644 SmallString<128> FullPathName;
1646 if (!UseDwarfDirectory && !Directory.
empty()) {
1650 FullPathName = Directory;
1657 OS <<
"\t.file\t" << FileNo <<
' ';
1658 if (!Directory.
empty()) {
1659 PrintQuotedString(Directory, OS);
1664 OS <<
" md5 0x" << Checksum->digest();
1667 PrintQuotedString(*Source, OS);
1671Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective(
1672 unsigned FileNo, StringRef Directory, StringRef
Filename,
1673 std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
1675 assert(CUID == 0 &&
"multiple CUs not supported by MCAsmStreamer");
1677 MCDwarfLineTable &Table =
getContext().getMCDwarfLineTable(CUID);
1679 Expected<unsigned> FileNoOrErr =
1684 FileNo = FileNoOrErr.
get();
1691 SmallString<128> Str;
1692 raw_svector_ostream OS1(Str);
1693 printDwarfFileDirective(FileNo, Directory,
Filename, Checksum, Source,
1694 UseDwarfDirectory, OS1);
1696 if (MCTargetStreamer *TS = getTargetStreamer())
1697 TS->emitDwarfFileDirective(OS1.str());
1699 emitRawText(OS1.str());
1704void MCAsmStreamer::emitDwarfFile0Directive(
1705 StringRef Directory, StringRef
Filename,
1706 std::optional<MD5::MD5Result> Checksum, std::optional<StringRef> Source,
1720 SmallString<128> Str;
1721 raw_svector_ostream OS1(Str);
1722 printDwarfFileDirective(0, Directory,
Filename, Checksum, Source,
1723 UseDwarfDirectory, OS1);
1725 if (MCTargetStreamer *TS = getTargetStreamer())
1726 TS->emitDwarfFileDirective(OS1.str());
1728 emitRawText(OS1.str());
1732void MCAsmStreamer::emitDwarfLocDirectiveFlags(
unsigned Flags,
unsigned Isa,
1733 unsigned Discriminator) {
1738 OS <<
" basic_block";
1740 OS <<
" prologue_end";
1742 OS <<
" epilogue_begin";
1744 const unsigned OldFlags =
getContext().getCurrentDwarfLoc().getFlags();
1751 OS <<
" isa " << Isa;
1757void MCAsmStreamer::emitDwarfLocDirectiveSuffix(
unsigned FileNo,
unsigned Line,
1758 unsigned Column,
unsigned Flags,
1760 unsigned Discriminator,
1762 StringRef Comment) {
1764 emitDwarfLocDirectiveFlags(Flags, Isa, Discriminator);
1771 OS << FileName <<
':' <<
Line <<
':' << Column;
1779 Discriminator, FileName, Comment);
1782void MCAsmStreamer::emitDwarfLocDirective(
unsigned FileNo,
unsigned Line,
1783 unsigned Column,
unsigned Flags,
1784 unsigned Isa,
unsigned Discriminator,
1786 StringRef Comment) {
1794 Discriminator, FileName, Comment);
1799 OS <<
"\t.loc\t" << FileNo <<
" " <<
Line <<
" " << Column;
1802 emitDwarfLocDirectiveSuffix(FileNo, Line, Column, Flags, Isa, Discriminator,
1808void MCAsmStreamer::emitDwarfLocDirectiveWithInlinedAt(
1809 unsigned FileNo,
unsigned Line,
unsigned Column,
unsigned FileIA,
1810 unsigned LineIA,
unsigned ColIA,
const MCSymbol *Sym,
unsigned Flags,
1811 unsigned Isa,
unsigned Discriminator, StringRef FileName,
1812 StringRef Comment) {
1814 OS <<
"\t.loc\t" << FileNo <<
" " <<
Line <<
" " << Column;
1815 OS <<
", function_name " << *Sym;
1816 OS <<
", inlined_at " << FileIA <<
" " << LineIA <<
" " << ColIA;
1819 emitDwarfLocDirectiveSuffix(FileNo, Line, Column, Flags, Isa, Discriminator,
1823void MCAsmStreamer::emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name) {
1825 OS <<
".loc_label\t" <<
Name;
1829MCSymbol *MCAsmStreamer::getDwarfLineTableSymbol(
unsigned CUID) {
1835bool MCAsmStreamer::emitCVFileDirective(
unsigned FileNo, StringRef
Filename,
1836 ArrayRef<uint8_t> Checksum,
1837 unsigned ChecksumKind) {
1842 OS <<
"\t.cv_file\t" << FileNo <<
' ';
1845 if (!ChecksumKind) {
1851 PrintQuotedString(
toHex(Checksum), OS);
1858bool MCAsmStreamer::emitCVFuncIdDirective(
unsigned FuncId) {
1859 OS <<
"\t.cv_func_id " << FuncId <<
'\n';
1863bool MCAsmStreamer::emitCVInlineSiteIdDirective(
unsigned FunctionId,
1866 unsigned IALine,
unsigned IACol,
1868 OS <<
"\t.cv_inline_site_id " << FunctionId <<
" within " << IAFunc
1869 <<
" inlined_at " << IAFile <<
' ' << IALine <<
' ' << IACol <<
'\n';
1871 IALine, IACol, Loc);
1874void MCAsmStreamer::emitCVLocDirective(
unsigned FunctionId,
unsigned FileNo,
1875 unsigned Line,
unsigned Column,
1876 bool PrologueEnd,
bool IsStmt,
1877 StringRef FileName, SMLoc Loc) {
1879 if (!checkCVLocSection(FunctionId, FileNo, Loc))
1882 OS <<
"\t.cv_loc\t" << FunctionId <<
" " << FileNo <<
" " <<
Line <<
" "
1885 OS <<
" prologue_end";
1898void MCAsmStreamer::emitCVLinetableDirective(
unsigned FunctionId,
1899 const MCSymbol *FnStart,
1900 const MCSymbol *FnEnd) {
1901 OS <<
"\t.cv_linetable\t" << FunctionId <<
", ";
1902 FnStart->
print(OS, MAI);
1904 FnEnd->
print(OS, MAI);
1909void MCAsmStreamer::emitCVInlineLinetableDirective(
unsigned PrimaryFunctionId,
1910 unsigned SourceFileId,
1911 unsigned SourceLineNum,
1912 const MCSymbol *FnStartSym,
1913 const MCSymbol *FnEndSym) {
1914 OS <<
"\t.cv_inline_linetable\t" << PrimaryFunctionId <<
' ' << SourceFileId
1915 <<
' ' << SourceLineNum <<
' ';
1916 FnStartSym->
print(OS, MAI);
1918 FnEndSym->
print(OS, MAI);
1921 PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
1924void MCAsmStreamer::PrintCVDefRangePrefix(
1925 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges) {
1926 OS <<
"\t.cv_def_range\t";
1927 for (std::pair<const MCSymbol *, const MCSymbol *>
Range : Ranges) {
1935void MCAsmStreamer::emitCVDefRangeDirective(
1936 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1937 codeview::DefRangeRegisterRelHeader DRHdr) {
1938 PrintCVDefRangePrefix(Ranges);
1939 OS <<
", reg_rel, ";
1945void MCAsmStreamer::emitCVDefRangeDirective(
1946 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1947 codeview::DefRangeSubfieldRegisterHeader DRHdr) {
1948 PrintCVDefRangePrefix(Ranges);
1949 OS <<
", subfield_reg, ";
1954void MCAsmStreamer::emitCVDefRangeDirective(
1955 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1956 codeview::DefRangeRegisterHeader DRHdr) {
1957 PrintCVDefRangePrefix(Ranges);
1963void MCAsmStreamer::emitCVDefRangeDirective(
1964 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1965 codeview::DefRangeFramePointerRelHeader DRHdr) {
1966 PrintCVDefRangePrefix(Ranges);
1967 OS <<
", frame_ptr_rel, ";
1972void MCAsmStreamer::emitCVDefRangeDirective(
1973 ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
1974 codeview::DefRangeRegisterRelIndirHeader DRHdr) {
1975 PrintCVDefRangePrefix(Ranges);
1976 OS <<
", reg_rel_indir, ";
1982void MCAsmStreamer::emitCVStringTableDirective() {
1983 OS <<
"\t.cv_stringtable";
1987void MCAsmStreamer::emitCVFileChecksumsDirective() {
1988 OS <<
"\t.cv_filechecksums";
1992void MCAsmStreamer::emitCVFileChecksumOffsetDirective(
unsigned FileNo) {
1993 OS <<
"\t.cv_filechecksumoffset\t" << FileNo;
1997void MCAsmStreamer::emitCVFPOData(
const MCSymbol *ProcSym, SMLoc L) {
1998 OS <<
"\t.cv_fpo_data\t";
1999 ProcSym->
print(OS, MAI);
2003void MCAsmStreamer::emitIdent(StringRef IdentString) {
2006 PrintQuotedString(IdentString, OS);
2010void MCAsmStreamer::emitCFISections(
bool EH,
bool Debug,
bool SFrame) {
2012 OS <<
"\t.cfi_sections ";
2021 OS <<
".debug_frame";
2033void MCAsmStreamer::emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
2034 OS <<
"\t.cfi_startproc";
2040void MCAsmStreamer::emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
2042 OS <<
"\t.cfi_endproc";
2046void MCAsmStreamer::EmitRegisterName(int64_t
Register) {
2051 const MCRegisterInfo *MRI =
getContext().getRegisterInfo();
2052 if (std::optional<MCRegister> LLVMRegister =
2054 InstPrinter->printRegName(OS, *LLVMRegister);
2061void MCAsmStreamer::emitCFIDefCfa(int64_t
Register, int64_t
Offset, SMLoc Loc) {
2063 OS <<
"\t.cfi_def_cfa ";
2069void MCAsmStreamer::emitCFIDefCfaOffset(int64_t
Offset, SMLoc Loc) {
2071 OS <<
"\t.cfi_def_cfa_offset " <<
Offset;
2075void MCAsmStreamer::emitCFILLVMDefAspaceCfa(int64_t
Register, int64_t
Offset,
2078 OS <<
"\t.cfi_llvm_def_aspace_cfa ";
2086 OS <<
"\t.cfi_escape ";
2087 if (!Values.
empty()) {
2088 size_t e = Values.
size() - 1;
2089 for (
size_t i = 0; i < e; ++i)
2095void MCAsmStreamer::emitCFIEscape(StringRef Values, SMLoc Loc) {
2101void MCAsmStreamer::emitCFIGnuArgsSize(int64_t
Size, SMLoc Loc) {
2104 uint8_t Buffer[16] = { dwarf::DW_CFA_GNU_args_size };
2111void MCAsmStreamer::emitCFIDefCfaRegister(int64_t
Register, SMLoc Loc) {
2113 OS <<
"\t.cfi_def_cfa_register ";
2118void MCAsmStreamer::emitCFIOffset(int64_t
Register, int64_t
Offset, SMLoc Loc) {
2120 OS <<
"\t.cfi_offset ";
2126void MCAsmStreamer::emitCFIPersonality(
const MCSymbol *Sym,
2127 unsigned Encoding) {
2129 OS <<
"\t.cfi_personality " << Encoding <<
", ";
2130 Sym->
print(OS, MAI);
2134void MCAsmStreamer::emitCFILsda(
const MCSymbol *Sym,
unsigned Encoding) {
2136 OS <<
"\t.cfi_lsda " << Encoding <<
", ";
2137 Sym->
print(OS, MAI);
2141void MCAsmStreamer::emitCFIRememberState(SMLoc Loc) {
2143 OS <<
"\t.cfi_remember_state";
2147void MCAsmStreamer::emitCFIRestoreState(SMLoc Loc) {
2149 OS <<
"\t.cfi_restore_state";
2153void MCAsmStreamer::emitCFIRestore(int64_t
Register, SMLoc Loc) {
2155 OS <<
"\t.cfi_restore ";
2160void MCAsmStreamer::emitCFISameValue(int64_t
Register, SMLoc Loc) {
2162 OS <<
"\t.cfi_same_value ";
2167void MCAsmStreamer::emitCFIRelOffset(int64_t
Register, int64_t
Offset,
2170 OS <<
"\t.cfi_rel_offset ";
2176void MCAsmStreamer::emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc) {
2178 OS <<
"\t.cfi_adjust_cfa_offset " << Adjustment;
2182void MCAsmStreamer::emitCFISignalFrame() {
2184 OS <<
"\t.cfi_signal_frame";
2188void MCAsmStreamer::emitCFIUndefined(int64_t
Register, SMLoc Loc) {
2190 OS <<
"\t.cfi_undefined ";
2195void MCAsmStreamer::emitCFIRegister(int64_t Register1, int64_t Register2,
2198 OS <<
"\t.cfi_register ";
2199 EmitRegisterName(Register1);
2201 EmitRegisterName(Register2);
2205void MCAsmStreamer::emitCFILLVMRegisterPair(int64_t
Register, int64_t R1,
2206 int64_t R1Size, int64_t
R2,
2207 int64_t R2Size, SMLoc Loc) {
2210 OS <<
"\t.cfi_llvm_register_pair ";
2213 EmitRegisterName(R1);
2214 OS <<
", " << R1Size <<
", ";
2215 EmitRegisterName(
R2);
2216 OS <<
", " << R2Size;
2220void MCAsmStreamer::emitCFILLVMVectorRegisters(
2225 OS <<
"\t.cfi_llvm_vector_registers ";
2227 for (
auto [
Reg, Lane,
Size] : VRs)
2228 OS <<
", " <<
Reg <<
", " << Lane <<
", " <<
Size;
2232void MCAsmStreamer::emitCFILLVMVectorOffset(int64_t
Register,
2233 int64_t RegisterSize,
2234 int64_t MaskRegister,
2235 int64_t MaskRegisterSize,
2236 int64_t
Offset, SMLoc Loc) {
2238 MaskRegisterSize,
Offset, Loc);
2240 OS <<
"\t.cfi_llvm_vector_offset ";
2242 OS <<
", " << RegisterSize <<
", ";
2243 EmitRegisterName(MaskRegister);
2244 OS <<
", " << MaskRegisterSize <<
", " <<
Offset;
2248void MCAsmStreamer::emitCFILLVMVectorRegisterMask(
2249 int64_t
Register, int64_t SpillRegister,
2250 int64_t SpillRegisterLaneSizeInBits, int64_t MaskRegister,
2251 int64_t MaskRegisterSizeInBits, SMLoc Loc) {
2253 Register, SpillRegister, SpillRegisterLaneSizeInBits, MaskRegister,
2254 MaskRegisterSizeInBits, Loc);
2256 OS <<
"\t.cfi_llvm_vector_register_mask ";
2259 EmitRegisterName(SpillRegister);
2260 OS <<
", " << SpillRegisterLaneSizeInBits <<
", ";
2261 EmitRegisterName(MaskRegister);
2262 OS <<
", " << MaskRegisterSizeInBits;
2266void MCAsmStreamer::emitCFIWindowSave(SMLoc Loc) {
2268 OS <<
"\t.cfi_window_save";
2272void MCAsmStreamer::emitCFINegateRAState(SMLoc Loc) {
2274 OS <<
"\t.cfi_negate_ra_state";
2278void MCAsmStreamer::emitCFINegateRAStateWithPC(SMLoc Loc) {
2280 OS <<
"\t.cfi_negate_ra_state_with_pc";
2284void MCAsmStreamer::emitCFIReturnColumn(int64_t
Register) {
2286 OS <<
"\t.cfi_return_column ";
2291void MCAsmStreamer::emitCFILabelDirective(SMLoc Loc, StringRef Name) {
2293 OS <<
"\t.cfi_label " <<
Name;
2297void MCAsmStreamer::emitCFIBKeyFrame() {
2299 OS <<
"\t.cfi_b_key_frame";
2303void MCAsmStreamer::emitCFIMTETaggedFrame() {
2305 OS <<
"\t.cfi_mte_tagged_frame";
2309void MCAsmStreamer::emitCFIValOffset(int64_t
Register, int64_t
Offset,
2312 OS <<
"\t.cfi_val_offset ";
2318void MCAsmStreamer::emitWinCFIStartProc(
const MCSymbol *Symbol, SMLoc Loc) {
2326void MCAsmStreamer::emitWinCFIEndProc(SMLoc Loc) {
2329 OS <<
"\t.seh_endproc";
2333void MCAsmStreamer::emitWinCFIFuncletOrFuncEnd(SMLoc Loc) {
2336 OS <<
"\t.seh_endfunclet";
2340void MCAsmStreamer::emitWinCFISplitChained(SMLoc Loc) {
2343 OS <<
"\t.seh_splitchained";
2347void MCAsmStreamer::emitWinEHHandler(
const MCSymbol *Sym,
bool Unwind,
2348 bool Except, SMLoc Loc) {
2351 OS <<
"\t.seh_handler ";
2352 Sym->
print(OS, MAI);
2358 OS <<
", " << Marker <<
"unwind";
2360 OS <<
", " << Marker <<
"except";
2364void MCAsmStreamer::emitWinEHHandlerData(SMLoc Loc) {
2371 WinEH::FrameInfo *CurFrame = getCurrentWinFrameInfo();
2379 MCSection *XData = getAssociatedXDataSection(TextSec);
2380 switchSectionNoPrint(XData);
2382 OS <<
"\t.seh_handlerdata";
2386void MCAsmStreamer::emitWinCFIPushReg(MCRegister
Register, SMLoc Loc) {
2389 OS <<
"\t.seh_pushreg ";
2390 InstPrinter->printRegName(OS,
Register);
2394void MCAsmStreamer::emitWinCFISetFrame(MCRegister
Register,
unsigned Offset,
2398 OS <<
"\t.seh_setframe ";
2399 InstPrinter->printRegName(OS,
Register);
2404void MCAsmStreamer::emitWinCFIAllocStack(
unsigned Size, SMLoc Loc) {
2407 OS <<
"\t.seh_stackalloc " <<
Size;
2411void MCAsmStreamer::emitWinCFISaveReg(MCRegister
Register,
unsigned Offset,
2415 OS <<
"\t.seh_savereg ";
2416 InstPrinter->printRegName(OS,
Register);
2421void MCAsmStreamer::emitWinCFISaveXMM(MCRegister
Register,
unsigned Offset,
2425 OS <<
"\t.seh_savexmm ";
2426 InstPrinter->printRegName(OS,
Register);
2431void MCAsmStreamer::emitWinCFIPushFrame(
bool Code, SMLoc Loc) {
2434 OS <<
"\t.seh_pushframe";
2440void MCAsmStreamer::emitWinCFIEndProlog(SMLoc Loc) {
2443 OS <<
"\t.seh_endprologue";
2447void MCAsmStreamer::emitWinCFIBeginEpilogue(SMLoc Loc) {
2450 OS <<
"\t.seh_startepilogue";
2454void MCAsmStreamer::emitWinCFIEndEpilogue(SMLoc Loc) {
2457 OS <<
"\t.seh_endepilogue";
2461void MCAsmStreamer::emitWinCFIUnwindV2Start(SMLoc Loc) {
2464 OS <<
"\t.seh_unwindv2start";
2468void MCAsmStreamer::emitWinCFIUnwindVersion(uint8_t
Version, SMLoc Loc) {
2471 OS <<
"\t.seh_unwindversion " << (unsigned)
Version;
2475void MCAsmStreamer::emitCGProfileEntry(
const MCSymbolRefExpr *From,
2476 const MCSymbolRefExpr *To,
2478 OS <<
"\t.cg_profile ";
2482 OS <<
", " <<
Count;
2486void MCAsmStreamer::AddEncodingComment(
const MCInst &Inst,
2487 const MCSubtargetInfo &STI) {
2488 raw_ostream &OS = getCommentOS();
2489 SmallString<256>
Code;
2493 if (!getAssembler().getEmitterPtr())
2496 getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI);
2499 bool ForceLE =
getContext().getTargetTriple().isRISCV();
2506 for (
unsigned i = 0, e =
Code.size() * 8; i != e; ++i)
2509 for (
unsigned i = 0, e =
Fixups.size(); i != e; ++i) {
2511 MCFixupKindInfo
Info =
2512 getAssembler().getBackend().getFixupKindInfo(
F.getKind());
2513 for (
unsigned j = 0;
j !=
Info.TargetSize; ++
j) {
2514 unsigned Index =
F.getOffset() * 8 +
Info.TargetOffset +
j;
2515 assert(Index <
Code.size() * 8 &&
"Invalid offset in fixup!");
2516 FixupMap[
Index] = 1 + i;
2522 OS <<
"encoding: [";
2523 for (
unsigned i = 0, e =
Code.size(); i != e; ++i) {
2528 uint8_t MapEntry = FixupMap[i * 8 + 0];
2529 for (
unsigned j = 1;
j != 8; ++
j) {
2530 if (FixupMap[i * 8 + j] == MapEntry)
2533 MapEntry = uint8_t(~0U);
2537 if (MapEntry != uint8_t(~0U)) {
2538 if (MapEntry == 0) {
2539 OS <<
format(
"0x%02x", uint8_t(Code[i]));
2543 OS <<
format(
"0x%02x", uint8_t(Code[i])) <<
'\''
2544 << char(
'A' + MapEntry - 1) <<
'\'';
2546 OS << char(
'A' + MapEntry - 1);
2551 for (
unsigned j = 8;
j--;) {
2559 FixupBit = i * 8 +
j;
2561 FixupBit = i * 8 + (7-
j);
2563 if (uint8_t MapEntry = FixupMap[FixupBit]) {
2564 assert(Bit == 0 &&
"Encoder wrote into fixed up bit!");
2565 OS << char(
'A' + MapEntry - 1);
2573 for (
unsigned i = 0, e =
Fixups.size(); i != e; ++i) {
2575 OS <<
" fixup " << char(
'A' + i) <<
" - "
2576 <<
"offset: " <<
F.getOffset() <<
", value: ";
2578 auto Kind =
F.getKind();
2580 OS <<
", relocation type: " <<
Kind;
2583 auto Info = getAssembler().getBackend().getFixupKindInfo(Kind);
2584 if (
F.isPCRel() && StringRef(
Info.Name).starts_with(
"FK_Data_"))
2585 OS <<
"FK_PCRel_" << (
Info.TargetSize / 8);
2593void MCAsmStreamer::emitInstruction(
const MCInst &Inst,
2594 const MCSubtargetInfo &STI) {
2595 if (LFIRewriter && LFIRewriter->rewriteInst(Inst, *
this, STI))
2599 MCSection *Sec = getCurrentSectionOnly();
2603 if (MAI->
isAIX() && CurFrag)
2609 AddEncodingComment(Inst, STI);
2614 getCommentOS() <<
"\n";
2617 if(getTargetStreamer())
2618 getTargetStreamer()->prettyPrintAsm(*InstPrinter, 0, Inst, STI, OS);
2620 InstPrinter->printInst(&Inst, 0,
"", STI, OS);
2622 StringRef Comments = CommentToEmit;
2623 if (Comments.
size() && Comments.
back() !=
'\n')
2624 getCommentOS() <<
"\n";
2629void MCAsmStreamer::emitPseudoProbe(uint64_t
Guid, uint64_t Index,
2630 uint64_t
Type, uint64_t Attr,
2631 uint64_t Discriminator,
2634 OS <<
"\t.pseudoprobe\t" <<
Guid <<
" " <<
Index <<
" " <<
Type <<
" " << Attr;
2639 for (
const auto &Site : InlineStack)
2640 OS <<
" @ " << std::get<0>(Site) <<
":" << std::get<1>(Site);
2643 FnSym->
print(OS, MAI);
2648void MCAsmStreamer::emitRelocDirective(
const MCExpr &
Offset, StringRef Name,
2649 const MCExpr *Expr, SMLoc) {
2660void MCAsmStreamer::emitAddrsig() {
2665void MCAsmStreamer::emitAddrsigSym(
const MCSymbol *Sym) {
2666 OS <<
"\t.addrsig_sym ";
2667 Sym->
print(OS, MAI);
2674void MCAsmStreamer::emitRawTextImpl(StringRef
String) {
2675 String.consume_back(
"\n");
2680void MCAsmStreamer::finishImpl() {
2698 const auto &Tables =
getContext().getMCDwarfLineTables();
2699 if (!Tables.empty()) {
2700 assert(Tables.size() == 1 &&
"asm output only supports one line table");
2701 if (
auto *Label = Tables.begin()->second.getLabel()) {
2702 switchSection(
getContext().getObjectFileInfo()->getDwarfLineSection(), 0);
2708void MCAsmStreamer::emitDwarfUnitLength(uint64_t
Length,
const Twine &Comment) {
2720MCSymbol *MCAsmStreamer::emitDwarfUnitLength(
const Twine &Prefix,
2721 const Twine &Comment) {
2729 return getContext().createTempSymbol(Prefix +
"_end");
2733void MCAsmStreamer::emitDwarfLineStartLabel(MCSymbol *StartSym) {
2744 emitLabel(DebugLineSymTmp);
2748 unsigned LengthFieldSize =
2754 emitAssignment(StartSym, OuterSym);
2760void MCAsmStreamer::emitDwarfLineEndEntry(MCSection *Section,
2761 MCSymbol *LastLabel,
2762 MCSymbol *EndLabel) {
2769 ".loc should not be generated together with raw data!");
2782 emitDwarfAdvanceLineAddr(
INT64_MAX, LastLabel, EndLabel,
2787void MCAsmStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
2788 const MCSymbol *LastLabel,
2789 const MCSymbol *Label,
2790 unsigned PointerSize) {
2792 ".loc/.file don't need raw data in debug line section!");
2795 AddComment(
"Set address to " +
Label->getName());
2796 emitIntValue(dwarf::DW_LNS_extended_op, 1);
2797 emitULEB128IntValue(PointerSize + 1);
2798 emitIntValue(dwarf::DW_LNE_set_address, 1);
2799 emitSymbolValue(Label, PointerSize);
2803 AddComment(
"Start sequence");
2811 AddComment(
"End sequence");
2812 emitIntValue(dwarf::DW_LNS_extended_op, 1);
2813 emitULEB128IntValue(1);
2814 emitIntValue(dwarf::DW_LNE_end_sequence, 1);
2819 AddComment(
"Advance line " + Twine(LineDelta));
2820 emitIntValue(dwarf::DW_LNS_advance_line, 1);
2821 emitSLEB128IntValue(LineDelta);
2822 emitIntValue(dwarf::DW_LNS_copy, 1);
2826 std::unique_ptr<formatted_raw_ostream> OS,
2827 std::unique_ptr<MCInstPrinter> IP,
2828 std::unique_ptr<MCCodeEmitter> CE,
2829 std::unique_ptr<MCAsmBackend> MAB) {
2830 return new MCAsmStreamer(Context, std::move(OS), std::move(IP), std::move(CE),
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_LIKELY(EXPR)
static ManagedStatic< cl::opt< bool, true >, CreateDebug > Debug
static void PrintCFIEscape(llvm::formatted_raw_ostream &OS, StringRef Values)
static const char * getVersionMinDirective(MCVersionMinType Type)
static bool isPrintableString(StringRef Data)
static void PrintByteList(StringRef Data, raw_ostream &OS, MCAsmInfo::AsmCharLiteralSyntax ACLS)
static char toOctal(int X)
static void EmitSDKVersionSuffix(raw_ostream &OS, const VersionTuple &SDKVersion)
static int64_t truncateToSize(int64_t Value, unsigned Bytes)
static const char * getPlatformName(MachO::PlatformType Type)
#define DWARF2_FLAG_IS_STMT
#define DWARF2_FLAG_BASIC_BLOCK
#define DWARF2_FLAG_PROLOGUE_END
#define DWARF2_FLAG_EPILOGUE_BEGIN
This file declares the MCLFIRewriter class, an abstract class that encapsulates the rewriting logic f...
LFI-specific code for MC.
Promote Memory to Register
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
static constexpr StringLiteral Filename
This file defines the SmallString class.
StringRef getMnemonic(unsigned Opc)
LLVM_ABI void print(raw_ostream &OS) const
Print out the bounds to a stream.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
const char * getLabelSuffix() const
bool hasDotTypeDotSizeDirective() const
bool isLittleEndian() const
True if the target is little endian.
bool doesSupportDataRegionDirectives() const
bool usesSetToEquateSymbol() const
const char * getData32bitsDirective() const
unsigned getTextAlignFillValue() const
bool useDwarfRegNumForCFI() const
bool supportsExtendedDwarfLocDirective() const
const char * getData8bitsDirective() const
const char * getData64bitsDirective() const
AsmCharLiteralSyntax characterLiteralSyntax() const
LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const
void printExpr(raw_ostream &, const MCExpr &) const
virtual void printSwitchToSection(const MCSection &, uint32_t Subsection, const Triple &, raw_ostream &) const
StringRef getCommentString() const
const char * getAscizDirective() const
const char * getZeroDirective() const
const char * getWeakDirective() const
const char * getData16bitsDirective() const
const char * getSeparatorString() const
bool getCOMMDirectiveAlignmentIsInBytes() const
const char * getGlobalDirective() const
unsigned getCommentColumn() const
bool hasSingleParameterDotFile() const
const char * getAsciiDirective() const
AsmCharLiteralSyntax
Assembly character literal syntax types.
@ ACLS_SingleQuotePrefix
Unknown; character literals not used by LLVM for this target.
const char * getWeakRefDirective() const
bool hasNoDeadStrip() const
bool hasIdentDirective() const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Context object for machine code objects.
const MCObjectFileInfo * getObjectFileInfo() const
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
dwarf::DwarfFormat getDwarfFormat() const
const MCAsmInfo & getAsmInfo() const
static LLVM_ABI void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
static LLVM_ABI void make(MCStreamer *MCOS, MCSection *Section)
static LLVM_ABI void emit(MCStreamer *MCOS, MCDwarfLineTableParams Params)
LLVM_ABI Expected< unsigned > tryGetFile(StringRef &Directory, StringRef &FileName, std::optional< MD5::MD5Result > Checksum, std::optional< StringRef > Source, uint16_t DwarfVersion, unsigned FileNumber=0)
const SmallVectorImpl< MCDwarfFile > & getMCDwarfFiles() const
static LLVM_ABI void Emit(MCStreamer *MCOS)
LLVM_ABI void dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer=nullptr, StringRef Separator=" ", const MCContext *Ctx=nullptr) const
Dump the MCInst as prettily as possible using the additional MC structures, if given.
MCSection * getTextSection() const
std::optional< MCRegister > getLLVMRegNum(uint64_t RegNum, bool isEH) const
Map a dwarf register back to a target register.
StringRef getSegmentName() const
MCSymbol * getEndSymbol(MCContext &Ctx)
void setHasInstructions(bool Value)
StringRef getName() const
Streaming machine code generation interface.
virtual void emitCFIGnuArgsSize(int64_t Size, SMLoc Loc={})
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
virtual void emitCFILLVMVectorOffset(int64_t Register, int64_t RegisterSizeInBits, int64_t MaskRegister, int64_t MaskRegisterSizeInBits, int64_t Offset, SMLoc Loc={})
virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc={})
virtual void emitWinCFIUnwindVersion(uint8_t Version, SMLoc Loc=SMLoc())
virtual bool emitCVFuncIdDirective(unsigned FunctionId)
Introduces a function id for use with .cv_loc.
virtual void emitCFIBKeyFrame()
virtual void emitWinCFIPushReg(MCRegister Register, SMLoc Loc=SMLoc())
virtual bool popSection()
Restore the current and previous section from the section stack.
virtual void emitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except, SMLoc Loc=SMLoc())
virtual void emitCFISections(bool EH, bool Debug, bool SFrame)
virtual void emitDwarfLocLabelDirective(SMLoc Loc, StringRef Name)
This implements the '.loc_label Name' directive.
virtual void emitCFINegateRAStateWithPC(SMLoc Loc={})
virtual void emitCFISameValue(int64_t Register, SMLoc Loc={})
virtual void emitCFIReturnColumn(int64_t Register)
virtual void emitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
virtual void emitDwarfUnitLength(uint64_t Length, const Twine &Comment)
Emit a unit length field.
virtual void emitCFIWindowSave(SMLoc Loc={})
virtual void emitCFILLVMRegisterPair(int64_t Register, int64_t R1, int64_t R1SizeInBits, int64_t R2, int64_t R2SizeInBits, SMLoc Loc={})
virtual void emitWinCFIUnwindV2Start(SMLoc Loc=SMLoc())
virtual void emitWinCFIEndEpilogue(SMLoc Loc=SMLoc())
virtual void emitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
virtual void emitWinEHHandlerData(SMLoc Loc=SMLoc())
virtual void emitCFIUndefined(int64_t Register, SMLoc Loc={})
virtual void emitWinCFISaveXMM(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
virtual void emitCFINegateRAState(SMLoc Loc={})
virtual void emitCFILsda(const MCSymbol *Sym, unsigned Encoding)
virtual void emitWinCFIBeginEpilogue(SMLoc Loc=SMLoc())
virtual void emitCFIMTETaggedFrame()
virtual void emitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc=SMLoc())
virtual void emitDwarfLineStartLabel(MCSymbol *StartSym)
Emit the debug line start label.
virtual void emitCFIEscape(StringRef Values, SMLoc Loc={})
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
virtual void emitCFIRememberState(SMLoc Loc)
virtual void emitCFILabelDirective(SMLoc Loc, StringRef Name)
virtual void emitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName, StringRef Comment={})
This implements the DWARF2 '.loc fileno lineno ...' assembler directive.
virtual void emitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView '.cv_linetable' assembler directive.
virtual void emitWinCFISaveReg(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
virtual void emitWinCFIEndProlog(SMLoc Loc=SMLoc())
virtual void emitWinCFIEndProc(SMLoc Loc=SMLoc())
virtual void emitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
virtual void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc={})
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
virtual void emitCFIRegister(int64_t Register1, int64_t Register2, SMLoc Loc={})
virtual void emitWinCFIFuncletOrFuncEnd(SMLoc Loc=SMLoc())
This is used on platforms, such as Windows on ARM64, that require function or funclet sizes to be emi...
virtual void emitCFIAdjustCfaOffset(int64_t Adjustment, SMLoc Loc={})
virtual void emitCFILLVMVectorRegisterMask(int64_t Register, int64_t SpillRegister, int64_t SpillRegisterLaneSizeInBits, int64_t MaskRegister, int64_t MaskRegisterSizeInBits, SMLoc Loc={})
virtual void emitCFIRelOffset(int64_t Register, int64_t Offset, SMLoc Loc)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
virtual void emitCFIRestoreState(SMLoc Loc)
virtual void emitCFIOffset(int64_t Register, int64_t Offset, SMLoc Loc={})
virtual void emitWinCFISetFrame(MCRegister Register, unsigned Offset, SMLoc Loc=SMLoc())
virtual void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc={})
virtual void emitWinCFISplitChained(SMLoc Loc=SMLoc())
virtual void emitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
virtual void emitCFIValOffset(int64_t Register, int64_t Offset, SMLoc Loc={})
virtual bool emitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol, SMLoc Loc)
Introduces an inline call site id for use with .cv_loc.
virtual void emitCFISignalFrame()
virtual void emitCFILLVMVectorRegisters(int64_t Register, ArrayRef< MCCFIInstruction::VectorRegisterWithLane > VRs, SMLoc Loc={})
virtual void emitCFIRestore(int64_t Register, SMLoc Loc={})
virtual void emitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView '.cv_inline_linetable' assembler directive.
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
virtual void emitCFILLVMDefAspaceCfa(int64_t Register, int64_t Offset, int64_t AddressSpace, SMLoc Loc={})
const MCSymbol & getSymbol() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
LLVM_ABI void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
DwarfDirectory MCUseDwarfDirectory
void append(StringRef RHS)
Append from a StringRef.
void push_back(const T &Elt)
Represent a constant reference to a string, i.e.
std::string str() const
Get the contents as an std::string.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
Check if the string is empty.
char back() const
Get the last character in the string.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
constexpr size_t size() const
Get the string size.
char front() const
Get the first character in the string.
size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
Represents a version number in the form major[.minor[.subminor[.build]]].
unsigned getMajor() const
Retrieve the major version number.
std::optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
bool empty() const
Determine whether this version information is empty (e.g., all version components are zero).
std::optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_hex(unsigned long long N)
Output N in hexadecimal, without any prefix or padding.
size_t GetNumBytesInBuffer() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
void emitInstruction(MCObjectStreamer &, const MCInst &Inst, const MCSubtargetInfo &STI)
uint8_t getUnitLengthFieldByteSize(DwarfFormat Format)
Get the byte size of the unit length field depending on the DWARF format.
support::ulittle32_t Word
bool isRelocation(MCFixupKind FixupKind)
LLVM_ABI int getDwarfVersion()
@ Emitted
Assigned address, still materializing.
NodeAddr< CodeNode * > Code
Context & getContext() const
uint32_t read32be(const void *P)
LLVM_ABI bool is_absolute(const Twine &path, Style style=Style::native)
Is path absolute?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
FunctionAddr VTableAddr Value
@ Debug
Register 'use' is for debugging purpose.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static StringRef MCLOHDirectiveName()
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
LLVM_ABI MCStreamer * createAsmStreamer(MCContext &Ctx, std::unique_ptr< formatted_raw_ostream > OS, std::unique_ptr< MCInstPrinter > InstPrint, std::unique_ptr< MCCodeEmitter > CE, std::unique_ptr< MCAsmBackend > TAB)
Create a machine code streamer which will print out assembly for the native target,...
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
@ MCDR_DataRegionEnd
.end_data_region
@ MCDR_DataRegion
.data_region
@ MCDR_DataRegionJT8
.data_region jt8
@ MCDR_DataRegionJT32
.data_region jt32
@ MCDR_DataRegionJT16
.data_region jt16
MCLOHDirective::LOHArgs MCLOHArgs
LLVM_ABI void emitLFINoteSection(MCStreamer &Streamer, MCContext &Ctx)
FunctionAddr VTableAddr uintptr_t uintptr_t Version
SmallVector< InlineSite, 8 > MCPseudoProbeInlineStack
@ MCVM_WatchOSVersionMin
.watchos_version_min
@ MCVM_OSXVersionMin
.macosx_version_min
@ MCVM_TvOSVersionMin
.tvos_version_min
@ MCVM_IOSVersionMin
.ios_version_min
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
FunctionAddr VTableAddr Count
LLVM_ABI raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
static int MCLOHIdToNbArgs(MCLOHType Kind)
FunctionAddr VTableAddr uintptr_t uintptr_t Data
MCLOHType
Linker Optimization Hint Type.
ArrayRef(const T &OneElt) -> ArrayRef< T >
void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)
Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
bool isPrint(char C)
Checks whether character C is printable.
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
unsigned Log2(Align A)
Returns the log2 of the alignment.
std::pair< MCSection *, uint32_t > MCSectionSubPair
T bit_floor(T Value)
Returns the largest integral power of two no greater than Value if Value is nonzero.
@ MCSA_WeakDefAutoPrivate
.weak_def_can_be_hidden (MachO)
@ MCSA_Memtag
.memtag (ELF)
@ MCSA_Protected
.protected (ELF)
@ MCSA_OSLinkage
symbol uses OS linkage (GOFF)
@ MCSA_Exported
.globl _foo, exported (XCOFF)
@ MCSA_PrivateExtern
.private_extern (MachO)
@ MCSA_Internal
.internal (ELF)
@ MCSA_WeakReference
.weak_reference (MachO)
@ MCSA_AltEntry
.alt_entry (MachO)
@ MCSA_ELF_TypeIndFunction
.type _foo, STT_GNU_IFUNC
@ MCSA_LazyReference
.lazy_reference (MachO)
@ MCSA_ELF_TypeNoType
.type _foo, STT_NOTYPE # aka @notype
@ MCSA_Reference
.reference (MachO)
@ MCSA_SymbolResolver
.symbol_resolver (MachO)
@ MCSA_ELF_TypeTLS
.type _foo, STT_TLS # aka @tls_object
@ MCSA_IndirectSymbol
.indirect_symbol (MachO)
@ MCSA_WeakDefinition
.weak_definition (MachO)
@ MCSA_ELF_TypeCommon
.type _foo, STT_COMMON # aka @common
@ MCSA_Global
.type _foo, @gnu_unique_object
@ MCSA_WeakAntiDep
.weak_anti_dep (COFF)
@ MCSA_XPLinkage
symbol uses XP linkage (GOFF)
@ MCSA_Extern
.extern (XCOFF)
@ MCSA_ELF_TypeObject
.type _foo, STT_OBJECT # aka @object
@ MCSA_ELF_TypeGnuUniqueObject
@ MCSA_ELF_TypeFunction
.type _foo, STT_FUNC # aka @function
@ MCSA_Hidden
.hidden (ELF)
@ MCSA_LGlobal
.lglobl (XCOFF)
@ MCSA_Invalid
Not a valid directive.
@ MCSA_NoDeadStrip
.no_dead_strip (MachO)
static StringRef MCLOHIdToName(MCLOHType Kind)
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
const MCSymbol * Function