[LLVMdev] Re: how to code a loop in llvm assembly

Misha Brukman brukman at cs.uiuc.edu
Sat Apr 15 07:13:54 PDT 2006


On Sat, Apr 15, 2006 at 07:47:00AM +0200, Oscar Fuentes wrote:
> Simon Burton <simon at arrowtheory.com> writes:
> > I've read over the "LLVM Language Reference Manual"
> > a few times, and writing some ll code, but i'm stuck at
> > a very basic point. How to decrement a counter variable ?
[snip]
> > I guess I could malloc a variable and use store/load. Is that the right way ?
[snip]
> You need a phi node.

As others have pointed out, because LLVM is in SSA form, you will need
to use a phi node.  To see how it would be written, try using the demo
script as Oscar suggested, or you can do what you suggested (I would use
alloca instead of malloc, though I think either should work) and then
run it through "opt -mem2reg" to convert it to the phi-node form.

-- 
Misha Brukman :: http://misha.brukman.net




More information about the llvm-dev mailing list