Lvc.Liveness

Require Import AllInRel List Map Env DecSolve.
Require Import IL Annotation AutoIndTac Bisim Exp MoreExp Filter.

Set Implicit Arguments.

Local Hint Resolve incl_empty minus_incl incl_right incl_left.

Liveness

We have two flavors of liveness: functional and imperative. See comments in inductive definition live_sound.

Inductive overapproximation : Set
  := Functional | Imperative | FunctionalAndImperative.

Definition isFunctional (o:overapproximation) :=
  match o with
    | Functionaltrue
    | FunctionalAndImperativetrue
    | _false
  end.

Definition isImperative (o:overapproximation) :=
  match o with
    | Imperativetrue
    | FunctionalAndImperativetrue
    | _false
  end.

Inductive Definition of Liveness


Inductive live_sound (i:overapproximation) : list (set var×params) → stmtann (set var) → Prop :=
| LOpr x Lv b lv e (al:ann (set var))
  : live_sound i Lv b al
  → live_exp_sound e lv
  → (getAnn al\ singleton x) lv
  → x getAnn al
  → live_sound i Lv (stmtLet x e b) (ann1 lv al)
| LIf Lv e b1 b2 lv al1 al2
  : live_sound i Lv b1 al1
  → live_sound i Lv b2 al2
  → live_exp_sound e lv
  → getAnn al1 lv
  → getAnn al2 lv
  → live_sound i Lv (stmtIf e b1 b2) (ann2 lv al1 al2)
| LGoto l Y Lv lv blv Z
  : get Lv (counted l) (blv,Z)
Imperative Liveness requires the globals of a function to be live at the call site
  → (if isImperative i then ((blv \ of_list Z) lv) else True)
  → length Y = length Z
  → ( n y, get Y n ylive_exp_sound y lv)
  → live_sound i Lv (stmtApp l Y) (ann0 lv)
| LReturn Lv e lv
  : live_exp_sound e lv
  → live_sound i Lv (stmtReturn e) (ann0 lv)
| LExtern x Lv b lv Y al f
  : live_sound i Lv b al
  → ( n y, get Y n ylive_exp_sound y lv)
  → (getAnn al\{{x}}) lv
  → x getAnn al
  → live_sound i Lv (stmtExtern x f Y b) (ann1 lv al)
| LLet Lv s Z b lv als alb
  : live_sound i ((getAnn als,Z)::Lv) s als
  → live_sound i ((getAnn als,Z)::Lv) b alb
  → (of_list Z) getAnn als
Functional Liveness requires the globals of a function to be live at the definition (for building the closure)
  → (if isFunctional i then (getAnn als \ of_list Z lv) else True)
  → getAnn alb lv
  → live_sound i Lv (stmtFun Z s b)(ann2 lv als alb).

Relation between different overapproximations

live_sound ensures that the annotation matches the program

Some monotonicity properties


Definition live_ann_subset (lvZ lvZ´ : set var × list var) :=
  match lvZ, lvZ´ with
    | (lv,Z), (lv´,)lv´ lv Z =
  end.

Instance live_ann_subset_refl : Reflexive live_ann_subset.
Qed.

Lemma live_sound_monotone i LV LV´ s lv
: live_sound i LV s lv
  → PIR2 live_ann_subset LV LV´
  → live_sound i LV´ s lv.

Lemma live_sound_monotone2 i LV s lv a
: live_sound i LV s lv
  → getAnn lv a
  → live_sound i LV s (setTopAnn lv a).

Live variables always contain the free variables

Liveness is stable under renaming

For functional programs, only free variables are significant


Inductive approxF : F.blockF.blockProp :=
 | approxFI E Z s
    : agree_on eq (IL.freeVars s \ of_list Z) E
    → approxF (F.blockI E Z s) (F.blockI Z s).


Inductive freeVarSimF : F.stateF.stateProp :=
  freeVarSimFI (E :onv val) L s
  (LA: PIR2 approxF L )
  (AG:agree_on eq (IL.freeVars s) E )
  : freeVarSimF (L, E, s) (, , s).

Lemma freeVarSimF_sim σ1 σ2
  : freeVarSimF σ1 σ2bisim σ1 σ2.

Since live variables contain free variables, liveness contains all variables significant to an IL/F program


Inductive approxF´ : list (set var × params) → F.blockF.blockProp :=
  approxFI´ DL E Z s lv
  : live_sound Functional ((getAnn lv, Z)::DL) s lv
    → agree_on eq (getAnn lv \ of_list Z) E
    → approxF´ ((getAnn lv,Z)::DL) (F.blockI E Z s) (F.blockI Z s).

Inductive liveSimF : F.stateF.stateProp :=
  liveSimFI (E :onv val) L s Lv lv
            (LS:live_sound Functional Lv s lv)
            (LA:AIR3 approxF´ Lv L )
            (AG:agree_on eq (getAnn lv) E )
  : liveSimF (L, E, s) (, , s).

Lemma liveSim_freeVarSim σ1 σ2
  : liveSimF σ1 σ2freeVarSimF σ1 σ2.

Live variables contain all variables significant to an IL/I program


Inductive approxI
  : list (set var × params) → I.blockI.blockProp :=
  approxII DL Z s lv
  : live_sound Imperative ((getAnn lv, Z)::DL) s lv
    → approxI ((getAnn lv,Z)::DL) (I.blockI Z s) (I.blockI Z s).

Inductive liveSimI : I.stateI.stateProp :=
  liveSimII (E :onv val) L s Lv lv
  (LS:live_sound Imperative Lv s lv)
  (LA:AIR3 approxI Lv L L)
  (AG:agree_on eq (getAnn lv) E )
  : liveSimI (L, E, s) (L, , s).

Lemma liveSimI_sim σ1 σ2
  : liveSimI σ1 σ2bisim σ1 σ2.