@@ -70,6 +70,17 @@ class MCAsmStreamer final : public MCStreamer {
7070 void emitCFIStartProcImpl (MCDwarfFrameInfo &Frame) override ;
7171 void emitCFIEndProcImpl (MCDwarfFrameInfo &Frame) override ;
7272
73+ // / Helper to emit common .loc directive flags, isa, and discriminator
74+ void emitDwarfLocDirectiveFlags (unsigned Flags, unsigned Isa,
75+ unsigned Discriminator);
76+
77+ // / Helper to emit the common suffix of .loc directives (flags, comment, EOL,
78+ // / parent call)
79+ void emitDwarfLocDirectiveSuffix (unsigned FileNo, unsigned Line,
80+ unsigned Column, unsigned Flags,
81+ unsigned Isa, unsigned Discriminator,
82+ StringRef FileName, StringRef Comment);
83+
7384public:
7485 MCAsmStreamer (MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
7586 std::unique_ptr<MCInstPrinter> printer,
@@ -297,6 +308,14 @@ class MCAsmStreamer final : public MCStreamer {
297308 StringRef Location = {}) override ;
298309 void emitDwarfLocLabelDirective (SMLoc Loc, StringRef Name) override ;
299310
311+ void emitDwarfLocDirectiveWithInlinedAt (unsigned FileNo, unsigned Line,
312+ unsigned Column, unsigned FileIA,
313+ unsigned LineIA, unsigned ColIA,
314+ const MCSymbol *Sym, unsigned Flags,
315+ unsigned Isa, unsigned Discriminator,
316+ StringRef FileName,
317+ StringRef Comment = {}) override ;
318+
300319 MCSymbol *getDwarfLineTableSymbol (unsigned CUID) override ;
301320
302321 bool emitCVFileDirective (unsigned FileNo, StringRef Filename,
@@ -1675,6 +1694,57 @@ void MCAsmStreamer::emitDwarfFile0Directive(
16751694 emitRawText (OS1.str ());
16761695}
16771696
1697+ // / Helper to emit common .loc directive flags, isa, and discriminator
1698+ void MCAsmStreamer::emitDwarfLocDirectiveFlags (unsigned Flags, unsigned Isa,
1699+ unsigned Discriminator) {
1700+ if (!MAI->supportsExtendedDwarfLocDirective ())
1701+ return ;
1702+
1703+ if (Flags & DWARF2_FLAG_BASIC_BLOCK)
1704+ OS << " basic_block" ;
1705+ if (Flags & DWARF2_FLAG_PROLOGUE_END)
1706+ OS << " prologue_end" ;
1707+ if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1708+ OS << " epilogue_begin" ;
1709+
1710+ const unsigned OldFlags = getContext ().getCurrentDwarfLoc ().getFlags ();
1711+ if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
1712+ OS << " is_stmt " ;
1713+ OS << ((Flags & DWARF2_FLAG_IS_STMT) ? " 1" : " 0" );
1714+ }
1715+
1716+ if (Isa)
1717+ OS << " isa " << Isa;
1718+ if (Discriminator)
1719+ OS << " discriminator " << Discriminator;
1720+ }
1721+
1722+ // / Helper to emit the common suffix of .loc directives
1723+ void MCAsmStreamer::emitDwarfLocDirectiveSuffix (unsigned FileNo, unsigned Line,
1724+ unsigned Column, unsigned Flags,
1725+ unsigned Isa,
1726+ unsigned Discriminator,
1727+ StringRef FileName,
1728+ StringRef Comment) {
1729+ // Emit flags, isa, and discriminator
1730+ emitDwarfLocDirectiveFlags (Flags, Isa, Discriminator);
1731+
1732+ // Emit verbose comment if enabled
1733+ if (IsVerboseAsm) {
1734+ OS.PadToColumn (MAI->getCommentColumn ());
1735+ OS << MAI->getCommentString () << ' ' ;
1736+ if (Comment.empty ())
1737+ OS << FileName << ' :' << Line << ' :' << Column;
1738+ else
1739+ OS << Comment;
1740+ }
1741+
1742+ // Emit end of line and update parent state
1743+ EmitEOL ();
1744+ MCStreamer::emitDwarfLocDirective (FileNo, Line, Column, Flags, Isa,
1745+ Discriminator, FileName, Comment);
1746+ }
1747+
16781748void MCAsmStreamer::emitDwarfLocDirective (unsigned FileNo, unsigned Line,
16791749 unsigned Column, unsigned Flags,
16801750 unsigned Isa, unsigned Discriminator,
@@ -1691,42 +1761,29 @@ void MCAsmStreamer::emitDwarfLocDirective(unsigned FileNo, unsigned Line,
16911761 return ;
16921762 }
16931763
1764+ // Emit the basic .loc directive
16941765 OS << " \t .loc\t " << FileNo << " " << Line << " " << Column;
1695- if (MAI->supportsExtendedDwarfLocDirective ()) {
1696- if (Flags & DWARF2_FLAG_BASIC_BLOCK)
1697- OS << " basic_block" ;
1698- if (Flags & DWARF2_FLAG_PROLOGUE_END)
1699- OS << " prologue_end" ;
1700- if (Flags & DWARF2_FLAG_EPILOGUE_BEGIN)
1701- OS << " epilogue_begin" ;
1702-
1703- unsigned OldFlags = getContext ().getCurrentDwarfLoc ().getFlags ();
1704- if ((Flags & DWARF2_FLAG_IS_STMT) != (OldFlags & DWARF2_FLAG_IS_STMT)) {
1705- OS << " is_stmt " ;
1706-
1707- if (Flags & DWARF2_FLAG_IS_STMT)
1708- OS << " 1" ;
1709- else
1710- OS << " 0" ;
1711- }
17121766
1713- if (Isa)
1714- OS << " isa " << Isa;
1715- if (Discriminator)
1716- OS << " discriminator " << Discriminator;
1717- }
1767+ // Emit common suffix (flags, comment, EOL, parent call)
1768+ emitDwarfLocDirectiveSuffix (FileNo, Line, Column, Flags, Isa, Discriminator,
1769+ FileName, Comment);
1770+ }
17181771
1719- if (IsVerboseAsm) {
1720- OS.PadToColumn (MAI->getCommentColumn ());
1721- OS << MAI->getCommentString () << ' ' ;
1722- if (Comment.empty ())
1723- OS << FileName << ' :' << Line << ' :' << Column;
1724- else
1725- OS << Comment;
1726- }
1727- EmitEOL ();
1728- this ->MCStreamer ::emitDwarfLocDirective (FileNo, Line, Column, Flags, Isa,
1729- Discriminator, FileName, Comment);
1772+ // / This is same as emitDwarfLocDirective, except also emits inlined function
1773+ // / and inlined callsite information.
1774+ void MCAsmStreamer::emitDwarfLocDirectiveWithInlinedAt (
1775+ unsigned FileNo, unsigned Line, unsigned Column, unsigned FileIA,
1776+ unsigned LineIA, unsigned ColIA, const MCSymbol *Sym, unsigned Flags,
1777+ unsigned Isa, unsigned Discriminator, StringRef FileName,
1778+ StringRef Comment) {
1779+ // Emit the basic .loc directive with NVPTX-specific extensions
1780+ OS << " \t .loc\t " << FileNo << " " << Line << " " << Column;
1781+ OS << " , function_name " << *Sym;
1782+ OS << " , inlined_at " << FileIA << " " << LineIA << " " << ColIA;
1783+
1784+ // Emit common suffix (flags, comment, EOL, parent call)
1785+ emitDwarfLocDirectiveSuffix (FileNo, Line, Column, Flags, Isa, Discriminator,
1786+ FileName, Comment);
17301787}
17311788
17321789void MCAsmStreamer::emitDwarfLocLabelDirective (SMLoc Loc, StringRef Name) {
0 commit comments