[LLVMdev] Alloca Outside of Entry Block

Mike Stump mrs at apple.com
Wed Aug 13 11:25:19 PDT 2008

On Aug 13, 2008, at 11:19 AM, Dale Johannesen wrote:
> This is the right answer for C's alloca.  The question probably  
> referred to LLVM IR's alloca, however.

Is there a difference?

The code I gave produced the below with llvm-gcc.  It appears to me to  
use llvm's alloca in other than the entry block, no?

; ModuleID = 'ta.c'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32- 
target triple = "i386-apple-darwin9"
@vp = common global i8* null		; <i8**> [#uses=2]

define i8* @bar(i32 %i) nounwind  {
	%i_addr = alloca i32		; <i32*> [#uses=3]
	%retval = alloca i8*		; <i8**> [#uses=1]
	%"alloca point" = bitcast i32 0 to i32		; <i32> [#uses=0]
	store i32 %i, i32* %i_addr
	%tmp = load i32* %i_addr, align 4		; <i32> [#uses=1]
	%tmp1 = icmp ne i32 %tmp, 0		; <i1> [#uses=1]
	%tmp12 = zext i1 %tmp1 to i8		; <i8> [#uses=1]
	%toBool = icmp ne i8 %tmp12, 0		; <i1> [#uses=1]
	br i1 %toBool, label %bb, label %bb8

bb:		; preds = %entry
	%tmp3 = load i32* %i_addr, align 4		; <i32> [#uses=1]
	%tmp4 = call i32 @foo( i32 %tmp3 ) nounwind 		; <i32> [#uses=1]
	%tmp6 = alloca i8, i32 %tmp4		; <i8*> [#uses=1]
	store i8* %tmp6, i8** @vp, align 4
	br label %bb8

bb8:		; preds = %bb, %entry
	%tmp9 = load i8** @vp, align 4		; <i8*> [#uses=1]
	call void @watch( i8* %tmp9 ) nounwind
	br label %return

return:		; preds = %bb8
	%retval11 = load i8** %retval		; <i8*> [#uses=1]
	ret i8* %retval11

declare i32 @foo(i32)

declare void @watch(i8*)

More information about the llvm-dev mailing list