[llvm-dev] Getting actual value of local variable

mats petersson via llvm-dev llvm-dev at lists.llvm.org
Fri Jul 7 03:28:36 PDT 2017


Hi Rasha,

What are you actually trying to do?

This is not something that can be done trivially. Obviously for this
particular code-sequence:

   {
     int a = 0;
     a++;
     printf("a=%d", a);
   }

the compiler may well optimize it to `printf("a=%d\n", 1)` - and you could
get the value from the constant integer that is in the IR after
optimisations.

If we ignore such trivial cases, and look at REAL code, that actually does
things:

    {
        int a;
        a = rand() % 11;
        if (a < 5)
            a++;
        else
            a--;
        printf("a=%d", a);
    }

This can't be understood by the compiler, and it's impossible to get the
value of `a`, other than by storing the value with a store instruction [you
need a defined place to store it, however, which makes life a bit
difficult].

If you have a specific use-case that you want this for, perhaps there is
something "better", so perhaps if you can explain what you are actually
trying to do, maybe someone can give you a better suggestion - no promises
tho'. (For example, debuggers are able to figure out, through information
stored in the debug info, how to get to a particular variable's value - not
100% of cases, even after optimizations - but some opts some do crazy
things like invert loop counts to save an instruction, which will make this
break tho')

--
Mats



On 6 July 2017 at 21:29, Rasha Omar via llvm-dev <llvm-dev at lists.llvm.org>
wrote:

>
> If I have this example:
>
> int a=0, b=0;
>
> a and b are local variables and make any modifications in their values,
> such as:
>
> a++;
> b++;
>
> I need to get the value in this line code during running MCJIT.
>
> I mean by value not Value class, but the actual integer or any type value.
>
>
>
>
> Sent from my iPhone
>
> _______________________________________________
> 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/20170707/84c3ca8f/attachment.html>


More information about the llvm-dev mailing list