diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index e9551d428faf2..ded67fdd58377 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -3294,6 +3294,63 @@ gcc_jit_blocks_clone (int num_blocks, reinterpret_cast (out_clones)); } +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::block::get_successor_blocks method in + jit-recording.cc. */ + +int +gcc_jit_block_get_successor_count (gcc_jit_block *block) +{ + RETURN_VAL_IF_FAIL (block, 0, NULL, NULL, "NULL block"); + gcc::jit::recording::context *ctxt = block->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + + /* An unterminated block has no successors. */ + if (!block->has_been_terminated ()) + return 0; + + vec successors + = block->get_successor_blocks (); + int num_successors = successors.length (); + successors.release (); + return num_successors; +} + +/* Public entrypoint. See description in libgccjit.h. + + After error-checking, the real work is done by the + gcc::jit::recording::block::get_successor_blocks method in + jit-recording.cc. */ + +gcc_jit_block * +gcc_jit_block_get_successor (gcc_jit_block *block, int index) +{ + RETURN_NULL_IF_FAIL (block, NULL, NULL, "NULL block"); + gcc::jit::recording::context *ctxt = block->get_context (); + JIT_LOG_FUNC (ctxt->get_logger ()); + RETURN_NULL_IF_FAIL_PRINTF1 ( + block->has_been_terminated (), ctxt, NULL, + "block %s has not been terminated, so it has no successors", + block->get_debug_string ()); + + vec successors + = block->get_successor_blocks (); + gcc::jit::recording::block *successor = NULL; + bool valid_index = index >= 0 && index < (int) successors.length (); + if (valid_index) + successor = successors[index]; + int num_successors = successors.length (); + successors.release (); + + RETURN_NULL_IF_FAIL_PRINTF3 ( + valid_index, ctxt, NULL, + "index %i is out of range for block %s, which has %i successors", + index, block->get_debug_string (), num_successors); + + return static_cast (successor); +} /* Public entrypoint. See description in libgccjit.h. diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h index 8e1b9259d4b61..404b3bd28807e 100644 --- a/gcc/jit/libgccjit.h +++ b/gcc/jit/libgccjit.h @@ -1639,6 +1639,27 @@ gcc_jit_block_add_cleanup (gcc_jit_block *block, #define LIBGCCJIT_HAVE_gcc_jit_block_add_cleanup +/* Get the number of successor blocks. + + This API entrypoint was added in LIBGCCJIT_ABI_55; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_gcc_jit_block_get_successor +*/ +extern int +gcc_jit_block_get_successor_count (gcc_jit_block *block); + +/* Get one of the successor blocks. + + This API entrypoint was added in LIBGCCJIT_ABI_55; you can test for its + presence using + #ifdef LIBGCCJIT_HAVE_gcc_jit_block_get_successor +*/ +extern gcc_jit_block * +gcc_jit_block_get_successor (gcc_jit_block *block, + int index); + +#define LIBGCCJIT_HAVE_gcc_jit_block_get_successor + /* Add evaluation of an rvalue, assigning the result to the given lvalue. diff --git a/gcc/jit/libgccjit.map b/gcc/jit/libgccjit.map index 6d70f6844da37..ae383d92b8a5a 100644 --- a/gcc/jit/libgccjit.map +++ b/gcc/jit/libgccjit.map @@ -440,3 +440,9 @@ LIBGCCJIT_ABI_54 { gcc_jit_type_add_attribute; gcc_jit_type_add_integer_attribute; } LIBGCCJIT_ABI_53; + +LIBGCCJIT_ABI_55 { + global: + gcc_jit_block_get_successor_count; + gcc_jit_block_get_successor; +} LIBGCCJIT_ABI_54;