weirflow 0.1.0

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

pub fn prepare_reaching_graph(
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
    let mut scratch = crate::fixed_point_scratch::FixedPointScratch::default();
    scratch.prepare_edge_kind_masks(
        edge_kind_mask,
        vyre_primitives::predicate::edge_kind::CONTROL,
    )?;
    crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "reaching_closure",
        node_count,
        edge_offsets,
        edge_targets,
        &scratch.edge_kind_masks,
    )
}

/// Repack invariant reaching graph buffers into an existing prepared graph.
pub fn prepare_reaching_graph_into(
    graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<(), String> {
    let mut scratch = crate::fixed_point_scratch::FixedPointScratch::default();
    scratch.prepare_edge_kind_masks(
        edge_kind_mask,
        vyre_primitives::predicate::edge_kind::CONTROL,
    )?;
    graph.replace_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "reaching_closure",
        node_count,
        edge_offsets,
        edge_targets,
        &scratch.edge_kind_masks,
    )
}

/// Prepare invariant reaching graph buffers using caller-owned scratch for
/// edge-kind filtering.
pub fn prepare_reaching_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> {
    scratch.prepare_edge_kind_masks(
        edge_kind_mask,
        vyre_primitives::predicate::edge_kind::CONTROL,
    )?;
    crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "reaching_closure",
        node_count,
        edge_offsets,
        edge_targets,
        &scratch.edge_kind_masks,
    )
}

/// Repack invariant reaching graph buffers into an existing prepared graph
/// using caller-owned scratch for edge-kind filtering.
pub fn prepare_reaching_graph_into_with_scratch(
    graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
    scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
) -> Result<(), String> {
    scratch.prepare_edge_kind_masks(
        edge_kind_mask,
        vyre_primitives::predicate::edge_kind::CONTROL,
    )?;
    graph.replace_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "reaching_closure",
        node_count,
        edge_offsets,
        edge_targets,
        &scratch.edge_kind_masks,
    )
}

/// Prepare invariant reaching graph buffers and emitted Program once.
pub fn prepare_reaching_plan(
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
) -> Result<crate::fixed_point_graph::FixedPointAnalysisPlan, String> {
    let graph = prepare_reaching_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)?;
    let program = reaching_defs_step(
        ProgramGraphShape::new(graph.node_count, graph.edge_count),
        "fin",
        "fout",
    );
    Ok(
        crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
            crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
            graph,
            program,
        ),
    )
}

/// Prepare invariant reaching graph buffers and emitted Program once using
/// caller-owned scratch for edge-kind filtering.
pub fn prepare_reaching_plan_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::FixedPointAnalysisPlan, String> {
    scratch.prepare_edge_kind_masks(
        edge_kind_mask,
        vyre_primitives::predicate::edge_kind::CONTROL,
    )?;
    let graph = crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "reaching_closure",
        node_count,
        edge_offsets,
        edge_targets,
        &scratch.edge_kind_masks,
    )?;
    let program = reaching_defs_step(
        ProgramGraphShape::new(graph.node_count, graph.edge_count),
        "fin",
        "fout",
    );
    Ok(
        crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
            crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
            graph,
            program,
        ),
    )
}

/// Repack reaching graph buffers and refresh the emitted Program in place.
pub fn prepare_reaching_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::Reaching,
        "prepare_reaching_plan_into",
    )?;
    prepare_reaching_graph_into(
        plan.graph_mut(),
        node_count,
        edge_offsets,
        edge_targets,
        edge_kind_mask,
    )?;
    let program = reaching_defs_step(
        ProgramGraphShape::new(plan.graph().node_count, plan.graph().edge_count),
        "fin",
        "fout",
    );
    plan.replace_program_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        program,
    );
    Ok(())
}

/// Repack reaching graph buffers and refresh the emitted Program in place
/// using caller-owned scratch for edge-kind filtering.
pub fn prepare_reaching_plan_into_with_scratch(
    plan: &mut crate::fixed_point_graph::FixedPointAnalysisPlan,
    node_count: u32,
    edge_offsets: &[u32],
    edge_targets: &[u32],
    edge_kind_mask: &[u32],
    scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
) -> Result<(), String> {
    plan.require_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        "prepare_reaching_plan_into_with_scratch",
    )?;
    prepare_reaching_graph_into_with_scratch(
        plan.graph_mut(),
        node_count,
        edge_offsets,
        edge_targets,
        edge_kind_mask,
        scratch,
    )?;
    let program = reaching_defs_step(
        ProgramGraphShape::new(plan.graph().node_count, plan.graph().edge_count),
        "fin",
        "fout",
    );
    plan.replace_program_for_kind(
        crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
        program,
    );
    Ok(())
}