[LLVMdev] Little Problem about Variable memory allocating way in function

Duncan Sands baldrick at free.fr
Sat Apr 21 09:39:41 PDT 2012


Hi Jianfei Hu,

> As I want to generate code for  the varaible declaration, at first, I thought
> AllocInstruction()

AllocaInst

could implement this.
> However, the name "alloc" seems to allocate memory from heap memory.and the
> local variable in function should  stay at stack memory.

AllocaInst represents stack memory, not heap memory, much like the alloca
standard library function.

> In which way did llvm allocate memeory to AllocInstruction() ? Would the memory
> allocated by AllocInstruction() be recycled back?
> If not what is the ideal way to locate memory for local varaible in function?
>
> ps: I've tried llvm.org/demo <http://llvm.org/demo> to watch the IR code,
> however, it seems to optimize so much to eliminate any intermidate varaible.

You can disable optimization by choosing "None" for "Optimization level".

Ciao, Duncan.



More information about the llvm-dev mailing list