@@ -125,25 +125,27 @@ module Unroll = struct
125125 (match deq.content with
126126 | Eqn (lhs , e , sync ) ->
127127 Eqn (List. map (unroll_var env_it) lhs, unroll_expr env_it e, sync)
128- | Loop ( i , ei , ef , dl , opts ) ->
128+ | Loop t ->
129129 Loop
130- ( i,
131- simpl_arith env_it ei,
132- simpl_arith env_it ef,
133- List. map (unroll_deq env_it) dl,
134- opts ));
130+ {
131+ t with
132+ start = simpl_arith env_it t.start;
133+ stop = simpl_arith env_it t.stop;
134+ body = List. map (unroll_deq env_it) t.body;
135+ });
135136 }
136137
137- (* |i |, |ei |, |ef | and |deqs | are from the loop being expanded,
138- which should be like Loop(i, ei, ef, deqs, _)
138+ (* |id |, |start |, |stop | and |body | are from the loop being expanded,
139+ which should be like Loop {id; start; stop; body; _}
139140 *)
140- let do_unroll (i : ident ) (ei : int ) (ef : int ) (deqs : deq list ) : deq list =
141+ let do_unroll (id : ident ) (start : int ) (stop : int ) (body : deq list ) :
142+ deq list =
141143 let env_it = Ident.Hashtbl. create 1 in
142144 flat_map
143145 (fun i_val ->
144- Ident.Hashtbl. replace env_it i i_val;
145- List. map (unroll_deq env_it) deqs )
146- (gen_list_bounds ei ef )
146+ Ident.Hashtbl. replace env_it id i_val;
147+ List. map (unroll_deq env_it) body )
148+ (gen_list_bounds start stop )
147149end
148150
149151(* We need two functions to propagate the expansion into variables,
@@ -240,26 +242,27 @@ let rec propagate_deqs (expand_env : var list VarHashtbl.t) (deqs : deq list) :
240242 sync );
241243 };
242244 ]
243- | Loop ( i , ei , ef , dl , opts ) -> (
245+ | Loop t -> (
244246 try
245247 [
246248 {
247249 d with
248- content = Loop (i, ei, ef, propagate_deqs expand_env dl, opts);
250+ content =
251+ Loop { t with body = propagate_deqs expand_env t.body };
249252 };
250253 ]
251254 with Need_unroll ->
252255 (* raise one more Need_unroll if ei/ef can't be computed
253256 because they are in a nested loop and use surrounding
254257 loop variable *)
255- let ei =
256- try eval_arith_ne ei with Not_found -> raise Need_unroll
258+ let start =
259+ try eval_arith_ne t.start with Not_found -> raise Need_unroll
257260 in
258- let ef =
259- try eval_arith_ne ef with Not_found -> raise Need_unroll
261+ let stop =
262+ try eval_arith_ne t.stop with Not_found -> raise Need_unroll
260263 in
261264
262- let new_eqns = Unroll. do_unroll i ei ef dl in
265+ let new_eqns = Unroll. do_unroll t.id start stop t.body in
263266 propagate_deqs expand_env new_eqns))
264267 deqs
265268
@@ -438,12 +441,12 @@ let rec expand_deq (env_fun : def Ident.Hashtbl.t)
438441 let args = match_args env_fun env_var f f.p_in args in
439442 let ret = match_ret env_fun env_var f f.p_out lhs in
440443 Eqn (ret, Fun (id, args), sync)
441- | Loop ( i , ei , ef , dl , opts ) ->
442- Ident.Hashtbl. add env_var i Nat ;
444+ | Loop t ->
445+ Ident.Hashtbl. add env_var t.id Nat ;
443446 let res =
444- Loop (i, ei, ef, List. map (expand_deq env_fun env_var) dl, opts)
447+ Loop { t with body = List. map (expand_deq env_fun env_var) t.body }
445448 in
446- Ident.Hashtbl. remove env_var i ;
449+ Ident.Hashtbl. remove env_var t.id ;
447450 res
448451 | _ -> deq.content);
449452 }
0 commit comments