Module RTLpathSchedulerproof
Lemma s_find_function_fundef f sp svos rs0 m0 fd
(LIVE: liveness_ok_function f):
sfind_function pge ge sp svos rs0 m0 = Some fd ->
liveness_ok_fundef fd.
Proof.
Local Hint Resolve s_find_function_fundef: core.
Lemma s_find_function_preserved f sp svos1 svos2 rs0 m0 fd
(LIVE: liveness_ok_function f):
(svident_simu f (mkctx sp rs0 m0 LIVE) svos1 svos2) ->
sfind_function pge ge sp svos1 rs0 m0 = Some fd ->
exists fd', sfind_function tpge tge sp svos2 rs0 m0 = Some fd'
/\ transf_fundef fd = OK fd'.
Proof.
Lemma sistate_simu f dupmap outframe sp st st' rs m is
(LIVE: liveness_ok_function f):
ssem_internal ge sp st rs m is ->
sistate_simu dupmap f outframe st st' (mkctx sp rs m LIVE)->
exists is',
ssem_internal tge sp st' rs m is' /\ istate_simu f dupmap outframe is is'.
Proof.
intros SEM X; eapply X; eauto.
Qed.
Lemma seval_builtin_sval_preserved sp rs m:
forall bs, seval_builtin_sval ge sp bs rs m = seval_builtin_sval tge sp bs rs m.
Proof.
Lemma seval_list_builtin_sval_preserved sp rs m:
forall lbs,
seval_list_builtin_sval ge sp lbs rs m = seval_list_builtin_sval tge sp lbs rs m.
Proof.
Lemma ssem_final_simu dm f f' stk stk' sp st st' rs0 m0 sv sv' rs m t s
(LIVE: liveness_ok_function f):
match_function dm f f' ->
list_forall2 match_stackframes stk stk' ->
sfval_simu dm f st.(si_pc) st'.(si_pc) (mkctx sp rs0 m0 LIVE) sv sv' ->
ssem_final pge ge sp st.(si_pc) stk f rs0 m0 sv rs m t s ->
exists s', ssem_final tpge tge sp st'.(si_pc) stk' f' rs0 m0 sv' rs m t s' /\ match_states s s'.
Proof.
Lemma siexec_snone_por_correct rs' is t s alive path0 i sp s0 st0 stk stk' f rs0 m0: forall
(SSEM2 : ssem_final pge ge sp (si_pc s0) stk f rs0 m0 Snone
(irs is) (imem is) t s)
(SIEXEC : siexec_inst i st0 = Some s0)
(ICHK : inst_checker (fn_path f) alive (pre_output_regs path0) i = Some tt),
(liveness_ok_function f) ->
list_forall2 match_stackframes stk stk' ->
eqlive_reg (fun r : Regset.elt => Regset.In r (pre_output_regs path0)) (irs is) rs' ->
exists s' : state,
ssem_final pge ge sp (si_pc s0) stk f rs0 m0 Snone rs' (imem is) t s' /\
eqlive_states s s'.
Proof.
Local Hint Resolve eqlive_stacks_refl:
core.
intros ? ? ?
LIVE STK EQLIVE.
inversion SSEM2;
subst;
clear SSEM2.
eexists;
split.
*
econstructor.
*
generalize ICHK.
unfold inst_checker.
destruct i;
simpl in *;
unfold exit_checker;
try discriminate.
all:
try destruct (
list_mem _ _);
simpl;
try (
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence;
fail).
4,5:
destruct (
Regset.mem _ _);
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence.
1,2,3,4:
assert (
NPC:
n=(
si_pc s0)).
all:
try (
inv SIEXEC;
simpl;
auto;
fail).
1,2,3,4:
try (
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence);
simpl;
inversion_SOME p;
destruct (
Regset.subset (
input_regs p) (
pre_output_regs path0))
eqn:
SUB_PATH;
try congruence;
intros NPATH _;
econstructor;
eauto;
try (
instantiate (1:=
p);
rewrite <-
NPC;
auto;
fail).
1,2,3,4:
eapply eqlive_reg_monotonic;
eauto;
simpl;
intros;
apply Regset.subset_2 in SUB_PATH;
unfold Regset.Subset in SUB_PATH;
apply SUB_PATH in H;
auto.
assert (
NPC:
n0=(
si_pc s0)). {
inv SIEXEC;
simpl;
auto. }
inversion_SOME p.
2: {
destruct (
Regset.subset _ _)
eqn:?;
try congruence. }
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence.
2: {
destruct (
Regset.subset (
pre_output_regs path0)
alive)
eqn:?;
try congruence. }
simpl.
destruct (
Regset.subset (
pre_output_regs path0)
alive)
eqn:
SUB_ALIVE';
try congruence.
inversion_SOME p'.
destruct (
Regset.subset (
input_regs p') (
pre_output_regs path0))
eqn:
SUB_PATH;
try congruence.
intros NPATH NPATH'
_.
econstructor;
eauto.
instantiate (1:=
p').
rewrite <-
NPC;
auto.
eapply eqlive_reg_monotonic;
eauto;
simpl.
intros.
apply Regset.subset_2 in SUB_PATH.
unfold Regset.Subset in SUB_PATH.
apply SUB_PATH in H;
auto.
Qed.
Lemma pre_output_regs_correct f pc0 path0 stk stk' sp (st:sstate) rs0 m0 t s is rs':
(liveness_ok_function f) ->
(fn_path f) ! pc0 = Some path0 ->
sexec f pc0 = Some st ->
list_forall2 match_stackframes stk stk' ->
ssem_final pge ge sp (si_pc st) stk f rs0 m0 (final st) (irs is) (imem is) t s ->
eqlive_reg (fun r : Regset.elt => Regset.In r (pre_output_regs path0)) (irs is) rs' ->
exists s', ssem_final pge ge sp (si_pc st) stk f rs0 m0 (final st) rs' (imem is) t s' /\ eqlive_states s s'.
Proof.
Local Hint Resolve eqlive_stacks_refl:
core.
intros LIVE PATH0 SEXEC STK SSEM2 EQLIVE.
generalize (
LIVE pc0 path0 PATH0).
unfold path_checker.
inversion_SOME res;
intros IPCHK.
inversion_SOME i;
intros INST ICHK.
exploit ipath_checker_default_succ;
eauto.
intros DEFSUCC.
generalize SEXEC;
clear SEXEC.
unfold sexec;
rewrite PATH0.
inversion_SOME st0;
intros SEXEC_PATH.
exploit siexec_path_default_succ;
eauto.
simpl.
rewrite DEFSUCC.
clear DEFSUCC.
destruct res as [
alive pc1].
simpl in *.
try_simplify_someHyps.
destruct (
siexec_inst i st0)
eqn:
SIEXEC;
try_simplify_someHyps;
intros.
eapply siexec_snone_por_correct;
eauto.
destruct i;
try_simplify_someHyps;
try congruence;
inversion SSEM2;
subst;
clear SSEM2;
simpl in *.
+
eexists;
split.
*
econstructor;
eauto.
*
econstructor;
eauto.
econstructor;
eauto.
generalize ICHK.
unfold inst_checker;
simpl in *.
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence.
destruct (
list_mem _ _);
try congruence.
destruct (
reg_sum_mem _ _);
try congruence.
intros EXIT.
exploit exit_checker_eqlive_ext1;
eauto.
intros.
destruct H as [
p [
PATH EQLIVE']].
econstructor;
eauto.
+
eexists;
split.
*
econstructor;
eauto.
*
econstructor;
eauto.
+
eexists;
split.
*
econstructor;
eauto.
*
generalize ICHK.
unfold inst_checker;
simpl in *.
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence.
destruct (
list_mem _ _);
try congruence.
intros EXIT.
exploit exit_checker_eqlive_builtin_res;
eauto.
intros.
destruct H as [
p [
PATH EQLIVE']].
econstructor;
eauto.
+
eexists;
split.
*
econstructor;
eauto.
*
generalize ICHK.
unfold inst_checker;
simpl in *.
destruct (
Regset.subset _ _)
eqn:
SUB_ALIVE;
try congruence.
destruct (
Regset.mem _ _);
try congruence.
destruct (
exit_list_checker _ _ _)
eqn:
EQL;
try congruence.
exploit exit_list_checker_eqlive;
eauto.
intros.
destruct H as [
p [
PATH EQLIVE']].
econstructor;
eauto.
+
eexists;
split.
*
econstructor;
eauto.
*
econstructor;
eauto.
Qed.
Theorem ssem_sstate_simu dm f f' pc0 path0 stk stk' sp st st' rs m t s:
(fn_path f) ! pc0 = Some path0 ->
sexec f pc0 = Some st ->
match_function dm f f' ->
liveness_ok_function f ->
list_forall2 match_stackframes stk stk' ->
ssem pge ge sp st stk f rs m t s ->
(forall ctx: simu_proof_context f, sstate_simu dm f (pre_output_regs path0) st st' ctx) ->
exists s', ssem tpge tge sp st' stk' f' rs m t s' /\ match_states s s'.
Proof.
intros PATH0 SEXEC MFUNC LIVE STACKS SEM SIMU.
destruct (
SIMU (
mkctx sp rs m LIVE))
as (
SIMU1 &
SIMU2);
clear SIMU.
destruct SEM as [
is CONT SEM|
is t s'
CONT SEM1 SEM2];
simpl in *.
-
exploit sistate_simu;
eauto.
unfold istate_simu;
rewrite CONT.
intros (
is' &
SEM' & (
path &
PATH & (
CONT' &
RS' &
M') &
PC')).
exists (
State stk'
f'
sp (
ipc is') (
irs is') (
imem is')).
split.
+
eapply ssem_early;
auto.
congruence.
+
rewrite M'.
econstructor;
eauto.
-
exploit sistate_simu;
eauto.
unfold istate_simu;
rewrite CONT.
intros (
is' &
SEM' & (
CONT' &
RS' &
M')).
exploit pre_output_regs_correct;
eauto.
clear SEM2;
intros (
s0 &
SEM2 &
EQLIVE).
exploit ssem_final_simu;
eauto.
clear SEM2;
intros (
s1 &
SEM2 &
MATCH0).
exploit ssem_final_equiv;
eauto.
clear SEM2;
rewrite M';
rewrite CONT'
in CONT;
intros (
s2 &
EQ &
SEM2).
exists s2;
split.
+
eapply ssem_normal;
eauto.
+
eapply eqlive_match_states;
eauto.
eapply match_states_equiv;
eauto.
Qed.
Lemma exec_path_simulation dupmap path stk stk' f f' sp rs m pc pc' t s:
(fn_path f)!pc = Some path ->
path_step ge pge path.(psize) stk f sp rs m pc t s ->
list_forall2 match_stackframes stk stk' ->
dupmap ! pc' = Some pc ->
match_function dupmap f f' ->
liveness_ok_function f ->
exists path' s', (fn_path f')!pc' = Some path' /\ path_step tge tpge path'.(psize) stk' f' sp rs m pc' t s' /\ match_states s s'.
Proof.
Lemma step_simulation s1 t s1' s2:
step ge pge s1 t s1' ->
match_states s1 s2 ->
exists s2',
step tge tpge s2 t s2'
/\ match_states s1' s2'.
Proof.
Theorem transf_program_correct:
forward_simulation (semantics prog) (semantics tprog).
Proof.
End PRESERVATION.