[cfe-dev] [llvm-dev] Query about JIT
Rajesh Jayaprakash via cfe-dev
cfe-dev at lists.llvm.org
Mon May 13 04:24:34 PDT 2019
Hi Alexey,
Thanks very much for your pointers, will check them out.
Regards,
Rajesh
On Mon, May 13, 2019 at 4:23 PM Sachkov, Alexey <alexey.sachkov at intel.com>
wrote:
> Hi Rajesh,
>
> >> I bundle the Clang/LLVM libraries (along with the modified code from
> clang-interpreter) into a shared library and am able to invoke the JIT
> functionality both statically and dynamically. However, the size of the
> shared library is ~54 MB, which I feel is too large. Am I doing something
> wrong, and is there a way to strip out unneeded bits and reduce the size?
> Or, is this the price I have to pay for removing any runtime dependency on
> Clang/LLVM?
>
>
>
> I don’t know which specific numbers you need to expect, but the size of
> LLVM+Clang might be large. For example, take a look at the slides from the
> EuroLLVM 2019 [0] from Russell Gallop about size of clang compiler on
> windows
>
> >> 2. This is more of a general JIT query: my current plan is to dump the
> generated C code to a file and invoke clang on this file through the API. I
> haven't tested out the performance implications of this yet, but wanted to
> know if this is kosher. This method has the advantage that my interaction
> with the clang API is quite coarse-grained as opposed to using (other)
> finer-grained API calls.
>
> I cannot say much here because I’ve never tried to do so, but as I can
> see, ROCm-OpenCL-Driver [1] uses such method, you could try to reach
> developers of this library and ask them.
>
> [0]: https://www.youtube.com/watch?v=N1CbQNQYs-8
> [1]: https://github.com/RadeonOpenCompute/ROCm-OpenCL-Driver
>
>
>
> *From:* cfe-dev [mailto:cfe-dev-bounces at lists.llvm.org] *On Behalf Of *Rajesh
> Jayaprakash via cfe-dev
> *Sent:* Monday, May 13, 2019 8:56 AM
> *To:* cfe-dev <cfe-dev at lists.llvm.org>
> *Subject:* Re: [cfe-dev] [llvm-dev] Query about JIT
>
>
>
> Dear cfe-dev mailing list,
>
>
>
> I had posted earlier in this list with some queries about JIT. Thanks
> Alexey and Mehdi for your help.
>
>
>
> I have liberally borrowed from the provided clang-interpreter example and
> have more or less managed to meet my objectives. Two concerns remain,
> however:
>
>
>
> 1. I bundle the Clang/LLVM libraries (along with the modified code from
> clang-interpreter) into a shared library and am able to invoke the JIT
> functionality both statically and dynamically. However, the size of the
> shared library is ~54 MB, which I feel is too large. Am I doing something
> wrong, and is there a way to strip out unneeded bits and reduce the size?
> Or, is this the price I have to pay for removing any runtime dependency on
> Clang/LLVM?
>
>
>
> 2. This is more of a general JIT query: my current plan is to dump the
> generated C code to a file and invoke clang on this file through the API. I
> haven't tested out the performance implications of this yet, but wanted to
> know if this is kosher. This method has the advantage that my interaction
> with the clang API is quite coarse-grained as opposed to using (other)
> finer-grained API calls.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> Thanks,
>
> Rajesh Jayaprakash
>
> (https://github.com/shikantaza/plisp)
>
>
>
> On Wed, Mar 13, 2019 at 2:56 PM Rajesh Jayaprakash <
> rajesh.jayaprakash at gmail.com> wrote:
>
> 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
>
>
>
>
> --
>
> Regards,
> Rajesh
>
>
> --------------------------------------------------------------------
> 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.
>
--
Regards,
Rajesh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190513/2254f4da/attachment.html>
More information about the cfe-dev
mailing list