diff options
author | David Malcolm <dmalcolm@redhat.com> | 2015-06-30 20:39:50 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2015-06-30 20:39:50 +0000 |
commit | ec5d0088148d1d6218f5f503d1c8e67a529dfacd (patch) | |
tree | c7cf3f33890bd8579a8afa8a850a326bc0b1fd58 /gcc/jit/libgccjit.h | |
parent | 6a3603e356e14096e9554ceef57916fd03d9072b (diff) | |
download | gcc-ec5d0088148d1d6218f5f503d1c8e67a529dfacd.zip gcc-ec5d0088148d1d6218f5f503d1c8e67a529dfacd.tar.gz gcc-ec5d0088148d1d6218f5f503d1c8e67a529dfacd.tar.bz2 |
jit: add switch statements
gcc/ChangeLog:
* typed-splay-tree.h: New file.
gcc/jit/ChangeLog:
* docs/cp/topics/functions.rst (Blocks): Add switch statements to
list of ways to terminate a block.
(gccjit::block::end_with_switch): Add function description.
(gccjit::case_): Add class.
(gccjit::context::new_case): Add function description.
* docs/cp/topics/objects.rst: Add "case_" to class hierarchy.
* docs/topics/compatibility.rst (LIBGCCJIT_ABI_3): New.
* docs/topics/functions.rst (Blocks): Add switch statements to
list of ways to terminate a block.
(gcc_jit_block_end_with_switch): Add function description.
(gcc_jit_case): Add type.
(gcc_jit_context_new_case): Add function description.
(gcc_jit_case_as_object): Add function description.
* docs/topics/objects.rst: Add gcc_jit_case to class hierarchy.
* docs/_build/texinfo/libgccjit.texi: Regenerate.
* jit-common.h (gcc::jit::recording::case_): Add forward decl.
(gcc::jit::playback::case_): Add forward decl.
* jit-playback.c (add_case): New function.
(gcc::jit::playback::block::add_switch): New function.
* jit-playback.h (gcc::jit::playback::case_): New struct.
(gcc::jit::playback::block::get_function): New method.
(gcc::jit::playback::block::add_switch): New method.
* jit-recording.c: Within namespace gcc::jit...
(recording::context::new_case): New method.
(recording::function::validate): Update for change to
get_successor_blocks.
(recording::block::end_with_switch): New method.
(recording::block::get_successor_blocks): Update to support an
arbitrary number of successor blocks.
(recording::block::dump_edges_to_dot): Likewise.
(memento_of_new_rvalue_from_const <int>::get_wide_int): New.
(memento_of_new_rvalue_from_const <long>::get_wide_int): New.
(memento_of_new_rvalue_from_const <double>::get_wide_int): New.
(memento_of_new_rvalue_from_const <void *>::get_wide_int): New.
(recording::statement::get_successor_blocks): Update to support an
arbitrary number of successor blocks.
(recording::conditional::get_successor_blocks): Likewise.
(recording::jump::get_successor_blocks): Likewise.
(recording::return_::get_successor_blocks): Likewise.
(recording::case_::write_reproducer): New.
(recording::case_::make_debug_string): New.
(recording::switch_::switch_): New.
(recording::switch_::replay_into): New.
(recording::switch_::get_successor_blocks): New.
(recording::switch_::make_debug_string): New.
(recording::switch_::write_reproducer): New.
* jit-recording.h: Within namespace gcc::jit::recording...
(context::new_case): New.
(rvalue::is_constant): New.
(rvalue::get_wide_int): New.
(block::end_with_switch): New.
(block::get_successor_blocks): Update to support an arbitrary
number of successor blocks.
(memento_of_new_rvalue_from_const::is_constant): New.
(memento_of_new_rvalue_from_const::get_wide_int): New.
(statement::get_successor_blocks): Update to support an arbitrary
number of successor blocks.
(conditional::get_successor_blocks): Likewise.
(jump::get_successor_blocks): Likewise.
(return_::get_successor_blocks): Likewise.
(case_): New subclass of memento.
(switch_): New subclass of statement.
* libgccjit++.h (gccjit::case_): New subclass of gccjit::object.
(gccjit::context::new_case): New method.
(gccjit::block::end_with_switch): New method.
(gccjit::case_::case): New ctors.
(gccjit::case_::get_inner_case): New method.
* libgccjit.c: Include "typed-splay-tree.h"
(struct gcc_jit_case): New.
(gcc_jit_context_new_case): New function.
(gcc_jit_case_as_object): New function.
(valid_dest_for_switch): New function.
(valid_case_for_switch): New function.
(class api_call_validator): New class.
(class case_range_validator): New class.
(case_range_validator::case_range_validator): New.
(case_range_validator::validate): New.
(case_range_validator::case_compare): New.
(case_range_validator::get_wide_int): new.
(gcc_jit_block_end_with_switch): New.
* libgccjit.h: Add gcc_jit_case to class hierarchy comment.
(gcc_jit_case): New typedef.
(gcc_jit_context_new_case): New function.
(gcc_jit_case_as_object): New function.
(gcc_jit_block_end_with_switch): New function.
(LIBGCCJIT_HAVE_SWITCH_STATEMENTS): New.
* libgccjit.map: Add gcc_jit_block_end_with_switch,
gcc_jit_case_as_object and gcc_jit_context_new_case.
gcc/testsuite/ChangeLog:
* jit.dg/all-non-failing-tests.h: Add test-switch.c.
* jit.dg/test-error-gcc_jit_block_end_with_switch-NULL-case.c: New
testcase.
* jit.dg/test-error-gcc_jit_block_end_with_switch-mismatching-case-type.c:
New testcase.
* jit.dg/test-error-gcc_jit_block_end_with_switch-overlapping-ranges.c:
New testcase.
* jit.dg/test-error-gcc_jit_context_new_case-non-const-label.c:
New testcase.
* jit.dg/test-error-gcc_jit_context_new_case-non-integer-type.c:
New testcase.
* jit.dg/test-error-gcc_jit_context_new_case-reversed-endpoints.c:
New testcase.
* jit.dg/test-switch.c: New testcase.
* jit.dg/test-switch.cc: New testcase.
From-SVN: r225207
Diffstat (limited to 'gcc/jit/libgccjit.h')
-rw-r--r-- | gcc/jit/libgccjit.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index e33900c..32f2a5d 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -67,6 +67,7 @@ typedef struct gcc_jit_result gcc_jit_result; +- gcc_jit_rvalue +- gcc_jit_lvalue +- gcc_jit_param + +- gcc_jit_case */ typedef struct gcc_jit_object gcc_jit_object; @@ -131,6 +132,12 @@ typedef struct gcc_jit_lvalue gcc_jit_lvalue; rvalue); use gcc_jit_param_as_lvalue to convert. */ typedef struct gcc_jit_param gcc_jit_param; +/* A gcc_jit_case is for use when building multiway branches via + gcc_jit_block_end_with_switch and represents a range of integer + values (or an individual integer value) together with an associated + destination block. */ +typedef struct gcc_jit_case gcc_jit_case; + /* Acquire a JIT-compilation context. */ extern gcc_jit_context * gcc_jit_context_acquire (void); @@ -1097,6 +1104,81 @@ extern void gcc_jit_block_end_with_void_return (gcc_jit_block *block, gcc_jit_location *loc); +/* Create a new gcc_jit_case instance for use in a switch statement. + min_value and max_value must be constants of integer type. + + This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS +*/ +extern gcc_jit_case * +gcc_jit_context_new_case (gcc_jit_context *ctxt, + gcc_jit_rvalue *min_value, + gcc_jit_rvalue *max_value, + gcc_jit_block *dest_block); + +/* Upcasting from case to object. + + This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS +*/ + +extern gcc_jit_object * +gcc_jit_case_as_object (gcc_jit_case *case_); + +/* Terminate a block by adding evalation of an rvalue, then performing + a multiway branch. + + This is roughly equivalent to this C code: + + switch (expr) + { + default: + goto default_block; + + case C0.min_value ... C0.max_value: + goto C0.dest_block; + + case C1.min_value ... C1.max_value: + goto C1.dest_block; + + ...etc... + + case C[N - 1].min_value ... C[N - 1].max_value: + goto C[N - 1].dest_block; + } + + block, expr, default_block and cases must all be non-NULL. + + expr must be of the same integer type as all of the min_value + and max_value within the cases. + + num_cases must be >= 0. + + The ranges of the cases must not overlap (or have duplicate + values). + + This API entrypoint was added in LIBGCCJIT_ABI_3; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_SWITCH_STATEMENTS +*/ + +extern void +gcc_jit_block_end_with_switch (gcc_jit_block *block, + gcc_jit_location *loc, + gcc_jit_rvalue *expr, + gcc_jit_block *default_block, + int num_cases, + gcc_jit_case **cases); + +/* Pre-canned feature macro to indicate the presence of + gcc_jit_block_end_with_switch, gcc_jit_case_as_object, and + gcc_jit_context_new_case. + + This can be tested for with #ifdef. */ +#define LIBGCCJIT_HAVE_SWITCH_STATEMENTS + /********************************************************************** Nested contexts. **********************************************************************/ |