Skip to content

Commit ee5f249

Browse files
committed
WIP
1 parent 8b545e4 commit ee5f249

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

compiler/lib/driver.ml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -608,29 +608,31 @@ let simplify_js js =
608608

609609
let collects_shapes p =
610610
let l = ref StringMap.empty in
611-
let t = Timer.make () in
612-
let _, info = Flow.f p in
613-
let pure = Pure_fun.f p in
614-
let return_values = Code.return_values p in
615-
Code.Addr.Map.iter
616-
(fun _ block ->
617-
List.iter block.Code.body ~f:(fun i ->
618-
match i with
619-
| Code.Let
620-
( _
621-
, Prim
622-
( Extern "caml_register_global"
623-
, [ _code; Pv block; Pc (NativeString name) ] ) ) ->
624-
let shape = Flow.the_shape_of ~return_values ~pure info block in
625-
let name =
626-
match name with
627-
| Byte s -> s
628-
| Utf (Utf8 s) -> s
629-
in
630-
l := StringMap.add name shape !l
631-
| _ -> ()))
632-
p.blocks;
633-
if times () then Format.eprintf " shapes: %a@." Timer.print t;
611+
if true
612+
then (
613+
let t = Timer.make () in
614+
let _, info = Flow.f p in
615+
let pure = Pure_fun.f p in
616+
let return_values = Code.return_values p in
617+
Code.Addr.Map.iter
618+
(fun _ block ->
619+
List.iter block.Code.body ~f:(fun i ->
620+
match i with
621+
| Code.Let
622+
( _
623+
, Prim
624+
( Extern "caml_register_global"
625+
, [ _code; Pv block; Pc (NativeString name) ] ) ) ->
626+
let shape = Flow.the_shape_of ~return_values ~pure info block in
627+
let name =
628+
match name with
629+
| Byte s -> s
630+
| Utf (Utf8 s) -> s
631+
in
632+
l := StringMap.add name shape !l
633+
| _ -> ()))
634+
p.blocks;
635+
if times () then Format.eprintf " shapes: %a@." Timer.print t);
634636
!l
635637

636638
let configure formatter =

compiler/lib/shape.ml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,34 @@ module Store = struct
132132
end
133133

134134
module State = struct
135-
type nonrec t = t Code.Var.Hashtbl.t
135+
type nonrec t =
136+
{ table : t Code.Var.Hashtbl.t
137+
; cache : BitSet.t
138+
}
136139

137-
let t : t = Code.Var.Hashtbl.create 17
140+
let t : t = { table = Code.Var.Hashtbl.create 17; cache = BitSet.create () }
138141

139-
let assign x shape = Code.Var.Hashtbl.replace t x shape
142+
let assign x shape =
143+
Code.Var.Hashtbl.replace t.table x shape;
144+
BitSet.set t.cache (Code.Var.idx x)
140145

141146
let propagate x offset target =
142-
match Code.Var.Hashtbl.find_opt t x with
147+
match Code.Var.Hashtbl.find_opt t.table x with
143148
| None -> ()
144149
| Some (Top _ | Function _) -> ()
145150
| Some (Block l) -> assign target (List.nth l offset)
146151

147-
let get x = Code.Var.Hashtbl.find_opt t x
152+
let get x = Code.Var.Hashtbl.find_opt t.table x
148153

149-
let mem x = Code.Var.Hashtbl.mem t x
154+
let mem x = BitSet.mem t.cache (Code.Var.idx x)
150155

151156
let is_pure_fun x =
152-
match Code.Var.Hashtbl.find_opt t x with
157+
match Code.Var.Hashtbl.find_opt t.table x with
153158
| None -> false
154159
| Some (Top _ | Block _) -> false
155160
| Some (Function { pure; _ }) -> pure
156161

157-
let reset () = Code.Var.Hashtbl.clear t
162+
let reset () =
163+
Code.Var.Hashtbl.clear t.table;
164+
BitSet.clear t.cache
158165
end

0 commit comments

Comments
 (0)