<div dir="ltr"><div dir="ltr">Thanks! </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 27, 2020 at 6:05 PM Teresa Johnson <<a href="mailto:tejohnson@google.com">tejohnson@google.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 dir="ltr">By default even regular LTO now has module summaries (like the kind used for ThinLTO). LTO will then run index based dead symbol analysis here:<div><a href="http://llvm-cs.pcc.me.uk/lib/LTO/LTO.cpp#923" target="_blank">http://llvm-cs.pcc.me.uk/lib/LTO/LTO.cpp#923</a>. Then when linkRegularLTO is called here: <a href="http://llvm-cs.pcc.me.uk/lib/LTO/LTO.cpp#935" target="_blank">http://llvm-cs.pcc.me.uk/lib/LTO/LTO.cpp#935</a>, it indicates that the index should be consulted for liveness, and that routine skips even adding the dead symbols to the Keep set. So they never make it into the combined module.<br></div><div><br></div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jan 27, 2020 at 5:43 PM Gábor Horváth via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</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 dir="ltr">Hi!<div><br></div><div>LLVM newbie here, I was mainly working on the frontend so far. We had a small hackathon project idea to piggyback on LTO to detect dead code (unused functions). The basic idea is to compile the code for every target and dump the removed functions. Intersect the function symbol names for each target and those functions should be safe to remove from the source code (unless there were some configuration that was not compiled). Is this reasonable?</div><div><br></div><div>I started to play around with some toy examples and got stuck on the very beginning not being able to figure out where the unused functions are actually getting removed.<br><br>Here is what I did:<br>tu1.cpp:<br><font face="monospace">int unused(int a);<br>int probably_inlined(int a);<br>int main(int argc, const char *argv[]) {<br>  return probably_inlined(argc);<br>}</font><br><br>tu2.cpp:<br><font face="monospace">int unused(int a) {<br>  return a + 1;<br>}<br>int probably_inlined(int a) {<br>  return a + 2;<br>}</font><br></div><div><br>I produced two object files with bitcode:<br><font face="monospace">clang -c -flto tu1.cpp -o tu1.o</font><br></div><div><br></div><div>And I run LTO and attempted to dump the IR before each pass:<br><font face="monospace">clang -O2 -Wl,-mllvm -Wl,-print-before-all tu1.o tu2.o -o optimized</font><br></div><div><br>In my dumps I saw the function <font face="monospace">unused</font> removed even before the first pass. Where did that happen? I tried to invoke <font face="monospace">llvm-link</font> manually and that did not remove <font face="monospace">unused</font>.</div><div><br></div><div>I also tried to dump optimization remarks and was no trace of a function being removed (I only saw a function being inlined).<br><br>Thanks in advance,<br>Gabor</div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top:2px solid rgb(213,15,37)">Teresa Johnson |</td><td nowrap style="border-top:2px solid rgb(51,105,232)"> Software Engineer |</td><td nowrap style="border-top:2px solid rgb(0,153,57)"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top:2px solid rgb(238,178,17)"><br></td></tr></tbody></table></span></div></div></div>
</blockquote></div></div>