TLDR: Request for indirect jump exposure in api, with required target
lists to make control flow easy.

Hi all,

I am currently working on a language compiler backend targeting libgccjit
and ran into a limitation regarding low-level control flow primitives:
the lack of support for indirect branches (computed gotos).

While dense switch statements can often be lowered to jump tables, doing
so routes execution through a single centralized dispatch point. In
interpreter dispatch loops and state machines, this introduces branch
target buffer aliasing and prediction penalties compared to direct
threading, where each instruction handler site ends with its own indirect
jump.

Beyond interpreter loops, having first-class indirect jumps avoids
impedance mismatches when lowering language-level computed gotos or
arbitrary CFGs, matching what GNU C (&&label / goto *expr) and LLVM IR
(indirectbr) already provides.

To support this cleanly without overcomplicating the existing API, I would
like to propose exposing two core primitives:

1. Extracting the code address of a basic block as a void* rvalue:

   gcc_jit_rvalue *
   gcc_jit_block_get_address (gcc_jit_block *block,
                              gcc_jit_location *loc);

2. Terminating a block with an indirect jump to a dynamic pointer,
   explicitly passing possible targets to preserve CFG edges and prevent
   dead-code elimination:

   void
   gcc_jit_block_end_with_indirect_jump (gcc_jit_block *block,
                                         gcc_jit_location *loc,
                                         gcc_jit_rvalue *target_ptr,
                                         int num_possible_targets,
                                         gcc_jit_block **possible_targets);

Since GCC's middle-end already supports LABEL_EXPR, ADDR_EXPR, and GIMPLE_GOTO
with forced labels, this primarily involves plumbing the libgccjit C API
and constructing the appropriate CFG edges during compilation.

Does this API surface look reasonable, and would a patch along these lines
be welcome for the current development cycle?

Thanks,
m4rn-progs

Reply via email to