-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwinExecutionAux.v
2368 lines (2300 loc) · 77.4 KB
/
TwinExecutionAux.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
Require Import Bool.
Require Import BinNat.
Require Import sflib.
Require Import Omega.
Require Import Permutation.
Require Import Common.
Require Import Lang.
Require Import Value.
Require Import Behaviors.
Require Import Memory.
Require Import State.
Require Import WellTyped.
Require Import LoadStore.
Require Import SmallStep.
Require Import TwinExecution.
Module Ir.
Import TwinExecution.
Import Ir.
Lemma twin_state_sym:
forall st1 st2 blkid (HTWIN:twin_state st1 st2 blkid),
twin_state st2 st1 blkid.
Proof.
intros.
inv HTWIN.
split.
{ apply Ir.Config.eq_wom_sym. assumption. }
inv H0.
split. congruence.
inv H2.
split. congruence.
inv H3.
split. congruence.
intros.
assert (H4' := H4 bid'). inv H4'. clear H4.
split.
{ intros HH. subst bid'.
assert (HH2 := eq_refl blkid).
apply H3 in HH2.
destruct HH2 as [mb1 HH2].
destruct HH2 as [mb2 HH2].
inv HH2.
destruct H6.
destruct H7.
destruct H8.
destruct H9.
destruct H10.
destruct H11.
destruct H12.
exists mb2, mb1.
repeat (split; try congruence).
apply Permutation_sym. congruence.
}
{ intros. apply H5 in HMATCH.
congruence.
}
Qed.
Lemma twin_state_allocatable_eq:
forall st1 st2 blkid r md
(HTWIN:twin_state st1 st2 blkid)
(HWF1:Ir.Config.wf md st1)
(HWF2:Ir.Config.wf md st2),
Ir.Memory.allocatable (Ir.Config.m st1) r =
Ir.Memory.allocatable (Ir.Config.m st2) r.
Proof.
intros.
unfold Ir.Memory.allocatable.
assert (HP:Permutation (r ++ Ir.Memory.alive_P_ranges (Ir.Config.m st1))
(r ++ Ir.Memory.alive_P_ranges (Ir.Config.m st2))).
{ apply Permutation_app.
{ apply Permutation_refl. }
{ unfold Ir.Memory.alive_P_ranges.
unfold Ir.Memory.alive_blocks.
remember (Ir.Memory.blocks (Ir.Config.m st1)) as mbs1.
remember (Ir.Memory.blocks (Ir.Config.m st2)) as mbs2.
assert (HNODUP1:List.NoDup mbs1).
{ inv HWF1. inv wf_m.
apply list_keys_NoDup.
apply wf_uniqueid. }
assert (HNODUPK1:List.NoDup (list_keys mbs1)).
{ inv HWF1. inv wf_m. assumption. }
assert (HNODUP2:List.NoDup mbs2).
{ inv HWF2. inv wf_m.
apply list_keys_NoDup.
apply wf_uniqueid. }
assert (HNODUPK2:List.NoDup (list_keys mbs2)).
{ inv HWF2. inv wf_m. assumption. }
destruct (list_find_key mbs1 blkid) eqn:HAS_BLKID;
destruct (list_find_key mbs2 blkid) eqn:HAS_BLKID2.
{ (* okay, Permutation mbs1 mbs2 should hold. *)
assert (Permutation mbs1 mbs2).
{ apply NoDup_Permutation;try eauto.
{ intros.
inv HTWIN.
destruct H0. destruct H1. destruct H2.
assert (H3' := H3 (fst x)). clear H3.
destruct H3'. clear H3.
split.
{ intros HH.
assert (HNOX: fst x <> blkid).
{ eapply list_find_key_In_none.
eapply HAS_BLKID. assumption. }
apply H4 in HNOX. clear H4.
destruct (Ir.Memory.get (Ir.Config.m st1) (fst x)) eqn:HGET1.
{ symmetry in HGET1.
apply Ir.Memory.get_In with (blks := Ir.Memory.blocks (Ir.Config.m st1)) in HGET1;
try reflexivity.
apply Ir.Memory.get_In with (blks := Ir.Memory.blocks (Ir.Config.m st2)) in HNOX;
try reflexivity.
destruct x.
simpl in *.
assert (t = t0).
{ eapply list_find_key_NoDup_In2.
eapply HGET1. eapply HH. assumption. }
subst t. assumption.
}
{ assert (~ List.In x (Ir.Memory.blocks (Ir.Config.m st1))).
{ destruct x. eapply Ir.Memory.get_not_In.
symmetry in HGET1. eapply HGET1. reflexivity. }
congruence.
}
}
{ intros HH.
assert (HNOX: fst x <> blkid).
{ eapply list_find_key_In_none.
eapply HAS_BLKID2. assumption. }
apply H4 in HNOX. clear H4.
destruct (Ir.Memory.get (Ir.Config.m st2) (fst x)) eqn:HGET2.
{ symmetry in HGET2.
apply Ir.Memory.get_In with (blks := Ir.Memory.blocks (Ir.Config.m st2)) in HGET2;
try reflexivity.
symmetry in HNOX.
apply Ir.Memory.get_In with (blks := Ir.Memory.blocks (Ir.Config.m st1)) in HNOX;
try reflexivity.
destruct x.
simpl in *.
assert (t = t0).
{ eapply list_find_key_NoDup_In2.
eapply HGET2. eapply HH. assumption. }
subst t. assumption.
}
{ assert (~ List.In x (Ir.Memory.blocks (Ir.Config.m st2))).
{ destruct x. eapply Ir.Memory.get_not_In.
symmetry in HGET2. eapply HGET2. reflexivity. }
congruence.
}
}
}
}
eapply concat_map_Permutation.
eapply filter_Permutation.
assumption.
}
{ (* cannot happen *)
inv HTWIN.
destruct H0. destruct H1. destruct H2.
assert (H3' := H3 blkid). clear H3.
destruct H3'. clear H4. exploit H3.
reflexivity. intros HH. clear H3.
destruct HH. destruct H3. destruct H3. destruct H4.
unfold Ir.Memory.get in H3, H4.
rewrite HAS_BLKID in H3. congruence.
}
{ (* cannot happen *)
inv HTWIN.
destruct H0. destruct H1. destruct H2.
assert (H3' := H3 blkid). clear H3.
destruct H3'. clear H4. exploit H3.
reflexivity. intros HH. clear H3.
destruct HH. destruct H3. destruct H3. destruct H4.
unfold Ir.Memory.get in H3, H4.
rewrite HAS_BLKID2 in H4. congruence.
}
{ inv HTWIN.
destruct H0. destruct H1. destruct H2.
assert (H3' := H3 blkid).
destruct H3'. clear H5. exploit H4.
reflexivity. intros HH. clear H4.
destruct HH. destruct H4. destruct H4. destruct H5.
dup H4. dup H5.
remember (Ir.Memory.blocks (Ir.Config.m st1)) as mbs1.
remember (Ir.Memory.blocks (Ir.Config.m st2)) as mbs2.
eapply Ir.Memory.get_In with (blks := mbs1) in H7.
eapply Ir.Memory.get_In with (blks := mbs2) in H8.
apply List.In_split in H7.
apply List.In_split in H8.
destruct H7 as [mbs11 [mbs12 HMBS1]].
destruct H8 as [mbs21 [mbs22 HMBS2]].
(* show that to_front has (blkd, _) at the front *)
assert (HFRONT1: to_front mbs1 blkid = (blkid, x)::mbs11 ++ mbs12).
{ eapply to_front_spec. assumption. assumption. }
assert (HFRONT2: to_front mbs2 blkid = (blkid, x0)::mbs21 ++ mbs22).
{ eapply to_front_spec. assumption. assumption. }
(* Let's show that mbs11+mbs12 is permutation of mbs21++mbs22. *)
(* to show this, we have to show that mbs11, mbs12, mbs21, ms22 does not
have blkid. *)
assert (HNOTIN1:~List.In blkid (list_keys (mbs11++mbs12))).
{ rewrite HMBS1 in HNODUPK1.
rewrite list_keys_app in HNODUPK1.
simpl in HNODUPK1.
rewrite list_keys_app.
apply List.NoDup_remove_2 in HNODUPK1.
assumption. }
assert (HNOTIN2:~List.In blkid (list_keys (mbs21++mbs22))).
{ rewrite HMBS2 in HNODUPK2.
rewrite list_keys_app in HNODUPK2.
simpl in HNODUPK2.
rewrite list_keys_app.
apply List.NoDup_remove_2 in HNODUPK2.
assumption. }
remember (mbs11++mbs12) as mbs1'.
remember (mbs21++mbs22) as mbs2'.
assert (HNODUP1':List.NoDup mbs1').
{ rewrite Heqmbs1'.
eapply List.NoDup_remove_1.
rewrite HMBS1 in HNODUP1. eassumption. }
assert (HNODUP2':List.NoDup mbs2').
{ rewrite Heqmbs2'.
eapply List.NoDup_remove_1.
rewrite HMBS2 in HNODUP2. eassumption. }
assert (HLSS1:lsubseq mbs1 mbs1').
{ rewrite Heqmbs1'. rewrite HMBS1.
apply lsubseq_append. apply lsubseq_refl.
constructor. apply lsubseq_refl.
}
assert (HLSS2:lsubseq mbs2 mbs2').
{ rewrite Heqmbs2'. rewrite HMBS2.
apply lsubseq_append. apply lsubseq_refl.
constructor. apply lsubseq_refl.
}
(* okay, Permutation mbs1' mbs2' should hold. *)
assert (HPERM:Permutation mbs1' mbs2').
{ apply NoDup_Permutation; try eauto.
{ intros.
assert (H3' := H3 (fst x1)). clear H3.
destruct H3'. clear H3.
split.
{ (* if x1 is in mbs1', it's in mbs2'. *)
intros HH.
(* x1's key can never be blkid. *)
assert (HNOX: fst x1 <> blkid).
{ intros HH2. subst blkid. destruct x1.
apply list_keys_In in HH. simpl in *. apply HNOTIN1. assumption. }
dup HNOX.
apply H7 in HNOX. clear H7.
destruct (Ir.Memory.get (Ir.Config.m st1) (fst x1)) eqn:HGET1.
{ symmetry in HGET1.
apply Ir.Memory.get_In with
(blks := Ir.Memory.blocks (Ir.Config.m st1)) in HGET1;
try reflexivity.
apply Ir.Memory.get_In with
(blks := Ir.Memory.blocks (Ir.Config.m st2)) in HNOX;
try reflexivity.
destruct x1.
simpl in *.
assert (t = t0).
{ eapply list_find_key_NoDup_In2.
eapply HGET1.
eapply lsubseq_In.
eapply HH. rewrite Heqmbs1 in HLSS1. assumption.
rewrite Heqmbs1 in HNODUPK1. assumption. }
subst t.
rewrite Heqmbs2'.
apply List.in_or_app.
rewrite <- Heqmbs2 in HNOX.
rewrite HMBS2 in HNOX.
apply List.in_app_or in HNOX.
destruct HNOX.
{ eauto. }
{ inv H3. { congruence. } { eauto. } }
}
{ (* Memory.get (fst x1) is None..! *)
assert (~ List.In x1 (Ir.Memory.blocks (Ir.Config.m st1))).
{ destruct x1. eapply Ir.Memory.get_not_In.
symmetry in HGET1. eapply HGET1. reflexivity. }
apply lsubseq_NotIn with (l' := mbs1') in H3.
{ congruence. }
{ congruence. }
}
}
{ intros HH.
assert (HNOX: fst x1 <> blkid).
{ intros HH2. subst blkid. destruct x1.
apply list_keys_In in HH. simpl in *. apply HNOTIN2. assumption. }
dup HNOX. apply H7 in HNOX. clear H7.
destruct (Ir.Memory.get (Ir.Config.m st2) (fst x1)) eqn:HGET2.
{ symmetry in HGET2.
apply Ir.Memory.get_In with
(blks := Ir.Memory.blocks (Ir.Config.m st2)) in HGET2;
try reflexivity.
symmetry in HNOX.
apply Ir.Memory.get_In with
(blks := Ir.Memory.blocks (Ir.Config.m st1)) in HNOX;
try reflexivity.
destruct x1.
simpl in *.
assert (t = t0).
{ eapply list_find_key_NoDup_In2.
eapply HGET2. eapply lsubseq_In.
eapply HH. rewrite <- Heqmbs2. assumption.
congruence. }
subst t.
rewrite Heqmbs1'.
apply List.in_or_app.
rewrite <- Heqmbs1 in HNOX.
rewrite HMBS1 in HNOX.
apply List.in_app_or in HNOX.
destruct HNOX.
{ eauto. }
{ inv H3. { congruence. } { eauto. } }
}
{ assert (~ List.In x1 (Ir.Memory.blocks (Ir.Config.m st2))).
{ destruct x1. eapply Ir.Memory.get_not_In.
symmetry in HGET2. eapply HGET2. reflexivity. }
apply lsubseq_NotIn with (l' := mbs2') in H3.
{ congruence. }
{ congruence. }
}
}
}
}
(* Okay, and now, for permutation of P of the twin block: *)
assert (HPERM2': Permutation (Ir.MemBlock.P_ranges x) (Ir.MemBlock.P_ranges x0)).
{ destruct H6. destruct H7. destruct H8. destruct H9.
unfold Ir.MemBlock.P_ranges. rewrite H8.
eapply map_Permutation2.
destruct H10. destruct H11. assumption. }
(* yes, it's almost done!!*)
(* now: show that filter mbs1' and filter mbs2' are pmerutation. *)
remember (List.filter (fun xb => Ir.MemBlock.alive (snd xb)) mbs1') as mbs1f'.
remember (List.filter (fun xb => Ir.MemBlock.alive (snd xb)) mbs2') as mbs2f'.
assert (HPERM3:Permutation mbs1f' mbs2f').
{ rewrite Heqmbs1f', Heqmbs2f'. eapply filter_Permutation. assumption. }
(* and, Permutation (map mbs1f') (map mbs2f'): *)
remember (List.map (fun b => Ir.MemBlock.P_ranges (snd b)) mbs1f') as mbs1m'.
remember (List.map (fun b => Ir.MemBlock.P_ranges (snd b)) mbs2f') as mbs2m'.
assert (HPERM4:Permutation mbs1m' mbs2m').
{ rewrite Heqmbs1m', Heqmbs2m'. eapply map_Permutation. eassumption. }
(* and, Permutation (concat ..) (concat ..): *)
remember (List.concat mbs1m') as mbs1c'.
remember (List.concat mbs2m') as mbs2c'.
assert (HPERM5:Permutation mbs1c' mbs2c').
{ rewrite Heqmbs1c', Heqmbs2c'.
eapply concat_Permutation2. assumption. }
(* okay, now start with.. to_fronts. *)
assert (HPERM6: Permutation
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter (fun xb => Ir.MemBlock.alive (snd xb))
(to_front mbs1 blkid))))
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter (fun xb => Ir.MemBlock.alive (snd xb))
(to_front mbs2 blkid))))).
{ rewrite HFRONT1. rewrite HFRONT2.
simpl.
assert (HALIVE: Ir.MemBlock.alive x = Ir.MemBlock.alive x0).
{ destruct H6. destruct H7.
unfold Ir.MemBlock.alive. rewrite H7. congruence. }
rewrite HALIVE in *.
des_if.
{ simpl. eapply Permutation_app. assumption.
{ rewrite Heqmbs1c', Heqmbs2c' in HPERM5.
rewrite Heqmbs1m', Heqmbs2m' in HPERM5.
rewrite Heqmbs1f', Heqmbs2f' in HPERM5.
assumption. }
}
{ rewrite Heqmbs1c', Heqmbs2c' in HPERM5.
rewrite Heqmbs1m', Heqmbs2m' in HPERM5.
rewrite Heqmbs1f', Heqmbs2f' in HPERM5.
assumption. }
}
assert (HPERM7:
Permutation
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter
(fun xb => Ir.MemBlock.alive (snd xb))
mbs1)))
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter
(fun xb => Ir.MemBlock.alive (snd xb))
(to_front mbs1 blkid))))).
{ apply concat_Permutation2. apply map_Permutation.
apply filter_Permutation. apply to_front_Permutation. }
assert (HPERM8:
Permutation
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter
(fun xb => Ir.MemBlock.alive (snd xb))
(to_front mbs2 blkid))))
(List.concat
(List.map (fun b => Ir.MemBlock.P_ranges (snd b))
(List.filter
(fun xb => Ir.MemBlock.alive (snd xb))
mbs2)))).
{ apply concat_Permutation2. apply map_Permutation.
apply filter_Permutation.
apply Permutation_sym. apply to_front_Permutation. }
(* Now, a bunch of transitivity! *)
eapply Permutation_trans.
eapply HPERM7.
eapply Permutation_trans.
eapply HPERM6.
eapply Permutation_trans.
eapply HPERM8.
(* and.. finally!*)
eapply Permutation_refl.
(* just a bunch of .. *)
eassumption. eassumption.
}
}
}
apply disjoint_ranges_Permutation.
assumption.
Qed.
Lemma twin_state_get_funid_eq:
forall (st1 st2:Ir.Config.t) c blkid
(HTWIN:twin_state st1 st2 blkid),
Ir.Config.get_funid st1 c = Ir.Config.get_funid st2 c.
Proof.
intros.
unfold Ir.Config.get_funid.
inv HTWIN.
inv H.
inv H2.
rewrite H.
reflexivity.
Qed.
Lemma twin_state_cur_fdef_pc_eq:
forall (md:Ir.IRModule.t) (st1 st2:Ir.Config.t) blkid
(HTWIN:twin_state st1 st2 blkid),
Ir.Config.cur_fdef_pc md st1 = Ir.Config.cur_fdef_pc md st2.
Proof.
intros.
dup HTWIN.
unfold Ir.Config.cur_fdef_pc.
inv HTWIN.
inv H0.
inv H1.
inv H.
des_ifs; try (inv H0; fail).
try ( unfold Ir.Stack.eq in H0; inv H0;
simpl in H6; inv H6; inv H0;
rewrite twin_state_get_funid_eq with (st2 := st2) (blkid := blkid) in Heq0;
try assumption;
rewrite Heq3 in Heq0; inv Heq0;
rewrite Heq4 in Heq1; inv Heq1;
reflexivity
).
{ unfold Ir.Stack.eq in H0.
inv H0.
simpl in H6.
inv H6. inv H0.
rewrite twin_state_get_funid_eq with (st2 := st2) (blkid := blkid) in Heq0;
try assumption.
rewrite Heq3 in Heq0. inv Heq0.
rewrite Heq4 in Heq1. inv Heq1.
}
{ unfold Ir.Stack.eq in H0.
inv H0.
simpl in H6.
inv H6. inv H0.
rewrite twin_state_get_funid_eq with (st2 := st2) (blkid := blkid) in Heq0;
try assumption.
rewrite Heq3 in Heq0. inv Heq0.
}
{ unfold Ir.Stack.eq in H0.
inv H0.
simpl in H6.
inv H6. inv H0.
rewrite twin_state_get_funid_eq with (st2 := st2) (blkid := blkid) in Heq0;
try assumption.
rewrite Heq3 in Heq0. inv Heq0.
rewrite Heq4 in Heq1. inv Heq1.
}
{ unfold Ir.Stack.eq in H0.
inv H0.
simpl in H6.
inv H6. inv H0.
rewrite twin_state_get_funid_eq with (st2 := st2) (blkid := blkid) in Heq0;
try assumption.
rewrite Heq2 in Heq0. inv Heq0.
}
Qed.
Lemma twin_state_cur_inst_eq:
forall (md:Ir.IRModule.t) (st1 st2:Ir.Config.t) blkid
(HTWIN:twin_state st1 st2 blkid),
Ir.Config.cur_inst md st1 = Ir.Config.cur_inst md st2.
Proof.
intros.
inv HTWIN.
unfold Ir.Config.cur_inst.
inv H.
unfold Ir.Config.cur_fdef_pc.
unfold Ir.Stack.eq in H1.
destruct (Ir.Config.s st1);
destruct (Ir.Config.s st2).
{ reflexivity. }
{ inv H1. }
{ inv H1. }
{ inv H1. inv H5. inv H1.
destruct p. destruct p0. simpl in H. subst c.
simpl in H3.
destruct p. destruct p0.
simpl in H3. subst p.
simpl in H4.
unfold Ir.Config.get_funid.
inv H2.
rewrite H.
des_ifs.
}
Qed.
Lemma twin_state_cur_phi_eq:
forall (md:Ir.IRModule.t) (st1 st2:Ir.Config.t) blkid
(HTWIN:twin_state st1 st2 blkid),
Ir.Config.cur_phi md st1 = Ir.Config.cur_phi md st2.
Proof.
intros.
inv HTWIN.
unfold Ir.Config.cur_phi.
inv H.
unfold Ir.Config.cur_fdef_pc.
unfold Ir.Stack.eq in H1.
destruct (Ir.Config.s st1);
destruct (Ir.Config.s st2).
{ reflexivity. }
{ inv H1. }
{ inv H1. }
{ inv H1. inv H5. inv H1.
destruct p. destruct p0. simpl in H. subst c.
simpl in H3.
destruct p. destruct p0.
simpl in H3. subst p.
simpl in H4.
unfold Ir.Config.get_funid.
inv H2.
rewrite H.
des_ifs.
}
Qed.
Lemma twin_state_get_val_eq:
forall (st1 st2:Ir.Config.t) blkid r
(HTWIN:twin_state st1 st2 blkid),
Ir.Config.get_val st1 r = Ir.Config.get_val st2 r.
Proof.
intros.
inv HTWIN.
unfold Ir.Config.get_val.
destruct r; try reflexivity.
unfold Ir.Config.get_rval.
inv H.
unfold Ir.Stack.eq in H1.
destruct (Ir.Config.s st1);
destruct (Ir.Config.s st2).
{ reflexivity. }
{ inv H1. }
{ inv H1. }
{ inv H1. inv H5. inv H1.
destruct p. destruct p0. simpl in H. subst c.
simpl in H3.
destruct p. destruct p0.
simpl in H3. subst p.
simpl in H4.
unfold Ir.Regfile.eq in H4.
apply H4.
}
Qed.
Lemma twin_state_update_rval:
forall (st1 st2:Ir.Config.t) blkid r v
(HTWIN:twin_state st1 st2 blkid),
twin_state (Ir.Config.update_rval st1 r v)
(Ir.Config.update_rval st2 r v) blkid.
Proof.
intros.
inv HTWIN.
inv H.
unfold Ir.Config.update_rval.
des_ifs; try (inv H1; fail).
{ split.
{ split. rewrite Heq, Heq0. assumption.
assumption. }
{ apply H0. }
}
{ inv H1.
simpl in H5. inv H5. inv H1.
destruct H0.
destruct H0.
destruct H1.
split.
{ split.
{ simpl. unfold Ir.Stack.eq. simpl.
apply List.Forall2_cons. simpl.
split. congruence. split . congruence.
apply Ir.Regfile.update_eq. assumption.
assumption.
}
{ assumption. }
}
simpl.
split. congruence.
split. congruence.
split. congruence.
intros.
assert (H4' := H4 bid'). clear H4.
split.
{ intros HH. simpl. subst bid'.
destruct H4'. assert (HDUMMY: blkid = blkid). reflexivity.
apply H4 in HDUMMY. clear H4.
destruct HDUMMY as [mb1 HDUMMY].
destruct HDUMMY as [mb2 HDUMMY].
exists mb1. exists mb2.
assumption.
}
{ intros HH. destruct H4'.
apply H5 in HH. assumption.
}
}
Qed.
Lemma twin_state_update_pc:
forall (st1 st2:Ir.Config.t) blkid pc0
(HTWIN:twin_state st1 st2 blkid),
twin_state (Ir.Config.update_pc st1 pc0)
(Ir.Config.update_pc st2 pc0) blkid.
Proof.
intros.
inv HTWIN.
inv H.
unfold Ir.Config.update_pc.
des_ifs; try (inv H1; fail).
{ split.
{ split. rewrite Heq, Heq0. assumption.
assumption. }
{ apply H0. }
}
{ inv H1.
simpl in H5. inv H5. inv H1.
split.
{ split.
{ simpl. unfold Ir.Stack.eq. simpl.
apply List.Forall2_cons. simpl.
split. congruence. split . congruence.
assumption.
assumption.
}
{ assumption. }
}
simpl in *.
destruct H0.
destruct H0.
destruct H1.
split. congruence.
split. congruence.
split. congruence.
intros.
assert (H4' := H4 bid').
clear H4. destruct H4'.
split.
{ intros. eauto. }
{ intros. eauto. }
}
Qed.
Lemma twin_state_incrpc:
forall md (st1 st2:Ir.Config.t) blkid
(HTWIN:twin_state st1 st2 blkid),
twin_state (Ir.SmallStep.incrpc md st1)
(Ir.SmallStep.incrpc md st2) blkid.
Proof.
intros.
dup HTWIN.
inv HTWIN.
inv H.
unfold Ir.SmallStep.incrpc.
rewrite twin_state_cur_fdef_pc_eq with (st2 := st2) (blkid := blkid);
try assumption.
des_ifs; try (inv H1; fail).
apply twin_state_update_pc.
assumption.
Qed.
Lemma twin_state_update_reg_and_incrpc:
forall md (st1 st2:Ir.Config.t) blkid r v
(HTWIN:twin_state st1 st2 blkid),
twin_state (Ir.SmallStep.update_reg_and_incrpc md st1 r v)
(Ir.SmallStep.update_reg_and_incrpc md st2 r v) blkid.
Proof.
intros.
unfold Ir.SmallStep.update_reg_and_incrpc.
apply twin_state_incrpc.
apply twin_state_update_rval.
assumption.
Qed.
Lemma twin_state_p2N_eq:
forall st1 st2 b blkid n o
(HTWIN: twin_state st1 st2 blkid)
(HNEQ:b <> blkid),
Ir.SmallStep.p2N (Ir.plog b o) (Ir.Config.m st1) n =
Ir.SmallStep.p2N (Ir.plog b o) (Ir.Config.m st2) n.
Proof.
intros.
inv HTWIN.
destruct H0.
destruct H1.
destruct H2.
assert (HH := H3 b).
clear H3.
destruct HH. clear H3.
apply H4 in HNEQ. clear H4.
unfold Ir.SmallStep.p2N.
unfold Ir.log_to_phy.
rewrite HNEQ.
reflexivity.
Qed.
Lemma twin_state_gep_eq:
forall st1 st2 b blkid n t o inb
(HTWIN: twin_state st1 st2 blkid),
Ir.SmallStep.gep (Ir.plog b o) n t (Ir.Config.m st1) inb =
Ir.SmallStep.gep (Ir.plog b o) n t (Ir.Config.m st2) inb.
Proof.
intros.
destruct HTWIN.
destruct H0.
destruct H1.
destruct H2.
assert (HH := H3 b).
clear H3.
destruct HH.
destruct (b =? blkid) eqn:HBLKID.
{ rewrite PeanoNat.Nat.eqb_eq in HBLKID.
dup HBLKID.
apply H3 in HBLKID.
subst b.
clear H3. destruct HBLKID. destruct H3.
destruct H3.
destruct H5.
unfold Ir.SmallStep.gep.
destruct inb.
{ rewrite <- H3. rewrite <- H5.
assert (HINB: forall o', Ir.MemBlock.inbounds o' x = Ir.MemBlock.inbounds o' x0).
{ intros.
unfold Ir.MemBlock.inbounds.
destruct H6.
destruct H7.
destruct H8.
rewrite H8. reflexivity. }
rewrite HINB.
rewrite HINB.
reflexivity.
}
{ reflexivity. }
}
{ unfold Ir.SmallStep.gep.
rewrite PeanoNat.Nat.eqb_neq in HBLKID.
apply H4 in HBLKID.
rewrite HBLKID.
reflexivity.
}
Qed.
Lemma twin_state_deref_eq:
forall st1 st2 blkid (HTWIN:twin_state st1 st2 blkid)
l ofs n,
Ir.deref (Ir.Config.m st1) (Ir.plog l ofs) n =
Ir.deref (Ir.Config.m st2) (Ir.plog l ofs) n.
Proof.
intros.
unfold Ir.deref.
unfold Ir.get_deref.
destruct (l =? blkid) eqn:HBLKID.
{ rewrite PeanoNat.Nat.eqb_eq in HBLKID.
subst l.
destruct HTWIN.
destruct H0.
destruct H1.
destruct H2.
assert (H3' := H3 blkid).
destruct H3'.
exploit H4.
reflexivity.
intros H4'.
destruct H4' as [mb1 [mb2 H4']].
destruct H4' as [HH0 HH1].
destruct HH1 as [HH1 HH2].
destruct HH2 as [HH2 HH3].
destruct HH3 as [HH3 HH4].
destruct HH4 as [HH4 HH5].
destruct HH5 as [HH5 HH6].
rewrite <- HH0.
rewrite <- HH1.
unfold Ir.MemBlock.alive.
unfold Ir.MemBlock.inbounds.
rewrite HH3.
rewrite HH4.
des_ifs.
}
{ rewrite PeanoNat.Nat.eqb_neq in HBLKID.
destruct HTWIN.
destruct H0.
destruct H1.
destruct H2.
assert (H3' := H3 l).
destruct H3'.
apply H5 in HBLKID.
rewrite HBLKID. reflexivity.
}
Qed.
Ltac decompose_HTWIN HTWIN blkid :=
destruct HTWIN as [HTWIN1 HTWIN2];
destruct HTWIN2 as [HTWIN2 HTWIN3];
destruct HTWIN3 as [HTWIN3 HTWIN4];
destruct HTWIN4 as [HTWIN4 HTWIN5];
assert (HTWIN5' := HTWIN5 blkid).
Ltac decompose_mbs H4':=
destruct H4' as [mb1 [mb2 H4']];
destruct H4' as [HH0 HH1];
destruct HH1 as [HH1 HH2];
destruct HH2 as [HH2 HH3];
destruct HH3 as [HH3 HH4];
destruct HH4 as [HH4 HH5];
destruct HH5 as [HH5 HH6];
destruct HH6 as [HH6 HH7].
Ltac decompose_HTWIN' HTWIN blkid :=
destruct HTWIN as [HTWIN1' HTWIN2']; destruct HTWIN2' as [HTWIN2' HTWIN3'];
destruct HTWIN3' as [HTWIN3' HTWIN4']; destruct HTWIN4' as [HTWIN4' HTWIN5'];
pose proof (HTWIN5' blkid) as HTWIN5'.
Ltac decompose_mbs' H4':=
destruct H4' as [mb1' [mb2' H4'']];
destruct H4'' as [HH0' HH1'];
destruct HH1' as [HH1' HH2'];
destruct HH2' as [HH2' HH3'];
destruct HH3' as [HH3' HH4'];
destruct HH4' as [HH4' HH5'];
destruct HH5' as [HH5' HH6'];
destruct HH6' as [HH6' HH7'].
Lemma twin_state_load_bytes_eq:
forall st1 st2 blkid (HTWIN:twin_state st1 st2 blkid) l ofs thety,
Ir.load_bytes (Ir.Config.m st1) (Ir.plog l ofs) thety =
Ir.load_bytes (Ir.Config.m st2) (Ir.plog l ofs) thety.
Proof.
intros.
unfold Ir.load_bytes.
destruct (Ir.get_deref
(Ir.Config.m st1) (Ir.plog l ofs) thety)
eqn:HGD1;
destruct (Ir.get_deref
(Ir.Config.m st2) (Ir.plog l ofs) thety)
eqn:HGD2; try reflexivity.
{ unfold Ir.get_deref in HGD1, HGD2.
destruct (l =? blkid) eqn:HBLKID.
{ rewrite PeanoNat.Nat.eqb_eq in HBLKID.
subst l.
decompose_HTWIN HTWIN blkid.
destruct HTWIN5'.
exploit H. reflexivity. intro HH.
decompose_mbs HH. clear H.
rewrite <- HH0 in HGD1.
rewrite <- HH1 in HGD2.
unfold Ir.MemBlock.alive in *.
rewrite HH3 in HGD1.
unfold Ir.MemBlock.inbounds in *.
rewrite HH4 in HGD1.
des_ifs.
}
{ rewrite PeanoNat.Nat.eqb_neq in HBLKID.
decompose_HTWIN HTWIN l.
destruct HTWIN5'.
exploit H0. assumption. intro HH.
rewrite HH in HGD1. rewrite HGD1 in HGD2. congruence.
}
}
{ unfold Ir.get_deref in HGD1, HGD2.
destruct (l =? blkid) eqn:HBLKID.
{ rewrite PeanoNat.Nat.eqb_eq in HBLKID.
subst l.
decompose_HTWIN HTWIN blkid.
destruct HTWIN5'.
exploit H. reflexivity. intro HH.
decompose_mbs HH. clear H.
rewrite <- HH0 in HGD1.
rewrite <- HH1 in HGD2.
unfold Ir.MemBlock.alive in *.
rewrite HH3 in HGD1.
unfold Ir.MemBlock.inbounds in *.
rewrite HH4 in HGD1.
des_ifs.
}
{ rewrite PeanoNat.Nat.eqb_neq in HBLKID.
decompose_HTWIN HTWIN l.
destruct HTWIN5'.
exploit H0. assumption. intro HH.
rewrite HH in HGD1. rewrite HGD1 in HGD2. congruence.
}
}
{ unfold Ir.get_deref in HGD1, HGD2.
destruct (l =? blkid) eqn:HBLKID.
{ rewrite PeanoNat.Nat.eqb_eq in HBLKID.
subst l.
decompose_HTWIN HTWIN blkid.
destruct HTWIN5'.
exploit H. reflexivity. intro HH.
decompose_mbs HH.
unfold Ir.MemBlock.alive in HGD1, HGD2.
unfold Ir.MemBlock.inbounds in HGD1, HGD2.
rewrite <- HH0 in HGD1.
rewrite <- HH1 in HGD2.
rewrite HH3 in HGD1.
rewrite HH4 in HGD1.
des_ifs.
{ unfold Ir.MemBlock.bytes in *.
rewrite HH6. reflexivity.
}
}
{ rewrite PeanoNat.Nat.eqb_neq in HBLKID.
decompose_HTWIN HTWIN l.
destruct HTWIN5'.
exploit H0. assumption. intros HH.
rewrite HH in HGD1. rewrite HGD1 in HGD2.
inv HGD2. reflexivity.
}
}
Qed.
Lemma twin_state_load_val_eq:
forall st1 st2 blkid (HTWIN:twin_state st1 st2 blkid) l ofs thety,
Ir.load_val (Ir.Config.m st1) (Ir.plog l ofs) thety =
Ir.load_val (Ir.Config.m st2) (Ir.plog l ofs) thety.
Proof.
intros.
unfold Ir.load_val.
destruct thety.
{ erewrite twin_state_load_bytes_eq. reflexivity.
eassumption. }
{ erewrite twin_state_load_bytes_eq. reflexivity.
eassumption. }
Qed.
Lemma store_val_wf_unfold_int:
forall st blkid ofs (n0:nat) isz mb
(HDEREF:Ir.deref (Ir.Config.m st) (Ir.plog blkid ofs)
(length (Ir.Byte.ofint (N.of_nat n0) isz)) = true)
(HTYSZ:Ir.ty_bytesz (Ir.ity isz) = length (Ir.Byte.ofint (N.of_nat n0) isz))
(HGET:Some mb = Ir.Memory.get (Ir.Config.m st) blkid)
(HSZ:Ir.ty_bytesz (Ir.ity isz) >0)
(HWF:Ir.Memory.wf
(Ir.store_val (Ir.Config.m st) (Ir.plog blkid ofs)
(Ir.num n0) (Ir.ity isz))),
Ir.Memory.wf
(Ir.Memory.set (Ir.Config.m st) blkid
(Ir.MemBlock.set_bytes mb ofs (Ir.Byte.ofint (N.of_nat n0) isz))).
Proof.
intros.
unfold Ir.store_val in HWF.
unfold Ir.store_bytes in HWF.
rewrite HTYSZ in HWF. rewrite PeanoNat.Nat.eqb_refl in HWF.
unfold Ir.deref in HDEREF.
des_ifs.
{ unfold Ir.get_deref in Heq.
rewrite <- HGET in Heq.
des_ifs.
unfold Ir.MemBlock.inbounds in Heq1.
rewrite PeanoNat.Nat.ltb_lt in Heq0.
rewrite PeanoNat.Nat.lt_nge in Heq0.
rewrite <- PeanoNat.Nat.leb_nle in Heq0.
rewrite Heq0 in Heq1.
rewrite andb_false_r in Heq1. congruence.
}
{ unfold Ir.get_deref in Heq.
rewrite <- HGET in Heq.
des_ifs.
}