[llvm-dev] `free` counterpart to `alloca`, or way to lift to function home
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Sun Mar 18 03:49:14 PDT 2018
On 18 March 2018 at 09:46, edA-qa mort-ora-y via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I'm curious also, since this actually allocates each time in the loop,
> is there a way to say the stack allocations are no longer required and
> return to an early stack position? My `alloca` will always be in order,
> in a tree, thus it'd be safe to return to an early allocation point.
As usual, Clang knows the answer:
$ cat tmp.c
void foo(int *);
void bar(int n) {
for (int i = 0; i < n; ++i) {
int arr[i];
foo(arr);
}
}
$ clang tmp.c -S -o- -emit-llvm -Os
[...]
define void @bar(i32) local_unnamed_addr #0 {
[...]
%8 = call i8* @llvm.stacksave()
%9 = alloca i32, i64 %7, align 16
call void @foo(i32* nonnull %9) #3
call void @llvm.stackrestore(i8* %8)
[...]
}
Cheers.
Tim.
More information about the llvm-dev
mailing list