[cfe-dev] [llvm-dev] Query about JIT

Rajesh Jayaprakash via cfe-dev cfe-dev at lists.llvm.org
Wed Mar 13 02:26:01 PDT 2019


Thanks Mehdi!

Regards,
Rajesh

On Wed, Mar 13, 2019 at 2:42 PM Mehdi AMINI <joker.eph at gmail.com> wrote:

> Hi Rajesh,
>
> Adding the cfe-dev (Clang FrontEnd) mailing list as your question seems to
> be more targeted towards clang (your input is C code if I understood
> correctly).
>
> At the LLVM level, there is a (limited but "stable") C API here:
> https://github.com/llvm/llvm-project/tree/master/llvm/include/llvm-c
> For the JIT, this file seems relevant:
> https://github.com/llvm/llvm-project/blob/master/llvm/include/llvm-c/OrcBindings.h
> But this assumes you get LLVM IR in the first place, and I don't know of a
> C API for clang for this.
>
> Best,
>
> --
> Mehdi
>
>
> On Tue, Mar 12, 2019 at 7:05 AM Rajesh Jayaprakash via llvm-dev <
> llvm-dev at lists.llvm.org> wrote:
>
>> Hi Alexey,
>>
>> Thank you very much for your detailed reply, will look into the resources
>> indicated. I'd like to avoid C++ if possible, let me see how it goes.
>>
>> Regards,
>> Rajesh Jayaprakash
>>
>> On Tue 12 Mar, 2019, 6:35 PM Sachkov, Alexey, <alexey.sachkov at intel.com>
>> wrote:
>>
>>> Hi Rajesh,
>>>
>>> If I understand correctly, libclang is a C interface to Clang features,
>>> not LLVM. That means that you cannot get LLVM IR via libclang: The C
>>> Interface to Clang provides a relatively small API that exposes facilities
>>> for parsing source code into an abstract syntax tree (AST), loading
>>> already-parsed ASTs, traversing the AST, associating physical source
>>> locations with elements within the AST, and other facilities that support
>>> Clang-based development tools.
>>>
>>> To get LLVM IR and perform JIT compilation you need to use C++ API of
>>> Clang and LLVM.
>>>
>>>
>>>
>>> Here is some links which might be helpful:
>>>
>>> * [cfe-dev] How to use clang and llvm for JIT, preferably via the C API
>>> http://lists.llvm.org/pipermail/cfe-dev/2015-August/044869.html
>>>
>>> * [cfe-dev] Help on Generating LLVM Module from C++ file using libClang
>>> http://lists.llvm.org/pipermail/cfe-dev/2017-November/056033.html
>>>
>>> * [LLVMdev] libclang JIT frontend
>>> http://lists.llvm.org/pipermail/llvm-dev/2013-October/066088.html
>>>
>>> * Generate assembly from C code in memory using libclang
>>> https://stackoverflow.com/questions/34828480/generate-assembly-from-c-code-in-memory-using-libclang
>>>
>>>
>>>
>>> BTW, there is a library for translating OpenCL C source code into a LLVM
>>> IR which features in-memory translation:
>>>
>>> * https://github.com/intel/opencl-clang
>>> It is not suitable for performing the whole JIT compilation, but it is
>>> used by https://github.com/intel/intel-graphics-compiler as a
>>> front-end. Also I’m not sure that you will be able to use it as-is for your
>>> purposes, but at least it can be used as an example
>>>
>>>
>>>
>>> *From:* llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] *On Behalf Of
>>> *Rajesh Jayaprakash via llvm-dev
>>> *Sent:* Friday, March 8, 2019 2:14 PM
>>> *To:* llvm-dev at lists.llvm.org
>>> *Subject:* [llvm-dev] Query about JIT
>>>
>>>
>>>
>>> Dear llvm-dev list,
>>>
>>>
>>>
>>> Apologies if this list is not the right venue for this query - suitable
>>> redirection would be appreciated in that case.
>>>
>>>
>>>
>>> I have a JIT use case that I'd like to know the best way to implement
>>> using LLVM.
>>>
>>>
>>>
>>> I am looking to migrate from the existing native compilation option
>>> (Tiny C Compiler - TCC) for pLisp, a Lisp dialect and IDE.
>>>
>>>
>>>
>>> At present, the native compilation is done by converting the Lisp code
>>> to C, storing the C code in a char buffer, and passing it to TCC
>>> programmatically via the API provided. I get a function pointer in return,
>>> which I store and invoke as needed.
>>>
>>>
>>>
>>> Delving into the LLVM documentation, I found that one possible way to
>>> achieve the same functionality in LLVM is to use clag/libclang to convert
>>> the C source to LLVM IR, load this IR into the the JIT context and
>>> (skipping some steps I'm yet to figure out) get the desired function
>>> pointer.
>>>
>>>
>>>
>>> Is this approach the right one? One issue I foresee is that libclang's
>>> clang_parseTranslateUnit() function expects the C code to be from a file
>>> (although the file can be in-memory), whereas in my case the C code needs
>>> to be picked up from a char buffer - necessitating fmemopen(), etc.
>>>
>>>
>>>
>>> Thanks for your assistance.
>>>
>>>
>>>
>>> Regards,
>>> Rajesh Jayaprakash
>>>
>>> (https://github.com/shikantaza/plisp)
>>>
>>>
>>> --------------------------------------------------------------------
>>> Joint Stock Company Intel A/O
>>> Registered legal address: Krylatsky Hills Business Park,
>>> 17 Krylatskaya Str., Bldg 4, Moscow 121614,
>>> Russian Federation
>>>
>>> This e-mail and any attachments may contain confidential material for
>>> the sole use of the intended recipient(s). Any review or distribution
>>> by others is strictly prohibited. If you are not the intended
>>> recipient, please contact the sender and delete all copies.
>>>
>> _______________________________________________
>> LLVM Developers mailing list
>> llvm-dev at lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>>
>

-- 
Regards,
Rajesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190313/7d317f11/attachment.html>


More information about the cfe-dev mailing list