freeing alloca'd variables before function exits

Hi,

In my llvm code I want to create some function calls. The function prototype is as follows:

int memoize ( char *function_name,
int *int_params, unsigned num_ints,
double *double_params, unsigned num_doubles)

In order to create these calls I do the following for example:

%88 = alloca [7 x i8]
store volatile [7 x i8] c"ORACLE\00", [7 x i8]* %88
%89 = getelementptr [7 x i8]* %88, i32 0, i32 0

%90 = alloca [1 x i32]
%91 = getelementptr inbounds [1 x i32]* %90, i32 0, i32 0
store volatile i32 3, i32* %91
%92 = getelementptr inbounds [1 x i32]* %90, i32 0, i32 0

%93 = alloca [0 x double]
%94 = getelementptr inbounds [0 x double]* %93, i32 0, i32 0

%95 = call i32 @memoize(i8* %89, i32* %92, i32 1, double* %94, i32 0)

This works, but I need to create many such function calls in one “parent” function, and eventually all the “alloca” instructions add up to overflowing the stack. So I have two questions:

a) Is it possible to create the arrays for my function call args without using the alloca instruction (maybe use heap)?
b) If not, can I release those alloca’d spaces during the function execution and not after it returns?

Thanks,
Ali

We treat allocas in the entry block as normal stack space and allocas outside the entry block as similar to C alloca calls. You likely want all of your local variables allocated in the entry block. It should help.

Stack colouring should be able to reuse the same stack space, if the live ranges of the pointers don’t overlap. But I don’t think anyone has built a general solution for alloca’d space.

Stack colouring should be able to reuse the same stack space, if the live ranges of the pointers don’t overlap. But I don’t think anyone has built a general solution for alloca’d space.

For stack coloring to work you would need to mark them with lifetime markers.