# il2cpp-post-export-optimizer **Repository Path**: xuewuli/il2cpp-post-export-optimizer ## Basic Information - **Project Name**: il2cpp-post-export-optimizer - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: codex/evidence-retention - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-23 - **Last Updated**: 2026-10-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # il2cpp-post-export-optimizer An independent, out-of-tree optimizer for exported IL2CPP C++ trees. The current `il2cpp` checkout is never a build dependency. It may be supplied as an explicit read-only reference source when an implementation detail needs to be compared. The current editor target is Tuanjie `2022.3.62t15`. Extract the original IL2CPP payload and Android SDK/NDK from that installation, and bind them to a matching export, compilation database, and cache. Changing editors requires a new input identity. The reference checkout supplies no authoritative generator, generated C++, or managed inputs. Development follows the [IL-guided C++ optimizer design](docs/superpowers/specs/2026-09-24-il-guided-cpp-optimizer-design.md) and [project workflow](AGENTS.md). The delivery target is a unified optimizer; individual experimental rules and indexing tools do not establish that this end-to-end product is complete. ## Bootstrap From this repository, run: ```powershell powershell -NoProfile -ExecutionPolicy Bypass -File tools/Seed-OptimizerRepository.ps1 dotnet build Optimizer.sln -c Release powershell -NoProfile -ExecutionPolicy Bypass -File tools/Smoke-Help.ps1 ``` Large generated trees and generator binaries are stored under `.artifacts/` and are ignored by Git. No command in this repository invokes IL2CPP during the bootstrap smoke test. ### Mainland download sources The LLVM 18.1.8 installer source is recorded in the analysis-toolchain manifest. An optional mainland access proxy (not an LLVM official mirror) is: ```text https://ghfast.top/https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/LLVM-18.1.8-win64.exe ``` Verify availability when downloading. The pinned installer SHA-256 is `94af030060d88cc17e9f00ef1663ebdc1126b35e16bebdfa1e807984b70abd8f`; the hash, rather than the mirror response, is the acceptance gate. `.NET` restore uses `NuGet.config`, with Huawei Cloud first and `nuget.org` as an explicit fallback. Restore explicitly when reproducing the checkout: ```powershell dotnet restore --configfile NuGet.config ``` Mirror availability is not treated as provenance: every downloaded artifact must still match its recorded SHA-256. ## Scope and non-goals IL and managed metadata provide semantic facts for transformations on exported C++. The first planned consumers are cross-TU call simplification and checks whose non-null or array-length facts can be proved; intrinsic coverage expands by semantic category. Simple-copy is an existing bounded experiment, not the product's entire scope. Implementation, unified-flow integration, and measured native benefit are tracked separately. Design coverage does not imply that all of these rules are implemented or enabled. The optimizer does not modify IL2CPP source or use LLVM IR as its production output. Editor export and baseline generation are input-preparation steps; ordinary optimization operates on the supplied matching bundle. `tools/Export-TuanjieNativeBundle.ps1` can create a fresh Android export from the pinned Tuanjie Editor in an isolated external work project. The script writes `Assets/csc.rsp` with `-langversion:10.0`, excludes stale Unity caches and Android output, and records a file-level manifest. A generated export is not considered replayable until a matching `compile_commands.json` is captured; the manifest remains `PendingCompilerDatabase` otherwise. For a new input, choose fresh paths and export with explicit editor identity (replace the source project path with the controlled input project): ```powershell $editorRoot = 'C:\Program Files\Tuanjie\Hub\Editor\2022.3.62t15' $editorVersion = '2022.3.62t15' $attemptRoot = '.artifacts\t15-input-new' # Must be unused for this attempt. $workRoot = Join-Path $attemptRoot 'work-project' $nativeRoot = Join-Path $attemptRoot 'native-bundle\android-project' $androidTools = Join-Path $editorRoot 'Editor\Data\PlaybackEngines\AndroidPlayer' pwsh -NoProfile -File tools/Export-TuanjieNativeBundle.ps1 ` -UnityEditorRoot $editorRoot -UnityEditorVersion $editorVersion ` -UnityEditorExe (Join-Path $editorRoot 'Editor\Tuanjie.exe') ` -SourceProject 'E:\path\to\controlled-project' ` -WorkRoot $workRoot -OutputRoot (Join-Path $attemptRoot 'native-bundle') pwsh -NoProfile -File tools/Replay-TuanjieNativeCompile.ps1 ` -BundleRoot $nativeRoot -NdkRoot (Join-Path $androidTools 'NDK') ` -OutputRoot (Join-Path $attemptRoot 'native-replay') pwsh -NoProfile -File tools/Capture-CompilerDatabase.ps1 ` -BundleRoot $nativeRoot -ReplayRoot (Join-Path $attemptRoot 'native-replay') ``` The capture records every compiler action from Bee's completed DAG and updates the bundle manifest to `ReplayableWithCompilerDatabase`. IL2CPP lump sources are retained in the external replay cache because they are part of that exact replay input. The separately generated baseline tree still requires a matching native bundle before it can be used for an optimizer result. Extract the matching generator using the fresh export's version evidence and capture the analysis toolchain with the same editor's Android tools: ```powershell $generatorRoot = Join-Path $attemptRoot 'generator' $toolchainManifest = Join-Path $attemptRoot 'toolchain\analysis-toolchain.json' pwsh -NoProfile -File tools/Extract-UnityIl2Cpp.ps1 ` -UnityEditorRoot $editorRoot -UnityEditorVersion $editorVersion ` -EditorVersionEvidencePath (Join-Path $workRoot 'ProjectSettings\ProjectVersion.txt') ` -DestinationArtifactRoot $generatorRoot -TargetTriple 'aarch64-linux-android22' pwsh -NoProfile -File tools/Capture-AnalysisToolchain.ps1 ` -UnityEditorRoot $editorRoot -OutputPath $toolchainManifest ``` `Capture-AnalysisToolchain.ps1` also needs its configured LLVM installation and installer. Supply `-ToolchainRoot` and `-InstallerPath` if they differ from the script defaults. Analysis LLVM is separate from the editor's native compiler. Use the fresh export's generated source/data as the baseline. If a separate `Generate-Baseline.ps1` run is needed, pass the matching extracted payload, `ManagedStripped` assemblies, and actual conversion switches explicitly, then verify its identity against the export. File counts and byte equality must be measured for that input; they are not fixed properties of an editor version. Create and validate a self-contained baseline artifact bundle with: ```powershell $generatedRoot = Join-Path $nativeRoot 'tuanjieLibrary\src\main\Il2CppOutputProject\Source\il2cppOutput' $bundleRoot = Join-Path $attemptRoot 'artifact-bundle' pwsh -NoProfile -File tools/New-ArtifactBundle.ps1 ` -EditorRoot $editorRoot -EditorVersion $editorVersion ` -GeneratorPayloadRoot (Join-Path $generatorRoot 'unity-editor-payload') ` -NativeBundleRoot $nativeRoot ` -CompilerDatabasePath (Join-Path $nativeRoot 'compile_commands.json') ` -BaselineGeneratedCppRoot $generatedRoot ` -OriginalDll (Join-Path $workRoot 'Library\Bee\artifacts\Android\ManagedStripped\Assembly-CSharp.dll') ` -CscResponseFile (Join-Path $workRoot 'Assets\csc.rsp') ` -AnalysisToolchainManifest $toolchainManifest -OutputRoot $bundleRoot dotnet run --project src\Optimizer.Cli\Optimizer.Cli.csproj -c Release -- ` validate-bundle $bundleRoot ``` The validator hashes the complete tree and rejects missing roots, path escapes, source-root outputs, and compiler databases whose first executable is IL2CPP. The bundle also retains the export's `input/csc.rsp` so the C# 10 language version is part of the recorded managed-input provenance. Validate the captured analysis toolchain before AST/IR work: ```powershell dotnet run --project src\Optimizer.Cli\Optimizer.Cli.csproj -c Release -- ` validate-toolchain $toolchainManifest ``` The AST and IR tools use this LLVM payload as an analysis oracle; their output is never treated as equivalent to the Unity native compiler's code generation. Evidence lifecycle and rolling retention are defined in [`docs/evidence-retention-policy.md`](docs/evidence-retention-policy.md). For repeated analysis iterations, `index-tree` and `emit-ir-tree` accept an external `--cache-root` plus the complete provenance key (`--clang-version`, `--target-triple`, `--toolchain-fingerprint`, `--bundle-identity`, and `--rule-version`). `FastIterative` reuses hash-valid Brotli-compressed TU entries; `FullAudit` rebuilds every translation unit. The cache is disposable, versioned binary data, while the emitted manifests remain canonical JSON. `FastIterative` still defaults to `FullExport`; request `--output-mode SelectedProjection` and explicit selection inputs to load and emit only selected TUs. See the [audit runbook](docs/audit-runbook.md) for scope and measurement rules. A complete index export alone is not a complete audit. ## Analysis and materialization After emitting a matching C++ index, IL/C++ mapping, O0 IR analysis, and planning report, materialize a separate optimized tree with the following template. Replace the placeholders with outputs from the same validated input: ```powershell dotnet run --project src\Optimizer.Cli\Optimizer.Cli.csproj -c Release -- ` optimized-tree ` --planning-report ` --cpp-index ` --bundle $bundleRoot ` --baseline-root (Join-Path $bundleRoot 'baseline\generated-cpp') ` --output ``` The materializer selects only index shards referenced by transformed method identities, then fully parses and hash-checks those shards and every rewritten source file. This keeps repeated materialization fast without weakening the full-bundle audit path; the baseline tree is never overwritten.