Skip to documentation
SLOP

tiny.choir.passes.cse

Reference tiny.choir passes cse

Defined in passes.

API (21)

Actions

Public operations.

Types and contracts

Public types and contracts.

Values and defaults

Public values and defaults.

No direct callersNo direct callspassescse
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/choir/src/passes/cse/storage.zig:304

zig
pub const Table = struct {    slots: []CseSlot,    insertion_slots: []usize,    insertion_count: *usize,    log_start: usize,    pub fn candidates(self: Table, key: u64) CandidateIterator {        return CandidateIterator.init(self.slots, key);    }    pub fn add(self: Table, key: u64, op: *ir.Operation) error{CapacityExceeded}!void {        if (self.insertion_count.* >= self.insertion_slots.len) {            return error.CapacityExceeded;        }        if (self.slots.len == 0) return error.CapacityExceeded;        var index = cseSlotIndex(key, self.slots.len);        var remaining = self.slots.len;        while (remaining > 0) : (remaining -= 1) {            const slot = &self.slots[index];            if (slot.op == null) {                slot.* = .{                    .key = key,                    .op = op,                };                self.insertion_slots[self.insertion_count.*] = index;                self.insertion_count.* += 1;                return;            }            index = (index + 1) & (self.slots.len - 1);        }        return error.CapacityExceeded;    }    fn clear(self: *Table) void {        std.debug.assert(self.insertion_count.* >= self.log_start);        while (self.insertion_count.* > self.log_start) {            self.insertion_count.* -= 1;            const index = self.insertion_slots[self.insertion_count.*];            std.debug.assert(self.slots[index].op != null);            self.slots[index] = .{};        }    }};

Source: lib/choir/src/passes/cse/storage.zig:90

zig
pub const Workspace = struct {    pub const claim: alloc_phase.capacity.Declaration = .{        .source = .{            .id = "choir.cse_workspace",            .kind = .phase_static,            .limit_source = .caller,            .storage = .{                .covered = &.{                    .{                        .id = "effect_records_bounded_by_declared_contract_capacity",                        .lifetime = .steady,                        .detail = "reused fact buffer bounded by arity-derived contract capacity",                    },                    .{                        .id = "scoped_cse_hash_slots_bounded_by_peak_active_candidate_shapes",                        .lifetime = .steady,                        .detail = "scoped CSE hash slots bounded by peak active candidate shapes",                    },                    .{                        .id = "lifo_insertion_indices_bounded_by_peak_active_candidate_shapes",                        .lifetime = .steady,                        .detail = "LIFO insertion indices bounded by peak active candidate shapes",                    },                },                .excluded = &.{                    "borrowed IR and dominance analysis",                },            },            .capacity = .{                .inputs = &.{                    alloc_phase.capacity.bindInput(Limits, "facts_operation_depth", "facts.operation_depth"),                    alloc_phase.capacity.bindInput(Limits, "facts_peak_candidate_count", "facts.peak_candidate_count"),                    alloc_phase.capacity.bindInput(                        Limits,                        "facts_peak_effect_records",                        "facts.peak_effect_records",                    ),                },                .type_selectors = &.{},                .nodes = &.{                    .{ .input = 0 },                    .{ .input = 1 },                    .{ .add = .{ .left = 0, .right = 1 } },                    .{ .input = 2 },                    .{ .add = .{ .left = 2, .right = 3 } },                },                .assertions = &.{.{                    .scope = .closure_total,                    .measure = .retained,                    .relation = .upper_bound,                    .expression = 4,                }},            },            .overload = .{                .kind = .reject_before_seal,                .detail = "nesting, count arithmetic, capacity arithmetic, or fallback OOM rejects before CSE traversal",            },            .risks = .{                .transitive = .{                    .status = .witnessed,                    .detail = "CSE equivalence, result remapping, duplicate erasure, and scoped table mutation use only admitted storage after activation",                },                .foreign = .{                    .status = .open,                    .detail = "the workspace has no visible foreign edge, but foreign-edge closure lacks a machine-checked certificate",                },            },            .obligations = &.{                .{ .key = "cse_inline_boundary", .role = .overload },                .{ .key = "cse_capacity", .role = .capacity_model },                .{ .key = "cse_sealed_reuse_overload", .role = .overload },                .{ .key = "cse_sealed_reuse_foreign_risk", .role = .foreign_risk },                .{ .key = "cse_oom_retry", .role = .overload },                .{ .key = "cse_steady_no_alloc", .role = .transitive_risk },            },        },        .bindings = .{            .owner = @This(),            .seal = .{                .family = alloc_phase.capacity.selector(@This().activate),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },            .teardown = .{                .family = alloc_phase.capacity.selector(@This().deinit),                .premise = .{                    .class = .checked_semantic_fact,                    .authority = .checker,                },            },        },    };    phase: alloc_phase.capacity.Phase,    capacity: CseCapacity,    bytes: []align(cse_storage_alignment) u8,    slots: []CseSlot,    insertion_slots: []usize,    effect_records: []effects.Fact,    insertion_count: usize,    active_scope_count: usize,    pub const Limits = CseLimits;    pub const Capacity = CseCapacity;    pub fn initForRoot(allocator: Allocator, root: *ir.Operation) !Workspace {        return init(allocator, try Limits.inspect(root));    }    pub fn init(allocator: Allocator, limits: Limits) !Workspace {        const capacity = try Capacity.derive(limits);        const bytes = try allocator.alignedAlloc(            u8,            .fromByteUnits(cse_storage_alignment),            capacity.working_bytes,        );        const slots = cseTypedSlice(            CseSlot,            bytes,            0,            capacity.slot_count,        );        @memset(slots, .{});        return .{            .phase = .initialization,            .capacity = capacity,            .bytes = bytes,            .slots = slots,            .insertion_slots = cseTypedSlice(                usize,                bytes,                capacity.insertion_offset,                capacity.facts.peak_candidate_count,            ),            .insertion_count = 0,            .active_scope_count = 0,            .effect_records = cseTypedSlice(                effects.Fact,                bytes,                capacity.effect_offset,                capacity.facts.peak_effect_records,            ),        };    }    pub fn activate(self: *Workspace) error{AlreadyActive}!void {        if (self.phase != .initialization) return error.AlreadyActive;        self.phase = .steady;    }    pub fn requiresDominance(self: *const Workspace) bool {        if (self.phase != .initialization) {            @panic("CSE dominance admission checked outside initialization");        }        return self.capacity.facts.requires_dominance;    }    pub fn acquire(self: *Workspace) Table {        self.requireSteady();        self.active_scope_count = std.math.add(            usize,            self.active_scope_count,            1,        ) catch @panic("CSE active scope count overflow after activation");        return .{            .slots = self.slots,            .insertion_slots = self.insertion_slots,            .insertion_count = &self.insertion_count,            .log_start = self.insertion_count,        };    }    pub fn release(self: *Workspace, table: Table) void {        self.requireSteady();        std.debug.assert(table.slots.ptr == self.slots.ptr);        std.debug.assert(table.insertion_slots.ptr == self.insertion_slots.ptr);        std.debug.assert(table.insertion_count == &self.insertion_count);        var scope = table;        scope.clear();        std.debug.assert(self.active_scope_count > 0);        self.active_scope_count -= 1;    }    pub fn deinit(self: *Workspace, allocator: Allocator) void {        if (self.phase == .teardown) @panic("CSE workspace teardown is terminal");        std.debug.assert(self.insertion_count == 0);        std.debug.assert(self.active_scope_count == 0);        self.phase = .teardown;        allocator.free(self.bytes);        self.bytes = undefined;        self.slots = undefined;        self.insertion_slots = undefined;        self.insertion_count = undefined;        self.active_scope_count = undefined;    }    fn requireSteady(self: *const Workspace) void {        if (self.phase != .steady) {            @panic("CSE workspace used outside its steady phase");        }    }};

