-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoundPostcondCmdAdd.v
1166 lines (1112 loc) · 42.9 KB
/
SoundPostcondCmdAdd.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 syntax.
Require Import alist.
Require Import FMapWeakList.
Require Import Classical.
Require Import Coqlib.
Require Import infrastructure.
Require Import Metatheory.
Import LLVMsyntax.
Import LLVMinfra.
Require Import opsem.
Require Import sflib.
Require Import paco.
Import Opsem.
Require Import TODO.
Require Import Exprs.
Require Import Hints.
Require Import Postcond.
Require Import Validator.
Require Import GenericValues.
Require AssnMem.
Require AssnState.
Require Import Inject.
Require Import SoundBase.
Require Import SoundReduceMaydiff.
Require Import memory_props.
Require Import TODOProof.
Require Import MemAux.
Set Implicit Arguments.
Definition cmd_is_normal (c:cmd): bool :=
match c with
| insn_malloc _ _ _ _
| insn_free _ _ _
| insn_alloca _ _ _ _
| insn_load _ _ _ _
| insn_store _ _ _ _ _
| insn_call _ _ _ _ _ _ _ => false
| _ => true
end.
Lemma normal_event
conf st0 st1 evt cmd cmds
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd::cmds)
(NORMAL: cmd_is_normal cmd):
evt = events.E0.
Proof.
inv STEP; ss. inv CMDS. ss.
Qed.
Lemma AtomSetImpl_inter_empty
a l1 l2
(EMPTY: AtomSetImpl.Empty (AtomSetImpl.inter l1 l2))
(IN: a `in` l1)
:
<<NOTIN: a `notin` l2>>.
Proof.
ii. exploit EMPTY; eauto.
Qed.
Lemma AtomSetImpl_from_list_inter_is_empty
l1 l2
(INTER_EMPTY: AtomSetImpl.is_empty
(AtomSetImpl.inter (AtomSetImpl_from_list l1)
(AtomSetImpl_from_list l2)) = true)
:
List.Forall (fun x => List.Forall (fun y => x <> y) l2) l1
.
Proof.
revert l2 INTER_EMPTY. induction l1; ss. i.
apply AtomSetFacts.is_empty_iff in INTER_EMPTY.
exploit IHl1.
{ rewrite <- AtomSetFacts.is_empty_iff.
ii. eapply INTER_EMPTY.
eapply AtomSetFacts.inter_s_m_Proper; eauto.
- ii.
apply AtomSetFacts.mem_iff, AtomSetImpl_from_list_spec. right.
apply AtomSetImpl_from_list_spec, AtomSetFacts.mem_iff. ss.
- reflexivity.
}
i. econs; ss. clear -INTER_EMPTY.
hexploit AtomSetImpl_inter_empty; eauto.
{ apply AtomSetFacts.mem_iff, AtomSetImpl_from_list_spec. left. ss. }
intro A. des.
apply AtomSetFacts.not_mem_iff in A.
apply Forall_forall. ii. subst.
apply AtomSetImpl_from_list_spec in H. clarify.
Qed.
Ltac simpl_list :=
repeat match goal with
| [ H: Forall _ (_ :: _) |- _ ] => inv H
| [ H: Forall _ [] |- _ ] => clear H
end.
Ltac des_lookupAL_updateAddAL :=
repeat match goal with
| [ H: context[lookupAL ?t (updateAddAL ?t _ ?idA _) ?idB] |- _ ] =>
destruct (eq_atom_dec idB idA);
[ss; clarify; rewrite lookupAL_updateAddAL_eq in H |
ss; clarify; rewrite <- lookupAL_updateAddAL_neq in H]; ss; clarify
| [ |- context[lookupAL ?t (updateAddAL ?t _ ?idA _) ?idB] ] =>
destruct (eq_atom_dec idB idA);
[ss; clarify; rewrite lookupAL_updateAddAL_eq |
ss; clarify; rewrite <- lookupAL_updateAddAL_neq]; ss; clarify
end.
Ltac simpl_ep_set :=
repeat
match goal with
| [H: ExprPairSet.In _ (ExprPairSet.add _ _) |- _] =>
eapply ExprPairSetFacts.add_iff in H; des; clarify
end.
Ltac u := autounfold in *.
Hint Unfold AssnState.Unary.sem_idT.
Hint Unfold Cmd.get_ids.
Hint Unfold getOperandValue.
Ltac clear_true :=
repeat match goal with
| [ H: is_true true |- _ ] => clear H
| [ H: True |- _ ] => clear H
| [ H: ?x = ?x |- _ ] => clear H
end.
Lemma remove_def_from_maydiff_Subset_old
id0 inv0
:
Assertion.Subset
inv0
(remove_def_from_maydiff
id0 id0
(Assertion.update_tgt (Assertion.update_unique (add id0))
(Assertion.update_src (Assertion.update_unique (add id0)) inv0)))
.
Proof.
destruct inv0; ss.
destruct src; ss.
destruct tgt; ss.
unfold Assertion.update_src, Assertion.update_tgt,
remove_def_from_maydiff, Assertion.update_maydiff. ss.
destruct (id_dec id0 id0); clarify.
unfold Assertion.update_unique; ss.
econs; ss; try (econs; try splits; ss).
-
ii.
eapply AtomSetFacts.add_s_m. eauto.
apply AtomSetFacts.Subset_refl.
info_eauto.
-
ii.
eapply AtomSetFacts.add_s_m. eauto.
apply AtomSetFacts.Subset_refl.
info_eauto.
-
ii.
rewrite IdTSetFacts.mem_iff in *.
rewrite IdTSetFacts.remove_b in H.
des_bool; des; ss.
Qed.
Lemma remove_def_from_maydiff_Subset
id0 inv0
:
Assertion.Subset
inv0
(remove_def_from_maydiff
id0 id0 (Assertion.update_src (Assertion.update_unique (add id0)) inv0))
.
Proof.
destruct inv0; ss.
destruct src; ss.
destruct tgt; ss.
unfold Assertion.update_src, Assertion.update_tgt,
remove_def_from_maydiff, Assertion.update_maydiff. ss.
destruct (id_dec id0 id0); clarify.
unfold Assertion.update_unique; ss.
econs; ss; try (econs; try splits; ss).
-
ii.
eapply AtomSetFacts.add_s_m. eauto.
apply AtomSetFacts.Subset_refl.
info_eauto.
-
ii.
rewrite IdTSetFacts.mem_iff in *.
rewrite IdTSetFacts.remove_b in H.
des_bool; des; ss.
Qed.
Lemma add_unique_alloca
cmds_src id0 align0 inv_unary TD F B lc gn ECS0 tmn SRC_MEM als SRC_MEM_STEP tsz mb conf_src gmax
(ALLOCA: alloca TD SRC_MEM tsz gn align0 = Some (SRC_MEM_STEP, mb))
(UNIQUE: AtomSetImpl.For_all
(AssnState.Unary.sem_unique conf_src
{|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cmds_src;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 (blk2GV TD mb);
Allocas := mb :: als |};
ECS := ECS0;
Mem := SRC_MEM_STEP |} gmax) (Assertion.unique inv_unary))
(WF : MemProps.wf_Mem gmax (CurTargetData conf_src) SRC_MEM)
(GLOBALS : genericvalues_inject.wf_globals gmax (Globals conf_src))
(WF_LOCAL : MemProps.wf_lc SRC_MEM lc)
:
<<UNIQUE_ADD: AtomSetImpl.For_all
(AssnState.Unary.sem_unique conf_src
{|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cmds_src;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 (blk2GV TD mb);
Allocas := mb :: als |};
ECS := ECS0;
Mem := SRC_MEM_STEP |} gmax) (add id0 (Assertion.unique inv_unary))>>
.
Proof.
intros x xIn.
apply AtomSetFacts.add_iff in xIn.
des; [clear UNIQUE; subst id0|apply UNIQUE; auto].
econs; eauto; ss.
+ (* VAL *)
des_lookupAL_updateAddAL.
+ (* LOCALS *)
ii.
des_lookupAL_updateAddAL.
eapply locals_alloca_diffblock; ss; eauto.
+ (* MEM *)
ii. eapply mload_alloca_diffblock; eauto.
+ (* GLOBALS *)
ii. ss. clarify.
des; ss. clarify.
eapply globals_alloca_diffblock; eauto.
Qed.
Lemma postcond_cmd_add_inject_sound
m_src conf_src st0_src st1_src cmd_src cmds_src def_src uses_src
m_tgt conf_tgt st0_tgt st1_tgt cmd_tgt cmds_tgt def_tgt uses_tgt
invst1 assnmem1 inv1
invst0 assnmem0 inv0
evt
(CONF: AssnState.valid_conf m_src m_tgt conf_src conf_tgt)
(POSTCOND_CHECK: Postcond.postcond_cmd_check
cmd_src cmd_tgt def_src def_tgt uses_src uses_tgt inv1)
(STATE: AssnState.Rel.sem conf_src conf_tgt st0_src st0_tgt invst0 assnmem0 inv0)
(STATE_STEP: AssnState.Rel.sem conf_src conf_tgt st1_src st1_tgt invst1 assnmem1 inv1)
(MEM: AssnMem.Rel.sem conf_src conf_tgt st0_src.(Mem) st0_tgt.(Mem) assnmem0)
(MEM_STEP: AssnMem.Rel.sem conf_src conf_tgt st1_src.(Mem) st1_tgt.(Mem) assnmem1)
(MEM_GMAX: assnmem0.(AssnMem.Rel.gmax) = assnmem1.(AssnMem.Rel.gmax))
(STEP_SRC: sInsn conf_src st0_src st1_src evt)
(STEP_TGT: sInsn conf_tgt st0_tgt st1_tgt evt)
(CMDS_SRC: st0_src.(EC).(CurCmds) = cmd_src :: cmds_src)
(CMDS_TGT: st0_tgt.(EC).(CurCmds) = cmd_tgt :: cmds_tgt)
(NONCALL_SRC: Instruction.isCallInst cmd_src = false)
(NONCALL_TGT: Instruction.isCallInst cmd_tgt = false)
(DEF_SRC: def_src = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd_src)))
(DEF_TGT: def_tgt = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd_tgt)))
(USES_SRC: uses_src = AtomSetImpl_from_list (Cmd.get_ids cmd_src))
(USES_TGT: uses_tgt = AtomSetImpl_from_list (Cmd.get_ids cmd_tgt))
(ALLOC_INJECT: alloc_inject conf_src conf_tgt st0_src st0_tgt
st1_src st1_tgt cmd_src cmd_tgt assnmem1)
(ALLOC_PRIVATE: alloc_private conf_src conf_tgt cmd_src cmd_tgt st0_src st0_tgt
st1_src st1_tgt assnmem1)
:
<<STATE: AssnState.Rel.sem
conf_src conf_tgt st1_src st1_tgt invst1 assnmem1
(Postcond.postcond_cmd_add_inject cmd_src cmd_tgt inv1)>> /\
<<POSTCOND: Postcond.postcond_cmd_check
cmd_src cmd_tgt def_src def_tgt uses_src uses_tgt
(Postcond.postcond_cmd_add_inject cmd_src cmd_tgt inv1)>>
.
Proof.
remember (st0_src.(Mem).(Memory.Mem.nextblock)) as src_nxt.
remember (st0_tgt.(Mem).(Memory.Mem.nextblock)) as tgt_nxt.
destruct (classic (Postcond.postcond_cmd_add_inject cmd_src cmd_tgt inv1 = inv1)).
{ rewrite H in *. esplits; eauto. }
destruct cmd_src, cmd_tgt; ss.
- (* nop, alloca *)
clear ALLOC_INJECT.
unfold postcond_cmd_check in *. des_ifs; des_bool; clarify.
(* ss. clear_true. *)
(* splits; ss. *)
(* apply_all_once AtomSetImpl_from_list_inter_is_empty. *)
(* simpl_list. *)
(* inv STATE_STEP. *)
(* ((inv STEP_SRC; ss); []). *)
(* (* inv SRC. *) *)
(* inv CMDS_SRC. *)
(* econs; eauto; []. *)
(* ((inv STEP_TGT; ss); []). *)
(* (* inv TGT. *) *)
(* inv CMDS_TGT. *)
(* ss. *)
(* clear MAYDIFF. *)
(* inv TGT. *)
(* clear H H2. *)
(* clear MEM_STEP. *)
(* clear CONF. *)
(* (* inv TGT. clear LESSDEF0 NOALIAS0 UNIQUE0 PRIVATE0 WF_LOCAL0. *) *)
(* unfold alloc_private, alloc_private_unary in *. ss. *)
(* destruct ALLOC_PRIVATE as [_ ALLOC_PRIVATE]. *)
(* exploit ALLOC_PRIVATE; eauto. clear ALLOC_PRIVATE. intro ALLOC_PRIVATE. *)
(* econs; eauto; (* [|]; *) clear LESSDEF NOALIAS WF_LOCAL. *)
(* (* + clear ALLOC_PRIVATE. *) *)
(* (* clear PRIVATE. *) *)
(* (* unfold Assertion.update_src. ss. *) *)
(* (* intros ____id____ IN. *) *)
(* (* eapply AtomSetFacts.add_iff in IN. *) *)
(* (* des; [|eauto]; []. *) *)
(* (* subst. *) *)
(* (* eapply add_unique_alloca; eauto; try apply MEM; try apply STATE; *) *)
(* (* rewrite <- MEM_GMAX; try apply MEM; try apply STATE. *) *)
(* + clear UNIQUE. *)
(* clear MEM SRC STATE. *)
(* unfold Assertion.update_private. ss. *)
(* ii. rewrite IdTSetFacts.add_iff in *. des. *)
(* { (* x is alloca *) *)
(* destruct x as [[] x]; ss. *)
(* unfold IdT.lift, AssnState.Unary.sem_idT in *. ss. clarify. *)
(* exploit ALLOC_PRIVATE0; eauto. *)
(* } *)
(* { exploit PRIVATE; eauto. } *)
- (* allica, nop *)
clear ALLOC_INJECT.
unfold postcond_cmd_check in *. des_ifs; des_bool; clarify.
ss. clear_true.
splits; ss.
apply_all_once AtomSetImpl_from_list_inter_is_empty.
simpl_list.
inv STATE_STEP.
((inv STEP_SRC; ss); []).
(* inv SRC. *)
inv CMDS_SRC.
econs; eauto; [].
((inv STEP_TGT; ss); []).
(* inv TGT. *)
inv CMDS_TGT.
ss.
clear MAYDIFF.
inv SRC.
clear H H2.
clear MEM_STEP.
clear CONF.
(* inv TGT. clear LESSDEF0 NOALIAS0 UNIQUE0 PRIVATE0 WF_LOCAL0. *)
unfold alloc_private, alloc_private_unary in *. ss.
destruct ALLOC_PRIVATE as [ALLOC_PRIVATE _].
exploit ALLOC_PRIVATE; eauto. clear ALLOC_PRIVATE. intro ALLOC_PRIVATE.
econs; eauto; [|]; clear LESSDEF NOALIAS WF_LOCAL.
+ clear ALLOC_PRIVATE.
clear PRIVATE.
unfold Assertion.update_src. ss.
intros ____id____ IN.
eapply AtomSetFacts.add_iff in IN.
des; [|eauto]; [].
subst.
eapply add_unique_alloca; eauto; try apply MEM; try apply STATE;
rewrite <- MEM_GMAX; try apply MEM; try apply STATE.
+ clear UNIQUE.
clear MEM TGT STATE.
unfold Assertion.update_private. ss.
ii. rewrite IdTSetFacts.add_iff in *. des.
{ (* x is alloca *)
destruct x as [[] x]; ss.
unfold IdT.lift, AssnState.Unary.sem_idT in *. ss. clarify.
exploit ALLOC_PRIVATE0; eauto. solve_leibniz. clarify. }
{ exploit PRIVATE; eauto. }
- (* alloca, alloca *)
(*
* assnmem1 = assnmem0 + (newl_src -> newl_tgt)
* invstate.rel.sem inv0: possible (monotone w.r.t. assnmem)
* invstate.rel.sem unique (added): newl <> old locations
* newl: st0.mem.nextblock,
wf: st0's old locations < st0.mem.nextblock (genericvalues_inject.wf_sb_mi)
* invstate.rel.sem remove_def_from_maydiff (add): possible
* assnmem.rel.sem: adding (newl_src -> newl_tgt)
* assnmem.rel.le: possible
* postcond_cmd_check: monotonicity
*)
clear ALLOC_PRIVATE.
(* unfold postcond_cmd_check in POSTCOND_CHECK. des_ifs; des_bool; clarify. *)
unfold postcond_cmd_check in *. des_ifs; des_bool; clarify.
{
erewrite postcond_cmd_inject_event_Subset in Heq1; clarify.
ss.
repeat (des_bool; des); des_sumbool; clarify.
eapply remove_def_from_maydiff_Subset.
}
ss. repeat (des_bool; des; des_sumbool). subst.
clear_true.
splits; ss.
unfold remove_def_from_maydiff in *.
destruct (id_dec id0 id0); [clear_true|ss].
apply_all_once AtomSetImpl_from_list_inter_is_empty.
simpl_list.
inv STATE_STEP.
((inv STEP_SRC; ss); []).
(* inv SRC. *)
inv CMDS_SRC.
((inv STEP_TGT; ss); []).
(* inv TGT. *)
inv CMDS_TGT.
ss.
rename Mem0 into SRC_MEM.
rename Mem' into SRC_MEM_STEP.
rename Mem1 into TGT_MEM.
rename Mem'0 into TGT_MEM_STEP.
remember {| CurSystem := S; CurTargetData := TD;
CurProducts := Ps; Globals := gl; FunTable := fs |} as conf_src.
remember {| CurSystem := S0; CurTargetData := TD0;
CurProducts := Ps0; Globals := gl0; FunTable := fs0 |} as conf_tgt.
remember {|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cmds_src;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 (blk2GV TD mb);
Allocas := mb :: als |};
ECS := ECS0;
Mem := SRC_MEM_STEP |} as EC_src.
remember {|
EC := {|
CurFunction := F0;
CurBB := B0;
CurCmds := cmds_tgt;
Terminator := tmn0;
Locals := updateAddAL GenericValue lc0 id0 (blk2GV TD0 mb0);
Allocas := mb0 :: als0 |};
ECS := ECS1;
Mem := TGT_MEM_STEP |} as EC_tgt.
{
econs; eauto.
- (* SRC *)
inv SRC. inv MEM. inv STATE.
econs; eauto; []. ss.
eapply add_unique_alloca; eauto; try apply SRC; try apply SRC0;
rewrite <- MEM_GMAX; try apply SRC; try apply SRC0.
(* - (* TGT *) *)
(* inv TGT. inv MEM. inv STATE. *)
(* econs; eauto; []. ss. *)
(* eapply add_unique_alloca; eauto; try apply TGT; try apply TGT0; *)
(* rewrite <- MEM_GMAX; try apply TGT; try apply TGT0. *)
- (* MAYDIFF *)
inv SRC. inv TGT.
ii.
simpl in NOTIN.
rewrite IdTSetFacts.remove_b in NOTIN. repeat (des_bool; des).
{ eapply MAYDIFF; eauto. }
unfold IdTSetFacts.eqb in NOTIN.
destruct (IdTSetFacts.eq_dec (IdT.lift Tag.physical id0) id1); [|ss].
clear_true. clarify.
solve_leibniz. clarify.
u. ss.
des_lookupAL_updateAddAL.
clarify. clear_true.
esplits; eauto.
move H3 at bottom.
move H7 at bottom.
idtac.
unfold blk2GV.
unfold ptr2GV.
unfold val2GV.
Fail eapply genericvalues_inject.gv_inject_cons.
move CONF at bottom.
inv CONF. inv INJECT. simpl in TARGETDATA. clarify.
econs; eauto. { i; clarify. }
rename mb into _____________mb______________.
rename mb0 into _____________mb0______________.
move WF_LOCAL0 at bottom.
move H7 at bottom.
(* exploit MemProps.nextblock_malloc; try apply H3; []; ii; des. *)
(* exploit MemProps.nextblock_malloc; try apply H7; []; ii; des. *)
exploit MemProps.alloca_result; try apply H3; []; intro ALLOCA_RES1; des.
exploit MemProps.alloca_result; try apply H7; []; intro ALLOCA_RES2; des.
rewrite ALLOCA_RES1. rewrite ALLOCA_RES2. (* subst, clarify ruin ordering of premisses *)
move ALLOC_INJECT at bottom.
unfold alloc_inject in ALLOC_INJECT.
exploit ALLOC_INJECT; eauto; []; ii; des; clear ALLOC_INJECT.
destruct assnmem1; ss.
unfold alloc_inject_unary in *. des. ss.
des_lookupAL_updateAddAL.
econs; eauto.
- ss. clarify.
}
Qed.
Lemma opsem_assigns_getCmdID
conf st0 st1 evt
cmd cmds x
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(CMD_ID: getCmdID cmd = Some x)
: exists gv, lookupAL _ st1.(EC).(Locals) x = Some gv.
Proof.
inv STEP; ss; clarify; ss; clarify;
try by esplits; apply lookupAL_updateAddAL_eq.
Qed.
Lemma wf_GVs__lessthan_undef
TD gl t gvu gv
(CONST_GV: const2GV TD gl (const_undef t) = Some gvu)
(WF_GVS: opsem_wf.OpsemPP.wf_GVs TD gv t)
: GVs.lessdef gvu gv.
Proof.
exploit const2GV_undef; eauto. i. des.
inv WF_GVS. unfold gv_chunks_match_typ in *. des_ifs.
apply all_undef_lessdef_aux; eauto.
exploit vm_matches_typ__eq__snd; eauto. i.
rewrite util.snd_split__map_snd in *. eauto.
apply vm_matches_typ__gv_has_chunk in H1. unfold gv_has_chunk in *.
eapply Forall_impl; eauto.
i. ss. des_ifs. apply genericvalues_inject.has_chunk__has_chunkb. s. ss.
Qed.
Lemma lessdef_definedness
conf st0 st1 invst evt
cmd cmds exp_pair
(STEP: sInsn conf st0 st1 evt)
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(DEFINED: postcond_cmd_get_definedness cmd = Some exp_pair)
: AssnState.Unary.sem_lessdef conf st1 invst exp_pair.
Proof.
ii.
unfold postcond_cmd_get_definedness in *. des_ifs. ss.
unfold AssnState.Unary.sem_idT. ss.
unfold Cmd.get_def in *.
assert (CMD_TYP: lookupTypViaIDFromFdef st1.(EC).(CurFunction) i0 = Some t).
{ replace st1.(EC).(CurFunction) with st0.(EC).(CurFunction); cycle 1.
{ inv STEP; ss; by clarify. }
unfold opsem_wf.OpsemPP.wf_State in *. des_ifs. ss. des.
unfold opsem_wf.OpsemPP.wf_ExecutionContext in *.
destruct EC0. destruct WF_STATE_PREV as (_ & IN_FDEF & IN_PRODS & WF_LC & _ & CMDS_BB0).
destruct CurBB0 as [l [phis_BB0 cmds_BB0 tmn_BB0]].
eapply infrastructure_props.uniqF__lookupTypViaIDFromFdef; eauto.
- ss.
eapply infrastructure_props.uniqSystem__uniqFdef.
+ inv WF_CONF1. eauto.
+ unfold productInSystemModuleB. unfold is_true.
apply andb_true_iff. split; eauto.
- des. clarify. ss.
apply in_app. right. subst. econs. eauto.
}
assert (WF_STATE_NEXT: opsem_wf.OpsemPP.wf_State conf st1).
{ eapply opsem_wf.OpsemPP.preservation; eauto. }
assert (WF_LC : forall (gvs0 : GenericValue),
lookupAL GenericValue st1.(EC).(Locals) i0 = Some gvs0 ->
opsem_wf.OpsemPP.wf_GVs conf.(CurTargetData) gvs0 t).
{ unfold opsem_wf.OpsemPP.wf_State in WF_STATE_NEXT. des_ifs. ss.
destruct WF_STATE_NEXT as [WF_EC _].
unfold opsem_wf.OpsemPP.wf_ExecutionContext in *. destruct EC0. simpl.
destruct WF_EC as (_ & _ & _ & WF_LC & _).
unfold opsem_wf.OpsemPP.wf_lc in *. eauto.
}
exploit opsem_assigns_getCmdID; eauto. i. des.
esplits; eauto.
exploit WF_LC; eauto. intros WF_GVS.
eapply wf_GVs__lessthan_undef; eauto.
Qed.
Lemma lessdef_add_definedness
conf st0 st1 evt
cmd cmds
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(NONCALL: Instruction.isCallInst cmd = false)
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
: forall invst exp_pair lessdef
(DEFINED: postcond_cmd_get_definedness cmd = Some exp_pair)
(FORALL: ExprPairSet.For_all
(AssnState.Unary.sem_lessdef conf st1 invst)
lessdef),
ExprPairSet.For_all
(AssnState.Unary.sem_lessdef conf st1 invst)
(ExprPairSet.add exp_pair lessdef).
Proof.
ii. simpl_ep_set; ss; cycle 1.
- apply FORALL; ss.
- solve_leibniz. clarify.
exploit lessdef_definedness; eauto.
Qed.
Lemma lessdef_add
conf st invst lessdef lhs rhs
(FORALL: ExprPairSet.For_all
(AssnState.Unary.sem_lessdef conf st invst)
lessdef)
(EQ: AssnState.Unary.sem_expr conf st invst lhs = AssnState.Unary.sem_expr conf st invst rhs):
ExprPairSet.For_all
(AssnState.Unary.sem_lessdef conf st invst)
(ExprPairSet.add (lhs, rhs) (ExprPairSet.add (rhs, lhs) lessdef)).
Proof.
ii. simpl_ep_set; ss; cycle 2.
- apply FORALL; ss.
- solve_leibniz. clarify. ss.
rewrite <- EQ. esplits; eauto. apply GVs.lessdef_refl. (* TODO: reflexivity *)
- solve_leibniz. clarify. ss.
rewrite EQ. esplits; eauto. apply GVs.lessdef_refl. (* TODO: reflexivity *)
Qed.
(* TODO Move to AssnState? Unity with AssnState.Unary.sem_valueT_physical? *)
Lemma sem_list_valueT_physical
conf state invst0 sz_values1 lc gl
__INSN_ID__ mp'
(STATE: Locals (EC state) = updateAddAL GenericValue lc __INSN_ID__ mp')
(CONFIG: (Globals conf) = gl)
(POSTCOND_CHECK: Forall (fun y => __INSN_ID__ <> y)
(filter_map Value.get_ids (List.map snd sz_values1)))
:
<<EQUIV: values2GVs (CurTargetData conf) sz_values1 lc gl =
AssnState.Unary.sem_list_valueT
conf state invst0
(List.map (fun elt => (fst elt,
ValueT.lift Tag.physical (snd elt))) sz_values1)>>
.
Proof.
red.
generalize dependent lc.
generalize dependent gl.
generalize dependent POSTCOND_CHECK.
induction sz_values1; ii; ss.
destruct a; ss.
rewrite IHsz_values1; auto; cycle 1.
{ unfold compose in *. ss. destruct t; ss; simpl_list; ss. }
clear IHsz_values1.
remember
(AssnState.Unary.sem_list_valueT
conf state invst0
(List.map (fun elt => (fst elt, ValueT.lift Tag.physical (snd elt))) sz_values1)) as
X.
clear HeqX.
destruct X eqn:T; ss; des_ifs;
try (erewrite AssnState.Unary.sem_valueT_physical in Heq0; eauto; []; ii; des);
try rewrite STATE in *; u; ss;
des_ifs; simpl_list; des_lookupAL_updateAddAL.
Qed.
Lemma postcond_cmd_add_lessdef_unary_sound_alloca
conf st0 st1 cmd cmds def uses
invst0 assnmem0 inv0 gmax public
evt
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(POSTCOND_CHECK: AtomSetImpl.is_empty (AtomSetImpl.inter def uses))
(STATE: AssnState.Unary.sem conf st1 invst0 assnmem0 gmax public inv0)
(MEM: AssnMem.Unary.sem conf gmax public st1.(Mem) assnmem0)
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(DEF: def = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd)))
(USES: uses = AtomSetImpl_from_list (Cmd.get_ids cmd))
id1 typ1 value1 align1
(GEP: cmd = insn_alloca id1 typ1 value1 align1)
:
<<STATE: AssnState.Unary.sem
conf st1 invst0 assnmem0 gmax public
(Assertion.update_lessdef (postcond_cmd_add_lessdef cmd) inv0)>>
.
Proof.
generalize (lessdef_add_definedness WF_CONF WF_STATE_PREV NONCALL STEP CMDS).
intro DEFINEDNESS.
(inv NONCALL; []); (inv STATE; []); ss; ((inv STEP; ss); []).
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK.
(* clear LESSDEF NOALIAS UNIQUE PRIVATE. *)
remember
{| CurSystem := S; CurTargetData := TD; CurProducts := Ps; Globals := gl; FunTable := fs |}
as conf.
assert(CONF1: conf.(CurTargetData) = TD).
{ rewrite Heqconf. auto. }
assert(CONF2: conf.(Globals) = gl).
{ rewrite Heqconf. auto. }
remember {|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cs;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 (blk2GV TD mb);
Allocas := mb :: als |};
ECS := ECS0;
Mem := Mem' |} as state.
assert(STATE1: state.(EC).(Locals) = updateAddAL GenericValue lc id0 (blk2GV TD mb)).
{ rewrite Heqstate. auto. }
assert(STATE2: state.(Mem) = Mem').
{ rewrite Heqstate. auto. }
clear Heqconf Heqstate.
inv CMDS.
(* clear MEM. *)
simpl_list.
rename id1 into __INSN_ID__.
ss. u. ss.
destruct (Decs.align_dec align1 Align.One) eqn:T; ss.
-
apply lessdef_add; [apply DEFINEDNESS; ss|];[].
{
ss. u. ss.
rewrite STATE1. des_lookupAL_updateAddAL.
exploit memory_props.MemProps.nextblock_alloca; eauto; []; ii; des.
exploit memory_props.MemProps.alloca_result; eauto; []; ii; des.
subst. ss.
unfold const2GV. unfold _const2GV.
unfold gundef.
unfold mload.
destruct (flatten_typ (CurTargetData conf) typ1) eqn:T2; ss.
erewrite MemProps.alloca_mload_aux_undef; eauto.
unfold const2GV. unfold _const2GV. unfold gundef. rewrite T2. ss.
}
-
apply lessdef_add.
+
apply lessdef_add; [apply DEFINEDNESS; ss|]; [].
{
ss. u. ss.
rewrite STATE1. des_lookupAL_updateAddAL.
exploit memory_props.MemProps.nextblock_alloca; eauto; []; ii; des.
exploit memory_props.MemProps.alloca_result; eauto; []; ii; des.
subst. ss.
unfold const2GV. unfold _const2GV.
unfold gundef.
unfold mload.
destruct (flatten_typ (CurTargetData conf) typ1) eqn:T2; ss.
erewrite MemProps.alloca_mload_aux_undef; eauto.
unfold const2GV. unfold _const2GV. unfold gundef. rewrite T2. ss.
}
+
{
ss. u. ss.
rewrite STATE1. des_lookupAL_updateAddAL.
exploit memory_props.MemProps.nextblock_alloca; eauto; []; ii; des.
exploit memory_props.MemProps.alloca_result; eauto; []; ii; des.
subst. ss.
unfold const2GV. unfold _const2GV.
unfold gundef.
unfold mload.
destruct (flatten_typ (CurTargetData conf) typ1) eqn:T2; ss.
erewrite MemProps.alloca_mload_aux_undef; eauto.
unfold const2GV. unfold _const2GV. unfold gundef. rewrite T2. ss.
}
Unshelve.
eauto.
eauto.
eauto.
Qed.
Lemma postcond_cmd_add_lessdef_unary_sound_gep
conf st0 st1 cmd cmds def uses
invst0 assnmem0 inv0 gmax public
evt
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(POSTCOND_CHECK: AtomSetImpl.is_empty (AtomSetImpl.inter def uses))
(STATE: AssnState.Unary.sem conf st1 invst0 assnmem0 gmax public inv0)
(MEM: AssnMem.Unary.sem conf gmax public st1.(Mem) assnmem0)
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(DEF: def = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd)))
(USES: uses = AtomSetImpl_from_list (Cmd.get_ids cmd))
id1 inbounds1 typ1 value1 sz_values1 typ2
(GEP: cmd = insn_gep id1 inbounds1 typ1 value1 sz_values1 typ2)
:
<<STATE: AssnState.Unary.sem
conf st1 invst0 assnmem0 gmax public
(Assertion.update_lessdef (postcond_cmd_add_lessdef cmd) inv0)>>
.
Proof.
generalize (lessdef_add_definedness WF_CONF WF_STATE_PREV NONCALL STEP CMDS).
intro DEFINEDNESS.
(inv NONCALL; []); (inv STATE; []); ss; ((inv STEP; ss); []).
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK.
apply lessdef_add; [apply DEFINEDNESS; ss|]; [].
clear LESSDEF NOALIAS UNIQUE PRIVATE.
remember
{| CurSystem := S; CurTargetData := TD; CurProducts := Ps; Globals := gl; FunTable := fs |}
as conf.
assert(CONF1: conf.(CurTargetData) = TD).
{ rewrite Heqconf. auto. }
assert(CONF2: conf.(Globals) = gl).
{ rewrite Heqconf. auto. }
remember
{|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cs;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 mp';
Allocas := als |};
ECS := ECS0;
Mem := Mem0 |} as state.
assert(STATE: state.(EC).(Locals) = updateAddAL GenericValue lc id0 mp').
{ rewrite Heqstate. auto. }
clear Heqconf Heqstate.
inv CMDS.
clear MEM.
simpl_list.
rename id1 into __INSN_ID__.
ss. u. ss.
rewrite STATE. des_lookupAL_updateAddAL.
clear e.
rewrite <- H2. clear H2.
exploit sem_list_valueT_physical; eauto.
{ destruct value1; ss; simpl_list; eauto. }
ii; des.
rewrite <- x0.
rewrite AssnState.Unary.sem_valueT_physical in *.
destruct value1; ss.
- rewrite STATE; simpl_list; des_lookupAL_updateAddAL.
rewrite H.
rewrite H1.
ss.
- rewrite H.
rewrite H1.
ss.
Qed.
Lemma postcond_cmd_add_lessdef_unary_sound_select
conf st0 st1 cmd cmds def uses
invst0 assnmem0 inv0 gmax public
evt
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(POSTCOND_CHECK: AtomSetImpl.is_empty (AtomSetImpl.inter def uses))
(STATE: AssnState.Unary.sem conf st1 invst0 assnmem0 gmax public inv0)
(MEM: AssnMem.Unary.sem conf gmax public st1.(Mem) assnmem0)
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(DEF: def = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd)))
(USES: uses = AtomSetImpl_from_list (Cmd.get_ids cmd))
id1 value_cond typ1 value1 value2
(GEP: cmd = insn_select id1 value_cond typ1 value1 value2)
:
<<STATE: AssnState.Unary.sem
conf st1 invst0 assnmem0 gmax public
(Assertion.update_lessdef (postcond_cmd_add_lessdef cmd) inv0)>>
.
Proof.
generalize (lessdef_add_definedness WF_CONF WF_STATE_PREV NONCALL STEP CMDS).
clear WF_STATE_PREV.
intro DEFINEDNESS.
(inv NONCALL; []); (inv STATE; []); ss; ((inv STEP; ss); []).
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK.
apply lessdef_add; [apply DEFINEDNESS; ss|]; [].
clear LESSDEF NOALIAS UNIQUE PRIVATE.
remember
{| CurSystem := S; CurTargetData := TD; CurProducts := Ps; Globals := gl; FunTable := fs |}
as conf.
assert(CONF1: conf.(CurTargetData) = TD).
{ rewrite Heqconf. auto. }
assert(CONF2: conf.(Globals) = gl).
{ rewrite Heqconf. auto. }
remember {|
EC := {|
CurFunction := F;
CurBB := B;
CurCmds := cs;
Terminator := tmn;
Locals := updateAddAL GenericValue lc id0 gvresult;
Allocas := als |};
ECS := ECS0;
Mem := Mem0 |} as state.
assert(STATE: state.(EC).(Locals) = updateAddAL GenericValue lc id0 gvresult).
{ rewrite Heqstate. auto. }
clear Heqconf Heqstate.
inv CMDS.
clear MEM.
simpl_list.
rename id1 into __INSN_ID__.
ss. u. ss.
rewrite STATE. des_lookupAL_updateAddAL.
clear e.
rewrite ? AssnState.Unary.sem_valueT_physical in *.
unfold SELECT in *.
destruct value_cond, value1, value2; simpl in *;
try rewrite STATE; simpl_list; des_lookupAL_updateAddAL;
try rewrite H; try rewrite H1; try rewrite H2; try rewrite INT; ss.
Qed.
Lemma postcond_cmd_add_lessdef_unary_sound
conf st0 st1 cmd cmds def uses
invst0 assnmem0 inv0 gmax public
evt
(WF_CONF: opsem_wf.OpsemPP.wf_Config conf)
(WF_STATE_PREV: opsem_wf.OpsemPP.wf_State conf st0)
(POSTCOND_CHECK: AtomSetImpl.is_empty (AtomSetImpl.inter def uses))
(STATE: AssnState.Unary.sem conf st1 invst0 assnmem0 gmax public inv0)
(MEM: AssnMem.Unary.sem conf gmax public st1.(Mem) assnmem0)
(STEP: sInsn conf st0 st1 evt)
(CMDS: st0.(EC).(CurCmds) = cmd :: cmds)
(NONCALL: Instruction.isCallInst cmd = false)
(DEF: def = AtomSetImpl_from_list (option_to_list (Cmd.get_def cmd)))
(USES: uses = AtomSetImpl_from_list (Cmd.get_ids cmd))
:
<<STATE: AssnState.Unary.sem
conf st1 invst0 assnmem0 gmax public
(Assertion.update_lessdef (postcond_cmd_add_lessdef cmd) inv0)>>
.
Proof.
generalize (lessdef_add_definedness WF_CONF WF_STATE_PREV NONCALL STEP CMDS).
intro DEFINEDNESS.
(* clear WF_CONF WF_STATE_PREV. *)
destruct cmd;
try (eapply postcond_cmd_add_lessdef_unary_sound_alloca; eauto; fail);
try (eapply postcond_cmd_add_lessdef_unary_sound_gep; eauto; fail);
try (eapply postcond_cmd_add_lessdef_unary_sound_select; eauto; fail);
ss; (inv NONCALL; []); (inv STATE; []); ss; ((inv STEP; ss); []);
try (econs; eauto; []; apply lessdef_add; [apply DEFINEDNESS;ss |]; ss;
rewrite ? AssnState.Unary.sem_valueT_physical in *; ss;
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK; [];
repeat match goal with
| [ v: value |- _ ] => destruct v
end; u; ss; simpl_list; des_lookupAL_updateAddAL; des_ifs; fail).
- (* alloca *)
clear WF_CONF WF_STATE_PREV.
clarify.
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
des_ifs;
repeat apply lessdef_add; ss;
(rewrite ? AssnState.Unary.sem_valueT_physical in *; ss; [];
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK; [];
repeat match goal with
| [ v: value |- _ ] => destruct v
end; u; ss; simpl_list; des_lookupAL_updateAddAL; des_ifs;
apply DEFINEDNESS; ss).
- (* load *)
clear WF_CONF WF_STATE_PREV.
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
des_ifs;
repeat apply lessdef_add; ss;
(rewrite ? AssnState.Unary.sem_valueT_physical in *; ss; [];
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK; [];
repeat match goal with
| [ v: value |- _ ] => destruct v
end; u; ss; simpl_list; des_lookupAL_updateAddAL; des_ifs;
apply DEFINEDNESS; ss).
- (* store *)
clear WF_CONF WF_STATE_PREV.
econs; eauto; [].
unfold postcond_cmd_add_lessdef. ss.
apply AtomSetImpl_from_list_inter_is_empty in POSTCOND_CHECK.
simpl_list.
des_ifs.
+
apply lessdef_add; [apply LESSDEF|].
clear LESSDEF NOALIAS UNIQUE PRIVATE.
ss.
destruct value1, value2; ss; u; ss; rewrite H; rewrite H0; des_lookupAL_updateAddAL;
erewrite MemProps.mstore_mload_same; eauto.
+
apply lessdef_add.
apply lessdef_add; [apply LESSDEF|].
clear LESSDEF NOALIAS UNIQUE PRIVATE.