<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">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><img src="https://my-email-signature.link/signature.gif?u=452460&e=99778492&v=56263c4e7d01f860d3efa1adf5833f2b2bb5c495c2b335518840cfe3a9e00630" style="width: 2px; max-height: 0px; overflow: hidden;">
_______________________________________________<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>