Semion Prihodko
2011-Aug-26 14:23 UTC
[LLVMdev] Dynamically allocate and free variables in stack
Hi, guys. I have a beginner's question. The virtual machine I develop have instructions to dynamically allocate variable in stack and to free it (consistency of such instructions is checked before the actual jitting). To allocate memory in stack we have alloca IR instruction, but I didn't find any instruction to free it (such variables will be freed only when an enclosing function will return). This means that I have to create function for every stack allocation which is not convenient. Can you suggest me easier way to dynamically allocate and free variables in stack? Thanks. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110826/bed80c1f/attachment.html>
Reid Kleckner
2011-Aug-26 14:38 UTC
[LLVMdev] Dynamically allocate and free variables in stack
Use alloca to get enough memory for your stack and manage it yourself with an offset to the next free slot. This works if the amount of space can be determined statically, and is not expected to be large. Reid On Fri, Aug 26, 2011 at 10:23 AM, Semion Prihodko <semion.ababo at gmail.com> wrote:> Hi, guys. > I have a beginner's question. The virtual machine I develop have > instructions to dynamically allocate variable in stack and to free it > (consistency of such instructions is checked before the actual jitting). To > allocate memory in stack we have alloca IR instruction, but I didn't find > any instruction to free it (such variables will be freed only when an > enclosing function will return). This means that I have to create > function for every stack allocation which is not convenient. Can you suggest > me easier way to dynamically allocate and free variables in stack? Thanks. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >
Richard Osborne
2011-Aug-26 14:53 UTC
[LLVMdev] Dynamically allocate and free variables in stack
On 26/08/11 15:23, Semion Prihodko wrote:> Hi, guys. > > I have a beginner's question. The virtual machine I develop have > instructions to dynamically allocate variable in stack and to free it > (consistency of such instructions is checked before the actual > jitting). To allocate memory in stack we have alloca IR instruction, > but I didn't find any instruction to free it (such variables will be > freed only when an enclosing function will return). This means that I > have to create function for every stack allocation which is > not convenient. Can you suggest me easier way to dynamically allocate > and free variables in stack? Thanks.You can use the llvm.stacksave intrinsic to save the current stack pointer, allocate some memory on the stack with variable sized allocas and then restore the stack with the llvm.stackrestore intrinsic which effectively frees all the allocas executed inbetween. -- Richard Osborne | XMOS http://www.xmos.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110826/bbc2d7e0/attachment.html>
Apparently Analagous Threads
- [LLVMdev] LLVM: Cannot instantiate JIT execution engine
- [LLVMdev] LLVM: Cannot instantiate JIT execution engine
- [LLVMdev] LLVM: Cannot instantiate JIT execution engine
- [LLVMdev] LLVM: segfault while modifying a thread-local global variable
- [LLVMdev] LLVM: segfault while modifying a thread-local global variable