[LLVMdev] llvm jit acting at runtime, like libgccjit ?

James Molloy james at jamesmolloy.co.uk
Thu Jul 9 07:53:01 PDT 2015


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>


More information about the llvm-dev mailing list