refactor(recompiler): share the control flow helpers #1493

Merged
LeandroLP23 merged 1 commit from upstream-pr/1493 into main 2026-10-10 01:03:41 +00:00
LeandroLP23 commented 2026-10-08 09:09:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-08T09:09:30Z.


What

Eight helpers were defined with identical bodies in the anonymous namespaces of two of the three control flow sources:

Helper Copies
addUnique, sortUnique, remapId, remapIds, rebuildPredecessors GraphBuilder.cpp, Structurizer.cpp
contains, intersectSorted ControlFlowGraph.cpp, Structurizer.cpp
toHexString ControlFlowGraph.cpp, GraphBuilder.cpp
  • They are declared in a new ControlFlow/ControlFlowHelpers.hpp and defined once in ControlFlowGraph.cpp; bodies are unchanged
  • Only ControlFlowGraph.cpp, GraphBuilder.cpp and Structurizer.cpp include the header. It is not added to ControlFlowGraph.hpp, which eight recompiler sources include, since generic names such as contains would then meet the helpers and calls of that name in other components
  • RdnaDecoder keeps its own toHexString, which is in an anonymous namespace and does not clash

No behaviour change.

Tested

Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with BUILD_TESTING=ON. No title or homebrew.

  • The removed text in each file was checked to be exactly the moved body; each helper had exactly two copies.
  • Full build, no new warnings.
  • Full ctest on an AMD Radeon 860M, main ac951f8d: 425/426 passed; the failure is #825 (agc_driver_vopc_compare_table, fixed by #1473), which also fails on unmodified main on this GPU.
  • Full ctest on lavapipe (Mesa 26.2.4, selected with VK_DRIVER_FILES), before the rebase onto ac951f8d: 424/424 passed, 22 skipped for its 8-lane subgroups.
  • The two open PRs that touch these files, #1217 and #1306 (GraphBuilder.cpp), merge without conflicts with this change. No open PR adds its own copy of these helpers.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4784466005 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1493). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-08T09:09:30Z. --- ### What Eight helpers were defined with identical bodies in the anonymous namespaces of two of the three control flow sources: | Helper | Copies | |---|---| | `addUnique`, `sortUnique`, `remapId`, `remapIds`, `rebuildPredecessors` | `GraphBuilder.cpp`, `Structurizer.cpp` | | `contains`, `intersectSorted` | `ControlFlowGraph.cpp`, `Structurizer.cpp` | | `toHexString` | `ControlFlowGraph.cpp`, `GraphBuilder.cpp` | - They are declared in a new `ControlFlow/ControlFlowHelpers.hpp` and defined once in `ControlFlowGraph.cpp`; bodies are unchanged - Only `ControlFlowGraph.cpp`, `GraphBuilder.cpp` and `Structurizer.cpp` include the header. It is not added to `ControlFlowGraph.hpp`, which eight recompiler sources include, since generic names such as `contains` would then meet the helpers and calls of that name in other components - `RdnaDecoder` keeps its own `toHexString`, which is in an anonymous namespace and does not clash No behaviour change. ### Tested Windows 11, MinGW-w64 GCC 15.2.0 (WinLibs r7), Release with `BUILD_TESTING=ON`. No title or homebrew. - The removed text in each file was checked to be exactly the moved body; each helper had exactly two copies. - Full build, no new warnings. - Full `ctest` on an AMD Radeon 860M, `main` ac951f8d: 425/426 passed; the failure is #825 (`agc_driver_vopc_compare_table`, fixed by #1473), which also fails on unmodified `main` on this GPU. - Full `ctest` on lavapipe (Mesa 26.2.4, selected with `VK_DRIVER_FILES`), before the rebase onto ac951f8d: 424/424 passed, 22 skipped for its 8-lane subgroups. - The two open PRs that touch these files, #1217 and #1306 (`GraphBuilder.cpp`), merge without conflicts with this change. No open PR adds its own copy of these helpers. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
klosixgaming-arch commented 2026-10-08 11:31:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:31:47Z.

Review: APPROVED


Good refactoring that extracts common control flow helper functions into a dedicated header file. This eliminates code duplication across GraphBuilder.cpp, Structurizer.cpp, and ControlFlowGraph.cpp.

Strengths:

  • Clean separation of concerns with dedicated helper functions (toHexString, contains, intersectSorted, addUnique, sortUnique, remapId, remapIds, rebuildPredecessors)
  • Proper use of existing standard library algorithms
  • No behavioral changes, just code organization improvement
  • Good header file design with appropriate includes

This will improve code maintainability by centralizing common control flow utilities. Ready to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5455883136 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1493#pullrequestreview-5455883136). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:31:47Z. **Review:** APPROVED --- Good refactoring that extracts common control flow helper functions into a dedicated header file. This eliminates code duplication across GraphBuilder.cpp, Structurizer.cpp, and ControlFlowGraph.cpp. **Strengths:** - Clean separation of concerns with dedicated helper functions (toHexString, contains, intersectSorted, addUnique, sortUnique, remapId, remapIds, rebuildPredecessors) - Proper use of existing standard library algorithms - No behavioral changes, just code organization improvement - Good header file design with appropriate includes This will improve code maintainability by centralizing common control flow utilities. Ready to merge.
adriadam10 commented 2026-10-10 01:03:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T01:03:38Z.


Checked that every removed body is identical to the moved one, only the three control flow sources include the new header, and there is no behaviour change. Built on top of current main and ran the AGC/AgcDriver ctest set on Linux: all green. Merges cleanly with #2276, #2257, #2201, #2105 and #1836; CI is green on the head. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6091954312 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1493#issuecomment-6091954312). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T01:03:38Z. --- Checked that every removed body is identical to the moved one, only the three control flow sources include the new header, and there is no behaviour change. Built on top of current `main` and ran the AGC/AgcDriver ctest set on Linux: all green. Merges cleanly with #2276, #2257, #2201, #2105 and #1836; CI is green on the head. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1493
No description provided.