(* *********************************************************************)
(*                                                                     *)
(*              The Compcert verified compiler                         *)
(*                                                                     *)
(*          Xavier Leroy, INRIA Paris-Rocquencourt                     *)
(*                                                                     *)
(*  Copyright Institut National de Recherche en Informatique et en     *)
(*  Automatique.  All rights reserved.  This file is distributed       *)
(*  under the terms of the INRIA Non-Commercial License Agreement.     *)
(*                                                                     *)
(* *********************************************************************)
(** Correctness proof for RTL generation. *)
(** * Correspondence between Cminor environments and RTL register sets *)
(** A compilation environment (mapping) is well-formed if the following properties hold: - Two distinct Cminor local variables are mapped to distinct pseudo-registers. - A Cminor local variable and a let-bound variable are mapped to distinct pseudo-registers. *)
Record map_wf (m: mapping) : Prop :=
mk_map_wf {
map_wf_inj:
(forall id1 id2 r,
m.(map_vars)!id1 = Some r -> m.(map_vars)!id2 = Some r -> id1 = id2);
map_wf_disj:
(forall id r,
m.(map_vars)!id = Some r -> In r m.(map_letvars) -> False)
}.
(** An RTL register environment matches a CminorSel local environment and let-environment if the value of every local or let-bound variable in the CminorSel environments is identical to the value of the corresponding pseudo-register in the RTL register environment. *)
Record match_env
(map: mapping) (e: env) (le: letenv) (rs: regset) : Prop :=
mk_match_env {
me_vars:
(forall id v,
e!id = Some v -> exists r, map.(map_vars)!id = Some r /\ Val.lessdef v rs#r);
me_letvars:
Val.lessdef_list le rs##(map.(map_letvars))
}.

Lemma match_env_find_letvar:
forall map e le rs idx v r,
match_env map e le rs ->
List.nth_error le idx = Some v ->
List.nth_error map.(map_letvars) idx = Some r ->
Val.lessdef v rs#r.