From: David Malcolm <dmalcolm@redhat.com>
To: "Li, Yicheng" <yli137@vols.utk.edu>, "jit@gcc.gnu.org" <jit@gcc.gnu.org>
Subject: Re: JIT function compile to file
Date: Thu, 03 Aug 2023 11:47:18 -0400 [thread overview]
Message-ID: <f0be23d547272c32d7eb5b24864c07163b65d8b2.camel@redhat.com> (raw)
In-Reply-To: <1A45981A-5FCC-4B7A-9586-85F3315169C2@vols.utk.edu>
On Thu, 2023-08-03 at 15:07 +0000, Li, Yicheng via Jit wrote:
> Hi,
>
> I’m looking for examples that can let me build a jit function on one
> run, save it to a file, and grab from file again on the second run
> without rebuilding and recompilation.
> I’ve seen the function, gcc_jit_context_compile_to_file, and I’m
> wondering how to use it.
gcc_jit_context_compile_to_file is for ahead-of-time compilation. You
could compile the function into a shared library, and then load the
shared library when the process restarts.
Emacs does something like this for its Lisp files; see:
https://akrl.sdf.org/gccemacs.html
> Throughout the documentation, I see the gcc_jit_location type
> variable, I’m unsure how to use it, and if it is related to calling a
> saved-to-file jit function.
gcc_jit_location is for providing "source location" information for use
when stepping through the code in a debugger. It doesn't affect the
destination where code is compiled to.
> It would be great if there’s any example that can be provided.
I don't think there's an existing example in the documentation or
testsuite, but use gcc_jit_context_compile_to_file with
GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY to make a .so file, then on
rerunning the process use dlopen to load the .so file, and dlsym to
extract the function.
FWIW the testsuite
has:https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/testsuite/jit.dg/test-compile-to-dynamic-library.c
but that testcase merely does the compilation-to-dynamic-library, not
the loading of the built library, and it heavily uses the preprocessor
so probably isn't good as an example.
Hope this is helpful
Dave
prev parent reply other threads:[~2023-08-03 15:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 15:07 Li, Yicheng
2023-08-03 15:47 ` David Malcolm [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f0be23d547272c32d7eb5b24864c07163b65d8b2.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=jit@gcc.gnu.org \
--cc=yli137@vols.utk.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).