feat(aot): add opt-in LLVM integer leaf compiler #9776
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9776"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Xx-LiDAF-xX on 2026-10-22T14:34:05Z.
What
An opt-in experimental compiler for one named, sized x86-64 ELF integer leaf function. It uses LLVM 20.1.5 from the pinned source submodule to verify IR and emit native x86-64 ELF, COFF or Mach-O objects and assembly. The input contract is zero to six
uint64_tSystem V arguments and auint64_tresult. Unsupported instructions, memory, control flow, relocations and undeclared inputs fail explicitly. The old placeholder backend and unrelated runtime/I/O/graphics additions are removed.This PR is held as a draft pending a genuine in-tree consumer, as noted in the October 27 review and November 14 review:
ANYPS5_BUILD_AOTdefaults to OFF in every root build configuration.ONexplicitly enables it; existing CMake caches retain their prior value. BUILD documents this and the LLVM fetch cost.update = nonein.gitmodules. The normal recursive initialization skips it. Opt-in requiresgit submodule update --init --checkout 3rdparty/llvm-project; the explicit--checkoutoverrides the configured skip. Naming the path alone does not. Existing local Git update settings take precedence.--output,--emit-asm,--emit-llvm) are now staged to temporary files on disk and checked for case-insensitive path collisions before any destination path is replaced, with RAII cleanup of all staged.tmpfiles if any write or validation step fails.main(96dddbe61d).Depends on: #5021.Depends onis nownone. #1835 remains open as an architecture discussion thread, not an implementation to merge.LLVM fetch cost: the measured pinned working tree contains 154,024 files, 1,785,225,413 bytes (1.66 GiB), excluding Git metadata. The local shallow checkout also has 396.50 MiB of Git pack data. These are logical local sizes, not measured network-transfer or filesystem-allocation sizes. The full-build
git submodule update --init --recursivecommand skips LLVM by default, so these costs are opt-in. Existing local Git configuration may override the default.Measured fresh-directory source-build cost on the Windows machine below: configuration took 39.27 seconds. The eight-worker build ran 697.41 seconds (11m 37s) before compiler processes ran out of memory while root build/test validation was also running. A two-worker retry was interrupted before its completion timer was recorded. Resuming the remaining 195 steps with two workers then completed successfully in 607.08 seconds (10m 7s). These are separate observed phases, not a clean end-to-end benchmark; total uninterrupted clean-build time is unavailable. LLVM compilation adds no build work when AOT is OFF. The documented opt-in example uses two workers.
Tested
November 22 rebase validation (
5cd81c31cb9025423954d24bea54934b50c13bafon upstream96dddbe61db803ce7e3a0b538b203c3286f7a72d), same Windows 11 machine, WinLibs GCC 15.2.0:docs/dev/BUILD.md: kept upstream's newtools/relinker_seed_manifest.pyparagraph and placed the leaf-compiler section after it. Compiler sources are unchanged by the rebase.aot_leaf_rejectnow printsSkipped aliased-output rejection: the filesystem is case-sensitivewhen the case-alias check cannot run (5cd81c31cb).build-leaf,ANYPS5_RELINKER_ONLY=ON,ANYPS5_BUILD_AOT=ON, fresh LLVM checkout at7b09d7b446). Configure took 36.58 s. The six-worker build ofaot_compiler_cliandaot_ir_checktook 853.75 s (14m 14s) for 1558/1558 steps, with no out-of-memory retry.ctest -R "^aot_leaf_": 6/6 passed, 0 skipped, in 12.81 s.ctest -R "conventions_|test_script_registration": 67/67 passed, 0 skipped, in 195.91 s.python tools/check_conventions.py --base upstream/main,git diff --check upstream/mainandpython tools/check_test_registration.py --scriptspass.tools/pr_overlap.py --branchresult, refreshed table below. It fails closed only on PRs that already conflict with main. The only same-new-file overlap is #1835, an architecture discussion thread.November 14 rebase and multi-output staging validation (
6ab76219be0c05756517c71921a51c114d35ab5bon upstreamc04f8bec02607da57e2b99219a7e49fd20c89340):Depends on: #5021per the closing comment on #5021.build-aot): 6/6 AOT CTest groups passed, zero skipped in 11.46 seconds.build-root,ANYPS5_RELINKER_ONLY=ONandANYPS5_BUILD_AOT=ON): 6/6 AOT CTest groups passed, zero skipped, and focused relinker/conventions/registration tests (13/13 passed, zero skipped in 27.73 seconds:conventions_doc_links,conventions_debt_length,conventions_debt_labels,test_script_registration,aot_leaf_abi,aot_leaf_arithmetic,aot_leaf_moves,aot_leaf_shifts,aot_leaf_reject,aot_leaf_formats,relinker_conversion,relr_relocationsandwindows_trace_imports).aot_leaf_rejectnow verifies that secondary output failures (--emit-llvmor--emit-asmtargeting a missing directory) preserve existing primary output and clean up all.tmpfiles, and that case-insensitive output aliases (alias.oandALIAS.O) fail during staging before creating any destination file.python tools/check_conventions.py --base upstream/main,python tools/check_conventions.py --base origin/main,git diff --check upstream/main..HEADandpython tools/check_test_registration.py --scriptspass with zero findings.Earlier validation (October 27–28; original heads recorded below):
Windows 11 x86-64, Ryzen 7 5800X, WinLibs MinGW-w64 GCC 15.2.0, Ninja and Python 3.14.8.
--checkoutinitializes it at the pinned commit. The fixture reads the actual LLVMupdatesetting from this branch. No LLVM checkout download was needed for this policy check.windows_trace_importsfailed with Windows error 1455 (paging file too small) during the eight-worker LLVM build; its focused rerun passed (1.07 seconds test time) after that build stopped. All six AOT groups passed in the root run. This is not presented as an uninterrupted 370/370 pass.Compiler/build validation head:
5cd81c31cb9025423954d24bea54934b50c13baf(prior heads6ab76219be0c05756517c71921a51c114d35ab5b,758b3527733935394d67f0b84db49281ad8669e1,82345086e561dbb548c3bb304d9fc3c3bfccb240); upstream base:96dddbe61db803ce7e3a0b538b203c3286f7a72d.Reproduce the focused build/tests:
The November 22 open-PR overlap scan is below (omitting the self-comparison against #9776's pre-push remote head). Shared files in PRs already conflicting with main remain unverified; no overlap-free merge is claimed.
Open-PR overlap scan
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/aot/CMakeLists.txtdocs/dev/debt/aot.mdSome comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
.gitmodulesCMakeLists.txtcore/aot/CMakeLists.txtdocs/dev/BUILD.mddocs/dev/debt/aot.mdCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtdocs/dev/BUILD.mddocs/dev/BUILD.mdCMakeLists.txtCMakeLists.txtdocs/dev/BUILD.mdCMakeLists.txtdocs/dev/BUILD.mdCMakeLists.txtdocs/dev/BUILD.mddocs/dev/BUILD.mddocs/dev/BUILD.mddocs/dev/BUILD.mddocs/dev/BUILD.mddocs/dev/BUILD.mdCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtCMakeLists.txtdocs/dev/BUILD.mddocs/dev/BUILD.mdCMakeLists.txtChecklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T16:35:51Z.
Review: CHANGES_REQUESTED
I built the exact PR’s standalone AOT project and ran its tests: all 4/4 pass. However, an end-to-end compiler check exposes a blocking issue. I compiled a minimal ELF with one
_startfunction (mov $0, %eax; ret) and ran the newaot_compiler_cliwith--outputand--emit-llvm. The CLI reported “AOT Compilation succeeded” and one function lifted, but the object file is 0 bytes and the emitted IR contains onlyModuleIDandtarget triple, no function.The added LLVM compatibility layer is currently a no-op for code generation:
Module::printemits only those two lines;TargetRegistry::lookupTargetaccepts any nonempty triple;TargetMachine::addPassesToEmitFilereturns success without registering an emitter; andPassManager::runperforms no work. The four tests exercise the parser, lifter, runtime, graphics and I/O components, but do not callAotCompilerDriver::Compileand assert a valid output object/executable. Please use real LLVM code generation or implement and test a working backend for the lifted instructions, and add an end-to-end test that parses the generated object and verifies emitted function code. Until then the new compiler’s success report is a false positive.There is also no
add_subdirectory(core/aot)in the repository’s rootCMakeLists.txt; the new tests run only when configuringcore/aotas a separate project, so normal builds and upstream PR CI do not build or test this code. Please integrate the AOT targets/tests with the repository build (or document and wire up an intentional standalone build in the project’s normal CI path).The exact-head standalone build and 4/4 CTest pass, but they do not cover the broken output path. Current-main conventions and
git diff --checkpass. The branch is 13 commits behind and 39 commits ahead of livemain(499b1cf9fc44da935fe6d63813675ad5810e8402); CONTRIBUTING.md requires keeping branches up to date. Please refresh the branch after addressing the output and integration gaps, then rerun the end-to-end and normal build tests.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T22:34:58Z.
Review: COMMENTED
I built the exact current head (
241c38a7c4508702520758cf1cdeb9c7f924a448) withcmake -S core/aot -B build-aot -G Ninja, built all targets, and ran CTest: 3/4 pass;test_aot_runtimeaborts atTestAotRuntime.cpp:43because the queried block remainsMemoryProtection::Readafter theaps5_sys_mprotect(..., 3)call. The failure is in the test setup: lines 11–15 create/allocate a localMemoryBridge, and lines 33–37 protect/query that instance, butaps5_sys_mprotectinRuntimeRegistry.cpp:123–131always calls the distinct staticgMemoryBridge. That syscall initializes/updates its own address space; the nextmemory.QueryMemoryBlockstill reads the untouched local bridge. Please testProtectdirectly on the local instance, and separately test the syscall using an allocation/query that goes through the registry-backed bridge (or expose a consistent instance for the integration test). This also means the reported 4/4 result is not reproducible on the current head. I did not run the hosted product build.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T04:42:26Z.
Review: COMMENTED
The Tested section says native execution on macOS wasn't tried. On Apple silicon, the
arithmetic,movesandshiftsgroups can't pass as written. I didn't build LLVM here. I reproduced the test's reference step by hand on an M2 Max (macOS 27.2, Apple clang 21, head2cb4c77224).-DCMAKE_OSX_ARCHITECTURES=x86_64), CMake setsCMAKE_SYSTEM_PROCESSORtox86_64, so thenative x86-64 hostgate incore/aot/tests/CMakeLists.txtpasses. ctest then runstest_aot_compiler.pywithPython3_EXECUTABLE(Xcode's/usr/bin/python3). That Python runs as arm64.execute_caseslinks with--host-compilerwithout an-arch, so clang builds arm64. I wrotereference.cppandreference.sthe way the script does, with one case:.byte 72,137,248,195(mov rax, rdi; ret) and theoriginal_0wrapper.clang++ -shared -fPIC -o reference.so reference.cpp reference.sgivesMach-O 64-bit dynamically linked shared library arm64. Callingoriginal_0throughctypeskills Python with SIGILL (exit 132), because the x86 bytes run as arm64 code.objectandassemblylibraries would fail the same way. They are x86-64 Mach-O objects linked by an arm64 link.With
-arch x86_64on the host-compiler calls and the script run underarch -x86_64 /usr/bin/python3, the same reference library loads and returns 5 fororiginal_0(5, ...). So on macOS, either pass-arch x86_64and launch Python under Rosetta, or skip the three execution groups whenplatform.machine()isn'tx86_64. As it stands, a full macOS build withBUILD_TESTING=ONgets three crashing groups, because AOT is on by default outside relinker-only builds.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T14:25:19Z.
Review: CHANGES_REQUESTED
I reviewed exact head
f8b85103b0ca449c286f80fbbb4221d810a15481. The earlier empty-object/IR issue is addressed in this revision, and the new macOS subprocess architecture checks are a concrete fix. Conventions and whitespace pass; the author reports 240/240 Windows tests and 5/5 standalone groups.One test-harness ABI mismatch still blocks relying on the Windows execution results:
test_aot_compiler.pydeclares bothguest_iandoriginal_iwithsysv_abiin the generated reference source (around line 161).execute_programdeclares the called symbols and itsFunctionpointer with the host default ABI (around lines 194-197), and CMake passes${CMAKE_CXX_COMPILER}as that host compiler. On Windows x64, that is the Microsoft ABI, whileoriginal_iexpects SysV registers. For example, the runner places its first argument inRCX, but the SysV wrapper readsRDI; so the reference result is not a reliable oracle for the emitted function.I reproduced the call-site mismatch with GCC's
-mabi=ms: the caller emittedmov $1, %ecx; call original, while thesysv_abiwrapper read%rdi. Please make the outeroriginal_iwrapper use the host ABI while keeping only the rawguest_ibyte function SysV (so the compiler bridges the arguments), or otherwise make the runner's declaration and function-pointer type explicitly SysV. Then rerun the Windows execution groups; the current reported 26,040 evaluations should not be treated as validated until the reference call convention is corrected. Linux/macOS default to SysV, so the mismatch is specific to the Windows host run.This head is also 18 commits behind current
main(e94545a5, merge base938812df), though Git reports a clean merge. Refresh and rerun the AOT tests and conventions on the refreshed head before merge. The current PR CI only ran contribution checks; product jobs are skipped. I started an independent Linux build from the pinned LLVM submodule in an isolated worktree; configuration succeeded, and the 1,556-step build is still running, so I have no local CTest result yet.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-26T10:36:35Z.
Review: CHANGES_REQUESTED
The lifter, ELF reader and output handling read correctly: unsupported encodings, memory, relocations and undeclared register reads throw, and the tests pin values against the original bytes. Blocking points are about scope and cost:
CMakeLists.txt:309:ANYPS5_BUILD_AOTdefaults to ON in full builds, so every Build run (one per PR in the merge queue, Windows and Linux) compiles LLVM's X86 backend from source for a tool nothing in the tree consumes. Default it to OFF in every configuration and keep it opt-in (-DANYPS5_BUILD_AOT=ON); update the sentence indocs/dev/BUILD.md("Full build") accordingly. Also state the added build time and the size of the3rdparty/llvm-projectcheckout, sincegit submodule update --init --recursivein that same section would now fetch it for everyone.core/aot/CMakeLists.txtanddocs/dev/debt/aot.mdtoo, with a different design (x86-64 to native ARM64, with a runtime and a title running). Both cannot land as written. Please agree with that PR's author on the directory layout and list the one that goes first underDepends on.Unblocks: none. AnyPS5 already relinks x86-64 executables to native x86-64, so an x86-64 to x86-64 leaf compiler does not plug into that flow. Describe what consumes it (a caller, a follow-up PR, a qualified title) or leave it out until there is one.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-27T11:28:50Z.
Review: CHANGES_REQUESTED
Thanks for the update:
ANYPS5_BUILD_AOTis now OFF in every configuration anddocs/dev/BUILD.mdstates the LLVM checkout and build cost. That point is settled. What still blocks:core/aot/CMakeLists.txtanddocs/dev/debt/aot.mdwith a different design. The PR body says there is no agreement yet. Please settle the layout and merge order with that PR's author and list the one that goes first underDepends on; both cannot land as written.Unblocks: noneand the body says no consumer exists. An x86-64 to x86-64 leaf compiler does not plug into the relinker flow. Either add the caller/follow-up PR that uses it, or hold this until #5021's direction shows where it fits..gitmodules/docs/dev/BUILD.md: the "Full build" stepgit submodule update --init --recursivenow fetches the 1.66 GiB LLVM tree for everyone even with AOT OFF. Please setupdate = noneon the3rdparty/llvm-projectentry (so only an explicitgit submodule update --init 3rdparty/llvm-projectfetches it) and say so in BUILD.md.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T10:18:53Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change based on the inspected implementation; the draft status and unresolved integration direction keep a formal approval from being justified.
What I ran
Read the prepared diff at head
758b3527733935394d67f0b84db49281ad8669e1, its description, commits, manifest, and selected changed files throughrepo_read.py. No build or tests were run during this review. The description reports prior Windows and focused test results; those results were not independently reproduced here.Results
Findings
Blocking
None.
Non-blocking
core/aot/compiler/src/AotCompilerDriver.cpp:153-155). The debt documentation records this limitation.Not verified
3rdparty/llvm-projectwas excluded from full-text review because it is not plain text; its pinned commit is shown in the diff.description.md,commits.md,manifest.json,diff.patch,.gitmodules,CMakeLists.txt,core/aot/compiler/src/AotCompilerDriver.cpp,core/aot/compiler/src/ElfBinaryParser.cpp,core/aot/compiler/src/LlvmLifter.cpp,core/aot/tests/test_aot_compiler.py, anddocs/dev/BUILD.md. The manifest marks these changed files as included;3rdparty/llvm-projectwas excluded by rule. Other included changed files were not read in full.To get this to a good state
Nothing is required for correctness based on the reviewed code. Optional: resolve the stated integration purpose and layout with the proposed prerequisite; consider staging all requested outputs before publishing them as a group.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T02:16:14Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
1cd795ed5a580076f93d5e1b1309c14861626bf1, basemain. No merge preview.Read-only lookups at the head
Results
Findings
Blocking
None.
Non-blocking
core/aot/tests/test_aot_compiler.py:273— The case-alias rejection runs only when the upper-case name of the input exists, which is true only on a case-insensitive filesystem. On a case-sensitive host the branch is skipped silently, and therejectgroup still prints its "Rejected N invalid or unsupported inputs" line as if every check had run. Suggest printing a line when the alias branch is skipped, so the log shows that the alias case was not exercised.Not verified
docs/dev/debt/aot.md: the lifter was read, but each encoding was not checked against the SDM text.c04f8bec02..gitmodules,CMakeLists.txtanddocs/dev/BUILD.mdwere read at the changed hunks and at the lines listed above, not in full.3rdparty/llvm-projectis a gitlink, so it holds a commit pointer, not text.To get this to a good state
Nothing is required. The optional point above can be taken or left.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T23:29:33Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed code has no verified blocking defect; I am leaving a formal decision open because the PR itself identifies its missing production consumer or committed integration follow-up as an acceptance blocker.
What I ran
Reviewed head
5cd81c31cb9025423954d24bea54934b50c13baf. I inspected the prepared diff and changed-file manifest; I did not run commands or tests. The author reports Windows build and test results in the PR description.Results
Findings
Blocking
None verified in the inspected diff.
Non-blocking
docs/dev/debt/aot.md:1216; callers requesting multiple output files should account for the possibility of a partial update.Not verified
The pinned LLVM submodule contents were unavailable in the review bundle. I did not independently verify builds, tests, other operating systems, or console behavior. The review bundle lists 17 changed paths: I inspected the diff for the 16 text files; the LLVM gitlink was not available as text.
To get this to a good state
Nothing is required by this review. The PR description identifies a production consumer or committed integration follow-up as needed to clear its acceptance blocker.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T02:25:35Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this draft; the implementation is opt-in and its documented limits match the reviewed code, while production integration remains an explicit follow-up.
What I ran
Reviewed head
938d96cdae3aceb9bcf9177f42f3d241e2fe3b3c. No commands or tests were run in this review; validation details below are author-reported in the PR description.Results
Findings
Blocking
None.
Non-blocking
core/aot/compiler/src/AotCompilerDriver.cpp:377). This is recorded in the debt file.Not verified
3rdparty/llvm-projectsubmodule entry is unavailable as a plain text file; its pinned commit is visible in the diff..gitmodules,CMakeLists.txt,core/aot/CMakeLists.txt, all included compiler and test files undercore/aot,docs/dev/BUILD.md, anddocs/dev/debt/aot.md. Excluded:3rdparty/llvm-project(submodule entry is not plain text).To get this to a good state
Nothing is required. Optional: establish and document a production consumer or committed integration follow-up before taking the PR out of draft.
Pull request closed