1use super::reaching_defs_step;
2use vyre_primitives::graph::program_graph::ProgramGraphShape;
3
4pub fn prepare_reaching_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 let mut scratch = crate::fixed_point_scratch::FixedPointScratch::default();
11 scratch.prepare_edge_kind_masks(
12 edge_kind_mask,
13 vyre_primitives::predicate::edge_kind::CONTROL,
14 )?;
15 crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
16 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
17 "reaching_closure",
18 node_count,
19 edge_offsets,
20 edge_targets,
21 &scratch.edge_kind_masks,
22 )
23}
24
25pub fn prepare_reaching_graph_into(
27 graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
28 node_count: u32,
29 edge_offsets: &[u32],
30 edge_targets: &[u32],
31 edge_kind_mask: &[u32],
32) -> Result<(), String> {
33 let mut scratch = crate::fixed_point_scratch::FixedPointScratch::default();
34 scratch.prepare_edge_kind_masks(
35 edge_kind_mask,
36 vyre_primitives::predicate::edge_kind::CONTROL,
37 )?;
38 graph.replace_for_kind(
39 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
40 "reaching_closure",
41 node_count,
42 edge_offsets,
43 edge_targets,
44 &scratch.edge_kind_masks,
45 )
46}
47
48pub fn prepare_reaching_graph_with_scratch(
51 node_count: u32,
52 edge_offsets: &[u32],
53 edge_targets: &[u32],
54 edge_kind_mask: &[u32],
55 scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
56) -> Result<crate::fixed_point_graph::FixedPointForwardGraph, String> {
57 scratch.prepare_edge_kind_masks(
58 edge_kind_mask,
59 vyre_primitives::predicate::edge_kind::CONTROL,
60 )?;
61 crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
62 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
63 "reaching_closure",
64 node_count,
65 edge_offsets,
66 edge_targets,
67 &scratch.edge_kind_masks,
68 )
69}
70
71pub fn prepare_reaching_graph_into_with_scratch(
74 graph: &mut crate::fixed_point_graph::FixedPointForwardGraph,
75 node_count: u32,
76 edge_offsets: &[u32],
77 edge_targets: &[u32],
78 edge_kind_mask: &[u32],
79 scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
80) -> Result<(), String> {
81 scratch.prepare_edge_kind_masks(
82 edge_kind_mask,
83 vyre_primitives::predicate::edge_kind::CONTROL,
84 )?;
85 graph.replace_for_kind(
86 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
87 "reaching_closure",
88 node_count,
89 edge_offsets,
90 edge_targets,
91 &scratch.edge_kind_masks,
92 )
93}
94
95pub fn prepare_reaching_plan(
97 node_count: u32,
98 edge_offsets: &[u32],
99 edge_targets: &[u32],
100 edge_kind_mask: &[u32],
101) -> Result<crate::fixed_point_graph::FixedPointAnalysisPlan, String> {
102 let graph = prepare_reaching_graph(node_count, edge_offsets, edge_targets, edge_kind_mask)?;
103 let program = reaching_defs_step(
104 ProgramGraphShape::new(graph.node_count, graph.edge_count),
105 "fin",
106 "fout",
107 );
108 Ok(
109 crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
110 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
111 graph,
112 program,
113 ),
114 )
115}
116
117pub fn prepare_reaching_plan_with_scratch(
120 node_count: u32,
121 edge_offsets: &[u32],
122 edge_targets: &[u32],
123 edge_kind_mask: &[u32],
124 scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
125) -> Result<crate::fixed_point_graph::FixedPointAnalysisPlan, String> {
126 scratch.prepare_edge_kind_masks(
127 edge_kind_mask,
128 vyre_primitives::predicate::edge_kind::CONTROL,
129 )?;
130 let graph = crate::fixed_point_graph::FixedPointForwardGraph::new_for_kind(
131 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
132 "reaching_closure",
133 node_count,
134 edge_offsets,
135 edge_targets,
136 &scratch.edge_kind_masks,
137 )?;
138 let program = reaching_defs_step(
139 ProgramGraphShape::new(graph.node_count, graph.edge_count),
140 "fin",
141 "fout",
142 );
143 Ok(
144 crate::fixed_point_graph::FixedPointAnalysisPlan::new_for_kind(
145 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
146 graph,
147 program,
148 ),
149 )
150}
151
152pub fn prepare_reaching_plan_into(
154 plan: &mut crate::fixed_point_graph::FixedPointAnalysisPlan,
155 node_count: u32,
156 edge_offsets: &[u32],
157 edge_targets: &[u32],
158 edge_kind_mask: &[u32],
159) -> Result<(), String> {
160 plan.require_kind(
161 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
162 "prepare_reaching_plan_into",
163 )?;
164 prepare_reaching_graph_into(
165 plan.graph_mut(),
166 node_count,
167 edge_offsets,
168 edge_targets,
169 edge_kind_mask,
170 )?;
171 let program = reaching_defs_step(
172 ProgramGraphShape::new(plan.graph().node_count, plan.graph().edge_count),
173 "fin",
174 "fout",
175 );
176 plan.replace_program_for_kind(
177 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
178 program,
179 );
180 Ok(())
181}
182
183pub fn prepare_reaching_plan_into_with_scratch(
186 plan: &mut crate::fixed_point_graph::FixedPointAnalysisPlan,
187 node_count: u32,
188 edge_offsets: &[u32],
189 edge_targets: &[u32],
190 edge_kind_mask: &[u32],
191 scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
192) -> Result<(), String> {
193 plan.require_kind(
194 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
195 "prepare_reaching_plan_into_with_scratch",
196 )?;
197 prepare_reaching_graph_into_with_scratch(
198 plan.graph_mut(),
199 node_count,
200 edge_offsets,
201 edge_targets,
202 edge_kind_mask,
203 scratch,
204 )?;
205 let program = reaching_defs_step(
206 ProgramGraphShape::new(plan.graph().node_count, plan.graph().edge_count),
207 "fin",
208 "fout",
209 );
210 plan.replace_program_for_kind(
211 crate::fixed_point_graph::FixedPointAnalysisKind::Reaching,
212 program,
213 );
214 Ok(())
215}