[llvm-dev] How to actively reclaim stack memory

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Thu Dec 15 02:01:05 PST 2016


On 15 Dec 2016, at 07:26, haifeng.qin at wellintech.com via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> For help:
> 
> for loop lead to stack overflow, want to actively reclaim stack memory of alloc instruction.
> 
> How to actively reclaim stack memory ?

This sounds as if you’re putting the alloca inside the loop, not in the entry basic block and reusing it.  If you need the same amount of storage for each loop iteration, then you should put the alloca in the entry basic block and use the lifetime start / stop intrinsics in the loop to mark reuse of the memory.  If you need different sized allocations, then you will need to use the stack save and stack restore intrinsics inside the loop to reset the stack allocations in the loop.

David



More information about the llvm-dev mailing list