@@ -710,7 +710,30 @@ let the_cond_of info x =
710
710
| _ -> Unknown )
711
711
x
712
712
713
- let eval_branch update_branch info l =
713
+ module Simple_block = struct
714
+ type t =
715
+ | Return of Var .t
716
+ | Expr of expr
717
+ | Branch of cont
718
+
719
+ let equal a b =
720
+ match a, b with
721
+ | Return a , Return b -> Var. equal a b
722
+ | Expr a , Expr b -> Poly. equal a b
723
+ | Branch c1 , Branch c2 -> Poly. equal c1 c2
724
+ | Return _, (Expr _ | Branch _)
725
+ | Expr _, (Return _ | Branch _)
726
+ | Branch _ , (Return _ | Expr _ ) -> false
727
+
728
+ let hash = function
729
+ | Return x -> Var. idx x
730
+ | Branch c1 -> Hashtbl. hash c1
731
+ | Expr x -> Hashtbl. hash x
732
+ end
733
+
734
+ module SBT = Hashtbl. Make (Simple_block )
735
+
736
+ let eval_branch blocks update_branch info l =
714
737
match l with
715
738
| Cond (x , ftrue , ffalse ) as b -> (
716
739
match the_cond_of info x with
@@ -721,13 +744,43 @@ let eval_branch update_branch info l =
721
744
incr update_branch;
722
745
Branch ftrue
723
746
| Unknown -> b)
724
- | Switch (x , a ) as b -> (
747
+ | Switch (x , a ) -> (
725
748
match the_cont_of info x a with
726
749
| Some cont ->
727
750
incr update_branch;
728
751
Branch cont
729
- | None -> b)
730
- | _ as b -> b
752
+ | None ->
753
+ let t = SBT. create 18 in
754
+ Switch
755
+ ( x
756
+ , Array. map a ~f: (function
757
+ | pc , [] -> (
758
+ let block = Code.Addr.Map. find pc blocks in
759
+ let sb =
760
+ match block with
761
+ | { body = [] | [ Event _ ]; branch = Return x ; params = [] } ->
762
+ Some (Simple_block. Return x)
763
+ | { body = [ Let (x, e) ] | [ Event _; Let (x, e) ]
764
+ ; branch = Return x'
765
+ ; params = []
766
+ }
767
+ when Var. equal x x' -> Some (Simple_block. Expr e)
768
+ | { body = [] | [ Event _ ]; branch = Branch c1 ; params = [] } ->
769
+ Some (Simple_block. Branch c1)
770
+ | _ -> None
771
+ in
772
+ match sb with
773
+ | None -> pc, []
774
+ | Some sb -> (
775
+ match SBT. find_opt t sb with
776
+ | Some pc' when pc' <> pc ->
777
+ incr update_branch;
778
+ pc', []
779
+ | Some _ | None ->
780
+ SBT. add t sb pc;
781
+ pc, [] ))
782
+ | cont -> cont) ))
783
+ | cont -> cont
731
784
732
785
exception May_raise
733
786
@@ -808,7 +861,7 @@ let eval update_count update_branch inline_constant ~target info blocks =
808
861
block.body
809
862
~f: (eval_instr update_count inline_constant ~target info)
810
863
in
811
- let branch = eval_branch update_branch info block.branch in
864
+ let branch = eval_branch blocks update_branch info block.branch in
812
865
{ block with Code. body; Code. branch })
813
866
blocks
814
867
0 commit comments