@@ -770,24 +770,36 @@ let map_loc_find loc m =
770770 try U.LocEnv. find loc m
771771 with Not_found -> []
772772
773+ (* Event set ordered by to (generalised) program order *)
774+
775+ module
776+ EvtSetByPo
777+ (I :sig val es : S.event_structure end ) =
778+ struct
779+
780+ let is_before_strict = U. is_before_strict I. es
781+
782+ include Set. Make
783+ (struct
784+
785+ type t = E .event
786+
787+ let compare e1 e2 =
788+ if is_before_strict e1 e2 then - 1
789+ else if is_before_strict e2 e1 then 1
790+ else
791+ let () =
792+ Printf. eprintf " Not ordered stores %a and %a\n " E. debug_event e1
793+ E. debug_event e2
794+ in
795+ assert false
796+
797+ end )
798+ end
799+
773800let match_reg_events add_eq es csn =
774801 let loc_loads_stores = U. collect_reg_loads_stores es in
775- let is_before_strict = U. is_before_strict es in
776- let compare e1 e2 =
777- if is_before_strict e1 e2 then - 1
778- else if is_before_strict e2 e1 then 1
779- else
780- let () =
781- Printf. eprintf " Not ordered stores %a and %a\n " E. debug_event e1
782- E. debug_event e2
783- in
784- assert false
785- in
786- let module StoreSet = Set. Make (struct
787- type t = E .event
788-
789- let compare = compare
790- end ) in
802+ let module StoreSet = EvtSetByPo (struct let es = es end ) in
791803 let add wt rf (rfm , csn ) = (S.RFMap. add wt rf rfm, add_eq rfm wt rf csn) in
792804 (* For all loads find the right store, the one "just before" the load *)
793805 U.LocEnv. fold
@@ -803,7 +815,7 @@ let match_reg_events add_eq es csn =
803815 (* Add the corresponding store for each load *)
804816 List. fold_left
805817 (fun k load ->
806- let f e = is_before_strict e load in
818+ let f e = StoreSet. is_before_strict e load in
807819 let rf =
808820 match StoreSet. find_last_opt f stores with
809821 | Some store -> S. Store store
@@ -1672,37 +1684,43 @@ let get_rf_value test read =
16721684(* Reconstruct load/store atomic pairs *)
16731685
16741686 let make_atomic_load_store es =
1675- let all = E. atomics_of es.E. events in
1676- let atms = U. collect_atomics es in
1677- U.LocEnv. fold
1678- (fun _loc atms k ->
1679- let atms =
1680- List. filter
1681- (fun e -> not (E. is_load e && E. is_store e))
1682- atms in (* get rid of C RMW *)
1683- let rs,ws = List. partition E. is_load atms in
1684- List. fold_left
1685- (fun k r ->
1686- let exp = E. is_explicit r in
1687- List. fold_left
1688- (fun k w ->
1689- if
1690- S. atomic_pair_allowed r w &&
1691- U. is_before_strict es r w &&
1692- E. is_explicit w = exp &&
1693- not
1694- (E.EventSet. exists
1695- (fun e ->
1696- E. is_explicit e = exp &&
1697- U. is_before_strict es r e &&
1698- U. is_before_strict es e w)
1699- all)
1700- then E.EventRel. add (r,w) k
1701- else k)
1702- k ws)
1703- k rs)
1704- atms E.EventRel. empty
1705-
1687+ let atms,spurious = U. collect_atomics es in
1688+ let module StoreSet = EvtSetByPo (struct let es = es end ) in
1689+ let make_atomic_pairs es k =
1690+ let rs,ws = List. partition E. is_load es in
1691+ let stores = StoreSet. of_list ws in
1692+ List. fold_left
1693+ (fun k load ->
1694+ let f e = StoreSet. is_before_strict load e in
1695+ match StoreSet. find_first_opt f stores with
1696+ | None -> k (* No matching store (e.g. final load reserve) *)
1697+ | Some store ->
1698+ if S. atomic_pair_allowed load store then
1699+ E.EventRel. add (load,store) k
1700+ else k)
1701+ k rs in
1702+ let r1 =
1703+ List. map
1704+ (fun (_ ,m ) ->
1705+ U.LocEnv. fold
1706+ (fun _loc es k ->
1707+ let exps,nexps = List. partition E. is_explicit es in
1708+ make_atomic_pairs exps @@ make_atomic_pairs nexps k)
1709+ m E.EventRel. empty)
1710+ atms |> E.EventRel. unions
1711+ and r2 =
1712+ let iico = es.E. intra_causality_data in
1713+ List. map
1714+ (fun e ->
1715+ if E. is_load e then
1716+ match
1717+ E.EventRel. succs iico e |> E.EventSet. as_singleton
1718+ with
1719+ | None -> assert false (* spurious updates are by pairs *)
1720+ | Some w -> E.EventRel. singleton (e,w)
1721+ else E.EventRel. empty)
1722+ spurious |> E.EventRel. unions in
1723+ E.EventRel. union r1 r2
17061724
17071725(* Retrieve last store from rfmap *)
17081726 let get_max_store _test _es rfm loc =
0 commit comments