[llvm-dev] Preventing LLVM from optimizing out a variable
Jameson Nash via llvm-dev
llvm-dev at lists.llvm.org
Mon Jul 11 13:50:39 PDT 2016
If you mark that store as `volatile`, then LLVM should be unable to remove
it or the alloca (while still being free to do load-store forwarding, if it
deems that profitable), which should usually also keep the debug info
intact as a side-benefit.
On Mon, Jul 11, 2016 at 4:45 PM David Jones via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> I have code along the lines of:
>
> void foo(struct A *a) {
> struct B *b = a->m_B;
> /* do a whole bunch of things with b */
> }
>
> When LLVM generates code for this, it sees that after initializing b, a is
> no longer used, so it is optimized out.
>
> 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.
>
> Is there any way of marking a Value* as "precious", not to be optimized
> out?
>
> 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:
>
> define void @foo(%A*) {
> %2 = alloca %A*
> store %0, %2
> call void @llvm.dbg.declare(metadata %A* %2, metadata !101, metadata
> !100), !dbg ...
>
> !100 = !DIExpression()
> !101 = !DILocalVariable(...)
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160711/b0c9e312/attachment.html>
More information about the llvm-dev
mailing list