[llvm-dev] alloca function in llvm

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 29 09:52:40 PDT 2017


On 29 Aug 2017, at 17:30, Samaneh Berenjian via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> I know that we use alloca method in llvm (llvmlite) to statically allocate a stack slot for size values of type typ. However, if I want to deallocate and free the memory from the allocated stack, there is no free method. Does any one know how can I simply deallocate the allocated stack in llvm or llvmlite?

I have no idea about llvmlite and any questions related to it are better addressed to the llvmlite mailing list.

In LLVM, the alloca instruction allocates space in the current stack frame.  This space is (as you would expect in any language with normal stack discipline) freed automatically when the function returns.  If you have dynamic allocas that are reached more than once in a function (for example, in a loop), then you can use the stacksave and stackrestore intrinsics.  The stackrestore intrinsic will reset the stack to a value from a corresponding stacksave, effectively freeing all allocas that occur in the middle.  You cannot free individual allocas in any other order (it would not make sense to do so, because they are stack allocations).

David



More information about the llvm-dev mailing list