Skip to content

Commit d67f208

Browse files
committed
[herd] Follow suggestions (to be squashed later)
1 parent c3b869a commit d67f208

File tree

3 files changed

+68
-36
lines changed

3 files changed

+68
-36
lines changed

herd/mem.ml

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -866,43 +866,10 @@ and get_written e = match E.written_of e with
866866

867867
let map_loc_find loc m = U.LocEnv.safe_find [] loc m
868868

869-
(* Event set ordered by to (generalised) program order *)
870-
871-
module
872-
EvtSetByPo
873-
(I:sig val es : S.event_structure end) =
874-
struct
875-
876-
let is_before_strict = U.is_before_strict I.es
877-
878-
include Set.Make
879-
(struct
880-
881-
type t = E.event
882-
883-
let compare e1 e2 =
884-
if is_before_strict e1 e2 then -1
885-
else if is_before_strict e2 e1 then 1
886-
else
887-
let () =
888-
Printf.eprintf "Not ordered stores %a and %a\n" E.debug_event e1
889-
E.debug_event e2
890-
in
891-
assert false
892-
893-
end)
894-
895-
let find_last_before set e =
896-
find_last_opt (fun e' -> is_before_strict e' e) set
897-
898-
let find_first_after e set =
899-
find_first_opt (fun e' -> is_before_strict e e') set
900-
901-
end
902869

903870
let match_reg_events add_eq es csn =
904871
let loc_loads_stores = U.collect_reg_loads_stores es in
905-
let module StoreSet = EvtSetByPo(struct let es = es end) in
872+
let module StoreSet = U.EvtSetByPo(struct let es = es end) in
906873
let add wt rf (rfm, csn) = (S.RFMap.add wt rf rfm, add_eq rfm wt rf csn) in
907874
(* For all loads find the right store, the one "just before" the load *)
908875
U.LocEnv.fold
@@ -1026,6 +993,11 @@ let get_rf_value test read =
1026993
S.simplify_vars_in_rfmap sol rfm,
1027994
csn )
1028995
with Contradiction -> None
996+
| e ->
997+
let module PP = Pretty.Make(S) in
998+
eprintf "Coucou\n%!" ;
999+
PP.show_es_rfm test es S.RFMap.empty ;
1000+
raise e
10291001

10301002
let solve_regs test es csn =
10311003
profile "solve_regs" @@ fun () ->
@@ -1840,7 +1812,7 @@ let get_rf_value test read =
18401812

18411813
let make_atomic_load_store es =
18421814
let atms,spurious = U.collect_atomics es in
1843-
let module StoreSet = EvtSetByPo(struct let es = es end) in
1815+
let module StoreSet = U.EvtSetByPo(struct let es = es end) in
18441816
let make_atomic_pairs es k =
18451817
let rs,ws = List.partition E.is_load es in
18461818
let ws = StoreSet.of_list ws

herd/memUtils.ml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,41 @@ module Make(S : SemExtra.S) = struct
5858
else (* e1 and e2 are from the same instruction *)
5959
E.EventRel.exists_path (e1,e2) iico)
6060

61-
(* Fence *)
61+
(* Event set ordered by to (generalised) program order *)
62+
63+
module
64+
EvtSetByPo
65+
(I:sig val es : S.event_structure end) =
66+
struct
67+
68+
let is_before_strict = is_before_strict I.es
69+
70+
include Set.Make
71+
(struct
72+
73+
type t = E.event
74+
75+
let compare e1 e2 =
76+
if E.po_strict e1 e2 then -1
77+
else if E.po_strict e2 e1 then 1
78+
else
79+
let () =
80+
Printf.eprintf "Not ordered stores %a and %a\n" E.debug_event e1
81+
E.debug_event e2 ;
82+
in
83+
assert false
84+
85+
end)
86+
87+
let find_last_before set e =
88+
find_last_opt (fun e' -> is_before_strict e' e) set
89+
90+
let find_first_after e set =
91+
find_first_opt (fun e' -> is_before_strict e e') set
92+
93+
end
94+
95+
(* Fence *)
6296
let po_fence_po po pred =
6397
let r1 =
6498
E.EventRel.restrict_domains E.is_mem pred po

herd/memUtils.mli

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,32 @@ module Make : functor (S: SemExtra.S) -> sig
2525
val po_iico : S.event_structure -> S.event_rel
2626
(* po union iico_data union iico_control *)
2727
val is_before_strict : S.event_structure -> S.event -> S.event -> bool
28+
29+
(*
30+
* Set of events ordered by is_before_strict.
31+
* Notice it is an error to add unrelated events
32+
* to this set.
33+
*)
34+
module
35+
EvtSetByPo :
36+
functor
37+
(I:sig val es : S.event_structure end) ->
38+
sig
39+
40+
(* Strict ordering, taking iico into account for effects
41+
from the same instruction. *)
42+
val is_before_strict : S.event -> S.event -> bool
43+
44+
include Set.S with type elt = S.event
45+
46+
(* [find_last_before set e] find maximal effect in [set] before [e] *)
47+
val find_last_before : t -> S.event -> S.event option
48+
49+
(* [find_last_before set e] find minimal effect in [set] after [e] *)
50+
val find_first_after : S.event -> t -> S.event option
51+
52+
end
53+
2854
(* Fence like relations *)
2955
val po_fence_po : S.event_rel (* po *) -> (S.event -> bool) -> S.event_rel
3056

0 commit comments

Comments
 (0)