Backthreader refactors candidate work out of adjust_paths_after_duplication.
Refactors backthreader code to separate candidate finding from adjustment, improving clarity and removing spaghetti code.
This commit restructures the adjust_paths_after_duplication function in the backthreader to separate the process of finding candidate paths from the process of adjusting them. The per-candidate work is moved into a new adjust_one_path function, simplifying the control flow, removing the use of goto, and making the logic for rewiring candidates clearer.
In Details
This patch refactors back_jt_path_registry::adjust_paths_after_duplication by extracting the per-candidate adjustment logic into adjust_one_path. Previously, the search for candidates and their adjustment were interleaved, using a goto statement. This change separates concerns, leading to cleaner code and a more straightforward understanding of when rewiring occurs, based on the mismatch index relative to the candidate's length.
- backthreader
- A GCC pass that optimizes control flow by identifying and threading common execution paths, aiming to reduce execution time and improve instruction cache locality.
- adjust_paths_after_duplication
- A function within the GCC backthreader that processes and adjusts paths after a duplication event, aiming to optimize control flow.
- goto
- A control flow statement that transfers program execution directly to another specified point in the code, often used to break out of nested loops or handle complex error conditions. Its overuse can lead to 'spaghetti code,' making it hard to follow.