(** * Properties of equations *)
Module ESF := FSetFacts.Facts(EqSet).
Module ESP := FSetProperties.Properties(EqSet).
Module ESD := FSetDecide.Decide(EqSet).
Definition sel_val (k: equation_kind) (v: val) : val :=
match k with
| Full => v
| Low => Val.loword v
| High => Val.hiword v
end.
(** A set of equations [e] is satisfied in a RTL pseudoreg state [rs] and an LTL location state [ls] if, for every equation [r = l [k]] in [e], [sel_val k (rs#r)] (the [k] fragment of [r]'s value in the RTL code) is less defined than [ls l] (the value of [l] in the LTL code). *)
Definition satisf (rs: regset) (ls: locset) (e: eqs) : Prop :=
forall q, EqSet.In q e -> Val.lessdef (sel_val (ekind q) rs#(ereg q)) (ls (eloc q)).

(* Specifications: *)
Lemma empty_eqs_satisf:
forall rs ls, satisf rs ls empty_eqs.
Lemma satisf_incr:
forall rs ls (e1 e2: eqs),
satisf rs ls e2 -> EqSet.Subset e1 e2 -> satisf rs ls e1.
Lemma satisf_undef_reg:
forall rs ls e r,
satisf rs ls e ->
satisf (rs#r <- Vundef) ls e.
Lemma add_equation_lessdef:
forall rs ls q e,
satisf rs ls (add_equation q e) -> Val.lessdef (sel_val (ekind q) rs#(ereg q)) (ls (eloc q)).
Lemma add_equation_satisf:
forall rs ls q e,
satisf rs ls (add_equation q e) -> satisf rs ls e.
Lemma add_equations_satisf:
forall rs ls rl ml e e',
add_equations rl ml e = Some e' ->
satisf rs ls e' -> satisf rs ls e.
Lemma add_equations_lessdef:
forall rs ls rl ml e e',
add_equations rl ml e = Some e' ->
satisf rs ls e' ->
Val.lessdef_list (rs##rl) (reglist ls ml).
Lemma add_equations_args_satisf:
forall rs ls rl tyl ll e e',
add_equations_args rl tyl ll e = Some e' ->
satisf rs ls e' -> satisf rs ls e.
Lemma val_longofwords_eq_1:
forall v,
Val.has_type v Tlong -> Archi.ptr64 = false ->
Val.longofwords (Val.hiword v) (Val.loword v) = v.
Lemma val_longofwords_eq_2:
forall v,
Val.has_type v Tlong -> Archi.splitlong = true ->
Val.longofwords (Val.hiword v) (Val.loword v) = v.
Lemma add_equations_args_lessdef:
forall rs ls rl tyl ll e e',
add_equations_args rl tyl ll e = Some e' ->
satisf rs ls e' ->
Val.has_type_list (rs##rl) tyl ->
Val.lessdef_list (rs##rl) (map (fun p => Locmap.getpair p ls) ll).
Lemma add_equation_ros_satisf:
forall rs ls ros mos e e',
add_equation_ros ros mos e = Some e' ->
satisf rs ls e' -> satisf rs ls e.
Lemma remove_equation_satisf:
forall rs ls q e,
satisf rs ls e -> satisf rs ls (remove_equation q e).
Lemma remove_equation_res_satisf:
forall rs ls r l e e',
remove_equations_res r l e = Some e' ->
satisf rs ls e -> satisf rs ls e'.