[llvm-dev] New to LLVM, need some help with JIT

Lang Hames via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 3 10:30:34 PDT 2016


Hi Pooya,

1) What's the right way to add a class or an instance of it to a module? I
> could only find ways to add structs to modules and I'm not sure how to deal
> with classes. Any good references to check? Or any good
> article/projects/code samples to look into?


LLVM IR is a low level representation - it doesn't have any built-in
representation of classes beyond the structs that you've seen. Your
frontend has to map those concepts onto LLVM IR.

2) Is there a way to declare that certain parts of a structure won’t change
> during execution?


This is also a problem for the frontend.

You could take a look at how clang maps these concepts from C++ to LLVM IR
by writing some simple C++ examples and then running:

clang++ -emit-llvm -S -o foo.ll foo.cpp

If your input language is C/C++ you may want to use clang to build the IR
that you want to JIT. There is an example of that in the
clang/examples/clang-interpreter directory.

Finally, if your ultimate goal is to experiment with optimizations in the
JIT you may find the new tutorial series that I'm working on helpful:
"Building A JIT in LLVM" at http://llvm.org/docs/tutorial/ . These
tutorials are very new, and only the first chapter has a complete write-up,
but all of the code is complete, and the code for Chapter 2, "Adding
Optimizations", may be relevant to you.

Cheers,
Lang.


On Thu, Jun 2, 2016 at 4:36 PM, Pooya SaadatPanah via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi,
>
> I'm a grad student working on a C++11 project and I have no compiler
> background. I apologize for asking basic questions here.
>
> Currently I'm looking for ways to optimize my code and as a starting point
> I wanted to experiment with loop unrolling and further I might consider
> function in-lining . I have been introduced to JIT compiler of LLVM and the
> possible application of it in my project.
>
> Currently I know the basics about creating a module and getting a JIT
> compiler. I followed this:
>
> https://llvm.org/svn/llvm-project/llvm/trunk/examples/HowToUseJIT/HowToUseJIT.cpp
>
> I have two questions:
>
> 1) What's the right way to add a class or an instance of it to a module? I
> could only find ways to add structs to modules and I'm not sure how to deal
> with classes. Any good references to check? Or any good
> article/projects/code samples to look into?
>
> 2) Is there a way to declare that certain parts of a structure won’t
> change during execution? For instance, let’s say that I have a class 'foo'
> and foo.x is 7 and doesn’t change over the life of the code, but foo.y
> does. There is a function in class foo and the function uses foo.x as the
> condition in the loop, thus I’d like to tell LLVM that foo.x is always 7,
> so that it can unroll the loop "for(int i = 0;i < foo.x;i++)". But I’m a
> little confused about how LLVM uses constants – they appear to be tied to
> global variables only, and only an entire global variable, so I don’t see
> how to make one component of it a constant.
>
> Thank you,
>
> -P.S.P
>
> --
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160603/62e73f0c/attachment.html>


More information about the llvm-dev mailing list