Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions gcc/jit/libgccjit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3294,6 +3294,63 @@ gcc_jit_blocks_clone (int num_blocks,
reinterpret_cast<gcc::jit::recording::block **> (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 <gcc::jit::recording::block *> 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 <gcc::jit::recording::block *> 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 <gcc_jit_block *> (successor);
}

/* Public entrypoint. See description in libgccjit.h.

Expand Down
21 changes: 21 additions & 0 deletions gcc/jit/libgccjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 6 additions & 0 deletions gcc/jit/libgccjit.map
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Loading