Skip to content

v.ssa.optimize #

Common subexpression elimination.

Go's cse.go (cmd/compile/internal/ssa) partitions values into equivalence classes and rewrites a value to an equal one that dominates it. In SSA that is the same result as this scoped walk of the dominator tree, which keeps the expressions available on the path from the entry. Zig leaves this to LLVM.

fn optimize #

fn optimize(mut m ssa.Module)

optimize runs the production optimization pipeline. Scalar alloca promotion and phi elimination are kept together because the ARM64 backend consumes the resulting edge copies rather than native phi nodes. V3_VERIFY=1 structured verify after each pass (V3_VERIFY_STRICT=1 = fatal)

fn optimize_with_options #

fn optimize_with_options(mut m ssa.Module, opts OptimizeOptions)

optimize_with_options supports optimize with options handling for optimize.

fn verify #

fn verify(m &ssa.Module) []VerifyError

verify performs comprehensive validation of SSA invariants and returns every error found (empty slice == valid). v3 stores branch/phi/switch targets as raw block ids, so block operands are validated as block ids, not block values.

fn verify_and_panic #

fn verify_and_panic(m &ssa.Module, pass_name string)

verify_and_panic runs verification and panics on critical errors only.

fn verify_and_panic_with_options #

fn verify_and_panic_with_options(m &ssa.Module, pass_name string, opts VerifyPanicOptions)

verify_and_panic_with_options runs verification with an explicit warning policy. Declaration-only functions (C externs / prototypes) are always accepted.

struct OptimizeOptions #

struct OptimizeOptions {
pub:
	mem2reg          bool // promote scalar allocas to SSA values + phi nodes
	eliminate_phis   bool // lower phis to `assign` copies (for backends without phi)
	verify_each_pass bool // run the structured verifier after every structural pass
	strict_verify    bool // treat historically-noncritical verifier findings as fatal
}

OptimizeOptions controls optimize options behavior used by optimize.

struct VerifyError #

struct VerifyError {
pub:
	msg       string
	func_id   int = -1
	func_name string
	block_id  int = -1
	val_id    int = -1
}

VerifyError is a structured SSA verification failure. Unlike verify_ssa() (which panics on the first problem), the structured API collects every error so callers can decide which are fatal.

fn (VerifyError) str #

fn (e VerifyError) str() string

str returns the string form for VerifyError.

struct VerifyPanicOptions #

struct VerifyPanicOptions {
pub:
	allow_noncritical bool
}

VerifyPanicOptions controls verify panic options behavior used by optimize.