From 421d0d0f54294a7bf2872b3b2ac521ce0fa9869e Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 12 Nov 2020 17:28:17 -0500 Subject: [PATCH] jit: add support for inline asm [PR87291] This patch adds various entrypoints to libgccjit for directly embedding asm statements into a compile, analogous to inline asm in the C frontend: gcc_jit_block_add_extended_asm gcc_jit_block_end_with_extended_asm_goto gcc_jit_extended_asm_as_object gcc_jit_extended_asm_set_volatile_flag gcc_jit_extended_asm_set_inline_flag gcc_jit_extended_asm_add_output_operand gcc_jit_extended_asm_add_input_operand gcc_jit_extended_asm_add_clobber gcc_jit_context_add_top_level_asm gcc/jit/ChangeLog: PR jit/87291 * docs/cp/topics/asm.rst: New file. * docs/cp/topics/index.rst (Topic Reference): Add it. * docs/topics/asm.rst: New file. * docs/topics/compatibility.rst (LIBGCCJIT_ABI_15): New. * docs/topics/functions.rst (Statements): Add link to extended asm. * docs/topics/index.rst (Topic Reference): Add asm.rst. * docs/topics/objects.rst: Add gcc_jit_extended_asm to ASCII art. * docs/_build/texinfo/Makefile: Regenerate. * docs/_build/texinfo/libgccjit.texi: Regenerate. * jit-common.h (gcc::jit::recording::extended_asm): New forward decl. (gcc::jit::recording::top_level_asm): Likewise. * jit-playback.c: Include "stmt.h". (build_string): New. (gcc::jit::playback::context::new_string_literal): Disambiguate build_string call. (gcc::jit::playback::context::add_top_level_asm): New. (build_operand_chain): New. (build_clobbers): New. (build_goto_operands): New. (gcc::jit::playback::block::add_extended_asm): New. * jit-playback.h (gcc::jit::playback::context::add_top_level_asm): New decl. (struct gcc::jit::playback::asm_operand): New struct. (gcc::jit::playback::block::add_extended_asm): New decl. * jit-recording.c (gcc::jit::recording::context::dump_to_file): Dump top-level asms. (gcc::jit::recording::context::add_top_level_asm): New. (gcc::jit::recording::block::add_extended_asm): New. (gcc::jit::recording::block::end_with_extended_asm_goto): New. (gcc::jit::recording::asm_operand::asm_operand): New. (gcc::jit::recording::asm_operand::print): New. (gcc::jit::recording::asm_operand::make_debug_string): New. (gcc::jit::recording::output_asm_operand::write_reproducer): New. (gcc::jit::recording::output_asm_operand::print): New. (gcc::jit::recording::input_asm_operand::write_reproducer): New. (gcc::jit::recording::input_asm_operand::print): New. (gcc::jit::recording::extended_asm::add_output_operand): New. (gcc::jit::recording::extended_asm::add_input_operand): New. (gcc::jit::recording::extended_asm::add_clobber): New. (gcc::jit::recording::extended_asm::replay_into): New. (gcc::jit::recording::extended_asm::make_debug_string): New. (gcc::jit::recording::extended_asm::write_flags): New. (gcc::jit::recording::extended_asm::write_clobbers): New. (gcc::jit::recording::extended_asm_simple::write_reproducer): New. (gcc::jit::recording::extended_asm::maybe_populate_playback_blocks): New. (gcc::jit::recording::extended_asm_goto::extended_asm_goto): New. (gcc::jit::recording::extended_asm_goto::replay_into): New. (gcc::jit::recording::extended_asm_goto::write_reproducer): New. (gcc::jit::recording::extended_asm_goto::get_successor_blocks): New. (gcc::jit::recording::extended_asm_goto::maybe_print_gotos): New. (gcc::jit::recording::extended_asm_goto::maybe_populate_playback_blocks): New. (gcc::jit::recording::top_level_asm::top_level_asm): New. (gcc::jit::recording::top_level_asm::replay_into): New. (gcc::jit::recording::top_level_asm::make_debug_string): New. (gcc::jit::recording::top_level_asm::write_to_dump): New. (gcc::jit::recording::top_level_asm::write_reproducer): New. * jit-recording.h (gcc::jit::recording::context::add_top_level_asm): New decl. (gcc::jit::recording::context::m_top_level_asms): New field. (gcc::jit::recording::block::add_extended_asm): New decl. (gcc::jit::recording::block::end_with_extended_asm_goto): New decl. (gcc::jit::recording::asm_operand): New class. (gcc::jit::recording::output_asm_operand): New class. (gcc::jit::recording::input_asm_operand): New class. (gcc::jit::recording::extended_asm): New class. (gcc::jit::recording::extended_asm_simple): New class. (gcc::jit::recording::extended_asm_goto): New class. (gcc::jit::recording::top_level_asm): New class. * libgccjit++.h (gccjit::extended_asm): New forward decl. (gccjit::context::add_top_level_asm): New. (gccjit::block::add_extended_asm): New. (gccjit::block::end_with_extended_asm_goto): New. (gccjit::extended_asm): New class. (gccjit::extended_asm::extended_asm): New ctors. (gccjit::extended_asm::set_volatile_flag): New. (gccjit::extended_asm::set_inline_flag): New. (gccjit::extended_asm::add_output_operand): New. (gccjit::extended_asm::add_input_operand): New. (gccjit::extended_asm::add_clobber): New. (gccjit::extended_asm::get_inner_extended_asm): New. * libgccjit.c (struct gcc_jit_extended_asm): New. (jit_error): Make "loc" param take a gcc::jit::recording::location * rather than a gcc_jit_location *. (gcc_jit_block_add_extended_asm): New entrypoint. (gcc_jit_block_end_with_extended_asm_goto): New entrypoint. (gcc_jit_extended_asm_as_object): New entrypoint. (gcc_jit_extended_asm_set_volatile_flag): New entrypoint. (gcc_jit_extended_asm_set_inline_flag): New entrypoint. (gcc_jit_extended_asm_add_output_operand): New entrypoint. (gcc_jit_extended_asm_add_clobber): New entrypoint. (gcc_jit_context_add_top_level_asm): New entrypoint. * libgccjit.h: Add gcc_jit_extended_asm to ASCII art. (gcc_jit_extended_asm): New typedef. (LIBGCCJIT_HAVE_ASM_STATEMENTS): New define. (gcc_jit_block_add_extended_asm): New entrypoint. (gcc_jit_block_end_with_extended_asm_goto): New entrypoint. (gcc_jit_extended_asm_as_object): New entrypoint. (gcc_jit_extended_asm_set_volatile_flag): New entrypoint. (gcc_jit_extended_asm_set_inline_flag): New entrypoint. (gcc_jit_extended_asm_add_output_operand): New entrypoint. (gcc_jit_extended_asm_add_input_operand): New entrypoint. (gcc_jit_extended_asm_add_clobber): New entrypoint. (gcc_jit_context_add_top_level_asm): New entrypoint. * libgccjit.map (LIBGCCJIT_ABI_15): New. gcc/testsuite/ChangeLog: PR jit/87291 * jit.dg/jit.exp: Load target-supports-dg.exp. Set dg-do-what-default. (jit-dg-test): Set dg-do-what and call dg-get-options, skipping the test if it's not supported on the given target. * jit.dg/test-asm.c: New test. * jit.dg/test-asm.cc: New test. --- gcc/jit/docs/_build/texinfo/Makefile | 11 +- gcc/jit/docs/_build/texinfo/libgccjit.texi | 1837 ++++++++++++++------ gcc/jit/docs/cp/topics/asm.rst | 308 ++++ gcc/jit/docs/cp/topics/index.rst | 1 + gcc/jit/docs/topics/asm.rst | 311 ++++ gcc/jit/docs/topics/compatibility.rst | 17 + gcc/jit/docs/topics/functions.rst | 3 + gcc/jit/docs/topics/index.rst | 1 + gcc/jit/docs/topics/objects.rst | 1 + gcc/jit/jit-common.h | 2 + gcc/jit/jit-playback.c | 125 +- gcc/jit/jit-playback.h | 27 + gcc/jit/jit-recording.c | 514 ++++++ gcc/jit/jit-recording.h | 215 +++ gcc/jit/libgccjit++.h | 170 ++ gcc/jit/libgccjit.c | 188 +- gcc/jit/libgccjit.h | 103 ++ gcc/jit/libgccjit.map | 13 + gcc/testsuite/jit.dg/jit.exp | 31 + gcc/testsuite/jit.dg/test-asm.c | 492 ++++++ gcc/testsuite/jit.dg/test-asm.cc | 453 +++++ 21 files changed, 4318 insertions(+), 505 deletions(-) create mode 100644 gcc/jit/docs/cp/topics/asm.rst create mode 100644 gcc/jit/docs/topics/asm.rst create mode 100644 gcc/testsuite/jit.dg/test-asm.c create mode 100644 gcc/testsuite/jit.dg/test-asm.cc diff --git a/gcc/jit/docs/_build/texinfo/Makefile b/gcc/jit/docs/_build/texinfo/Makefile index 81c60f502bf..e3b732cda78 100644 --- a/gcc/jit/docs/_build/texinfo/Makefile +++ b/gcc/jit/docs/_build/texinfo/Makefile @@ -18,13 +18,20 @@ pdf: $(addsuffix .pdf,$(ALLDOCS)) install-info: info for f in *.info; do \ - cp -t $(infodir) "$$f" && \ - $(INSTALL_INFO) --info-dir=$(infodir) "$$f" ; \ + mkdir -p $(infodir) && \ + cp "$$f" $(infodir) && \ + $(INSTALL_INFO) --info-dir=$(infodir) "$$f" && \ + \ + FIGURE_DIR="`basename \"$$f\" .info`-figures" && \ + if [ -e "$$FIGURE_DIR" ]; then \ + cp -r "$$FIGURE_DIR" $(infodir) ; \ + fi; \ done uninstall-info: info for f in *.info; do \ rm -f "$(infodir)/$$f" ; \ + rm -rf "$(infodir)/`basename '$$f' .info`-figures" && \ $(INSTALL_INFO) --delete --info-dir=$(infodir) "$$f" ; \ done diff --git a/gcc/jit/docs/_build/texinfo/libgccjit.texi b/gcc/jit/docs/_build/texinfo/libgccjit.texi index 57aca7ae08b..7b957b79c94 100644 --- a/gcc/jit/docs/_build/texinfo/libgccjit.texi +++ b/gcc/jit/docs/_build/texinfo/libgccjit.texi @@ -3,7 +3,7 @@ @setfilename libgccjit.info @documentencoding UTF-8 @ifinfo -@*Generated by Sphinx 1.6.7.@* +@*Generated by Sphinx 2.2.2.@* @end ifinfo @settitle libgccjit Documentation @defindex ge @@ -21,7 +21,7 @@ @copying @quotation -libgccjit 11.0.0 (experimental 20200914), Sep 14, 2020 +libgccjit 11.0.0 (experimental 20201112), Nov 12, 2020 David Malcolm @@ -173,6 +173,7 @@ Topic Reference * Compiling a context:: * ABI and API compatibility:: * Performance:: +* Using Assembly Language with libgccjit:: Compilation contexts @@ -256,11 +257,17 @@ ABI symbol tags * LIBGCCJIT_ABI_12:: * LIBGCCJIT_ABI_13:: * LIBGCCJIT_ABI_14:: +* LIBGCCJIT_ABI_15:: Performance * The timing API:: +Using Assembly Language with libgccjit + +* Adding assembler instructions within a function:: +* Adding top-level assembler statements:: + C++ bindings for libgccjit * Tutorial: Tutorial<2>. @@ -312,6 +319,7 @@ Topic Reference * Creating and using functions: Creating and using functions<2>. * Source Locations: Source Locations<2>. * Compiling a context: Compiling a context<2>. +* Using Assembly Language with libgccjit++:: Compilation contexts @@ -372,6 +380,11 @@ Compiling a context * In-memory compilation: In-memory compilation<2>. * Ahead-of-time compilation: Ahead-of-time compilation<2>. +Using Assembly Language with libgccjit++ + +* Adding assembler instructions within a function: Adding assembler instructions within a function<2>. +* Adding top-level assembler statements: Adding top-level assembler statements<2>. + Internals * Working on the JIT library:: @@ -390,7 +403,7 @@ Running the test suite @end menu @node Tutorial,Topic Reference,Top,Top -@anchor{intro/index libgccjit}@anchor{1}@anchor{intro/index doc}@anchor{2}@anchor{intro/index tutorial}@anchor{3} +@anchor{intro/index doc}@anchor{1}@anchor{intro/index libgccjit}@anchor{2}@anchor{intro/index tutorial}@anchor{3} @chapter Tutorial @@ -1122,7 +1135,7 @@ result: 25 @c . @node Tutorial part 3 Loops and variables,Tutorial part 4 Adding JIT-compilation to a toy interpreter,Tutorial part 2 Creating a trivial machine code function,Tutorial -@anchor{intro/tutorial03 tutorial-part-3-loops-and-variables}@anchor{21}@anchor{intro/tutorial03 doc}@anchor{22} +@anchor{intro/tutorial03 doc}@anchor{21}@anchor{intro/tutorial03 tutorial-part-3-loops-and-variables}@anchor{22} @section Tutorial part 3: Loops and variables @@ -1171,7 +1184,7 @@ Here’s what the final control flow graph will look like: @float Figure -@image{sum-of-squares1,,,image of a control flow graph,png} +@image{libgccjit-figures/sum-of-squares1,,,image of a control flow graph,png} @end float @@ -1520,7 +1533,7 @@ install it with @cite{yum install python-xdot}): @float Figure -@image{sum-of-squares1,,,image of a control flow graph,png} +@image{libgccjit-figures/sum-of-squares1,,,image of a control flow graph,png} @end float @@ -1740,7 +1753,7 @@ loop_test returned: 285 @c . @node Tutorial part 4 Adding JIT-compilation to a toy interpreter,Tutorial part 5 Implementing an Ahead-of-Time compiler,Tutorial part 3 Loops and variables,Tutorial -@anchor{intro/tutorial04 tutorial-part-4-adding-jit-compilation-to-a-toy-interpreter}@anchor{35}@anchor{intro/tutorial04 doc}@anchor{36} +@anchor{intro/tutorial04 doc}@anchor{35}@anchor{intro/tutorial04 tutorial-part-4-adding-jit-compilation-to-a-toy-interpreter}@anchor{36} @section Tutorial part 4: Adding JIT-compilation to a toy interpreter @@ -2716,7 +2729,7 @@ errors in our compiler. @float Figure -@image{factorial1,,,image of a control flow graph,png} +@image{libgccjit-figures/factorial1,,,image of a control flow graph,png} @end float @@ -4435,11 +4448,12 @@ and to a dynamic library. See the documentation of * Compiling a context:: * ABI and API compatibility:: * Performance:: +* Using Assembly Language with libgccjit:: @end menu @node Compilation contexts,Objects,,Topic Reference -@anchor{topics/contexts compilation-contexts}@anchor{51}@anchor{topics/contexts doc}@anchor{52} +@anchor{topics/contexts doc}@anchor{51}@anchor{topics/contexts compilation-contexts}@anchor{52} @section Compilation contexts @@ -5130,7 +5144,7 @@ its presence using @c . @node Objects,Types,Compilation contexts,Topic Reference -@anchor{topics/objects objects}@anchor{76}@anchor{topics/objects doc}@anchor{77} +@anchor{topics/objects doc}@anchor{76}@anchor{topics/objects objects}@anchor{77} @section Objects @@ -5175,6 +5189,7 @@ looks like this: +- gcc_jit_lvalue +- gcc_jit_param +- gcc_jit_case + +- gcc_jit_extended_asm @end example There are casting methods for upcasting from subclasses to parent classes. @@ -5875,7 +5890,7 @@ Function pointer types can be created using @c . @node Expressions,Creating and using functions,Types,Topic Reference -@anchor{topics/expressions expressions}@anchor{96}@anchor{topics/expressions doc}@anchor{97} +@anchor{topics/expressions doc}@anchor{96}@anchor{topics/expressions expressions}@anchor{97} @section Expressions @@ -7520,6 +7535,9 @@ create_code (gcc_jit_context *ctxt, void *user_data) @end quotation @end deffn +See also @ref{f1,,gcc_jit_extended_asm} for entrypoints for adding inline +assembler statements to a function. + @c Copyright (C) 2017-2020 Free Software Foundation, Inc. @c Originally contributed by David Malcolm @c @@ -7538,7 +7556,7 @@ create_code (gcc_jit_context *ctxt, void *user_data) @c . @node Function pointers<2>,Source Locations,Creating and using functions,Topic Reference -@anchor{topics/function-pointers doc}@anchor{f1}@anchor{topics/function-pointers function-pointers}@anchor{f2} +@anchor{topics/function-pointers doc}@anchor{f2}@anchor{topics/function-pointers function-pointers}@anchor{f3} @section Function pointers @@ -7557,7 +7575,7 @@ via @ref{c0,,gcc_jit_function_get_address()}. Get the address of a function as an rvalue, of function pointer type. -This entrypoint was added in @ref{f3,,LIBGCCJIT_ABI_9}; you can test +This entrypoint was added in @ref{f4,,LIBGCCJIT_ABI_9}; you can test for its presence using @example @@ -7619,7 +7637,7 @@ Each of @cite{param_types} must be non-@cite{void}; @cite{return_type} may be @c @c . @node Source Locations,Compiling a context,Function pointers<2>,Topic Reference -@anchor{topics/locations source-locations}@anchor{f4}@anchor{topics/locations doc}@anchor{f5} +@anchor{topics/locations doc}@anchor{f5}@anchor{topics/locations source-locations}@anchor{f6} @section Source Locations @@ -7667,7 +7685,7 @@ on-stack buffer. @end menu @node Faking it,,,Source Locations -@anchor{topics/locations faking-it}@anchor{f6} +@anchor{topics/locations faking-it}@anchor{f7} @subsection Faking it @@ -7703,7 +7721,7 @@ file, giving you @emph{something} you can step through in the debugger. @c . @node Compiling a context,ABI and API compatibility,Source Locations,Topic Reference -@anchor{topics/compilation compiling-a-context}@anchor{f7}@anchor{topics/compilation doc}@anchor{f8} +@anchor{topics/compilation doc}@anchor{f8}@anchor{topics/compilation compiling-a-context}@anchor{f9} @section Compiling a context @@ -7722,7 +7740,7 @@ prevent any future compilation of that context. @end menu @node In-memory compilation,Ahead-of-time compilation,,Compiling a context -@anchor{topics/compilation in-memory-compilation}@anchor{f9} +@anchor{topics/compilation in-memory-compilation}@anchor{fa} @subsection In-memory compilation @@ -7842,7 +7860,7 @@ by calling @ref{17,,gcc_jit_result_get_code()} or @end deffn @node Ahead-of-time compilation,,In-memory compilation,Compiling a context -@anchor{topics/compilation ahead-of-time-compilation}@anchor{fa} +@anchor{topics/compilation ahead-of-time-compilation}@anchor{fb} @subsection Ahead-of-time compilation @@ -7871,7 +7889,7 @@ suffix of the output file when determining what to do. @end cartouche @geindex gcc_jit_output_kind (C type) -@anchor{topics/compilation c gcc_jit_output_kind}@anchor{fb} +@anchor{topics/compilation c gcc_jit_output_kind}@anchor{fc} @deffn {C Type} enum gcc_jit_output_kind @end deffn @@ -7889,7 +7907,7 @@ Typical suffix @item -@ref{fc,,GCC_JIT_OUTPUT_KIND_ASSEMBLER} +@ref{fd,,GCC_JIT_OUTPUT_KIND_ASSEMBLER} @tab @@ -7897,7 +7915,7 @@ Typical suffix @item -@ref{fd,,GCC_JIT_OUTPUT_KIND_OBJECT_FILE} +@ref{fe,,GCC_JIT_OUTPUT_KIND_OBJECT_FILE} @tab @@ -7905,7 +7923,7 @@ Typical suffix @item -@ref{fe,,GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY} +@ref{ff,,GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY} @tab @@ -7913,7 +7931,7 @@ Typical suffix @item -@ref{ff,,GCC_JIT_OUTPUT_KIND_EXECUTABLE} +@ref{100,,GCC_JIT_OUTPUT_KIND_EXECUTABLE} @tab @@ -7923,21 +7941,21 @@ None, or .exe @geindex GCC_JIT_OUTPUT_KIND_ASSEMBLER (C macro) -@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_ASSEMBLER}@anchor{fc} +@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_ASSEMBLER}@anchor{fd} @deffn {C Macro} GCC_JIT_OUTPUT_KIND_ASSEMBLER Compile the context to an assembler file. @end deffn @geindex GCC_JIT_OUTPUT_KIND_OBJECT_FILE (C macro) -@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_OBJECT_FILE}@anchor{fd} +@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_OBJECT_FILE}@anchor{fe} @deffn {C Macro} GCC_JIT_OUTPUT_KIND_OBJECT_FILE Compile the context to an object file. @end deffn @geindex GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY (C macro) -@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY}@anchor{fe} +@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY}@anchor{ff} @deffn {C Macro} GCC_JIT_OUTPUT_KIND_DYNAMIC_LIBRARY Compile the context to a dynamic library. @@ -7947,7 +7965,7 @@ against. @end deffn @geindex GCC_JIT_OUTPUT_KIND_EXECUTABLE (C macro) -@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_EXECUTABLE}@anchor{ff} +@anchor{topics/compilation c GCC_JIT_OUTPUT_KIND_EXECUTABLE}@anchor{100} @deffn {C Macro} GCC_JIT_OUTPUT_KIND_EXECUTABLE Compile the context to an executable. @@ -7974,7 +7992,7 @@ against. @c . @node ABI and API compatibility,Performance,Compiling a context,Topic Reference -@anchor{topics/compatibility abi-and-api-compatibility}@anchor{100}@anchor{topics/compatibility doc}@anchor{101} +@anchor{topics/compatibility doc}@anchor{101}@anchor{topics/compatibility abi-and-api-compatibility}@anchor{102} @section ABI and API compatibility @@ -8030,21 +8048,21 @@ Version definitions: @end menu @node Programmatically checking version,ABI symbol tags,,ABI and API compatibility -@anchor{topics/compatibility programmatically-checking-version}@anchor{102} +@anchor{topics/compatibility programmatically-checking-version}@anchor{103} @subsection Programmatically checking version Client code can programmatically check libgccjit version using: @geindex gcc_jit_version_major (C function) -@anchor{topics/compatibility c gcc_jit_version_major}@anchor{103} +@anchor{topics/compatibility c gcc_jit_version_major}@anchor{104} @deffn {C Function} int gcc_jit_version_major (void) Return libgccjit major version. This is analogous to __GNUC__ in C code. @end deffn @geindex gcc_jit_version_minor (C function) -@anchor{topics/compatibility c gcc_jit_version_minor}@anchor{104} +@anchor{topics/compatibility c gcc_jit_version_minor}@anchor{105} @deffn {C Function} int gcc_jit_version_minor (void) Return libgccjit minor version. This is analogous to @@ -8052,7 +8070,7 @@ __GNUC_MINOR__ in C code. @end deffn @geindex gcc_jit_version_patchlevel (C function) -@anchor{topics/compatibility c gcc_jit_version_patchlevel}@anchor{105} +@anchor{topics/compatibility c gcc_jit_version_patchlevel}@anchor{106} @deffn {C Function} int gcc_jit_version_patchlevel (void) Return libgccjit patchlevel version. This is analogous to @@ -8067,7 +8085,7 @@ These entry points has been added with @code{LIBGCCJIT_ABI_13} @end cartouche @node ABI symbol tags,,Programmatically checking version,ABI and API compatibility -@anchor{topics/compatibility abi-symbol-tags}@anchor{106} +@anchor{topics/compatibility abi-symbol-tags}@anchor{107} @subsection ABI symbol tags @@ -8091,11 +8109,12 @@ Newer releases use the following tags. * LIBGCCJIT_ABI_12:: * LIBGCCJIT_ABI_13:: * LIBGCCJIT_ABI_14:: +* LIBGCCJIT_ABI_15:: @end menu @node LIBGCCJIT_ABI_0,LIBGCCJIT_ABI_1,,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-0}@anchor{107}@anchor{topics/compatibility id1}@anchor{108} +@anchor{topics/compatibility id1}@anchor{108}@anchor{topics/compatibility libgccjit-abi-0}@anchor{109} @subsubsection @code{LIBGCCJIT_ABI_0} @@ -8107,7 +8126,7 @@ continue to work, with this being handled transparently by the linker (see this post@footnote{https://gcc.gnu.org/ml/gcc-patches/2015-06/msg02126.html}) @node LIBGCCJIT_ABI_1,LIBGCCJIT_ABI_2,LIBGCCJIT_ABI_0,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-1}@anchor{73}@anchor{topics/compatibility id2}@anchor{109} +@anchor{topics/compatibility id2}@anchor{10a}@anchor{topics/compatibility libgccjit-abi-1}@anchor{73} @subsubsection @code{LIBGCCJIT_ABI_1} @@ -8115,7 +8134,7 @@ continue to work, with this being handled transparently by the linker @ref{72,,gcc_jit_context_add_command_line_option()} @node LIBGCCJIT_ABI_2,LIBGCCJIT_ABI_3,LIBGCCJIT_ABI_1,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-2}@anchor{6c}@anchor{topics/compatibility id3}@anchor{10a} +@anchor{topics/compatibility id3}@anchor{10b}@anchor{topics/compatibility libgccjit-abi-2}@anchor{6c} @subsubsection @code{LIBGCCJIT_ABI_2} @@ -8123,7 +8142,7 @@ continue to work, with this being handled transparently by the linker @ref{6b,,gcc_jit_context_set_bool_allow_unreachable_blocks()} @node LIBGCCJIT_ABI_3,LIBGCCJIT_ABI_4,LIBGCCJIT_ABI_2,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-3}@anchor{ef}@anchor{topics/compatibility id4}@anchor{10b} +@anchor{topics/compatibility id4}@anchor{10c}@anchor{topics/compatibility libgccjit-abi-3}@anchor{ef} @subsubsection @code{LIBGCCJIT_ABI_3} @@ -8147,7 +8166,7 @@ entrypoints: @end quotation @node LIBGCCJIT_ABI_4,LIBGCCJIT_ABI_5,LIBGCCJIT_ABI_3,ABI symbol tags -@anchor{topics/compatibility id5}@anchor{10c}@anchor{topics/compatibility libgccjit-abi-4}@anchor{10d} +@anchor{topics/compatibility id5}@anchor{10d}@anchor{topics/compatibility libgccjit-abi-4}@anchor{10e} @subsubsection @code{LIBGCCJIT_ABI_4} @@ -8160,30 +8179,30 @@ entrypoints: @itemize * @item -@ref{10e,,gcc_jit_context_get_timer()} +@ref{10f,,gcc_jit_context_get_timer()} @item -@ref{10f,,gcc_jit_context_set_timer()} +@ref{110,,gcc_jit_context_set_timer()} @item -@ref{110,,gcc_jit_timer_new()} +@ref{111,,gcc_jit_timer_new()} @item -@ref{111,,gcc_jit_timer_release()} +@ref{112,,gcc_jit_timer_release()} @item -@ref{112,,gcc_jit_timer_push()} +@ref{113,,gcc_jit_timer_push()} @item -@ref{113,,gcc_jit_timer_pop()} +@ref{114,,gcc_jit_timer_pop()} @item -@ref{114,,gcc_jit_timer_print()} +@ref{115,,gcc_jit_timer_print()} @end itemize @end quotation @node LIBGCCJIT_ABI_5,LIBGCCJIT_ABI_6,LIBGCCJIT_ABI_4,ABI symbol tags -@anchor{topics/compatibility id6}@anchor{115}@anchor{topics/compatibility libgccjit-abi-5}@anchor{6e} +@anchor{topics/compatibility id6}@anchor{116}@anchor{topics/compatibility libgccjit-abi-5}@anchor{6e} @subsubsection @code{LIBGCCJIT_ABI_5} @@ -8191,7 +8210,7 @@ entrypoints: @ref{6d,,gcc_jit_context_set_bool_use_external_driver()} @node LIBGCCJIT_ABI_6,LIBGCCJIT_ABI_7,LIBGCCJIT_ABI_5,ABI symbol tags -@anchor{topics/compatibility id7}@anchor{116}@anchor{topics/compatibility libgccjit-abi-6}@anchor{be} +@anchor{topics/compatibility id7}@anchor{117}@anchor{topics/compatibility libgccjit-abi-6}@anchor{be} @subsubsection @code{LIBGCCJIT_ABI_6} @@ -8199,7 +8218,7 @@ entrypoints: @ref{bd,,gcc_jit_rvalue_set_bool_require_tail_call()} @node LIBGCCJIT_ABI_7,LIBGCCJIT_ABI_8,LIBGCCJIT_ABI_6,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-7}@anchor{83}@anchor{topics/compatibility id8}@anchor{117} +@anchor{topics/compatibility id8}@anchor{118}@anchor{topics/compatibility libgccjit-abi-7}@anchor{83} @subsubsection @code{LIBGCCJIT_ABI_7} @@ -8207,7 +8226,7 @@ entrypoints: @ref{82,,gcc_jit_type_get_aligned()} @node LIBGCCJIT_ABI_8,LIBGCCJIT_ABI_9,LIBGCCJIT_ABI_7,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-8}@anchor{86}@anchor{topics/compatibility id9}@anchor{118} +@anchor{topics/compatibility id9}@anchor{119}@anchor{topics/compatibility libgccjit-abi-8}@anchor{86} @subsubsection @code{LIBGCCJIT_ABI_8} @@ -8215,7 +8234,7 @@ entrypoints: @ref{85,,gcc_jit_type_get_vector()} @node LIBGCCJIT_ABI_9,LIBGCCJIT_ABI_10,LIBGCCJIT_ABI_8,ABI symbol tags -@anchor{topics/compatibility id10}@anchor{119}@anchor{topics/compatibility libgccjit-abi-9}@anchor{f3} +@anchor{topics/compatibility id10}@anchor{11a}@anchor{topics/compatibility libgccjit-abi-9}@anchor{f4} @subsubsection @code{LIBGCCJIT_ABI_9} @@ -8223,7 +8242,7 @@ entrypoints: @ref{c0,,gcc_jit_function_get_address()} @node LIBGCCJIT_ABI_10,LIBGCCJIT_ABI_11,LIBGCCJIT_ABI_9,ABI symbol tags -@anchor{topics/compatibility id11}@anchor{11a}@anchor{topics/compatibility libgccjit-abi-10}@anchor{a0} +@anchor{topics/compatibility id11}@anchor{11b}@anchor{topics/compatibility libgccjit-abi-10}@anchor{a0} @subsubsection @code{LIBGCCJIT_ABI_10} @@ -8231,7 +8250,7 @@ entrypoints: @ref{87,,gcc_jit_context_new_rvalue_from_vector()} @node LIBGCCJIT_ABI_11,LIBGCCJIT_ABI_12,LIBGCCJIT_ABI_10,ABI symbol tags -@anchor{topics/compatibility id12}@anchor{11b}@anchor{topics/compatibility libgccjit-abi-11}@anchor{75} +@anchor{topics/compatibility id12}@anchor{11c}@anchor{topics/compatibility libgccjit-abi-11}@anchor{75} @subsubsection @code{LIBGCCJIT_ABI_11} @@ -8239,7 +8258,7 @@ entrypoints: @ref{74,,gcc_jit_context_add_driver_option()} @node LIBGCCJIT_ABI_12,LIBGCCJIT_ABI_13,LIBGCCJIT_ABI_11,ABI symbol tags -@anchor{topics/compatibility id13}@anchor{11c}@anchor{topics/compatibility libgccjit-abi-12}@anchor{8d} +@anchor{topics/compatibility id13}@anchor{11d}@anchor{topics/compatibility libgccjit-abi-12}@anchor{8d} @subsubsection @code{LIBGCCJIT_ABI_12} @@ -8247,7 +8266,7 @@ entrypoints: @ref{8c,,gcc_jit_context_new_bitfield()} @node LIBGCCJIT_ABI_13,LIBGCCJIT_ABI_14,LIBGCCJIT_ABI_12,ABI symbol tags -@anchor{topics/compatibility id14}@anchor{11d}@anchor{topics/compatibility libgccjit-abi-13}@anchor{11e} +@anchor{topics/compatibility id14}@anchor{11e}@anchor{topics/compatibility libgccjit-abi-13}@anchor{11f} @subsubsection @code{LIBGCCJIT_ABI_13} @@ -8260,24 +8279,66 @@ entrypoints: @itemize * @item -@ref{103,,gcc_jit_version_major()} +@ref{104,,gcc_jit_version_major()} @item -@ref{104,,gcc_jit_version_minor()} +@ref{105,,gcc_jit_version_minor()} @item -@ref{105,,gcc_jit_version_patchlevel()} +@ref{106,,gcc_jit_version_patchlevel()} @end itemize @end quotation -@node LIBGCCJIT_ABI_14,,LIBGCCJIT_ABI_13,ABI symbol tags -@anchor{topics/compatibility libgccjit-abi-14}@anchor{cf}@anchor{topics/compatibility id15}@anchor{11f} +@node LIBGCCJIT_ABI_14,LIBGCCJIT_ABI_15,LIBGCCJIT_ABI_13,ABI symbol tags +@anchor{topics/compatibility id15}@anchor{120}@anchor{topics/compatibility libgccjit-abi-14}@anchor{cf} @subsubsection @code{LIBGCCJIT_ABI_14} @code{LIBGCCJIT_ABI_14} covers the addition of @ref{ce,,gcc_jit_global_set_initializer()} +@node LIBGCCJIT_ABI_15,,LIBGCCJIT_ABI_14,ABI symbol tags +@anchor{topics/compatibility id16}@anchor{121}@anchor{topics/compatibility libgccjit-abi-15}@anchor{122} +@subsubsection @code{LIBGCCJIT_ABI_15} + + +@code{LIBGCCJIT_ABI_15} covers the addition of API entrypoints for directly +embedding assembler instructions: + +@quotation + + +@itemize * + +@item +@ref{123,,gcc_jit_block_add_extended_asm()} + +@item +@ref{124,,gcc_jit_block_end_with_extended_asm_goto()} + +@item +@ref{125,,gcc_jit_extended_asm_as_object()} + +@item +@ref{126,,gcc_jit_extended_asm_set_volatile_flag()} + +@item +@ref{127,,gcc_jit_extended_asm_set_inline_flag()} + +@item +@ref{128,,gcc_jit_extended_asm_add_output_operand()} + +@item +@ref{129,,gcc_jit_extended_asm_add_input_operand()} + +@item +@ref{12a,,gcc_jit_extended_asm_add_clobber()} + +@item +@ref{12b,,gcc_jit_context_add_top_level_asm()} +@end itemize +@end quotation + @c Copyright (C) 2015-2020 Free Software Foundation, Inc. @c Originally contributed by David Malcolm @c @@ -8295,8 +8356,8 @@ entrypoints: @c along with this program. If not, see @c . -@node Performance,,ABI and API compatibility,Topic Reference -@anchor{topics/performance performance}@anchor{120}@anchor{topics/performance doc}@anchor{121} +@node Performance,Using Assembly Language with libgccjit,ABI and API compatibility,Topic Reference +@anchor{topics/performance doc}@anchor{12c}@anchor{topics/performance performance}@anchor{12d} @section Performance @@ -8306,14 +8367,14 @@ entrypoints: @end menu @node The timing API,,,Performance -@anchor{topics/performance the-timing-api}@anchor{122} +@anchor{topics/performance the-timing-api}@anchor{12e} @subsection The timing API As of GCC 6, libgccjit exposes a timing API, for printing reports on how long was spent in different parts of code. -You can create a @ref{123,,gcc_jit_timer} instance, which will +You can create a @ref{12f,,gcc_jit_timer} instance, which will measure time spent since its creation. The timer maintains a stack of “timer items”: as control flow moves through your code, you can push and pop named items relating to your code onto the stack, and the timer @@ -8411,7 +8472,7 @@ Client items: The exact format is intended to be human-readable, and is subject to change. @geindex LIBGCCJIT_HAVE_TIMING_API (C macro) -@anchor{topics/performance c LIBGCCJIT_HAVE_TIMING_API}@anchor{124} +@anchor{topics/performance c LIBGCCJIT_HAVE_TIMING_API}@anchor{130} @deffn {C Macro} LIBGCCJIT_HAVE_TIMING_API The timer API was added to libgccjit in GCC 6. @@ -8428,21 +8489,21 @@ gcc_jit_context_set_timer (ctxt, t); @end deffn @geindex gcc_jit_timer (C type) -@anchor{topics/performance c gcc_jit_timer}@anchor{123} +@anchor{topics/performance c gcc_jit_timer}@anchor{12f} @deffn {C Type} gcc_jit_timer @end deffn @geindex gcc_jit_timer_new (C function) -@anchor{topics/performance c gcc_jit_timer_new}@anchor{110} +@anchor{topics/performance c gcc_jit_timer_new}@anchor{111} @deffn {C Function} gcc_jit_timer * gcc_jit_timer_new (void) -Create a @ref{123,,gcc_jit_timer} instance, and start timing: +Create a @ref{12f,,gcc_jit_timer} instance, and start timing: @example gcc_jit_timer *t = gcc_jit_timer_new (); @end example -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8451,10 +8512,10 @@ for its presence using @end deffn @geindex gcc_jit_timer_release (C function) -@anchor{topics/performance c gcc_jit_timer_release}@anchor{111} +@anchor{topics/performance c gcc_jit_timer_release}@anchor{112} @deffn {C Function} void gcc_jit_timer_release (gcc_jit_timer@w{ }*timer) -Release a @ref{123,,gcc_jit_timer} instance: +Release a @ref{12f,,gcc_jit_timer} instance: @example gcc_jit_timer_release (t); @@ -8462,7 +8523,7 @@ gcc_jit_timer_release (t); This should be called exactly once on a timer. -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8471,10 +8532,10 @@ for its presence using @end deffn @geindex gcc_jit_context_set_timer (C function) -@anchor{topics/performance c gcc_jit_context_set_timer}@anchor{10f} +@anchor{topics/performance c gcc_jit_context_set_timer}@anchor{110} @deffn {C Function} void gcc_jit_context_set_timer (gcc_jit_context@w{ }*ctxt, gcc_jit_timer@w{ }*timer) -Associate a @ref{123,,gcc_jit_timer} instance with a context: +Associate a @ref{12f,,gcc_jit_timer} instance with a context: @example gcc_jit_context_set_timer (ctxt, t); @@ -8487,7 +8548,7 @@ Timers have no locking, so if you have a multithreaded program, you must provide your own locks if more than one thread could be working with the same timer via timer-associated contexts. -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8496,12 +8557,12 @@ for its presence using @end deffn @geindex gcc_jit_context_get_timer (C function) -@anchor{topics/performance c gcc_jit_context_get_timer}@anchor{10e} +@anchor{topics/performance c gcc_jit_context_get_timer}@anchor{10f} @deffn {C Function} gcc_jit_timer *gcc_jit_context_get_timer (gcc_jit_context@w{ }*ctxt) Get the timer associated with a context (if any). -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8510,7 +8571,7 @@ for its presence using @end deffn @geindex gcc_jit_timer_push (C function) -@anchor{topics/performance c gcc_jit_timer_push}@anchor{112} +@anchor{topics/performance c gcc_jit_timer_push}@anchor{113} @deffn {C Function} void gcc_jit_timer_push (gcc_jit_timer@w{ }*timer, const char@w{ }*item_name) Push the given item onto the timer’s stack: @@ -8521,7 +8582,7 @@ run_the_code (ctxt, result); gcc_jit_timer_pop (t, "running code"); @end example -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8530,7 +8591,7 @@ for its presence using @end deffn @geindex gcc_jit_timer_pop (C function) -@anchor{topics/performance c gcc_jit_timer_pop}@anchor{113} +@anchor{topics/performance c gcc_jit_timer_pop}@anchor{114} @deffn {C Function} void gcc_jit_timer_pop (gcc_jit_timer@w{ }*timer, const char@w{ }*item_name) Pop the top item from the timer’s stack. @@ -8538,7 +8599,7 @@ Pop the top item from the timer’s stack. If “item_name” is provided, it must match that of the top item. Alternatively, @code{NULL} can be passed in, to suppress checking. -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8547,13 +8608,13 @@ for its presence using @end deffn @geindex gcc_jit_timer_print (C function) -@anchor{topics/performance c gcc_jit_timer_print}@anchor{114} +@anchor{topics/performance c gcc_jit_timer_print}@anchor{115} @deffn {C Function} void gcc_jit_timer_print (gcc_jit_timer@w{ }*timer, FILE@w{ }*f_out) Print timing information to the given stream about activity since the timer was started. -This API entrypoint was added in @ref{10d,,LIBGCCJIT_ABI_4}; you can test +This API entrypoint was added in @ref{10e,,LIBGCCJIT_ABI_4}; you can test for its presence using @example @@ -8561,6 +8622,403 @@ for its presence using @end example @end deffn +@c Copyright (C) 2020 Free Software Foundation, Inc. +@c Originally contributed by David Malcolm +@c +@c This is free software: you can redistribute it and/or modify it +@c under the terms of the GNU General Public License as published by +@c the Free Software Foundation, either version 3 of the License, or +@c (at your option) any later version. +@c +@c This program is distributed in the hope that it will be useful, but +@c WITHOUT ANY WARRANTY; without even the implied warranty of +@c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +@c General Public License for more details. +@c +@c You should have received a copy of the GNU General Public License +@c along with this program. If not, see +@c . + +@node Using Assembly Language with libgccjit,,Performance,Topic Reference +@anchor{topics/asm doc}@anchor{131}@anchor{topics/asm using-assembly-language-with-libgccjit}@anchor{132} +@section Using Assembly Language with libgccjit + + +libgccjit has some support for directly embedding assembler instructions. +This is based on GCC’s support for inline @code{asm} in C code, and the +following assumes a familiarity with that functionality. See +How to Use Inline Assembly Language in C Code@footnote{https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html} +in GCC’s documentation, the “Extended Asm” section in particular. + +These entrypoints were added in @ref{122,,LIBGCCJIT_ABI_15}; you can test +for their presence using + +@quotation + +@example +#ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS +@end example +@end quotation + +@menu +* Adding assembler instructions within a function:: +* Adding top-level assembler statements:: + +@end menu + +@node Adding assembler instructions within a function,Adding top-level assembler statements,,Using Assembly Language with libgccjit +@anchor{topics/asm adding-assembler-instructions-within-a-function}@anchor{133} +@subsection Adding assembler instructions within a function + + +@geindex gcc_jit_extended_asm (C type) +@anchor{topics/asm c gcc_jit_extended_asm}@anchor{f1} +@deffn {C Type} gcc_jit_extended_asm + +A @cite{gcc_jit_extended_asm} represents an extended @code{asm} statement: a +series of low-level instructions inside a function that convert inputs +to outputs. + +To avoid having an API entrypoint with a very large number of +parameters, an extended @code{asm} statement is made in stages: +an initial call to create the @ref{f1,,gcc_jit_extended_asm}, +followed by calls to add operands and set other properties of the +statement. + +There are two API entrypoints for creating a @ref{f1,,gcc_jit_extended_asm}: + + +@itemize * + +@item +@ref{123,,gcc_jit_block_add_extended_asm()} for an @code{asm} statement with +no control flow, and + +@item +@ref{124,,gcc_jit_block_end_with_extended_asm_goto()} for an @code{asm goto}. +@end itemize + +For example, to create the equivalent of: + +@example + asm ("mov %1, %0\n\t" + "add $1, %0" + : "=r" (dst) + : "r" (src)); +@end example + +the following API calls could be used: + +@example + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm (block, NULL, + "mov %1, %0\n\t" + "add $1, %0"); + gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=r", dst); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_lvalue_as_rvalue (src)); +@end example + +@cartouche +@quotation Warning +When considering the numbering of operands within an +extended @code{asm} statement (e.g. the @code{%0} and @code{%1} +above), the equivalent to the C syntax is followed i.e. all +output operands, then all input operands, regardless of +what order the calls to +@ref{128,,gcc_jit_extended_asm_add_output_operand()} and +@ref{129,,gcc_jit_extended_asm_add_input_operand()} were made in. +@end quotation +@end cartouche + +As in the C syntax, operands can be given symbolic names to avoid having +to number them. For example, to create the equivalent of: + +@example + asm ("bsfl %[aMask], %[aIndex]" + : [aIndex] "=r" (Index) + : [aMask] "r" (Mask) + : "cc"); +@end example + +the following API calls could be used: + +@example + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm (block, NULL, + "bsfl %[aMask], %[aIndex]"); + gcc_jit_extended_asm_add_output_operand (ext_asm, "aIndex", "=r", index); + gcc_jit_extended_asm_add_input_operand (ext_asm, "aMask", "r", + gcc_jit_param_as_rvalue (mask)); + gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); +@end example +@end deffn + +@geindex gcc_jit_block_add_extended_asm (C function) +@anchor{topics/asm c gcc_jit_block_add_extended_asm}@anchor{123} +@deffn {C Function} gcc_jit_extended_asm * gcc_jit_block_add_extended_asm (gcc_jit_block@w{ }*block, gcc_jit_location@w{ }*loc, const char@w{ }*asm_template) + +Create a @ref{f1,,gcc_jit_extended_asm} for an extended @code{asm} statement +with no control flow (i.e. without the @code{goto} qualifier). + +The parameter @code{asm_template} corresponds to the @cite{AssemblerTemplate} +within C’s extended @code{asm} syntax. It must be non-NULL. The call takes +a copy of the underlying string, so it is valid to pass in a pointer to +an on-stack buffer. +@end deffn + +@geindex gcc_jit_block_end_with_extended_asm_goto (C function) +@anchor{topics/asm c gcc_jit_block_end_with_extended_asm_goto}@anchor{124} +@deffn {C Function} gcc_jit_extended_asm * gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block@w{ }*block, gcc_jit_location@w{ }*loc, const char@w{ }*asm_template, int@w{ }num_goto_blocks, gcc_jit_block@w{ }**goto_blocks, gcc_jit_block@w{ }*fallthrough_block) + +Create a @ref{f1,,gcc_jit_extended_asm} for an extended @code{asm} statement +that may perform jumps, and use it to terminate the given block. +This is equivalent to the @code{goto} qualifier in C’s extended @code{asm} +syntax. + +For example, to create the equivalent of: + +@example + asm goto ("btl %1, %0\n\t" + "jc %l[carry]" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); +@end example + +the following API calls could be used: + +@example + const char *asm_template = + (use_name + ? /* Label referred to by name: "%l[carry]". */ + ("btl %1, %0\n\t" + "jc %l[carry]") + : /* Label referred to numerically: "%l2". */ + ("btl %1, %0\n\t" + "jc %l2")); + + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_end_with_extended_asm_goto (b_start, NULL, + asm_template, + 1, &b_carry, + b_fallthru); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_param_as_rvalue (p1)); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_param_as_rvalue (p2)); + gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); +@end example + +here referencing a @ref{28,,gcc_jit_block} named “carry”. + +@code{num_goto_blocks} must be >= 0. + +@code{goto_blocks} must be non-NULL. This corresponds to the @code{GotoLabels} +parameter within C’s extended @code{asm} syntax. The block names can be +referenced within the assembler template. + +@code{fallthrough_block} can be NULL. If non-NULL, it specifies the block +to fall through to after the statement. + +@cartouche +@quotation Note +This is needed since each @ref{28,,gcc_jit_block} must have a +single exit point, as a basic block: you can’t jump from the +middle of a block. A “goto” is implicitly added after the +asm to handle the fallthrough case, which is equivalent to what +would have happened in the C case. +@end quotation +@end cartouche +@end deffn + +@geindex gcc_jit_extended_asm_set_volatile_flag (C function) +@anchor{topics/asm c gcc_jit_extended_asm_set_volatile_flag}@anchor{126} +@deffn {C Function} void gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm@w{ }*ext_asm, int@w{ }flag) + +Set whether the @ref{f1,,gcc_jit_extended_asm} has side-effects, equivalent to the +volatile@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile} +qualifier in C’s extended asm syntax. + +For example, to create the equivalent of: + +@example +asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (msr) + : + : "rdx"); +@end example + +the following API calls could be used: + +@example + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm + (block, NULL, + "rdtsc\n\t" /* Returns the time in EDX:EAX. */ + "shl $32, %%rdx\n\t" /* Shift the upper bits left. */ + "or %%rdx, %0"); /* 'Or' in the lower bits. */ + gcc_jit_extended_asm_set_volatile_flag (ext_asm, 1); + gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=a", msr); + gcc_jit_extended_asm_add_clobber (ext_asm, "rdx"); +@end example + +where the @ref{f1,,gcc_jit_extended_asm} is flagged as volatile. +@end deffn + +@geindex gcc_jit_extended_asm_set_inline_flag (C function) +@anchor{topics/asm c gcc_jit_extended_asm_set_inline_flag}@anchor{127} +@deffn {C Function} void gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm@w{ }*ext_asm, int@w{ }flag) + +Set the equivalent of the +inline@footnote{https://gcc.gnu.org/onlinedocs/gcc/Size-of-an-asm.html#Size-of-an-asm} +qualifier in C’s extended @code{asm} syntax. +@end deffn + +@geindex gcc_jit_extended_asm_add_output_operand (C function) +@anchor{topics/asm c gcc_jit_extended_asm_add_output_operand}@anchor{128} +@deffn {C Function} void gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm@w{ }*ext_asm, const char@w{ }*asm_symbolic_name, const char@w{ }*constraint, gcc_jit_lvalue@w{ }*dest) + +Add an output operand to the extended @code{asm} statement. See the +Output Operands@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands} +section of the documentation of the C syntax. + +@code{asm_symbolic_name} corresponds to the @code{asmSymbolicName} component of C’s +extended @code{asm} syntax. It can be NULL. If non-NULL it specifies the +symbolic name for the operand. + +@code{constraint} corresponds to the @code{constraint} component of C’s extended +@code{asm} syntax. It must be non-NULL. + +@code{dest} corresponds to the @code{cvariablename} component of C’s extended +@code{asm} syntax. It must be non-NULL. + +@example +// Example with a NULL symbolic name, the equivalent of: +// : "=r" (dst) +gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=r", dst); + +// Example with a symbolic name ("aIndex"), the equivalent of: +// : [aIndex] "=r" (index) +gcc_jit_extended_asm_add_output_operand (ext_asm, "aIndex", "=r", index); +@end example + +This function can’t be called on an @code{asm goto} as such instructions can’t +have outputs; see the +Goto Labels@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GotoLabels} +section of GCC’s “Extended Asm” documentation. +@end deffn + +@geindex gcc_jit_extended_asm_add_input_operand (C function) +@anchor{topics/asm c gcc_jit_extended_asm_add_input_operand}@anchor{129} +@deffn {C Function} void gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm@w{ }*ext_asm, const char@w{ }*asm_symbolic_name, const char@w{ }*constraint, gcc_jit_rvalue@w{ }*src) + +Add an input operand to the extended @code{asm} statement. See the +Input Operands@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#InputOperands} +section of the documentation of the C syntax. + +@code{asm_symbolic_name} corresponds to the @code{asmSymbolicName} component of C’s +extended @code{asm} syntax. It can be NULL. If non-NULL it specifies the +symbolic name for the operand. + +@code{constraint} corresponds to the @code{constraint} component of C’s extended +@code{asm} syntax. It must be non-NULL. + +@code{src} corresponds to the @code{cexpression} component of C’s extended +@code{asm} syntax. It must be non-NULL. + +@example +// Example with a NULL symbolic name, the equivalent of: +// : "r" (src) +gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_lvalue_as_rvalue (src)); + +// Example with a symbolic name ("aMask"), the equivalent of: +// : [aMask] "r" (Mask) +gcc_jit_extended_asm_add_input_operand (ext_asm, "aMask", "r", + gcc_jit_lvalue_as_rvalue (mask)); +@end example +@end deffn + +@geindex gcc_jit_extended_asm_add_clobber (C function) +@anchor{topics/asm c gcc_jit_extended_asm_add_clobber}@anchor{12a} +@deffn {C Function} void gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm@w{ }*ext_asm, const char@w{ }*victim) + +Add @cite{victim} to the list of registers clobbered by the extended @code{asm} +statement. It must be non-NULL. See the +Clobbers and Scratch Registers@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers#} +section of the documentation of the C syntax. + +Statements with multiple clobbers will require multiple calls, one per +clobber. + +For example: + +@example +gcc_jit_extended_asm_add_clobber (ext_asm, "r0"); +gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); +gcc_jit_extended_asm_add_clobber (ext_asm, "memory"); +@end example +@end deffn + +A @ref{f1,,gcc_jit_extended_asm} is a @ref{e,,gcc_jit_object} “owned” by +the block’s context. The following upcast is available: + +@geindex gcc_jit_extended_asm_as_object (C function) +@anchor{topics/asm c gcc_jit_extended_asm_as_object}@anchor{125} +@deffn {C Function} gcc_jit_object * gcc_jit_extended_asm_as_object (gcc_jit_extended_asm@w{ }*ext_asm) + +Upcast from extended @code{asm} to object. +@end deffn + +@node Adding top-level assembler statements,,Adding assembler instructions within a function,Using Assembly Language with libgccjit +@anchor{topics/asm adding-top-level-assembler-statements}@anchor{134} +@subsection Adding top-level assembler statements + + +In addition to creating extended @code{asm} instructions within a function, +there is support for creating “top-level” assembler statements, outside +of any function. + +@geindex gcc_jit_context_add_top_level_asm (C function) +@anchor{topics/asm c gcc_jit_context_add_top_level_asm}@anchor{12b} +@deffn {C Function} void gcc_jit_context_add_top_level_asm (gcc_jit_context@w{ }*ctxt, gcc_jit_location@w{ }*loc, const char@w{ }*asm_stmts) + +Create a set of top-level asm statements, analogous to those created +by GCC’s “basic” @code{asm} syntax in C at file scope. + +For example, to create the equivalent of: + +@example + asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @@function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t.popsection\n"); +@end example + +the following API calls could be used: + +@example + gcc_jit_context_add_top_level_asm (ctxt, NULL, + "\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @@function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t# some asm here\n" + "\t.popsection\n"); +@end example +@end deffn + @c Copyright (C) 2014-2020 Free Software Foundation, Inc. @c Originally contributed by David Malcolm @c @@ -8579,7 +9037,7 @@ for its presence using @c . @node C++ bindings for libgccjit,Internals,Topic Reference,Top -@anchor{cp/index c-bindings-for-libgccjit}@anchor{125}@anchor{cp/index doc}@anchor{126} +@anchor{cp/index doc}@anchor{135}@anchor{cp/index c-bindings-for-libgccjit}@anchor{136} @chapter C++ bindings for libgccjit @@ -8623,7 +9081,7 @@ Contents: @end menu @node Tutorial<2>,Topic Reference<2>,,C++ bindings for libgccjit -@anchor{cp/intro/index doc}@anchor{127}@anchor{cp/intro/index tutorial}@anchor{128} +@anchor{cp/intro/index doc}@anchor{137}@anchor{cp/intro/index tutorial}@anchor{138} @section Tutorial @@ -8653,7 +9111,7 @@ Contents: @end menu @node Tutorial part 1 “Hello world”<2>,Tutorial part 2 Creating a trivial machine code function<2>,,Tutorial<2> -@anchor{cp/intro/tutorial01 doc}@anchor{129}@anchor{cp/intro/tutorial01 tutorial-part-1-hello-world}@anchor{12a} +@anchor{cp/intro/tutorial01 doc}@anchor{139}@anchor{cp/intro/tutorial01 tutorial-part-1-hello-world}@anchor{13a} @subsection Tutorial part 1: “Hello world” @@ -8816,7 +9274,7 @@ hello world @c . @node Tutorial part 2 Creating a trivial machine code function<2>,Tutorial part 3 Loops and variables<2>,Tutorial part 1 “Hello world”<2>,Tutorial<2> -@anchor{cp/intro/tutorial02 doc}@anchor{12b}@anchor{cp/intro/tutorial02 tutorial-part-2-creating-a-trivial-machine-code-function}@anchor{12c} +@anchor{cp/intro/tutorial02 doc}@anchor{13b}@anchor{cp/intro/tutorial02 tutorial-part-2-creating-a-trivial-machine-code-function}@anchor{13c} @subsection Tutorial part 2: Creating a trivial machine code function @@ -8838,10 +9296,10 @@ First we need to include the relevant header: @end example All state associated with compilation is associated with a -@ref{12d,,gccjit;;context}, which is a thin C++ wrapper around the C API’s +@ref{13d,,gccjit;;context}, which is a thin C++ wrapper around the C API’s @ref{8,,gcc_jit_context *}. -Create one using @ref{12e,,gccjit;;context;;acquire()}: +Create one using @ref{13e,,gccjit;;context;;acquire()}: @example gccjit::context ctxt; @@ -8851,19 +9309,19 @@ ctxt = gccjit::context::acquire (); The JIT library has a system of types. It is statically-typed: every expression is of a specific type, fixed at compile-time. In our example, all of the expressions are of the C @cite{int} type, so let’s obtain this from -the context, as a @ref{12f,,gccjit;;type}, using -@ref{130,,gccjit;;context;;get_type()}: +the context, as a @ref{13f,,gccjit;;type}, using +@ref{140,,gccjit;;context;;get_type()}: @example gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT); @end example -@ref{12f,,gccjit;;type} is an example of a “contextual” object: every -entity in the API is associated with a @ref{12d,,gccjit;;context}. +@ref{13f,,gccjit;;type} is an example of a “contextual” object: every +entity in the API is associated with a @ref{13d,,gccjit;;context}. Memory management is easy: all such “contextual” objects are automatically cleaned up for you when the context is released, using -@ref{131,,gccjit;;context;;release()}: +@ref{141,,gccjit;;context;;release()}: @example ctxt.release (); @@ -8890,9 +9348,9 @@ The C++ class hierarchy within the @code{gccjit} namespace looks like this: +- param @end example -One thing you can do with a @ref{132,,gccjit;;object} is +One thing you can do with a @ref{142,,gccjit;;object} is to ask it for a human-readable description as a @code{std::string}, using -@ref{133,,gccjit;;object;;get_debug_string()}: +@ref{143,,gccjit;;object;;get_debug_string()}: @example printf ("obj: %s\n", obj.get_debug_string ().c_str ()); @@ -8908,7 +9366,7 @@ This is invaluable when debugging. Let’s create the function. To do so, we first need to construct its single parameter, specifying its type and giving it a name, -using @ref{134,,gccjit;;context;;new_param()}: +using @ref{144,,gccjit;;context;;new_param()}: @example gccjit::param param_i = ctxt.new_param (int_type, "i"); @@ -8949,7 +9407,7 @@ gccjit::block block = func.new_block (); Our basic block is relatively simple: it immediately terminates by returning the value of an expression. -We can build the expression using @ref{135,,gccjit;;context;;new_binary_op()}: +We can build the expression using @ref{145,,gccjit;;context;;new_binary_op()}: @example gccjit::rvalue expr = @@ -8958,9 +9416,9 @@ gccjit::rvalue expr = param_i, param_i); @end example -A @ref{136,,gccjit;;rvalue} is another example of a -@ref{132,,gccjit;;object} subclass. As before, we can print it with -@ref{133,,gccjit;;object;;get_debug_string()}. +A @ref{146,,gccjit;;rvalue} is another example of a +@ref{142,,gccjit;;object} subclass. As before, we can print it with +@ref{143,,gccjit;;object;;get_debug_string()}. @example printf ("expr: %s\n", expr.get_debug_string ().c_str ()); @@ -8972,7 +9430,7 @@ giving this output: expr: i * i @end example -Note that @ref{136,,gccjit;;rvalue} provides numerous overloaded operators +Note that @ref{146,,gccjit;;rvalue} provides numerous overloaded operators which can be used to dramatically reduce the amount of typing needed. We can build the above binary operation more directly with this one-liner: @@ -8989,7 +9447,7 @@ block.end_with_return (expr); @end example OK, we’ve populated the context. We can now compile it using -@ref{137,,gccjit;;context;;compile()}: +@ref{147,,gccjit;;context;;compile()}: @example gcc_jit_result *result; @@ -9031,12 +9489,12 @@ result: 25 @end menu @node Options<3>,Full example<3>,,Tutorial part 2 Creating a trivial machine code function<2> -@anchor{cp/intro/tutorial02 options}@anchor{138} +@anchor{cp/intro/tutorial02 options}@anchor{148} @subsubsection Options To get more information on what’s going on, you can set debugging flags -on the context using @ref{139,,gccjit;;context;;set_bool_option()}. +on the context using @ref{149,,gccjit;;context;;set_bool_option()}. @c (I'm deliberately not mentioning @c :c:macro:`GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE` here since I think @@ -9100,7 +9558,7 @@ square: By default, no optimizations are performed, the equivalent of GCC’s @cite{-O0} option. We can turn things up to e.g. @cite{-O3} by calling -@ref{13a,,gccjit;;context;;set_int_option()} with +@ref{14a,,gccjit;;context;;set_int_option()} with @ref{1f,,GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL}: @example @@ -9130,7 +9588,7 @@ square: Naturally this has only a small effect on such a trivial function. @node Full example<3>,,Options<3>,Tutorial part 2 Creating a trivial machine code function<2> -@anchor{cp/intro/tutorial02 full-example}@anchor{13b} +@anchor{cp/intro/tutorial02 full-example}@anchor{14b} @subsubsection Full example @@ -9268,7 +9726,7 @@ result: 25 @c . @node Tutorial part 3 Loops and variables<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2>,Tutorial part 2 Creating a trivial machine code function<2>,Tutorial<2> -@anchor{cp/intro/tutorial03 tutorial-part-3-loops-and-variables}@anchor{13c}@anchor{cp/intro/tutorial03 doc}@anchor{13d} +@anchor{cp/intro/tutorial03 doc}@anchor{14c}@anchor{cp/intro/tutorial03 tutorial-part-3-loops-and-variables}@anchor{14d} @subsection Tutorial part 3: Loops and variables @@ -9317,14 +9775,14 @@ Here’s what the final control flow graph will look like: @float Figure -@image{sum-of-squares,,,image of a control flow graph,png} +@image{libgccjit-figures/sum-of-squares,,,image of a control flow graph,png} @end float @end quotation As before, we include the libgccjit++ header and make a -@ref{12d,,gccjit;;context}. +@ref{13d,,gccjit;;context}. @example #include @@ -9378,18 +9836,18 @@ gccjit::function func = @end menu @node Expressions lvalues and rvalues<2>,Control flow<2>,,Tutorial part 3 Loops and variables<2> -@anchor{cp/intro/tutorial03 expressions-lvalues-and-rvalues}@anchor{13e} +@anchor{cp/intro/tutorial03 expressions-lvalues-and-rvalues}@anchor{14e} @subsubsection Expressions: lvalues and rvalues -The base class of expression is the @ref{136,,gccjit;;rvalue}, +The base class of expression is the @ref{146,,gccjit;;rvalue}, representing an expression that can be on the @emph{right}-hand side of an assignment: a value that can be computed somehow, and assigned @emph{to} a storage area (such as a variable). It has a specific -@ref{12f,,gccjit;;type}. +@ref{13f,,gccjit;;type}. -Anothe important class is @ref{13f,,gccjit;;lvalue}. -A @ref{13f,,gccjit;;lvalue}. is something that can of the @emph{left}-hand +Anothe important class is @ref{14f,,gccjit;;lvalue}. +A @ref{14f,,gccjit;;lvalue}. is something that can of the @emph{left}-hand side of an assignment: a storage area (such as a variable). In other words, every assignment can be thought of as: @@ -9398,8 +9856,8 @@ In other words, every assignment can be thought of as: LVALUE = RVALUE; @end example -Note that @ref{13f,,gccjit;;lvalue} is a subclass of -@ref{136,,gccjit;;rvalue}, where in an assignment of the form: +Note that @ref{14f,,gccjit;;lvalue} is a subclass of +@ref{146,,gccjit;;rvalue}, where in an assignment of the form: @example LVALUE_A = LVALUE_B; @@ -9429,7 +9887,7 @@ gccjit::rvalue expr = gccjit::rvalue expr = param_i * param_i; @end example -which is a @ref{136,,gccjit;;rvalue}, and +which is a @ref{146,,gccjit;;rvalue}, and @end quotation @@ -9437,15 +9895,15 @@ which is a @ref{136,,gccjit;;rvalue}, and @item the various function parameters: @cite{param_i} and @cite{param_n}, instances of -@ref{140,,gccjit;;param}, which is a subclass of @ref{13f,,gccjit;;lvalue} -(and, in turn, of @ref{136,,gccjit;;rvalue}): +@ref{150,,gccjit;;param}, which is a subclass of @ref{14f,,gccjit;;lvalue} +(and, in turn, of @ref{146,,gccjit;;rvalue}): we can both read from and write to function parameters within the body of a function. @end enumerate Our new example has a new kind of expression: we have two local variables. We create them by calling -@ref{141,,gccjit;;function;;new_local()}, supplying a type and a name: +@ref{151,,gccjit;;function;;new_local()}, supplying a type and a name: @example /* Build locals: */ @@ -9453,7 +9911,7 @@ gccjit::lvalue i = func.new_local (the_type, "i"); gccjit::lvalue sum = func.new_local (the_type, "sum"); @end example -These are instances of @ref{13f,,gccjit;;lvalue} - they can be read from +These are instances of @ref{14f,,gccjit;;lvalue} - they can be read from and written to. Note that there is no precanned way to create @emph{and} initialize a variable @@ -9467,7 +9925,7 @@ Instead, having added the local to the function, we have to separately add an assignment of @cite{0} to @cite{local_i} at the beginning of the function. @node Control flow<2>,Visualizing the control flow graph<2>,Expressions lvalues and rvalues<2>,Tutorial part 3 Loops and variables<2> -@anchor{cp/intro/tutorial03 control-flow}@anchor{142} +@anchor{cp/intro/tutorial03 control-flow}@anchor{152} @subsubsection Control flow @@ -9490,8 +9948,8 @@ the body of the loop after the loop terminates (@cite{return sum}) @end enumerate -so we create these as @ref{143,,gccjit;;block} instances within the -@ref{144,,gccjit;;function}: +so we create these as @ref{153,,gccjit;;block} instances within the +@ref{154,,gccjit;;function}: @example gccjit::block b_initial = func.new_block ("initial"); @@ -9504,8 +9962,8 @@ We now populate each block with statements. The entry block @cite{b_initial} consists of initializations followed by a jump to the conditional. We assign @cite{0} to @cite{i} and to @cite{sum}, using -@ref{145,,gccjit;;block;;add_assignment()} to add -an assignment statement, and using @ref{146,,gccjit;;context;;zero()} to get +@ref{155,,gccjit;;block;;add_assignment()} to add +an assignment statement, and using @ref{156,,gccjit;;context;;zero()} to get the constant value @cite{0} for the relevant type for the right-hand side of the assignment: @@ -9526,9 +9984,9 @@ b_initial.end_with_jump (b_loop_cond); The conditional block is equivalent to the line @cite{while (i < n)} from our C example. It contains a single statement: a conditional, which jumps to one of two destination blocks depending on a boolean -@ref{136,,gccjit;;rvalue}, in this case the comparison of @cite{i} and @cite{n}. +@ref{146,,gccjit;;rvalue}, in this case the comparison of @cite{i} and @cite{n}. -We could build the comparison using @ref{147,,gccjit;;context;;new_comparison()}: +We could build the comparison using @ref{157,,gccjit;;context;;new_comparison()}: @example gccjit::rvalue guard = @@ -9537,7 +9995,7 @@ gccjit::rvalue guard = @end example and can then use this to add @cite{b_loop_cond}’s sole statement, via -@ref{148,,gccjit;;block;;end_with_conditional()}: +@ref{158,,gccjit;;block;;end_with_conditional()}: @example b_loop_cond.end_with_conditional (guard, @@ -9545,7 +10003,7 @@ b_loop_cond.end_with_conditional (guard, b_loop_body); // on_false @end example -However @ref{136,,gccjit;;rvalue} has overloaded operators for this, so we +However @ref{146,,gccjit;;rvalue} has overloaded operators for this, so we express the conditional as @example @@ -9565,7 +10023,7 @@ Next, we populate the body of the loop. The C statement @cite{sum += i * i;} is an assignment operation, where an lvalue is modified “in-place”. We use -@ref{149,,gccjit;;block;;add_assignment_op()} to handle these operations: +@ref{159,,gccjit;;block;;add_assignment_op()} to handle these operations: @example /* sum += i * i */ @@ -9589,7 +10047,7 @@ b_loop_body.add_assignment_op (i, @cartouche @quotation Note For numeric constants other than 0 or 1, we could use -@ref{14a,,gccjit;;context;;new_rvalue()}, which has overloads +@ref{15a,,gccjit;;context;;new_rvalue()}, which has overloads for both @code{int} and @code{double}. @end quotation @end cartouche @@ -9655,12 +10113,12 @@ result: 285 @end example @node Visualizing the control flow graph<2>,Full example<4>,Control flow<2>,Tutorial part 3 Loops and variables<2> -@anchor{cp/intro/tutorial03 visualizing-the-control-flow-graph}@anchor{14b} +@anchor{cp/intro/tutorial03 visualizing-the-control-flow-graph}@anchor{15b} @subsubsection Visualizing the control flow graph You can see the control flow graph of a function using -@ref{14c,,gccjit;;function;;dump_to_dot()}: +@ref{15c,,gccjit;;function;;dump_to_dot()}: @example func.dump_to_dot ("/tmp/sum-of-squares.dot"); @@ -9683,14 +10141,14 @@ install it with @cite{yum install python-xdot}): @float Figure -@image{sum-of-squares,,,image of a control flow graph,png} +@image{libgccjit-figures/sum-of-squares,,,image of a control flow graph,png} @end float @end quotation @node Full example<4>,,Visualizing the control flow graph<2>,Tutorial part 3 Loops and variables<2> -@anchor{cp/intro/tutorial03 full-example}@anchor{14d} +@anchor{cp/intro/tutorial03 full-example}@anchor{15d} @subsubsection Full example @@ -9868,7 +10326,7 @@ loop_test returned: 285 @c . @node Tutorial part 4 Adding JIT-compilation to a toy interpreter<2>,,Tutorial part 3 Loops and variables<2>,Tutorial<2> -@anchor{cp/intro/tutorial04 tutorial-part-4-adding-jit-compilation-to-a-toy-interpreter}@anchor{14e}@anchor{cp/intro/tutorial04 doc}@anchor{14f} +@anchor{cp/intro/tutorial04 doc}@anchor{15e}@anchor{cp/intro/tutorial04 tutorial-part-4-adding-jit-compilation-to-a-toy-interpreter}@anchor{15f} @subsection Tutorial part 4: Adding JIT-compilation to a toy interpreter @@ -9890,7 +10348,7 @@ to it. @end menu @node Our toy interpreter<2>,Compiling to machine code<2>,,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 our-toy-interpreter}@anchor{150} +@anchor{cp/intro/tutorial04 our-toy-interpreter}@anchor{160} @subsubsection Our toy interpreter @@ -10292,7 +10750,7 @@ toyvm_function::interpret (int arg, FILE *trace) @end quotation @node Compiling to machine code<2>,Setting things up<2>,Our toy interpreter<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 compiling-to-machine-code}@anchor{151} +@anchor{cp/intro/tutorial04 compiling-to-machine-code}@anchor{161} @subsubsection Compiling to machine code @@ -10362,7 +10820,7 @@ This means our compiler has the following state: @end quotation @node Setting things up<2>,Populating the function<2>,Compiling to machine code<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 setting-things-up}@anchor{152} +@anchor{cp/intro/tutorial04 setting-things-up}@anchor{162} @subsubsection Setting things up @@ -10452,7 +10910,7 @@ compilation_state::add_pop (gccjit::block block, @end quotation We will support single-stepping through the generated code in the -debugger, so we need to create @ref{153,,gccjit;;location} instances, one +debugger, so we need to create @ref{163,,gccjit;;location} instances, one per operation in the source code. These will reference the lines of e.g. @code{factorial.toy}. @@ -10512,7 +10970,7 @@ We create the locals within the function. @end quotation @node Populating the function<2>,Verifying the control flow graph<2>,Setting things up<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 populating-the-function}@anchor{154} +@anchor{cp/intro/tutorial04 populating-the-function}@anchor{164} @subsubsection Populating the function @@ -10625,7 +11083,7 @@ stack into @code{y} instead erroneously assigned it to @code{x}, leaving @code{y uninitialized. To track this kind of thing down, we can use -@ref{155,,gccjit;;block;;add_comment()} to add descriptive comments +@ref{165,,gccjit;;block;;add_comment()} to add descriptive comments to the internal representation. This is invaluable when looking through the generated IR for, say @code{factorial}: @@ -10765,14 +11223,14 @@ to the next block. This is analogous to simply incrementing the program counter. @node Verifying the control flow graph<2>,Compiling the context<2>,Populating the function<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 verifying-the-control-flow-graph}@anchor{156} +@anchor{cp/intro/tutorial04 verifying-the-control-flow-graph}@anchor{166} @subsubsection Verifying the control flow graph Having finished looping over the blocks, the context is complete. As before, we can verify that the control flow and statements are sane by -using @ref{14c,,gccjit;;function;;dump_to_dot()}: +using @ref{15c,,gccjit;;function;;dump_to_dot()}: @example fn.dump_to_dot ("/tmp/factorial.dot"); @@ -10787,14 +11245,14 @@ errors in our compiler. @float Figure -@image{factorial,,,image of a control flow graph,png} +@image{libgccjit-figures/factorial,,,image of a control flow graph,png} @end float @end quotation @node Compiling the context<2>,Single-stepping through the generated code<2>,Verifying the control flow graph<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 compiling-the-context}@anchor{157} +@anchor{cp/intro/tutorial04 compiling-the-context}@anchor{167} @subsubsection Compiling the context @@ -10845,7 +11303,7 @@ private: @end quotation @node Single-stepping through the generated code<2>,Examining the generated code<2>,Compiling the context<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 single-stepping-through-the-generated-code}@anchor{158} +@anchor{cp/intro/tutorial04 single-stepping-through-the-generated-code}@anchor{168} @subsubsection Single-stepping through the generated code @@ -10859,14 +11317,14 @@ It’s possible to debug the generated code. To do this we need to both: @item Set up source code locations for our statements, so that we can meaningfully step through the code. We did this above by -calling @ref{159,,gccjit;;context;;new_location()} and using the +calling @ref{169,,gccjit;;context;;new_location()} and using the results. @item Enable the generation of debugging information, by setting @ref{42,,GCC_JIT_BOOL_OPTION_DEBUGINFO} on the -@ref{12d,,gccjit;;context} via -@ref{139,,gccjit;;context;;set_bool_option()}: +@ref{13d,,gccjit;;context} via +@ref{149,,gccjit;;context;;set_bool_option()}: @example ctxt.set_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO, 1); @@ -10930,14 +11388,14 @@ optimization level in a regular compiler. @end cartouche @node Examining the generated code<2>,Putting it all together<2>,Single-stepping through the generated code<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 examining-the-generated-code}@anchor{15a} +@anchor{cp/intro/tutorial04 examining-the-generated-code}@anchor{16a} @subsubsection Examining the generated code How good is the optimized code? We can turn up optimizations, by calling -@ref{13a,,gccjit;;context;;set_int_option()} with +@ref{14a,,gccjit;;context;;set_int_option()} with @ref{1f,,GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL}: @example @@ -11105,7 +11563,7 @@ Note that the stack pushing and popping have been eliminated, as has the recursive call (in favor of an iteration). @node Putting it all together<2>,Behind the curtain How does our code get optimized?<2>,Examining the generated code<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 putting-it-all-together}@anchor{15b} +@anchor{cp/intro/tutorial04 putting-it-all-together}@anchor{16b} @subsubsection Putting it all together @@ -11136,7 +11594,7 @@ compiler result: 55 @end example @node Behind the curtain How does our code get optimized?<2>,,Putting it all together<2>,Tutorial part 4 Adding JIT-compilation to a toy interpreter<2> -@anchor{cp/intro/tutorial04 behind-the-curtain-how-does-our-code-get-optimized}@anchor{15c} +@anchor{cp/intro/tutorial04 behind-the-curtain-how-does-our-code-get-optimized}@anchor{16c} @subsubsection Behind the curtain: How does our code get optimized? @@ -11314,7 +11772,7 @@ instr9: @} @end example -Note in the above how all the @ref{143,,gccjit;;block} instances we +Note in the above how all the @ref{153,,gccjit;;block} instances we created have been consolidated into just 3 blocks in GCC’s internal representation: @code{initial}, @code{instr4} and @code{instr9}. @@ -11325,7 +11783,7 @@ representation: @code{initial}, @code{instr4} and @code{instr9}. @end menu @node Optimizing away stack manipulation<2>,Elimination of tail recursion<2>,,Behind the curtain How does our code get optimized?<2> -@anchor{cp/intro/tutorial04 optimizing-away-stack-manipulation}@anchor{15d} +@anchor{cp/intro/tutorial04 optimizing-away-stack-manipulation}@anchor{16d} @subsubsection Optimizing away stack manipulation @@ -11589,7 +12047,7 @@ instr9: @end example @node Elimination of tail recursion<2>,,Optimizing away stack manipulation<2>,Behind the curtain How does our code get optimized?<2> -@anchor{cp/intro/tutorial04 elimination-of-tail-recursion}@anchor{15e} +@anchor{cp/intro/tutorial04 elimination-of-tail-recursion}@anchor{16e} @subsubsection Elimination of tail recursion @@ -11672,7 +12130,7 @@ instr9: @c . @node Topic Reference<2>,,Tutorial<2>,C++ bindings for libgccjit -@anchor{cp/topics/index doc}@anchor{15f}@anchor{cp/topics/index topic-reference}@anchor{160} +@anchor{cp/topics/index doc}@anchor{16f}@anchor{cp/topics/index topic-reference}@anchor{170} @section Topic Reference @@ -11701,26 +12159,27 @@ instr9: * Creating and using functions: Creating and using functions<2>. * Source Locations: Source Locations<2>. * Compiling a context: Compiling a context<2>. +* Using Assembly Language with libgccjit++:: @end menu @node Compilation contexts<2>,Objects<2>,,Topic Reference<2> -@anchor{cp/topics/contexts compilation-contexts}@anchor{161}@anchor{cp/topics/contexts doc}@anchor{162} +@anchor{cp/topics/contexts doc}@anchor{171}@anchor{cp/topics/contexts compilation-contexts}@anchor{172} @subsection Compilation contexts @geindex gccjit;;context (C++ class) -@anchor{cp/topics/contexts _CPPv2N6gccjit7contextE}@anchor{12d}@anchor{cp/topics/contexts gccjit context}@anchor{163} +@anchor{cp/topics/contexts _CPPv4N6gccjit7contextE}@anchor{13d}@anchor{cp/topics/contexts _CPPv3N6gccjit7contextE}@anchor{173}@anchor{cp/topics/contexts _CPPv2N6gccjit7contextE}@anchor{174}@anchor{cp/topics/contexts gccjit context}@anchor{175} @deffn {C++ Class} gccjit::context @end deffn -The top-level of the C++ API is the @ref{12d,,gccjit;;context} type. +The top-level of the C++ API is the @ref{13d,,gccjit;;context} type. -A @ref{12d,,gccjit;;context} instance encapsulates the state of a +A @ref{13d,,gccjit;;context} instance encapsulates the state of a compilation. You can set up options on it, and add types, functions and code. -Invoking @ref{137,,gccjit;;context;;compile()} on it gives you a +Invoking @ref{147,,gccjit;;context;;compile()} on it gives you a @ref{16,,gcc_jit_result *}. It is a thin wrapper around the C API’s @ref{8,,gcc_jit_context *}. @@ -11735,7 +12194,7 @@ It is a thin wrapper around the C API’s @ref{8,,gcc_jit_context *}. @end menu @node Lifetime-management<2>,Thread-safety<2>,,Compilation contexts<2> -@anchor{cp/topics/contexts lifetime-management}@anchor{164} +@anchor{cp/topics/contexts lifetime-management}@anchor{176} @subsubsection Lifetime-management @@ -11744,17 +12203,17 @@ have their lifetime bounded by the context they are created within, and cleanup of such objects is done for you when the context is released. @geindex gccjit;;context;;acquire (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context7acquireEv}@anchor{12e}@anchor{cp/topics/contexts gccjit context acquire}@anchor{165} -@deffn {C++ Function} gccjit::@ref{12d,,context} gccjit::context::acquire () +@anchor{cp/topics/contexts _CPPv4N6gccjit7context7acquireEv}@anchor{13e}@anchor{cp/topics/contexts _CPPv3N6gccjit7context7acquireEv}@anchor{177}@anchor{cp/topics/contexts _CPPv2N6gccjit7context7acquireEv}@anchor{178}@anchor{cp/topics/contexts gccjit context acquire}@anchor{179} +@deffn {C++ Function} gccjit::@ref{13d,,context} gccjit::@ref{13d,,context}::acquire () -This function acquires a new @ref{12d,,gccjit;;context} instance, +This function acquires a new @ref{13d,,gccjit;;context} instance, which is independent of any others that may be present within this process. @end deffn @geindex gccjit;;context;;release (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context7releaseEv}@anchor{131}@anchor{cp/topics/contexts gccjit context release}@anchor{166} -@deffn {C++ Function} void gccjit::context::release () +@anchor{cp/topics/contexts _CPPv4N6gccjit7context7releaseEv}@anchor{141}@anchor{cp/topics/contexts _CPPv3N6gccjit7context7releaseEv}@anchor{17a}@anchor{cp/topics/contexts _CPPv2N6gccjit7context7releaseEv}@anchor{17b}@anchor{cp/topics/contexts gccjit context release}@anchor{17c} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::release () This function releases all resources associated with the given context. Both the context itself and all of its @code{gccjit::object *} @@ -11770,8 +12229,8 @@ ctxt.release (); @end deffn @geindex gccjit;;context;;new_child_context (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context17new_child_contextEv}@anchor{167}@anchor{cp/topics/contexts gccjit context new_child_context}@anchor{168} -@deffn {C++ Function} gccjit::@ref{12d,,context} gccjit::context::new_child_context () +@anchor{cp/topics/contexts _CPPv4N6gccjit7context17new_child_contextEv}@anchor{17d}@anchor{cp/topics/contexts _CPPv3N6gccjit7context17new_child_contextEv}@anchor{17e}@anchor{cp/topics/contexts _CPPv2N6gccjit7context17new_child_contextEv}@anchor{17f}@anchor{cp/topics/contexts gccjit context new_child_context}@anchor{180} +@deffn {C++ Function} gccjit::@ref{13d,,context} gccjit::@ref{13d,,context}::new_child_context () Given an existing JIT context, create a child context. @@ -11802,16 +12261,16 @@ there will likely be a performance hit for such nesting. @end deffn @node Thread-safety<2>,Error-handling<3>,Lifetime-management<2>,Compilation contexts<2> -@anchor{cp/topics/contexts thread-safety}@anchor{169} +@anchor{cp/topics/contexts thread-safety}@anchor{181} @subsubsection Thread-safety -Instances of @ref{12d,,gccjit;;context} created via -@ref{12e,,gccjit;;context;;acquire()} are independent from each other: +Instances of @ref{13d,,gccjit;;context} created via +@ref{13e,,gccjit;;context;;acquire()} are independent from each other: only one thread may use a given context at once, but multiple threads could each have their own contexts without needing locks. -Contexts created via @ref{167,,gccjit;;context;;new_child_context()} are +Contexts created via @ref{17d,,gccjit;;context;;new_child_context()} are related to their parent context. They can be partitioned by their ultimate ancestor into independent “family trees”. Only one thread within a process may use a given “family tree” of such contexts at once, @@ -11819,7 +12278,7 @@ and if you’re using multiple threads you should provide your own locking around entire such context partitions. @node Error-handling<3>,Debugging<2>,Thread-safety<2>,Compilation contexts<2> -@anchor{cp/topics/contexts error-handling}@anchor{16a} +@anchor{cp/topics/contexts error-handling}@anchor{182} @subsubsection Error-handling @@ -11832,11 +12291,11 @@ NULL. You don’t have to check everywhere for NULL results, since the API gracefully handles a NULL being passed in for any argument. Errors are printed on stderr and can be queried using -@ref{16b,,gccjit;;context;;get_first_error()}. +@ref{183,,gccjit;;context;;get_first_error()}. @geindex gccjit;;context;;get_first_error (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context15get_first_errorEPN6gccjit7contextE}@anchor{16b}@anchor{cp/topics/contexts gccjit context get_first_error__gccjit contextP}@anchor{16c} -@deffn {C++ Function} const char *gccjit::context::get_first_error (gccjit::context *ctxt) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context15get_first_errorEPN6gccjit7contextE}@anchor{183}@anchor{cp/topics/contexts _CPPv3N6gccjit7context15get_first_errorEPN6gccjit7contextE}@anchor{184}@anchor{cp/topics/contexts _CPPv2N6gccjit7context15get_first_errorEPN6gccjit7contextE}@anchor{185}@anchor{cp/topics/contexts gccjit context get_first_error__gccjit contextP}@anchor{186} +@deffn {C++ Function} const char *gccjit::@ref{13d,,context}::get_first_error (gccjit::context *ctxt) Returns the first error message that occurred on the context. @@ -11847,18 +12306,18 @@ If no errors occurred, this will be NULL. @end deffn @node Debugging<2>,Options<4>,Error-handling<3>,Compilation contexts<2> -@anchor{cp/topics/contexts debugging}@anchor{16d} +@anchor{cp/topics/contexts debugging}@anchor{187} @subsubsection Debugging @geindex gccjit;;context;;dump_to_file (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context12dump_to_fileERKNSt6stringEi}@anchor{16e}@anchor{cp/topics/contexts gccjit context dump_to_file__ssCR i}@anchor{16f} -@deffn {C++ Function} void gccjit::context::dump_to_file (const std::string &path, int update_locations) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context12dump_to_fileERKNSt6stringEi}@anchor{188}@anchor{cp/topics/contexts _CPPv3N6gccjit7context12dump_to_fileERKNSt6stringEi}@anchor{189}@anchor{cp/topics/contexts _CPPv2N6gccjit7context12dump_to_fileERKNSt6stringEi}@anchor{18a}@anchor{cp/topics/contexts gccjit context dump_to_file__ssCR i}@anchor{18b} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::dump_to_file (const std::string &path, int update_locations) To help with debugging: dump a C-like representation to the given path, describing what’s been set up on the context. -If “update_locations” is true, then also set up @ref{153,,gccjit;;location} +If “update_locations” is true, then also set up @ref{163,,gccjit;;location} information throughout the context, pointing at the dump file as if it were a source file. This may be of use in conjunction with @code{GCCJIT::BOOL_OPTION_DEBUGINFO} to allow stepping through the @@ -11866,8 +12325,8 @@ code in a debugger. @end deffn @geindex gccjit;;context;;dump_reproducer_to_file (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context23dump_reproducer_to_fileEP15gcc_jit_contextPKc}@anchor{170}@anchor{cp/topics/contexts gccjit context dump_reproducer_to_file__gcc_jit_contextP cCP}@anchor{171} -@deffn {C++ Function} void gccjit::context::dump_reproducer_to_file (gcc_jit_context *ctxt, const char *path) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context23dump_reproducer_to_fileEP15gcc_jit_contextPKc}@anchor{18c}@anchor{cp/topics/contexts _CPPv3N6gccjit7context23dump_reproducer_to_fileEP15gcc_jit_contextPKc}@anchor{18d}@anchor{cp/topics/contexts _CPPv2N6gccjit7context23dump_reproducer_to_fileEP15gcc_jit_contextPKc}@anchor{18e}@anchor{cp/topics/contexts gccjit context dump_reproducer_to_file__gcc_jit_contextP cCP}@anchor{18f} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::dump_reproducer_to_file (gcc_jit_context *ctxt, const char *path) This is a thin wrapper around the C API @ref{5d,,gcc_jit_context_dump_reproducer_to_file()}, and hence works the @@ -11878,7 +12337,7 @@ for seeing what the C++ bindings are doing at the C level. @end deffn @node Options<4>,,Debugging<2>,Compilation contexts<2> -@anchor{cp/topics/contexts options}@anchor{172} +@anchor{cp/topics/contexts options}@anchor{190} @subsubsection Options @@ -11891,13 +12350,13 @@ for seeing what the C++ bindings are doing at the C level. @end menu @node String Options<2>,Boolean options<2>,,Options<4> -@anchor{cp/topics/contexts string-options}@anchor{173} +@anchor{cp/topics/contexts string-options}@anchor{191} @subsubsection String Options @geindex gccjit;;context;;set_str_option (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context14set_str_optionE18gcc_jit_str_optionPKc}@anchor{174}@anchor{cp/topics/contexts gccjit context set_str_option__gcc_jit_str_option cCP}@anchor{175} -@deffn {C++ Function} void gccjit::context::set_str_option (enum gcc_jit_str_option, const char *value) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context14set_str_optionE18gcc_jit_str_optionPKc}@anchor{192}@anchor{cp/topics/contexts _CPPv3N6gccjit7context14set_str_optionE18gcc_jit_str_optionPKc}@anchor{193}@anchor{cp/topics/contexts _CPPv2N6gccjit7context14set_str_optionE18gcc_jit_str_optionPKc}@anchor{194}@anchor{cp/topics/contexts gccjit context set_str_option__gcc_jit_str_option cCP}@anchor{195} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::set_str_option (enum gcc_jit_str_option, const char *value) Set a string option of the context. @@ -11907,13 +12366,13 @@ meaning. @end deffn @node Boolean options<2>,Integer options<2>,String Options<2>,Options<4> -@anchor{cp/topics/contexts boolean-options}@anchor{176} +@anchor{cp/topics/contexts boolean-options}@anchor{196} @subsubsection Boolean options @geindex gccjit;;context;;set_bool_option (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context15set_bool_optionE19gcc_jit_bool_optioni}@anchor{139}@anchor{cp/topics/contexts gccjit context set_bool_option__gcc_jit_bool_option i}@anchor{177} -@deffn {C++ Function} void gccjit::context::set_bool_option (enum gcc_jit_bool_option, int value) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context15set_bool_optionE19gcc_jit_bool_optioni}@anchor{149}@anchor{cp/topics/contexts _CPPv3N6gccjit7context15set_bool_optionE19gcc_jit_bool_optioni}@anchor{197}@anchor{cp/topics/contexts _CPPv2N6gccjit7context15set_bool_optionE19gcc_jit_bool_optioni}@anchor{198}@anchor{cp/topics/contexts gccjit context set_bool_option__gcc_jit_bool_option i}@anchor{199} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::set_bool_option (enum gcc_jit_bool_option, int value) Set a boolean option of the context. @@ -11923,8 +12382,8 @@ meaning. @end deffn @geindex gccjit;;context;;set_bool_allow_unreachable_blocks (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context33set_bool_allow_unreachable_blocksEi}@anchor{178}@anchor{cp/topics/contexts gccjit context set_bool_allow_unreachable_blocks__i}@anchor{179} -@deffn {C++ Function} void gccjit::context::set_bool_allow_unreachable_blocks (int bool_value) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context33set_bool_allow_unreachable_blocksEi}@anchor{19a}@anchor{cp/topics/contexts _CPPv3N6gccjit7context33set_bool_allow_unreachable_blocksEi}@anchor{19b}@anchor{cp/topics/contexts _CPPv2N6gccjit7context33set_bool_allow_unreachable_blocksEi}@anchor{19c}@anchor{cp/topics/contexts gccjit context set_bool_allow_unreachable_blocks__i}@anchor{19d} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::set_bool_allow_unreachable_blocks (int bool_value) By default, libgccjit will issue an error about unreachable blocks within a function. @@ -11942,8 +12401,8 @@ its presence using @end deffn @geindex gccjit;;context;;set_bool_use_external_driver (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context28set_bool_use_external_driverEi}@anchor{17a}@anchor{cp/topics/contexts gccjit context set_bool_use_external_driver__i}@anchor{17b} -@deffn {C++ Function} void gccjit::context::set_bool_use_external_driver (int bool_value) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context28set_bool_use_external_driverEi}@anchor{19e}@anchor{cp/topics/contexts _CPPv3N6gccjit7context28set_bool_use_external_driverEi}@anchor{19f}@anchor{cp/topics/contexts _CPPv2N6gccjit7context28set_bool_use_external_driverEi}@anchor{1a0}@anchor{cp/topics/contexts gccjit context set_bool_use_external_driver__i}@anchor{1a1} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::set_bool_use_external_driver (int bool_value) libgccjit internally generates assembler, and uses “driver” code for converting it to other formats (e.g. shared libraries). @@ -11964,13 +12423,13 @@ its presence using @end deffn @node Integer options<2>,Additional command-line options<2>,Boolean options<2>,Options<4> -@anchor{cp/topics/contexts integer-options}@anchor{17c} +@anchor{cp/topics/contexts integer-options}@anchor{1a2} @subsubsection Integer options @geindex gccjit;;context;;set_int_option (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context14set_int_optionE18gcc_jit_int_optioni}@anchor{13a}@anchor{cp/topics/contexts gccjit context set_int_option__gcc_jit_int_option i}@anchor{17d} -@deffn {C++ Function} void gccjit::context::set_int_option (enum gcc_jit_int_option, int value) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context14set_int_optionE18gcc_jit_int_optioni}@anchor{14a}@anchor{cp/topics/contexts _CPPv3N6gccjit7context14set_int_optionE18gcc_jit_int_optioni}@anchor{1a3}@anchor{cp/topics/contexts _CPPv2N6gccjit7context14set_int_optionE18gcc_jit_int_optioni}@anchor{1a4}@anchor{cp/topics/contexts gccjit context set_int_option__gcc_jit_int_option i}@anchor{1a5} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::set_int_option (enum gcc_jit_int_option, int value) Set an integer option of the context. @@ -11980,13 +12439,13 @@ meaning. @end deffn @node Additional command-line options<2>,,Integer options<2>,Options<4> -@anchor{cp/topics/contexts additional-command-line-options}@anchor{17e} +@anchor{cp/topics/contexts additional-command-line-options}@anchor{1a6} @subsubsection Additional command-line options @geindex gccjit;;context;;add_command_line_option (C++ function) -@anchor{cp/topics/contexts _CPPv2N6gccjit7context23add_command_line_optionEPKc}@anchor{17f}@anchor{cp/topics/contexts gccjit context add_command_line_option__cCP}@anchor{180} -@deffn {C++ Function} void gccjit::context::add_command_line_option (const char *optname) +@anchor{cp/topics/contexts _CPPv4N6gccjit7context23add_command_line_optionEPKc}@anchor{1a7}@anchor{cp/topics/contexts _CPPv3N6gccjit7context23add_command_line_optionEPKc}@anchor{1a8}@anchor{cp/topics/contexts _CPPv2N6gccjit7context23add_command_line_optionEPKc}@anchor{1a9}@anchor{cp/topics/contexts gccjit context add_command_line_option__cCP}@anchor{1aa} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::add_command_line_option (const char *optname) Add an arbitrary gcc command-line option to the context for use when compiling. @@ -12020,18 +12479,18 @@ its presence using @c . @node Objects<2>,Types<2>,Compilation contexts<2>,Topic Reference<2> -@anchor{cp/topics/objects objects}@anchor{181}@anchor{cp/topics/objects doc}@anchor{182} +@anchor{cp/topics/objects doc}@anchor{1ab}@anchor{cp/topics/objects objects}@anchor{1ac} @subsection Objects @geindex gccjit;;object (C++ class) -@anchor{cp/topics/objects _CPPv2N6gccjit6objectE}@anchor{132}@anchor{cp/topics/objects gccjit object}@anchor{183} +@anchor{cp/topics/objects _CPPv4N6gccjit6objectE}@anchor{142}@anchor{cp/topics/objects _CPPv3N6gccjit6objectE}@anchor{1ad}@anchor{cp/topics/objects _CPPv2N6gccjit6objectE}@anchor{1ae}@anchor{cp/topics/objects gccjit object}@anchor{1af} @deffn {C++ Class} gccjit::object @end deffn Almost every entity in the API (with the exception of -@ref{12d,,gccjit;;context} and @ref{16,,gcc_jit_result *}) is a -“contextual” object, a @ref{132,,gccjit;;object}. +@ref{13d,,gccjit;;context} and @ref{16,,gcc_jit_result *}) is a +“contextual” object, a @ref{142,,gccjit;;object}. A JIT object: @@ -12041,7 +12500,7 @@ A JIT object: @itemize * @item -is associated with a @ref{12d,,gccjit;;context}. +is associated with a @ref{13d,,gccjit;;context}. @item is automatically cleaned up for you when its context is released so @@ -12066,18 +12525,18 @@ The C++ class hierarchy within the @code{gccjit} namespace looks like this: +- case_ @end example -The @ref{132,,gccjit;;object} base class has the following operations: +The @ref{142,,gccjit;;object} base class has the following operations: @geindex gccjit;;object;;get_context (C++ function) -@anchor{cp/topics/objects _CPPv2NK6gccjit6object11get_contextEv}@anchor{184}@anchor{cp/topics/objects gccjit object get_contextC}@anchor{185} -@deffn {C++ Function} gccjit::@ref{12d,,context} gccjit::object::get_context () const +@anchor{cp/topics/objects _CPPv4NK6gccjit6object11get_contextEv}@anchor{1b0}@anchor{cp/topics/objects _CPPv3NK6gccjit6object11get_contextEv}@anchor{1b1}@anchor{cp/topics/objects _CPPv2NK6gccjit6object11get_contextEv}@anchor{1b2}@anchor{cp/topics/objects gccjit object get_contextC}@anchor{1b3} +@deffn {C++ Function} gccjit::@ref{13d,,context} gccjit::@ref{142,,object}::get_context () const Which context is the obj within? @end deffn @geindex gccjit;;object;;get_debug_string (C++ function) -@anchor{cp/topics/objects _CPPv2NK6gccjit6object16get_debug_stringEv}@anchor{133}@anchor{cp/topics/objects gccjit object get_debug_stringC}@anchor{186} -@deffn {C++ Function} std::string gccjit::object::get_debug_string () const +@anchor{cp/topics/objects _CPPv4NK6gccjit6object16get_debug_stringEv}@anchor{143}@anchor{cp/topics/objects _CPPv3NK6gccjit6object16get_debug_stringEv}@anchor{1b4}@anchor{cp/topics/objects _CPPv2NK6gccjit6object16get_debug_stringEv}@anchor{1b5}@anchor{cp/topics/objects gccjit object get_debug_stringC}@anchor{1b6} +@deffn {C++ Function} std::string gccjit::@ref{142,,object}::get_debug_string () const Generate a human-readable description for the given object. @@ -12112,16 +12571,16 @@ obj: 4.0 * (float)i @c . @node Types<2>,Expressions<2>,Objects<2>,Topic Reference<2> -@anchor{cp/topics/types doc}@anchor{187}@anchor{cp/topics/types types}@anchor{188} +@anchor{cp/topics/types doc}@anchor{1b7}@anchor{cp/topics/types types}@anchor{1b8} @subsection Types @geindex gccjit;;type (C++ class) -@anchor{cp/topics/types _CPPv2N6gccjit4typeE}@anchor{12f}@anchor{cp/topics/types gccjit type}@anchor{189} +@anchor{cp/topics/types _CPPv4N6gccjit4typeE}@anchor{13f}@anchor{cp/topics/types _CPPv3N6gccjit4typeE}@anchor{1b9}@anchor{cp/topics/types _CPPv2N6gccjit4typeE}@anchor{1ba}@anchor{cp/topics/types gccjit type}@anchor{1bb} @deffn {C++ Class} gccjit::type gccjit::type represents a type within the library. It is a subclass -of @ref{132,,gccjit;;object}. +of @ref{142,,gccjit;;object}. @end deffn Types can be created in several ways: @@ -12131,7 +12590,7 @@ Types can be created in several ways: @item fundamental types can be accessed using -@ref{130,,gccjit;;context;;get_type()}: +@ref{140,,gccjit;;context;;get_type()}: @example gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT); @@ -12147,7 +12606,7 @@ See @ref{b,,gcc_jit_context_get_type()} for the available types. @item derived types can be accessed by using functions such as -@ref{18a,,gccjit;;type;;get_pointer()} and @ref{18b,,gccjit;;type;;get_const()}: +@ref{1bc,,gccjit;;type;;get_pointer()} and @ref{1bd,,gccjit;;type;;get_const()}: @example gccjit::type const_int_star = int_type.get_const ().get_pointer (); @@ -12167,28 +12626,28 @@ by creating structures (see below). @end menu @node Standard types<2>,Pointers const and volatile<2>,,Types<2> -@anchor{cp/topics/types standard-types}@anchor{18c} +@anchor{cp/topics/types standard-types}@anchor{1be} @subsubsection Standard types @geindex gccjit;;context;;get_type (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context8get_typeE13gcc_jit_types}@anchor{130}@anchor{cp/topics/types gccjit context get_type__gcc_jit_types}@anchor{18d} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::context::get_type (enum gcc_jit_types) +@anchor{cp/topics/types _CPPv4N6gccjit7context8get_typeE13gcc_jit_types}@anchor{140}@anchor{cp/topics/types _CPPv3N6gccjit7context8get_typeE13gcc_jit_types}@anchor{1bf}@anchor{cp/topics/types _CPPv2N6gccjit7context8get_typeE13gcc_jit_types}@anchor{1c0}@anchor{cp/topics/types gccjit context get_type__gcc_jit_types}@anchor{1c1} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13d,,context}::get_type (enum gcc_jit_types) Access a specific type. This is a thin wrapper around @ref{b,,gcc_jit_context_get_type()}; the parameter has the same meaning. @end deffn @geindex gccjit;;context;;get_int_type (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context12get_int_typeE6size_ti}@anchor{18e}@anchor{cp/topics/types gccjit context get_int_type__s i}@anchor{18f} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::context::get_int_type (size_t num_bytes, int is_signed) +@anchor{cp/topics/types _CPPv4N6gccjit7context12get_int_typeE6size_ti}@anchor{1c2}@anchor{cp/topics/types _CPPv3N6gccjit7context12get_int_typeE6size_ti}@anchor{1c3}@anchor{cp/topics/types _CPPv2N6gccjit7context12get_int_typeE6size_ti}@anchor{1c4}@anchor{cp/topics/types gccjit context get_int_type__s i}@anchor{1c5} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13d,,context}::get_int_type (size_t num_bytes, int is_signed) Access the integer type of the given size. @end deffn @geindex gccjit;;context;;get_int_type (C++ function) -@anchor{cp/topics/types _CPPv2IEN6gccjit7context12get_int_typeI1TEEv}@anchor{190} -@deffn {C++ Function} template<>gccjit::@ref{12f,,type} gccjit::context::get_int_type () +@anchor{cp/topics/types _CPPv4IEN6gccjit7context12get_int_typeI1TEEN6gccjit4typeEv}@anchor{1c6}@anchor{cp/topics/types _CPPv3IEN6gccjit7context12get_int_typeI1TEEv}@anchor{1c7}@anchor{cp/topics/types _CPPv2IEN6gccjit7context12get_int_typeI1TEEv}@anchor{1c8} +@deffn {C++ Function} template<>gccjit::@ref{13f,,type} gccjit::@ref{13d,,context}::get_int_type () Access the given integer type. For example, you could map the @code{unsigned short} type into a gccjit::type via: @@ -12199,34 +12658,34 @@ gccjit::type t = ctxt.get_int_type (); @end deffn @node Pointers const and volatile<2>,Vector types<2>,Standard types<2>,Types<2> -@anchor{cp/topics/types pointers-const-and-volatile}@anchor{191} +@anchor{cp/topics/types pointers-const-and-volatile}@anchor{1c9} @subsubsection Pointers, @cite{const}, and @cite{volatile} @geindex gccjit;;type;;get_pointer (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit4type11get_pointerEv}@anchor{18a}@anchor{cp/topics/types gccjit type get_pointer}@anchor{192} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::type::get_pointer () +@anchor{cp/topics/types _CPPv4N6gccjit4type11get_pointerEv}@anchor{1bc}@anchor{cp/topics/types _CPPv3N6gccjit4type11get_pointerEv}@anchor{1ca}@anchor{cp/topics/types _CPPv2N6gccjit4type11get_pointerEv}@anchor{1cb}@anchor{cp/topics/types gccjit type get_pointer}@anchor{1cc} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13f,,type}::get_pointer () Given type “T”, get type “T*”. @end deffn @geindex gccjit;;type;;get_const (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit4type9get_constEv}@anchor{18b}@anchor{cp/topics/types gccjit type get_const}@anchor{193} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::type::get_const () +@anchor{cp/topics/types _CPPv4N6gccjit4type9get_constEv}@anchor{1bd}@anchor{cp/topics/types _CPPv3N6gccjit4type9get_constEv}@anchor{1cd}@anchor{cp/topics/types _CPPv2N6gccjit4type9get_constEv}@anchor{1ce}@anchor{cp/topics/types gccjit type get_const}@anchor{1cf} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13f,,type}::get_const () Given type “T”, get type “const T”. @end deffn @geindex gccjit;;type;;get_volatile (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit4type12get_volatileEv}@anchor{194}@anchor{cp/topics/types gccjit type get_volatile}@anchor{195} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::type::get_volatile () +@anchor{cp/topics/types _CPPv4N6gccjit4type12get_volatileEv}@anchor{1d0}@anchor{cp/topics/types _CPPv3N6gccjit4type12get_volatileEv}@anchor{1d1}@anchor{cp/topics/types _CPPv2N6gccjit4type12get_volatileEv}@anchor{1d2}@anchor{cp/topics/types gccjit type get_volatile}@anchor{1d3} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13f,,type}::get_volatile () Given type “T”, get type “volatile T”. @end deffn @geindex gccjit;;type;;get_aligned (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit4type11get_alignedE6size_t}@anchor{196}@anchor{cp/topics/types gccjit type get_aligned__s}@anchor{197} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::type::get_aligned (size_t alignment_in_bytes) +@anchor{cp/topics/types _CPPv4N6gccjit4type11get_alignedE6size_t}@anchor{1d4}@anchor{cp/topics/types _CPPv3N6gccjit4type11get_alignedE6size_t}@anchor{1d5}@anchor{cp/topics/types _CPPv2N6gccjit4type11get_alignedE6size_t}@anchor{1d6}@anchor{cp/topics/types gccjit type get_aligned__s}@anchor{1d7} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13f,,type}::get_aligned (size_t alignment_in_bytes) Given type “T”, get type: @@ -12238,21 +12697,21 @@ The alignment must be a power of two. @end deffn @geindex gccjit;;context;;new_array_type (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context14new_array_typeEN6gccjit4typeEiN6gccjit8locationE}@anchor{198}@anchor{cp/topics/types gccjit context new_array_type__gccjit type i gccjit location}@anchor{199} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::context::new_array_type (gccjit::type element_type, int num_elements, gccjit::location loc) +@anchor{cp/topics/types _CPPv4N6gccjit7context14new_array_typeEN6gccjit4typeEiN6gccjit8locationE}@anchor{1d8}@anchor{cp/topics/types _CPPv3N6gccjit7context14new_array_typeEN6gccjit4typeEiN6gccjit8locationE}@anchor{1d9}@anchor{cp/topics/types _CPPv2N6gccjit7context14new_array_typeEN6gccjit4typeEiN6gccjit8locationE}@anchor{1da}@anchor{cp/topics/types gccjit context new_array_type__gccjit type i gccjit location}@anchor{1db} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13d,,context}::new_array_type (gccjit::type element_type, int num_elements, gccjit::location loc) Given type “T”, get type “T[N]” (for a constant N). Param “loc” is optional. @end deffn @node Vector types<2>,Structures and unions<2>,Pointers const and volatile<2>,Types<2> -@anchor{cp/topics/types vector-types}@anchor{19a} +@anchor{cp/topics/types vector-types}@anchor{1dc} @subsubsection Vector types @geindex gccjit;;type;;get_vector (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit4type10get_vectorE6size_t}@anchor{19b}@anchor{cp/topics/types gccjit type get_vector__s}@anchor{19c} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::type::get_vector (size_t num_units) +@anchor{cp/topics/types _CPPv4N6gccjit4type10get_vectorE6size_t}@anchor{1dd}@anchor{cp/topics/types _CPPv3N6gccjit4type10get_vectorE6size_t}@anchor{1de}@anchor{cp/topics/types _CPPv2N6gccjit4type10get_vectorE6size_t}@anchor{1df}@anchor{cp/topics/types gccjit type get_vector__s}@anchor{1e0} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{13f,,type}::get_vector (size_t num_units) Given type “T”, get type: @@ -12264,31 +12723,31 @@ T must be integral or floating point; num_units must be a power of two. @end deffn @node Structures and unions<2>,,Vector types<2>,Types<2> -@anchor{cp/topics/types structures-and-unions}@anchor{19d} +@anchor{cp/topics/types structures-and-unions}@anchor{1e1} @subsubsection Structures and unions @geindex gccjit;;struct_ (C++ class) -@anchor{cp/topics/types _CPPv2N6gccjit7struct_E}@anchor{19e}@anchor{cp/topics/types gccjit struct_}@anchor{19f} +@anchor{cp/topics/types _CPPv4N6gccjit7struct_E}@anchor{1e2}@anchor{cp/topics/types _CPPv3N6gccjit7struct_E}@anchor{1e3}@anchor{cp/topics/types _CPPv2N6gccjit7struct_E}@anchor{1e4}@anchor{cp/topics/types gccjit struct_}@anchor{1e5} @deffn {C++ Class} gccjit::struct_ @end deffn A compound type analagous to a C @cite{struct}. -@ref{19e,,gccjit;;struct_} is a subclass of @ref{12f,,gccjit;;type} (and thus -of @ref{132,,gccjit;;object} in turn). +@ref{1e2,,gccjit;;struct_} is a subclass of @ref{13f,,gccjit;;type} (and thus +of @ref{142,,gccjit;;object} in turn). @geindex gccjit;;field (C++ class) -@anchor{cp/topics/types _CPPv2N6gccjit5fieldE}@anchor{1a0}@anchor{cp/topics/types gccjit field}@anchor{1a1} +@anchor{cp/topics/types _CPPv4N6gccjit5fieldE}@anchor{1e6}@anchor{cp/topics/types _CPPv3N6gccjit5fieldE}@anchor{1e7}@anchor{cp/topics/types _CPPv2N6gccjit5fieldE}@anchor{1e8}@anchor{cp/topics/types gccjit field}@anchor{1e9} @deffn {C++ Class} gccjit::field @end deffn -A field within a @ref{19e,,gccjit;;struct_}. +A field within a @ref{1e2,,gccjit;;struct_}. -@ref{1a0,,gccjit;;field} is a subclass of @ref{132,,gccjit;;object}. +@ref{1e6,,gccjit;;field} is a subclass of @ref{142,,gccjit;;object}. -You can model C @cite{struct} types by creating @ref{19e,,gccjit;;struct_} and -@ref{1a0,,gccjit;;field} instances, in either order: +You can model C @cite{struct} types by creating @ref{1e2,,gccjit;;struct_} and +@ref{1e6,,gccjit;;field} instances, in either order: @itemize * @@ -12336,15 +12795,15 @@ node.set_fields (fields); @c FIXME: the above API doesn't seem to exist yet @geindex gccjit;;context;;new_field (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context9new_fieldEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{1a2}@anchor{cp/topics/types gccjit context new_field__gccjit type cCP gccjit location}@anchor{1a3} -@deffn {C++ Function} gccjit::@ref{1a0,,field} gccjit::context::new_field (gccjit::type type, const char *name, gccjit::location loc) +@anchor{cp/topics/types _CPPv4N6gccjit7context9new_fieldEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{1ea}@anchor{cp/topics/types _CPPv3N6gccjit7context9new_fieldEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{1eb}@anchor{cp/topics/types _CPPv2N6gccjit7context9new_fieldEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{1ec}@anchor{cp/topics/types gccjit context new_field__gccjit type cCP gccjit location}@anchor{1ed} +@deffn {C++ Function} gccjit::@ref{1e6,,field} gccjit::@ref{13d,,context}::new_field (gccjit::type type, const char *name, gccjit::location loc) Construct a new field, with the given type and name. @end deffn @geindex gccjit;;context;;new_struct_type (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context15new_struct_typeERKNSt6stringERNSt6vectorI5fieldEEN6gccjit8locationE}@anchor{1a4}@anchor{cp/topics/types gccjit context new_struct_type__ssCR std vector field R gccjit location}@anchor{1a5} -@deffn {C++ Function} gccjit::@ref{19e,,struct_} gccjit::context::new_struct_type (const std::string &name, std::vector &fields, gccjit::location loc) +@anchor{cp/topics/types _CPPv4N6gccjit7context15new_struct_typeERKNSt6stringERNSt6vectorI5fieldEEN6gccjit8locationE}@anchor{1ee}@anchor{cp/topics/types _CPPv3N6gccjit7context15new_struct_typeERKNSt6stringERNSt6vectorI5fieldEEN6gccjit8locationE}@anchor{1ef}@anchor{cp/topics/types _CPPv2N6gccjit7context15new_struct_typeERKNSt6stringERNSt6vectorI5fieldEEN6gccjit8locationE}@anchor{1f0}@anchor{cp/topics/types gccjit context new_struct_type__ssCR std vector field R gccjit location}@anchor{1f1} +@deffn {C++ Function} gccjit::@ref{1e2,,struct_} gccjit::@ref{13d,,context}::new_struct_type (const std::string &name, std::vector &fields, gccjit::location loc) @quotation @@ -12353,8 +12812,8 @@ Construct a new struct type, with the given name and fields. @end deffn @geindex gccjit;;context;;new_opaque_struct (C++ function) -@anchor{cp/topics/types _CPPv2N6gccjit7context17new_opaque_structERKNSt6stringEN6gccjit8locationE}@anchor{1a6}@anchor{cp/topics/types gccjit context new_opaque_struct__ssCR gccjit location}@anchor{1a7} -@deffn {C++ Function} gccjit::@ref{19e,,struct_} gccjit::context::new_opaque_struct (const std::string &name, gccjit::location loc) +@anchor{cp/topics/types _CPPv4N6gccjit7context17new_opaque_structERKNSt6stringEN6gccjit8locationE}@anchor{1f2}@anchor{cp/topics/types _CPPv3N6gccjit7context17new_opaque_structERKNSt6stringEN6gccjit8locationE}@anchor{1f3}@anchor{cp/topics/types _CPPv2N6gccjit7context17new_opaque_structERKNSt6stringEN6gccjit8locationE}@anchor{1f4}@anchor{cp/topics/types gccjit context new_opaque_struct__ssCR gccjit location}@anchor{1f5} +@deffn {C++ Function} gccjit::@ref{1e2,,struct_} gccjit::@ref{13d,,context}::new_opaque_struct (const std::string &name, gccjit::location loc) Construct a new struct type, with the given name, but without specifying the fields. The fields can be omitted (in which case the @@ -12380,7 +12839,7 @@ size of the struct is not known), or later specified using @c . @node Expressions<2>,Creating and using functions<2>,Types<2>,Topic Reference<2> -@anchor{cp/topics/expressions expressions}@anchor{1a8}@anchor{cp/topics/expressions doc}@anchor{1a9} +@anchor{cp/topics/expressions doc}@anchor{1f6}@anchor{cp/topics/expressions expressions}@anchor{1f7} @subsection Expressions @@ -12392,17 +12851,17 @@ size of the struct is not known), or later specified using @end menu @node Rvalues<2>,Lvalues<2>,,Expressions<2> -@anchor{cp/topics/expressions rvalues}@anchor{1aa} +@anchor{cp/topics/expressions rvalues}@anchor{1f8} @subsubsection Rvalues @geindex gccjit;;rvalue (C++ class) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalueE}@anchor{136}@anchor{cp/topics/expressions gccjit rvalue}@anchor{1ab} +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvalueE}@anchor{146}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvalueE}@anchor{1f9}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalueE}@anchor{1fa}@anchor{cp/topics/expressions gccjit rvalue}@anchor{1fb} @deffn {C++ Class} gccjit::rvalue @end deffn -A @ref{136,,gccjit;;rvalue} is an expression that can be computed. It is a -subclass of @ref{132,,gccjit;;object}, and is a thin wrapper around +A @ref{146,,gccjit;;rvalue} is an expression that can be computed. It is a +subclass of @ref{142,,gccjit;;object}, and is a thin wrapper around @ref{13,,gcc_jit_rvalue *} from the C API. It can be simple, e.g.: @@ -12448,8 +12907,8 @@ Every rvalue has an associated type, and the API will check to ensure that types match up correctly (otherwise the context will emit an error). @geindex gccjit;;rvalue;;get_type (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue8get_typeEv}@anchor{1ac}@anchor{cp/topics/expressions gccjit rvalue get_type}@anchor{1ad} -@deffn {C++ Function} gccjit::@ref{12f,,type} gccjit::rvalue::get_type () +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvalue8get_typeEv}@anchor{1fc}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvalue8get_typeEv}@anchor{1fd}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue8get_typeEv}@anchor{1fe}@anchor{cp/topics/expressions gccjit rvalue get_type}@anchor{1ff} +@deffn {C++ Function} gccjit::@ref{13f,,type} gccjit::@ref{146,,rvalue}::get_type () Get the type of this rvalue. @end deffn @@ -12467,29 +12926,29 @@ Get the type of this rvalue. @end menu @node Simple expressions<2>,Vector expressions<2>,,Rvalues<2> -@anchor{cp/topics/expressions simple-expressions}@anchor{1ae} +@anchor{cp/topics/expressions simple-expressions}@anchor{200} @subsubsection Simple expressions @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEi}@anchor{14a}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type iC}@anchor{1af} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (gccjit::type numeric_type, int value) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueEN6gccjit4typeEi}@anchor{15a}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueEN6gccjit4typeEi}@anchor{201}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEi}@anchor{202}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type iC}@anchor{203} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (gccjit::type numeric_type, int value) const Given a numeric type (integer or floating point), build an rvalue for the given constant @code{int} value. @end deffn @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEl}@anchor{1b0}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type lC}@anchor{1b1} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (gccjit::type numeric_type, long value) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueEN6gccjit4typeEl}@anchor{204}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueEN6gccjit4typeEl}@anchor{205}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEl}@anchor{206}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type lC}@anchor{207} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (gccjit::type numeric_type, long value) const Given a numeric type (integer or floating point), build an rvalue for the given constant @code{long} value. @end deffn @geindex gccjit;;context;;zero (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context4zeroEN6gccjit4typeE}@anchor{146}@anchor{cp/topics/expressions gccjit context zero__gccjit typeC}@anchor{1b2} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::zero (gccjit::type numeric_type) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context4zeroEN6gccjit4typeE}@anchor{156}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context4zeroEN6gccjit4typeE}@anchor{208}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context4zeroEN6gccjit4typeE}@anchor{209}@anchor{cp/topics/expressions gccjit context zero__gccjit typeC}@anchor{20a} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::zero (gccjit::type numeric_type) const Given a numeric type (integer or floating point), get the rvalue for zero. Essentially this is just a shortcut for: @@ -12500,8 +12959,8 @@ ctxt.new_rvalue (numeric_type, 0) @end deffn @geindex gccjit;;context;;one (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context3oneEN6gccjit4typeE}@anchor{1b3}@anchor{cp/topics/expressions gccjit context one__gccjit typeC}@anchor{1b4} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::one (gccjit::type numeric_type) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context3oneEN6gccjit4typeE}@anchor{20b}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context3oneEN6gccjit4typeE}@anchor{20c}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context3oneEN6gccjit4typeE}@anchor{20d}@anchor{cp/topics/expressions gccjit context one__gccjit typeC}@anchor{20e} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::one (gccjit::type numeric_type) const Given a numeric type (integer or floating point), get the rvalue for one. Essentially this is just a shortcut for: @@ -12512,36 +12971,36 @@ ctxt.new_rvalue (numeric_type, 1) @end deffn @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEd}@anchor{1b5}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type doubleC}@anchor{1b6} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (gccjit::type numeric_type, double value) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueEN6gccjit4typeEd}@anchor{20f}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueEN6gccjit4typeEd}@anchor{210}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEd}@anchor{211}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type doubleC}@anchor{212} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (gccjit::type numeric_type, double value) const Given a numeric type (integer or floating point), build an rvalue for the given constant @code{double} value. @end deffn @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEPv}@anchor{1b7}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type voidPC}@anchor{1b8} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (gccjit::type pointer_type, void *value) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueEN6gccjit4typeEPv}@anchor{213}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueEN6gccjit4typeEPv}@anchor{214}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeEPv}@anchor{215}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type voidPC}@anchor{216} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (gccjit::type pointer_type, void *value) const Given a pointer type, build an rvalue for the given address. @end deffn @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueERKNSt6stringE}@anchor{1b9}@anchor{cp/topics/expressions gccjit context new_rvalue__ssCRC}@anchor{1ba} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (const std::string &value) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueERKNSt6stringE}@anchor{217}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueERKNSt6stringE}@anchor{218}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueERKNSt6stringE}@anchor{219}@anchor{cp/topics/expressions gccjit context new_rvalue__ssCRC}@anchor{21a} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (const std::string &value) const Generate an rvalue of type @code{GCC_JIT_TYPE_CONST_CHAR_PTR} for the given string. This is akin to a string literal. @end deffn @node Vector expressions<2>,Unary Operations<2>,Simple expressions<2>,Rvalues<2> -@anchor{cp/topics/expressions vector-expressions}@anchor{1bb} +@anchor{cp/topics/expressions vector-expressions}@anchor{21b} @subsubsection Vector expressions @geindex gccjit;;context;;new_rvalue (C++ function) -@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeENSt6vectorIN6gccjit6rvalueEEE}@anchor{1bc}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type std vector gccjit rvalue C}@anchor{1bd} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_rvalue (gccjit::type vector_type, std::vector elements) const +@anchor{cp/topics/expressions _CPPv4NK6gccjit7context10new_rvalueEN6gccjit4typeENSt6vectorIN6gccjit6rvalueEEE}@anchor{21c}@anchor{cp/topics/expressions _CPPv3NK6gccjit7context10new_rvalueEN6gccjit4typeENSt6vectorIN6gccjit6rvalueEEE}@anchor{21d}@anchor{cp/topics/expressions _CPPv2NK6gccjit7context10new_rvalueEN6gccjit4typeENSt6vectorIN6gccjit6rvalueEEE}@anchor{21e}@anchor{cp/topics/expressions gccjit context new_rvalue__gccjit type std vector gccjit rvalue C}@anchor{21f} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_rvalue (gccjit::type vector_type, std::vector elements) const Given a vector type, and a vector of scalar rvalue elements, generate a vector rvalue. @@ -12550,13 +13009,13 @@ The number of elements needs to match that of the vector type. @end deffn @node Unary Operations<2>,Binary Operations<2>,Vector expressions<2>,Rvalues<2> -@anchor{cp/topics/expressions unary-operations}@anchor{1be} +@anchor{cp/topics/expressions unary-operations}@anchor{220} @subsubsection Unary Operations @geindex gccjit;;context;;new_unary_op (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context12new_unary_opE16gcc_jit_unary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1bf}@anchor{cp/topics/expressions gccjit context new_unary_op__gcc_jit_unary_op gccjit type gccjit rvalue gccjit location}@anchor{1c0} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_unary_op (enum gcc_jit_unary_op, gccjit::type result_type, gccjit::rvalue rvalue, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context12new_unary_opE16gcc_jit_unary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{221}@anchor{cp/topics/expressions _CPPv3N6gccjit7context12new_unary_opE16gcc_jit_unary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{222}@anchor{cp/topics/expressions _CPPv2N6gccjit7context12new_unary_opE16gcc_jit_unary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{223}@anchor{cp/topics/expressions gccjit context new_unary_op__gcc_jit_unary_op gccjit type gccjit rvalue gccjit location}@anchor{224} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_unary_op (enum gcc_jit_unary_op, gccjit::type result_type, gccjit::rvalue rvalue, gccjit::location loc) Build a unary operation out of an input rvalue. @@ -12571,8 +13030,8 @@ There are shorter ways to spell the various specific kinds of unary operation: @geindex gccjit;;context;;new_minus (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1c1}@anchor{cp/topics/expressions gccjit context new_minus__gccjit type gccjit rvalue gccjit location}@anchor{1c2} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{225}@anchor{cp/topics/expressions _CPPv3N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{226}@anchor{cp/topics/expressions _CPPv2N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{227}@anchor{cp/topics/expressions gccjit context new_minus__gccjit type gccjit rvalue gccjit location}@anchor{228} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) Negate an arithmetic value; for example: @@ -12588,8 +13047,8 @@ builds the equivalent of this C expression: @end deffn @geindex new_bitwise_negate (C++ function) -@anchor{cp/topics/expressions _CPPv218new_bitwise_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1c3}@anchor{cp/topics/expressions new_bitwise_negate__gccjit type gccjit rvalue gccjit location}@anchor{1c4} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} new_bitwise_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv418new_bitwise_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{229}@anchor{cp/topics/expressions _CPPv318new_bitwise_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22a}@anchor{cp/topics/expressions _CPPv218new_bitwise_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22b}@anchor{cp/topics/expressions new_bitwise_negate__gccjit type gccjit rvalue gccjit location}@anchor{22c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} new_bitwise_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) Bitwise negation of an integer value (one’s complement); for example: @@ -12605,8 +13064,8 @@ builds the equivalent of this C expression: @end deffn @geindex new_logical_negate (C++ function) -@anchor{cp/topics/expressions _CPPv218new_logical_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1c5}@anchor{cp/topics/expressions new_logical_negate__gccjit type gccjit rvalue gccjit location}@anchor{1c6} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} new_logical_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv418new_logical_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22d}@anchor{cp/topics/expressions _CPPv318new_logical_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22e}@anchor{cp/topics/expressions _CPPv218new_logical_negateN6gccjit4typeEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22f}@anchor{cp/topics/expressions new_logical_negate__gccjit type gccjit rvalue gccjit location}@anchor{230} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} new_logical_negate (gccjit::type result_type, gccjit::rvalue a, gccjit::location loc) Logical negation of an arithmetic or pointer value; for example: @@ -12624,8 +13083,8 @@ builds the equivalent of this C expression: The most concise way to spell them is with overloaded operators: @geindex operator- (C++ function) -@anchor{cp/topics/expressions _CPPv2miN6gccjit6rvalueE}@anchor{1c7}@anchor{cp/topics/expressions sub-operator__gccjit rvalue}@anchor{1c8} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator@w{-} (gccjit::rvalue a) +@anchor{cp/topics/expressions _CPPv4miN6gccjit6rvalueE}@anchor{231}@anchor{cp/topics/expressions _CPPv3miN6gccjit6rvalueE}@anchor{232}@anchor{cp/topics/expressions _CPPv2miN6gccjit6rvalueE}@anchor{233}@anchor{cp/topics/expressions sub-operator__gccjit rvalue}@anchor{234} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator@w{-} (gccjit::rvalue a) @example gccjit::rvalue negpi = -pi; @@ -12633,8 +13092,8 @@ gccjit::rvalue negpi = -pi; @end deffn @geindex operator~ (C++ function) -@anchor{cp/topics/expressions _CPPv2coN6gccjit6rvalueE}@anchor{1c9}@anchor{cp/topics/expressions inv-operator__gccjit rvalue}@anchor{1ca} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator~ (gccjit::rvalue a) +@anchor{cp/topics/expressions _CPPv4coN6gccjit6rvalueE}@anchor{235}@anchor{cp/topics/expressions _CPPv3coN6gccjit6rvalueE}@anchor{236}@anchor{cp/topics/expressions _CPPv2coN6gccjit6rvalueE}@anchor{237}@anchor{cp/topics/expressions inv-operator__gccjit rvalue}@anchor{238} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator~ (gccjit::rvalue a) @example gccjit::rvalue mask = ~a; @@ -12642,8 +13101,8 @@ gccjit::rvalue mask = ~a; @end deffn @geindex operator! (C++ function) -@anchor{cp/topics/expressions _CPPv2ntN6gccjit6rvalueE}@anchor{1cb}@anchor{cp/topics/expressions not-operator__gccjit rvalue}@anchor{1cc} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator! (gccjit::rvalue a) +@anchor{cp/topics/expressions _CPPv4ntN6gccjit6rvalueE}@anchor{239}@anchor{cp/topics/expressions _CPPv3ntN6gccjit6rvalueE}@anchor{23a}@anchor{cp/topics/expressions _CPPv2ntN6gccjit6rvalueE}@anchor{23b}@anchor{cp/topics/expressions not-operator__gccjit rvalue}@anchor{23c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator! (gccjit::rvalue a) @example gccjit::rvalue guard = !cond; @@ -12651,13 +13110,13 @@ gccjit::rvalue guard = !cond; @end deffn @node Binary Operations<2>,Comparisons<2>,Unary Operations<2>,Rvalues<2> -@anchor{cp/topics/expressions binary-operations}@anchor{1cd} +@anchor{cp/topics/expressions binary-operations}@anchor{23d} @subsubsection Binary Operations @geindex gccjit;;context;;new_binary_op (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context13new_binary_opE17gcc_jit_binary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{135}@anchor{cp/topics/expressions gccjit context new_binary_op__gcc_jit_binary_op gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1ce} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_binary_op (enum gcc_jit_binary_op, gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context13new_binary_opE17gcc_jit_binary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{145}@anchor{cp/topics/expressions _CPPv3N6gccjit7context13new_binary_opE17gcc_jit_binary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{23e}@anchor{cp/topics/expressions _CPPv2N6gccjit7context13new_binary_opE17gcc_jit_binary_opN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{23f}@anchor{cp/topics/expressions gccjit context new_binary_op__gcc_jit_binary_op gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{240} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_binary_op (enum gcc_jit_binary_op, gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) Build a binary operation out of two constituent rvalues. @@ -12672,60 +13131,60 @@ There are shorter ways to spell the various specific kinds of binary operation: @geindex gccjit;;context;;new_plus (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_plusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1cf}@anchor{cp/topics/expressions gccjit context new_plus__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1d0} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_plus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context8new_plusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{241}@anchor{cp/topics/expressions _CPPv3N6gccjit7context8new_plusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{242}@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_plusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{243}@anchor{cp/topics/expressions gccjit context new_plus__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{244} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_plus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_minus (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1d1}@anchor{cp/topics/expressions gccjit context new_minus__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1d2} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{245}@anchor{cp/topics/expressions _CPPv3N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{246}@anchor{cp/topics/expressions _CPPv2N6gccjit7context9new_minusEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{247}@anchor{cp/topics/expressions gccjit context new_minus__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{248} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_minus (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_mult (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_multEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1d3}@anchor{cp/topics/expressions gccjit context new_mult__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1d4} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_mult (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context8new_multEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{249}@anchor{cp/topics/expressions _CPPv3N6gccjit7context8new_multEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24a}@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_multEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24b}@anchor{cp/topics/expressions gccjit context new_mult__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{24c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_mult (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_divide (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_divideEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1d5}@anchor{cp/topics/expressions gccjit context new_divide__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1d6} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_divide (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context10new_divideEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24d}@anchor{cp/topics/expressions _CPPv3N6gccjit7context10new_divideEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24e}@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_divideEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24f}@anchor{cp/topics/expressions gccjit context new_divide__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{250} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_divide (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_modulo (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_moduloEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1d7}@anchor{cp/topics/expressions gccjit context new_modulo__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1d8} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_modulo (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context10new_moduloEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{251}@anchor{cp/topics/expressions _CPPv3N6gccjit7context10new_moduloEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{252}@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_moduloEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{253}@anchor{cp/topics/expressions gccjit context new_modulo__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{254} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_modulo (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_bitwise_and (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_bitwise_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1d9}@anchor{cp/topics/expressions gccjit context new_bitwise_and__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1da} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_bitwise_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context15new_bitwise_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{255}@anchor{cp/topics/expressions _CPPv3N6gccjit7context15new_bitwise_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{256}@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_bitwise_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{257}@anchor{cp/topics/expressions gccjit context new_bitwise_and__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{258} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_bitwise_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_bitwise_xor (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_bitwise_xorEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1db}@anchor{cp/topics/expressions gccjit context new_bitwise_xor__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1dc} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_bitwise_xor (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context15new_bitwise_xorEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{259}@anchor{cp/topics/expressions _CPPv3N6gccjit7context15new_bitwise_xorEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{25a}@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_bitwise_xorEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{25b}@anchor{cp/topics/expressions gccjit context new_bitwise_xor__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{25c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_bitwise_xor (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_bitwise_or (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_bitwise_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1dd}@anchor{cp/topics/expressions gccjit context new_bitwise_or__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1de} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_bitwise_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context14new_bitwise_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{25d}@anchor{cp/topics/expressions _CPPv3N6gccjit7context14new_bitwise_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{25e}@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_bitwise_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{25f}@anchor{cp/topics/expressions gccjit context new_bitwise_or__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{260} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_bitwise_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_logical_and (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_logical_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1df}@anchor{cp/topics/expressions gccjit context new_logical_and__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1e0} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_logical_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context15new_logical_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{261}@anchor{cp/topics/expressions _CPPv3N6gccjit7context15new_logical_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{262}@anchor{cp/topics/expressions _CPPv2N6gccjit7context15new_logical_andEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{263}@anchor{cp/topics/expressions gccjit context new_logical_and__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{264} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_logical_and (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_logical_or (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_logical_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1e1}@anchor{cp/topics/expressions gccjit context new_logical_or__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{1e2} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_logical_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context14new_logical_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{265}@anchor{cp/topics/expressions _CPPv3N6gccjit7context14new_logical_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{266}@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_logical_orEN6gccjit4typeEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{267}@anchor{cp/topics/expressions gccjit context new_logical_or__gccjit type gccjit rvalue gccjit rvalue gccjit location}@anchor{268} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_logical_or (gccjit::type result_type, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn The most concise way to spell them is with overloaded operators: @geindex operator+ (C++ function) -@anchor{cp/topics/expressions _CPPv2plN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1e3}@anchor{cp/topics/expressions add-operator__gccjit rvalue gccjit rvalue}@anchor{1e4} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator+ (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4plN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{269}@anchor{cp/topics/expressions _CPPv3plN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{26a}@anchor{cp/topics/expressions _CPPv2plN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{26b}@anchor{cp/topics/expressions add-operator__gccjit rvalue gccjit rvalue}@anchor{26c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator+ (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue sum = a + b; @@ -12733,8 +13192,8 @@ gccjit::rvalue sum = a + b; @end deffn @geindex operator- (C++ function) -@anchor{cp/topics/expressions _CPPv2miN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1e5}@anchor{cp/topics/expressions sub-operator__gccjit rvalue gccjit rvalue}@anchor{1e6} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator@w{-} (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4miN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{26d}@anchor{cp/topics/expressions _CPPv3miN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{26e}@anchor{cp/topics/expressions _CPPv2miN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{26f}@anchor{cp/topics/expressions sub-operator__gccjit rvalue gccjit rvalue}@anchor{270} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator@w{-} (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue diff = a - b; @@ -12742,8 +13201,8 @@ gccjit::rvalue diff = a - b; @end deffn @geindex operator* (C++ function) -@anchor{cp/topics/expressions _CPPv2mlN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1e7}@anchor{cp/topics/expressions mul-operator__gccjit rvalue gccjit rvalue}@anchor{1e8} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator* (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4mlN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{271}@anchor{cp/topics/expressions _CPPv3mlN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{272}@anchor{cp/topics/expressions _CPPv2mlN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{273}@anchor{cp/topics/expressions mul-operator__gccjit rvalue gccjit rvalue}@anchor{274} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator* (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue prod = a * b; @@ -12751,8 +13210,8 @@ gccjit::rvalue prod = a * b; @end deffn @geindex operator/ (C++ function) -@anchor{cp/topics/expressions _CPPv2dvN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1e9}@anchor{cp/topics/expressions div-operator__gccjit rvalue gccjit rvalue}@anchor{1ea} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator/ (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4dvN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{275}@anchor{cp/topics/expressions _CPPv3dvN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{276}@anchor{cp/topics/expressions _CPPv2dvN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{277}@anchor{cp/topics/expressions div-operator__gccjit rvalue gccjit rvalue}@anchor{278} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator/ (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue result = a / b; @@ -12760,8 +13219,8 @@ gccjit::rvalue result = a / b; @end deffn @geindex operator% (C++ function) -@anchor{cp/topics/expressions _CPPv2rmN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1eb}@anchor{cp/topics/expressions mod-operator__gccjit rvalue gccjit rvalue}@anchor{1ec} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator% (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4rmN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{279}@anchor{cp/topics/expressions _CPPv3rmN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{27a}@anchor{cp/topics/expressions _CPPv2rmN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{27b}@anchor{cp/topics/expressions mod-operator__gccjit rvalue gccjit rvalue}@anchor{27c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator% (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue mod = a % b; @@ -12769,8 +13228,8 @@ gccjit::rvalue mod = a % b; @end deffn @geindex operator& (C++ function) -@anchor{cp/topics/expressions _CPPv2anN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1ed}@anchor{cp/topics/expressions and-operator__gccjit rvalue gccjit rvalue}@anchor{1ee} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator& (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4anN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{27d}@anchor{cp/topics/expressions _CPPv3anN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{27e}@anchor{cp/topics/expressions _CPPv2anN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{27f}@anchor{cp/topics/expressions and-operator__gccjit rvalue gccjit rvalue}@anchor{280} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator& (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue x = a & b; @@ -12778,8 +13237,8 @@ gccjit::rvalue x = a & b; @end deffn @geindex operator^ (C++ function) -@anchor{cp/topics/expressions _CPPv2eoN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1ef}@anchor{cp/topics/expressions xor-operator__gccjit rvalue gccjit rvalue}@anchor{1f0} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator^ (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4eoN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{281}@anchor{cp/topics/expressions _CPPv3eoN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{282}@anchor{cp/topics/expressions _CPPv2eoN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{283}@anchor{cp/topics/expressions xor-operator__gccjit rvalue gccjit rvalue}@anchor{284} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator^ (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue x = a ^ b; @@ -12787,8 +13246,8 @@ gccjit::rvalue x = a ^ b; @end deffn @geindex operator| (C++ function) -@anchor{cp/topics/expressions _CPPv2orN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1f1}@anchor{cp/topics/expressions or-operator__gccjit rvalue gccjit rvalue}@anchor{1f2} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator| (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4orN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{285}@anchor{cp/topics/expressions _CPPv3orN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{286}@anchor{cp/topics/expressions _CPPv2orN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{287}@anchor{cp/topics/expressions or-operator__gccjit rvalue gccjit rvalue}@anchor{288} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator| (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue x = a | b; @@ -12796,8 +13255,8 @@ gccjit::rvalue x = a | b; @end deffn @geindex operator&& (C++ function) -@anchor{cp/topics/expressions _CPPv2aaN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1f3}@anchor{cp/topics/expressions sand-operator__gccjit rvalue gccjit rvalue}@anchor{1f4} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator&& (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4aaN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{289}@anchor{cp/topics/expressions _CPPv3aaN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{28a}@anchor{cp/topics/expressions _CPPv2aaN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{28b}@anchor{cp/topics/expressions sand-operator__gccjit rvalue gccjit rvalue}@anchor{28c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator&& (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = a && b; @@ -12805,8 +13264,8 @@ gccjit::rvalue cond = a && b; @end deffn @geindex operator|| (C++ function) -@anchor{cp/topics/expressions _CPPv2ooN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{1f5}@anchor{cp/topics/expressions sor-operator__gccjit rvalue gccjit rvalue}@anchor{1f6} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator|| (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4ooN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{28d}@anchor{cp/topics/expressions _CPPv3ooN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{28e}@anchor{cp/topics/expressions _CPPv2ooN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{28f}@anchor{cp/topics/expressions sor-operator__gccjit rvalue gccjit rvalue}@anchor{290} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator|| (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = a || b; @@ -12824,13 +13283,13 @@ gccjit::rvalue discriminant = (b * b) - (four * a * c); @end quotation @node Comparisons<2>,Function calls<2>,Binary Operations<2>,Rvalues<2> -@anchor{cp/topics/expressions comparisons}@anchor{1f7} +@anchor{cp/topics/expressions comparisons}@anchor{291} @subsubsection Comparisons @geindex gccjit;;context;;new_comparison (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_comparisonE18gcc_jit_comparisonN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{147}@anchor{cp/topics/expressions gccjit context new_comparison__gcc_jit_comparison gccjit rvalue gccjit rvalue gccjit location}@anchor{1f8} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_comparison (enum gcc_jit_comparison, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context14new_comparisonE18gcc_jit_comparisonN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{157}@anchor{cp/topics/expressions _CPPv3N6gccjit7context14new_comparisonE18gcc_jit_comparisonN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{292}@anchor{cp/topics/expressions _CPPv2N6gccjit7context14new_comparisonE18gcc_jit_comparisonN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{293}@anchor{cp/topics/expressions gccjit context new_comparison__gcc_jit_comparison gccjit rvalue gccjit rvalue gccjit location}@anchor{294} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_comparison (enum gcc_jit_comparison, gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) Build a boolean rvalue out of the comparison of two other rvalues. @@ -12845,40 +13304,40 @@ There are shorter ways to spell the various specific kinds of binary operation: @geindex gccjit;;context;;new_eq (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_eqEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1f9}@anchor{cp/topics/expressions gccjit context new_eq__gccjit rvalue gccjit rvalue gccjit location}@anchor{1fa} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_eq (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_eqEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{295}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_eqEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{296}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_eqEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{297}@anchor{cp/topics/expressions gccjit context new_eq__gccjit rvalue gccjit rvalue gccjit location}@anchor{298} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_eq (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_ne (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_neEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1fb}@anchor{cp/topics/expressions gccjit context new_ne__gccjit rvalue gccjit rvalue gccjit location}@anchor{1fc} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_ne (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_neEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{299}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_neEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{29a}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_neEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{29b}@anchor{cp/topics/expressions gccjit context new_ne__gccjit rvalue gccjit rvalue gccjit location}@anchor{29c} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_ne (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_lt (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_ltEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1fd}@anchor{cp/topics/expressions gccjit context new_lt__gccjit rvalue gccjit rvalue gccjit location}@anchor{1fe} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_lt (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_ltEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{29d}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_ltEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{29e}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_ltEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{29f}@anchor{cp/topics/expressions gccjit context new_lt__gccjit rvalue gccjit rvalue gccjit location}@anchor{2a0} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_lt (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_le (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_leEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{1ff}@anchor{cp/topics/expressions gccjit context new_le__gccjit rvalue gccjit rvalue gccjit location}@anchor{200} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_le (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_leEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a1}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_leEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a2}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_leEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a3}@anchor{cp/topics/expressions gccjit context new_le__gccjit rvalue gccjit rvalue gccjit location}@anchor{2a4} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_le (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_gt (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_gtEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{201}@anchor{cp/topics/expressions gccjit context new_gt__gccjit rvalue gccjit rvalue gccjit location}@anchor{202} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_gt (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_gtEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a5}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_gtEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a6}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_gtEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a7}@anchor{cp/topics/expressions gccjit context new_gt__gccjit rvalue gccjit rvalue gccjit location}@anchor{2a8} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_gt (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn @geindex gccjit;;context;;new_ge (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_geEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{203}@anchor{cp/topics/expressions gccjit context new_ge__gccjit rvalue gccjit rvalue gccjit location}@anchor{204} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_ge (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context6new_geEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2a9}@anchor{cp/topics/expressions _CPPv3N6gccjit7context6new_geEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2aa}@anchor{cp/topics/expressions _CPPv2N6gccjit7context6new_geEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2ab}@anchor{cp/topics/expressions gccjit context new_ge__gccjit rvalue gccjit rvalue gccjit location}@anchor{2ac} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_ge (gccjit::rvalue a, gccjit::rvalue b, gccjit::location loc) @end deffn The most concise way to spell them is with overloaded operators: @geindex operator== (C++ function) -@anchor{cp/topics/expressions _CPPv2eqN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{205}@anchor{cp/topics/expressions eq-operator__gccjit rvalue gccjit rvalue}@anchor{206} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator== (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4eqN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2ad}@anchor{cp/topics/expressions _CPPv3eqN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2ae}@anchor{cp/topics/expressions _CPPv2eqN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2af}@anchor{cp/topics/expressions eq-operator__gccjit rvalue gccjit rvalue}@anchor{2b0} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator== (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = (a == ctxt.zero (t_int)); @@ -12886,8 +13345,8 @@ gccjit::rvalue cond = (a == ctxt.zero (t_int)); @end deffn @geindex operator!= (C++ function) -@anchor{cp/topics/expressions _CPPv2neN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{207}@anchor{cp/topics/expressions neq-operator__gccjit rvalue gccjit rvalue}@anchor{208} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator!= (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4neN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b1}@anchor{cp/topics/expressions _CPPv3neN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b2}@anchor{cp/topics/expressions _CPPv2neN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b3}@anchor{cp/topics/expressions neq-operator__gccjit rvalue gccjit rvalue}@anchor{2b4} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator!= (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = (i != j); @@ -12895,8 +13354,8 @@ gccjit::rvalue cond = (i != j); @end deffn @geindex operator< (C++ function) -@anchor{cp/topics/expressions _CPPv2ltN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{209}@anchor{cp/topics/expressions lt-operator__gccjit rvalue gccjit rvalue}@anchor{20a} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator< (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4ltN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b5}@anchor{cp/topics/expressions _CPPv3ltN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b6}@anchor{cp/topics/expressions _CPPv2ltN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b7}@anchor{cp/topics/expressions lt-operator__gccjit rvalue gccjit rvalue}@anchor{2b8} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator< (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = i < n; @@ -12904,8 +13363,8 @@ gccjit::rvalue cond = i < n; @end deffn @geindex operator<= (C++ function) -@anchor{cp/topics/expressions _CPPv2leN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{20b}@anchor{cp/topics/expressions lte-operator__gccjit rvalue gccjit rvalue}@anchor{20c} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator<= (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4leN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2b9}@anchor{cp/topics/expressions _CPPv3leN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2ba}@anchor{cp/topics/expressions _CPPv2leN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2bb}@anchor{cp/topics/expressions lte-operator__gccjit rvalue gccjit rvalue}@anchor{2bc} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator<= (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = i <= n; @@ -12913,8 +13372,8 @@ gccjit::rvalue cond = i <= n; @end deffn @geindex operator> (C++ function) -@anchor{cp/topics/expressions _CPPv2gtN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{20d}@anchor{cp/topics/expressions gt-operator__gccjit rvalue gccjit rvalue}@anchor{20e} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator> (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4gtN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2bd}@anchor{cp/topics/expressions _CPPv3gtN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2be}@anchor{cp/topics/expressions _CPPv2gtN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2bf}@anchor{cp/topics/expressions gt-operator__gccjit rvalue gccjit rvalue}@anchor{2c0} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator> (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = (ch > limit); @@ -12922,8 +13381,8 @@ gccjit::rvalue cond = (ch > limit); @end deffn @geindex operator>= (C++ function) -@anchor{cp/topics/expressions _CPPv2geN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{20f}@anchor{cp/topics/expressions gte-operator__gccjit rvalue gccjit rvalue}@anchor{210} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} operator>= (gccjit::rvalue a, gccjit::rvalue b) +@anchor{cp/topics/expressions _CPPv4geN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2c1}@anchor{cp/topics/expressions _CPPv3geN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2c2}@anchor{cp/topics/expressions _CPPv2geN6gccjit6rvalueEN6gccjit6rvalueE}@anchor{2c3}@anchor{cp/topics/expressions gte-operator__gccjit rvalue gccjit rvalue}@anchor{2c4} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} operator>= (gccjit::rvalue a, gccjit::rvalue b) @example gccjit::rvalue cond = (score >= ctxt.new_rvalue (t_int, 100)); @@ -12933,12 +13392,12 @@ gccjit::rvalue cond = (score >= ctxt.new_rvalue (t_int, 100)); @c TODO: beyond this point @node Function calls<2>,Function pointers<3>,Comparisons<2>,Rvalues<2> -@anchor{cp/topics/expressions function-calls}@anchor{211} +@anchor{cp/topics/expressions function-calls}@anchor{2c5} @subsubsection Function calls @geindex gcc_jit_context_new_call (C++ function) -@anchor{cp/topics/expressions _CPPv224gcc_jit_context_new_callP15gcc_jit_contextP16gcc_jit_locationP16gcc_jit_functioniPP14gcc_jit_rvalue}@anchor{212}@anchor{cp/topics/expressions gcc_jit_context_new_call__gcc_jit_contextP gcc_jit_locationP gcc_jit_functionP i gcc_jit_rvaluePP}@anchor{213} +@anchor{cp/topics/expressions _CPPv424gcc_jit_context_new_callP15gcc_jit_contextP16gcc_jit_locationP16gcc_jit_functioniPP14gcc_jit_rvalue}@anchor{2c6}@anchor{cp/topics/expressions _CPPv324gcc_jit_context_new_callP15gcc_jit_contextP16gcc_jit_locationP16gcc_jit_functioniPP14gcc_jit_rvalue}@anchor{2c7}@anchor{cp/topics/expressions _CPPv224gcc_jit_context_new_callP15gcc_jit_contextP16gcc_jit_locationP16gcc_jit_functioniPP14gcc_jit_rvalue}@anchor{2c8}@anchor{cp/topics/expressions gcc_jit_context_new_call__gcc_jit_contextP gcc_jit_locationP gcc_jit_functionP i gcc_jit_rvaluePP}@anchor{2c9} @deffn {C++ Function} gcc_jit_rvalue *gcc_jit_context_new_call (gcc_jit_context *ctxt, gcc_jit_location *loc, gcc_jit_function *func, int numargs, gcc_jit_rvalue **args) Given a function and the given table of argument rvalues, construct a @@ -12947,14 +13406,14 @@ call to the function, with the result as an rvalue. @cartouche @quotation Note @code{gccjit::context::new_call()} merely builds a -@ref{136,,gccjit;;rvalue} i.e. an expression that can be evaluated, +@ref{146,,gccjit;;rvalue} i.e. an expression that can be evaluated, perhaps as part of a more complicated expression. The call @emph{won’t} happen unless you add a statement to a function that evaluates the expression. For example, if you want to call a function and discard the result (or to call a function with @code{void} return type), use -@ref{214,,gccjit;;block;;add_eval()}: +@ref{2ca,,gccjit;;block;;add_eval()}: @example /* Add "(void)printf (arg0, arg1);". */ @@ -12965,26 +13424,26 @@ block.add_eval (ctxt.new_call (printf_func, arg0, arg1)); @end deffn @node Function pointers<3>,Type-coercion<2>,Function calls<2>,Rvalues<2> -@anchor{cp/topics/expressions function-pointers}@anchor{215} +@anchor{cp/topics/expressions function-pointers}@anchor{2cb} @subsubsection Function pointers @geindex gccjit;;function;;get_address (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit8function11get_addressEN6gccjit8locationE}@anchor{216}@anchor{cp/topics/expressions gccjit function get_address__gccjit location}@anchor{217} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::function::get_address (gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit8function11get_addressEN6gccjit8locationE}@anchor{2cc}@anchor{cp/topics/expressions _CPPv3N6gccjit8function11get_addressEN6gccjit8locationE}@anchor{2cd}@anchor{cp/topics/expressions _CPPv2N6gccjit8function11get_addressEN6gccjit8locationE}@anchor{2ce}@anchor{cp/topics/expressions gccjit function get_address__gccjit location}@anchor{2cf} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{154,,function}::get_address (gccjit::location loc) Get the address of a function as an rvalue, of function pointer type. @end deffn @node Type-coercion<2>,,Function pointers<3>,Rvalues<2> -@anchor{cp/topics/expressions type-coercion}@anchor{218} +@anchor{cp/topics/expressions type-coercion}@anchor{2d0} @subsubsection Type-coercion @geindex gccjit;;context;;new_cast (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_castEN6gccjit6rvalueEN6gccjit4typeEN6gccjit8locationE}@anchor{219}@anchor{cp/topics/expressions gccjit context new_cast__gccjit rvalue gccjit type gccjit location}@anchor{21a} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::context::new_cast (gccjit::rvalue rvalue, gccjit::type type, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context8new_castEN6gccjit6rvalueEN6gccjit4typeEN6gccjit8locationE}@anchor{2d1}@anchor{cp/topics/expressions _CPPv3N6gccjit7context8new_castEN6gccjit6rvalueEN6gccjit4typeEN6gccjit8locationE}@anchor{2d2}@anchor{cp/topics/expressions _CPPv2N6gccjit7context8new_castEN6gccjit6rvalueEN6gccjit4typeEN6gccjit8locationE}@anchor{2d3}@anchor{cp/topics/expressions gccjit context new_cast__gccjit rvalue gccjit type gccjit location}@anchor{2d4} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{13d,,context}::new_cast (gccjit::rvalue rvalue, gccjit::type type, gccjit::location loc) Given an rvalue of T, construct another rvalue of another type. @@ -13008,25 +13467,25 @@ P* <-> Q*, for pointer types P and Q @end deffn @node Lvalues<2>,Working with pointers structs and unions<2>,Rvalues<2>,Expressions<2> -@anchor{cp/topics/expressions lvalues}@anchor{21b} +@anchor{cp/topics/expressions lvalues}@anchor{2d5} @subsubsection Lvalues @geindex gccjit;;lvalue (C++ class) -@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalueE}@anchor{13f}@anchor{cp/topics/expressions gccjit lvalue}@anchor{21c} +@anchor{cp/topics/expressions _CPPv4N6gccjit6lvalueE}@anchor{14f}@anchor{cp/topics/expressions _CPPv3N6gccjit6lvalueE}@anchor{2d6}@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalueE}@anchor{2d7}@anchor{cp/topics/expressions gccjit lvalue}@anchor{2d8} @deffn {C++ Class} gccjit::lvalue @end deffn An lvalue is something that can of the @emph{left}-hand side of an assignment: a storage area (such as a variable). It is a subclass of -@ref{136,,gccjit;;rvalue}, where the rvalue is computed by reading from the +@ref{146,,gccjit;;rvalue}, where the rvalue is computed by reading from the storage area. It iss a thin wrapper around @ref{24,,gcc_jit_lvalue *} from the C API. @geindex gccjit;;lvalue;;get_address (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalue11get_addressEN6gccjit8locationE}@anchor{21d}@anchor{cp/topics/expressions gccjit lvalue get_address__gccjit location}@anchor{21e} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::lvalue::get_address (gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit6lvalue11get_addressEN6gccjit8locationE}@anchor{2d9}@anchor{cp/topics/expressions _CPPv3N6gccjit6lvalue11get_addressEN6gccjit8locationE}@anchor{2da}@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalue11get_addressEN6gccjit8locationE}@anchor{2db}@anchor{cp/topics/expressions gccjit lvalue get_address__gccjit location}@anchor{2dc} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{14f,,lvalue}::get_address (gccjit::location loc) Take the address of an lvalue; analogous to: @@ -13045,13 +13504,13 @@ Parameter “loc” is optional. @end menu @node Global variables<2>,,,Lvalues<2> -@anchor{cp/topics/expressions global-variables}@anchor{21f} +@anchor{cp/topics/expressions global-variables}@anchor{2dd} @subsubsection Global variables @geindex gccjit;;context;;new_global (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_globalE19gcc_jit_global_kindN6gccjit4typeEPKcN6gccjit8locationE}@anchor{220}@anchor{cp/topics/expressions gccjit context new_global__gcc_jit_global_kind gccjit type cCP gccjit location}@anchor{221} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::context::new_global (enum gcc_jit_global_kind, gccjit::type type, const char *name, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context10new_globalE19gcc_jit_global_kindN6gccjit4typeEPKcN6gccjit8locationE}@anchor{2de}@anchor{cp/topics/expressions _CPPv3N6gccjit7context10new_globalE19gcc_jit_global_kindN6gccjit4typeEPKcN6gccjit8locationE}@anchor{2df}@anchor{cp/topics/expressions _CPPv2N6gccjit7context10new_globalE19gcc_jit_global_kindN6gccjit4typeEPKcN6gccjit8locationE}@anchor{2e0}@anchor{cp/topics/expressions gccjit context new_global__gcc_jit_global_kind gccjit type cCP gccjit location}@anchor{2e1} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{13d,,context}::new_global (enum gcc_jit_global_kind, gccjit::type type, const char *name, gccjit::location loc) Add a new global variable of the given type and name to the context. @@ -13060,13 +13519,13 @@ the C API; the “kind” parameter has the same meaning as there. @end deffn @node Working with pointers structs and unions<2>,,Lvalues<2>,Expressions<2> -@anchor{cp/topics/expressions working-with-pointers-structs-and-unions}@anchor{222} +@anchor{cp/topics/expressions working-with-pointers-structs-and-unions}@anchor{2e2} @subsubsection Working with pointers, structs and unions @geindex gccjit;;rvalue;;dereference (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue11dereferenceEN6gccjit8locationE}@anchor{223}@anchor{cp/topics/expressions gccjit rvalue dereference__gccjit location}@anchor{224} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::rvalue::dereference (gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvalue11dereferenceEN6gccjit8locationE}@anchor{2e3}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvalue11dereferenceEN6gccjit8locationE}@anchor{2e4}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue11dereferenceEN6gccjit8locationE}@anchor{2e5}@anchor{cp/topics/expressions gccjit rvalue dereference__gccjit location}@anchor{2e6} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{146,,rvalue}::dereference (gccjit::location loc) Given an rvalue of pointer type @code{T *}, dereferencing the pointer, getting an lvalue of type @code{T}. Analogous to: @@ -13084,8 +13543,8 @@ If you don’t need to specify the location, this can also be expressed using an overloaded operator: @geindex gccjit;;rvalue;;operator* (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvaluemlEv}@anchor{225}@anchor{cp/topics/expressions gccjit rvalue mul-operator}@anchor{226} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::rvalue::operator* () +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvaluemlEv}@anchor{2e7}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvaluemlEv}@anchor{2e8}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvaluemlEv}@anchor{2e9}@anchor{cp/topics/expressions gccjit rvalue mul-operator}@anchor{2ea} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{146,,rvalue}::operator* () @example gccjit::lvalue content = *ptr; @@ -13095,8 +13554,8 @@ gccjit::lvalue content = *ptr; Field access is provided separately for both lvalues and rvalues: @geindex gccjit;;lvalue;;access_field (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{227}@anchor{cp/topics/expressions gccjit lvalue access_field__gccjit field gccjit location}@anchor{228} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::lvalue::access_field (gccjit::field field, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit6lvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2eb}@anchor{cp/topics/expressions _CPPv3N6gccjit6lvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2ec}@anchor{cp/topics/expressions _CPPv2N6gccjit6lvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2ed}@anchor{cp/topics/expressions gccjit lvalue access_field__gccjit field gccjit location}@anchor{2ee} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{14f,,lvalue}::access_field (gccjit::field field, gccjit::location loc) Given an lvalue of struct or union type, access the given field, getting an lvalue of the field’s type. Analogous to: @@ -13109,8 +13568,8 @@ in C. @end deffn @geindex gccjit;;rvalue;;access_field (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{229}@anchor{cp/topics/expressions gccjit rvalue access_field__gccjit field gccjit location}@anchor{22a} -@deffn {C++ Function} gccjit::@ref{136,,rvalue} gccjit::rvalue::access_field (gccjit::field field, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2ef}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2f0}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue12access_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2f1}@anchor{cp/topics/expressions gccjit rvalue access_field__gccjit field gccjit location}@anchor{2f2} +@deffn {C++ Function} gccjit::@ref{146,,rvalue} gccjit::@ref{146,,rvalue}::access_field (gccjit::field field, gccjit::location loc) Given an rvalue of struct or union type, access the given field as an rvalue. Analogous to: @@ -13123,8 +13582,8 @@ in C. @end deffn @geindex gccjit;;rvalue;;dereference_field (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue17dereference_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{22b}@anchor{cp/topics/expressions gccjit rvalue dereference_field__gccjit field gccjit location}@anchor{22c} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::rvalue::dereference_field (gccjit::field field, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit6rvalue17dereference_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2f3}@anchor{cp/topics/expressions _CPPv3N6gccjit6rvalue17dereference_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2f4}@anchor{cp/topics/expressions _CPPv2N6gccjit6rvalue17dereference_fieldEN6gccjit5fieldEN6gccjit8locationE}@anchor{2f5}@anchor{cp/topics/expressions gccjit rvalue dereference_field__gccjit field gccjit location}@anchor{2f6} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{146,,rvalue}::dereference_field (gccjit::field field, gccjit::location loc) Given an rvalue of pointer type @code{T *} where T is of struct or union type, access the given field as an lvalue. Analogous to: @@ -13137,8 +13596,8 @@ in C, itself equivalent to @code{(*EXPR).FIELD}. @end deffn @geindex gccjit;;context;;new_array_access (C++ function) -@anchor{cp/topics/expressions _CPPv2N6gccjit7context16new_array_accessEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{22d}@anchor{cp/topics/expressions gccjit context new_array_access__gccjit rvalue gccjit rvalue gccjit location}@anchor{22e} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::context::new_array_access (gccjit::rvalue ptr, gccjit::rvalue index, gccjit::location loc) +@anchor{cp/topics/expressions _CPPv4N6gccjit7context16new_array_accessEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2f7}@anchor{cp/topics/expressions _CPPv3N6gccjit7context16new_array_accessEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2f8}@anchor{cp/topics/expressions _CPPv2N6gccjit7context16new_array_accessEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2f9}@anchor{cp/topics/expressions gccjit context new_array_access__gccjit rvalue gccjit rvalue gccjit location}@anchor{2fa} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{13d,,context}::new_array_access (gccjit::rvalue ptr, gccjit::rvalue index, gccjit::location loc) Given an rvalue of pointer type @code{T *}, get at the element @cite{T} at the given index, using standard C array indexing rules i.e. each @@ -13154,7 +13613,7 @@ in C (or, indeed, to @code{PTR + INDEX}). Parameter “loc” is optional. @end deffn -For array accesses where you don’t need to specify a @ref{153,,gccjit;;location}, +For array accesses where you don’t need to specify a @ref{163,,gccjit;;location}, two overloaded operators are available: @quotation @@ -13190,7 +13649,7 @@ gccjit::lvalue element = array[0]; @c . @node Creating and using functions<2>,Source Locations<2>,Expressions<2>,Topic Reference<2> -@anchor{cp/topics/functions doc}@anchor{22f}@anchor{cp/topics/functions creating-and-using-functions}@anchor{230} +@anchor{cp/topics/functions doc}@anchor{2fb}@anchor{cp/topics/functions creating-and-using-functions}@anchor{2fc} @subsection Creating and using functions @@ -13203,36 +13662,36 @@ gccjit::lvalue element = array[0]; @end menu @node Params<2>,Functions<2>,,Creating and using functions<2> -@anchor{cp/topics/functions params}@anchor{231} +@anchor{cp/topics/functions params}@anchor{2fd} @subsubsection Params @geindex gccjit;;param (C++ class) -@anchor{cp/topics/functions _CPPv2N6gccjit5paramE}@anchor{140}@anchor{cp/topics/functions gccjit param}@anchor{232} +@anchor{cp/topics/functions _CPPv4N6gccjit5paramE}@anchor{150}@anchor{cp/topics/functions _CPPv3N6gccjit5paramE}@anchor{2fe}@anchor{cp/topics/functions _CPPv2N6gccjit5paramE}@anchor{2ff}@anchor{cp/topics/functions gccjit param}@anchor{300} @deffn {C++ Class} gccjit::param A @cite{gccjit::param} represents a parameter to a function. @end deffn @geindex gccjit;;context;;new_param (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit7context9new_paramEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{134}@anchor{cp/topics/functions gccjit context new_param__gccjit type cCP gccjit location}@anchor{233} -@deffn {C++ Function} gccjit::@ref{140,,param} gccjit::context::new_param (gccjit::type type, const char *name, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit7context9new_paramEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{144}@anchor{cp/topics/functions _CPPv3N6gccjit7context9new_paramEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{301}@anchor{cp/topics/functions _CPPv2N6gccjit7context9new_paramEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{302}@anchor{cp/topics/functions gccjit context new_param__gccjit type cCP gccjit location}@anchor{303} +@deffn {C++ Function} gccjit::@ref{150,,param} gccjit::@ref{13d,,context}::new_param (gccjit::type type, const char *name, gccjit::location loc) In preparation for creating a function, create a new parameter of the given type and name. @end deffn -@ref{140,,gccjit;;param} is a subclass of @ref{13f,,gccjit;;lvalue} (and thus -of @ref{136,,gccjit;;rvalue} and @ref{132,,gccjit;;object}). It is a thin +@ref{150,,gccjit;;param} is a subclass of @ref{14f,,gccjit;;lvalue} (and thus +of @ref{146,,gccjit;;rvalue} and @ref{142,,gccjit;;object}). It is a thin wrapper around the C API’s @ref{25,,gcc_jit_param *}. @node Functions<2>,Blocks<2>,Params<2>,Creating and using functions<2> -@anchor{cp/topics/functions functions}@anchor{234} +@anchor{cp/topics/functions functions}@anchor{304} @subsubsection Functions @geindex gccjit;;function (C++ class) -@anchor{cp/topics/functions _CPPv2N6gccjit8functionE}@anchor{144}@anchor{cp/topics/functions gccjit function}@anchor{235} +@anchor{cp/topics/functions _CPPv4N6gccjit8functionE}@anchor{154}@anchor{cp/topics/functions _CPPv3N6gccjit8functionE}@anchor{305}@anchor{cp/topics/functions _CPPv2N6gccjit8functionE}@anchor{306}@anchor{cp/topics/functions gccjit function}@anchor{307} @deffn {C++ Class} gccjit::function A @cite{gccjit::function} represents a function - either one that we’re @@ -13240,8 +13699,8 @@ creating ourselves, or one that we’re referencing. @end deffn @geindex gccjit;;context;;new_function (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit7context12new_functionE21gcc_jit_function_kindN6gccjit4typeEPKcRNSt6vectorI5paramEEiN6gccjit8locationE}@anchor{236}@anchor{cp/topics/functions gccjit context new_function__gcc_jit_function_kind gccjit type cCP std vector param R i gccjit location}@anchor{237} -@deffn {C++ Function} gccjit::@ref{144,,function} gccjit::context::new_function (enum gcc_jit_function_kind, gccjit::type return_type, const char *name, std::vector ¶ms, int is_variadic, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit7context12new_functionE21gcc_jit_function_kindN6gccjit4typeEPKcRNSt6vectorI5paramEEiN6gccjit8locationE}@anchor{308}@anchor{cp/topics/functions _CPPv3N6gccjit7context12new_functionE21gcc_jit_function_kindN6gccjit4typeEPKcRNSt6vectorI5paramEEiN6gccjit8locationE}@anchor{309}@anchor{cp/topics/functions _CPPv2N6gccjit7context12new_functionE21gcc_jit_function_kindN6gccjit4typeEPKcRNSt6vectorI5paramEEiN6gccjit8locationE}@anchor{30a}@anchor{cp/topics/functions gccjit context new_function__gcc_jit_function_kind gccjit type cCP std vector param R i gccjit location}@anchor{30b} +@deffn {C++ Function} gccjit::@ref{154,,function} gccjit::@ref{13d,,context}::new_function (enum gcc_jit_function_kind, gccjit::type return_type, const char *name, std::vector ¶ms, int is_variadic, gccjit::location loc) Create a gcc_jit_function with the given name and parameters. @@ -13251,49 +13710,49 @@ This is a wrapper around the C API’s @ref{11,,gcc_jit_context_new_function()}. @end deffn @geindex gccjit;;context;;get_builtin_function (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit7context20get_builtin_functionEPKc}@anchor{238}@anchor{cp/topics/functions gccjit context get_builtin_function__cCP}@anchor{239} -@deffn {C++ Function} gccjit::@ref{144,,function} gccjit::context::get_builtin_function (const char *name) +@anchor{cp/topics/functions _CPPv4N6gccjit7context20get_builtin_functionEPKc}@anchor{30c}@anchor{cp/topics/functions _CPPv3N6gccjit7context20get_builtin_functionEPKc}@anchor{30d}@anchor{cp/topics/functions _CPPv2N6gccjit7context20get_builtin_functionEPKc}@anchor{30e}@anchor{cp/topics/functions gccjit context get_builtin_function__cCP}@anchor{30f} +@deffn {C++ Function} gccjit::@ref{154,,function} gccjit::@ref{13d,,context}::get_builtin_function (const char *name) This is a wrapper around the C API’s @ref{e1,,gcc_jit_context_get_builtin_function()}. @end deffn @geindex gccjit;;function;;get_param (C++ function) -@anchor{cp/topics/functions _CPPv2NK6gccjit8function9get_paramEi}@anchor{23a}@anchor{cp/topics/functions gccjit function get_param__iC}@anchor{23b} -@deffn {C++ Function} gccjit::@ref{140,,param} gccjit::function::get_param (int index) const +@anchor{cp/topics/functions _CPPv4NK6gccjit8function9get_paramEi}@anchor{310}@anchor{cp/topics/functions _CPPv3NK6gccjit8function9get_paramEi}@anchor{311}@anchor{cp/topics/functions _CPPv2NK6gccjit8function9get_paramEi}@anchor{312}@anchor{cp/topics/functions gccjit function get_param__iC}@anchor{313} +@deffn {C++ Function} gccjit::@ref{150,,param} gccjit::@ref{154,,function}::get_param (int index) const Get the param of the given index (0-based). @end deffn @geindex gccjit;;function;;dump_to_dot (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit8function11dump_to_dotEPKc}@anchor{14c}@anchor{cp/topics/functions gccjit function dump_to_dot__cCP}@anchor{23c} -@deffn {C++ Function} void gccjit::function::dump_to_dot (const char *path) +@anchor{cp/topics/functions _CPPv4N6gccjit8function11dump_to_dotEPKc}@anchor{15c}@anchor{cp/topics/functions _CPPv3N6gccjit8function11dump_to_dotEPKc}@anchor{314}@anchor{cp/topics/functions _CPPv2N6gccjit8function11dump_to_dotEPKc}@anchor{315}@anchor{cp/topics/functions gccjit function dump_to_dot__cCP}@anchor{316} +@deffn {C++ Function} void gccjit::@ref{154,,function}::dump_to_dot (const char *path) Emit the function in graphviz format to the given path. @end deffn @geindex gccjit;;function;;new_local (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit8function9new_localEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{141}@anchor{cp/topics/functions gccjit function new_local__gccjit type cCP gccjit location}@anchor{23d} -@deffn {C++ Function} gccjit::@ref{13f,,lvalue} gccjit::function::new_local (gccjit::type type, const char *name, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit8function9new_localEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{151}@anchor{cp/topics/functions _CPPv3N6gccjit8function9new_localEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{317}@anchor{cp/topics/functions _CPPv2N6gccjit8function9new_localEN6gccjit4typeEPKcN6gccjit8locationE}@anchor{318}@anchor{cp/topics/functions gccjit function new_local__gccjit type cCP gccjit location}@anchor{319} +@deffn {C++ Function} gccjit::@ref{14f,,lvalue} gccjit::@ref{154,,function}::new_local (gccjit::type type, const char *name, gccjit::location loc) Create a new local variable within the function, of the given type and name. @end deffn @node Blocks<2>,Statements<2>,Functions<2>,Creating and using functions<2> -@anchor{cp/topics/functions blocks}@anchor{23e} +@anchor{cp/topics/functions blocks}@anchor{31a} @subsubsection Blocks @geindex gccjit;;block (C++ class) -@anchor{cp/topics/functions _CPPv2N6gccjit5blockE}@anchor{143}@anchor{cp/topics/functions gccjit block}@anchor{23f} +@anchor{cp/topics/functions _CPPv4N6gccjit5blockE}@anchor{153}@anchor{cp/topics/functions _CPPv3N6gccjit5blockE}@anchor{31b}@anchor{cp/topics/functions _CPPv2N6gccjit5blockE}@anchor{31c}@anchor{cp/topics/functions gccjit block}@anchor{31d} @deffn {C++ Class} gccjit::block A @cite{gccjit::block} represents a basic block within a function i.e. a sequence of statements with a single entry point and a single exit point. -@ref{143,,gccjit;;block} is a subclass of @ref{132,,gccjit;;object}. +@ref{153,,gccjit;;block} is a subclass of @ref{142,,gccjit;;object}. The first basic block that you create within a function will be the entrypoint. @@ -13307,8 +13766,8 @@ one function. @end deffn @geindex gccjit;;function;;new_block (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit8function9new_blockEPKc}@anchor{240}@anchor{cp/topics/functions gccjit function new_block__cCP}@anchor{241} -@deffn {C++ Function} gccjit::@ref{143,,block} gccjit::function::new_block (const char *name) +@anchor{cp/topics/functions _CPPv4N6gccjit8function9new_blockEPKc}@anchor{31e}@anchor{cp/topics/functions _CPPv3N6gccjit8function9new_blockEPKc}@anchor{31f}@anchor{cp/topics/functions _CPPv2N6gccjit8function9new_blockEPKc}@anchor{320}@anchor{cp/topics/functions gccjit function new_block__cCP}@anchor{321} +@deffn {C++ Function} gccjit::@ref{153,,block} gccjit::@ref{154,,function}::new_block (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 @@ -13317,13 +13776,13 @@ messages. @end deffn @node Statements<2>,,Blocks<2>,Creating and using functions<2> -@anchor{cp/topics/functions statements}@anchor{242} +@anchor{cp/topics/functions statements}@anchor{322} @subsubsection Statements @geindex gccjit;;block;;add_eval (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block8add_evalEN6gccjit6rvalueEN6gccjit8locationE}@anchor{214}@anchor{cp/topics/functions gccjit block add_eval__gccjit rvalue gccjit location}@anchor{243} -@deffn {C++ Function} void gccjit::block::add_eval (gccjit::rvalue rvalue, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block8add_evalEN6gccjit6rvalueEN6gccjit8locationE}@anchor{2ca}@anchor{cp/topics/functions _CPPv3N6gccjit5block8add_evalEN6gccjit6rvalueEN6gccjit8locationE}@anchor{323}@anchor{cp/topics/functions _CPPv2N6gccjit5block8add_evalEN6gccjit6rvalueEN6gccjit8locationE}@anchor{324}@anchor{cp/topics/functions gccjit block add_eval__gccjit rvalue gccjit location}@anchor{325} +@deffn {C++ Function} void gccjit::@ref{153,,block}::add_eval (gccjit::rvalue rvalue, gccjit::location loc) Add evaluation of an rvalue, discarding the result (e.g. a function call that “returns” void). @@ -13336,8 +13795,8 @@ This is equivalent to this C code: @end deffn @geindex gccjit;;block;;add_assignment (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block14add_assignmentEN6gccjit6lvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{145}@anchor{cp/topics/functions gccjit block add_assignment__gccjit lvalue gccjit rvalue gccjit location}@anchor{244} -@deffn {C++ Function} void gccjit::block::add_assignment (gccjit::lvalue lvalue, gccjit::rvalue rvalue, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block14add_assignmentEN6gccjit6lvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{155}@anchor{cp/topics/functions _CPPv3N6gccjit5block14add_assignmentEN6gccjit6lvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{326}@anchor{cp/topics/functions _CPPv2N6gccjit5block14add_assignmentEN6gccjit6lvalueEN6gccjit6rvalueEN6gccjit8locationE}@anchor{327}@anchor{cp/topics/functions gccjit block add_assignment__gccjit lvalue gccjit rvalue gccjit location}@anchor{328} +@deffn {C++ Function} void gccjit::@ref{153,,block}::add_assignment (gccjit::lvalue lvalue, gccjit::rvalue rvalue, gccjit::location loc) Add evaluation of an rvalue, assigning the result to the given lvalue. @@ -13350,8 +13809,8 @@ lvalue = rvalue; @end deffn @geindex gccjit;;block;;add_assignment_op (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block17add_assignment_opEN6gccjit6lvalueE17gcc_jit_binary_opN6gccjit6rvalueEN6gccjit8locationE}@anchor{149}@anchor{cp/topics/functions gccjit block add_assignment_op__gccjit lvalue gcc_jit_binary_op gccjit rvalue gccjit location}@anchor{245} -@deffn {C++ Function} void gccjit::block::add_assignment_op (gccjit::lvalue lvalue, enum gcc_jit_binary_op, gccjit::rvalue rvalue, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block17add_assignment_opEN6gccjit6lvalueE17gcc_jit_binary_opN6gccjit6rvalueEN6gccjit8locationE}@anchor{159}@anchor{cp/topics/functions _CPPv3N6gccjit5block17add_assignment_opEN6gccjit6lvalueE17gcc_jit_binary_opN6gccjit6rvalueEN6gccjit8locationE}@anchor{329}@anchor{cp/topics/functions _CPPv2N6gccjit5block17add_assignment_opEN6gccjit6lvalueE17gcc_jit_binary_opN6gccjit6rvalueEN6gccjit8locationE}@anchor{32a}@anchor{cp/topics/functions gccjit block add_assignment_op__gccjit lvalue gcc_jit_binary_op gccjit rvalue gccjit location}@anchor{32b} +@deffn {C++ Function} void gccjit::@ref{153,,block}::add_assignment_op (gccjit::lvalue lvalue, enum gcc_jit_binary_op, gccjit::rvalue rvalue, gccjit::location loc) Add evaluation of an rvalue, using the result to modify an lvalue. @@ -13376,8 +13835,8 @@ loop_body.add_assignment_op ( @end deffn @geindex gccjit;;block;;add_comment (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block11add_commentEPKcN6gccjit8locationE}@anchor{155}@anchor{cp/topics/functions gccjit block add_comment__cCP gccjit location}@anchor{246} -@deffn {C++ Function} void gccjit::block::add_comment (const char *text, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block11add_commentEPKcN6gccjit8locationE}@anchor{165}@anchor{cp/topics/functions _CPPv3N6gccjit5block11add_commentEPKcN6gccjit8locationE}@anchor{32c}@anchor{cp/topics/functions _CPPv2N6gccjit5block11add_commentEPKcN6gccjit8locationE}@anchor{32d}@anchor{cp/topics/functions gccjit block add_comment__cCP gccjit location}@anchor{32e} +@deffn {C++ Function} void gccjit::@ref{153,,block}::add_comment (const char *text, gccjit::location loc) 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 @@ -13390,8 +13849,8 @@ Parameter “loc” is optional. @end deffn @geindex gccjit;;block;;end_with_conditional (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block20end_with_conditionalEN6gccjit6rvalueEN6gccjit5blockEN6gccjit5blockEN6gccjit8locationE}@anchor{148}@anchor{cp/topics/functions gccjit block end_with_conditional__gccjit rvalue gccjit block gccjit block gccjit location}@anchor{247} -@deffn {C++ Function} void gccjit::block::end_with_conditional (gccjit::rvalue boolval, gccjit::block on_true, gccjit::block on_false, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block20end_with_conditionalEN6gccjit6rvalueEN6gccjit5blockEN6gccjit5blockEN6gccjit8locationE}@anchor{158}@anchor{cp/topics/functions _CPPv3N6gccjit5block20end_with_conditionalEN6gccjit6rvalueEN6gccjit5blockEN6gccjit5blockEN6gccjit8locationE}@anchor{32f}@anchor{cp/topics/functions _CPPv2N6gccjit5block20end_with_conditionalEN6gccjit6rvalueEN6gccjit5blockEN6gccjit5blockEN6gccjit8locationE}@anchor{330}@anchor{cp/topics/functions gccjit block end_with_conditional__gccjit rvalue gccjit block gccjit block gccjit location}@anchor{331} +@deffn {C++ Function} void gccjit::@ref{153,,block}::end_with_conditional (gccjit::rvalue boolval, gccjit::block on_true, gccjit::block on_false, gccjit::location loc) Terminate a block by adding evaluation of an rvalue, branching on the result to the appropriate successor block. @@ -13409,8 +13868,8 @@ block, boolval, on_true, and on_false must be non-NULL. @end deffn @geindex gccjit;;block;;end_with_jump (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block13end_with_jumpEN6gccjit5blockEN6gccjit8locationE}@anchor{248}@anchor{cp/topics/functions gccjit block end_with_jump__gccjit block gccjit location}@anchor{249} -@deffn {C++ Function} void gccjit::block::end_with_jump (gccjit::block target, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block13end_with_jumpEN6gccjit5blockEN6gccjit8locationE}@anchor{332}@anchor{cp/topics/functions _CPPv3N6gccjit5block13end_with_jumpEN6gccjit5blockEN6gccjit8locationE}@anchor{333}@anchor{cp/topics/functions _CPPv2N6gccjit5block13end_with_jumpEN6gccjit5blockEN6gccjit8locationE}@anchor{334}@anchor{cp/topics/functions gccjit block end_with_jump__gccjit block gccjit location}@anchor{335} +@deffn {C++ Function} void gccjit::@ref{153,,block}::end_with_jump (gccjit::block target, gccjit::location loc) Terminate a block by adding a jump to the given target block. @@ -13422,8 +13881,8 @@ goto target; @end deffn @geindex gccjit;;block;;end_with_return (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_returnEN6gccjit6rvalueEN6gccjit8locationE}@anchor{24a}@anchor{cp/topics/functions gccjit block end_with_return__gccjit rvalue gccjit location}@anchor{24b} -@deffn {C++ Function} void gccjit::block::end_with_return (gccjit::rvalue rvalue, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block15end_with_returnEN6gccjit6rvalueEN6gccjit8locationE}@anchor{336}@anchor{cp/topics/functions _CPPv3N6gccjit5block15end_with_returnEN6gccjit6rvalueEN6gccjit8locationE}@anchor{337}@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_returnEN6gccjit6rvalueEN6gccjit8locationE}@anchor{338}@anchor{cp/topics/functions gccjit block end_with_return__gccjit rvalue gccjit location}@anchor{339} +@deffn {C++ Function} void gccjit::@ref{153,,block}::end_with_return (gccjit::rvalue rvalue, gccjit::location loc) Terminate a block. @@ -13452,8 +13911,8 @@ return; @end deffn @geindex gccjit;;block;;end_with_switch (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_switchEN6gccjit6rvalueEN6gccjit5blockENSt6vectorIN6gccjit5case_EEEN6gccjit8locationE}@anchor{24c}@anchor{cp/topics/functions gccjit block end_with_switch__gccjit rvalue gccjit block std vector gccjit case_ gccjit location}@anchor{24d} -@deffn {C++ Function} void gccjit::block::end_with_switch (gccjit::rvalue expr, gccjit::block default_block, std::vector cases, gccjit::location loc) +@anchor{cp/topics/functions _CPPv4N6gccjit5block15end_with_switchEN6gccjit6rvalueEN6gccjit5blockENSt6vectorIN6gccjit5case_EEEN6gccjit8locationE}@anchor{33a}@anchor{cp/topics/functions _CPPv3N6gccjit5block15end_with_switchEN6gccjit6rvalueEN6gccjit5blockENSt6vectorIN6gccjit5case_EEEN6gccjit8locationE}@anchor{33b}@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_switchEN6gccjit6rvalueEN6gccjit5blockENSt6vectorIN6gccjit5case_EEEN6gccjit8locationE}@anchor{33c}@anchor{cp/topics/functions gccjit block end_with_switch__gccjit rvalue gccjit block std vector gccjit case_ gccjit location}@anchor{33d} +@deffn {C++ Function} void gccjit::@ref{153,,block}::end_with_switch (gccjit::rvalue expr, gccjit::block default_block, std::vector cases, gccjit::location loc) Terminate a block by adding evalation of an rvalue, then performing a multiway branch. @@ -13493,10 +13952,10 @@ The API entrypoints relating to switch statements and cases: @itemize * @item -@code{gccjit::block::end_with_switch()} +@ref{33a,,gccjit;;block;;end_with_switch()} @item -@ref{24e,,gccjit;;context;;new_case()} +@code{gccjit::context::new_case()} @end itemize @end quotation @@ -13507,32 +13966,15 @@ using #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS @end example -@geindex gccjit;;block;;end_with_switch;;gccjit;;case_ (C++ class) -@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_switch6gccjit5case_E}@anchor{24f}@anchor{cp/topics/functions gccjit block end_with_switch gccjit case_}@anchor{250} -@deffn {C++ Class} gccjit::case_ -@end deffn - A @cite{gccjit::case_} represents a case within a switch statement, and -is created within a particular @code{gccjit::context} using -@ref{24e,,gccjit;;context;;new_case()}. It is a subclass of -@code{gccjit::object}. +is created within a particular @ref{13d,,gccjit;;context} using +@code{gccjit::context::new_case()}. It is a subclass of +@ref{142,,gccjit;;object}. Each case expresses a multivalued range of integer values. You can express single-valued cases by passing in the same value for both @cite{min_value} and @cite{max_value}. -@geindex gccjit;;block;;end_with_switch;;gccjit;;context;;new_case (C++ function) -@anchor{cp/topics/functions _CPPv2N6gccjit5block15end_with_switch6gccjit7context8new_caseEN6gccjit6rvalueEN6gccjit6rvalueEN6gccjit5blockE}@anchor{24e}@anchor{cp/topics/functions gccjit block end_with_switch gccjit context new_case__gccjit rvalue gccjit rvalue gccjit block}@anchor{251} -@deffn {C++ Function} gccjit::@ref{24f,,case_} *gccjit::context::new_case (gccjit::rvalue min_value, gccjit::rvalue max_value, gccjit::block dest_block) - -Create a new gccjit::case for use in a switch statement. -@cite{min_value} and @cite{max_value} must be constants of an integer type, -which must match that of the expression of the switch statement. - -@cite{dest_block} must be within the same function as the switch -statement. -@end deffn - Here’s an example of creating a switch statement: @quotation @@ -13630,12 +14072,12 @@ create_code (gcc_jit_context *c_ctxt, void *user_data) @c . @node Source Locations<2>,Compiling a context<2>,Creating and using functions<2>,Topic Reference<2> -@anchor{cp/topics/locations source-locations}@anchor{252}@anchor{cp/topics/locations doc}@anchor{253} +@anchor{cp/topics/locations doc}@anchor{33e}@anchor{cp/topics/locations source-locations}@anchor{33f} @subsection Source Locations @geindex gccjit;;location (C++ class) -@anchor{cp/topics/locations _CPPv2N6gccjit8locationE}@anchor{153}@anchor{cp/topics/locations gccjit location}@anchor{254} +@anchor{cp/topics/locations _CPPv4N6gccjit8locationE}@anchor{163}@anchor{cp/topics/locations _CPPv3N6gccjit8locationE}@anchor{340}@anchor{cp/topics/locations _CPPv2N6gccjit8locationE}@anchor{341}@anchor{cp/topics/locations gccjit location}@anchor{342} @deffn {C++ Class} gccjit::location A @cite{gccjit::location} encapsulates a source code location, so that @@ -13646,10 +14088,10 @@ single-step through your language. @cite{gccjit::location} instances are optional: you can always omit them from any C++ API entrypoint accepting one. -You can construct them using @ref{159,,gccjit;;context;;new_location()}. +You can construct them using @ref{169,,gccjit;;context;;new_location()}. You need to enable @ref{42,,GCC_JIT_BOOL_OPTION_DEBUGINFO} on the -@ref{12d,,gccjit;;context} for these locations to actually be usable by +@ref{13d,,gccjit;;context} for these locations to actually be usable by the debugger: @example @@ -13658,8 +14100,8 @@ ctxt.set_bool_option (GCC_JIT_BOOL_OPTION_DEBUGINFO, 1); @end deffn @geindex gccjit;;context;;new_location (C++ function) -@anchor{cp/topics/locations _CPPv2N6gccjit7context12new_locationEPKcii}@anchor{159}@anchor{cp/topics/locations gccjit context new_location__cCP i i}@anchor{255} -@deffn {C++ Function} gccjit::@ref{153,,location} gccjit::context::new_location (const char *filename, int line, int column) +@anchor{cp/topics/locations _CPPv4N6gccjit7context12new_locationEPKcii}@anchor{169}@anchor{cp/topics/locations _CPPv3N6gccjit7context12new_locationEPKcii}@anchor{343}@anchor{cp/topics/locations _CPPv2N6gccjit7context12new_locationEPKcii}@anchor{344}@anchor{cp/topics/locations gccjit context new_location__cCP i i}@anchor{345} +@deffn {C++ Function} gccjit::@ref{163,,location} gccjit::@ref{13d,,context}::new_location (const char *filename, int line, int column) Create a @cite{gccjit::location} instance representing the given source location. @@ -13671,13 +14113,13 @@ location. @end menu @node Faking it<2>,,,Source Locations<2> -@anchor{cp/topics/locations faking-it}@anchor{256} +@anchor{cp/topics/locations faking-it}@anchor{346} @subsubsection Faking it If you don’t have source code for your internal representation, but need to debug, you can generate a C-like representation of the functions in -your context using @ref{16e,,gccjit;;context;;dump_to_file()}: +your context using @ref{188,,gccjit;;context;;dump_to_file()}: @example ctxt.dump_to_file ("/tmp/something.c", @@ -13706,14 +14148,14 @@ file, giving you @emph{something} you can step through in the debugger. @c along with this program. If not, see @c . -@node Compiling a context<2>,,Source Locations<2>,Topic Reference<2> -@anchor{cp/topics/compilation compiling-a-context}@anchor{257}@anchor{cp/topics/compilation doc}@anchor{258} +@node Compiling a context<2>,Using Assembly Language with libgccjit++,Source Locations<2>,Topic Reference<2> +@anchor{cp/topics/compilation doc}@anchor{347}@anchor{cp/topics/compilation compiling-a-context}@anchor{348} @subsection Compiling a context -Once populated, a @ref{12d,,gccjit;;context} can be compiled to -machine code, either in-memory via @ref{137,,gccjit;;context;;compile()} or -to disk via @ref{259,,gccjit;;context;;compile_to_file()}. +Once populated, a @ref{13d,,gccjit;;context} can be compiled to +machine code, either in-memory via @ref{147,,gccjit;;context;;compile()} or +to disk via @ref{349,,gccjit;;context;;compile_to_file()}. You can compile a context multiple times (using either form of compilation), although any errors that occur on the context will @@ -13726,13 +14168,13 @@ prevent any future compilation of that context. @end menu @node In-memory compilation<2>,Ahead-of-time compilation<2>,,Compiling a context<2> -@anchor{cp/topics/compilation in-memory-compilation}@anchor{25a} +@anchor{cp/topics/compilation in-memory-compilation}@anchor{34a} @subsubsection In-memory compilation @geindex gccjit;;context;;compile (C++ function) -@anchor{cp/topics/compilation _CPPv2N6gccjit7context7compileEv}@anchor{137}@anchor{cp/topics/compilation gccjit context compile}@anchor{25b} -@deffn {C++ Function} gcc_jit_result *gccjit::context::compile () +@anchor{cp/topics/compilation _CPPv4N6gccjit7context7compileEv}@anchor{147}@anchor{cp/topics/compilation _CPPv3N6gccjit7context7compileEv}@anchor{34b}@anchor{cp/topics/compilation _CPPv2N6gccjit7context7compileEv}@anchor{34c}@anchor{cp/topics/compilation gccjit context compile}@anchor{34d} +@deffn {C++ Function} gcc_jit_result *gccjit::@ref{13d,,context}::compile () This calls into GCC and builds the code, returning a @cite{gcc_jit_result *}. @@ -13742,25 +14184,418 @@ This is a thin wrapper around the @end deffn @node Ahead-of-time compilation<2>,,In-memory compilation<2>,Compiling a context<2> -@anchor{cp/topics/compilation ahead-of-time-compilation}@anchor{25c} +@anchor{cp/topics/compilation ahead-of-time-compilation}@anchor{34e} @subsubsection Ahead-of-time compilation Although libgccjit is primarily aimed at just-in-time compilation, it can also be used for implementing more traditional ahead-of-time -compilers, via the @ref{259,,gccjit;;context;;compile_to_file()} method. +compilers, via the @ref{349,,gccjit;;context;;compile_to_file()} method. @geindex gccjit;;context;;compile_to_file (C++ function) -@anchor{cp/topics/compilation _CPPv2N6gccjit7context15compile_to_fileE19gcc_jit_output_kindPKc}@anchor{259}@anchor{cp/topics/compilation gccjit context compile_to_file__gcc_jit_output_kind cCP}@anchor{25d} -@deffn {C++ Function} void gccjit::context::compile_to_file (enum gcc_jit_output_kind, const char *output_path) +@anchor{cp/topics/compilation _CPPv4N6gccjit7context15compile_to_fileE19gcc_jit_output_kindPKc}@anchor{349}@anchor{cp/topics/compilation _CPPv3N6gccjit7context15compile_to_fileE19gcc_jit_output_kindPKc}@anchor{34f}@anchor{cp/topics/compilation _CPPv2N6gccjit7context15compile_to_fileE19gcc_jit_output_kindPKc}@anchor{350}@anchor{cp/topics/compilation gccjit context compile_to_file__gcc_jit_output_kind cCP}@anchor{351} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::compile_to_file (enum gcc_jit_output_kind, const char *output_path) -Compile the @ref{12d,,gccjit;;context} to a file of the given +Compile the @ref{13d,,gccjit;;context} to a file of the given kind. This is a thin wrapper around the @ref{4a,,gcc_jit_context_compile_to_file()} API entrypoint. @end deffn +@c Copyright (C) 2020 Free Software Foundation, Inc. +@c Originally contributed by David Malcolm +@c +@c This is free software: you can redistribute it and/or modify it +@c under the terms of the GNU General Public License as published by +@c the Free Software Foundation, either version 3 of the License, or +@c (at your option) any later version. +@c +@c This program is distributed in the hope that it will be useful, but +@c WITHOUT ANY WARRANTY; without even the implied warranty of +@c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +@c General Public License for more details. +@c +@c You should have received a copy of the GNU General Public License +@c along with this program. If not, see +@c . + +@node Using Assembly Language with libgccjit++,,Compiling a context<2>,Topic Reference<2> +@anchor{cp/topics/asm doc}@anchor{352}@anchor{cp/topics/asm using-assembly-language-with-libgccjit}@anchor{353} +@subsection Using Assembly Language with libgccjit++ + + +libgccjit has some support for directly embedding assembler instructions. +This is based on GCC’s support for inline @code{asm} in C code, and the +following assumes a familiarity with that functionality. See +How to Use Inline Assembly Language in C Code@footnote{https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html} +in GCC’s documentation, the “Extended Asm” section in particular. + +These entrypoints were added in @ref{122,,LIBGCCJIT_ABI_15}; you can test +for their presence using + +@quotation + +@example +#ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS +@end example +@end quotation + +@menu +* Adding assembler instructions within a function: Adding assembler instructions within a function<2>. +* Adding top-level assembler statements: Adding top-level assembler statements<2>. + +@end menu + +@node Adding assembler instructions within a function<2>,Adding top-level assembler statements<2>,,Using Assembly Language with libgccjit++ +@anchor{cp/topics/asm adding-assembler-instructions-within-a-function}@anchor{354} +@subsubsection Adding assembler instructions within a function + + +@geindex gccjit;;extended_asm (C++ class) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asmE}@anchor{355}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asmE}@anchor{356}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asmE}@anchor{357}@anchor{cp/topics/asm gccjit extended_asm}@anchor{358} +@deffn {C++ Class} gccjit::extended_asm + +A @cite{gccjit::extended_asm} represents an extended @code{asm} statement: a +series of low-level instructions inside a function that convert inputs +to outputs. + +@ref{355,,gccjit;;extended_asm} is a subclass of @ref{142,,gccjit;;object}. +It is a thin wrapper around the C API’s @ref{f1,,gcc_jit_extended_asm *}. + +To avoid having an API entrypoint with a very large number of +parameters, an extended @code{asm} statement is made in stages: +an initial call to create the @ref{355,,gccjit;;extended_asm}, +followed by calls to add operands and set other properties of the +statement. + +There are two API entrypoints for creating a @ref{355,,gccjit;;extended_asm}: + + +@itemize * + +@item +@ref{359,,gccjit;;block;;add_extended_asm()} for an @code{asm} statement with +no control flow, and + +@item +@ref{35a,,gccjit;;block;;end_with_extended_asm_goto()} for an @code{asm goto}. +@end itemize + +For example, to create the equivalent of: + +@example + asm ("mov %1, %0\n\t" + "add $1, %0" + : "=r" (dst) + : "r" (src)); +@end example + +the following API calls could be used: + +@example + block.add_extended_asm ("mov %1, %0\n\t" + "add $1, %0") + .add_output_operand ("=r", dst) + .add_input_operand ("r", src); +@end example + +@cartouche +@quotation Warning +When considering the numbering of operands within an +extended @code{asm} statement (e.g. the @code{%0} and @code{%1} +above), the equivalent to the C syntax is followed i.e. all +output operands, then all input operands, regardless of +what order the calls to +@ref{35b,,gccjit;;extended_asm;;add_output_operand()} and +@ref{35c,,gccjit;;extended_asm;;add_input_operand()} were made in. +@end quotation +@end cartouche + +As in the C syntax, operands can be given symbolic names to avoid having +to number them. For example, to create the equivalent of: + +@example + asm ("bsfl %[aMask], %[aIndex]" + : [aIndex] "=r" (Index) + : [aMask] "r" (Mask) + : "cc"); +@end example + +the following API calls could be used: + +@example + block.add_extended_asm ("bsfl %[aMask], %[aIndex]") + .add_output_operand ("aIndex", "=r", index) + .add_input_operand ("aMask", "r", mask) + .add_clobber ("cc"); +@end example +@end deffn + +@geindex gccjit;;block;;add_extended_asm (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit5block16add_extended_asmERKNSt6stringEN6gccjit8locationE}@anchor{359}@anchor{cp/topics/asm _CPPv3N6gccjit5block16add_extended_asmERKNSt6stringEN6gccjit8locationE}@anchor{35d}@anchor{cp/topics/asm _CPPv2N6gccjit5block16add_extended_asmERKNSt6stringEN6gccjit8locationE}@anchor{35e}@anchor{cp/topics/asm gccjit block add_extended_asm__ssCR gccjit location}@anchor{35f} +@deffn {C++ Function} @ref{355,,extended_asm} gccjit::@ref{153,,block}::add_extended_asm (const std::string &asm_template, gccjit::location loc = location()) + +Create a @ref{355,,gccjit;;extended_asm} for an extended @code{asm} statement +with no control flow (i.e. without the @code{goto} qualifier). + +The parameter @code{asm_template} corresponds to the @cite{AssemblerTemplate} +within C’s extended @code{asm} syntax. It must be non-NULL. The call takes +a copy of the underlying string, so it is valid to pass in a pointer to +an on-stack buffer. +@end deffn + +@geindex gccjit;;block;;end_with_extended_asm_goto (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit5block26end_with_extended_asm_gotoERKNSt6stringENSt6vectorI5blockEEP5block8location}@anchor{35a}@anchor{cp/topics/asm _CPPv3N6gccjit5block26end_with_extended_asm_gotoERKNSt6stringENSt6vectorI5blockEEP5block8location}@anchor{360}@anchor{cp/topics/asm _CPPv2N6gccjit5block26end_with_extended_asm_gotoERKNSt6stringENSt6vectorI5blockEEP5block8location}@anchor{361}@anchor{cp/topics/asm gccjit block end_with_extended_asm_goto__ssCR std vector block blockP location}@anchor{362} +@deffn {C++ Function} @ref{355,,extended_asm} gccjit::@ref{153,,block}::end_with_extended_asm_goto (const std::string &asm_template, std::vector goto_blocks, block *fallthrough_block, location loc = location()) + +Create a @ref{355,,gccjit;;extended_asm} for an extended @code{asm} statement +that may perform jumps, and use it to terminate the given block. +This is equivalent to the @code{goto} qualifier in C’s extended @code{asm} +syntax. + +For example, to create the equivalent of: + +@example + asm goto ("btl %1, %0\n\t" + "jc %l[carry]" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); +@end example + +the following API calls could be used: + +@example + const char *asm_template = + (use_name + ? /* Label referred to by name: "%l[carry]". */ + ("btl %1, %0\n\t" + "jc %l[carry]") + : /* Label referred to numerically: "%l2". */ + ("btl %1, %0\n\t" + "jc %l2")); + + std::vector goto_blocks (@{b_carry@}); + gccjit::extended_asm ext_asm + = (b_start.end_with_extended_asm_goto (asm_template, + goto_blocks, + &b_fallthru) + .add_input_operand ("r", p1) + .add_input_operand ("r", p2) + .add_clobber ("cc")); +@end example + +here referencing a @code{gcc_jit_block} named “carry”. + +@code{num_goto_blocks} corresponds to the @code{GotoLabels} parameter within C’s +extended @code{asm} syntax. The block names can be referenced within the +assembler template. + +@code{fallthrough_block} can be NULL. If non-NULL, it specifies the block +to fall through to after the statement. + +@cartouche +@quotation Note +This is needed since each @ref{153,,gccjit;;block} must have a +single exit point, as a basic block: you can’t jump from the +middle of a block. A “goto” is implicitly added after the +asm to handle the fallthrough case, which is equivalent to what +would have happened in the C case. +@end quotation +@end cartouche +@end deffn + +@geindex gccjit;;extended_asm;;set_volatile_flag (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm17set_volatile_flagEb}@anchor{363}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm17set_volatile_flagEb}@anchor{364}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm17set_volatile_flagEb}@anchor{365}@anchor{cp/topics/asm gccjit extended_asm set_volatile_flag__b}@anchor{366} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::set_volatile_flag (bool flag) + +Set whether the @ref{355,,gccjit;;extended_asm} has side-effects, equivalent to the +volatile@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile} +qualifier in C’s extended asm syntax. + +For example, to create the equivalent of: + +@example +asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (msr) + : + : "rdx"); +@end example + +the following API calls could be used: + +@example + gccjit::extended_asm ext_asm + = block.add_extended_asm + ("rdtsc\n\t" /* Returns the time in EDX:EAX. */ + "shl $32, %%rdx\n\t" /* Shift the upper bits left. */ + "or %%rdx, %0") /* 'Or' in the lower bits. */ + .set_volatile_flag (true) + .add_output_operand ("=a", msr) + .add_clobber ("rdx"); +@end example + +where the @ref{355,,gccjit;;extended_asm} is flagged as volatile. +@end deffn + +@geindex gccjit;;extended_asm;;set_inline_flag (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm15set_inline_flagEb}@anchor{367}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm15set_inline_flagEb}@anchor{368}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm15set_inline_flagEb}@anchor{369}@anchor{cp/topics/asm gccjit extended_asm set_inline_flag__b}@anchor{36a} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::set_inline_flag (bool flag) + +Set the equivalent of the +inline@footnote{https://gcc.gnu.org/onlinedocs/gcc/Size-of-an-asm.html#Size-of-an-asm} +qualifier in C’s extended @code{asm} syntax. +@end deffn + +@geindex gccjit;;extended_asm;;add_output_operand (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm18add_output_operandERKNSt6stringERKNSt6stringEN6gccjit6lvalueE}@anchor{35b}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm18add_output_operandERKNSt6stringERKNSt6stringEN6gccjit6lvalueE}@anchor{36b}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm18add_output_operandERKNSt6stringERKNSt6stringEN6gccjit6lvalueE}@anchor{36c}@anchor{cp/topics/asm gccjit extended_asm add_output_operand__ssCR ssCR gccjit lvalue}@anchor{36d} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::add_output_operand (const std::string &asm_symbolic_name, const std::string &constraint, gccjit::lvalue dest) + +Add an output operand to the extended @code{asm} statement. See the +Output Operands@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#OutputOperands} +section of the documentation of the C syntax. + +@code{asm_symbolic_name} corresponds to the @code{asmSymbolicName} component of +C’s extended @code{asm} syntax, and specifies the symbolic name for the operand. +See the overload below for an alternative that does not supply a symbolic +name. + +@code{constraint} corresponds to the @code{constraint} component of C’s extended +@code{asm} syntax. + +@code{dest} corresponds to the @code{cvariablename} component of C’s extended +@code{asm} syntax. + +@example +// Example with a symbolic name ("aIndex"), the equivalent of: +// : [aIndex] "=r" (index) +ext_asm.add_output_operand ("aIndex", "=r", index); +@end example + +This function can’t be called on an @code{asm goto} as such instructions can’t +have outputs; see the +Goto Labels@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GotoLabels} +section of GCC’s “Extended Asm” documentation. +@end deffn + +@geindex gccjit;;extended_asm;;add_output_operand (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm18add_output_operandERKNSt6stringEN6gccjit6lvalueE}@anchor{36e}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm18add_output_operandERKNSt6stringEN6gccjit6lvalueE}@anchor{36f}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm18add_output_operandERKNSt6stringEN6gccjit6lvalueE}@anchor{370}@anchor{cp/topics/asm gccjit extended_asm add_output_operand__ssCR gccjit lvalue}@anchor{371} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::add_output_operand (const std::string &constraint, gccjit::lvalue dest) + +As above, but don’t supply a symbolic name for the operand. + +@example +// Example without a symbolic name, the equivalent of: +// : "=r" (dst) +ext_asm.add_output_operand ("=r", dst); +@end example +@end deffn + +@geindex gccjit;;extended_asm;;add_input_operand (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm17add_input_operandERKNSt6stringERKNSt6stringEN6gccjit6rvalueE}@anchor{35c}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm17add_input_operandERKNSt6stringERKNSt6stringEN6gccjit6rvalueE}@anchor{372}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm17add_input_operandERKNSt6stringERKNSt6stringEN6gccjit6rvalueE}@anchor{373}@anchor{cp/topics/asm gccjit extended_asm add_input_operand__ssCR ssCR gccjit rvalue}@anchor{374} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::add_input_operand (const std::string &asm_symbolic_name, const std::string &constraint, gccjit::rvalue src) + +Add an input operand to the extended @code{asm} statement. See the +Input Operands@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#InputOperands} +section of the documentation of the C syntax. + +@code{asm_symbolic_name} corresponds to the @code{asmSymbolicName} component +of C’s extended @code{asm} syntax. See the overload below for an alternative +that does not supply a symbolic name. + +@code{constraint} corresponds to the @code{constraint} component of C’s extended +@code{asm} syntax. + +@code{src} corresponds to the @code{cexpression} component of C’s extended +@code{asm} syntax. + +@example +// Example with a symbolic name ("aMask"), the equivalent of: +// : [aMask] "r" (Mask) +ext_asm.add_input_operand ("aMask", "r", mask); +@end example +@end deffn + +@geindex gccjit;;extended_asm;;add_input_operand (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm17add_input_operandERKNSt6stringEN6gccjit6rvalueE}@anchor{375}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm17add_input_operandERKNSt6stringEN6gccjit6rvalueE}@anchor{376}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm17add_input_operandERKNSt6stringEN6gccjit6rvalueE}@anchor{377}@anchor{cp/topics/asm gccjit extended_asm add_input_operand__ssCR gccjit rvalue}@anchor{378} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::add_input_operand (const std::string &constraint, gccjit::rvalue src) + +As above, but don’t supply a symbolic name for the operand. + +@example +// Example without a symbolic name, the equivalent of: +// : "r" (src) +ext_asm.add_input_operand ("r", src); +@end example +@end deffn + +@geindex gccjit;;extended_asm;;add_clobber (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit12extended_asm11add_clobberERKNSt6stringE}@anchor{379}@anchor{cp/topics/asm _CPPv3N6gccjit12extended_asm11add_clobberERKNSt6stringE}@anchor{37a}@anchor{cp/topics/asm _CPPv2N6gccjit12extended_asm11add_clobberERKNSt6stringE}@anchor{37b}@anchor{cp/topics/asm gccjit extended_asm add_clobber__ssCR}@anchor{37c} +@deffn {C++ Function} gccjit::@ref{355,,extended_asm} &gccjit::@ref{355,,extended_asm}::add_clobber (const std::string &victim) + +Add @cite{victim} to the list of registers clobbered by the extended @code{asm} +statement. See the +Clobbers and Scratch Registers@footnote{https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers#} +section of the documentation of the C syntax. + +Statements with multiple clobbers will require multiple calls, one per +clobber. + +For example: + +@example +ext_asm.add_clobber ("r0").add_clobber ("cc").add_clobber ("memory"); +@end example +@end deffn + +@node Adding top-level assembler statements<2>,,Adding assembler instructions within a function<2>,Using Assembly Language with libgccjit++ +@anchor{cp/topics/asm adding-top-level-assembler-statements}@anchor{37d} +@subsubsection Adding top-level assembler statements + + +In addition to creating extended @code{asm} instructions within a function, +there is support for creating “top-level” assembler statements, outside +of any function. + +@geindex gccjit;;context;;add_top_level_asm (C++ function) +@anchor{cp/topics/asm _CPPv4N6gccjit7context17add_top_level_asmEPKcN6gccjit8locationE}@anchor{37e}@anchor{cp/topics/asm _CPPv3N6gccjit7context17add_top_level_asmEPKcN6gccjit8locationE}@anchor{37f}@anchor{cp/topics/asm _CPPv2N6gccjit7context17add_top_level_asmEPKcN6gccjit8locationE}@anchor{380}@anchor{cp/topics/asm gccjit context add_top_level_asm__cCP gccjit location}@anchor{381} +@deffn {C++ Function} void gccjit::@ref{13d,,context}::add_top_level_asm (const char *asm_stmts, gccjit::location loc = location()) + +Create a set of top-level asm statements, analogous to those created +by GCC’s “basic” @code{asm} syntax in C at file scope. + +For example, to create the equivalent of: + +@example + asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @@function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t.popsection\n"); +@end example + +the following API calls could be used: + +@example + ctxt.add_top_level_asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @@function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t# some asm here\n" + "\t.popsection\n"); +@end example +@end deffn + @c Copyright (C) 2014-2020 Free Software Foundation, Inc. @c Originally contributed by David Malcolm @c @@ -13779,7 +14614,7 @@ This is a thin wrapper around the @c . @node Internals,Indices and tables,C++ bindings for libgccjit,Top -@anchor{internals/index internals}@anchor{25e}@anchor{internals/index doc}@anchor{25f} +@anchor{internals/index doc}@anchor{382}@anchor{internals/index internals}@anchor{383} @chapter Internals @@ -13795,7 +14630,7 @@ This is a thin wrapper around the @end menu @node Working on the JIT library,Running the test suite,,Internals -@anchor{internals/index working-on-the-jit-library}@anchor{260} +@anchor{internals/index working-on-the-jit-library}@anchor{384} @section Working on the JIT library @@ -13828,7 +14663,7 @@ gcc/libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), Here’s what those configuration options mean: @geindex command line option; --enable-host-shared -@anchor{internals/index cmdoption-enable-host-shared}@anchor{261} +@anchor{internals/index cmdoption-enable-host-shared}@anchor{385} @deffn {Option} @w{-}@w{-}enable@w{-}host@w{-}shared Configuring with this option means that the compiler is built as @@ -13837,7 +14672,7 @@ but it necessary for a shared library. @end deffn @geindex command line option; --enable-languages=jit@comma{}c++ -@anchor{internals/index cmdoption-enable-languages}@anchor{262} +@anchor{internals/index cmdoption-enable-languages}@anchor{386} @deffn {Option} @w{-}@w{-}enable@w{-}languages=jit,c++ This specifies which frontends to build. The JIT library looks like @@ -13854,7 +14689,7 @@ c++: error trying to exec 'cc1plus': execvp: No such file or directory @end deffn @geindex command line option; --disable-bootstrap -@anchor{internals/index cmdoption-disable-bootstrap}@anchor{263} +@anchor{internals/index cmdoption-disable-bootstrap}@anchor{387} @deffn {Option} @w{-}@w{-}disable@w{-}bootstrap For hacking on the “jit” subdirectory, performing a full @@ -13864,7 +14699,7 @@ the compiler can still bootstrap itself. @end deffn @geindex command line option; --enable-checking=release -@anchor{internals/index cmdoption-enable-checking}@anchor{264} +@anchor{internals/index cmdoption-enable-checking}@anchor{388} @deffn {Option} @w{-}@w{-}enable@w{-}checking=release The compile can perform extensive self-checking as it runs, useful when @@ -13875,7 +14710,7 @@ disable this self-checking. @end deffn @node Running the test suite,Environment variables,Working on the JIT library,Internals -@anchor{internals/index running-the-test-suite}@anchor{265} +@anchor{internals/index running-the-test-suite}@anchor{389} @section Running the test suite @@ -13933,7 +14768,7 @@ and once a test has been compiled, you can debug it directly: @end menu @node Running under valgrind,,,Running the test suite -@anchor{internals/index running-under-valgrind}@anchor{266} +@anchor{internals/index running-under-valgrind}@anchor{38a} @subsection Running under valgrind @@ -13982,7 +14817,7 @@ When running under valgrind, it’s best to have configured gcc with various known false positives. @node Environment variables,Packaging notes,Running the test suite,Internals -@anchor{internals/index environment-variables}@anchor{267} +@anchor{internals/index environment-variables}@anchor{38b} @section Environment variables @@ -13990,7 +14825,7 @@ When running client code against a locally-built libgccjit, three environment variables need to be set up: @geindex environment variable; LD_LIBRARY_PATH -@anchor{internals/index envvar-LD_LIBRARY_PATH}@anchor{268} +@anchor{internals/index envvar-LD_LIBRARY_PATH}@anchor{38c} @deffn {Environment Variable} LD_LIBRARY_PATH @quotation @@ -14010,7 +14845,7 @@ libgccjit.so.0.0.1: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), @end deffn @geindex environment variable; PATH -@anchor{internals/index envvar-PATH}@anchor{269} +@anchor{internals/index envvar-PATH}@anchor{38d} @deffn {Environment Variable} PATH The library uses a driver executable for converting from .s assembler @@ -14029,7 +14864,7 @@ of development. @end deffn @geindex environment variable; LIBRARY_PATH -@anchor{internals/index envvar-LIBRARY_PATH}@anchor{26a} +@anchor{internals/index envvar-LIBRARY_PATH}@anchor{38e} @deffn {Environment Variable} LIBRARY_PATH The driver executable invokes the linker, and the latter needs to locate @@ -14061,11 +14896,11 @@ hello world @end example @node Packaging notes,Overview of code structure,Environment variables,Internals -@anchor{internals/index packaging-notes}@anchor{26b} +@anchor{internals/index packaging-notes}@anchor{38f} @section Packaging notes -The configure-time option @ref{261,,--enable-host-shared} is needed when +The configure-time option @ref{385,,--enable-host-shared} is needed when building the jit in order to get position-independent code. This will slow down the regular compiler by a few percent. Hence when packaging gcc with libgccjit, please configure and build twice: @@ -14076,10 +14911,10 @@ with libgccjit, please configure and build twice: @itemize * @item -once without @ref{261,,--enable-host-shared} for most languages, and +once without @ref{385,,--enable-host-shared} for most languages, and @item -once with @ref{261,,--enable-host-shared} for the jit +once with @ref{385,,--enable-host-shared} for the jit @end itemize @end quotation @@ -14121,7 +14956,7 @@ popd @end example @node Overview of code structure,Design notes,Packaging notes,Internals -@anchor{internals/index overview-of-code-structure}@anchor{26c} +@anchor{internals/index overview-of-code-structure}@anchor{390} @section Overview of code structure @@ -14168,7 +15003,9 @@ The gcc::jit::recording classes (within @code{jit-recording.c} and class base_call; class function_pointer; class statement; + class extended_asm; class case_; + class top_level_asm; @end example @end quotation @@ -14588,7 +15425,7 @@ JIT: gcc::jit::logger::~logger() @end example @node Design notes,Submitting patches,Overview of code structure,Internals -@anchor{internals/index design-notes}@anchor{26d} +@anchor{internals/index design-notes}@anchor{391} @section Design notes @@ -14601,7 +15438,7 @@ close as possible to the error; failing that, a good place is within @code{recording::context::validate ()} in jit-recording.c. @node Submitting patches,,Design notes,Internals -@anchor{internals/index submitting-patches}@anchor{26e} +@anchor{internals/index submitting-patches}@anchor{392} @section Submitting patches @@ -14735,7 +15572,7 @@ large and inconsequential (e.g. anchor renumbering), rather like generated committing to svn. @node Indices and tables,Index,Internals,Top -@anchor{index indices-and-tables}@anchor{26f} +@anchor{index indices-and-tables}@anchor{393} @unnumbered Indices and tables diff --git a/gcc/jit/docs/cp/topics/asm.rst b/gcc/jit/docs/cp/topics/asm.rst new file mode 100644 index 00000000000..69e2d1e8da7 --- /dev/null +++ b/gcc/jit/docs/cp/topics/asm.rst @@ -0,0 +1,308 @@ +.. Copyright (C) 2020 Free Software Foundation, Inc. + Originally contributed by David Malcolm + + 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 + . + +.. default-domain:: cpp + +Using Assembly Language with libgccjit++ +======================================== + +libgccjit has some support for directly embedding assembler instructions. +This is based on GCC's support for inline ``asm`` in C code, and the +following assumes a familiarity with that functionality. See +`How to Use Inline Assembly Language in C Code `_ +in GCC's documentation, the "Extended Asm" section in particular. + +These entrypoints were added in :ref:`LIBGCCJIT_ABI_15`; you can test +for their presence using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS + +Adding assembler instructions within a function +*********************************************** + +.. class:: gccjit::extended_asm + + A `gccjit::extended_asm` represents an extended ``asm`` statement: a + series of low-level instructions inside a function that convert inputs + to outputs. + + :class:`gccjit::extended_asm` is a subclass of :class:`gccjit::object`. + It is a thin wrapper around the C API's :c:type:`gcc_jit_extended_asm *`. + + To avoid having an API entrypoint with a very large number of + parameters, an extended ``asm`` statement is made in stages: + an initial call to create the :type:`gccjit::extended_asm`, + followed by calls to add operands and set other properties of the + statement. + + There are two API entrypoints for creating a :type:`gccjit::extended_asm`: + + * :func:`gccjit::block::add_extended_asm` for an ``asm`` statement with + no control flow, and + + * :func:`gccjit::block::end_with_extended_asm_goto` for an ``asm goto``. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: // Quote from here in docs/cp/topics/asm.rst: example 1: C + :end-before: // Quote up to here in docs/cp/topics/asm.rst: example 1: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: /* Quote from here in docs/cp/topics/asm.rst: example 1: jit. */ + :end-before: /* Quote up to here in docs/cp/topics/asm.rst: example 1: jit. */ + :language: c + + .. warning:: When considering the numbering of operands within an + extended ``asm`` statement (e.g. the ``%0`` and ``%1`` + above), the equivalent to the C syntax is followed i.e. all + output operands, then all input operands, regardless of + what order the calls to + :func:`gccjit::extended_asm::add_output_operand` and + :func:`gccjit::extended_asm::add_input_operand` were made in. + + As in the C syntax, operands can be given symbolic names to avoid having + to number them. For example, to create the equivalent of: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: // Quote from here in docs/cp/topics/asm.rst: example 2: C + :end-before: // Quote up to here in docs/cp/topics/asm.rst: example 2: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: /* Quote from here in docs/cp/topics/asm.rst: example 2: jit. */ + :end-before: /* Quote up to here in docs/cp/topics/asm.rst: example 2: jit. */ + :language: c + +.. function:: extended_asm \ + gccjit::block::add_extended_asm (const std::string &asm_template,\ + gccjit::location loc = location ()) + + Create a :type:`gccjit::extended_asm` for an extended ``asm`` statement + with no control flow (i.e. without the ``goto`` qualifier). + + The parameter ``asm_template`` corresponds to the `AssemblerTemplate` + within C's extended ``asm`` syntax. It must be non-NULL. The call takes + a copy of the underlying string, so it is valid to pass in a pointer to + an on-stack buffer. + +.. function:: extended_asm\ + gccjit::block::end_with_extended_asm_goto (const std::string &asm_template,\ + std::vector goto_blocks,\ + block *fallthrough_block,\ + location loc = location ()) + + Create a :type:`gccjit::extended_asm` for an extended ``asm`` statement + that may perform jumps, and use it to terminate the given block. + This is equivalent to the ``goto`` qualifier in C's extended ``asm`` + syntax. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: // Quote from here in docs/cp/topics/asm.rst: example 3b: C + :end-before: // Quote up to here in docs/cp/topics/asm.rst: example 3b: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: /* Quote from here in docs/cp/topics/asm.rst: example 3: jit. */ + :end-before: /* Quote up to here in docs/cp/topics/asm.rst: example 3: jit. */ + :language: c + + here referencing a :type:`gcc_jit_block` named "carry". + + ``num_goto_blocks`` corresponds to the ``GotoLabels`` parameter within C's + extended ``asm`` syntax. The block names can be referenced within the + assembler template. + + ``fallthrough_block`` can be NULL. If non-NULL, it specifies the block + to fall through to after the statement. + + .. note:: This is needed since each :type:`gccjit::block` must have a + single exit point, as a basic block: you can't jump from the + middle of a block. A "goto" is implicitly added after the + asm to handle the fallthrough case, which is equivalent to what + would have happened in the C case. + +.. function:: gccjit::extended_asm &\ + gccjit::extended_asm::set_volatile_flag (bool flag) + + Set whether the :type:`gccjit::extended_asm` has side-effects, equivalent to the + `volatile `_ + qualifier in C's extended asm syntax. + + For example, to create the equivalent of: + + .. code-block:: c + + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (msr) + : + : "rdx"); + + the following API calls could be used: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: /* Quote from here in docs/cp/topics/asm.rst: example 4: jit. */ + :end-before: /* Quote up to here in docs/cp/topics/asm.rst: example 4: jit. */ + :language: c + + where the :type:`gccjit::extended_asm` is flagged as volatile. + +.. function:: gccjit::extended_asm &\ + gccjit::extended_asm::set_inline_flag (bool flag) + + Set the equivalent of the + `inline `_ + qualifier in C's extended ``asm`` syntax. + +.. function:: gccjit::extended_asm&\ + gccjit::extended_asm::add_output_operand (const std::string &asm_symbolic_name,\ + const std::string &constraint,\ + gccjit::lvalue dest) + + Add an output operand to the extended ``asm`` statement. See the + `Output Operands `_ + section of the documentation of the C syntax. + + ``asm_symbolic_name`` corresponds to the ``asmSymbolicName`` component of + C's extended ``asm`` syntax, and specifies the symbolic name for the operand. + See the overload below for an alternative that does not supply a symbolic + name. + + ``constraint`` corresponds to the ``constraint`` component of C's extended + ``asm`` syntax. + + ``dest`` corresponds to the ``cvariablename`` component of C's extended + ``asm`` syntax. + + .. code-block:: c++ + + // Example with a symbolic name ("aIndex"), the equivalent of: + // : [aIndex] "=r" (index) + ext_asm.add_output_operand ("aIndex", "=r", index); + + This function can't be called on an ``asm goto`` as such instructions can't + have outputs; see the + `Goto Labels `_ + section of GCC's "Extended Asm" documentation. + +.. function:: gccjit::extended_asm&\ + gccjit::extended_asm::add_output_operand (const std::string &constraint,\ + gccjit::lvalue dest) + + As above, but don't supply a symbolic name for the operand. + + .. code-block:: c++ + + // Example without a symbolic name, the equivalent of: + // : "=r" (dst) + ext_asm.add_output_operand ("=r", dst); + +.. function:: gccjit::extended_asm&\ + gccjit::extended_asm::add_input_operand (const std::string &asm_symbolic_name, \ + const std::string &constraint, \ + gccjit::rvalue src) + + Add an input operand to the extended ``asm`` statement. See the + `Input Operands `_ + section of the documentation of the C syntax. + + ``asm_symbolic_name`` corresponds to the ``asmSymbolicName`` component + of C's extended ``asm`` syntax. See the overload below for an alternative + that does not supply a symbolic name. + + ``constraint`` corresponds to the ``constraint`` component of C's extended + ``asm`` syntax. + + ``src`` corresponds to the ``cexpression`` component of C's extended + ``asm`` syntax. + + .. code-block:: c++ + + // Example with a symbolic name ("aMask"), the equivalent of: + // : [aMask] "r" (Mask) + ext_asm.add_input_operand ("aMask", "r", mask); + +.. function:: gccjit::extended_asm&\ + gccjit::extended_asm::add_input_operand (const std::string &constraint,\ + gccjit::rvalue src) + + As above, but don't supply a symbolic name for the operand. + + .. code-block:: c++ + + // Example without a symbolic name, the equivalent of: + // : "r" (src) + ext_asm.add_input_operand ("r", src); + +.. function:: gccjit::extended_asm&\ + gccjit::extended_asm::add_clobber (const std::string &victim) + + Add `victim` to the list of registers clobbered by the extended ``asm`` + statement. See the + `Clobbers and Scratch Registers `_ + section of the documentation of the C syntax. + + Statements with multiple clobbers will require multiple calls, one per + clobber. + + For example: + + .. code-block:: c++ + + ext_asm.add_clobber ("r0").add_clobber ("cc").add_clobber ("memory"); + + +Adding top-level assembler statements +************************************* + +In addition to creating extended ``asm`` instructions within a function, +there is support for creating "top-level" assembler statements, outside +of any function. + +.. function:: void\ + gccjit::context::add_top_level_asm (const char *asm_stmts,\ + gccjit::location loc = location ()) + + Create a set of top-level asm statements, analogous to those created + by GCC's "basic" ``asm`` syntax in C at file scope. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: // Quote from here in docs/cp/topics/asm.rst: example 5: C + :end-before: // Quote up to here in docs/cp/topics/asm.rst: example 5: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../../testsuite/jit.dg/test-asm.cc + :start-after: /* Quote from here in docs/cp/topics/asm.rst: example 5: jit. */ + :end-before: /* Quote up to here in docs/cp/topics/asm.rst: example 5: jit. */ + :language: c diff --git a/gcc/jit/docs/cp/topics/index.rst b/gcc/jit/docs/cp/topics/index.rst index 187a20d03b3..721e70cfa1b 100644 --- a/gcc/jit/docs/cp/topics/index.rst +++ b/gcc/jit/docs/cp/topics/index.rst @@ -28,3 +28,4 @@ Topic Reference functions.rst locations.rst compilation.rst + asm.rst diff --git a/gcc/jit/docs/topics/asm.rst b/gcc/jit/docs/topics/asm.rst new file mode 100644 index 00000000000..b91514d4140 --- /dev/null +++ b/gcc/jit/docs/topics/asm.rst @@ -0,0 +1,311 @@ +.. Copyright (C) 2020 Free Software Foundation, Inc. + Originally contributed by David Malcolm + + 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 + . + +.. default-domain:: c + +Using Assembly Language with libgccjit +====================================== + +libgccjit has some support for directly embedding assembler instructions. +This is based on GCC's support for inline ``asm`` in C code, and the +following assumes a familiarity with that functionality. See +`How to Use Inline Assembly Language in C Code `_ +in GCC's documentation, the "Extended Asm" section in particular. + +These entrypoints were added in :ref:`LIBGCCJIT_ABI_15`; you can test +for their presence using + + .. code-block:: c + + #ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS + +Adding assembler instructions within a function +*********************************************** + +.. type:: gcc_jit_extended_asm + + A `gcc_jit_extended_asm` represents an extended ``asm`` statement: a + series of low-level instructions inside a function that convert inputs + to outputs. + + To avoid having an API entrypoint with a very large number of + parameters, an extended ``asm`` statement is made in stages: + an initial call to create the :type:`gcc_jit_extended_asm`, + followed by calls to add operands and set other properties of the + statement. + + There are two API entrypoints for creating a :type:`gcc_jit_extended_asm`: + + * :func:`gcc_jit_block_add_extended_asm` for an ``asm`` statement with + no control flow, and + + * :func:`gcc_jit_block_end_with_extended_asm_goto` for an ``asm goto``. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: // Quote from here in docs/topics/asm.rst: example 1: C + :end-before: // Quote up to here in docs/topics/asm.rst: example 1: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: /* Quote from here in docs/topics/asm.rst: example 1: jit. */ + :end-before: /* Quote up to here in docs/topics/asm.rst: example 1: jit. */ + :language: c + + .. warning:: When considering the numbering of operands within an + extended ``asm`` statement (e.g. the ``%0`` and ``%1`` + above), the equivalent to the C syntax is followed i.e. all + output operands, then all input operands, regardless of + what order the calls to + :func:`gcc_jit_extended_asm_add_output_operand` and + :func:`gcc_jit_extended_asm_add_input_operand` were made in. + + As in the C syntax, operands can be given symbolic names to avoid having + to number them. For example, to create the equivalent of: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: // Quote from here in docs/topics/asm.rst: example 2: C + :end-before: // Quote up to here in docs/topics/asm.rst: example 2: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: /* Quote from here in docs/topics/asm.rst: example 2: jit. */ + :end-before: /* Quote up to here in docs/topics/asm.rst: example 2: jit. */ + :language: c + +.. function:: gcc_jit_extended_asm *\ + gcc_jit_block_add_extended_asm (gcc_jit_block *block,\ + gcc_jit_location *loc,\ + const char *asm_template) + + Create a :type:`gcc_jit_extended_asm` for an extended ``asm`` statement + with no control flow (i.e. without the ``goto`` qualifier). + + The parameter ``asm_template`` corresponds to the `AssemblerTemplate` + within C's extended ``asm`` syntax. It must be non-NULL. The call takes + a copy of the underlying string, so it is valid to pass in a pointer to + an on-stack buffer. + +.. function:: gcc_jit_extended_asm *\ + gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block *block,\ + gcc_jit_location *loc,\ + const char *asm_template,\ + int num_goto_blocks,\ + gcc_jit_block **goto_blocks,\ + gcc_jit_block *fallthrough_block) + + Create a :type:`gcc_jit_extended_asm` for an extended ``asm`` statement + that may perform jumps, and use it to terminate the given block. + This is equivalent to the ``goto`` qualifier in C's extended ``asm`` + syntax. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: // Quote from here in docs/topics/asm.rst: example 3b: C + :end-before: // Quote up to here in docs/topics/asm.rst: example 3b: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: /* Quote from here in docs/topics/asm.rst: example 3: jit. */ + :end-before: /* Quote up to here in docs/topics/asm.rst: example 3: jit. */ + :language: c + + here referencing a :type:`gcc_jit_block` named "carry". + + ``num_goto_blocks`` must be >= 0. + + ``goto_blocks`` must be non-NULL. This corresponds to the ``GotoLabels`` + parameter within C's extended ``asm`` syntax. The block names can be + referenced within the assembler template. + + ``fallthrough_block`` can be NULL. If non-NULL, it specifies the block + to fall through to after the statement. + + .. note:: This is needed since each :type:`gcc_jit_block` must have a + single exit point, as a basic block: you can't jump from the + middle of a block. A "goto" is implicitly added after the + asm to handle the fallthrough case, which is equivalent to what + would have happened in the C case. + +.. function:: void\ + gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm *ext_asm,\ + int flag) + + Set whether the :type:`gcc_jit_extended_asm` has side-effects, equivalent to the + `volatile `_ + qualifier in C's extended asm syntax. + + For example, to create the equivalent of: + + .. code-block:: c + + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (msr) + : + : "rdx"); + + the following API calls could be used: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: /* Quote from here in docs/topics/asm.rst: example 4: jit. */ + :end-before: /* Quote up to here in docs/topics/asm.rst: example 4: jit. */ + :language: c + + where the :type:`gcc_jit_extended_asm` is flagged as volatile. + +.. function:: void\ + gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm *ext_asm,\ + int flag) + + Set the equivalent of the + `inline `_ + qualifier in C's extended ``asm`` syntax. + +.. function:: void\ + gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm *ext_asm,\ + const char *asm_symbolic_name,\ + const char *constraint,\ + gcc_jit_lvalue *dest) + + Add an output operand to the extended ``asm`` statement. See the + `Output Operands `_ + section of the documentation of the C syntax. + + ``asm_symbolic_name`` corresponds to the ``asmSymbolicName`` component of C's + extended ``asm`` syntax. It can be NULL. If non-NULL it specifies the + symbolic name for the operand. + + ``constraint`` corresponds to the ``constraint`` component of C's extended + ``asm`` syntax. It must be non-NULL. + + ``dest`` corresponds to the ``cvariablename`` component of C's extended + ``asm`` syntax. It must be non-NULL. + + .. code-block:: c + + // Example with a NULL symbolic name, the equivalent of: + // : "=r" (dst) + gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=r", dst); + + // Example with a symbolic name ("aIndex"), the equivalent of: + // : [aIndex] "=r" (index) + gcc_jit_extended_asm_add_output_operand (ext_asm, "aIndex", "=r", index); + + This function can't be called on an ``asm goto`` as such instructions can't + have outputs; see the + `Goto Labels `_ + section of GCC's "Extended Asm" documentation. + +.. function:: void\ + gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm *ext_asm,\ + const char *asm_symbolic_name,\ + const char *constraint,\ + gcc_jit_rvalue *src) + + Add an input operand to the extended ``asm`` statement. See the + `Input Operands `_ + section of the documentation of the C syntax. + + ``asm_symbolic_name`` corresponds to the ``asmSymbolicName`` component of C's + extended ``asm`` syntax. It can be NULL. If non-NULL it specifies the + symbolic name for the operand. + + ``constraint`` corresponds to the ``constraint`` component of C's extended + ``asm`` syntax. It must be non-NULL. + + ``src`` corresponds to the ``cexpression`` component of C's extended + ``asm`` syntax. It must be non-NULL. + + .. code-block:: c + + // Example with a NULL symbolic name, the equivalent of: + // : "r" (src) + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_lvalue_as_rvalue (src)); + + // Example with a symbolic name ("aMask"), the equivalent of: + // : [aMask] "r" (Mask) + gcc_jit_extended_asm_add_input_operand (ext_asm, "aMask", "r", + gcc_jit_lvalue_as_rvalue (mask)); + +.. function:: void\ + gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm *ext_asm,\ + const char *victim) + + Add `victim` to the list of registers clobbered by the extended ``asm`` + statement. It must be non-NULL. See the + `Clobbers and Scratch Registers `_ + section of the documentation of the C syntax. + + Statements with multiple clobbers will require multiple calls, one per + clobber. + + For example: + + .. code-block:: c + + gcc_jit_extended_asm_add_clobber (ext_asm, "r0"); + gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); + gcc_jit_extended_asm_add_clobber (ext_asm, "memory"); + +A :type:`gcc_jit_extended_asm` is a :type:`gcc_jit_object` "owned" by +the block's context. The following upcast is available: + +.. function:: gcc_jit_object *\ + gcc_jit_extended_asm_as_object (gcc_jit_extended_asm *ext_asm) + + Upcast from extended ``asm`` to object. + + +Adding top-level assembler statements +************************************* + +In addition to creating extended ``asm`` instructions within a function, +there is support for creating "top-level" assembler statements, outside +of any function. + +.. function:: void \ + gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt,\ + gcc_jit_location *loc,\ + const char *asm_stmts) + + Create a set of top-level asm statements, analogous to those created + by GCC's "basic" ``asm`` syntax in C at file scope. + + For example, to create the equivalent of: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: // Quote from here in docs/topics/asm.rst: example 5: C + :end-before: // Quote up to here in docs/topics/asm.rst: example 5: C + :language: c + + the following API calls could be used: + + .. literalinclude:: ../../../testsuite/jit.dg/test-asm.c + :start-after: /* Quote from here in docs/topics/asm.rst: example 5: jit. */ + :end-before: /* Quote up to here in docs/topics/asm.rst: example 5: jit. */ + :language: c diff --git a/gcc/jit/docs/topics/compatibility.rst b/gcc/jit/docs/topics/compatibility.rst index 6bfa101ed71..b953da590f1 100644 --- a/gcc/jit/docs/topics/compatibility.rst +++ b/gcc/jit/docs/topics/compatibility.rst @@ -226,3 +226,20 @@ entrypoints: -------------------- ``LIBGCCJIT_ABI_14`` covers the addition of :func:`gcc_jit_global_set_initializer` + +.. _LIBGCCJIT_ABI_15: + +``LIBGCCJIT_ABI_15`` +----------------------- +``LIBGCCJIT_ABI_15`` covers the addition of API entrypoints for directly +embedding assembler instructions: + + * :func:`gcc_jit_block_add_extended_asm` + * :func:`gcc_jit_block_end_with_extended_asm_goto` + * :func:`gcc_jit_extended_asm_as_object` + * :func:`gcc_jit_extended_asm_set_volatile_flag` + * :func:`gcc_jit_extended_asm_set_inline_flag` + * :func:`gcc_jit_extended_asm_add_output_operand` + * :func:`gcc_jit_extended_asm_add_input_operand` + * :func:`gcc_jit_extended_asm_add_clobber` + * :func:`gcc_jit_context_add_top_level_asm` diff --git a/gcc/jit/docs/topics/functions.rst b/gcc/jit/docs/topics/functions.rst index eb40d64010e..b869256a1cd 100644 --- a/gcc/jit/docs/topics/functions.rst +++ b/gcc/jit/docs/topics/functions.rst @@ -458,3 +458,6 @@ Statements :start-after: /* Quote from here in docs/topics/functions.rst. */ :end-before: /* Quote up to here in docs/topics/functions.rst. */ :language: c + +See also :type:`gcc_jit_extended_asm` for entrypoints for adding inline +assembler statements to a function. diff --git a/gcc/jit/docs/topics/index.rst b/gcc/jit/docs/topics/index.rst index 8352ca25818..d7cb86aa0d8 100644 --- a/gcc/jit/docs/topics/index.rst +++ b/gcc/jit/docs/topics/index.rst @@ -31,3 +31,4 @@ Topic Reference compilation.rst compatibility.rst performance.rst + asm.rst diff --git a/gcc/jit/docs/topics/objects.rst b/gcc/jit/docs/topics/objects.rst index 12d3c9f7987..cdee2c0af6a 100644 --- a/gcc/jit/docs/topics/objects.rst +++ b/gcc/jit/docs/topics/objects.rst @@ -48,6 +48,7 @@ looks like this:: +- gcc_jit_lvalue +- gcc_jit_param +- gcc_jit_case + +- gcc_jit_extended_asm There are casting methods for upcasting from subclasses to parent classes. For example, :c:func:`gcc_jit_type_as_object`: diff --git a/gcc/jit/jit-common.h b/gcc/jit/jit-common.h index 4570bd2d717..b8c3685c073 100644 --- a/gcc/jit/jit-common.h +++ b/gcc/jit/jit-common.h @@ -131,7 +131,9 @@ namespace recording { class base_call; class function_pointer; class statement; + class extended_asm; class case_; + class top_level_asm; /* End of recording types. */ } diff --git a/gcc/jit/jit-playback.c b/gcc/jit/jit-playback.c index 4fac64dcab7..5bccf591a3f 100644 --- a/gcc/jit/jit-playback.c +++ b/gcc/jit/jit-playback.c @@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "opt-suggestions.h" #include "gcc.h" #include "diagnostic.h" +#include "stmt.h" #include @@ -86,6 +87,18 @@ namespace jit { Playback. **********************************************************************/ +/* Build a STRING_CST tree for STR, or return NULL if it is NULL. + The TREE_TYPE is not initialized. */ + +static tree +build_string (const char *str) +{ + if (str) + return ::build_string (strlen (str), str); + else + return NULL_TREE; +} + /* The constructor for gcc::jit::playback::context. */ playback::context::context (recording::context *ctxt) @@ -774,7 +787,7 @@ new_string_literal (const char *value) tree a_type = build_array_type (char_type_node, i_type); /* build_string len parameter must include NUL terminator when building C strings. */ - tree t_str = build_string (len + 1, value); + tree t_str = ::build_string (len + 1, value); TREE_TYPE (t_str) = a_type; /* Convert to (const char*), loosely based on @@ -821,6 +834,18 @@ as_truth_value (tree expr, location *loc) return expr; } +/* Add a "top-level" basic asm statement (i.e. one outside of any functions) + containing ASM_STMTS. + + Compare with c_parser_asm_definition. */ + +void +playback::context::add_top_level_asm (const char *asm_stmts) +{ + tree asm_str = build_string (asm_stmts); + symtab->finalize_toplevel_asm (asm_str); +} + /* Construct a playback::rvalue instance (wrapping a tree) for a unary op. */ @@ -1897,6 +1922,104 @@ add_switch (location *loc, add_stmt (switch_stmt); } +/* Convert OPERANDS to a tree-based chain suitable for creating an + extended asm stmt. + Compare with c_parser_asm_operands. */ + +static tree +build_operand_chain (const auto_vec *operands) +{ + tree result = NULL_TREE; + unsigned i; + playback::asm_operand *asm_op; + FOR_EACH_VEC_ELT (*operands, i, asm_op) + { + tree name = build_string (asm_op->m_asm_symbolic_name); + tree str = build_string (asm_op->m_constraint); + tree value = asm_op->m_expr; + result = chainon (result, + build_tree_list (build_tree_list (name, str), + value)); + } + return result; +} + +/* Convert CLOBBERS to a tree-based list suitable for creating an + extended asm stmt. + Compare with c_parser_asm_clobbers. */ + +static tree +build_clobbers (const auto_vec *clobbers) +{ + tree list = NULL_TREE; + unsigned i; + const char *clobber; + FOR_EACH_VEC_ELT (*clobbers, i, clobber) + { + tree str = build_string (clobber); + list = tree_cons (NULL_TREE, str, list); + } + return list; +} + +/* Convert BLOCKS to a tree-based list suitable for creating an + extended asm stmt. + Compare with c_parser_asm_goto_operands. */ + +static tree +build_goto_operands (const auto_vec *blocks) +{ + tree list = NULL_TREE; + unsigned i; + playback::block *b; + FOR_EACH_VEC_ELT (*blocks, i, b) + { + tree label = b->as_label_decl (); + tree name = build_string (IDENTIFIER_POINTER (DECL_NAME (label))); + TREE_USED (label) = 1; + list = tree_cons (name, label, list); + } + return nreverse (list); +} + +/* Add an extended asm statement to this block. + + Compare with c_parser_asm_statement (in c/c-parser.c) + and build_asm_expr (in c/c-typeck.c). */ + +void +playback::block::add_extended_asm (location *loc, + const char *asm_template, + bool is_volatile, + bool is_inline, + const auto_vec *outputs, + const auto_vec *inputs, + const auto_vec *clobbers, + const auto_vec *goto_blocks) +{ + tree t_string = build_string (asm_template); + tree t_outputs = build_operand_chain (outputs); + tree t_inputs = build_operand_chain (inputs); + tree t_clobbers = build_clobbers (clobbers); + tree t_labels = build_goto_operands (goto_blocks); + t_string + = resolve_asm_operand_names (t_string, t_outputs, t_inputs, t_labels); + tree asm_stmt + = build5 (ASM_EXPR, void_type_node, + t_string, t_outputs, t_inputs, t_clobbers, t_labels); + + /* asm statements without outputs, including simple ones, are treated + as volatile. */ + ASM_VOLATILE_P (asm_stmt) = (outputs->length () == 0); + ASM_INPUT_P (asm_stmt) = 0; /* extended asm stmts are not "simple". */ + ASM_INLINE_P (asm_stmt) = is_inline; + if (is_volatile) + ASM_VOLATILE_P (asm_stmt) = 1; + if (loc) + set_tree_location (asm_stmt, loc); + add_stmt (asm_stmt); +} + /* Constructor for gcc::jit::playback::block. */ playback::block:: diff --git a/gcc/jit/jit-playback.h b/gcc/jit/jit-playback.h index 50b69753bb4..ff1f778d026 100644 --- a/gcc/jit/jit-playback.h +++ b/gcc/jit/jit-playback.h @@ -252,6 +252,8 @@ public: timer *get_timer () const { return m_recording_ctxt->get_timer (); } + void add_top_level_asm (const char *asm_stmts); + private: void dump_generated_code (); @@ -514,6 +516,21 @@ struct case_ block *m_dest_block; }; +struct asm_operand +{ + asm_operand (const char *asm_symbolic_name, + const char *constraint, + tree expr) + : m_asm_symbolic_name (asm_symbolic_name), + m_constraint (constraint), + m_expr (expr) + {} + + const char *m_asm_symbolic_name; + const char *m_constraint; + tree m_expr; +}; + class block : public wrapper { public: @@ -563,6 +580,16 @@ public: block *default_block, const auto_vec *cases); + void + add_extended_asm (location *loc, + const char *asm_template, + bool is_volatile, + bool is_inline, + const auto_vec *outputs, + const auto_vec *inputs, + const auto_vec *clobbers, + const auto_vec *goto_blocks); + private: void set_tree_location (tree t, location *loc) diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c index 3a84c1fc5c0..1b0f8bc7db3 100644 --- a/gcc/jit/jit-recording.c +++ b/gcc/jit/jit-recording.c @@ -1578,6 +1578,10 @@ recording::context::dump_to_file (const char *path, bool update_locations) { fn->write_to_dump (d); } + + top_level_asm *tla; + FOR_EACH_VEC_ELT (m_top_level_asms, i, tla) + tla->write_to_dump (d); } static const char * const @@ -1904,6 +1908,22 @@ recording::context::get_all_requested_dumps (vec *ou out->splice (m_requested_dumps); } +/* Create a recording::top_level_asm instance and add it to this + context's list of mementos and to m_top_level_asms. + + Implements the post-error-checking part of + gcc_jit_context_add_top_level_asm. */ + +void +recording::context::add_top_level_asm (recording::location *loc, + const char *asm_stmts) +{ + recording::top_level_asm *asm_obj + = new recording::top_level_asm (this, loc, new_string (asm_stmts)); + record (asm_obj); + m_top_level_asms.safe_push (asm_obj); +} + /* This is a pre-compilation check for the context (and any parents). Detect errors within the context, adding errors if any are found. */ @@ -4206,6 +4226,23 @@ recording::block::add_comment (recording::location *loc, return result; } +/* Create a recording::extended_asm_simple instance and add it to + the block's context's list of mementos, and to the block's + list of statements. + + Implements the heart of gcc_jit_block_add_extended_asm. */ + +recording::extended_asm * +recording::block::add_extended_asm (location *loc, + const char *asm_template) +{ + extended_asm *result + = new extended_asm_simple (this, loc, new_string (asm_template)); + m_ctxt->record (result); + m_statements.safe_push (result); + return result; +} + /* Create a recording::end_with_conditional instance and add it to the block's context's list of mementos, and to the block's list of statements. @@ -4288,6 +4325,30 @@ recording::block::end_with_switch (recording::location *loc, return result; } +/* Create a recording::extended_asm_goto instance and add it to + the block's context's list of mementos, and to the block's + list of statements. + + Implements the heart of gcc_jit_block_end_with_extended_asm_goto. */ + + +recording::extended_asm * +recording::block::end_with_extended_asm_goto (location *loc, + const char *asm_template, + int num_goto_blocks, + block **goto_blocks, + block *fallthrough_block) +{ + extended_asm *result + = new extended_asm_goto (this, loc, new_string (asm_template), + num_goto_blocks, goto_blocks, + fallthrough_block); + m_ctxt->record (result); + m_statements.safe_push (result); + m_has_been_terminated = true; + return result; +} + /* Override the default implementation of recording::memento::write_to_dump for blocks by writing an unindented block name as a label, followed by the indented @@ -6508,6 +6569,459 @@ recording::switch_::write_reproducer (reproducer &r) cases_id); } +/* class asm_operand : public memento. */ + +recording::asm_operand::asm_operand (extended_asm *ext_asm, + string *asm_symbolic_name, + string *constraint) +: memento (ext_asm->get_context ()), + m_ext_asm (ext_asm), + m_asm_symbolic_name (asm_symbolic_name), + m_constraint (constraint) +{ +} + +void +recording::asm_operand::print (pretty_printer *pp) const +{ + if (m_asm_symbolic_name) + { + pp_character (pp, '['); + pp_string (pp, m_asm_symbolic_name->c_str ()); + pp_character (pp, ']'); + pp_space (pp); + } + pp_string (pp, m_constraint->get_debug_string ()); + /* Subclass will add lvalue/rvalue. */ +} + +recording::string * +recording::asm_operand::make_debug_string () +{ + pretty_printer pp; + print (&pp); + return m_ctxt->new_string (pp_formatted_text (&pp), false); +} + +/* class output_asm_operand : public asm_operand. */ + +void +recording::output_asm_operand::write_reproducer (reproducer &r) +{ + const char *fmt = + " gcc_jit_extended_asm_add_output_operand (%s, /* gcc_jit_extended_asm *ext_asm */\n" + " %s, /* const char *asm_symbolic_name */\n" + " %s, /* const char *constraint */\n" + " %s); /* gcc_jit_lvalue *dest */\n"; + r.write (fmt, + r.get_identifier (m_ext_asm), + (m_asm_symbolic_name + ? m_asm_symbolic_name->get_debug_string () : "NULL"), + m_constraint->get_debug_string (), + r.get_identifier (m_dest)); +} + +void +recording::output_asm_operand::print (pretty_printer *pp) const +{ + asm_operand::print (pp); + pp_string (pp, " ("); + pp_string (pp, m_dest->get_debug_string ()); + pp_string (pp, ")"); +} + +/* class input_asm_operand : public asm_operand. */ + +void +recording::input_asm_operand::write_reproducer (reproducer &r) +{ + const char *fmt = + " gcc_jit_extended_asm_add_input_operand (%s, /* gcc_jit_extended_asm *ext_asm */\n" + " %s, /* const char *asm_symbolic_name */\n" + " %s, /* const char *constraint */\n" + " %s); /* gcc_jit_rvalue *src */\n"; + r.write (fmt, + r.get_identifier (m_ext_asm), + (m_asm_symbolic_name + ? m_asm_symbolic_name->get_debug_string () : "NULL"), + m_constraint->get_debug_string (), + r.get_identifier_as_rvalue (m_src)); +} + +void +recording::input_asm_operand::print (pretty_printer *pp) const +{ + asm_operand::print (pp); + pp_string (pp, " ("); + pp_string (pp, m_src->get_debug_string ()); + pp_string (pp, ")"); +} + +/* The implementation of class gcc::jit::recording::extended_asm. */ + +void +recording::extended_asm::add_output_operand (const char *asm_symbolic_name, + const char *constraint, + lvalue *dest) +{ + output_asm_operand *op + = new output_asm_operand (this, + new_string (asm_symbolic_name), + new_string (constraint), + dest); + m_ctxt->record (op); + m_output_ops.safe_push (op); +} + +void +recording::extended_asm::add_input_operand (const char *asm_symbolic_name, + const char *constraint, + rvalue *src) +{ + input_asm_operand *op + = new input_asm_operand (this, + new_string (asm_symbolic_name), + new_string (constraint), + src); + m_ctxt->record (op); + m_input_ops.safe_push (op); +} + +void +recording::extended_asm::add_clobber (const char *victim) +{ + m_clobbers.safe_push (new_string (victim)); +} + +/* Implementation of recording::memento::replay_into + for recording::extended_asm. */ + +void +recording::extended_asm::replay_into (replayer *r) +{ + auto_vec playback_output_ops; + auto_vec playback_input_ops; + auto_vec playback_clobbers; + auto_vec playback_goto_blocks; + + /* Populate outputs. */ + { + output_asm_operand *rec_asm_op; + unsigned i; + FOR_EACH_VEC_ELT (m_output_ops, i, rec_asm_op) + { + playback::asm_operand playback_asm_op + (rec_asm_op->get_symbolic_name (), + rec_asm_op->get_constraint (), + rec_asm_op->get_lvalue ()->playback_lvalue ()->as_tree ()); + playback_output_ops.safe_push (playback_asm_op); + } + } + + /* Populate inputs. */ + { + input_asm_operand *rec_asm_op; + unsigned i; + FOR_EACH_VEC_ELT (m_input_ops, i, rec_asm_op) + { + playback::asm_operand playback_asm_op + (rec_asm_op->get_symbolic_name (), + rec_asm_op->get_constraint (), + rec_asm_op->get_rvalue ()->playback_rvalue ()->as_tree ()); + playback_input_ops.safe_push (playback_asm_op); + } + } + + /* Populate clobbers. */ + { + string *rec_clobber; + unsigned i; + FOR_EACH_VEC_ELT (m_clobbers, i, rec_clobber) + playback_clobbers.safe_push (rec_clobber->c_str ()); + } + + /* Populate playback blocks if an "asm goto". */ + maybe_populate_playback_blocks (&playback_goto_blocks); + + playback_block (get_block ()) + ->add_extended_asm (playback_location (r), + m_asm_template->c_str (), + m_is_volatile, m_is_inline, + &playback_output_ops, + &playback_input_ops, + &playback_clobbers, + &playback_goto_blocks); +} + +/* Implementation of recording::memento::make_debug_string for + an extended_asm "statement". */ + +recording::string * +recording::extended_asm::make_debug_string () +{ + pretty_printer pp; + pp_string (&pp, "asm "); + if (m_is_volatile) + pp_string (&pp, "volatile "); + if (m_is_inline) + pp_string (&pp, "inline "); + if (is_goto ()) + pp_string (&pp, "goto "); + pp_character (&pp, '('); + pp_string (&pp, m_asm_template->get_debug_string ()); + pp_string (&pp, " : "); + unsigned i; + { + output_asm_operand *asm_op; + FOR_EACH_VEC_ELT (m_output_ops, i, asm_op) + { + if (i > 0) + pp_string (&pp, ", "); + asm_op->print (&pp); + } + } + pp_string (&pp, " : "); + { + input_asm_operand *asm_op; + FOR_EACH_VEC_ELT (m_input_ops, i, asm_op) + { + if (i > 0) + pp_string (&pp, ", "); + asm_op->print (&pp); + } + } + pp_string (&pp, " : "); + string *rec_clobber; + FOR_EACH_VEC_ELT (m_clobbers, i, rec_clobber) + { + if (i > 0) + pp_string (&pp, ", "); + pp_string (&pp, rec_clobber->get_debug_string ()); + } + maybe_print_gotos (&pp); + pp_character (&pp, ')'); + return new_string (pp_formatted_text (&pp)); +} + +void +recording::extended_asm::write_flags (reproducer &r) +{ + if (m_is_volatile) + r.write (" gcc_jit_extended_asm_set_volatile_flag (%s, 1);\n", + r.get_identifier (this)); + if (m_is_inline) + r.write (" gcc_jit_extended_asm_set_inline_flag (%s, 1);\n", + r.get_identifier (this)); +} + +void +recording::extended_asm::write_clobbers (reproducer &r) +{ + string *clobber; + unsigned i; + FOR_EACH_VEC_ELT (m_clobbers, i, clobber) + r.write (" gcc_jit_extended_asm_add_clobber (%s, %s);\n", + r.get_identifier (this), + clobber->get_debug_string ()); +} + +/* Implementation of recording::memento::write_reproducer for + extended_asm_simple. */ + +void +recording::extended_asm_simple::write_reproducer (reproducer &r) +{ + const char *id = r.make_identifier (this, "extended_asm"); + r.write (" gcc_jit_extended_asm *%s =\n" + " gcc_jit_block_add_extended_asm (%s, /*gcc_jit_block *block */\n" + " %s, /* gcc_jit_location *loc */\n" + " %s); /* const char *asm_template */\n", + id, + r.get_identifier (get_block ()), + r.get_identifier (get_loc ()), + m_asm_template->get_debug_string ()); + write_flags (r); + write_clobbers (r); +} + +void +recording::extended_asm:: +maybe_populate_playback_blocks (auto_vec *) +{ + /* Do nothing; not an "asm goto". */ +} + +/* The implementation of class gcc::jit::recording::extended_asm_goto. */ + +/* recording::extended_asm_goto's ctor. */ + +recording::extended_asm_goto::extended_asm_goto (block *b, + location *loc, + string *asm_template, + int num_goto_blocks, + block **goto_blocks, + block *fallthrough_block) +: extended_asm (b, loc, asm_template), + m_goto_blocks (num_goto_blocks), + m_fallthrough_block (fallthrough_block) +{ + for (int i = 0; i < num_goto_blocks; i++) + m_goto_blocks.quick_push (goto_blocks[i]); +} + +/* Implementation of recording::memento::replay_into + for recording::extended_asm_goto. */ + +void +recording::extended_asm_goto::replay_into (replayer *r) +{ + /* Chain up to base class impl. */ + recording::extended_asm::replay_into (r); + + /* ...and potentially add a goto for the fallthrough. */ + if (m_fallthrough_block) + playback_block (get_block ()) + ->add_jump (playback_location (r), + m_fallthrough_block->playback_block ()); +} + +/* Implementation of recording::memento::write_reproducer for + extended_asm_goto. */ + +void +recording::extended_asm_goto::write_reproducer (reproducer &r) +{ + const char *id = r.make_identifier (this, "extended_asm"); + const char *blocks_id = r.make_tmp_identifier ("blocks_for", this); + r.write (" gcc_jit_block *%s[%i] = {\n", + blocks_id, + m_goto_blocks.length ()); + int i; + block *b; + FOR_EACH_VEC_ELT (m_goto_blocks, i, b) + r.write (" %s,\n", r.get_identifier (b)); + r.write (" };\n"); + r.write (" gcc_jit_extended_asm *%s =\n" + " gcc_jit_block_end_with_extended_asm_goto (%s, /*gcc_jit_block *block */\n" + " %s, /* gcc_jit_location *loc */\n" + " %s, /* const char *asm_template */\n" + " %i, /* int num_goto_blocks */\n" + " %s, /* gcc_jit_block **goto_blocks */\n" + " %s); /* gcc_jit_block *fallthrough_block */\n", + id, + r.get_identifier (get_block ()), + r.get_identifier (get_loc ()), + m_asm_template->get_debug_string (), + m_goto_blocks.length (), + blocks_id, + (m_fallthrough_block + ? r.get_identifier (m_fallthrough_block) + : "NULL")); + write_flags (r); + write_clobbers (r); +} + +/* Override the poisoned default implementation of + gcc::jit::recording::statement::get_successor_blocks + + An extended_asm_goto can jump to the m_goto_blocks, and to + the (optional) m_fallthrough_block. */ + +vec +recording::extended_asm_goto::get_successor_blocks () const +{ + vec result; + result.create (m_goto_blocks.length () + 1); + if (m_fallthrough_block) + result.quick_push (m_fallthrough_block); + result.splice (m_goto_blocks); + return result; +} + +/* Vfunc for use by recording::extended_asm::make_debug_string. */ + +void +recording::extended_asm_goto::maybe_print_gotos (pretty_printer *pp) const +{ + pp_string (pp, " : "); + unsigned i; + block *b; + FOR_EACH_VEC_ELT (m_goto_blocks, i, b) + { + if (i > 0) + pp_string (pp, ", "); + pp_string (pp, b->get_debug_string ()); + } + /* Non-C syntax here. */ + if (m_fallthrough_block) + pp_printf (pp, " [fallthrough: %s]", + m_fallthrough_block->get_debug_string ()); +} + +/* Vfunc for use by recording::extended_asm::replay_into. */ + +void +recording::extended_asm_goto:: +maybe_populate_playback_blocks (auto_vec *out) +{ + unsigned i; + block *b; + FOR_EACH_VEC_ELT (m_goto_blocks, i, b) + out->safe_push (b->playback_block ()); +} + +/* class top_level_asm : public memento. */ + +recording::top_level_asm::top_level_asm (context *ctxt, + location *loc, + string *asm_stmts) +: memento (ctxt), + m_loc (loc), + m_asm_stmts (asm_stmts) +{ +} + +/* Implementation of recording::memento::replay_into for top-level asm. */ + +void +recording::top_level_asm::replay_into (replayer *r) +{ + r->add_top_level_asm (m_asm_stmts->c_str ()); +} + +/* Implementation of recording::memento::make_debug_string for + top-level asm. */ + +recording::string * +recording::top_level_asm::make_debug_string () +{ + return string::from_printf (m_ctxt, "asm (%s)", + m_asm_stmts->get_debug_string ()); +} + +/* Override the default implementation of + recording::memento::write_to_dump. + Don't indent the string. */ + +void +recording::top_level_asm::write_to_dump (dump &d) +{ + d.write ("%s;\n", get_debug_string ()); +} + +/* Implementation of recording::memento::write_reproducer for top-level asm. */ + +void +recording::top_level_asm::write_reproducer (reproducer &r) +{ + r.write (" gcc_jit_context_add_top_level_asm (%s, /* gcc_jit_context *ctxt */\n" + " %s, /* gcc_jit_location *loc */\n" + " %s); /* const char *asm_stmts */\n", + r.get_identifier (get_context ()), + r.get_identifier (m_loc), + m_asm_stmts->get_debug_string ()); +} + } // namespace gcc::jit } // namespace gcc diff --git a/gcc/jit/jit-recording.h b/gcc/jit/jit-recording.h index 9a43a7bf33a..e6948828d2a 100644 --- a/gcc/jit/jit-recording.h +++ b/gcc/jit/jit-recording.h @@ -301,6 +301,8 @@ public: void set_timer (timer *t) { m_timer = t; } timer *get_timer () const { return m_timer; } + void add_top_level_asm (location *loc, const char *asm_stmts); + private: void log_all_options () const; void log_str_option (enum gcc_jit_str_option opt) const; @@ -344,6 +346,7 @@ private: auto_vec m_compound_types; auto_vec m_globals; auto_vec m_functions; + auto_vec m_top_level_asms; type *m_basic_types[NUM_GCC_JIT_TYPES]; type *m_FILE_type; @@ -1275,6 +1278,10 @@ public: add_comment (location *loc, const char *text); + extended_asm * + add_extended_asm (location *loc, + const char *asm_template); + statement * end_with_conditional (location *loc, rvalue *boolval, @@ -1296,6 +1303,13 @@ public: int num_cases, case_ **cases); + extended_asm * + end_with_extended_asm_goto (location *loc, + const char *asm_template, + int num_goto_blocks, + block **goto_blocks, + block *fallthrough_block); + playback::block * playback_block () const { @@ -2112,6 +2126,207 @@ private: auto_vec m_cases; }; +class asm_operand : public memento +{ +public: + asm_operand (extended_asm *ext_asm, + string *asm_symbolic_name, + string *constraint); + + const char *get_symbolic_name () const + { + if (m_asm_symbolic_name) + return m_asm_symbolic_name->c_str (); + else + return NULL; + } + + const char *get_constraint () const + { + return m_constraint->c_str (); + } + + virtual void print (pretty_printer *pp) const; + +private: + string * make_debug_string () FINAL OVERRIDE; + +protected: + extended_asm *m_ext_asm; + string *m_asm_symbolic_name; + string *m_constraint; +}; + +class output_asm_operand : public asm_operand +{ +public: + output_asm_operand (extended_asm *ext_asm, + string *asm_symbolic_name, + string *constraint, + lvalue *dest) + : asm_operand (ext_asm, asm_symbolic_name, constraint), + m_dest (dest) + {} + + lvalue *get_lvalue () const { return m_dest; } + + void replay_into (replayer *) FINAL OVERRIDE {} + + void print (pretty_printer *pp) const FINAL OVERRIDE; + +private: + void write_reproducer (reproducer &r) FINAL OVERRIDE; + +private: + lvalue *m_dest; +}; + +class input_asm_operand : public asm_operand +{ +public: + input_asm_operand (extended_asm *ext_asm, + string *asm_symbolic_name, + string *constraint, + rvalue *src) + : asm_operand (ext_asm, asm_symbolic_name, constraint), + m_src (src) + {} + + rvalue *get_rvalue () const { return m_src; } + + void replay_into (replayer *) FINAL OVERRIDE {} + + void print (pretty_printer *pp) const FINAL OVERRIDE; + +private: + void write_reproducer (reproducer &r) FINAL OVERRIDE; + +private: + rvalue *m_src; +}; + +/* Abstract base class for extended_asm statements. */ + +class extended_asm : public statement +{ +public: + extended_asm (block *b, + location *loc, + string *asm_template) + : statement (b, loc), + m_asm_template (asm_template), + m_is_volatile (false), + m_is_inline (false) + {} + + void set_volatile_flag (bool flag) { m_is_volatile = flag; } + void set_inline_flag (bool flag) { m_is_inline = flag; } + + void add_output_operand (const char *asm_symbolic_name, + const char *constraint, + lvalue *dest); + void add_input_operand (const char *asm_symbolic_name, + const char *constraint, + rvalue *src); + void add_clobber (const char *victim); + + void replay_into (replayer *r) OVERRIDE; + + string *get_asm_template () const { return m_asm_template; } + + virtual bool is_goto () const = 0; + virtual void maybe_print_gotos (pretty_printer *) const = 0; + +protected: + void write_flags (reproducer &r); + void write_clobbers (reproducer &r); + +private: + string * make_debug_string () FINAL OVERRIDE; + virtual void maybe_populate_playback_blocks + (auto_vec *out) = 0; + +protected: + string *m_asm_template; + bool m_is_volatile; + bool m_is_inline; + auto_vec m_output_ops; + auto_vec m_input_ops; + auto_vec m_clobbers; +}; + +/* An extended_asm that's not a goto, as created by + gcc_jit_block_add_extended_asm. */ + +class extended_asm_simple : public extended_asm +{ +public: + extended_asm_simple (block *b, + location *loc, + string *asm_template) + : extended_asm (b, loc, asm_template) + {} + + void write_reproducer (reproducer &r) OVERRIDE; + bool is_goto () const FINAL OVERRIDE { return false; } + void maybe_print_gotos (pretty_printer *) const FINAL OVERRIDE {} + +private: + void maybe_populate_playback_blocks + (auto_vec *) FINAL OVERRIDE + {} +}; + +/* An extended_asm that's a asm goto, as created by + gcc_jit_block_end_with_extended_asm_goto. */ + +class extended_asm_goto : public extended_asm +{ +public: + extended_asm_goto (block *b, + location *loc, + string *asm_template, + int num_goto_blocks, + block **goto_blocks, + block *fallthrough_block); + + void replay_into (replayer *r) FINAL OVERRIDE; + void write_reproducer (reproducer &r) OVERRIDE; + + vec get_successor_blocks () const FINAL OVERRIDE; + + bool is_goto () const FINAL OVERRIDE { return true; } + void maybe_print_gotos (pretty_printer *) const FINAL OVERRIDE; + +private: + void maybe_populate_playback_blocks + (auto_vec *out) FINAL OVERRIDE; + +private: + auto_vec m_goto_blocks; + block *m_fallthrough_block; +}; + +/* A group of top-level asm statements, as created by + gcc_jit_context_add_top_level_asm. */ + +class top_level_asm : public memento +{ +public: + top_level_asm (context *ctxt, location *loc, string *asm_stmts); + + void write_to_dump (dump &d) FINAL OVERRIDE; + +private: + void replay_into (replayer *r) FINAL OVERRIDE; + string * make_debug_string () FINAL OVERRIDE; + void write_reproducer (reproducer &r) FINAL OVERRIDE; + +private: + location *m_loc; + string *m_asm_stmts; +}; + } // namespace gcc::jit::recording /* Create a recording::memento_of_new_rvalue_from_const instance and add diff --git a/gcc/jit/libgccjit++.h b/gcc/jit/libgccjit++.h index 1b9ef1a5db9..b4901ceb68a 100644 --- a/gcc/jit/libgccjit++.h +++ b/gcc/jit/libgccjit++.h @@ -46,6 +46,7 @@ namespace gccjit class lvalue; class param; class case_; + class extended_asm; class timer; class auto_time; @@ -316,6 +317,9 @@ namespace gccjit rvalue max_value, block dest_block); + void add_top_level_asm (const char *asm_stmts, + location loc = location ()); + private: gcc_jit_context *m_inner_ctxt; }; @@ -449,6 +453,13 @@ namespace gccjit block default_block, std::vector cases, location loc = location ()); + + extended_asm add_extended_asm (const std::string &asm_template, + location loc = location ()); + extended_asm end_with_extended_asm_goto (const std::string &asm_template, + std::vector goto_blocks, + block *fallthrough_block, + location loc = location ()); }; class rvalue : public object @@ -509,6 +520,40 @@ namespace gccjit gcc_jit_case *get_inner_case () const; }; + class extended_asm : public object + { + public: + extended_asm (); + extended_asm (gcc_jit_extended_asm *inner); + + extended_asm & + set_volatile_flag (bool flag); + + extended_asm & + set_inline_flag (bool flag); + + extended_asm& + add_output_operand (const std::string &asm_symbolic_name, + const std::string &constraint, + gccjit::lvalue dest); + extended_asm& + add_output_operand (const std::string &constraint, + gccjit::lvalue dest); + + extended_asm& + add_input_operand (const std::string &asm_symbolic_name, + const std::string &constraint, + gccjit::rvalue src); + extended_asm& + add_input_operand (const std::string &constraint, + gccjit::rvalue src); + + extended_asm& + add_clobber (const std::string &victim); + + gcc_jit_extended_asm *get_inner_extended_asm () const; + }; + /* Overloaded operators, for those who want the most terse API (at the possible risk of being a little too magical). @@ -1259,6 +1304,14 @@ context::new_case (rvalue min_value, dest_block.get_inner_block ())); } +inline void +context::add_top_level_asm (const char *asm_stmts, location loc) +{ + gcc_jit_context_add_top_level_asm (m_inner_ctxt, + loc.get_inner_location (), + asm_stmts); +} + // class object inline context object::get_context () const @@ -1554,6 +1607,37 @@ block::end_with_switch (rvalue expr, as_array_of_ptrs); } +inline extended_asm +block::add_extended_asm (const std::string &asm_template, + location loc) +{ + return gcc_jit_block_add_extended_asm (get_inner_block (), + loc.get_inner_location (), + asm_template.c_str ()); +} + +inline extended_asm +block::end_with_extended_asm_goto (const std::string &asm_template, + std::vector goto_blocks, + block *fallthrough_block, + location loc) +{ + /* Treat std::vector as an array, relying on it not being resized: */ + block *as_array_of_wrappers = &goto_blocks[0]; + + /* Treat the array as being of the underlying pointers, relying on + the wrapper type being such a pointer internally. */ + gcc_jit_block **as_array_of_ptrs = + reinterpret_cast (as_array_of_wrappers); + return gcc_jit_block_end_with_extended_asm_goto + (get_inner_block (), + loc.get_inner_location (), + asm_template.c_str (), + goto_blocks.size (), + as_array_of_ptrs, + fallthrough_block ? fallthrough_block->get_inner_block () : NULL); +} + inline rvalue block::add_call (function other, location loc) @@ -1767,6 +1851,92 @@ case_::get_inner_case () const return reinterpret_cast (get_inner_object ()); } +// class extended_asm : public object +inline extended_asm::extended_asm () : object () {} +inline extended_asm::extended_asm (gcc_jit_extended_asm *inner) + : object (gcc_jit_extended_asm_as_object (inner)) +{ +} + +inline extended_asm& +extended_asm::set_volatile_flag (bool flag) +{ + gcc_jit_extended_asm_set_volatile_flag (get_inner_extended_asm (), flag); + return *this; +} + +inline extended_asm& +extended_asm::set_inline_flag (bool flag) +{ + gcc_jit_extended_asm_set_inline_flag (get_inner_extended_asm (), flag); + return *this; +} + +inline extended_asm& +extended_asm::add_output_operand (const std::string &asm_symbolic_name, + const std::string &constraint, + gccjit::lvalue dest) +{ + gcc_jit_extended_asm_add_output_operand + (get_inner_extended_asm (), + asm_symbolic_name.c_str (), + constraint.c_str (), + dest.get_inner_lvalue ()); + return *this; +} + +inline extended_asm& +extended_asm::add_output_operand (const std::string &constraint, + gccjit::lvalue dest) +{ + gcc_jit_extended_asm_add_output_operand + (get_inner_extended_asm (), + NULL, /* asm_symbolic_name */ + constraint.c_str (), + dest.get_inner_lvalue ()); + return *this; +} + +inline extended_asm& +extended_asm::add_input_operand (const std::string &asm_symbolic_name, + const std::string &constraint, + gccjit::rvalue src) +{ + gcc_jit_extended_asm_add_input_operand + (get_inner_extended_asm (), + asm_symbolic_name.c_str (), + constraint.c_str (), + src.get_inner_rvalue ()); + return *this; +} + +inline extended_asm& +extended_asm::add_input_operand (const std::string &constraint, + gccjit::rvalue src) +{ + gcc_jit_extended_asm_add_input_operand + (get_inner_extended_asm (), + NULL, /* asm_symbolic_name */ + constraint.c_str (), + src.get_inner_rvalue ()); + return *this; +} + +inline extended_asm& +extended_asm::add_clobber (const std::string &victim) +{ + gcc_jit_extended_asm_add_clobber (get_inner_extended_asm (), + victim.c_str ()); + return *this; +} + +inline gcc_jit_extended_asm * +extended_asm::get_inner_extended_asm () const +{ + /* Manual downcast: */ + return reinterpret_cast (get_inner_object ()); +} + /* Overloaded operators. */ // Unary operators inline rvalue operator- (rvalue a) diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c index a00aefc7108..f9c33c63c64 100644 --- a/gcc/jit/libgccjit.c +++ b/gcc/jit/libgccjit.c @@ -96,6 +96,11 @@ struct gcc_jit_timer : public timer { }; +struct gcc_jit_extended_asm : public gcc::jit::recording::extended_asm +{ +}; + + /********************************************************************** Error-handling. @@ -300,13 +305,13 @@ struct gcc_jit_timer : public timer static void jit_error (gcc::jit::recording::context *ctxt, - gcc_jit_location *loc, + gcc::jit::recording::location *loc, const char *fmt, ...) GNU_PRINTF(3, 4); static void jit_error (gcc::jit::recording::context *ctxt, - gcc_jit_location *loc, + gcc::jit::recording::location *loc, const char *fmt, ...) { va_list ap; @@ -3290,3 +3295,182 @@ gcc_jit_version_patchlevel (void) version_info vi; return vi.patchlevel; } + +/********************************************************************** + Asm support. + **********************************************************************/ + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::block::add_extended_asm, in + jit-recording.c. */ + +gcc_jit_extended_asm * +gcc_jit_block_add_extended_asm (gcc_jit_block *block, + gcc_jit_location *loc, + const char *asm_template) +{ + RETURN_NULL_IF_NOT_VALID_BLOCK (block, loc); + gcc::jit::recording::context *ctxt = block->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + /* LOC can be NULL. */ + RETURN_NULL_IF_FAIL (asm_template, ctxt, loc, "NULL asm_template"); + + return (gcc_jit_extended_asm *)block->add_extended_asm (loc, asm_template); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::block::end_with_extended_asm_goto, in + jit-recording.c. */ + +gcc_jit_extended_asm * +gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block *block, + gcc_jit_location *loc, + const char *asm_template, + int num_goto_blocks, + gcc_jit_block **goto_blocks, + gcc_jit_block *fallthrough_block) +{ + RETURN_NULL_IF_NOT_VALID_BLOCK (block, loc); + gcc::jit::recording::context *ctxt = block->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + /* LOC can be NULL. */ + RETURN_NULL_IF_FAIL (asm_template, ctxt, loc, "NULL asm_template"); + RETURN_NULL_IF_FAIL (num_goto_blocks >= 0, ctxt, loc, "num_goto_blocks < 0"); + for (int i = 0; i < num_goto_blocks; i++) + RETURN_NULL_IF_FAIL_PRINTF1 (goto_blocks[i], + ctxt, loc, + "NULL goto_blocks[%i]", i); + /* fallthrough_block can be NULL. */ + return (gcc_jit_extended_asm *)block->end_with_extended_asm_goto + (loc, asm_template, + num_goto_blocks, (gcc::jit::recording::block **)goto_blocks, + fallthrough_block); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, this calls the trivial + gcc::jit::recording::memento::as_object method (an extended_asm is a + memento), in jit-recording.h. */ + +gcc_jit_object * +gcc_jit_extended_asm_as_object (gcc_jit_extended_asm *ext_asm) +{ + RETURN_NULL_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + + return static_cast (ext_asm->as_object ()); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::extended_asm::set_volatile_flag, in + jit-recording.c. */ + +void +gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm *ext_asm, + int flag) +{ + RETURN_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + ext_asm->set_volatile_flag (flag); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::extended_asm::set_inline_flag, in + jit-recording.c. */ + +void +gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm *ext_asm, + int flag) +{ + RETURN_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + ext_asm->set_inline_flag (flag); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::extended_asm::add_output_operand, in + jit-recording.c. */ + +void +gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm *ext_asm, + const char *asm_symbolic_name, + const char *constraint, + gcc_jit_lvalue *dest) +{ + RETURN_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + gcc::jit::recording::context *ctxt = ext_asm->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + gcc::jit::recording::location *loc = ext_asm->get_loc (); + /* asm_symbolic_name can be NULL. */ + RETURN_IF_FAIL (constraint, ctxt, loc, "NULL constraint"); + RETURN_IF_FAIL (dest, ctxt, loc, "NULL dest"); + RETURN_IF_FAIL (!ext_asm->is_goto (), ctxt, loc, + "cannot add output operand to asm goto"); + ext_asm->add_output_operand (asm_symbolic_name, constraint, dest); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::extended_asm::add_input_operand, in + jit-recording.c. */ + +extern void +gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm *ext_asm, + const char *asm_symbolic_name, + const char *constraint, + gcc_jit_rvalue *src) +{ + RETURN_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + gcc::jit::recording::context *ctxt = ext_asm->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + gcc::jit::recording::location *loc = ext_asm->get_loc (); + /* asm_symbolic_name can be NULL. */ + RETURN_IF_FAIL (constraint, ctxt, loc, "NULL constraint"); + RETURN_IF_FAIL (src, ctxt, loc, "NULL src"); + ext_asm->add_input_operand (asm_symbolic_name, constraint, src); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::extended_asm::add_clobber, in + jit-recording.c. */ + +void +gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm *ext_asm, + const char *victim) +{ + RETURN_IF_FAIL (ext_asm, NULL, NULL, "NULL ext_asm"); + gcc::jit::recording::context *ctxt = ext_asm->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + gcc::jit::recording::location *loc = ext_asm->get_loc (); + RETURN_IF_FAIL (victim, ctxt, loc, "NULL victim"); + ext_asm->add_clobber (victim); +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::context::add_top_level_asm, in + jit-recording.c. */ + +void +gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt, + gcc_jit_location *loc, + const char *asm_stmts) +{ + RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL ctxt"); + JIT_LOG_FUNC (ctxt->get_logger ()); + /* LOC can be NULL. */ + RETURN_IF_FAIL (asm_stmts, ctxt, NULL, "NULL asm_stmts"); + ctxt->add_top_level_asm (loc, asm_stmts); +} diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 7fbaa9f3162..c523f93a821 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -68,6 +68,7 @@ typedef struct gcc_jit_result gcc_jit_result; +- gcc_jit_lvalue +- gcc_jit_param +- gcc_jit_case + +- gcc_jit_extended_asm */ typedef struct gcc_jit_object gcc_jit_object; @@ -138,6 +139,12 @@ typedef struct gcc_jit_param gcc_jit_param; destination block. */ typedef struct gcc_jit_case gcc_jit_case; +/* A gcc_jit_extended_asm represents an assembly language statement, + analogous to an extended "asm" statement in GCC's C front-end: a series + of low-level instructions inside a function that convert inputs to + outputs. */ +typedef struct gcc_jit_extended_asm gcc_jit_extended_asm; + /* Acquire a JIT-compilation context. */ extern gcc_jit_context * gcc_jit_context_acquire (void); @@ -1518,6 +1525,102 @@ gcc_jit_version_minor (void); extern int gcc_jit_version_patchlevel (void); +/********************************************************************** + Asm support. + **********************************************************************/ + +/* Functions for adding inline assembler code, analogous to GCC's + "extended asm" syntax. + + See https://gcc.gnu.org/onlinedocs/gcc/Using-Assembly-Language-with-C.html + + These API entrypoints were added in LIBGCCJIT_ABI_15; you can test for their + presence using + #ifdef LIBGCCJIT_HAVE_ASM_STATEMENTS +*/ + +#define LIBGCCJIT_HAVE_ASM_STATEMENTS + +/* Create a gcc_jit_extended_asm for an extended asm statement + with no control flow (i.e. without the goto qualifier). + + The asm_template parameter corresponds to the AssemblerTemplate + within C's extended asm syntax. It must be non-NULL. */ + +extern gcc_jit_extended_asm * +gcc_jit_block_add_extended_asm (gcc_jit_block *block, + gcc_jit_location *loc, + const char *asm_template); + +/* Create a gcc_jit_extended_asm for an extended asm statement + that may perform jumps, and use it to terminate the given block. + This is equivalent to the "goto" qualifier in C's extended asm + syntax. */ + +extern gcc_jit_extended_asm * +gcc_jit_block_end_with_extended_asm_goto (gcc_jit_block *block, + gcc_jit_location *loc, + const char *asm_template, + int num_goto_blocks, + gcc_jit_block **goto_blocks, + gcc_jit_block *fallthrough_block); + +/* Upcasting from extended asm to object. */ + +extern gcc_jit_object * +gcc_jit_extended_asm_as_object (gcc_jit_extended_asm *ext_asm); + +/* Set whether the gcc_jit_extended_asm has side-effects, equivalent to + the "volatile" qualifier in C's extended asm syntax. */ + +extern void +gcc_jit_extended_asm_set_volatile_flag (gcc_jit_extended_asm *ext_asm, + int flag); + +/* Set the equivalent of the "inline" qualifier in C's extended asm + syntax. */ + +extern void +gcc_jit_extended_asm_set_inline_flag (gcc_jit_extended_asm *ext_asm, + int flag); + +/* Add an output operand to the extended asm statement. + "asm_symbolic_name" can be NULL. + "constraint" and "dest" must be non-NULL. + This function can't be called on an "asm goto" as such instructions + can't have outputs */ + +extern void +gcc_jit_extended_asm_add_output_operand (gcc_jit_extended_asm *ext_asm, + const char *asm_symbolic_name, + const char *constraint, + gcc_jit_lvalue *dest); + +/* Add an input operand to the extended asm statement. + "asm_symbolic_name" can be NULL. + "constraint" and "src" must be non-NULL. */ + +extern void +gcc_jit_extended_asm_add_input_operand (gcc_jit_extended_asm *ext_asm, + const char *asm_symbolic_name, + const char *constraint, + gcc_jit_rvalue *src); + +/* Add "victim" to the list of registers clobbered by the extended + asm statement. It must be non-NULL. */ + +extern void +gcc_jit_extended_asm_add_clobber (gcc_jit_extended_asm *ext_asm, + const char *victim); + +/* Add "asm_stmts", a set of top-level asm statements, analogous to + those created by GCC's "basic" asm syntax in C at file scope. */ + +extern void +gcc_jit_context_add_top_level_asm (gcc_jit_context *ctxt, + gcc_jit_location *loc, + const char *asm_stmts); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index a6e67e781a4..bcabe167c05 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -192,3 +192,16 @@ LIBGCCJIT_ABI_14 { global: gcc_jit_global_set_initializer; } LIBGCCJIT_ABI_13; + +LIBGCCJIT_ABI_15 { + global: + gcc_jit_block_add_extended_asm; + gcc_jit_block_end_with_extended_asm_goto; + gcc_jit_extended_asm_as_object; + gcc_jit_extended_asm_set_volatile_flag; + gcc_jit_extended_asm_set_inline_flag; + gcc_jit_extended_asm_add_output_operand; + gcc_jit_extended_asm_add_input_operand; + gcc_jit_extended_asm_add_clobber; + gcc_jit_context_add_top_level_asm; +} LIBGCCJIT_ABI_14; diff --git a/gcc/testsuite/jit.dg/jit.exp b/gcc/testsuite/jit.dg/jit.exp index 2d8c884b6b8..9af87f9c6ad 100644 --- a/gcc/testsuite/jit.dg/jit.exp +++ b/gcc/testsuite/jit.dg/jit.exp @@ -37,12 +37,16 @@ load_lib target-libpath.exp load_lib gcc.exp load_lib g++.exp load_lib dejagnu.exp +load_lib target-supports-dg.exp # Skip these tests for targets that don't support -lgccjit if { ![check_effective_target_lgccjit] } { return } +# The default do-what keyword. +set dg-do-what-default compile + # Look for lines of the form: # definitely lost: 11,316 bytes in 235 blocks # indirectly lost: 352 bytes in 4 blocks @@ -379,6 +383,33 @@ proc jit-dg-test { prog do_what extra_tool_flags } { verbose " do_what: $do_what" verbose " extra_tool_flags: $extra_tool_flags" + global dg-do-what-default + set dg-do-what [list ${dg-do-what-default} "" P] + + set tmp [dg-get-options $prog] + foreach op $tmp { + verbose "Processing option: $op" 3 + set status [catch "$op" errmsg] + if { $status != 0 } { + if { 0 && [info exists errorInfo] } { + # This also prints a backtrace which will just confuse + # testcase writers, so it's disabled. + perror "$name: $errorInfo\n" + } else { + perror "$name: $errmsg for \"$op\"\n" + } + perror "$name: $errmsg for \"$op\"" 0 + return + } + } + + # If we're not supposed to try this test on this target, we're done. + if { [lindex ${dg-do-what} 1] == "N" } { + unsupported "$name" + verbose "$name not supported on this target, skipping it" 3 + return + } + # test-threads.c needs to be linked against pthreads if {[string match "*test-threads.c" $prog]} { append extra_tool_flags " -lpthread" diff --git a/gcc/testsuite/jit.dg/test-asm.c b/gcc/testsuite/jit.dg/test-asm.c new file mode 100644 index 00000000000..e7777eeb4fe --- /dev/null +++ b/gcc/testsuite/jit.dg/test-asm.c @@ -0,0 +1,492 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ + +#include +#include +#include +#include + +#include "libgccjit.h" + +#include "harness.h" + +/********************************************************************** + Support fns for creating code. + **********************************************************************/ + +/* Make a "void FUNC_NAME (void)" function with a single block, returning + that block. */ + +static gcc_jit_block * +make_single_block_func (gcc_jit_context *ctxt, const char *func_name) +{ + gcc_jit_type *void_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID); + gcc_jit_function *func + = gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + void_type, + func_name, + 0, NULL, 0); + return gcc_jit_function_new_block (func, "initial"); +} + +static const char * +get_desc (gcc_jit_extended_asm *ext_asm) +{ + return gcc_jit_object_get_debug_string + (gcc_jit_extended_asm_as_object (ext_asm)); +} + +/********************************************************************** + Support fns for verifying code. + **********************************************************************/ + +typedef void (*void_void_fn) (void); + +static void_void_fn +get_test_fn (gcc_jit_result *result, const char *func_name) +{ + return (void_void_fn)gcc_jit_result_get_code (result, func_name); +} + +/********************************************************************** + test_i386_basic_asm_1: simple example of asm + **********************************************************************/ + +/* Create the equivalent of: + + int src; + int dst; + + void test_i386_basic_asm_1 (void) + { + // Quote from here in docs/topics/asm.rst: example 1: C + asm ("mov %1, %0\n\t" + "add $1, %0" + : "=r" (dst) + : "r" (src)); + // Quote up to here in docs/topics/asm.rst: example 1: C + } + + i.e. copy src to dst and add 1 to dst. */ + +static void +create_test_i386_basic_asm_1 (gcc_jit_context *ctxt) +{ + gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + gcc_jit_lvalue *dst + = gcc_jit_context_new_global (ctxt, NULL, + GCC_JIT_GLOBAL_EXPORTED, + int_type, "dst"); + gcc_jit_lvalue *src + = gcc_jit_context_new_global (ctxt, NULL, + GCC_JIT_GLOBAL_EXPORTED, + int_type, "src"); + + gcc_jit_block *block + = make_single_block_func (ctxt, "test_i386_basic_asm_1"); + + /* Quote from here in docs/topics/asm.rst: example 1: jit. */ + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm (block, NULL, + "mov %1, %0\n\t" + "add $1, %0"); + gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=r", dst); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_lvalue_as_rvalue (src)); + /* Quote up to here in docs/topics/asm.rst: example 1: jit. */ + + const char *desc = get_desc (ext_asm); + CHECK_STRING_VALUE + (desc, + "asm (\"mov %1, %0\\n\\tadd $1, %0\" : \"=r\" (dst) : \"r\" (src) : )"); + + gcc_jit_block_end_with_void_return (block, NULL); +} + +static void +verify_code_1 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + void_void_fn test_i386_basic_asm_1 + = get_test_fn (result, "test_i386_basic_asm_1"); + CHECK_NON_NULL (test_i386_basic_asm_1); + + int *dst_ptr = (int *)gcc_jit_result_get_global (result, "dst"); + CHECK_NON_NULL (dst_ptr); + int *src_ptr = (int *)gcc_jit_result_get_global (result, "src"); + CHECK_NON_NULL (src_ptr); + + *src_ptr = 42; + *dst_ptr = 0; + test_i386_basic_asm_1 (); + CHECK_VALUE (*src_ptr, 42); + CHECK_VALUE (*dst_ptr, 43); +} + +/********************************************************************** + test_i386_basic_asm_2: test of symbolic names and clobbers + **********************************************************************/ + +/* Create the equivalent of: + uint32_t test_i386_basic_asm_2 (uint32_t Mask) + { + uint32_t Index; + // Quote from here in docs/topics/asm.rst: example 2: C + asm ("bsfl %[aMask], %[aIndex]" + : [aIndex] "=r" (Index) + : [aMask] "r" (Mask) + : "cc"); + // Quote up to here in docs/topics/asm.rst: example 2: C + return Index; + } + i.e. return the first bit set in "Mask" + + This exercises symbolic names and clobbers. */ + +static void +create_test_i386_basic_asm_2 (gcc_jit_context *ctxt) +{ + gcc_jit_type *uint32_type = gcc_jit_context_get_int_type (ctxt, 4, 0); + gcc_jit_param *mask + = gcc_jit_context_new_param (ctxt, NULL, + uint32_type, "Mask"); + gcc_jit_function *func + = gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + uint32_type, + "test_i386_basic_asm_2", + 1, &mask, 0); + gcc_jit_lvalue *index + = gcc_jit_function_new_local (func, NULL, + uint32_type, "Index"); + gcc_jit_block *block = gcc_jit_function_new_block (func, "initial"); + + /* Quote from here in docs/topics/asm.rst: example 2: jit. */ + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm (block, NULL, + "bsfl %[aMask], %[aIndex]"); + gcc_jit_extended_asm_add_output_operand (ext_asm, "aIndex", "=r", index); + gcc_jit_extended_asm_add_input_operand (ext_asm, "aMask", "r", + gcc_jit_param_as_rvalue (mask)); + gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); + /* Quote up to here in docs/topics/asm.rst: example 2: jit. */ + + const char *desc = get_desc (ext_asm); + CHECK_STRING_VALUE + (desc, + "asm (\"bsfl %[aMask], %[aIndex]\"" + " : [aIndex] \"=r\" (Index) : [aMask] \"r\" (Mask) : \"cc\")"); + + gcc_jit_block_end_with_return (block, NULL, + gcc_jit_lvalue_as_rvalue (index)); +} + +static void +verify_code_2 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef uint32_t (*fntype) (uint32_t); + fntype test_i386_basic_asm_2 + = (fntype)gcc_jit_result_get_code (result, "test_i386_basic_asm_2"); + CHECK_NON_NULL (test_i386_basic_asm_2); + + CHECK_VALUE (test_i386_basic_asm_2 (1), 0); + CHECK_VALUE (test_i386_basic_asm_2 (2), 1); + CHECK_VALUE (test_i386_basic_asm_2 (4), 2); + CHECK_VALUE (test_i386_basic_asm_2 (8), 3); +} + +/********************************************************************** + test_i386_basic_asm_3a/b: test of control flow: "asm goto" + **********************************************************************/ + +/* Create the equivalent of: + + int test_i386_basic_asm_3a (int p1, int p2) + { + asm goto ("btl %1, %0\n\t" + "jc %l2" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); + + return 0; + + carry: + return 1; + } + + or (the "_3b" variant) using a name rather than a number for the goto + label: + + // Quote from here in docs/topics/asm.rst: example 3b: C + asm goto ("btl %1, %0\n\t" + "jc %l[carry]" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); + // Quote up to here in docs/topics/asm.rst: example 3b: C + + This exercises control flow with an asm. */ + +static void +create_test_i386_basic_asm_3 (gcc_jit_context *ctxt, + const char *funcname, + int use_name) +{ + gcc_jit_type *int_type = gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + gcc_jit_param *p1 = gcc_jit_context_new_param (ctxt, NULL, int_type, "p1"); + gcc_jit_param *p2 = gcc_jit_context_new_param (ctxt, NULL, int_type, "p2"); + gcc_jit_param *params[2] = {p1, p2}; + gcc_jit_function *func + = gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + int_type, + funcname, + 2, params, 0); + gcc_jit_block *b_start = gcc_jit_function_new_block (func, "start"); + gcc_jit_block *b_fallthru = gcc_jit_function_new_block (func, "fallthru"); + gcc_jit_block *b_carry = gcc_jit_function_new_block (func, "carry"); + + gcc_jit_rvalue *zero + = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0); + gcc_jit_rvalue *one + = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1); + + /* Quote from here in docs/topics/asm.rst: example 3: jit. */ + const char *asm_template = + (use_name + ? /* Label referred to by name: "%l[carry]". */ + ("btl %1, %0\n\t" + "jc %l[carry]") + : /* Label referred to numerically: "%l2". */ + ("btl %1, %0\n\t" + "jc %l2")); + + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_end_with_extended_asm_goto (b_start, NULL, + asm_template, + 1, &b_carry, + b_fallthru); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_param_as_rvalue (p1)); + gcc_jit_extended_asm_add_input_operand (ext_asm, NULL, "r", + gcc_jit_param_as_rvalue (p2)); + gcc_jit_extended_asm_add_clobber (ext_asm, "cc"); + /* Quote up to here in docs/topics/asm.rst: example 3: jit. */ + + const char *desc = get_desc (ext_asm); + CHECK_STRING_VALUE + (desc, + (use_name + ? ("asm goto (\"btl %1, %0\\n\\tjc %l[carry]\" " + ": : \"r\" (p1), \"r\" (p2) : \"cc\" " + ": carry [fallthrough: fallthru])") + : ("asm goto (\"btl %1, %0\\n\\tjc %l2\" " + ": : \"r\" (p1), \"r\" (p2) : \"cc\" " + ": carry [fallthrough: fallthru])"))); + + gcc_jit_block_end_with_return (b_fallthru, NULL, zero); + gcc_jit_block_end_with_return (b_carry, NULL, one); +} + +static void +verify_code_3 (gcc_jit_context *ctxt, gcc_jit_result *result, + const char *funcname) +{ + typedef int (*test_i386_basic_asm_3_type) (int, int); + + test_i386_basic_asm_3_type test_i386_basic_asm_3 + = (test_i386_basic_asm_3_type) gcc_jit_result_get_code (result, funcname); + CHECK_NON_NULL (test_i386_basic_asm_3); + + /* The fn should test bits, returning 0 or 1. */ + /* Bit 0. */ + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, 0), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0001, 0), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0002, 0), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0003, 0), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0004, 0), 0); + /* Bit 1. */ + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, 1), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0001, 1), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0002, 1), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0003, 1), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0004, 1), 0); + + for (int i = 0; i < 15; i++) + { + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, i), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0xffff, i), 1); + } +} + +/********************************************************************** + test_i386_basic_asm_4: test of "volatile" + **********************************************************************/ + +/* Create the equivalent of: + uint64_t test_i386_basic_asm_4 (void) + { + uint64_t start_time, end_time; + + // Get start time + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (start_time) + : + : "rdx"); + + // could do other work here + + // Get end time + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (start_time) + : + : "rdx"); + + // Get elapsed time + return end_time - start_time; + } + + This exercises "volatile"; without it, the optimizer can assume that + both asm generate the same value and thus the time difference is zero. */ + +static void +add_rdtsc (gcc_jit_block *block, gcc_jit_lvalue *msr) +{ + /* Quote from here in docs/topics/asm.rst: example 4: jit. */ + gcc_jit_extended_asm *ext_asm + = gcc_jit_block_add_extended_asm + (block, NULL, + "rdtsc\n\t" /* Returns the time in EDX:EAX. */ + "shl $32, %%rdx\n\t" /* Shift the upper bits left. */ + "or %%rdx, %0"); /* 'Or' in the lower bits. */ + gcc_jit_extended_asm_set_volatile_flag (ext_asm, 1); + gcc_jit_extended_asm_add_output_operand (ext_asm, NULL, "=a", msr); + gcc_jit_extended_asm_add_clobber (ext_asm, "rdx"); + /* Quote up to here in docs/topics/asm.rst: example 4: jit. */ + + const char *desc = get_desc (ext_asm); + CHECK_STRING_STARTS_WITH (desc, "asm volatile ("); +} + +static void +create_test_i386_basic_asm_4 (gcc_jit_context *ctxt) +{ + gcc_jit_type *uint64_type = gcc_jit_context_get_int_type (ctxt, 8, 0); + gcc_jit_function *func + = gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + uint64_type, + "test_i386_basic_asm_4", + 0, NULL, 0); + gcc_jit_block *block = gcc_jit_function_new_block (func, NULL); + + gcc_jit_lvalue *start_time + = gcc_jit_function_new_local (func, NULL, uint64_type, "start_time"); + add_rdtsc (block, start_time); + + gcc_jit_block_add_comment (block, NULL, "other work here"); + + gcc_jit_lvalue *end_time + = gcc_jit_function_new_local (func, NULL, uint64_type, "end_time"); + add_rdtsc (block, end_time); + + gcc_jit_rvalue *elapsed + = gcc_jit_context_new_binary_op (ctxt, NULL, GCC_JIT_BINARY_OP_MINUS, + uint64_type, + gcc_jit_lvalue_as_rvalue (end_time), + gcc_jit_lvalue_as_rvalue (start_time)); + gcc_jit_block_end_with_return (block, NULL, elapsed); +} + +static void +verify_code_4 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef uint64_t (*fntype) (void); + fntype test_i386_basic_asm_4 + = (fntype)gcc_jit_result_get_code (result, "test_i386_basic_asm_4"); + + CHECK_NON_NULL (test_i386_basic_asm_4); + + test_i386_basic_asm_4 (); +} + +/********************************************************************** + test_i386_basic_asm_5: test of top-level asm + **********************************************************************/ + +/* Create the equivalent of: + + // Quote from here in docs/topics/asm.rst: example 5: C + asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t.popsection\n"); + // Quote up to here in docs/topics/asm.rst: example 5: C + + to add a simple function ("add_asm") directly in assembly language. */ + +static void +create_test_i386_basic_asm_5 (gcc_jit_context *ctxt) +{ + /* Quote from here in docs/topics/asm.rst: example 5: jit. */ + gcc_jit_context_add_top_level_asm (ctxt, NULL, + "\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t# some asm here\n" + "\t.popsection\n"); + /* Quote up to here in docs/topics/asm.rst: example 5: jit. */ +} + +static void +verify_code_5 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef int (*test_i386_basic_asm_5_type) (int, int); + test_i386_basic_asm_5_type test_i386_basic_asm_5 + = (test_i386_basic_asm_5_type) gcc_jit_result_get_code (result, "add_asm"); + CHECK_NON_NULL (test_i386_basic_asm_5); + + CHECK_VALUE (test_i386_basic_asm_5 (2, 2), 4); + CHECK_VALUE (test_i386_basic_asm_5 (20, 7), 27); +} + +/********************************************************************** + Code for harness + **********************************************************************/ + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + create_test_i386_basic_asm_1 (ctxt); + create_test_i386_basic_asm_2 (ctxt); + create_test_i386_basic_asm_3 (ctxt, "test_i386_basic_asm_3a", 0); + create_test_i386_basic_asm_3 (ctxt, "test_i386_basic_asm_3b", 1); + create_test_i386_basic_asm_4 (ctxt); + create_test_i386_basic_asm_5 (ctxt); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_NON_NULL (result); + verify_code_1 (ctxt, result); + verify_code_2 (ctxt, result); + verify_code_3 (ctxt, result, "test_i386_basic_asm_3a"); + verify_code_3 (ctxt, result, "test_i386_basic_asm_3b"); + verify_code_4 (ctxt, result); + verify_code_5 (ctxt, result); +} diff --git a/gcc/testsuite/jit.dg/test-asm.cc b/gcc/testsuite/jit.dg/test-asm.cc new file mode 100644 index 00000000000..6f1828060ff --- /dev/null +++ b/gcc/testsuite/jit.dg/test-asm.cc @@ -0,0 +1,453 @@ +/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ + +#include "libgccjit++.h" + +#include "harness.h" + +/********************************************************************** + Support fns for creating code. + **********************************************************************/ + +/* Make a "void FUNC_NAME (void)" function with a single block, returning + that block. */ + +static gccjit::block +make_single_block_func (gccjit::context ctxt, const char *func_name) +{ + gccjit::type void_type = ctxt.get_type (GCC_JIT_TYPE_VOID); + std::vector params; + gccjit::function func + = ctxt.new_function (GCC_JIT_FUNCTION_EXPORTED, + void_type, + func_name, params, 0); + return func.new_block ("initial"); +} + +/********************************************************************** + Support fns for verifying code. + **********************************************************************/ + +typedef void (*void_void_fn) (void); + +static void_void_fn +get_test_fn (gcc_jit_result *result, const char *func_name) +{ + return (void_void_fn)gcc_jit_result_get_code (result, func_name); +} + +/********************************************************************** + test_i386_basic_asm_1: simple example of asm + **********************************************************************/ + +/* Create the equivalent of: + + int src; + int dst; + + void test_i386_basic_asm_1 (void) + { + // Quote from here in docs/cp/topics/asm.rst: example 1: C + asm ("mov %1, %0\n\t" + "add $1, %0" + : "=r" (dst) + : "r" (src)); + // Quote up to here in docs/cp/topics/asm.rst: example 1: C + } + + i.e. copy src to dst and add 1 to dst. */ + +static void +create_test_i386_basic_asm_1 (gcc_jit_context *c_ctxt) +{ + gccjit::context ctxt (c_ctxt); + gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT); + gccjit::lvalue dst + = ctxt.new_global (GCC_JIT_GLOBAL_EXPORTED, int_type, "dst"); + gccjit::lvalue src + = ctxt.new_global (GCC_JIT_GLOBAL_EXPORTED, int_type, "src"); + + gccjit::block block + = make_single_block_func (ctxt, "test_i386_basic_asm_1"); + + gccjit::extended_asm ext_asm = + /* Quote from here in docs/cp/topics/asm.rst: example 1: jit. */ + block.add_extended_asm ("mov %1, %0\n\t" + "add $1, %0") + .add_output_operand ("=r", dst) + .add_input_operand ("r", src); + /* Quote up to here in docs/cp/topics/asm.rst: example 1: jit. */ + + std::string desc = ext_asm.get_debug_string (); + CHECK_STRING_VALUE + (desc.c_str (), + "asm (\"mov %1, %0\\n\\tadd $1, %0\" : \"=r\" (dst) : \"r\" (src) : )"); + + block.end_with_return (); +} + +static void +verify_code_1 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + void_void_fn test_i386_basic_asm_1 + = get_test_fn (result, "test_i386_basic_asm_1"); + CHECK_NON_NULL (test_i386_basic_asm_1); + + int *dst_ptr = (int *)gcc_jit_result_get_global (result, "dst"); + CHECK_NON_NULL (dst_ptr); + int *src_ptr = (int *)gcc_jit_result_get_global (result, "src"); + CHECK_NON_NULL (src_ptr); + + *src_ptr = 42; + *dst_ptr = 0; + test_i386_basic_asm_1 (); + CHECK_VALUE (*src_ptr, 42); + CHECK_VALUE (*dst_ptr, 43); +} + +/********************************************************************** + test_i386_basic_asm_2: test of symbolic names and clobbers + **********************************************************************/ + +/* Create the equivalent of: + uint32_t test_i386_basic_asm_2 (uint32_t Mask) + { + uint32_t Index; + // Quote from here in docs/cp/topics/asm.rst: example 2: C + asm ("bsfl %[aMask], %[aIndex]" + : [aIndex] "=r" (Index) + : [aMask] "r" (Mask) + : "cc"); + // Quote up to here in docs/cp/topics/asm.rst: example 2: C + return Index; + } + i.e. return the first bit set in "Mask" + + This exercises symbolic names and clobbers. */ + +static void +create_test_i386_basic_asm_2 (gcc_jit_context *c_ctxt) +{ + gccjit::context ctxt (c_ctxt); + gccjit::type uint32_type = ctxt.get_int_type (4, 0); + gccjit::param mask = ctxt.new_param (uint32_type, "Mask"); + std::vector params {mask}; + gccjit::function func = ctxt.new_function (GCC_JIT_FUNCTION_EXPORTED, + uint32_type, + "test_i386_basic_asm_2", + params, 0); + gccjit::lvalue index = func.new_local (uint32_type, "Index"); + gccjit::block block = func.new_block ("initial"); + gccjit::extended_asm ext_asm = + /* Quote from here in docs/cp/topics/asm.rst: example 2: jit. */ + block.add_extended_asm ("bsfl %[aMask], %[aIndex]") + .add_output_operand ("aIndex", "=r", index) + .add_input_operand ("aMask", "r", mask) + .add_clobber ("cc"); + /* Quote up to here in docs/cp/topics/asm.rst: example 2: jit. */ + + std::string desc = ext_asm.get_debug_string (); + CHECK_STRING_VALUE + (desc.c_str (), + "asm (\"bsfl %[aMask], %[aIndex]\"" + " : [aIndex] \"=r\" (Index) : [aMask] \"r\" (Mask) : \"cc\")"); + + block.end_with_return (index); +} + +static void +verify_code_2 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef uint32_t (*fntype) (uint32_t); + fntype test_i386_basic_asm_2 + = (fntype)gcc_jit_result_get_code (result, "test_i386_basic_asm_2"); + CHECK_NON_NULL (test_i386_basic_asm_2); + + CHECK_VALUE (test_i386_basic_asm_2 (1), 0); + CHECK_VALUE (test_i386_basic_asm_2 (2), 1); + CHECK_VALUE (test_i386_basic_asm_2 (4), 2); + CHECK_VALUE (test_i386_basic_asm_2 (8), 3); +} + +/********************************************************************** + test_i386_basic_asm_3a/b: test of control flow: "asm goto" + **********************************************************************/ + +/* Create the equivalent of: + + int test_i386_basic_asm_3a (int p1, int p2) + { + asm goto ("btl %1, %0\n\t" + "jc %l2" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); + + return 0; + + carry: + return 1; + } + + or (the "_3b" variant) using a name rather than a number for the goto + label: + + // Quote from here in docs/cp/topics/asm.rst: example 3b: C + asm goto ("btl %1, %0\n\t" + "jc %l[carry]" + : // No outputs + : "r" (p1), "r" (p2) + : "cc" + : carry); + // Quote up to here in docs/cp/topics/asm.rst: example 3b: C + + This exercises control flow with an asm. */ + +static void +create_test_i386_basic_asm_3 (gcc_jit_context *c_ctxt, + const char *funcname, + int use_name) +{ + gccjit::context ctxt (c_ctxt); + gccjit::type int_type = ctxt.get_type (GCC_JIT_TYPE_INT); + gccjit::param p1 = ctxt.new_param (int_type, "p1"); + gccjit::param p2 = ctxt.new_param (int_type, "p2"); + std::vector params ({p1, p2}); + gccjit::function func = ctxt.new_function (GCC_JIT_FUNCTION_EXPORTED, + int_type, + funcname, + params, 0); + gccjit::block b_start = func.new_block ("start"); + gccjit::block b_fallthru = func.new_block ("fallthru"); + gccjit::block b_carry = func.new_block ("carry"); + + gccjit::rvalue zero = ctxt.new_rvalue (int_type, 0); + gccjit::rvalue one = ctxt.new_rvalue (int_type, 1); + + /* Quote from here in docs/cp/topics/asm.rst: example 3: jit. */ + const char *asm_template = + (use_name + ? /* Label referred to by name: "%l[carry]". */ + ("btl %1, %0\n\t" + "jc %l[carry]") + : /* Label referred to numerically: "%l2". */ + ("btl %1, %0\n\t" + "jc %l2")); + + std::vector goto_blocks ({b_carry}); + gccjit::extended_asm ext_asm + = (b_start.end_with_extended_asm_goto (asm_template, + goto_blocks, + &b_fallthru) + .add_input_operand ("r", p1) + .add_input_operand ("r", p2) + .add_clobber ("cc")); + /* Quote up to here in docs/cp/topics/asm.rst: example 3: jit. */ + + std::string desc = ext_asm.get_debug_string (); + CHECK_STRING_VALUE + (desc.c_str (), + (use_name + ? ("asm goto (\"btl %1, %0\\n\\tjc %l[carry]\" " + ": : \"r\" (p1), \"r\" (p2) : \"cc\" " + ": carry [fallthrough: fallthru])") + : ("asm goto (\"btl %1, %0\\n\\tjc %l2\" " + ": : \"r\" (p1), \"r\" (p2) : \"cc\" " + ": carry [fallthrough: fallthru])"))); + + b_fallthru.end_with_return (zero); + b_carry.end_with_return (one); +} + +static void +verify_code_3 (gcc_jit_context *ctxt, gcc_jit_result *result, + const char *funcname) +{ + typedef int (*test_i386_basic_asm_3_type) (int, int); + + test_i386_basic_asm_3_type test_i386_basic_asm_3 + = (test_i386_basic_asm_3_type) gcc_jit_result_get_code (result, funcname); + CHECK_NON_NULL (test_i386_basic_asm_3); + + /* The fn should test bits, returning 0 or 1. */ + /* Bit 0. */ + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, 0), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0001, 0), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0002, 0), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0003, 0), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0004, 0), 0); + /* Bit 1. */ + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, 1), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0001, 1), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0x0002, 1), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0003, 1), 1); + CHECK_VALUE (test_i386_basic_asm_3 (0x0004, 1), 0); + + for (int i = 0; i < 15; i++) + { + CHECK_VALUE (test_i386_basic_asm_3 (0x0000, i), 0); + CHECK_VALUE (test_i386_basic_asm_3 (0xffff, i), 1); + } +} + +/********************************************************************** + test_i386_basic_asm_4: test of "volatile" + **********************************************************************/ + +/* Create the equivalent of: + uint64_t test_i386_basic_asm_4 (void) + { + uint64_t start_time, end_time; + + // Get start time + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (start_time) + : + : "rdx"); + + // could do other work here + + // Get end time + asm volatile ("rdtsc\n\t" // Returns the time in EDX:EAX. + "shl $32, %%rdx\n\t" // Shift the upper bits left. + "or %%rdx, %0" // 'Or' in the lower bits. + : "=a" (start_time) + : + : "rdx"); + + // Get elapsed time + return end_time - start_time; + } + + This exercises "volatile"; without it, the optimizer can assume that + both asm generate the same value and thus the time difference is zero. */ + +static void +add_rdtsc (gccjit::block block, gccjit::lvalue msr) +{ + /* Quote from here in docs/cp/topics/asm.rst: example 4: jit. */ + gccjit::extended_asm ext_asm + = block.add_extended_asm + ("rdtsc\n\t" /* Returns the time in EDX:EAX. */ + "shl $32, %%rdx\n\t" /* Shift the upper bits left. */ + "or %%rdx, %0") /* 'Or' in the lower bits. */ + .set_volatile_flag (true) + .add_output_operand ("=a", msr) + .add_clobber ("rdx"); + /* Quote up to here in docs/cp/topics/asm.rst: example 4: jit. */ + + std::string desc = ext_asm.get_debug_string (); + CHECK_STRING_STARTS_WITH (desc.c_str (), "asm volatile ("); +} + +static void +create_test_i386_basic_asm_4 (gcc_jit_context *c_ctxt) +{ + gccjit::context ctxt (c_ctxt); + gccjit::type uint64_type = ctxt.get_int_type (8, 0); + std::vector params; + gccjit::function func = ctxt.new_function (GCC_JIT_FUNCTION_EXPORTED, + uint64_type, + "test_i386_basic_asm_4", + params, 0); + gccjit::block block = func.new_block (); + + gccjit::lvalue start_time = func.new_local (uint64_type, "start_time"); + add_rdtsc (block, start_time); + + block.add_comment ("other work here"); + + gccjit::lvalue end_time = func.new_local (uint64_type, "end_time"); + add_rdtsc (block, end_time); + + block.end_with_return (end_time - start_time); +} + +static void +verify_code_4 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef uint64_t (*fntype) (void); + fntype test_i386_basic_asm_4 + = (fntype)gcc_jit_result_get_code (result, "test_i386_basic_asm_4"); + + CHECK_NON_NULL (test_i386_basic_asm_4); + + test_i386_basic_asm_4 (); +} + +/********************************************************************** + test_i386_basic_asm_5: test of top-level asm + **********************************************************************/ + +/* Create the equivalent of: + + // Quote from here in docs/cp/topics/asm.rst: example 5: C + asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t.popsection\n"); + // Quote up to here in docs/cp/topics/asm.rst: example 5: C + + to add a simple function ("add_asm") directly in assembly language. */ + +static void +create_test_i386_basic_asm_5 (gcc_jit_context *c_ctxt) +{ + gccjit::context ctxt (c_ctxt); + /* Quote from here in docs/cp/topics/asm.rst: example 5: jit. */ + ctxt.add_top_level_asm ("\t.pushsection .text\n" + "\t.globl add_asm\n" + "\t.type add_asm, @function\n" + "add_asm:\n" + "\tmovq %rdi, %rax\n" + "\tadd %rsi, %rax\n" + "\tret\n" + "\t# some asm here\n" + "\t.popsection\n"); + /* Quote up to here in docs/cp/topics/asm.rst: example 5: jit. */ +} + +static void +verify_code_5 (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + typedef int (*test_i386_basic_asm_5_type) (int, int); + test_i386_basic_asm_5_type test_i386_basic_asm_5 + = (test_i386_basic_asm_5_type) gcc_jit_result_get_code (result, "add_asm"); + CHECK_NON_NULL (test_i386_basic_asm_5); + + CHECK_VALUE (test_i386_basic_asm_5 (2, 2), 4); + CHECK_VALUE (test_i386_basic_asm_5 (20, 7), 27); +} + +/********************************************************************** + Code for harness + **********************************************************************/ + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + create_test_i386_basic_asm_1 (ctxt); + create_test_i386_basic_asm_2 (ctxt); + create_test_i386_basic_asm_3 (ctxt, "test_i386_basic_asm_3a", 0); + create_test_i386_basic_asm_3 (ctxt, "test_i386_basic_asm_3b", 1); + create_test_i386_basic_asm_4 (ctxt); + create_test_i386_basic_asm_5 (ctxt); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_NON_NULL (result); + verify_code_1 (ctxt, result); + verify_code_2 (ctxt, result); + verify_code_3 (ctxt, result, "test_i386_basic_asm_3a"); + verify_code_3 (ctxt, result, "test_i386_basic_asm_3b"); + verify_code_4 (ctxt, result); + verify_code_5 (ctxt, result); +} -- 2.30.2