On 9/22/26 3:33 AM, [email protected] wrote:
From: Kyrylo Tkachov <[email protected]>

AArch64 addr_diff_vec entries are relative to a synthetic text label.  The
casesi output sequence currently defines that label at each dispatch.  If
several dispatches share one table, they define the same assembler symbol more
than once.

The base label belongs to the table:

   dispatch A --\
   dispatch B ----> .LrtxN: -> table N
   dispatch C --/

Add TARGET_ASM_JUMP_TABLE_BASE and call it once while final still has the
function section selected.  Add TARGET_CAN_SHARE_JUMP_TABLE_P to decide
whether a tablejump can share its table before duplication.  Its default
returns whether the output hook is defined.  Targets can override it to
inspect the instruction form and current function's options.  Accepted forms
must reach the shared table without using their own jump address as the
table-entry base.  Output and late verification do not query this predicate.

Preserve the existing AArch64 path for an unshared table.  Its casesi output
still defines the base label and uses ADR.  Once a table is shared, the hook
emits the base label and each dispatch refers to it.  Shared copies can be more
than ADR's range from the base label, so use ADRP and ADD outside the tiny code
model and account for the extra instruction in the length attribute.

Other targets remain disabled because they do not define the hook.

gcc/ChangeLog:

        PR middle-end/126236
        * target.def (asm_out.jump_table_base): New hook.
        (can_share_jump_table_p): Likewise.
        * targhooks.cc (default_can_share_jump_table_p): New function.
        * targhooks.h (default_can_share_jump_table_p): Declare.
        * doc/tm.texi.in: Document the hooks.
        * doc/tm.texi: Regenerate.
        * final.cc (final_scan_insn_1): Call the jump-table base hook before
        switching away from the function section or invoking target table
        output.
        * config/aarch64/aarch64.cc (aarch64_far_jump_table_base_p): New
        function.
        (aarch64_output_casesi): Emit the base label here for an unshared
        table.  Use ADRP and ADD for a shared table outside the tiny code
        model.
        (aarch64_casesi_far_base_p): New function.
        (aarch64_asm_jump_table_base): New function.
        (TARGET_ASM_JUMP_TABLE_BASE): Define.
        * config/aarch64/aarch64-protos.h (aarch64_casesi_far_base_p):
        Declare.
        * config/aarch64/aarch64.md (length): Account for the longer base
        sequence.

Signed-off-by: Kyrylo Tkachov <[email protected]>
Generic bits look sensible to me.  Not totally surprised we need a label like this and I can almost see a path to make this scheme work everywhere.

Jeff

Reply via email to