Skip to main content

weir/fixed_point_resident_plan/
generic.rs

1#![allow(clippy::too_many_arguments)]
2
3use crate::fixed_point_graph::FixedPointAnalysisPlan;
4use crate::fixed_point_resident::FixedPointResidentGraph;
5use crate::fixed_point_resident_frontier::FixedPointResidentFrontierScratch;
6
7/// Trait abstracting over owned and borrowed resident graph references.
8pub trait GraphRef {
9    fn graph_ref(&self) -> &FixedPointResidentGraph;
10}
11
12impl GraphRef for FixedPointResidentGraph {
13    fn graph_ref(&self) -> &FixedPointResidentGraph {
14        self
15    }
16}
17
18impl GraphRef for &FixedPointResidentGraph {
19    fn graph_ref(&self) -> &FixedPointResidentGraph {
20        self
21    }
22}
23
24/// Generic plan executor that works with both owned and borrowed resident graphs.
25#[derive(Clone)]
26pub struct PlanBuilder<G: GraphRef> {
27    pub(crate) graph: G,
28    pub(crate) pipeline: std::sync::Arc<dyn vyre::CompiledPipeline>,
29}
30
31impl<G: GraphRef> std::fmt::Debug for PlanBuilder<G> {
32    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33        f.debug_struct("PlanBuilder")
34            .field("graph", self.graph.graph_ref())
35            .finish_non_exhaustive()
36    }
37}
38
39impl<G: GraphRef> PartialEq for PlanBuilder<G> {
40    fn eq(&self, other: &Self) -> bool {
41        self.graph.graph_ref() == other.graph.graph_ref()
42    }
43}
44
45impl<G: GraphRef> PlanBuilder<G> {
46    fn compiled_pipeline(&self) -> &dyn vyre::CompiledPipeline {
47        &*self.pipeline
48    }
49
50    fn require_sequence_layout(
51        &self,
52        plan: &FixedPointAnalysisPlan,
53        caller: &'static str,
54    ) -> Result<(), String> {
55        self.graph
56            .graph_ref()
57            .require_same_layout(plan.graph(), caller)
58    }
59
60    /// Number of graph nodes in the resident dispatch domain.
61    #[must_use]
62    pub fn node_count(&self) -> u32 {
63        self.graph.graph_ref().node_count()
64    }
65
66    /// Number of graph edges in the resident dispatch domain.
67    #[must_use]
68    pub fn edge_count(&self) -> u32 {
69        self.graph.graph_ref().edge_count()
70    }
71
72    /// Number of resident invariant graph resources.
73    #[must_use]
74    pub fn resident_resource_count(&self) -> usize {
75        self.graph.graph_ref().resident_resource_count()
76    }
77
78    /// Run reaching-definition closure with resident graph and frontier buffers.
79    pub fn reaching_resident_frontier(
80        &self,
81        backend: &dyn vyre::VyreBackend,
82        seed_bits: &[u32],
83        max_iterations: u32,
84        config: &vyre::DispatchConfig,
85        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
86    ) -> Result<Vec<u32>, String> {
87        self.graph.graph_ref().reaching_resident_frontier(
88            backend,
89            self.compiled_pipeline(),
90            seed_bits,
91            max_iterations,
92            config,
93            scratch,
94        )
95    }
96
97    /// Run reaching-definition closure with resident graph/frontier buffers
98    /// into caller-owned result storage.
99    pub fn reaching_resident_frontier_into(
100        &self,
101        backend: &dyn vyre::VyreBackend,
102        seed_bits: &[u32],
103        max_iterations: u32,
104        config: &vyre::DispatchConfig,
105        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
106        result: &mut Vec<u32>,
107    ) -> Result<(), String> {
108        self.graph.graph_ref().reaching_resident_frontier_into(
109            backend,
110            self.compiled_pipeline(),
111            seed_bits,
112            max_iterations,
113            config,
114            scratch,
115            result,
116        )
117    }
118
119    /// Run reaching-definition closure while reusing resident frontier buffers.
120    pub fn reaching_reusing_frontier(
121        &self,
122        backend: &dyn vyre::VyreBackend,
123        seed_bits: &[u32],
124        max_iterations: u32,
125        config: &vyre::DispatchConfig,
126        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
127        resident_frontier: &mut FixedPointResidentFrontierScratch,
128    ) -> Result<Vec<u32>, String> {
129        crate::reaching::reaching_closure_resident_plan_with_reusable_frontier_scratch(
130            backend,
131            self.compiled_pipeline(),
132            self.graph.graph_ref(),
133            seed_bits,
134            max_iterations,
135            config,
136            scratch,
137            resident_frontier,
138        )
139    }
140
141    /// Run reaching-definition closure while reusing resident frontier buffers
142    /// and caller-owned result storage.
143    pub fn reaching_reusing_frontier_into(
144        &self,
145        backend: &dyn vyre::VyreBackend,
146        seed_bits: &[u32],
147        max_iterations: u32,
148        config: &vyre::DispatchConfig,
149        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
150        resident_frontier: &mut FixedPointResidentFrontierScratch,
151        result: &mut Vec<u32>,
152    ) -> Result<(), String> {
153        crate::reaching::reaching_closure_resident_plan_with_reusable_frontier_scratch_into(
154            backend,
155            self.compiled_pipeline(),
156            self.graph.graph_ref(),
157            seed_bits,
158            max_iterations,
159            config,
160            scratch,
161            resident_frontier,
162            result,
163        )
164    }
165
166    /// Run live-variable closure with resident graph and frontier buffers.
167    pub fn live_resident_frontier(
168        &self,
169        backend: &dyn vyre::VyreBackend,
170        seed_bits: &[u32],
171        max_iterations: u32,
172        config: &vyre::DispatchConfig,
173        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
174    ) -> Result<Vec<u32>, String> {
175        self.graph.graph_ref().live_resident_frontier(
176            backend,
177            self.compiled_pipeline(),
178            seed_bits,
179            max_iterations,
180            config,
181            scratch,
182        )
183    }
184
185    /// Run live-variable closure with resident graph/frontier buffers into
186    /// caller-owned result storage.
187    pub fn live_resident_frontier_into(
188        &self,
189        backend: &dyn vyre::VyreBackend,
190        seed_bits: &[u32],
191        max_iterations: u32,
192        config: &vyre::DispatchConfig,
193        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
194        result: &mut Vec<u32>,
195    ) -> Result<(), String> {
196        self.graph.graph_ref().live_resident_frontier_into(
197            backend,
198            self.compiled_pipeline(),
199            seed_bits,
200            max_iterations,
201            config,
202            scratch,
203            result,
204        )
205    }
206
207    /// Run live-variable closure while reusing resident frontier buffers.
208    pub fn live_reusing_frontier(
209        &self,
210        backend: &dyn vyre::VyreBackend,
211        seed_bits: &[u32],
212        max_iterations: u32,
213        config: &vyre::DispatchConfig,
214        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
215        resident_frontier: &mut FixedPointResidentFrontierScratch,
216    ) -> Result<Vec<u32>, String> {
217        crate::live::live_closure_resident_plan_with_reusable_frontier_scratch(
218            backend,
219            self.compiled_pipeline(),
220            self.graph.graph_ref(),
221            seed_bits,
222            max_iterations,
223            config,
224            scratch,
225            resident_frontier,
226        )
227    }
228
229    /// Run live-variable closure while reusing resident frontier buffers and
230    /// caller-owned result storage.
231    pub fn live_reusing_frontier_into(
232        &self,
233        backend: &dyn vyre::VyreBackend,
234        seed_bits: &[u32],
235        max_iterations: u32,
236        config: &vyre::DispatchConfig,
237        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
238        resident_frontier: &mut FixedPointResidentFrontierScratch,
239        result: &mut Vec<u32>,
240    ) -> Result<(), String> {
241        crate::live::live_closure_resident_plan_with_reusable_frontier_scratch_into(
242            backend,
243            self.compiled_pipeline(),
244            self.graph.graph_ref(),
245            seed_bits,
246            max_iterations,
247            config,
248            scratch,
249            resident_frontier,
250            result,
251        )
252    }
253
254    /// Run points-to subset closure with resident graph and frontier buffers.
255    pub fn points_to_subset_resident_frontier(
256        &self,
257        backend: &dyn vyre::VyreBackend,
258        seed_bits: &[u32],
259        max_iterations: u32,
260        config: &vyre::DispatchConfig,
261        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
262    ) -> Result<Vec<u32>, String> {
263        self.graph.graph_ref().points_to_subset_resident_frontier(
264            backend,
265            self.compiled_pipeline(),
266            seed_bits,
267            max_iterations,
268            config,
269            scratch,
270        )
271    }
272
273    /// Run points-to subset closure with resident graph/frontier buffers into
274    /// caller-owned result storage.
275    pub fn points_to_subset_resident_frontier_into(
276        &self,
277        backend: &dyn vyre::VyreBackend,
278        seed_bits: &[u32],
279        max_iterations: u32,
280        config: &vyre::DispatchConfig,
281        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
282        result: &mut Vec<u32>,
283    ) -> Result<(), String> {
284        self.graph
285            .graph_ref()
286            .points_to_subset_resident_frontier_into(
287                backend,
288                self.compiled_pipeline(),
289                seed_bits,
290                max_iterations,
291                config,
292                scratch,
293                result,
294            )
295    }
296
297    /// Run points-to subset closure while reusing resident frontier buffers.
298    pub fn points_to_subset_reusing_frontier(
299        &self,
300        backend: &dyn vyre::VyreBackend,
301        seed_bits: &[u32],
302        max_iterations: u32,
303        config: &vyre::DispatchConfig,
304        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
305        resident_frontier: &mut FixedPointResidentFrontierScratch,
306    ) -> Result<Vec<u32>, String> {
307        crate::points_to::subset_closure_resident_plan_with_reusable_frontier_scratch(
308            backend,
309            self.compiled_pipeline(),
310            self.graph.graph_ref(),
311            seed_bits,
312            max_iterations,
313            config,
314            scratch,
315            resident_frontier,
316        )
317    }
318
319    /// Run points-to subset closure while reusing resident frontier buffers
320    /// and caller-owned result storage.
321    pub fn points_to_subset_reusing_frontier_into(
322        &self,
323        backend: &dyn vyre::VyreBackend,
324        seed_bits: &[u32],
325        max_iterations: u32,
326        config: &vyre::DispatchConfig,
327        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
328        resident_frontier: &mut FixedPointResidentFrontierScratch,
329        result: &mut Vec<u32>,
330    ) -> Result<(), String> {
331        crate::points_to::subset_closure_resident_plan_with_reusable_frontier_scratch_into(
332            backend,
333            self.compiled_pipeline(),
334            self.graph.graph_ref(),
335            seed_bits,
336            max_iterations,
337            config,
338            scratch,
339            resident_frontier,
340            result,
341        )
342    }
343
344    /// Run backward-slice closure with resident graph and frontier buffers.
345    pub fn slice_resident_frontier(
346        &self,
347        backend: &dyn vyre::VyreBackend,
348        seed_bits: &[u32],
349        max_iterations: u32,
350        config: &vyre::DispatchConfig,
351        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
352    ) -> Result<Vec<u32>, String> {
353        self.graph.graph_ref().slice_resident_frontier(
354            backend,
355            self.compiled_pipeline(),
356            seed_bits,
357            max_iterations,
358            config,
359            scratch,
360        )
361    }
362
363    /// Run backward-slice closure with resident graph/frontier buffers into
364    /// caller-owned result storage.
365    pub fn slice_resident_frontier_into(
366        &self,
367        backend: &dyn vyre::VyreBackend,
368        seed_bits: &[u32],
369        max_iterations: u32,
370        config: &vyre::DispatchConfig,
371        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
372        result: &mut Vec<u32>,
373    ) -> Result<(), String> {
374        self.graph.graph_ref().slice_resident_frontier_into(
375            backend,
376            self.compiled_pipeline(),
377            seed_bits,
378            max_iterations,
379            config,
380            scratch,
381            result,
382        )
383    }
384
385    /// Run backward-slice closure while reusing resident frontier buffers.
386    pub fn slice_reusing_frontier(
387        &self,
388        backend: &dyn vyre::VyreBackend,
389        seed_bits: &[u32],
390        max_iterations: u32,
391        config: &vyre::DispatchConfig,
392        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
393        resident_frontier: &mut FixedPointResidentFrontierScratch,
394    ) -> Result<Vec<u32>, String> {
395        crate::slice::slice_closure_resident_plan_with_reusable_frontier_scratch(
396            backend,
397            self.compiled_pipeline(),
398            self.graph.graph_ref(),
399            seed_bits,
400            max_iterations,
401            config,
402            scratch,
403            resident_frontier,
404        )
405    }
406
407    /// Run backward-slice closure while reusing resident frontier buffers and
408    /// caller-owned result storage.
409    pub fn slice_reusing_frontier_into(
410        &self,
411        backend: &dyn vyre::VyreBackend,
412        seed_bits: &[u32],
413        max_iterations: u32,
414        config: &vyre::DispatchConfig,
415        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
416        resident_frontier: &mut FixedPointResidentFrontierScratch,
417        result: &mut Vec<u32>,
418    ) -> Result<(), String> {
419        crate::slice::slice_closure_resident_plan_with_reusable_frontier_scratch_into(
420            backend,
421            self.compiled_pipeline(),
422            self.graph.graph_ref(),
423            seed_bits,
424            max_iterations,
425            config,
426            scratch,
427            resident_frontier,
428            result,
429        )
430    }
431
432    /// Run reaching-definition closure through backend resident sequence replay.
433    pub fn reaching_reusing_frontier_sequence_window(
434        &self,
435        backend: &dyn vyre::VyreBackend,
436        plan: &FixedPointAnalysisPlan,
437        seed_bits: &[u32],
438        max_iterations: u32,
439        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
440        resident_frontier: &mut FixedPointResidentFrontierScratch,
441    ) -> Result<Vec<u32>, String> {
442        self.require_sequence_layout(
443            plan,
444            "PlanBuilder::reaching_reusing_frontier_sequence_window",
445        )?;
446        crate::reaching::reaching_closure_resident_plan_with_reusable_frontier_scratch_sequence_window(
447            backend,
448            plan.program(),
449            self.graph.graph_ref(),
450            seed_bits,
451            max_iterations,
452            scratch,
453            resident_frontier,
454        )
455    }
456
457    /// Run reaching-definition closure through backend resident sequence replay
458    /// into caller-owned result storage.
459    pub fn reaching_reusing_frontier_sequence_window_into(
460        &self,
461        backend: &dyn vyre::VyreBackend,
462        plan: &FixedPointAnalysisPlan,
463        seed_bits: &[u32],
464        max_iterations: u32,
465        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
466        resident_frontier: &mut FixedPointResidentFrontierScratch,
467        result: &mut Vec<u32>,
468    ) -> Result<(), String> {
469        self.require_sequence_layout(
470            plan,
471            "PlanBuilder::reaching_reusing_frontier_sequence_window_into",
472        )?;
473        crate::reaching::reaching_closure_resident_plan_with_reusable_frontier_scratch_sequence_window_into(
474            backend,
475            plan.program(),
476            self.graph.graph_ref(),
477            seed_bits,
478            max_iterations,
479            scratch,
480            resident_frontier,
481            result,
482        )
483    }
484
485    /// Run live-variable closure through backend resident sequence replay.
486    pub fn live_reusing_frontier_sequence_window(
487        &self,
488        backend: &dyn vyre::VyreBackend,
489        plan: &FixedPointAnalysisPlan,
490        seed_bits: &[u32],
491        max_iterations: u32,
492        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
493        resident_frontier: &mut FixedPointResidentFrontierScratch,
494    ) -> Result<Vec<u32>, String> {
495        self.require_sequence_layout(plan, "PlanBuilder::live_reusing_frontier_sequence_window")?;
496        crate::live::live_closure_resident_plan_with_reusable_frontier_scratch_sequence_window(
497            backend,
498            plan.program(),
499            self.graph.graph_ref(),
500            seed_bits,
501            max_iterations,
502            scratch,
503            resident_frontier,
504        )
505    }
506
507    /// Run live-variable closure through backend resident sequence replay into
508    /// caller-owned result storage.
509    pub fn live_reusing_frontier_sequence_window_into(
510        &self,
511        backend: &dyn vyre::VyreBackend,
512        plan: &FixedPointAnalysisPlan,
513        seed_bits: &[u32],
514        max_iterations: u32,
515        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
516        resident_frontier: &mut FixedPointResidentFrontierScratch,
517        result: &mut Vec<u32>,
518    ) -> Result<(), String> {
519        self.require_sequence_layout(
520            plan,
521            "PlanBuilder::live_reusing_frontier_sequence_window_into",
522        )?;
523        crate::live::live_closure_resident_plan_with_reusable_frontier_scratch_sequence_window_into(
524            backend,
525            plan.program(),
526            self.graph.graph_ref(),
527            seed_bits,
528            max_iterations,
529            scratch,
530            resident_frontier,
531            result,
532        )
533    }
534
535    /// Run points-to subset closure through backend resident sequence replay.
536    pub fn points_to_subset_reusing_frontier_sequence_window(
537        &self,
538        backend: &dyn vyre::VyreBackend,
539        plan: &FixedPointAnalysisPlan,
540        seed_bits: &[u32],
541        max_iterations: u32,
542        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
543        resident_frontier: &mut FixedPointResidentFrontierScratch,
544    ) -> Result<Vec<u32>, String> {
545        self.require_sequence_layout(
546            plan,
547            "PlanBuilder::points_to_subset_reusing_frontier_sequence_window",
548        )?;
549        crate::points_to::subset_closure_resident_plan_with_reusable_frontier_scratch_sequence_window(
550            backend,
551            plan.program(),
552            self.graph.graph_ref(),
553            seed_bits,
554            max_iterations,
555            scratch,
556            resident_frontier,
557        )
558    }
559
560    /// Run points-to subset closure through backend resident sequence replay
561    /// into caller-owned result storage.
562    pub fn points_to_subset_reusing_frontier_sequence_window_into(
563        &self,
564        backend: &dyn vyre::VyreBackend,
565        plan: &FixedPointAnalysisPlan,
566        seed_bits: &[u32],
567        max_iterations: u32,
568        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
569        resident_frontier: &mut FixedPointResidentFrontierScratch,
570        result: &mut Vec<u32>,
571    ) -> Result<(), String> {
572        self.require_sequence_layout(
573            plan,
574            "PlanBuilder::points_to_subset_reusing_frontier_sequence_window_into",
575        )?;
576        crate::points_to::subset_closure_resident_plan_with_reusable_frontier_scratch_sequence_window_into(
577            backend,
578            plan.program(),
579            self.graph.graph_ref(),
580            seed_bits,
581            max_iterations,
582            scratch,
583            resident_frontier,
584            result,
585        )
586    }
587
588    /// Run backward-slice closure through backend resident sequence replay.
589    pub fn slice_reusing_frontier_sequence_window(
590        &self,
591        backend: &dyn vyre::VyreBackend,
592        plan: &FixedPointAnalysisPlan,
593        seed_bits: &[u32],
594        max_iterations: u32,
595        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
596        resident_frontier: &mut FixedPointResidentFrontierScratch,
597    ) -> Result<Vec<u32>, String> {
598        self.require_sequence_layout(plan, "PlanBuilder::slice_reusing_frontier_sequence_window")?;
599        crate::slice::slice_closure_resident_plan_with_reusable_frontier_scratch_sequence_window(
600            backend,
601            plan.program(),
602            self.graph.graph_ref(),
603            seed_bits,
604            max_iterations,
605            scratch,
606            resident_frontier,
607        )
608    }
609
610    /// Run backward-slice closure through backend resident sequence replay into
611    /// caller-owned result storage.
612    pub fn slice_reusing_frontier_sequence_window_into(
613        &self,
614        backend: &dyn vyre::VyreBackend,
615        plan: &FixedPointAnalysisPlan,
616        seed_bits: &[u32],
617        max_iterations: u32,
618        scratch: &mut crate::fixed_point_scratch::FixedPointScratch,
619        resident_frontier: &mut FixedPointResidentFrontierScratch,
620        result: &mut Vec<u32>,
621    ) -> Result<(), String> {
622        self.require_sequence_layout(
623            plan,
624            "PlanBuilder::slice_reusing_frontier_sequence_window_into",
625        )?;
626        crate::slice::slice_closure_resident_plan_with_reusable_frontier_scratch_sequence_window_into(
627            backend,
628            plan.program(),
629            self.graph.graph_ref(),
630            seed_bits,
631            max_iterations,
632            scratch,
633            resident_frontier,
634            result,
635        )
636    }
637}