<div dir="ltr"><div><font face="arial, helvetica, sans-serif">We've used this in the past:</font></div><font face="monospace, monospace"><div><font face="monospace, monospace"><br></font></div>#define KEEP_ALIVE(t) asm volatile("" : : "X"(t))</font><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 11, 2016 at 1:45 PM, David Jones via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>I have code along the lines of:<br><br></div>void foo(struct A *a) {<br></div>    struct B *b = a->m_B;<br></div>    /* do a whole bunch of things with b */<br>}<br><br></div>When LLVM generates code for this, it sees that after initializing b, a is no longer used, so it is optimized out.<br><br></div>Unfortunately, for debug, I'd like the value for a to be kept around, if only so that I can determine the value of b and go from there.  I don't care if a is spilled to the stack and never referenced thereafter, as long as it is available for debug.<br><br></div>Is there any way of marking a Value* as "precious", not to be optimized out?<br><br></div>Simply storing a to a local variable (result of alloca in the first basic block) and calling llvm.dbg.declare does not appear to be sufficient:<br><br></div>define void @foo(%A*) {<br></div>    %2 = alloca %A*<br></div>    store %0, %2<br></div>    call void @llvm.dbg.declare(metadata %A* %2, metadata !101, metadata !100), !dbg ...<br><br><div><div><div><div>!100 = !DIExpression()<br></div><div>!101 = !DILocalVariable(...)<br><br></div><div><br></div></div></div></div></div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>