[LLVMdev] all LLVM Instructions that may write to memory -- other than StoreInst?

Chuck Zhao
Fri, 21 Jan 2011 20:50:31 -0000

I need to figure out all LLVM Instructions that may write to memory.

In http://llvm.org/docs/tutorial/OCamlLangImpl7.html, it mentions that
"In LLVM, all memory accesses are explicit with load/store instructions,
and it is carefully designed not to have (or need) an "address-of"
operator."

I take this as "StoreInst is the only one that writes to memory".

However, this doesn't seem to be enough.

Consider:
...
int a, b, d;
d = a + b;
...

The above code is turned into LLVM IR:

   %0 = load i32* @a, align 4
   %1 = load i32* @b, align 4
   %2 = add nsw i32 %1, %0
   store i32 %2, i32* @d, align 4

Is it possible that temps such as %0, %1 and/or %2 will NOT being register
allocated later in the compilation stage, and thus left in memory?

The above code, when converted back to C level, looks like this:
...
   unsigned int llvm_cbe_tmp__6;
   unsigned int llvm_cbe_tmp__7;
   unsigned int llvm_cbe_tmp__8;
   unsigned int llvm_cbe_tmp__9;

   llvm_cbe_tmp__6 = *(&a);
   llvm_cbe_tmp__7 = *(&b);
   llvm_cbe_tmp__8 = ((unsigned int )(((unsigned int )llvm_cbe_tmp__7) +
((unsigned int )llvm_cbe_tmp__6)));
   *(&d) = llvm_cbe_tmp__8;
   llvm_cbe_tmp__9 =  /*tail*/ printf(((&_OC_str.array[((signed int )0u)])),
llvm_cbe_tmp__8);
...

It seems the compiler-generated temps are _actually_ left on stack, and writes
to them are actually writes to stack memory (via load, add, ...).



I am confused here.
Could somebody help to clarify it?

Thank you

Chuck



-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20110121/a53772e3/attachment.html>