deco33000 at yandex.com
2015-Jul-09 14:46 UTC
[LLVMdev] llvm jit acting at runtime, like libgccjit ?
<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=AwMD3g&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=E1cWW-PAGPIM-jv-wZPcbUaIGZF76F3khZvXTlblazk&s=J2ZYv617m9mjI0Khgzm9Epv-GE07oIQwzqBnZ-zvTjA&e=">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>
Hi, 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: clang -O0 -emit-llvm -S -o - my-trivial-program.c Clang, like any frontend, produces deliberately poor code and expects LLVM to clean it up - if you want more cleaned up code use -O2. The IR reference is here: http://llvm.org/docs/LangRef.html The IRBuilder reference, which is the object you use to build up some IR programatically, is here: http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilder.html (and http://llvm.org/docs/doxygen/html/classllvm_1_1IRBuilderBase.html ) 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. Best of luck, James On Thu, 9 Jul 2015 at 15:47 <deco33000 at yandex.com> wrote:> Thanks James, > > Kaleidoscope seems to differ in the sense that I cannot really understand > how to create, say, a loop. It all looks like very complicated ( > http://llvm.org/docs/tutorial/LangImpl3.html) > > llvm is new to me. > > 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..) > > I will keep doing my homework, but a bit of help is very welcome :) > > -- > Jog > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150709/af3215f6/attachment.html>
Dibyendu Majumdar
2015-Jul-09 15:27 UTC
[LLVMdev] llvm jit acting at runtime, like libgccjit ?
On 9 July 2015 at 15:53, James Molloy <james at jamesmolloy.co.uk> wrote:> You can do this by writing a trivial function with a > loop in Clang and running: > > clang -O0 -emit-llvm -S -o - my-trivial-program.c > > Clang, like any frontend, produces deliberately poor code and expects LLVM > to clean it up - if you want more cleaned up code use -O2.I find it is more useful to use this: clang -cc1 -O1 -disable-llvm-optzns -S -emit-llvm prog.c -O0 produces some extra rubbish that is just noise. -O1 and above can get rid of the code altogether - so using the disable optimizations flag appears to help. Regards Dibyendu