Source: lib/choir/src/passes/cse/pass.zig:17

zig
pub const common_subexpression_elimination_pass_description =    "Common subexpression elimination for pure operations";

Source: lib/choir/src/passes/cse/pass.zig:16

zig
pub const common_subexpression_elimination_pass_name = "choir-cse";

Source: lib/choir/src/passes/cse/pass.zig:30

zig
pub const common_subexpression_elimination_pass_registration = registry_mod.PassRegistration{    .name = common_subexpression_elimination_pass_name,    .description = common_subexpression_elimination_pass_description,    .pass = createCommonSubexpressionEliminationPass(),};

Source: lib/choir/src/passes/cse/pass.zig:20

zig
pub fn createCommonSubexpressionEliminationPass() Pass {    return .{        .name = common_subexpression_elimination_pass_name,        .description = common_subexpression_elimination_pass_description,        .run_fn = run,        .mutation_scope = .isolated,        .rerun_policy = .skip_if_unchanged,    };}
Called byCallsNo direct callsprivate sourcelib.choir.src.passes.cse.testrunCsePasstest sourcelib.choir.src.passes.cse.testtest: choir-cse eliminates qualified ...passes.optimizationsbuildDefaultOptimizationPipelineprivate sourcelib.choir.src.passes.optimizationscheckAllocationIdentityWitnesstest sourcelib.choir.src.passes.optimizationstest: F10a CSE retains two consuming ...+2 morepassescreateCommonSubexpressionEliminationP...
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/choir/src/passes/cse/pass.zig:36

