Ignore leading debug instructions for AArch64 and RISC-V
Ensures that debug instructions at the start of functions are ignored by RTL generation for AArch64 and RISC-V.
Functions like rest_of_insert_bti and riscv_mode_needed in the AArch64 and RISC-V backends previously could incorrectly consider leading DEBUG_INSNs when determining the first executable instruction. This commit introduces get_first_nonnote_nondebug_insn to reliably find the first actual instruction. This prevents redundant BTI C insertions on AArch64 and ensures correct hoisting of VXRM settings on RISC-V, which were previously hindered by debug directives.
In Details
The functions rest_of_insert_bti (in config/arm/aarch-bti-insert.cc) and riscv_mode_needed (in config/riscv/riscv.cc) require identifying the first executable instruction in a function. The existing get_first_nonnote_insn could return a DEBUG_INSN, leading to incorrect decisions. A new function, get_first_nonnote_nondebug_insn, is introduced in emit-rtl.cc and used at both sites. This ensures that only actual code instructions are considered, preventing issues like redundant PACIASP barriers on AArch64 and incorrect VXRM hoisting on RISC-V.
- RTL
- Register Transfer Language, an intermediate representation used internally by GCC.
- AArch64
- The 64-bit ARM architecture.
- RISC-V
- An open-standard instruction set architecture (ISA) based on Reduced Instruction Set Computer principles.
- DEBUG_INSN
- An RTL construct representing a debug-related instruction, which should typically be ignored during code generation optimization.
- BTI C
- Branch Target Identification, a security feature on some architectures (like ARMv8.3-A) that helps mitigate Return-Oriented Programming (ROP) attacks. 'BTI C' likely refers to a specific type of BTI instruction.
- PACIASP
- Pointer Authentication for Authenticated Stack Pointer, a security feature on ARM architectures that protects the stack pointer against tampering.
- VXRM
- Vector Register Mask, likely a control register on RISC-V used to manage vector operations or masks.