[LLVMdev] Emitting LLVM IR for control flow

Anton Skvorts anton.skvorts at gmail.com
Sun Nov 21 19:18:17 PST 2010


Hi
I'm following the excellent Kaleidoscope tutorial to learn how to build an
interpreter using LLVM. Apologize if this list is not the best place to post
beginner's questions. In Kaleidoscope 2.7 when I run

def binary : 1 (x y) y;

def testfor (x)
(for c = 1, c<2 in
x = x +1 ) :
x;

testfor(1)

unexpectadly get 3.000000 instead of 2.000000. This happens, I believe,
because the instruction

%faddtmp = fadd *double* %x1.0, 1.000000e+000 ; <*double*> [#uses=2]
is being generated before
%ltcmptmp = fcmp ult *double* %c.0, 2.000000e+000 ; <i1> [#uses=1]
br i1 %ltcmptmp, label %loop, label %afterloop

and therefore the loop body is emited first and only afterwards we determine
whether the loop should exit. I was wondering if this is the intended
behaviour, since the fibi(x) example in chapter 7 uses this extra loop to
return correct values for fibonacci numbers, or perhaps a known bug in
Kaleidoscope.

Any advice would be much apreciated
Anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20101122/def446bf/attachment.html>


More information about the llvm-dev mailing list