Require Import Classical.
Require Import Coqlib.
Require Import Maps.
Require Import AST.
Require Import Integers.
Require Import Values.
Require Import Memory.
Require Import Globalenvs.
Require Import Smallstep.
Require Import Op.
Require Import Events.
Require Import Registers.
Require Import Floats.
Require Import Utils.
Require Import SSA.
Require Import SSAutils.
Require Import SSAinv.
Require Import Utilsvalidproof.
Require Import DomCompute.
Require Import Axioms.
Require Import KildallComp.
Require Import OrderedType.
Require Import Ordered.
Require Import FSets.
Require FSetAVL.
Require Import Dsd.
Require Import OptInv.
Require Import GVNopt.
Require Import GVNoptProp.
Require Import DLib.
Require Import Linking.
Require Opt.
Require OptInv.
Unset Allow StrictProp.
Correctness of the optimization
Section PRESERVATION.
Definition match_prog (
p:
SSA.program) (
tp:
SSA.program) :=
match_program (
fun cu f tf =>
tf =
transf_fundef f)
eq p tp.
Lemma transf_program_match:
forall p,
match_prog p (
transf_program p).
Proof.
Section CORRECTNESS.
Variable prog:
program.
Variable tprog:
program.
Hypothesis TRANSL :
match_prog prog tprog.
Hypothesis HWF :
wf_ssa_program prog.
Let ge :=
Genv.globalenv prog.
Let tge :=
Genv.globalenv tprog.
Lemma symbols_preserved:
forall (
s:
ident),
Genv.find_symbol tge s =
Genv.find_symbol ge s.
Proof.
Lemma match_prog_wf_ssa :
wf_ssa_program tprog.
Proof.
red.
intros.
red in HWF.
inv TRANSL.
intuition.
revert H0 H HWF.
induction 1;
intros.
-
inv H.
-
inv H1.
+
inv H.
inv H4.
destruct f1 ;
simpl in * ;
try constructor;
auto.
eapply Opt.transf_function_preserve_wf_ssa_function;
eauto.
*
eapply new_code_same_or_Iop;
eauto.
*
exploit (
HWF (
Internal f)
id);
eauto.
destruct a1,
g;
simpl in * ;
try congruence.
left.
inv H;
simpl in *;
auto.
intros.
inv H4;
auto.
+
eapply IHlist_forall2;
eauto.
Qed.
Lemma funct_ptr_translated:
forall (
b:
Values.block) (
f:
fundef),
Genv.find_funct_ptr ge b =
Some f ->
Genv.find_funct_ptr tge b =
Some (
transf_fundef f).
Proof.
Lemma functions_translated:
forall (
v:
val) (
f:
fundef),
Genv.find_funct ge v =
Some f ->
Genv.find_funct tge v =
Some (
transf_fundef f).
Proof.
Lemma sig_preserved:
forall f,
funsig (
transf_fundef f) =
funsig f.
Proof.
destruct f; simpl ; try reflexivity.
Qed.
Lemma find_function_translated:
forall ros rs f,
find_function ge ros rs =
Some f ->
find_function tge ros rs =
Some (
transf_fundef f).
Proof.
Lemma fn_params_translated :
forall (
f:
function),
fn_params f =
fn_params (
transf_function f).
Proof.
Lemma fn_entrypoint_translated :
forall (
f:
function),
fn_entrypoint f =
fn_entrypoint (
transf_function f).
Proof.
Lemma senv_equiv :
Senv.equiv ge tge.
Proof.
Inductive match_stackframes :
list stackframe ->
list stackframe ->
Prop :=
|
match_stackframes_nil:
match_stackframes nil nil
|
match_stackframes_cons:
forall res (
f:
function)
sp b pc rs s st
(
STACK: (
match_stackframes s st))
(
SP:
sp = (
Vptr b Ptrofs.zero))
(
WFF:
wf_ssa_function f)
(
HG:
forall v,
gamma GVN f ge sp pc (
rs#
res <-
v))
(
EXE:
exec f pc),
match_stackframes
((
Stackframe res f sp pc rs) ::
s)
((
Stackframe res (
transf_function f)
sp pc rs) ::
st).
Variant match_states:
state ->
state ->
Prop :=
|
match_states_intro:
forall s st sp b pc rs m f
(
SP:
sp = (
Vptr b Ptrofs.zero))
(
SINV:
s_inv ge (
State s f sp pc rs m))
(
HG:
gamma GVN f ge sp pc rs)
(
EXE:
exec f pc)
(
STACK:
match_stackframes s st),
match_states (
State s f sp pc rs m) (
State st (
transf_function f)
sp pc rs m)
|
match_states_call:
forall s st f args m
(
SINV:
s_inv ge (
Callstate s f args m))
(
STACK:
match_stackframes s st),
match_states (
Callstate s f args m) (
Callstate st (
transf_fundef f)
args m)
|
match_states_return:
forall s st v m
(
SINV:
s_inv ge (
Returnstate s v m))
(
STACK:
match_stackframes s st),
match_states (
Returnstate s v m) (
Returnstate st v m).
Lemma transf_initial_states:
forall st1,
initial_state prog st1 ->
exists st2,
initial_state tprog st2 /\
match_states st1 st2.
Proof.
Lemma transf_final_states:
forall st1 st2 r,
match_states st1 st2 ->
final_state st1 r ->
final_state st2 r.
Proof.
intros. inv H0. inv H.
inv STACK.
constructor.
Qed.
Lemma same_fn_code:
forall f pc,
(
forall op args res pc',
(
fn_code f) !
pc <>
Some (
Iop op args res pc')) ->
(
fn_code (
transf_function f)) !
pc = (
fn_code f) !
pc.
Proof.
Lemma new_fn_code:
forall f pc op args res pc',
(
fn_code f) !
pc =
Some (
Iop op args res pc') ->
((
fn_code (
transf_function f)) !
pc =
Some (
Iop op args res pc'))
\/ (
exists res',
(
fn_code (
transf_function f)) !
pc =
Some (
Iop Omove (
res' ::
nil)
res pc')
/\
A_r f res =
res'
/\
res <>
res').
Proof.
Hint Constructors ext_params dsd:
core.
Lemma join_point_transf_function :
forall f (
WF:
wf_ssa_function f)
j,
join_point j (
transf_function f) <->
join_point j f.
Proof.
Lemma make_predecessors_transf_function:
forall f (
WF:
wf_ssa_function f),
(
Kildall.make_predecessors (
fn_code (
transf_function f))
successors_instr) =
(
Kildall.make_predecessors (
fn_code f)
successors_instr).
Proof.
Lemma eval_iop_correct :
forall f (
WF:
wf_ssa_function f)
m res rs sp v pc pc'
args op s,
exec f pc ->
gamma GVN f ge sp pc rs ->
eval_operation ge sp op rs ##
args m =
Some v ->
s_inv ge (
State s f sp pc rs m) ->
(
fn_code f) !
pc =
Some (
Iop op args res pc') ->
(
fn_code (
transf_function f)) !
pc =
Some (
Iop Omove (
A_r f res ::
nil)
res pc') ->
res <>
A_r f res ->
eval_operation tge sp Omove rs ## (
A_r f res ::
nil)
m =
Some v.
Proof.
Lemma match_stackframes_sfg_inv :
forall s st,
match_stackframes s st ->
sfg_inv GVN prog s.
Proof.
induction 1 ; go.
Qed.
Hint Resolve match_stackframes_sfg_inv:
core.
Lemma subj_red_gamma :
forall prog (
WFP:
wf_ssa_program prog),
forall (
f f' :
function)
(
t :
trace) (
m m' :
mem)
(
rs rs' :
regset)
sp sp' (
pc pc' :
node)
(
s s' :
list stackframe),
gamma GVN f (
Genv.globalenv prog) (
Vptr sp Ptrofs.zero)
pc rs ->
sfg_inv GVN prog s ->
exec f pc ->
s_inv (
Genv.globalenv prog) (
State s f (
Vptr sp Ptrofs.zero)
pc rs m) ->
step (
Genv.globalenv prog) (
State s f (
Vptr sp Ptrofs.zero)
pc rs m)
t
(
State s'
f' (
Vptr sp'
Ptrofs.zero)
pc'
rs'
m') ->
gamma GVN f' (
Genv.globalenv prog) (
Vptr sp'
Ptrofs.zero)
pc'
rs'.
Proof.
Lemma transl_step_correct:
forall s1 t s2,
step ge s1 t s2 ->
step ge s1 t s2 ->
forall s1' (
MS:
match_states s1 s1'),
exists s2',
step tge s1'
t s2' /\
match_states s2 s2'.
Proof.
Semantics preservation
Theorem transf_program_correct:
forward_simulation (
SSA.semantics prog) (
SSA.semantics tprog).
Proof.
End CORRECTNESS.
End PRESERVATION.