weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
use super::backward_slice;
use vyre_primitives::graph::program_graph::ProgramGraphShape;

pub fn prepare_slice_graph(
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
    crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
        "slice_closure",
        node_count,
        edge_offsets,
        edge_targets,
        edge_kind_mask,
    )
}

/// Prepare backward-slice graph buffers using caller-owned scratch.
pub fn prepare_slice_graph_with_scratch(
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
    _scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
    prepare_slice_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)
}

/// Repack backward-slice graph buffers into an existing prepared graph.
pub fn prepare_slice_graph_into(
    graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<(), String> {
    graph.replace_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
        "slice_closure",
        node_count,
        edge_offsets,
        edge_targets,
        edge_kind_mask,
    )
}

/// Prepare backward-slice graph buffers and Program once for repeated runs.
pub fn prepare_slice_plan(
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<crate::fixed_point_graph::FixedPointAnalysisPlan, String> {
    let graph = prepare_slice_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)?;
    let program = backward_slice(
        ProgramGraphShape::new(graph.node_count(), graph.edge_count()),
        "fin",
        "fout",
    );
    Ok(
        crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
            crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
            graph,
            program,
        ),
    )
}

/// Repack backward-slice graph buffers and refresh the emitted Program in place.
pub fn prepare_slice_plan_into(
    plan: &mut crate::fixed_point_graph::FixedPointAnalysisPlan,
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<(), String> {
    plan.require_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
        "prepare_slice_plan_into",
    )?;
    prepare_slice_graph_into(
        plan.graph_mut(),
        node_count,
        edge_offsets,
        edge_targets,
        edge_kind_mask,
    )?;
    let program = backward_slice(
        ProgramGraphShape::new(plan.graph().node_count(), plan.graph().edge_count()),
        "fin",
        "fout",
    );
    plan.replace_program_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
        program,
    );
    Ok(())
}