Section INIT.
Variable bc: block_classification.
Hypothesis GMATCH: genv_match bc ge.
Definition initial_mem_match (bc: block_classification) (m: mem) (g: genv) :=
forall id b v,
Genv.find_symbol g id = Some b -> Genv.find_var_info g b = Some v ->
v.(gvar_volatile) = false -> v.(gvar_readonly) = true ->
bmatch bc m b (store_init_data_list (ablock_init Pbot) 0 v.(gvar_init)).
Definition romem_consistent (defmap: PTree.t (globdef fundef unit)) (rm: romem) :=
forall id ab,
rm!id = Some ab ->
exists v,
defmap!id = Some (Gvar v)
/\ v.(gvar_readonly) = true
/\ v.(gvar_volatile) = false
/\ definitive_initializer v.(gvar_init) = true
/\ ab = store_init_data_list (ablock_init Pbot) 0 v.(gvar_init).
End INIT.
End INITIAL.
Hint Resolve areg_sound aregs_sound: va.
(** * Interface with other optimizations *)
Ltac InvSoundState :=
match goal with
| H1: sound_state ?prog ?st, H2: linkorder ?cunit ?prog |- _ =>
let S := fresh "S" in generalize (sound_state_inv _ _ _ H1 H2); intros S; inv S
end.
Definition avalue (a: VA.t) (r: reg) : aval :=
match a with
| VA.Bot => Vbot
| VA.State ae am => AE.get r ae
end.
Definition aaddr (a: VA.t) (r: reg) : aptr :=
match a with
| VA.Bot => Pbot
| VA.State ae am => aptr_of_aval (AE.get r ae)
end.
Definition aaddressing (a: VA.t) (addr: addressing) (args: list reg) : aptr :=
match a with
| VA.Bot => Pbot
| VA.State ae am => aptr_of_aval (eval_static_addressing addr (aregs ae args))
end.
(** This is a less precise version of [abuiltin_arg], where memory contents are not taken into account. *)
Definition aaddr_arg (a: VA.t) (ba: builtin_arg reg) : aptr :=
match a with
| VA.Bot => Pbot
| VA.State ae am =>
match ba with
| BA r => aptr_of_aval (AE.get r ae)
| BA_addrstack ofs => Stk ofs
| BA_addrglobal id ofs => Gl id ofs
| _ => Ptop
end
end.

Lemma aaddr_arg_sound_1:
forall bc rs ae m rm am ge sp a b ofs,
ematch bc rs ae ->
romatch bc m rm ->
mmatch bc m am ->
genv_match bc ge ->
bc sp = BCstack ->
eval_builtin_arg ge (fun r : positive => rs # r) (Vptr sp Ptrofs.zero) m a (Vptr b ofs) ->
pmatch bc b ofs (aaddr_arg (VA.State ae am) a).