<div dir="ltr">Hi,<br><br><div>Once you have a Module and Function created, which Kaleidoscope can show you how to do, the important thing is to understand what the LLVM IR you want to create will look like. You can do this by writing a trivial function with a loop in Clang and running:</div><div><br></div><div>clang -O0 -emit-llvm -S -o - my-trivial-program.c</div><div><br></div><div>Clang, like any frontend, produces deliberately poor code and expects LLVM to clean it up - if you want more cleaned up code use -O2.</div><div><br></div><div>The IR reference is here: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_LangRef.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ixjoYvd7eynlmwP6GKkckIt16L1WqC9N5LwEXm5Jxug&s=4_kA7I59Pr31yqLvAlJYpYpbV8jYQsy8OkJxG_n_3FE&e=">http://llvm.org/docs/LangRef.html</a></div><div>The IRBuilder reference, which is the object you use to build up some IR programatically, is here: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1IRBuilder.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ixjoYvd7eynlmwP6GKkckIt16L1WqC9N5LwEXm5Jxug&s=opAd-HqShgQlgwsmdfMFtI4f1VR5Amv8RKOkKie3x-8&e=">http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilder.html</a> (and <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_doxygen_html_classllvm-5F1-5F1IRBuilderBase.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ixjoYvd7eynlmwP6GKkckIt16L1WqC9N5LwEXm5Jxug&s=TX1TaxPPlpg7kfxqGCjmAGcBCU7q3m5pljWrdFjx1tQ&e=">http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilderBase.html</a> )</div><div><br></div><div>To create a simple loop you will need to create at least two blocks: the loop header, and loop body. The header will perform your exit test and conditionally exit the loop. The body will do all your work and then increment/decrement the loop counter.</div><div><br></div><div>Best of luck,</div><div><br></div><div>James</div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, 9 Jul 2015 at 15:47 <<a href="mailto:deco33000@yandex.com">deco33000@yandex.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Thanks James,</div><div> </div><div>Kaleidoscope seems to differ in the sense that I cannot really understand how to create, say, a loop. It all looks like very complicated (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_docs_tutorial_LangImpl3.html&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ixjoYvd7eynlmwP6GKkckIt16L1WqC9N5LwEXm5Jxug&s=6p1dYZQgFL8FsJWmpZQZ_01fgzcZ1KoaHTrqRcCxLIQ&e=" target="_blank">http://llvm.org/docs/tutorial/LangImpl3.html</a>)</div><div> </div><div>llvm is new to me.</div><div> </div><div>it is pretty basic, but the tutorial page of the libgccjit is very helpful in that regard (how to create a function, a condition, a loop..)</div><div> </div><div>I will keep doing my homework, but a bit of help is very welcome :)</div><div> </div><div>-- </div><div>Jog</div><div> </div>
</blockquote></div>