Files
hakorune/docs/reference/mir/phi_policy.md

1.7 KiB
Raw Blame History

MIR PHI Policy (Phase15)

Status

  • Default: PHIoff (edgecopy mode). Builders/Bridge do not emit PHI; merges are realized via perpredecessor Copy into the merge destination.
  • Devonly: PHIon is experimental for targeted tests (enable with NYASH_MIR_NO_PHI=0).
  • LLVM: PHI synthesis is delegated to the LLVM/llvmlite path (AOT/EXE). PyVM serves as the semantic reference.

Rationale

  • Simplify MIR builders and JSON bridge by removing PHI placement decisions from the core path.
  • Centralize SSA join formation at a single backend (LLVM harness), reducing maintenance and divergence.
  • Keep PyVM parity by treating merges as value routing; shortcircuit semantics remain unchanged.

Operational Rules (PHIoff)

  • Edgecopy only: predecessors write the merged destination via Copy { dst=merged, src=pred_value }.

  • Merge block: must not emit a selfCopy for the same destination; merged value is already defined by predecessors.

  • Verifier: verify_allow_no_phi() is on by default; dominance and merge checks are relaxed in PHIoff.

  • Developer Notes (PHIon dev mode)

  • Requires cargo feature phi-legacy. Build with --features phi-legacy and enable with NYASH_MIR_NO_PHI=0. Builders may place Phi at block heads with inputs covering all predecessors.

  • Use NYASH_LLVM_TRACE_PHI=1 for wiring trace; prefer small, isolated tests.

Backends

  • LLVM harness performs PHI synthesis based on predecessor copies and dominance.
  • Other backends (Cranelift/JIT) are secondary during Phase15; PHI synthesis there is not required.

Acceptance

  • Default smokes/CI run with PHIoff.
  • Parity checks compare PyVM vs. LLVM AOT outputs; differences are resolved on the LLVM side when they stem from PHI formation.