Skip to content

feat(pass)!: rebuild pass framework on LLVM new pass manager model#74

Merged
siyul-park merged 2 commits into
mainfrom
feature/pass-manager-redesign
Jun 15, 2026
Merged

feat(pass)!: rebuild pass framework on LLVM new pass manager model#74
siyul-park merged 2 commits into
mainfrom
feature/pass-manager-redesign

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Changes Made

Rebuild the analysis/optimization framework on LLVM's new pass manager model, removing heavy reflection and an awkward interface.

pass package

  • pass.Manager — lazy analysis cache: Register[U,R], GetResult[R](m, unit), Invalidate(Preserved). Only residual reflection is reflect.TypeFor[R]() as a map key; no dynamic method dispatch.
  • pass.Pipeline[U] — ordered transform sequence: AddPass, Run(m, unit), invalidating stale analyses between passes.
  • New Analysis[U,R] and Pass[U] interfaces; Preserved (PreserveAll/PreserveNone).
  • *pass.Manager is the first argument everywhere (context-style ordering).

analysis / transform / optimize

  • BasicBlocksPassBasicBlocksAnalysis; Run takes its unit directly.
  • Transforms (CF/CD/DCE) request blocks via GetResult and return pass.Preserved.
  • optimize uses a declarative level→passes table with O0/O1/O2 (O1 = CF+CD, O2 adds AlgebraicSimplification + DCE).
  • New AlgebraicSimplificationPass: integer (I32/I64) identities (x+0, x*1, x&-1, …) and strength reduction (x*2ⁿ<<n, unsigned x/2ⁿ>>n). Float identities skipped (IEEE-754).

Docs: pass-system.md, architecture.md, coding-patterns.md updated.

BREAKING CHANGE: pass public API replaced — Manager.Load/Run/Convert and Optimizer.Register removed in favor of GetResult/Pipeline/AddPass.

Related Issues

Additional Information

Test plan:

  • go build ./...
  • go vet ./..., gofmt clean
  • go test -race ./pass/... ./analysis/... ./transform/... ./optimize/...
  • new as_test.go covers each identity/strength-reduction case; Manager cache + Invalidate test; O2 optimizer case

Replace the reflection-based pass.Manager with a generics-based design
modeled on LLVM's new pass manager:

- pass.Manager: lazy analysis cache (Register/GetResult/Invalidate); only
  reflect.TypeFor[R]() remains as a map key, no dynamic method dispatch
- pass.Pipeline[U]: ordered transform sequence (AddPass/Run)
- Analysis[U,R] and Pass[U] interfaces; Preserved-based invalidation
- BasicBlocksPass -> BasicBlocksAnalysis
- transforms return pass.Preserved and request blocks via GetResult
- optimize: declarative O0/O1/O2 levels with a level->passes table
- new AlgebraicSimplificationPass: integer identities + strength reduction

BREAKING CHANGE: pass package API replaced; Manager.Load/Run/Convert and
Optimizer.Register removed in favor of GetResult/Pipeline/AddPass.

Copy link
Copy Markdown
Owner Author

PR Review — feat(pass)!: rebuild pass framework on LLVM new pass manager model

Decision: Request Changes


Merge Readiness Summary

The PR successfully redesigns the pass/analysis framework with a cleaner, more type-safe generics-based approach following LLVM's new pass manager. The architecture is sound, tests are comprehensive, and documentation is well-updated. However, the build is currently failing due to incompatible function signatures in interp/interp.go.


Blocking Findings

Compilation Error in interp/interp.go

Issue: newCompiler() calls missing required argument

Build logs show compilation failures:

  • Line 619: not enough arguments in call to newCompiler have () want (int)
  • Line 657: not enough arguments in call to newCompiler have () want (int)

Why it matters: Code cannot compile, which blocks merge.

Minimal fix: Update both newCompiler() calls in interp/interp.go to pass the required int argument.

Validation: Run go build ./... to verify compilation succeeds.


Detailed Assessment

✅ Scope Control

Focused on one concern: rebuilding the pass framework. No unrelated cleanups. Directly addresses architectural issue.

✅ Correctness (except CI issue)

  • Generics-based design is sound
  • Analysis caching logic is correct (keyed by result type + unit)
  • Pipeline correctly invalidates caches between passes
  • New AlgebraicSimplificationPass tests are comprehensive

✅ Test Coverage

  • New tests for Manager (Register, GetResult, Invalidate)
  • New tests for Pipeline (run in order, error handling)
  • 8+ test cases for AlgebraicSimplificationPass
  • All existing pass tests updated consistently

✅ Architecture Consistency

  • Follows LLVM's new pass manager design
  • Clear separation: Manager (analysis cache) vs Pipeline (transform sequence)
  • Generics eliminate unsafe reflection
  • More type-safe and easier to understand

✅ Risk & Compatibility

  • BREAKING CHANGE properly marked with ! in commit
  • Public API completely replaced (intentional & necessary)
  • Documentation updates explain new API

✅ Maintainability

  • Significantly simplified codebase
  • Generics are more type-safe than reflection
  • Clear separation of concerns
  • Better API surface

Minimal Path to Merge

  1. Fix the compilation error: Update lines 619 and 657 in interp/interp.go to call newCompiler(...) with the required int argument.
  2. Verify build: Run go build ./...
  3. Re-run CI: Confirm all tests pass.

Final Recommendation

Fix blocking findings and re-run validation.

The architectural work here is excellent and represents a significant improvement over the reflection-based approach. This is a well-executed framework redesign that will make the codebase safer and more maintainable. Once the compilation error is resolved, this should be merge-ready.


Generated by Claude Code

Commit 61b93f1 removed the cutoff int param from newCompiler and its
call sites but left the !arm64 stub taking an int, breaking non-arm64
builds. Drop the unused parameter so the stub matches.
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.27848% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.36%. Comparing base (d0d71ff) to head (65c49db).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
transform/as.go 71.42% 16 Missing and 6 partials ⚠️
transform/dce.go 42.85% 3 Missing and 1 partial ⚠️
transform/cf.go 60.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #74      +/-   ##
==========================================
- Coverage   64.04%   63.36%   -0.69%     
==========================================
  Files          60       63       +3     
  Lines       10859    11782     +923     
==========================================
+ Hits         6955     7466     +511     
- Misses       3184     3526     +342     
- Partials      720      790      +70     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@siyul-park siyul-park merged commit cef87ba into main Jun 15, 2026
5 checks passed
@siyul-park siyul-park deleted the feature/pass-manager-redesign branch June 15, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant