<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Yuri, Duncan,<br>
    <br>
    Thank you for the replies.<br>
    <br>
    I tried to do a GEP() on %0. The execution asserted, saying some
    type mismatching.<br>
    <br>
    I agree with Duncan, Compiler generated temporaries (%0) are neither
    local or global variables, they are actually virtual registers who
    don't have address, no types, while the size is determined by the
    operands of the instruction (E.g., add i32 has a result size of i32,
    while add i16 has a result size of i16).<br>
    <br>
    <pre wrap=""><font color="#ff0000">// Original C code:
void foo(int x, int y){
  volatile int z;
  z = x + y;
  printf("val : %d\n", z);
}
</font></pre>
    <br>
    and its generated LLVM IR:<br>
    <pre wrap=""><font color="#006600">// LLVM IR Code generated from the C code:
define void @foo(i32 %x, i32 %y) nounwind noinline {
entry:
  %z = alloca i32, align 4
 <font color="#ff0000"> %0 = add nsw i32 %y, %x</font>
  volatile store i32 %0, i32* %z, align 4
  %1 = volatile load i32* %z, align 4
  %2 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([10 x i8]* @.str, i32 0, i32 0), i32 %1) nounwind
  ret void
}</font>
</pre>
    <br>
    By piping it to the C Backend, I get<br>
    <pre wrap=""><font color="#993399">// C Code generated via the C Backend:
void foo(unsigned int llvm_cbe_x, unsigned int llvm_cbe_y) {
  unsigned int llvm_cbe_z;    /* Address-exposed local */
  unsigned int llvm_cbe_tmp__1;
  unsigned int llvm_cbe_tmp__2;

 <font color="#ff0000"> *((unsigned int volatile*)(&llvm_cbe_z)) = (((unsigned int )(((unsigned int )llvm_cbe_y) + ((unsigned int )llvm_cbe_x))));</font>
  llvm_cbe_tmp__1 = *((unsigned int volatile*)(&llvm_cbe_z));
  llvm_cbe_tmp__2 = printf(((&_OC_str.array[((signed int )0u)])), llvm_cbe_tmp__1);
  return;
}</font></pre>
    <br>
    Motivated by the C Backend, I think what I can do is to generate a
    local (stack) variable and store the %0 into it.<br>
    E.g.:<br>
    <pre wrap=""><font><font color="#006600"><font color="#330033"> </font><font color="#330033"> %0 = add nsw i32 %y, %x</font>
</font></font></pre>
    <font color="#000099">  
      %tmp_1 = alloca i32, align 4<br>
         store i32 %0, *i32 %tmp_1</font><br>
       ...<br>
    <br>
    Now, %tmp_1 is a local variable that holds the value of %0, has a
    known good size and can have its address taken.<br>
    <br>
    Does this make sense?<br>
    <br>
    <br>
    Thank you<br>
    <br>
    Chuck<br>
    <br>
    <br>
    On 2/22/2011 5:29 PM, Yuri wrote:
    <blockquote cite="mid:4D6438B9.9050405@rawbw.com" type="cite">On
      02/22/2011 14:01, Chuck Zhao wrote:
      <br>
      <blockquote type="cite">I wonder what is the right approach to
        obtain the address and size of
        <br>
        LLVM (compiler) generated temporaries?
        <br>
        <br>
        E.g.
        <br>
        <br>
        %0 = %x + %y
        <br>
        store i32 i0, i32 %z, align 4
        <br>
        <br>
        How can I get the address of %0 (which could be either a stack
        or heap
        <br>
        variable)?
        <br>
           </blockquote>
      <br>
      This is not possible since such value can also be in register.
      <br>
      <br>
      Yuri
      <br>
    </blockquote>
    <br>
  </body>
</html>