Skip to main content

weir/slice/
plan.rs

1use super::backward_slice;
2use vyre_primitives::graph::program_graph::ProgramGraphShape;
3
4pub fn prepare_slice_graph(
5    node_count: u32,
6    edge_offsets: &[u32],
7    edge_targets: &[u32],
8    edge_kind_mask: &[u32],
9) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
10    crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
11        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
12        "slice_closure",
13        node_count,
14        edge_offsets,
15        edge_targets,
16        edge_kind_mask,
17    )
18}
19
20/// Prepare backward-slice graph buffers using caller-owned scratch.
21pub fn prepare_slice_graph_with_scratch(
22    node_count: u32,
23    edge_offsets: &[u32],
24    edge_targets: &[u32],
25    edge_kind_mask: &[u32],
26    _scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
27) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
28    prepare_slice_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)
29}
30
31/// Repack backward-slice graph buffers into an existing prepared graph.
32pub fn prepare_slice_graph_into(
33    graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
34    node_count: u32,
35    edge_offsets: &[u32],
36    edge_targets: &[u32],
37    edge_kind_mask: &[u32],
38) -> Result<(), String> {
39    graph.replace_for_kind(
40        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
41        "slice_closure",
42        node_count,
43        edge_offsets,
44        edge_targets,
45        edge_kind_mask,
46    )
47}
48
49/// Prepare backward-slice graph buffers and Program once for repeated runs.
50pub fn prepare_slice_plan(
51    node_count: u32,
52    edge_offsets: &[u32],
53    edge_targets: &[u32],
54    edge_kind_mask: &[u32],
55) -> Result<crate::fixed_point_graph::FixedPointAnalysisPlan, String> {
56    let graph = prepare_slice_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)?;
57    let program = backward_slice(
58        ProgramGraphShape::new(graph.node_count(), graph.edge_count()),
59        "fin",
60        "fout",
61    );
62    Ok(
63        crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
64            crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
65            graph,
66            program,
67        ),
68    )
69}
70
71/// Repack backward-slice graph buffers and refresh the emitted Program in place.
72pub fn prepare_slice_plan_into(
73    plan: &mut crate::fixed_point_graph::FixedPointAnalysisPlan,
74    node_count: u32,
75    edge_offsets: &[u32],
76    edge_targets: &[u32],
77    edge_kind_mask: &[u32],
78) -> Result<(), String> {
79    plan.require_kind(
80        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
81        "prepare_slice_plan_into",
82    )?;
83    prepare_slice_graph_into(
84        plan.graph_mut(),
85        node_count,
86        edge_offsets,
87        edge_targets,
88        edge_kind_mask,
89    )?;
90    let program = backward_slice(
91        ProgramGraphShape::new(plan.graph().node_count(), plan.graph().edge_count()),
92        "fin",
93        "fout",
94    );
95    plan.replace_program_for_kind(
96        crate::fixed_point_graph::FixedPointAnalysisKind::Slice,
97        program,
98    );
99    Ok(())
100}