From de04594c6745ec13ef27fc5ec2852a0c5329c63d Mon Sep 17 00:00:00 2001 From: jsonch Date: Fri, 26 Jul 2024 19:50:51 -0400 Subject: [PATCH] reimplemented changes --- src/lib/backend/tofino/core/InlineEventVars.ml | 1 + .../backend/tofino/tofinocore/RemoveLocalInits.ml | 12 ++++++------ src/lib/backend/tofino/tofinocore/TofinoCore.ml | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/lib/backend/tofino/core/InlineEventVars.ml b/src/lib/backend/tofino/core/InlineEventVars.ml index 652f47a0..c666c085 100644 --- a/src/lib/backend/tofino/core/InlineEventVars.ml +++ b/src/lib/backend/tofino/core/InlineEventVars.ml @@ -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 diff --git a/src/lib/backend/tofino/tofinocore/RemoveLocalInits.ml b/src/lib/backend/tofino/tofinocore/RemoveLocalInits.ml index 1bff5441..bbbf1eb4 100644 --- a/src/lib/backend/tofino/tofinocore/RemoveLocalInits.ml +++ b/src/lib/backend/tofino/tofinocore/RemoveLocalInits.ml @@ -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; @@ -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. @@ -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 *) @@ -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 @@ -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 *) diff --git a/src/lib/backend/tofino/tofinocore/TofinoCore.ml b/src/lib/backend/tofino/tofinocore/TofinoCore.ml index 12e47f8c..b37a573d 100644 --- a/src/lib/backend/tofino/tofinocore/TofinoCore.ml +++ b/src/lib/backend/tofino/tofinocore/TofinoCore.ml @@ -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) -> @@ -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 @@ -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