Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the %"alloca point" line which occurs in llvm code?

Tags:

llvm

alloca

I've been looking at some LLVM assembly produced by llvm-gcc lately and I've noticed a recurring statement of which I'm not sure its purpose.

For example, the following C program:

int main(void)
{
   void (*f)(void) = (0x21332);
   f();
}

When compiled with "llvm-gcc -emit-llvm -S" will produce the following code (irrelevant parts removed):

define i32 @main() nounwind {
entry:
   %retval = alloca i32     ; <i32*> [#uses=1]
   %f = alloca void ()*     ; <void ()**> [#uses=2]
   %"alloca point" = bitcast i32 0 to i32       ; <i32> [#uses=0]
   store void ()* inttoptr (i64 135986 to void ()*), void ()** %f, align 4
   %0 = load void ()** %f, align 4      ; <void ()*> [#uses=1]
   call void %0() nounwind
   br label %return

I'm interested in the purpose of the line:

%"alloca point" = bitcast i32 0 to i32      ; <i32> [#uses=0]

Doesn't seem to do anything as the variable it assigns to is never used again and the bitcast itself is pointless. All I can think of is that its inserted really as a nop for later code generation / analysis purposes, indicating interesting parts of the code.

like image 390
David Terei Avatar asked Aug 21 '09 03:08

David Terei


1 Answers

From the llvm-gcc source: gcc/llvm-convert.cpp, it's just used as a helper Value* and it will be removed by a dead instruction elimination pass.

// Create a dummy instruction in the entry block as a marker to insert new
// alloc instructions before.  It doesn't matter what this instruction is,
// it is dead.  This allows us to insert allocas in order without having to
// scan for an insertion point. Use BitCast for int -> int
like image 73
Nathan Howell Avatar answered Nov 06 '22 23:11

Nathan Howell