public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* JIT function compile to file
@ 2023-08-03 15:07 Li, Yicheng
  2023-08-03 15:47 ` David Malcolm
  0 siblings, 1 reply; 2+ messages in thread
From: Li, Yicheng @ 2023-08-03 15:07 UTC (permalink / raw)
  To: jit

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.
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.
It would be great if there’s any example that can be provided.

Thank you
Yicheng Li

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: JIT function compile to file
  2023-08-03 15:07 JIT function compile to file Li, Yicheng
@ 2023-08-03 15:47 ` David Malcolm
  0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2023-08-03 15:47 UTC (permalink / raw)
  To: Li, Yicheng, jit

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-03 15:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-03 15:07 JIT function compile to file Li, Yicheng
2023-08-03 15:47 ` David Malcolm

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).