<div dir="ltr">Hi Tobias, <br><br>Thanks for your response! I was doing this as well, but it turns out adding  __attribute__((used)) prevents the function itself from being removed, but does not prevent <i>all calls to the function</i> from being removed, which is what I was after. I fixed it by changing some IR that was resulting in unconditionally dead branches ("br i1 false"). <br><br>Best, <br>Shishir</div><img src="https://my-email-signature.link/signature.gif?u=452460&e=100359152&v=892702a25a762388c6692cafe5220f39573ceaca540dbd7b14a0ac74b589646a" style="width:2px;max-height:0;overflow:hidden"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jun 10, 2020 at 1:04 AM Tobias Hieta <<a href="mailto:tobias@plexapp.com">tobias@plexapp.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">I don't know about calling the internal IR stuff directly - but when I ran into this in C code I added  __attribute__((used)) to the function to not have it be optimized out.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 9, 2020 at 8:01 PM Shishir V Jessu 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"><div dir="ltr">Hello, <br><br>I am adding function calls to an LLVM link-time optimization (LTO) pass, using the <font face="monospace">IRBuilder::CreateCall </font>method. I want these calls to remain in the final x86 binary at any optimization level, but on levels -O2 and -O3, some of these calls are being optimized out. <br><br>So far, I've tried adding each function in the program (excluding LLVM intrinsics) to the <font face="monospace">llvm.used </font>set, and I've also set <font face="monospace">noinline</font> and <font face="monospace">optnone</font> attributes on each function in the program. This has allowed me to retain <i>most, </i>but not all, of the calls I've added with <font face="monospace">IRBuilder::CreateCall. </font><br><font face="arial, sans-serif"><br>Furthermore, I have confirmed that all the calls I've created are present in the LLVM IR that results immediately after my pass. Thus, I know some future LTO pass is optimizing out some of these calls. <br><br>How can I ensure that none of the calls I add are optimized out? Thanks for your help!<br><br>Best, <br>Shishir Jessu</font></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>
</blockquote></div>