Skip to main content

weir/
fixed_point_batch.rs

1//! Batch orchestration for Weir fixed-point analyses.
2//!
3//! This file owns only sequencing and scratch reuse. Individual analysis
4//! semantics remain in `reaching`, `live`, `points_to`, and `slice`.
5
6use crate::fixed_point_scratch::FixedPointScratch;
7
8mod ifds;
9mod live;
10mod points_to;
11mod reaching;
12mod slice;
13#[cfg(test)]
14mod tests;
15
16pub use crate::graph_layout::CsrGraph;
17
18/// Fixed-point batch runner that reuses scratch across analyses.
19#[derive(Clone, Debug, PartialEq)]
20pub struct FixedPointBatch<'a, F> {
21    dispatch: &'a F,
22    scratch: FixedPointScratch,
23    ifds_prepare_scratch: crate::ifds_gpu::IfdsPrepareScratch,
24    ifds_scratch: crate::ifds_gpu::IfdsSolveScratch,
25}
26
27impl<'a, F> FixedPointBatch<'a, F>
28where
29    F: Fn(&vyre::ir::Program, &[&[u8]], Option<[u32; 3]>, &mut Vec<Vec<u8>>) -> Result<(), String>,
30{
31    /// Create a batch runner around a borrowed GPU dispatch adapter.
32    #[must_use]
33    pub fn new(dispatch: &'a F) -> Self {
34        Self {
35            dispatch,
36            scratch: FixedPointScratch::default(),
37            ifds_prepare_scratch: crate::ifds_gpu::IfdsPrepareScratch::default(),
38            ifds_scratch: crate::ifds_gpu::IfdsSolveScratch::default(),
39        }
40    }
41
42    /// Inspect retained scratch after one or more batch runs.
43    #[must_use]
44    pub fn scratch(&self) -> &FixedPointScratch {
45        &self.scratch
46    }
47
48    /// Latest host-observed frontier density from the last fixed-point solve.
49    #[must_use]
50    pub fn frontier_density(&self) -> crate::fixed_point_scratch::FrontierDensityTelemetry {
51        self.scratch.frontier_density()
52    }
53
54    /// Sparse/dense execution family recommended from the last solve's frontier density.
55    #[must_use]
56    pub fn recommended_frontier_execution_mode(
57        &self,
58    ) -> crate::fixed_point_scratch::FrontierExecutionMode {
59        self.scratch.frontier_density().recommended_execution_mode()
60    }
61
62    /// Build a scale-aware execution plan for a prepared graph using the last
63    /// observed frontier density.
64    pub fn execution_plan_for_prepared_graph(
65        &self,
66        graph: &crate::fixed_point_graph::FixedPointForwardGraph,
67    ) -> Result<crate::fixed_point_execution_plan::FixedPointExecutionPlan, String> {
68        crate::fixed_point_execution_plan::plan_prepared_graph(graph, self.frontier_density())
69    }
70
71    /// Clear logical scratch contents while preserving capacity.
72    pub fn clear(&mut self) {
73        self.scratch.clear();
74        self.ifds_prepare_scratch.clear();
75        self.ifds_scratch.clear();
76    }
77}