Skip to content

Commit 6b71705

Browse files
committed
libgccjit: Add a way to get successor blocks
1 parent a432666 commit 6b71705

3 files changed

Lines changed: 84 additions & 0 deletions

File tree

gcc/jit/libgccjit.cc

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3294,6 +3294,63 @@ gcc_jit_blocks_clone (int num_blocks,
32943294
reinterpret_cast<gcc::jit::recording::block **> (out_clones));
32953295
}
32963296

3297+
/* Public entrypoint. See description in libgccjit.h.
3298+
3299+
After error-checking, the real work is done by the
3300+
gcc::jit::recording::block::get_successor_blocks method in
3301+
jit-recording.cc. */
3302+
3303+
int
3304+
gcc_jit_block_get_successor_count (gcc_jit_block *block)
3305+
{
3306+
RETURN_VAL_IF_FAIL (block, 0, NULL, NULL, "NULL block");
3307+
gcc::jit::recording::context *ctxt = block->get_context ();
3308+
JIT_LOG_FUNC (ctxt->get_logger ());
3309+
3310+
/* An unterminated block has no successors. */
3311+
if (!block->has_been_terminated ())
3312+
return 0;
3313+
3314+
vec <gcc::jit::recording::block *> successors
3315+
= block->get_successor_blocks ();
3316+
int num_successors = successors.length ();
3317+
successors.release ();
3318+
return num_successors;
3319+
}
3320+
3321+
/* Public entrypoint. See description in libgccjit.h.
3322+
3323+
After error-checking, the real work is done by the
3324+
gcc::jit::recording::block::get_successor_blocks method in
3325+
jit-recording.cc. */
3326+
3327+
gcc_jit_block *
3328+
gcc_jit_block_get_successor (gcc_jit_block *block, int index)
3329+
{
3330+
RETURN_NULL_IF_FAIL (block, NULL, NULL, "NULL block");
3331+
gcc::jit::recording::context *ctxt = block->get_context ();
3332+
JIT_LOG_FUNC (ctxt->get_logger ());
3333+
RETURN_NULL_IF_FAIL_PRINTF1 (
3334+
block->has_been_terminated (), ctxt, NULL,
3335+
"block %s has not been terminated, so it has no successors",
3336+
block->get_debug_string ());
3337+
3338+
vec <gcc::jit::recording::block *> successors
3339+
= block->get_successor_blocks ();
3340+
gcc::jit::recording::block *successor = NULL;
3341+
bool valid_index = index >= 0 && index < (int) successors.length ();
3342+
if (valid_index)
3343+
successor = successors[index];
3344+
int num_successors = successors.length ();
3345+
successors.release ();
3346+
3347+
RETURN_NULL_IF_FAIL_PRINTF3 (
3348+
valid_index, ctxt, NULL,
3349+
"index %i is out of range for block %s, which has %i successors",
3350+
index, block->get_debug_string (), num_successors);
3351+
3352+
return static_cast <gcc_jit_block *> (successor);
3353+
}
32973354

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

gcc/jit/libgccjit.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,27 @@ gcc_jit_block_add_cleanup (gcc_jit_block *block,
16391639

16401640
#define LIBGCCJIT_HAVE_gcc_jit_block_add_cleanup
16411641

1642+
/* Get the number of successor blocks.
1643+
1644+
This API entrypoint was added in LIBGCCJIT_ABI_55; you can test for its
1645+
presence using
1646+
#ifdef LIBGCCJIT_HAVE_gcc_jit_block_get_successor
1647+
*/
1648+
extern int
1649+
gcc_jit_block_get_successor_count (gcc_jit_block *block);
1650+
1651+
/* Get one of the successor blocks.
1652+
1653+
This API entrypoint was added in LIBGCCJIT_ABI_55; you can test for its
1654+
presence using
1655+
#ifdef LIBGCCJIT_HAVE_gcc_jit_block_get_successor
1656+
*/
1657+
extern gcc_jit_block *
1658+
gcc_jit_block_get_successor (gcc_jit_block *block,
1659+
int index);
1660+
1661+
#define LIBGCCJIT_HAVE_gcc_jit_block_get_successor
1662+
16421663
/* Add evaluation of an rvalue, assigning the result to the given
16431664
lvalue.
16441665

gcc/jit/libgccjit.map

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,9 @@ LIBGCCJIT_ABI_54 {
440440
gcc_jit_type_add_attribute;
441441
gcc_jit_type_add_integer_attribute;
442442
} LIBGCCJIT_ABI_53;
443+
444+
LIBGCCJIT_ABI_55 {
445+
global:
446+
gcc_jit_block_get_successor_count;
447+
gcc_jit_block_get_successor;
448+
} LIBGCCJIT_ABI_54;

0 commit comments

Comments
 (0)