ChangeLog: * ChangeLog.jit: New. * MAINTAINERS (Various Maintainers): Add myself as jit maintainer. contrib/ChangeLog: * ChangeLog.jit: New. * jit-coverage-report.py: New file: a script to print crude code-coverage information for the libgccjit API. gcc/ChangeLog: * ChangeLog.jit: New. * Makefile.in (doc_build_sys): New variable, set to "sphinx" if sphinx is installed, falling back to "texinfo" otherwise. (FULL_DRIVER_NAME): New variable, adapted from the install-driver target. New target, a symlink within the builddir, linked to "xgcc", for use when running the JIT library from the builddir. (MOSTLYCLEANFILES): Add FULL_DRIVER_NAME. (install-driver): Use $(FULL_DRIVER_NAME) rather than spelling it out. * configure.ac (doc_build_sys): New variable, set to "sphinx" if sphinx is installed, falling back to "texinfo" otherwise. (GCC_DRIVER_NAME): Generate a gcc-driver-name.h file containing GCC_DRIVER_NAME for the benefit of jit/internal-api.c. * configure: Regenerate. * doc/install.texi (--enable-host-shared): Specify that this is required when building libgccjit. (Tools/packages necessary for modifying GCC): Add Sphinx. * timevar.def (TV_JIT_REPLAY): New. (TV_ASSEMBLE): New. (TV_LINK): New. (TV_LOAD): New. gcc/java/ChangeLog: * gcc/ChangeLog.jit: New. gcc/jit/ChangeLog: * ChangeLog.jit: New. * ChangeLog: New. * Make-lang.in: New. * TODO.rst: New. * config-lang.in: New. * docs/Makefile: New. * docs/_build/texinfo/Makefile: New. * docs/_build/texinfo/factorial.png: New. * docs/_build/texinfo/libgccjit.texi: New. * docs/_build/texinfo/sum-of-squares.png: New. * docs/conf.py: New. * docs/examples/tut01-hello-world.c: New. * docs/examples/tut02-square.c: New. * docs/examples/tut03-sum-of-squares.c: New. * docs/examples/tut04-toyvm/Makefile: New. * docs/examples/tut04-toyvm/factorial.toy: New. * docs/examples/tut04-toyvm/fibonacci.toy: New. * docs/examples/tut04-toyvm/toyvm.c: New. * docs/index.rst: New. * docs/internals/index.rst: New. * docs/intro/factorial.png: New. * docs/intro/index.rst: New. * docs/intro/sum-of-squares.png: New. * docs/intro/tutorial01.rst: New. * docs/intro/tutorial02.rst: New. * docs/intro/tutorial03.rst: New. * docs/intro/tutorial04.rst: New. * docs/topics/contexts.rst: New. * docs/topics/expressions.rst: New. * docs/topics/functions.rst: New. * docs/topics/index.rst: New. * docs/topics/locations.rst: New. * docs/topics/objects.rst: New. * docs/topics/results.rst: New. * docs/topics/types.rst: New. * dummy-frontend.c: New. * jit-builtins.c: New. * jit-builtins.h: New. * jit-common.h: New. * jit-playback.c: New. * jit-playback.h: New. * jit-recording.c: New. * jit-recording.h: New. * libgccjit++.h: New. * libgccjit.c: New. * libgccjit.h: New. * libgccjit.map: New. * notes.txt: New. gcc/testsuite/ChangeLog: * ChangeLog.jit: New. * jit.dg/all-non-failing-tests.h: New. * jit.dg/harness.h: New. * jit.dg/jit.exp: New. * jit.dg/test-accessing-struct.c: New. * jit.dg/test-accessing-union.c: New. * jit.dg/test-array-as-pointer.c: New. * jit.dg/test-arrays.c: New. * jit.dg/test-calling-external-function.c: New. * jit.dg/test-calling-function-ptr.c: New. * jit.dg/test-combination.c: New. * jit.dg/test-dot-product.c: New. * jit.dg/test-empty.c: New. * jit.dg/test-error-accessing-field-in-other-struct.c: New. * jit.dg/test-error-adding-to-terminated-block.c: New. * jit.dg/test-error-array-as-pointer.c: New. * jit.dg/test-error-bad-cast.c: New. * jit.dg/test-error-block-in-wrong-function.c: New. * jit.dg/test-error-call-through-ptr-with-mismatching-args.c: New. * jit.dg/test-error-call-through-ptr-with-non-function.c: New. * jit.dg/test-error-call-through-ptr-with-non-pointer.c: New. * jit.dg/test-error-call-through-ptr-with-not-enough-args.c: New. * jit.dg/test-error-call-through-ptr-with-too-many-args.c: New. * jit.dg/test-error-call-with-mismatching-args.c: New. * jit.dg/test-error-call-with-not-enough-args.c: New. * jit.dg/test-error-call-with-too-many-args.c: New. * jit.dg/test-error-dereference-field-of-non-pointer.c: New. * jit.dg/test-error-dereference-read-of-non-pointer.c: New. * jit.dg/test-error-get-type-bad-enum.c: New. * jit.dg/test-error-index-not-a-numeric-type.c: New. * jit.dg/test-error-mismatching-types-in-assignment.c: New. * jit.dg/test-error-mismatching-types-in-call.c: New. * jit.dg/test-error-missing-return.c: New. * jit.dg/test-error-new-binary-op-bad-op.c: New. * jit.dg/test-error-new-function-bad-kind.c: New. * jit.dg/test-error-new-unary-op-bad-op.c: New. * jit.dg/test-error-null-passed-to-api.c: New. * jit.dg/test-error-return-within-void-function.c: New. * jit.dg/test-error-unreachable-block.c: New. * jit.dg/test-error-unterminated-block.c: New. * jit.dg/test-error-value-not-a-numeric-type.c: New. * jit.dg/test-expressions.c: New. * jit.dg/test-factorial.c: New. * jit.dg/test-fibonacci.c: New. * jit.dg/test-functions.c: New. * jit.dg/test-fuzzer.c: New. * jit.dg/test-hello-world.c: New. * jit.dg/test-linked-list.c: New. * jit.dg/test-long-names.c: New. * jit.dg/test-nested-contexts.c: New. * jit.dg/test-nested-loops.c: New. * jit.dg/test-operator-overloading.cc: New. * jit.dg/test-quadratic.c: New. * jit.dg/test-quadratic.cc: New. * jit.dg/test-reading-struct.c: New. * jit.dg/test-string-literal.c: New. * jit.dg/test-sum-of-squares.c: New. * jit.dg/test-threads.c: New. * jit.dg/test-types.c: New. * jit.dg/test-using-global.c: New. * jit.dg/test-volatile.c: New. include/ChangeLog: * ChangeLog.jit: New. libbacktrace/ChangeLog: * ChangeLog.jit: New. libcpp/ChangeLog: * ChangeLog.jit: New. libdecnumber/ChangeLog: * ChangeLog.jit: New. libiberty/ChangeLog: * ChangeLog.jit: New. zlib/ChangeLog: * ChangeLog.jit: New. From-SVN: r217374
312 lines
9.8 KiB
ReStructuredText
312 lines
9.8 KiB
ReStructuredText
.. Copyright (C) 2014 Free Software Foundation, Inc.
|
|
Originally contributed by David Malcolm <dmalcolm@redhat.com>
|
|
|
|
This is free software: you can redistribute it and/or modify it
|
|
under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see
|
|
<http://www.gnu.org/licenses/>.
|
|
|
|
.. default-domain:: c
|
|
|
|
Creating and using functions
|
|
============================
|
|
|
|
Params
|
|
------
|
|
.. type:: gcc_jit_param
|
|
|
|
A `gcc_jit_param` represents a parameter to a function.
|
|
|
|
.. function:: gcc_jit_param *\
|
|
gcc_jit_context_new_param (gcc_jit_context *ctxt,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_type *type,\
|
|
const char *name)
|
|
|
|
In preparation for creating a function, create a new parameter of the
|
|
given type and name.
|
|
|
|
Parameters are lvalues, and thus are also rvalues (and objects), so the
|
|
following upcasts are available:
|
|
|
|
.. function:: gcc_jit_lvalue *\
|
|
gcc_jit_param_as_lvalue (gcc_jit_param *param)
|
|
|
|
Upcasting from param to lvalue.
|
|
|
|
.. function:: gcc_jit_rvalue *\
|
|
gcc_jit_param_as_rvalue (gcc_jit_param *param)
|
|
|
|
Upcasting from param to rvalue.
|
|
|
|
.. function:: gcc_jit_object *\
|
|
gcc_jit_param_as_object (gcc_jit_param *param)
|
|
|
|
Upcasting from param to object.
|
|
|
|
|
|
Functions
|
|
---------
|
|
|
|
.. type:: gcc_jit_function
|
|
|
|
A `gcc_jit_function` represents a function - either one that we're
|
|
creating ourselves, or one that we're referencing.
|
|
|
|
.. function:: gcc_jit_function *\
|
|
gcc_jit_context_new_function (gcc_jit_context *ctxt,\
|
|
gcc_jit_location *loc,\
|
|
enum gcc_jit_function_kind kind,\
|
|
gcc_jit_type *return_type,\
|
|
const char *name,\
|
|
int num_params,\
|
|
gcc_jit_param **params,\
|
|
int is_variadic)
|
|
|
|
Create a gcc_jit_function with the given name and parameters.
|
|
|
|
.. type:: enum gcc_jit_function_kind
|
|
|
|
This enum controls the kind of function created, and has the following
|
|
values:
|
|
|
|
.. macro:: GCC_JIT_FUNCTION_EXPORTED
|
|
|
|
Function is defined by the client code and visible
|
|
by name outside of the JIT.
|
|
|
|
.. macro:: GCC_JIT_FUNCTION_INTERNAL
|
|
|
|
Function is defined by the client code, but is invisible
|
|
outside of the JIT. Analogous to a "static" function.
|
|
|
|
.. macro:: GCC_JIT_FUNCTION_IMPORTED
|
|
|
|
Function is not defined by the client code; we're merely
|
|
referring to it. Analogous to using an "extern" function from a
|
|
header file.
|
|
|
|
.. macro:: GCC_JIT_FUNCTION_ALWAYS_INLINE
|
|
|
|
Function is only ever inlined into other functions, and is
|
|
invisible outside of the JIT.
|
|
|
|
Analogous to prefixing with ``inline`` and adding
|
|
``__attribute__((always_inline))``
|
|
|
|
Inlining will only occur when the optimization level is
|
|
above 0; when optimization is off, this is essentially the
|
|
same as GCC_JIT_FUNCTION_INTERNAL.
|
|
|
|
.. function:: gcc_jit_function *\
|
|
gcc_jit_context_get_builtin_function (gcc_jit_context *ctxt,\
|
|
const char *name)
|
|
|
|
.. function:: gcc_jit_object *\
|
|
gcc_jit_function_as_object (gcc_jit_function *func)
|
|
|
|
Upcasting from function to object.
|
|
|
|
.. function:: gcc_jit_param *\
|
|
gcc_jit_function_get_param (gcc_jit_function *func, int index)
|
|
|
|
Get the param of the given index (0-based).
|
|
|
|
.. function:: void \
|
|
gcc_jit_function_dump_to_dot (gcc_jit_function *func,\
|
|
const char *path)
|
|
|
|
Emit the function in graphviz format to the given path.
|
|
|
|
.. function:: gcc_jit_lvalue *\
|
|
gcc_jit_function_new_local (gcc_jit_function *func,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_type *type,\
|
|
const char *name)
|
|
|
|
Create a new local variable within the function, of the given type and
|
|
name.
|
|
|
|
|
|
Blocks
|
|
------
|
|
.. type:: gcc_jit_block
|
|
|
|
A `gcc_jit_block` represents a basic block within a function i.e. a
|
|
sequence of statements with a single entry point and a single exit
|
|
point.
|
|
|
|
The first basic block that you create within a function will
|
|
be the entrypoint.
|
|
|
|
Each basic block that you create within a function must be
|
|
terminated, either with a conditional, a jump, or a return.
|
|
|
|
It's legal to have multiple basic blocks that return within
|
|
one function.
|
|
|
|
.. function:: gcc_jit_block *\
|
|
gcc_jit_function_new_block (gcc_jit_function *func,\
|
|
const char *name)
|
|
|
|
Create a basic block of the given name. The name may be NULL, but
|
|
providing meaningful names is often helpful when debugging: it may
|
|
show up in dumps of the internal representation, and in error
|
|
messages.
|
|
|
|
.. function:: gcc_jit_object *\
|
|
gcc_jit_block_as_object (gcc_jit_block *block)
|
|
|
|
Upcast from block to object.
|
|
|
|
.. function:: gcc_jit_function *\
|
|
gcc_jit_block_get_function (gcc_jit_block *block)
|
|
|
|
Which function is this block within?
|
|
|
|
|
|
Statements
|
|
----------
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_add_eval (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_rvalue *rvalue)
|
|
|
|
Add evaluation of an rvalue, discarding the result
|
|
(e.g. a function call that "returns" void).
|
|
|
|
This is equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
(void)expression;
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_add_assignment (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_lvalue *lvalue,\
|
|
gcc_jit_rvalue *rvalue)
|
|
|
|
Add evaluation of an rvalue, assigning the result to the given
|
|
lvalue.
|
|
|
|
This is roughly equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
lvalue = rvalue;
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_add_assignment_op (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_lvalue *lvalue,\
|
|
enum gcc_jit_binary_op op,\
|
|
gcc_jit_rvalue *rvalue)
|
|
|
|
Add evaluation of an rvalue, using the result to modify an
|
|
lvalue.
|
|
|
|
This is analogous to "+=" and friends:
|
|
|
|
.. code-block:: c
|
|
|
|
lvalue += rvalue;
|
|
lvalue *= rvalue;
|
|
lvalue /= rvalue;
|
|
|
|
etc. For example:
|
|
|
|
.. code-block:: c
|
|
|
|
/* "i++" */
|
|
gcc_jit_block_add_assignment_op (
|
|
loop_body, NULL,
|
|
i,
|
|
GCC_JIT_BINARY_OP_PLUS,
|
|
gcc_jit_context_one (ctxt, int_type));
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_add_comment (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
const char *text)
|
|
|
|
Add a no-op textual comment to the internal representation of the
|
|
code. It will be optimized away, but will be visible in the dumps
|
|
seen via :macro:`GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE`
|
|
and :macro:`GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE`,
|
|
and thus may be of use when debugging how your project's internal
|
|
representation gets converted to the libgccjit IR.
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_end_with_conditional (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_rvalue *boolval,\
|
|
gcc_jit_block *on_true,\
|
|
gcc_jit_block *on_false)
|
|
|
|
Terminate a block by adding evaluation of an rvalue, branching on the
|
|
result to the appropriate successor block.
|
|
|
|
This is roughly equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
if (boolval)
|
|
goto on_true;
|
|
else
|
|
goto on_false;
|
|
|
|
block, boolval, on_true, and on_false must be non-NULL.
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_end_with_jump (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_block *target)
|
|
|
|
|
|
Terminate a block by adding a jump to the given target block.
|
|
|
|
This is roughly equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
goto target;
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_end_with_return (gcc_jit_block *block,\
|
|
gcc_jit_location *loc,\
|
|
gcc_jit_rvalue *rvalue)
|
|
|
|
|
|
Terminate a block by adding evaluation of an rvalue, returning the value.
|
|
|
|
This is roughly equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
return expression;
|
|
|
|
.. function:: void\
|
|
gcc_jit_block_end_with_void_return (gcc_jit_block *block,\
|
|
gcc_jit_location *loc)
|
|
|
|
|
|
Terminate a block by adding a valueless return, for use within a function
|
|
with "void" return type.
|
|
|
|
This is equivalent to this C code:
|
|
|
|
.. code-block:: c
|
|
|
|
return;
|