Ali Javadi
2013-Nov-03 20:00 UTC
[LLVMdev] 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131103/46b48a2c/attachment.html>
Eric Christopher
2013-Nov-03 23:24 UTC
[LLVMdev] freeing alloca'd variables before function exits
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. On Nov 3, 2013 12:04 PM, "Ali Javadi" <aj14889 at yahoo.com> wrote:> 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 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131103/b828a394/attachment.html>
Jeremy Lakeman
2013-Nov-04 00:54 UTC
[LLVMdev] freeing alloca'd variables before function exits
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. On Mon, Nov 4, 2013 at 6:30 AM, Ali Javadi <aj14889 at yahoo.com> wrote:> 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 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131104/5b41d79d/attachment.html>
Nadav Rotem
2013-Nov-04 04:41 UTC
[LLVMdev] freeing alloca'd variables before function exits
On Nov 3, 2013, at 4:54 PM, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote:> 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.> > On Mon, Nov 4, 2013 at 6:30 AM, Ali Javadi <aj14889 at yahoo.com> wrote: > 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 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131103/935d4d93/attachment.html>