[LLVMdev] how to code a loop in llvm assembly

Simon Burton simon at arrowtheory.com
Sat Apr 15 06:44:48 PDT 2006


Hi,

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 ?

int %count(int %n) {
EntryBlock:
  %cond = seteq int %n, 0
  br bool %cond, label %Exit, label %Next
Next:
; how to decrement n ?
  %new_n = sub int %n, 1
  br label %EntryBlock
Exit:
  ret int 0
}

I guess I could malloc a variable and use store/load. Is that the right way ?

Also the above code is invalid:
Entry block to function must not have predecessors!
label %EntryBlock
Broken module found, compilation aborted!

thanks for any hints,

Simon.

-- 
Simon Burton, B.Sc.
Licensed PO Box 8066
ANU Canberra 2601
Australia
Ph. 61 02 6249 6940
http://arrowtheory.com 




More information about the llvm-dev mailing list