zig
pub fn run(ctx: *PassContext) PassResult {    var stack_buffer: [cse.inline_workspace_bytes]u8 = undefined;    var stack_fallback = alloc_observe.buffer.First.init(&stack_buffer, ctx.allocator);    const workspace_allocator = stack_fallback.allocator();    var workspace = Workspace.initForRoot(workspace_allocator, ctx.op) catch        return .failure;    defer workspace.deinit(workspace_allocator);    const dominance: ?*const control_flow.DominanceAnalysis = if (workspace.requiresDominance())        control_flow.getDominanceAnalysis(ctx, ctx.op) catch return .failure    else        null;    workspace.activate() catch return .failure;    var modified = false;    var replacements: u64 = 0;    cseOnOp(        ctx.op,        dominance,        &workspace,        &modified,        &replacements,    );    std.debug.assert(workspace.insertion_count == 0);    std.debug.assert(workspace.active_scope_count == 0);    if (replacements != 0) {        ctx.addStatistic("replacements", "redundant operations replaced", replacements);    }    if (modified) {        ctx.preserveAnalysisSet(control_flow.analysis_ids);        ctx.markModified();    } else {        ctx.preserveAllAnalyses();    }    return .success;}
Called byCallstest sourcelib.choir.src.backends.gpu.nvptx.conversiontest: nvptx conversion lowers gpu idx...test sourcelib.choir.src.backends.gpu.nvptx.conversiontest: nvptx conversion rejects unknow...test sourcelib.choir.src.backends.gpu.spirv.conversiontest: gpu to spirv conversion rewrite...test sourcelib.choir.src.backends.gpu.spirv.conversiontest: spirv backend emits after gpu-t...test sourcelib.choir.src.backends.gpu.spirv.conversiontest: spirv conversion rejects unknow...private sourcelib.choir.src.passes.pass.manager.OpPassManagerrunPassEntryprivate sourcelib.choir.src.passes.cse.passcseOnOppasses.cse.WorkspaceinitForRootpasses.cserun
Static calls · unresolved targets: 0 · external targets: 10.
Called byCallsNo direct callersprivate sourcelib.choir.src.passes.cse.storagecseSlotIndexpasses.cse.Tableadd
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersprivate sourcelib.choir.src.passes.cse.storage.CandidateIte...initpasses.cse.Tablecandidates
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callersprivate sourcelib.choir.src.passes.cse.storage.WorkspacerequireSteadypasses.cse.Workspaceacquire
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callstest sourcelib.choir.src.passes.cse.storagetest: CSE workspace inline tier ends ...passes.cse.Workspacedeinit
Static calls · unresolved targets: 0 · external targets: 1.
Called byCallstest sourcelib.choir.src.passes.cse.storagetest: CSE workspace inline tier ends ...private sourcelib.choir.src.passes.cse.storagecseTypedSlicepasses.cse.Workspaceinit
Static calls · unresolved targets: 1 · external targets: 1.
Called byCallsNo direct callspasses.cserunprivate sourcelib.choir.src.passes.cse.storagecheckWorkspaceInitFailurestest sourcelib.choir.src.passes.cse.storagetest: CSE workspace initialization is...test sourcelib.choir.src.passes.cse.storagetest: CSE workspace reuses exact back...passes.cse.WorkspaceinitForRoot
Static calls · unresolved targets: 2 · external targets: 0.
Called byCallsNo direct callersprivate sourcelib.choir.src.passes.cse.storage.WorkspacerequireSteadypasses.cse.Workspacerelease
Static calls · unresolved targets: 1 · external targets: 0.

Source: lib/choir/src/passes/cse/storage.zig:501

zig
pub fn hasCandidateShape(op: *ir.Operation) bool {    return op.regions.items.len == 0 and        op.successors.items.len == 0 and        op.result_types.len != 0;}
Called byCallsNo direct callsprivate sourcelib.choir.src.passes.cse.storageaddWorkspaceRegionCandidatesprivate sourcelib.choir.src.passes.cse.storageinspectCseOperationpasses.csehasCandidateShape
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/choir/src/passes/cse/storage.zig:13

zig
pub const inline_workspace_bytes: usize = 8 * 1024;

Source: lib/choir/src/passes/cse/root.zig

zig
const implementation = @import("pass.zig");const storage = @import("storage.zig");pub const common_subexpression_elimination_pass_name =    implementation.common_subexpression_elimination_pass_name;pub const common_subexpression_elimination_pass_description =    implementation.common_subexpression_elimination_pass_description;pub const common_subexpression_elimination_pass_registration =    implementation.common_subexpression_elimination_pass_registration;pub const createCommonSubexpressionEliminationPass =    implementation.createCommonSubexpressionEliminationPass;pub const run = implementation.run;pub const hasCandidateShape = storage.hasCandidateShape;pub const inline_workspace_bytes = storage.inline_workspace_bytes;pub const Table = storage.Table;pub const Workspace = storage.Workspace;

Source: lib/choir/src/passes/root.zig:119

zig
pub const cse = @import("cse/root.zig");

Complete caller list for passes.createCommonSubexpressionEliminationPass

7 direct callers.

Audit

Definitions22
Public names30
Members12
Version26.7.0
Revisiondaab053ee433