aboutsummaryrefslogtreecommitdiff
path: root/gcc/jit/docs/internals
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@gcc.gnu.org>2014-11-11 21:55:52 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2014-11-11 21:55:52 +0000
commit35485da996c21efc9a574520a737e10fcbeab654 (patch)
tree50dc30071e711da437584255821706cc0e1ef426 /gcc/jit/docs/internals
parent970a9caa49aff82c46a9d9f96410653ac9a588f7 (diff)
downloadgcc-35485da996c21efc9a574520a737e10fcbeab654.zip
gcc-35485da996c21efc9a574520a737e10fcbeab654.tar.gz
gcc-35485da996c21efc9a574520a737e10fcbeab654.tar.bz2
Merger of dmalcolm/jit branch from git
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
Diffstat (limited to 'gcc/jit/docs/internals')
-rw-r--r--gcc/jit/docs/internals/index.rst216
1 files changed, 216 insertions, 0 deletions
diff --git a/gcc/jit/docs/internals/index.rst b/gcc/jit/docs/internals/index.rst
new file mode 100644
index 0000000..80626e4
--- /dev/null
+++ b/gcc/jit/docs/internals/index.rst
@@ -0,0 +1,216 @@
+.. 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/>.
+
+Internals
+=========
+
+Working on the JIT library
+--------------------------
+Having checked out the source code (to "src"), you can configure and build
+the JIT library like this:
+
+.. code-block:: bash
+
+ mkdir build
+ mkdir install
+ PREFIX=$(pwd)/install
+ cd build
+ ../src/configure \
+ --enable-host-shared \
+ --enable-languages=jit \
+ --disable-bootstrap \
+ --enable-checking=release \
+ --prefix=$PREFIX
+ nice make -j4 # altering the "4" to however many cores you have
+
+This should build a libgccjit.so within jit/build/gcc:
+
+.. code-block:: console
+
+ [build] $ file gcc/libgccjit.so*
+ gcc/libgccjit.so: symbolic link to `libgccjit.so.0'
+ gcc/libgccjit.so.0: symbolic link to `libgccjit.so.0.0.1'
+ gcc/libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
+
+Here's what those configuration options mean:
+
+.. option:: --enable-host-shared
+
+ Configuring with this option means that the compiler is built as
+ position-independent code, which incurs a slight performance hit,
+ but it necessary for a shared library.
+
+.. option:: --enable-languages=jit
+
+ This specifies which frontends to build. The JIT library looks like
+ a frontend to the rest of the code.
+
+.. option:: --disable-bootstrap
+
+ For hacking on the "jit" subdirectory, performing a full
+ bootstrap can be overkill, since it's unused by a bootstrap. However,
+ when submitting patches, you should remove this option, to ensure that
+ the compiler can still bootstrap itself.
+
+.. option:: --enable-checking=release
+
+ The compile can perform extensive self-checking as it runs, useful when
+ debugging, but slowing things down.
+
+ For maximum speed, configure with ``--enable-checking=release`` to
+ disable this self-checking.
+
+Running the test suite
+----------------------
+
+.. code-block:: console
+
+ [build] $ cd gcc
+ [gcc] $ make check-jit RUNTESTFLAGS="-v -v -v"
+
+A summary of the tests can then be seen in:
+
+.. code-block:: console
+
+ jit/build/gcc/testsuite/jit/jit.sum
+
+and detailed logs in:
+
+.. code-block:: console
+
+ jit/build/gcc/testsuite/jit/jit.log
+
+The test executables can be seen as:
+
+.. code-block:: console
+
+ jit/build/gcc/testsuite/jit/*.exe
+
+which can be run independently.
+
+You can compile and run individual tests by passing "jit.exp=TESTNAME" to RUNTESTFLAGS e.g.:
+
+.. code-block:: console
+
+ [gcc] $ make check-jit RUNTESTFLAGS="-v -v -v jit.exp=test-factorial.c"
+
+and once a test has been compiled, you can debug it directly:
+
+.. code-block:: console
+
+ [gcc] $ PATH=.:$PATH \
+ LD_LIBRARY_PATH=. \
+ LIBRARY_PATH=. \
+ gdb --args \
+ testsuite/jit/test-factorial.exe
+
+Environment variables
+---------------------
+When running client code against a locally-built libgccjit, three
+environment variables need to be set up:
+
+.. envvar:: LD_LIBRARY_PATH
+
+ `libgccjit.so` is dynamically linked into client code, so if running
+ against a locally-built library, ``LD_LIBRARY_PATH`` needs to be set
+ up appropriately. The library can be found within the "gcc"
+ subdirectory of the build tree:
+
+ .. code-block:: console
+
+ $ file libgccjit.so*
+ libgccjit.so: symbolic link to `libgccjit.so.0'
+ libgccjit.so.0: symbolic link to `libgccjit.so.0.0.1'
+ libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, not stripped
+
+.. envvar:: PATH
+
+ The library uses a driver executable for converting from .s assembler
+ files to .so shared libraries. Specifically, it looks for a name
+ expanded from
+ ``${target_noncanonical}-gcc-${gcc_BASEVER}${exeext}``
+ such as ``x86_64-unknown-linux-gnu-gcc-5.0.0``.
+
+ Hence ``PATH`` needs to include a directory where the library can
+ locate this executable.
+
+ The executable is normally installed to the installation bindir
+ (e.g. /usr/bin), but a copy is also created within the "gcc"
+ subdirectory of the build tree for running the testsuite, and for ease
+ of development.
+
+.. envvar:: LIBRARY_PATH
+
+ The driver executable invokes the linker, and the latter needs to locate
+ support libraries needed by the generated code, or you will see errors
+ like:
+
+ .. code-block:: console
+
+ ld: cannot find crtbeginS.o: No such file or directory
+ ld: cannot find -lgcc
+ ld: cannot find -lgcc_s
+
+ Hence if running directly from a locally-built copy (without installing),
+ ``LIBRARY_PATH`` needs to contain the "gcc" subdirectory of the build
+ tree.
+
+For example, to run a binary that uses the library against a non-installed
+build of the library in LIBGCCJIT_BUILD_DIR you need an invocation of the
+client code like this, to preprend the dir to each of the environment
+variables:
+
+.. code-block:: console
+
+ $ LD_LIBRARY_PATH=$(LIBGCCJIT_BUILD_DIR):$(LD_LIBRARY_PATH) \
+ PATH=$(LIBGCCJIT_BUILD_DIR):$(PATH) \
+ LIBRARY_PATH=$(LIBGCCJIT_BUILD_DIR):$(LIBRARY_PATH) \
+ ./jit-hello-world
+ hello world
+
+Overview of code structure
+--------------------------
+
+* ``libgccjit.c`` implements the API entrypoints. It performs error
+ checking, then calls into classes of the gcc::jit::recording namespace
+ within ``jit-recording.c`` and ``jit-recording.h``.
+
+* The gcc::jit::recording classes (within ``jit-recording.c`` and
+ ``jit-recording.h``) record the API calls that are made:
+
+ .. literalinclude:: ../../jit-common.h
+ :start-after: /* Recording types. */
+ :end-before: /* End of recording types. */
+ :language: c++
+
+* When the context is compiled, the gcc::jit::playback classes (within
+ ``jit-playback.c`` and ``jit-playback.h``) replay the API calls
+ within langhook:parse_file:
+
+ .. literalinclude:: ../../jit-common.h
+ :start-after: /* Playback types. */
+ :end-before: /* End of playback types. */
+ :language: c++
+
+ .. literalinclude:: ../../notes.txt
+ :lines: 1-
+
+Here is a high-level summary from ``jit-common.h``:
+
+.. include:: ../../jit-common.h
+ :start-after: This comment is included by the docs.
+ :end-before: End of comment for inclusion in the docs. */