Optimize Xtensa assembler branch target checking
Xtensa assembler performance improved by optimizing branch target checks, reducing assembly time from 20 mins to 1 second.
Assembly time for gcc.c-torture/compile/limits-externalid on Xtensa has been drastically reduced from approximately 20 minutes to 1 second. This is achieved by optimizing the next_frag_is_branch_target function to avoid redundant checks and by modifying xtensa_fix_target_frags to process a range of frags only once.
In Details
The next_frag_is_branch_target function in tc-xtensa.c is modified to accept a valid_until parameter, returning the end of the frag range checked. The caller, xtensa_fix_target_frags, now uses this to avoid re-scanning the same frag ranges, changing the complexity from O(N^2) to O(N) for this operation, thus fixing a performance regression.
- Gas
- The GNU Assembler, part of the GNU Binutils package. It translates assembly language code into machine code.
- Xtensa
- A configurable microprocessor architecture commonly used in embedded systems and System-on-Chips (SoCs).
- frag
- A 'fragment', a unit of memory or code that the assembler manages during the assembly process.
- branch target
- A location in the code that a branch instruction can jump to. The assembler needs to identify these for correct relocation and code generation.