Require Import Coqlib.
Require Import Errors.
Require Import Maps.
Require Import AST.
Require Import Globalenvs.
Require Import Smallstep.
Require Import Dom.
Require Import Op.
Require Import SSA.
Require Import SSAutils.
Require Import Utils.
Require Import CSSA.
Require Import DLib.
Require Import RTLpargen.
Require Import CSSAutils.
Require Import Registers.
Lemma def_code_correct_aux :
forall elems r r0 ins defs (
pc :
node),
In (
pc,
ins)
elems ->
NoDup (
map fst elems) ->
defined_var ins =
Some r0 ->
r0 =
r ->
(
forall pc'
ins'
r',
pc' <>
pc ->
In (
pc',
ins')
elems ->
defined_var ins' =
Some r' ->
r' <>
r) ->
(
fold_right
(
fun p a =>
match defined_var (
snd p)
with
|
Some r0 =>
PTree.set r0 (
fst p)
a
|
None =>
a
end)
defs elems) !
r =
Some pc.
Proof.
induction elems;
intros.
go.
simpl.
flatten.
+
rewrite PTree.gsspec.
flatten.
-
destruct a.
simpl in *.
case_eq(
peq n pc);
intros;
auto.
destruct H;
go.
symmetry in e.
contradict e.
apply H3 with (
pc' :=
n) (
ins' :=
i);
auto.
-
destruct a.
simpl in *.
case_eq(
peq pc n0);
intros;
auto.
destruct H;
go.
eapply IHelems;
go.
inv H0;
auto.
destruct H;
go.
eapply IHelems;
go.
inv H0;
auto.
+
eapply IHelems;
go.
inv H;
go.
inv H0;
auto.
Qed.
Lemma def_code_correct :
forall f r defs pc,
wf_cssa_function f ->
assigned_code_spec (
fn_code f)
pc r ->
(
compute_code_def f defs) !
r =
Some pc.
Proof.
Lemma nodef_code_correct_aux :
forall elems r defs,
NoDup (
map fst elems) ->
(
forall (
pcins :
node *
instruction)
r',
In pcins elems ->
defined_var (
snd pcins) =
Some r' ->
r' <>
r) ->
(
fold_right
(
fun p a =>
match defined_var (
snd p)
with
|
Some r0 =>
PTree.set r0 (
fst p)
a
|
None =>
a
end)
defs elems) !
r =
defs !
r.
Proof.
induction elems;
intros.
go.
simpl.
flatten.
+
rewrite PTree.gso.
-
apply IHelems.
inv H;
auto.
go.
-
unfold not;
intros.
assert(
r0 <>
r).
eapply H0;
go.
congruence.
+
eapply IHelems;
go.
inv H;
auto.
Qed.
Lemma nodef_code_correct :
forall f r defs,
wf_cssa_function f ->
(
forall pc, ~
assigned_code_spec (
fn_code f)
pc r) ->
(
compute_code_def f defs) !
r =
defs !
r.
Proof.
Lemma def_notin_parcb_correct:
forall parcb r (
pc :
node)
a,
(
forall src, ~
In (
Iparcopy src r)
parcb) ->
(
fold_right
(
fun p a =>
match p with
|
Iparcopy src dst =>
PTree.set dst pc a
end)
a parcb) !
r =
a !
r.
Proof.
induction parcb;
intros;
simpl;
auto.
flatten.
rewrite PTree.gsspec.
flatten.
+
rewrite <-
e in *.
specialize (
H r0).
exfalso.
apply H.
constructor;
auto.
+
apply IHparcb.
intros.
specialize (
H src);
go.
Qed.
Lemma def_in_parcb_correct:
forall parcb r (
pc :
node)
a,
(
exists src,
In (
Iparcopy src r)
parcb) ->
(
fold_right
(
fun p a =>
match p with
|
Iparcopy src dst =>
PTree.set dst pc a
end)
a parcb) !
r =
Some pc.
Proof.
induction parcb;
intros;
simpl.
+
destruct H.
contradiction.
+
flatten.
rewrite PTree.gsspec.
flatten.
apply IHparcb.
destruct H.
inv H;
try congruence.
eauto.
Qed.
Lemma nodef_parc_correct_aux :
forall elems r defs,
(
forall (
pc :
node)
parcb src,
In (
pc,
parcb)
elems ->
~
In (
Iparcopy src r)
parcb) ->
(
fold_right
(
fun pcparcb a =>
fold_left
(
fun a p =>
match p with
|
Iparcopy src dst =>
PTree.set dst (
fst pcparcb)
a
end)
(
snd pcparcb)
a)
defs elems) !
r =
defs !
r.
Proof.
Lemma def_parc_correct_aux :
forall elems r defs parcb (
pc :
node),
(
In (
pc,
parcb)
elems) ->
(
NoDup (
map fst elems)) ->
(
exists src,
In (
Iparcopy src r)
parcb) ->
(
forall src parcb'
pc',
pc' <>
pc ->
In (
pc',
parcb')
elems ->
~
In (
Iparcopy src r)
parcb') ->
(
fold_right
(
fun pcparcb a =>
fold_left
(
fun a p =>
match p with
|
Iparcopy src dst =>
PTree.set dst (
fst pcparcb)
a
end)
(
snd pcparcb)
a)
defs elems) !
r =
Some pc.
Proof.
Lemma def_parcode_correct :
forall f r defs pc,
wf_cssa_function f ->
assigned_parcopy_spec (
fn_parcopycode f)
pc r ->
(
compute_parc_def f defs) !
r =
Some pc.
Proof.
Lemma nodef_parcode_correct :
forall f r defs,
wf_cssa_function f ->
(
forall pc, ~
assigned_parcopy_spec (
fn_parcopycode f)
pc r) ->
(
compute_parc_def f defs) !
r =
defs !
r.
Proof.
Lemma def_notin_phib_correct:
forall phib r (
pc :
node)
a,
(
forall args, ~
In (
Iphi args r)
phib) ->
(
fold_right
(
fun p a =>
match p with
|
Iphi args dst =>
PTree.set dst pc a
end)
a phib) !
r =
a !
r.
Proof.
induction phib;
intros;
simpl;
auto.
flatten.
rewrite PTree.gsspec.
flatten.
+
rewrite <-
e in *.
specialize (
H l).
exfalso.
apply H.
constructor;
auto.
+
apply IHphib.
intros.
specialize (
H args);
go.
Qed.
Lemma def_in_phib_correct:
forall phib r (
pc :
node)
a,
(
exists args,
In (
Iphi args r)
phib) ->
(
fold_right
(
fun p a =>
match p with
|
Iphi args dst =>
PTree.set dst pc a
end)
a phib) !
r =
Some pc.
Proof.
induction phib;
intros;
simpl.
+
destruct H.
contradiction.
+
flatten.
rewrite PTree.gsspec.
flatten.
apply IHphib.
destruct H.
inv H;
try congruence.
eauto.
Qed.
Lemma nodef_phib_correct_aux :
forall elems r defs,
(
forall (
pc :
node)
phib args,
In (
pc,
phib)
elems ->
~
In (
Iphi args r)
phib) ->
(
fold_right
(
fun pcphib a =>
fold_left
(
fun a p =>
match p with
|
Iphi args dst =>
PTree.set dst (
fst pcphib)
a
end)
(
snd pcphib)
a)
defs elems) !
r =
defs !
r.
Proof.
Lemma def_phi_correct_aux :
forall elems r defs phib (
pc :
node),
(
In (
pc,
phib)
elems) ->
(
NoDup (
map fst elems)) ->
(
exists args,
In (
Iphi args r)
phib) ->
(
forall args phib'
pc',
pc' <>
pc ->
In (
pc',
phib')
elems ->
~
In (
Iphi args r)
phib') ->
(
fold_right
(
fun pcphib a =>
fold_left
(
fun a p =>
match p with
|
Iphi args dst =>
PTree.set dst (
fst pcphib)
a
end)
(
snd pcphib)
a)
defs elems) !
r =
Some pc.
Proof.
Lemma def_phicode_correct :
forall f r defs pc,
wf_cssa_function f ->
assigned_phi_spec (
fn_phicode f)
pc r ->
(
compute_phi_def f defs) !
r =
Some pc.
Proof.
Lemma nodef_phicode_correct :
forall f r defs,
wf_cssa_function f ->
(
forall pc, ~
assigned_phi_spec (
fn_phicode f)
pc r) ->
(
compute_phi_def f defs) !
r =
defs !
r.
Proof.
Lemma compute_def_correct :
forall f r d,
wf_cssa_function f ->
CSSA.def f r d ->
compute_def f (
get_all_def f)
r =
d.
Proof.
Lemma nodef_none :
forall f r,
wf_cssa_function f ->
(
forall pc, ~
assigned_phi_spec (
fn_phicode f)
pc r) ->
(
forall pc, ~
assigned_parcopy_spec (
fn_parcopycode f)
pc r) ->
(
forall pc, ~
assigned_code_spec (
fn_code f)
pc r) ->
(
get_all_def f) !
r =
None.
Proof.
Lemma code_def_not_none :
forall f r pc,
wf_cssa_function f ->
assigned_code_spec (
fn_code f)
pc r ->
(
get_all_def f) !
r <>
None.
Proof.
Lemma phi_def_not_none :
forall f r pc,
wf_cssa_function f ->
assigned_phi_spec (
fn_phicode f)
pc r ->
(
get_all_def f) !
r <>
None.
Proof.
Lemma parc_def_not_none :
forall f r pc,
wf_cssa_function f ->
assigned_parcopy_spec (
fn_parcopycode f)
pc r ->
(
get_all_def f) !
r <>
None.
Proof.
Lemma Infst_rtreenode :
forall (
l :
list (
reg *
positive))
r n,
In (
r,
n)
l ->
In r (
map fst l).
Proof.
induction l; go; intros.
simpl in *. destruct H; go.
Qed.
Lemma Infst_rtreenode_exists :
forall (
l :
list (
reg *
positive))
r,
In r (
map fst l) ->
exists n,
In (
r,
n)
l.
Proof.
induction l; go; intros.
simpl in *. destruct H; go.
destruct a; simpl in *; go.
exploit IHl; eauto; intros.
destruct H0. exists x. auto.
Qed.
Lemma not_none_in :
forall (
rtree :
PTree.t positive)
r,
rtree !
r <>
None ->
In r (
map fst (
PTree.elements rtree)).
Proof.
Lemma none_not_in :
forall (
rtree :
PTree.t positive)
r,
rtree !
r =
None ->
~
In r (
map fst (
PTree.elements rtree)).
Proof.
Lemma compute_def_in_correct :
forall f r d,
wf_cssa_function f ->
CSSA.def f r d ->
In r (
map fst (
PTree.elements (
get_all_def f)))
\/
SSARegSet.In r (
get_ext_params f (
get_all_def f)).
Proof.