[LLVMdev] Variables and/or identifiers?

Vyacheslav Akhmechet coffeemug at gmail.com
Thu Apr 14 08:06:45 PDT 2005

I am having trouble understanding the relationship between LLVM
identifiers,  stack (alloca) and variables. In particular, when I need
to create a variable, what should I use? For instance, consider the
following C-like language snippet:

int f()
int i = rand();
if(i > 5)
  i = 1;
return i;

Ignoring optimizations, what should I use to represent 'i'? Online
demo gives the following output for the above code:

int %_Z1fv() {
%tmp.0 = call int %rand( ); <int> [#uses=2]
%tmp.2 = setgt int %tmp.0, 5; <bool> [#uses=1]
%retval = select bool %tmp.2, int 1, int %tmp.0; <int> [#uses=1]
ret int %retval

but this is optimized, 'i' (tmp.0) is never reassigned a value. It
looks like no matter how convoluted I get, I can't fool the optimizier
:) It seems to me that my compiler should allocate an integer on the
stack and use load/store instructions but this doesn't look like what
C front end does. Could someone please clarify the relationships of
above concepts?

More information about the llvm-dev mailing list