-
Notifications
You must be signed in to change notification settings - Fork 2
/
LocalInfo.v
1219 lines (1155 loc) · 38.2 KB
/
LocalInfo.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Set Implicit Arguments.
Require Import Coq.Lists.List.
Require Import Coq.Program.Tactics.
Require Import Tid.
Require Import Lang.
Require Import Mid.
Require AccessHistory.
Require Import Node.
Require Import CG.
Require SJ_CG.
Require Import Trace.
Require Import Omega.
Module Locals.
Section Defs.
Variable A:Type.
Inductive op :=
| NEW: op
| COPY : node -> op
| CONS : A -> node -> op
| UNION : node -> node -> op.
Definition task_local := list A.
Definition local_memory := MN.t task_local.
Definition empty : local_memory := MN.empty task_local.
Inductive Reduces (m:local_memory): (node * op) -> local_memory -> Prop :=
| reduces_new:
forall n,
~ MN.In n m ->
Reduces m (n, NEW) (MN.add n nil m)
| reduces_copy:
forall l n n',
MN.MapsTo n l m ->
~ MN.In n' m ->
Reduces m (n', COPY n) (MN.add n' l m)
| reduces_cons:
forall l x n n',
MN.MapsTo n l m ->
~ MN.In n' m ->
Reduces m (n', CONS x n) (MN.add n' (x::l) m)
| reduces_union:
forall n n1 n2 l1 l2,
MN.MapsTo n1 l1 m ->
MN.MapsTo n2 l2 m ->
Reduces m (n, UNION n1 n2) (MN.add n (l1++l2) m).
Inductive MapsTo (n:node) (x:A) (ls:local_memory) : Prop :=
| local_def:
forall l,
MN.MapsTo n l ls ->
List.In x l ->
MapsTo n x ls.
Lemma maps_to_to_in:
forall n x l,
MapsTo n x l ->
MN.In n l.
Proof.
intros.
inversion H.
eauto using MN_Extra.mapsto_to_in.
Qed.
Lemma maps_to_inv_add:
forall n n' d (l:local_memory) h,
MapsTo n d (MN.add n' h l) ->
(n' = n /\ In d h) \/ (n' <> n /\ MapsTo n d l).
Proof.
intros.
inversion H; subst; clear H.
rewrite MN_Facts.add_mapsto_iff in *.
destruct H0 as [(?,?)|(?,?)]. {
subst.
auto.
}
eauto using local_def.
Qed.
End Defs.
Ltac simpl_red :=
repeat match goal with
| [ H1: Reduces _ (_, NEW _) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces _ (_, COPY _ _) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces _ (_, CONS _ _) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces _ (_, UNION _ _ _) _ |- _ ] =>
inversion H1; subst; clear H1
end.
End Locals.
Section Defs.
Require Import Trace.
Import Locals.
Inductive Mem : Trace.trace -> computation_graph -> local_memory datum -> Prop :=
| mem_nil:
Mem nil (nil, nil) (Locals.empty datum)
| mem_init:
forall l l' x vs es t,
Mem t (vs, es) l ->
CG.T.CG ((x,INIT)::t) (x::vs,es) ->
(* Add d to the locals of x *)
Locals.Reduces l (fresh vs, NEW datum) l' ->
Mem ((x, INIT)::t) (x::vs, es) l'
| mem_alloc:
forall l n n' d l' r es t x vs,
Mem t (vs, es) l ->
(* a global alloc is a continue edge in the CG *)
CG.T.CG ((x,(MEM r ALLOC))::t) (x::vs, C (n, n') :: es) ->
(* the datum being alloc'ed is a local *)
Locals.MapsTo n d l ->
(* add reference y to the locals of task x *)
Locals.Reduces l (n', CONS (d_mem r) n) l' ->
Mem ((x,(MEM r ALLOC))::t) (x::vs, C (n, n') :: es) l'
| reduces_read:
forall l d n n' r l' es vs t x,
Mem t (vs,es) l ->
(* a read is a continue edge in the CG *)
CG.T.CG ((x,(MEM r (READ d)))::t) (x::vs, C (n, n') :: es) ->
(* the reference y is in the locals of task x *)
Locals.MapsTo n (d_mem r) l ->
(* add datum d to the locals of x *)
Locals.Reduces l (n', CONS d n) l' ->
Mem ((x,(MEM r (READ d)))::t) (x::vs, C (n, n') :: es) l'
| mem_write:
forall l r d n n' es l' vs t x,
Mem t (vs,es) l ->
(* a global write is a continue in the CG *)
CG.T.CG ((x,(MEM r (WRITE d)))::t) (x::vs, C (n, n') :: es) ->
(* datum d being written is in the locals of task x *)
Locals.MapsTo n d l ->
(* the target reference is also in the locals of task x *)
Locals.MapsTo n (d_mem r) l ->
Locals.Reduces l (n', COPY datum n) l' ->
Mem ((x,(MEM r (WRITE d)))::t) (x::vs, C (n, n') :: es) l'
| mem_future:
forall x nx nx' ny l y l' l'' es t vs,
Mem t (vs,es) l ->
CG.T.CG ((x,FUTURE y)::t) (y::x::vs, F (nx, ny) :: C (nx, nx') :: es) ->
(* add task y to the locals of x *)
Locals.Reduces l (nx', CONS (d_task y) nx) l' ->
(* set the locals of y to be ds *)
Locals.Reduces l' (ny, COPY datum nx) l'' ->
Mem ((x,FUTURE y)::t) (y::x::vs, F (nx, ny) :: C (nx, nx') :: es) l''
| mem_force:
forall l nx nx' ny d l' vs es t x y,
Mem t (vs,es) l ->
(* CG reduced with a join *)
CG.T.CG ((x,FORCE y)::t) (x::vs, J (ny,nx') :: C (nx,nx') :: es) ->
(* Datum d is in the locals of y *)
Locals.MapsTo ny d l ->
(* Task y is in the local memory of nx *)
Locals.MapsTo nx (d_task y) l ->
(* Add d to the locals of x *)
Locals.Reduces l (nx', UNION datum nx ny) l' ->
Mem ((x,FORCE y)::t) (x::vs, J (ny,nx') :: C (nx,nx') :: es) l'.
Inductive LocalKnows (cg:computation_graph) (l:local_memory datum) : tid * tid -> Prop :=
| local_knows_def:
forall n x y,
TaskOf n x (fst cg) ->
Locals.MapsTo n (d_task y) l ->
LocalKnows cg l (x, y).
End Defs.
Ltac simpl_structs :=
repeat simpl in *; match goal with
| [ H2: ?x = ?x |- _ ] => clear H2
| [ H2: _ :: _ = _ :: _ |- _ ] => inversion H2; subst; clear H2
| [ H2:(_,_) = (_,_) |- _ ] => inversion H2; subst; clear H2
| [ H2: Some _ = Some _ |- _ ] => inversion H2; subst; clear H2
| [ H1: ?P, H2: ?P |- _ ] => clear P
end.
(*
Ltac simpl_red :=
match goal with
| [ H1: Reduces (_::_,_::_) _ CONTINUE _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_,_::_) _ (MEM _ ALLOC) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_,_::_) _ (MEM _ (WRITE _)) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_,_::_) _ (MEM _ (READ _)) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_::_,_::_::_) _ (FUTURE _) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_,_::_::_) _ (FORCE _) _ |- _ ] =>
inversion H1; subst; clear H1
| [ H1: Reduces (_::_,_) _ INIT _ |- _ ] =>
inversion H1; subst; clear H1
end;
simpl_structs.
Ltac handle_all :=
try SJ_CG.simpl_red;
try CG.simpl_red;
try simpl_red;
try Locals.simpl_red;
(* try Shadow.simpl_red;*)
try simpl_structs;
simpl in *.
*)
Section SR.
(*
Definition op_to_cg (o:op) : CG.op :=
match o with
| INIT => CG.INIT
| MEM _ _ => CG.CONTINUE
| FUTURE x => CG.FORK x
| FORCE x => CG.JOIN x
end.
Definition event_to_cg (e:event) : CG.event :=
let (x,o) := e in (x, op_to_cg o).
*)
Definition LocalToKnows (l:Locals.local_memory datum) cg sj :=
forall p,
LocalKnows cg l p ->
SJ_CG.Knows (fst cg) sj p.
Definition LastWriteKnows (cg:computation_graph) (g:AccessHistory.T.cg_access_history) l :=
forall x y n h r,
MM.MapsTo r h g ->
AccessHistory.LastWrite (HB (snd cg)) (n, Some (d_task y)) h ->
TaskOf n x (fst cg) ->
LocalKnows cg l (x, y).
Ltac expand H := inversion H; subst; clear H.
Let knows_eq:
forall l ls (x y:tid) n vs es,
MN.MapsTo n l ls ->
In (d_task y) l ->
MapsTo x n vs ->
LocalKnows (vs, es) ls (x, y).
Proof.
eauto using local_knows_def, Locals.local_def, maps_to_to_task_of.
Qed.
Section DomIncl.
Let DomIncl (l:Locals.local_memory datum) (vs:list tid) :=
forall n,
MN.In n l ->
Node n vs.
Let mem_to_dom_incl:
forall t l cg,
Mem t cg l ->
DomIncl l (fst cg).
Proof.
induction t; intros. {
inversion H; subst; clear H.
unfold DomIncl; intros.
rewrite MN_Facts.empty_in_iff in *.
contradiction.
}
unfold DomIncl in *; inversion H; subst; clear H; intros;
match goal with
[ H: (T.CG _) _ |- _] => inversion H; subst; clear H
end;
Locals.simpl_red; simpl_node;
assert (Hx := IHt _ _ H2);
try (rewrite MN_Facts.add_in_iff in *);
try (
destruct H; try (
subst; simpl;
auto using node_eq
);
simpl; auto using node_cons
).
rewrite MN_Facts.add_mapsto_iff in H3.
destruct H3 as [(?,?)|(?,mt)]. {
subst.
simpl_node.
}
assert (l1 = l) by eauto using MN_Facts.MapsTo_fun; subst.
rewrite MN_Facts.add_in_iff in *.
destruct H. {
subst.
auto using node_eq, node_cons.
}
eauto using node_cons.
Qed.
Lemma mem_in_to_node:
forall t l vs es n,
Mem t (vs,es) l ->
MN.In n l ->
Node n vs.
Proof.
intros.
apply mem_to_dom_incl in H.
apply H in H0.
auto.
Qed.
End DomIncl.
Section MemCG.
Lemma mem_to_cg:
forall t cg l,
Mem t cg l ->
CG.T.CG t cg.
Proof.
induction t; intros. {
inversion H; subst; clear H.
auto using CG.cg_nil.
}
inversion H; subst; clear H;
auto using CG.cg_init, CG.cg_continue, CG.cg_fork, CG.cg_join.
Qed.
End MemCG.
Section LocalToKnows.
Ltac handle_all :=
simpl in *;
SJ_CG.do_simpl;
Locals.simpl_red;
CG.simpl_red.
Lemma local_knows_inv_add:
forall x vs n es h l a b,
LocalKnows (x :: vs, C (n, fresh vs) :: es) (MN.add (fresh vs) h l) (a, b) ->
(a = x /\ In (d_task b) h) \/
MN.In (fresh vs) l \/
LocalKnows (vs, es) l (a,b).
Proof.
intros.
inversion H; subst; clear H; simpl in *.
apply task_of_inv in H2.
apply Locals.maps_to_inv_add in H3.
destruct H2 as [(?,?)|?]. {
destruct H3 as [(?,?)|(?,?)]; subst; eauto using Locals.maps_to_to_in.
}
destruct H3 as [(?,?)|(?,?)]. {
subst.
simpl_node.
}
eauto using local_knows_def.
Qed.
Lemma local_knows_inv_init:
forall x vs es l p,
LocalKnows (x :: vs, es) (MN.add (fresh vs) nil l) p ->
MN.In (fresh vs) l \/ LocalKnows (vs, es) l p.
Proof.
intros.
inversion H; subst; clear H.
apply Locals.maps_to_inv_add in H1.
apply task_of_inv in H0.
simpl in *.
destruct H1 as [(?,?)|(?,?)]. {
contradiction.
}
destruct H0 as [(?,?)|?]. {
subst.
apply Locals.maps_to_to_in in H1.
auto.
}
eauto using local_knows_def.
Qed.
Lemma local_knows_inv_alloc:
forall x vs n es h a b l r,
LocalKnows
(x :: vs, C (n, fresh vs) :: es)
(MN.add (fresh vs) (d_mem r :: h) l)
(a,b) ->
MN.MapsTo n h l ->
MapsTo x n vs ->
(a = x /\ LocalKnows (vs, es) l (a,b))
\/
MN.In (fresh vs) l
\/
LocalKnows (vs, es) l (a,b).
Proof.
intros.
inversion H; subst; clear H.
simpl in *.
apply task_of_inv in H4.
apply Locals.maps_to_inv_add in H5.
destruct H5 as [(?,?)|(?,?)]. {
destruct H4 as [(?,?)|?]. {
subst.
inversion H2. {
inversion H3.
}
apply maps_to_to_task_of in H1.
left.
split; auto.
apply local_knows_def with (n:=n); simpl;
eauto using maps_to_to_task_of, Locals.local_def.
}
subst.
simpl_node.
}
destruct H4 as [(?,?)|?]. {
subst.
eauto using Locals.maps_to_to_in.
}
eauto using local_knows_def.
Qed.
Lemma local_knows_inv_future:
forall n h1 h2 l1 vs x a b y es,
MN.MapsTo n h2 (MN.add (fresh vs) (d_task y :: h1) l1) ->
MN.MapsTo n h1 l1 ->
MapsTo x n vs ->
~ MN.In (fresh vs) l1 ->
LocalKnows
(y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es)
(MN.add (fresh (x :: vs)) h2 (MN.add (fresh vs) (d_task y :: h1) l1))
(a, b) ->
h1 = h2 /\
(
(a = y /\ LocalKnows (vs, es) l1 (x,b)) \/
(a = x /\ y = b) \/
(a = x /\ LocalKnows (vs, es) l1 (a,b)) \/
LocalKnows (vs, es) l1 (a,b)
).
Proof.
intros.
assert (h2 = h1). {
rewrite MN_Facts.add_mapsto_iff in *.
destruct H as [(?,?)|(?,mt)].
- subst.
contradiction H2.
eauto using MN_Extra.mapsto_to_in.
- eauto using MN_Facts.MapsTo_fun.
}
subst; clear H.
inversion H3; subst; clear H3.
simpl in *.
apply task_of_inv in H5. (* TaskOf _ _ _ *)
apply Locals.maps_to_inv_add in H6. (* Locals.MapsTo _ _ _ *)
destruct H5 as [(?,?)|Ht]. {
destruct H6 as [(?,?)|(?,?)]. {
eauto.
}
subst.
contradiction.
}
apply task_of_inv in Ht. (* TaskOf _ _ _ *)
destruct Ht as [(?,?)|Ht]. {
destruct H6 as [(?,?)|(?,Hl)]. {
subst.
unfold fresh in *.
inversion H4 (* make _ = make _ *).
omega. (* absurd *)
}
apply Locals.maps_to_inv_add in Hl. (* Locals.MapsTo _ _ _ *)
destruct Hl as [(?,Hi)|(?, Hl)]. {
simpl in Hi.
destruct Hi. {
inversion H6; clear H6. (* d_task _ = d_task _ *)
auto.
}
subst.
split; auto.
right.
right.
left.
eauto.
}
subst.
contradiction.
}
destruct H6 as [(?,Hi)|(?,Hl)]. {
subst.
rewrite fresh_cons_rw_next in *.
apply task_of_to_node in Ht.
simpl_node.
}
apply Locals.maps_to_inv_add in Hl. (* Locals.MapsTo _ _ _ *)
destruct Hl as [(?,Hi)|(?,Hl)]. {
subst.
simpl_node.
}
intuition.
right; right; right.
eapply local_knows_def; eauto.
Qed.
Lemma local_knows_inv_read:
forall x vs n es d h l a b,
LocalKnows (x :: vs, C (n, fresh vs) :: es)
(MN.add (fresh vs) (d :: h) l) (a,b) ->
(a = x /\ In (d_task b) (d :: h)) \/
MN.In (fresh vs) l \/
LocalKnows (vs, es) l (a,b).
Proof.
intros.
inversion H; subst; clear H; simpl in *.
apply task_of_inv in H2.
apply Locals.maps_to_inv_add in H3.
destruct H2 as [(?,?)|?]. {
destruct H3 as [(?,?)|(?,?)]; subst; eauto using Locals.maps_to_to_in.
}
destruct H3 as [(?,?)|(?,?)]. {
subst.
simpl_node.
}
eauto using local_knows_def.
Qed.
Let local_to_knows_init:
forall x vs es sj l l' t,
SJ_CG.SJ (map T.event_to_cg ((x, INIT) :: t)) (x :: vs, es) (SJ_CG.Nil :: sj) ->
Mem t (vs, es) l ->
LocalToKnows l (vs, es) sj ->
Locals.Reduces l (fresh vs, Locals.NEW datum) l' ->
LocalToKnows l' (x :: vs, es) (SJ_CG.Nil :: sj).
Proof.
intros.
handle_all.
assert (cg = (vs,es)) by eauto using SJ_CG.sj_cg_fun; subst;
clear H5.
unfold LocalToKnows; intros.
apply local_knows_inv_init in H.
destruct H as [H|H]. {
eapply mem_in_to_node in H; eauto.
simpl_node.
}
apply H1 in H.
simpl in *.
destruct p.
auto using SJ_CG.knows_init.
Qed.
Let mem_sj_to_cg_fun:
forall t cg l cg' sj,
Mem t cg l ->
SJ_CG.SJ (map T.event_to_cg t) cg' sj ->
cg = cg'.
Proof.
intros.
apply mem_to_cg in H;
apply SJ_CG.sj_to_cg in H0;
eauto using cg_fun.
Qed.
Let LastWriteCanJoin (cg:computation_graph) sj (ah:AccessHistory.T.cg_access_history) :=
forall x a h r,
MM.MapsTo r h ah ->
AccessHistory.LastWrite (HB (snd cg)) a h ->
AccessHistory.a_what a = Some (Trace.d_task x) ->
SJ_CG.CanJoin (AccessHistory.a_when a) x sj.
Let local_to_knows_alloc:
forall x vs es sj l l' t n n' d r,
SJ_CG.SJ (map T.event_to_cg ((x, MEM r ALLOC) :: t))
(x :: vs, C (n, n') :: es) (SJ_CG.Copy n :: sj) ->
Mem t (vs, es) l ->
LocalToKnows l (vs, es) sj ->
Locals.Reduces l (n', Locals.CONS (d_mem r) n) l' ->
Locals.MapsTo n d l ->
LocalToKnows l' (x :: vs, C (n, n') :: es) (SJ_CG.Copy n :: sj).
Proof.
intros.
handle_all.
assert (cg=(vs,es)). {
apply SJ_CG.sj_to_cg in H7.
eauto using cg_fun.
}
subst.
rename l0 into h.
clear H6. (* CG *)
unfold LocalToKnows in *; intros.
destruct p as (a,b).
apply local_knows_inv_alloc in H; auto.
destruct H as [(?,?)|[?|?]].
- subst.
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
- eapply mem_in_to_node in H; eauto.
simpl_node.
- destruct (tid_eq_dec x a). {
subst.
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
}
eauto using SJ_CG.knows_cons.
Qed.
Let local_to_knows_read:
forall x r d t sj es vs n n' l l' ah ah',
AccessHistory.T.DRF ((x, MEM r (READ d)) :: t)
(x :: vs, C (n, n') :: es) ah ->
SJ_CG.SJ (map T.event_to_cg ((x, MEM r (READ d)) :: t))
(x :: vs, C (n, n') :: es) (SJ_CG.Copy n :: sj) ->
Mem t (vs, es) l ->
Locals.MapsTo n (d_mem r) l ->
Locals.Reduces l (n', Locals.CONS d n) l' ->
LastWriteCanJoin (vs, es) sj ah' ->
AccessHistory.T.DRF t (vs, es) ah' ->
LocalToKnows l (vs, es) sj ->
LocalToKnows l' (x :: vs, C (n, n') :: es) (SJ_CG.Copy n :: sj).
Proof.
intros.
rename H4 into Hcj.
rename H5 into Hdrf0.
rename H6 into Hltk.
inversion H; subst; rename H into Hdrf;
simpl in *; inversion H12 (* op_to_ah _ = Some _ *);
subst; clear H12 H11 (* CG *).
handle_all.
assert (cg0=(vs,es)). {
apply SJ_CG.sj_to_cg in H6.
eauto using cg_fun.
}
assert (cg = (vs,es)). {
apply AccessHistory.T.drf_to_cg in H9.
eauto using cg_fun.
}
subst.
clear H5. (* CG *)
rename l0 into h.
unfold LocalToKnows in *; intros.
destruct p as (a,b).
apply local_knows_inv_read in H.
assert (ah0 = ah') by eauto using AccessHistory.T.drf_fun; subst.
destruct H as [(?,Hi)|[N|Hlk]].
- subst.
destruct Hi. {
(** this is the crucial step of the proof *)
(* d_task b = d *)
subst.
assert (Hdrf1 := Hdrf).
eapply AccessHistory.T.drf_check_inv_read_last_write with (x:=x) in Hdrf; eauto.
destruct Hdrf as (h', (a, (mt, (Hw, (?,?))))).
eapply SJ_CG.knows_def; eauto using maps_to_eq.
assert (R: fresh vs = fresh sj). {
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
apply SJ_CG.can_join_copy.
eapply CG.hb_inv_continue_1 in H0; eauto. {
destruct H0; subst;
unfold LastWriteCanJoin in *;
eapply Hcj with (r:=r) in Hw; eauto using SJ_CG.hb_spec.
}
apply AccessHistory.T.drf_to_cg in Hdrf1; simpl in *.
eauto.
}
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
- contradiction.
- destruct (tid_eq_dec x a). {
subst.
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
}
eauto using SJ_CG.knows_cons.
Qed.
Let last_write_can_join_init:
forall vs es ah x sj,
LastWriteCanJoin (vs, es) sj ah ->
LastWriteCanJoin (x :: vs, es) (SJ_CG.Nil :: sj) ah.
Proof.
unfold LastWriteCanJoin; intros.
simpl in *.
eauto using SJ_CG.can_join_cons.
Qed.
Let last_write_can_join_continue:
forall vs es sj ah n x t o,
AccessHistory.T.DRF t (vs, es) ah ->
AccessHistory.T.DRF ((x, o) :: t) (x :: vs, C (n, fresh vs) :: es) ah ->
LastWriteCanJoin (vs, es) sj ah ->
LastWriteCanJoin (x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj) ah.
Proof.
unfold LastWriteCanJoin; intros.
simpl in *.
eapply AccessHistory.T.last_write_inv_c in H3; eauto.
eauto using SJ_CG.can_join_cons.
Qed.
Let last_write_can_join_read:
forall vs es sj ah ah' x n r d t,
AccessHistory.T.DRF t (vs,es) ah ->
AccessHistory.T.DRF ((x,Trace.MEM r (Trace.READ d))::t) (x::vs,C (n, fresh vs) :: es) ah' ->
LastWriteCanJoin (vs, es) sj ah ->
AccessHistory.Add (HB (C (n, fresh vs) :: es)) ah
(r, fresh vs, (AccessHistory.READ, d)) ah' ->
LastWriteCanJoin (x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj) ah'.
Proof.
intros.
inversion H2; subst; clear H2.
simpl in *.
unfold LastWriteCanJoin; intros.
rewrite MM_Facts.add_mapsto_iff in *.
destruct H2 as [(?,Hi)|(?,?)];
unfold LastWriteCanJoin in *.
- simpl in *.
subst.
clear H9.
apply AccessHistory.last_write_inv_cons_read in H3.
apply AccessHistory.T.drf_to_cg in H0.
eapply AccessHistory.T.last_write_inv_hb in H10; eauto.
eapply AccessHistory.T.last_write_inv_hb in H3; eauto.
assert (a = (n', Some d))
by eauto using AccessHistory.T.drf_last_write_fun; subst; simpl in *.
inversion H4; subst; clear H4.
eapply H1 with (x:=x0) in H3; simpl; eauto.
auto using SJ_CG.can_join_cons.
- simpl in*.
apply AccessHistory.T.drf_to_cg in H0.
eapply AccessHistory.T.last_write_inv_hb in H3; eauto.
eauto using SJ_CG.can_join_cons.
Qed.
Let local_to_knows_write:
forall x vs es sj l l' t n d r,
SJ_CG.SJ (map T.event_to_cg ((x, MEM r (WRITE d)) :: t))
(x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj) ->
Mem t (vs, es) l ->
LocalToKnows l (vs, es) sj ->
Locals.Reduces l (fresh vs, Locals.COPY datum n) l' ->
LocalToKnows l' (x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj).
Proof.
intros.
handle_all.
assert (cg = (vs,es)) by eauto using SJ_CG.sj_cg_fun; subst;
clear H8 (* CG *).
unfold LocalToKnows; intros.
rename l0 into h.
destruct p as (a,b).
apply local_knows_inv_add in H.
destruct H as [(?,H)|[H|H]].
- subst.
simpl.
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
- contradiction.
- destruct (tid_eq_dec a x). {
subst.
eapply SJ_CG.knows_copy; eauto using SJ_CG.sj_to_length_0.
}
apply SJ_CG.knows_cons; auto.
Qed.
Let last_write_can_join_write:
forall vs es sj ah ah' x n r d t l,
AccessHistory.T.DRF t (vs,es) ah ->
AccessHistory.T.DRF ((x,Trace.MEM r (Trace.WRITE d))::t) (x::vs,C (n, fresh vs) :: es) ah' ->
LastWriteCanJoin (vs, es) sj ah ->
AccessHistory.Add (HB (C (n, fresh vs) :: es)) ah
(r, fresh vs, (AccessHistory.WRITE, d)) ah' ->
SJ_CG.SJ (map T.event_to_cg ((x, MEM r (WRITE d)) :: t))
(x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj) ->
LocalToKnows l (vs, es) sj ->
Locals.MapsTo n d l ->
MapsTo x n vs ->
LastWriteCanJoin (x :: vs, C (n, fresh vs) :: es) (SJ_CG.Copy n :: sj) ah'.
Proof.
intros.
rename H3 into Hsj.
rename H4 into Hlk.
rename H5 into Hr.
rename H6 into Hmt.
unfold LastWriteCanJoin; intros.
eapply AccessHistory.T.last_write_inv_write in H4; eauto.
(** Crucial part of the proof *)
destruct H4 as [(?,(?,(?,?)))|[(?,(?,?))|(?,(?,(l',(?,?))))]];
subst; simpl in *;
eauto using SJ_CG.can_join_cons. (* take care of the inductive case *)
- (* first write *)
inversion H5; subst; clear H5. (* Some _ = Some (d_task _ ) *)
assert (R: fresh vs = fresh sj). {
inversion Hsj; subst.
inversion H13; subst; clear H13. (* CG *)
assert (cg = (vs, es)) by eauto using SJ_CG.sj_to_cg, cg_fun.
subst.
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
(* Task x is writing x0, and we know from this rule that x0 is in
the local info. But from the local-to-knows property, then
x knows x0. *)
apply SJ_CG.can_join_copy.
unfold LocalToKnows in *.
assert (Hlk': LocalKnows (vs,es) l (x, x0)). {
apply local_knows_def with (n:=n); auto using maps_to_to_task_of.
}
apply Hlk in Hlk'.
(* If x knows x0 and x mapsto n, then n can join with x0. *)
inversion Hlk'; subst; simpl in *; simpl_node.
assumption.
- (* update write *)
subst.
simpl in *.
(* a_what _ = Some (d_task _) *)
inversion H5; subst; clear H5.
assert (R: fresh vs = fresh sj). {
inversion Hsj; subst.
inversion H13; subst; clear H13. (* CG *)
assert (cg = (vs, es)) by eauto using SJ_CG.sj_to_cg, cg_fun.
subst.
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
(* Task x is writing x0, and we know from this rule that x0 is in
the local info. But from the local-to-knows property, then
x knows x0. *)
apply SJ_CG.can_join_copy.
unfold LocalToKnows in *.
assert (Hlk': LocalKnows (vs,es) l (x, x0)). {
apply local_knows_def with (n:=n); auto using maps_to_to_task_of.
}
apply Hlk in Hlk'.
(* If x knows x0 and x mapsto n, then n can join with x0. *)
inversion Hlk'; subst; simpl in *; simpl_node.
assumption.
Qed.
Let last_write_can_join_future:
forall vs es sj ah x y n t,
AccessHistory.T.DRF ((x, FUTURE y) :: t)
(y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es) ah ->
LastWriteCanJoin (vs, es) sj ah ->
LastWriteCanJoin
(y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es)
(SJ_CG.Copy n :: SJ_CG.Cons y n :: sj) ah.
Proof.
unfold LastWriteCanJoin; intros.
simpl in *.
assert (mt := H1).
eapply AccessHistory.T.last_write_inv_future in H1; eauto
using SJ_CG.can_join_cons.
Qed.
Lemma fresh_eq_cons:
forall A B (a:A) (b:B) (l1:list A) (l2:list B),
fresh l1 = fresh l2 ->
fresh (a :: l1) = fresh (b :: l2).
Proof.
intros.
unfold fresh in *.
inversion H.
simpl.
rewrite H1.
auto.
Qed.
Let local_to_knows_future:
forall y x vs es sj l1 l2 l3 t n,
SJ_CG.SJ (map T.event_to_cg ((x, FUTURE y) :: t))
(y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es)
(SJ_CG.Copy n :: SJ_CG.Cons y n :: sj) ->
Mem t (vs, es) l1 ->
LocalToKnows l1 (vs, es) sj ->
Locals.Reduces l1 (fresh vs, Locals.CONS (d_task y) n) l2 ->
Locals.Reduces l2 (fresh (x :: vs), Locals.COPY datum n) l3 ->
LocalToKnows l3
(y :: x :: vs, F (n, fresh (x :: vs)) :: C (n, fresh vs) :: es)
(SJ_CG.Copy n :: SJ_CG.Cons y n :: sj).
Proof.
intros.
handle_all.
assert (cg=(vs,es)). {
apply SJ_CG.sj_to_cg in H6. (* SJ_CG.SJ *)
eauto using cg_fun.
}
subst.
rename l into h2.
rename l0 into h1.
unfold LocalToKnows in *; intros.
destruct p as (a,b).
apply local_knows_inv_future in H; auto.
destruct H as (?,[(?,Hl)|[(?,?)|[(?,Hl)|Hl]]]); subst; simpl.
- apply H1 in Hl.
inversion Hl; subst; clear Hl.
simpl in *; simpl_node.
apply SJ_CG.knows_def with (nx:=fresh (x::vs)); auto using maps_to_eq.
assert (R: fresh (x::vs) = fresh (SJ_CG.Cons y nx :: sj)). {
eauto using fresh_eq_cons, SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
auto using SJ_CG.can_join_copy, SJ_CG.can_join_cons.
- apply SJ_CG.knows_def with (nx:=fresh vs). {
apply maps_to_cons. {
unfold not; intros; subst.
apply maps_to_to_in in H19.
contradiction.
}
simpl.
apply maps_to_eq.
}
assert (R: fresh vs = fresh sj). {
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
auto using SJ_CG.can_join_cons, SJ_CG.can_join_eq.
- apply H1 in Hl.
inversion Hl; subst; clear Hl.
simpl in *; simpl_node.
apply SJ_CG.knows_def with (nx:=fresh vs). {
apply maps_to_cons. {
unfold not; intros; subst.
apply maps_to_to_in in H19.
contradiction.
}
simpl.
apply maps_to_eq.
}
assert (R: fresh vs = fresh sj). {
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
assert (b <> y). {
unfold not; intros; subst.
eapply SJ_CG.can_join_to_in in H4; eauto.
}
auto using SJ_CG.can_join_cons, SJ_CG.can_join_neq.
- apply H1 in Hl.
inversion Hl; subst; clear Hl.
simpl in *; simpl_node.
destruct (tid_eq_dec x a). {
subst.
simpl_node.
apply SJ_CG.knows_def with (nx:=fresh vs). {
apply maps_to_cons. {
unfold not; intros; subst.
apply maps_to_to_in in H19.
contradiction.
}
simpl.
apply maps_to_eq.
}
assert (R: fresh vs = fresh sj). {
eauto using SJ_CG.sj_to_length_0, maps_to_length_rw.
}
rewrite R.
assert (b <> y). {
unfold not; intros; subst.
eapply SJ_CG.can_join_to_in in H4; eauto.
}
auto using SJ_CG.can_join_cons, SJ_CG.can_join_neq.
}
assert (y <> a). {
unfold not; intros; subst.
apply maps_to_to_in in H3.
contradiction.
}
apply SJ_CG.knows_def with (nx:=nx); auto using maps_to_cons.
auto using SJ_CG.can_join_cons, SJ_CG.can_join_neq.
Qed.
Let last_write_can_join_force:
forall vs es sj ah x y nx ny t,
AccessHistory.T.DRF ((x, FORCE y) :: t)
(x :: vs, J (ny, fresh vs) :: C (nx, fresh vs) :: es) ah ->
LastWriteCanJoin (vs, es) sj ah ->
LastWriteCanJoin (x :: vs, J (ny, fresh vs) :: C (nx, fresh vs) :: es)
(SJ_CG.Append nx ny :: sj) ah.
Proof.
unfold LastWriteCanJoin; intros.
simpl in *.
assert (mt := H1).
eapply AccessHistory.T.last_write_inv_force in H1; eauto
using SJ_CG.can_join_cons.
Qed.
Lemma local_knows_inv_force:
forall x vs nx es l1 l2 ls a b ny y,
LocalKnows (x :: vs, J (ny, fresh vs) :: C (nx, fresh vs) :: es)
(MN.add (fresh vs) (l1 ++ l2) ls) (a, b) ->
MN.MapsTo nx l1 ls ->
MN.MapsTo ny l2 ls ->
MapsTo y ny vs ->
MapsTo x nx vs ->
x <> y ->
(a = x /\ LocalKnows (vs, es) ls (x, b)) \/
(a = x /\ LocalKnows (vs, es) ls (y, b)) \/
LocalKnows (vs, es) ls (a, b).
Proof.
intros.
inversion H; subst; clear H.
simpl in *.
apply task_of_inv in H7.
apply Locals.maps_to_inv_add in H8.
destruct H7 as [(?,?)|Ht]. {
destruct H8 as [(_,Hi)|(N,_)]. {