weirflow 0.1.0

GPU-first dataflow analysis primitives for Vyre and Santh compiler pipelines.
Documentation
//! Batch orchestration for Weir fixed-point analyses.
//!
//! This file owns only sequencing and scratch reuse. Individual analysis
//! semantics remain in `reaching`, `live`, `points_to`, and `slice`.

use crate::fixed_point_scratch::FixedPointScratch;

mod ifds;
mod live;
mod points_to;
mod reaching;
mod slice;
#[cfg(test)]
mod tests;

pub use crate::graph_layout::CsrGraph;

/// Fixed-point batch runner that reuses scratch across analyses.
#[derive(Clone, Debug, PartialEq)]
pub struct FixedPointBatch<'a, F> {
    dispatch: &'a F,
    scratch: FixedPointScratch,
    ifds_prepare_scratch: crate::ifds_gpu::IfdsPrepareScratch,
    ifds_scratch: crate::ifds_gpu::IfdsSolveScratch,
}

impl<'a, F> FixedPointBatch<'a, F>
where
    F: Fn(&vyre::ir::Program, &[&[u8]], Option<[u32; 3]>, &mut Vec<Vec<u8>>) -> Result<(), String>,
{
    /// Create a batch runner around a borrowed GPU dispatch adapter.
    #[must_use]
    pub fn new(dispatch: &'a F) -> Self {
        Self {
            dispatch,
            scratch: FixedPointScratch::default(),
            ifds_prepare_scratch: crate::ifds_gpu::IfdsPrepareScratch::default(),
            ifds_scratch: crate::ifds_gpu::IfdsSolveScratch::default(),
        }
    }

    /// Inspect retained scratch after one or more batch runs.
    #[must_use]
    pub fn scratch(&self) -> &FixedPointScratch {
        &self.scratch
    }

    /// Latest host-observed frontier density from the last fixed-point solve.
    #[must_use]
    pub fn frontier_density(&self) -> crate::fixed_point_scratch::FrontierDensityTelemetry {
        self.scratch.frontier_density()
    }

    /// Sparse/dense execution family recommended from the last solve's frontier density.
    #[must_use]
    pub fn recommended_frontier_execution_mode(
        &self,
    ) -> crate::fixed_point_scratch::FrontierExecutionMode {
        self.scratch.frontier_density().recommended_execution_mode()
    }

    /// Build a scale-aware execution plan for a prepared graph using the last
    /// observed frontier density.
    pub fn execution_plan_for_prepared_graph(
        &self,
        graph: &crate::fixed_point_graph::FixedPointForwardGraph,
    ) -> Result<crate::fixed_point_execution_plan::FixedPointExecutionPlan, String> {
        crate::fixed_point_execution_plan::plan_prepared_graph(graph, self.frontier_density())
    }

    /// Clear logical scratch contents while preserving capacity.
    pub fn clear(&mut self) {
        self.scratch.clear();
        self.ifds_prepare_scratch.clear();
        self.ifds_scratch.clear();
    }
}