What is the front end pattern?



<br>I find this pattern as below from <llvm-source-tree>/test/CodeGen/Mips/alloca.ll.<br>Do you know what front end pattern can be translated into this pattern alloca with variable argument %size as below? <br>Can some one help me? I am writing the llvm backend document --http://jonathan2251.github.com/lbd/index.html now.<br><br>%tmp1 = alloca i8, i32 %size, align 4 // has %size variable, not pattern, alloca i8, align 4<br><br>define i32 @twoalloca(i32 %size) nounwind {<br>entry:<br>...<br>? %tmp1 = alloca i8, i32 %size, align 4<br>}<br><br>Jonathan<br>

|

C's variable length arrays could generate something like this

E.g.:
void test (int size)
{
  char test[size];
}

Becomes:
$ clang -emit-llvm -S test.c -o -
; ModuleID = 'test.c'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"
target triple = "i386-pc-linux-gnu"

define void @test(i32 %size) nounwind {
entry:
   %size.addr = alloca i32, align 4
   %saved_stack = alloca i8*
   store i32 %size, i32* %size.addr, align 4
   %0 = load i32* %size.addr, align 4
   %1 = call i8* @llvm.stacksave()
   store i8* %1, i8** %saved_stack
   %vla = alloca i8, i32 %0, align 1
   %2 = load i8** %saved_stack
   call void @llvm.stackrestore(i8* %2)
   ret void
}

declare i8* @llvm.stacksave() nounwind

declare void @llvm.stackrestore(i8*) nounwind

Which has %vla = alloca i8, i32 %0, align 1

Regards,
  Roel