<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hi,</p>
<p>Thank you all for this great conversation!</p>
<p><br>
</p>
<p>I see that the [0] was removed after the commit for
<a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D70350">https://reviews.llvm.org/D70350</a> (e08f205f), so the 'retainedTypes'
is not being used for the feature anymore. Therefore, it is safe
just to remove it from LLVM IR.</p>
<p>Please find the change posted as <a class="moz-txt-link-freetext" href="https://reviews.llvm.org/D80369">https://reviews.llvm.org/D80369</a>.<br>
</p>
<p><br>
</p>
<p>[0] <a href="https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L882">https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L882</a></p>
<p><br>
</p>
<p>Best regards,</p>
<p>Djordje</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 21.5.20. 00:37, David Blaikie wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAENS6EvohzEys00OgNVW+OXcfOcQBF6jC+WfsHqeQNiLNHrvBQ@mail.gmail.com">
<div dir="ltr">
<div dir="ltr"><br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, May 20, 2020 at 3:01
PM Adrian Prantl <<a href="mailto:aprantl@apple.com" moz-do-not-send="true">aprantl@apple.com</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;"><br>
<div><br>
<blockquote type="cite">
<div>On May 20, 2020, at 1:57 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank" moz-do-not-send="true">dblaikie@gmail.com</a>>
wrote:</div>
<br>
<div><br>
<br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div dir="ltr" class="gmail_attr">On Wed, May 20,
2020 at 9:17 AM Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank" moz-do-not-send="true">aprantl@apple.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div><br>
<div><br>
<blockquote type="cite">
<div>On May 19, 2020, at 3:03 PM, Vedant
Kumar <<a href="mailto:vedant_kumar@apple.com" target="_blank" moz-do-not-send="true">vedant_kumar@apple.com</a>>
wrote:</div>
<br>
<div>
<div>Hi,
<div><br>
</div>
<div>In a recent review (<a href="https://reviews.llvm.org/D79967" target="_blank" moz-do-not-send="true">https://reviews.llvm.org/D79967</a>),
David Blaikie suggested that we have
a broader design discussion about
how support for DW_TAG_call_site is
supported in clang, so I’ll kick off
the discussion.</div>
<div><br>
</div>
<div>Some topics to discuss:</div>
<div><br>
</div>
<div>1) Under LTO, if we emit a
declaration DISubprogram for a
function in one TU, and another TU
defines the function with
__attribute__((nodebug)), would the
declaration DISubprogram get
attached to the definition?</div>
<div><br>
</div>
<div>My own thoughts on this: firstly,
as posed in <a href="https://reviews.llvm.org/D79967" target="_blank" moz-do-not-send="true">D79967</a>,
I think David was asking about the
case where the declaration
subprogram does not have an attached
unit. I’m not sure why it wouldn’t,
though, so I’d appreciate some
clarification on that. Second, as
far as I know, there isn’t a
mechanism for attaching a
declaration subprogram to a Function
which doesn’t have debug info.</div>
<div><br>
</div>
<div>2) Should declaration subprograms
emitted in support of
DW_TAG_call_site be kept in the CU’s
retainedTypes field?</div>
<div><br>
</div>
<div>David pointed out that these
declarations a) persist through
optimization and b) don't get
deduplicated against the
definitions, which means there’s
potential to bloat debug info. As an
alternative, we might attach a
declaration subprogram to the
corresponding Function (which we do
already), but leave it out of the
CU’s retainedTypes field.</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I'm having trouble visualizing this
example: We are talking about forward
declaration DISubprograms created for call
sites of functions that are not defined in
the CU where the call site is, correct?</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Right</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<div>What does "attaching a declaration to
the corresponding function" mean?</div>
</div>
</div>
</blockquote>
<div><br>
I think "attaching the declaration DISubprogram
to the corresponding llvm::Function" would be a
more precise statement. The same way definition
DISubprograms are attached to llvm::Functions,
using the Function's !dbg/getSubprogram field.<br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<div>Why are we currently entering those
declarations into retainedTypes?</div>
</div>
</div>
</blockquote>
<div><br>
Because we're not currently attaching those
DISubprogram declarations to the llvm::Function
declarations - or any other part of the IR.<br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I see.</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Just to correct this (for other readers) - as stated
later in my email, this statement is incorrect - declaration
DISubprograms are attached to declaration llvm::Functions in
addition to being added to retainedTypes. And because of
this, I have no answer to "why are we currently entering
those declarations into retainedTypes" - I don't see any
reason to do so.</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;">
<div>
<div> That was the piece I was missing — it wasn't clear
to me that there were llvm::Function forward
declarations in addition to the DISubprograms, but of
course, that is how external calls are represented in
IR. Makes perfect sense now.</div>
<br>
<blockquote type="cite">
<div>
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div> </div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<div>I would have expected the reference
from the call site to hold on to them.<span> </span></div>
</div>
</div>
</blockquote>
<div><br>
That would be a 3rd option - think attaching
them to the llvm::Function would /probably/ be
better. (since the IR already has the
infrastructure for that attachment, whereas the
call instruction doesn't - it just has the
DebugLoc attachment)<br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<div>I guess it's unclear to me how call
sites are represented at the moment.</div>
</div>
</div>
</blockquote>
<div><br>
Right, probably a good place to start.<br>
<br>
If the call is to a function defined in the same
module - there's no IR representation for the
call site - the CallInst refers the
llvm::Function that in turn refers to the
definition DISubprogram. So the DWARF emission
code looks that up to create the call site
description.<br>
<br>
But if it's a function that /isn't/ defined in
the same module, the declaration DISubprogram is
created and attached to the DICompileUnit's
retainedTypes list to make sure it doesn't get
dropped (because it's not referenced from
anywhere else in the IR/metadata/debug info)
and... it looks like I misunderstood.<br>
<br>
No, the declaration DISubprogram /is/ attached
to the llvm::Function via its !dbg attachment,
it's just the IR syntax wasn't what I was
expecting:<br>
<br>
For a definition llvm::Function, the !dbg is
rendered at the end of the line:<br>
<div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span style="font-variant-ligatures:no-common-ligatures">define dso_local void
@_Z2f2v() local_unnamed_addr #</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span style="font-variant-ligatures:no-common-ligatures"><span> </span>!dbg !</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">11</span><span style="font-variant-ligatures:no-common-ligatures"><span> </span>{</span></div>
<br>
But for a declaration llvm::Function, the !dbg
is rendered nearer the beginning:<br>
<div style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span style="font-variant-ligatures:no-common-ligatures">declare !dbg !</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">4</span><span style="font-variant-ligatures:no-common-ligatures"><span> </span>dso_local
void @_Z2f1v() local_unnamed_addr #</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span></div>
<br>
Quirky, but OK.<br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>What happens in an llvm-link when a forward
declaration and a definition for the same function are
imported from different llvm::Modules? Are the
Function forward decl and its DISubprogram RAUWed with
the respective definitions?</div>
</div>
</div>
</blockquote>
<div><br>
I believe so.<br>
<br>
lto1.ll:<br>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">declare
!dbg </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);background-color:rgb(224,228,9)">!4</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">
dso_local void @_Z2f1v() local_unnamed_addr #</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span style="font-variant-ligatures:no-common-ligatures">...</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DICompileUnit(language:
DW_LANG_C_plus_plus_14, file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
producer: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"clang
version 11.0.0 "</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
isOptimized: true, runtimeVersion: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
emissionKind: FullDebug, enums: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
retainedTypes: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">3</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
splitDebugInlining: false, nameTableKind: None)<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(251,0,255);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">
= !DIFile(filename: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">"lto1.cpp"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">,
...</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">3</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> = !{</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);background-color:rgb(224,228,9)">!4</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">}<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);background-color:rgb(224,228,9)">!4</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures"> =
!DISubprogram(</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(232,235,20)">name</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"f1"</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
linkageName: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"_Z2f1v"</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
scope: !</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
file: !</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
line: </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
type: !</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">5</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">,
flags: DIFlagPrototyped, spFlags: DISPFlagOptimized,
retainedNodes: !</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<br>
lto2.ll:<br>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">define
dso_local void @_Z2f1v() local_unnamed_addr #</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> !dbg
!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">7</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> {<br>
...<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DICompileUnit(language:
DW_LANG_C_plus_plus_14, file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
producer: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"clang
version 11.0.0 "</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
isOptimized: true, runtimeVersion: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
emissionKind: FullDebug, enums: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
splitDebugInlining: false, nameTableKind: None)</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(251,0,255);background-color:rgba(0,0,0,0.85)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">!</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">
= !DIFile(filename: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">"lto2.cpp"</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">,
...</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">7</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DISubprogram(</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(232,235,20)">name</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"f1"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
linkageName: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"_Z2f1v"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
scope: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
line: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
type: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">8</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
scopeLine: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
flags: DIFlagPrototyped | DIFlagAllCallsDescribed,
spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
retainedNodes: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<br>
lto1.ll + lto2.ll:<br>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">define
dso_local void @_Z2f1v() local_unnamed_addr #</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> !dbg
!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">18</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> {<br>
...<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DICompileUnit(language:
DW_LANG_C_plus_plus_14, file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
producer: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"clang
version 11.0.0 "</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
isOptimized: true, runtimeVersion: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
emissionKind: FullDebug, enums: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
retainedTypes: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">3</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
splitDebugInlining: false, nameTableKind: None)</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(251,0,255);background-color:rgba(0,0,0,0.85)"><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">!</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">
= !DIFile(filename: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">"lto1.cpp"</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">,
...</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(242,242,242)">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">3</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> = !{</span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);background-color:rgb(224,228,9)">!4</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">}</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0);background-color:rgb(224,228,9)">!4</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
!DISubprogram(</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(232,235,20)">name</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"f1"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
linkageName: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"_Z2f1v"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
scope: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
line: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
type: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">5</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
flags: DIFlagPrototyped, spFlags: DISPFlagOptimized,
retainedNodes: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">7</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DICompileUnit(language:
DW_LANG_C_plus_plus_14, file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">8</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
producer: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"clang
version 11.0.0 "</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
isOptimized: true, runtimeVersion: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">0</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
emissionKind: FullDebug, enums: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
splitDebugInlining: false, nameTableKind: None)<br>
</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-stretch:normal;font-size:10px;line-height:normal;font-family:Monaco;color:rgb(242,242,242);background-color:rgba(0,0,0,0.85)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">!</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">18</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> =
distinct !DISubprogram(</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(232,235,20)">name</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"f1"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
linkageName: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">"_Z2f1v"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
scope: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">8</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
file: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">8</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
line: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
type: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">5</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
scopeLine: </span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">1</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
flags: DIFlagPrototyped | DIFlagAllCallsDescribed,
spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">7</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">,
retainedNodes: !</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(251,0,255)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)<br>
<br>
</span></p>
<br>
In the linked IR there's no other referenec to !4 other than
the one via the retainedTypes list - and so far as I can
see, the only place that iterates retainedTypes <br>
seems to be here: <a href="https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L882" moz-do-not-send="true">https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/AsmPrinter/DwarfDebug.cpp#L882</a>
- so I'm /pretty/ sure that's dead IR that nothing's looking
at anymore.</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div style="overflow-wrap: break-word;">
<div><br>
<blockquote type="cite">
<div>
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div><br>
OK, so now my question becomes "why are these in
the retainedTypes list at all"? Because it looks
like they're attached in entirely the
good/proper/appropriate way that will keep them
when we need them, drop them when we don't,
merge them in LTO as desired, etc. (except for
them being in the retainedTypes list - which
thwarts a bunch of that and doesn't seem to be
providing any value that I can see - nothing
iterates the retainedTypes list expecting to
find them there/look for them there, so they're
just kept alive for no use I can see)<br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<br>
<br>
<blockquote type="cite">
<div>
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<div><br>
</div>
<div>-- adrian</div>
<br>
<blockquote type="cite">
<div>
<div>
<div><br>
</div>
<div>My own thoughts: as I understand
it, if a function ends up dead (all
call sites to it are optimized out),
we won’t emit a DW_TAG_call_site
that references the function, and so
we won't emit unnecessary
declaration subprograms. This is
demonstrated in the LTO case in
llvm/test/DebugInfo/X86/lto-cross-cu-call-origin-ref.ll
(added in<span> </span><a href="https://reviews.llvm.org/D70350" target="_blank" moz-do-not-send="true">https://reviews.llvm.org/D70350</a>),
where the declaration subprograms
for func_from_b, noinline_func_in_a,
and always_inline_helper_in_a_that_calls_foo are elided. The same test
demonstrates that llvm can emit
cross-CU references to definition
subprograms within DW_TAG_call_site.
However, all of this just pertains
to the final DWARF. There may still
be some cost (in terms of metadata)
to preserving a declaration
subprogram throughout optimization
when all references to the
declaration are removed. Before
changing the representation, it’d be
helpful to measure how much it costs
(either in terms of compile-time, or
metadata size) to keep unreferenced
declaration subprograms around (say,
on a stage2 clang build).</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div>I'm not too interested in the cost, just the
principle really - why are they tehre? (I'm ever
more confused why they're there now that I see
they are attached to the llvm::Function's !dbg,
and that I can't find any code using their
presence in RetainedTypes) <br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<blockquote type="cite">
<div>
<div>
<div><br>
</div>
<div>As for why declaration
subprograms are inserted into a CU’s
retainedTypes field in the first
place: I don’t think this was
intentionally changed just for
DW_TAG_call_site support. Adrian
(cc’d) changed EmitFunctionDecl to
retain declaration subprograms in
r266445, and the new code path which
calls into EmitFunctionDecl adopted
the same behavior. (Hopefully that
clears up some of the history,
that’s not to say that it’s not
worth revisiting.)</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div>Ah, OK, so thanks for pointing to the
revision that introduced this. <br>
<br>
"commit e76bda544bbf52d9ff3b55e6018b494a1e6bbc00<br>
Author: Adrian Prantl <<a href="mailto:aprantl@apple.com" target="_blank" moz-do-not-send="true">aprantl@apple.com</a>><br>
Date: Fri Apr 15 15:55:45 2016 +0000<br>
<br>
Update to match LLVM changes for PR27284.<br>
(Reverse the ownership between DICompileUnit
and DISubprogram.)<br>
<span> </span><br>
<span> </span><a href="http://reviews.llvm.org/D19034" target="_blank" moz-do-not-send="true">http://reviews.llvm.org/D19034</a><br>
<<a moz-do-not-send="true">rdar://problem/25256815</a>><br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>For reference, the title of that ticket was
"[ThinLTO] Remove list of subprograms from
DICompileUnit"</div>
<br>
<blockquote type="cite">
<div>
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div> <span> </span><br>
llvm-svn: 266445"<br>
<br>
Adrian - do you have any context on why this
change ended up adding declaration
DISubprogram's to the retained types list?
(perhaps something discussed in the rdar?) It
doesn't look like the clang part of this was
reviewed.<br>
<br>
I think it's probably best to just remove it
& see if anything breaks - I don't see
anything that depends on it, at least at a
cursory glance.<br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>I wouldn't be opposed to trying this. It looks like
this may have been a transitional necessity and is no
longer needed.</div>
<div><br>
</div>
<div>-- adrian</div>
<br>
<blockquote type="cite">
<div>
<div class="gmail_quote" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none">
<div><br>
</div>
<blockquote class="gmail_quote" style="margin:0px
0px 0px 0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div>
<div>
<blockquote type="cite">
<div>
<div>
<div>best,</div>
<div>vedant</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
</div>
</blockquote>
</body>
</html>