11use super :: CombDataflow ;
2- use crate :: ir_visitor:: { Action , Construct , Visitor , VisitorData } ;
2+ use crate :: {
3+ ir_passes:: {
4+ Monomorphize ,
5+ mono:: { BaseComp , MonoSig , Underlying , UnderlyingComp } ,
6+ } ,
7+ ir_visitor:: { Action , Construct , Visitor , VisitorData } ,
8+ } ;
39use easy_smt:: { self as smt, SExpr , SExprData } ;
410use fil_ir:: { self as ir, AddCtx , Ctx , DisplayCtx , MutCtx } ;
511use fil_utils:: { AttrCtx , CompNum } ;
@@ -23,22 +29,59 @@ impl From<u64> for SchedulingGoal {
2329}
2430
2531/// Sets the proper FSM Attributes for every component
26- pub struct Solve {
32+ pub struct Solve < ' comp , ' pass : ' comp > {
2733 /// Solver context
2834 sol : smt:: Context ,
2935 /// Scheduling goal
3036 goal : SchedulingGoal ,
3137 /// The expression to minimize
3238 minimize_expr : smt:: SExpr ,
33- // /// Map from ir elements to SExprs
34- // expr_map: ir::SparseInfoMap<ir::Expr, SExpr>,
35- // port_map: ir::SparseInfoMap<ir::PortIdx, SExpr>,
36- // event_map: ir::SparseInfoMap<ir::EventIdx, SExpr>,
37- // time_map: ir::SparseInfoMap<ir::TimeIdx, SExpr>,
38- // prop_map: ir::SparseInfoMap<ir::PropIdx, SExpr>,
39+
40+ /// The underlying component to be monomorphized
41+ pub underlying_idx : Underlying < ir:: Component > ,
42+ /// Underlying pointer
43+ pub pass : & ' comp mut Monomorphize < ' pass > ,
44+ /// Struct to keep track of all the mapping information from things owned by
45+ /// `underlying` to things owned by `base`
46+ pub monosig : & ' comp MonoSig ,
3947}
4048
41- impl Solve {
49+ impl < ' comp , ' pass > Solve < ' comp , ' pass >
50+ where
51+ ' pass : ' comp ,
52+ {
53+ fn new (
54+ underlying_idx : Underlying < ir:: Component > ,
55+ pass : & ' comp mut Monomorphize < ' pass > ,
56+ monosig : & ' comp MonoSig ,
57+ goal : u64 ,
58+ solver_file : Option < & str > ,
59+ ) -> Self {
60+ // We have to use Z3 as only it supports maximization of an objective function
61+ let ( name, s_opts) = ( "z3" , vec ! [ "-smt2" , "-in" ] ) ;
62+
63+ let mut sol = smt:: ContextBuilder :: new ( )
64+ . replay_file (
65+ solver_file. as_ref ( ) . map ( |s| fs:: File :: create ( s) . unwrap ( ) ) ,
66+ )
67+ . solver ( name, s_opts)
68+ . build ( )
69+ . unwrap ( ) ;
70+
71+ sol. push_many ( 1 ) . unwrap ( ) ;
72+
73+ Self {
74+ underlying_idx,
75+ pass,
76+ monosig,
77+ minimize_expr : sol. numeral ( 0 ) ,
78+ goal : goal. into ( ) ,
79+ sol,
80+ }
81+ }
82+ }
83+
84+ impl Solve < ' _ , ' _ > {
4285 /// Get the constant names for the start and end of a port
4386 pub fn get_port_name ( & self , pidx : ir:: PortIdx ) -> ( String , String ) {
4487 (
@@ -225,59 +268,15 @@ impl Solve {
225268 }
226269}
227270
228- impl Construct for Solve {
229- fn from ( opts : & crate :: cmdline:: Opts , _: & mut ir:: Context ) -> Self {
230- // We have to use Z3 as only it supports maximization of an objective function
231- let ( name, s_opts) = ( "z3" , vec ! [ "-smt2" , "-in" ] ) ;
232-
233- let mut sol = smt:: ContextBuilder :: new ( )
234- . replay_file (
235- opts. solver_replay_file
236- . as_ref ( )
237- . map ( |s| fs:: File :: create ( s) . unwrap ( ) ) ,
238- )
239- . solver ( name, s_opts)
240- . build ( )
241- . unwrap ( ) ;
242-
243- sol. push_many ( 1 ) . unwrap ( ) ;
244-
245- Self {
246- minimize_expr : sol. numeral ( 0 ) ,
247- goal : SchedulingGoal :: Latency ,
248- sol,
249- }
250- }
251-
252- fn clear_data ( & mut self ) {
253- // Create a new solver context
254- self . sol . pop_many ( 1 ) . unwrap ( ) ;
255- self . sol . push_many ( 1 ) . unwrap ( ) ;
256- }
257- }
258-
259- impl Visitor for Solve {
260- fn name ( ) -> & ' static str {
261- "schedule-solve"
262- }
263-
264- fn start ( & mut self , data : & mut VisitorData ) -> Action {
265- // Quit the pass if this attribute does not have the #[schedule] attribute
266- if let Some ( & goal) = data. comp . attrs . get ( CompNum :: Schedule ) {
267- self . goal = goal. into ( )
268- } else {
269- return Action :: Stop ;
270- }
271-
272- // make sure this component only has one event
273- assert_eq ! (
274- data. comp. events( ) . idx_iter( ) . count( ) ,
275- 1 ,
276- "Attempting to schedule a component with multiple events"
277- ) ;
278-
271+ impl Solve < ' _ , ' _ > {
272+ fn comp ( & mut self ) -> Action {
279273 // For the inputs and outputs of the component, we need to schedule them as expected.
280- for ( pidx, port) in data. comp . inputs ( ) . chain ( data. comp . outputs ( ) ) {
274+ for ( pidx, port) in self
275+ . monosig
276+ . base
277+ . inputs ( )
278+ . chain ( self . monosig . base . outputs ( ) )
279+ {
281280 let ir:: Range { start, end } = port. live . range ;
282281
283282 let start = data. comp . get ( start) . offset . concrete ( & data. comp ) ;
@@ -304,8 +303,6 @@ impl Visitor for Solve {
304303 . assert ( self . sol . eq ( self . sol . numeral ( end) , end_expr) )
305304 . unwrap ( ) ;
306305 }
307-
308- Action :: Continue
309306 }
310307
311308 fn connect (
0 commit comments