Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/PrincetonUniversity/lucid i…
Browse files Browse the repository at this point in the history
…nto main
  • Loading branch information
jsonch committed Jul 28, 2024
2 parents 94ee957 + bb011ae commit f63796c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/lib/backend/tofino/core/InlineEventVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ let evconstr_of_exp ctx exp =

let rec merge_contexts ctx1 ctx2 =
let event_constrs = ctx1.event_constrs @ ctx2.event_constrs in
let event_constrs = List.sort_uniq compare event_constrs in
let event_vars = List.fold_left
(fun event_vars (cid, constrs) ->
match List.assoc_opt cid event_vars with
Expand Down
12 changes: 6 additions & 6 deletions src/lib/backend/tofino/tofinocore/RemoveLocalInits.ml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ let vars_in_exp exp : cid list =
inherit [_] s_iter as super
method vars = Hashtbl.create 128;
method! visit_EVar _ cid =
Hashtbl.add (self#vars) cid true
Hashtbl.replace (self#vars) cid true
end
in
vars_read#visit_exp () exp;
Expand All @@ -113,7 +113,7 @@ let update_symbols symbols exp =
(* a variable is used after it is declared,
without an intermediate assignment. It is not
removable. *)
add symbols cid Read
Hashtbl.replace symbols cid Read
| _ -> ()
(* used without a declaration.
This can happen, e.g., params.
Expand All @@ -136,14 +136,14 @@ let find_vars_to_prealloc stmt =
(* post-visit locals (so we hit exp first) *)
super#visit_SLocal symbols id ty exp;
(* now, update the symbols table for the newly declared var *)
add symbols (Cid.id id) Declared;
Hashtbl.replace symbols (Cid.id id) Declared;

method! visit_SAssign symbols cid exp =
super#visit_SAssign symbols cid exp;
match (find_opt symbols (cid)) with
| Some(Declared) ->
(* was declared, now is declared and assigned *)
add symbols (cid) Assigned;
Hashtbl.replace symbols (cid) Assigned;
| _ -> ()

(* we need to handle branches, ensuring to update the symbols table at the end *)
Expand All @@ -161,7 +161,7 @@ let find_vars_to_prealloc stmt =
let ss2 = ht_to_list symbols2 in
let ss = ht_to_list symbols in
let ss = merge_symbols ss [ss1; ss2] in
Hashtbl.add_seq symbols (List.to_seq ss)
Hashtbl.replace_seq symbols (List.to_seq ss)
method! visit_SMatch symbols exps branches =
List.iter (super#visit_exp symbols) exps;
let bstmts = List.split branches |> snd in
Expand All @@ -176,7 +176,7 @@ let find_vars_to_prealloc stmt =
in
let ss = ht_to_list symbols in
let ss = merge_symbols ss bstmt_ss in
Hashtbl.add_seq symbols (List.to_seq ss)
Hashtbl.replace_seq symbols (List.to_seq ss)
end
in
(* traverse the program to build up the symbols table *)
Expand Down
4 changes: 4 additions & 0 deletions src/lib/backend/tofino/tofinocore/TofinoCore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ let append_and_new seqs e =
| seq :: seqs -> (seq @ [e]) :: append_to_all seqs e
;;
(* find all paths of statements that match the filter_map *)

let rec find_statement_paths paths_so_far stmt_filter stmt =
match stmt.s with
| SSeq (s1, s2) ->
Expand Down Expand Up @@ -645,6 +646,7 @@ let rec find_statement_paths paths_so_far stmt_filter stmt =


let res = s1_paths @ s2_paths in
let res = List.sort_uniq compare res in
(* let res =
find_statement_paths paths_so_far stmt_filter s1
@ find_statement_paths paths_so_far stmt_filter s2
Expand All @@ -661,6 +663,8 @@ let rec find_statement_paths paths_so_far stmt_filter stmt =
ps
in
res
(* just skip noops *)
| SNoop -> paths_so_far
| _ ->
(* base case: append this statement to all paths so far *)
(match stmt_filter stmt with
Expand Down

0 comments on commit f63796c

Please sign in to comment.