From 7b34d3c03fea76b85ec72d5ee82c53353960e2b2 Mon Sep 17 00:00:00 2001 From: David Monniaux Date: Fri, 16 Jul 2021 21:11:34 +0200 Subject: make CSE3 condition parametric --- backend/CSE3.v | 12 ++++++++++- backend/CSE3proof.v | 59 ++++++++++++++++++++++++++++------------------------- 2 files changed, 42 insertions(+), 29 deletions(-) (limited to 'backend') diff --git a/backend/CSE3.v b/backend/CSE3.v index 746ba399..5d05821a 100644 --- a/backend/CSE3.v +++ b/backend/CSE3.v @@ -20,6 +20,14 @@ Local Open Scope error_monad_scope. Axiom preanalysis : typing_env -> RTL.function -> invariants * analysis_hints. +Record cse3params : Type := + mkcse3params + { cse3_conditions : bool; + }. + +Section PARAMS. + Variable params : cse3params. + Section REWRITE. Context {ctx : eq_context}. @@ -54,7 +62,7 @@ Definition subst_args fmap pc xl := forward_move_l_b (PMap.get pc fmap) xl. Definition find_cond_in_fmap fmap pc cond args := - if Compopts.optim_CSE3_conditions tt + if cse3_conditions params then match PMap.get pc fmap with | Some rel => @@ -129,3 +137,5 @@ Definition transf_fundef (fd: fundef) : res fundef := Definition transf_program (p: program) : res program := transform_partial_program transf_fundef p. + +End PARAMS. diff --git a/backend/CSE3proof.v b/backend/CSE3proof.v index 0722f904..2d9992c6 100644 --- a/backend/CSE3proof.v +++ b/backend/CSE3proof.v @@ -28,12 +28,14 @@ Require Import Registers Op RTL. Require Import CSE3 CSE3analysis CSE3analysisproof. Require Import RTLtyping. - +Section PARAMS. + Variable params : cse3params. + Definition match_prog (p tp: RTL.program) := - match_program (fun ctx f tf => transf_fundef f = OK tf) eq p tp. + match_program (fun ctx f tf => transf_fundef params f = OK tf) eq p tp. Lemma transf_program_match: - forall p tp, transf_program p = OK tp -> match_prog p tp. + forall p tp, transf_program params p = OK tp -> match_prog p tp. Proof. intros. eapply match_transform_partial_program; eauto. Qed. @@ -111,7 +113,7 @@ Lemma functions_translated: forall (v: val) (f: RTL.fundef), Genv.find_funct ge v = Some f -> exists tf, - Genv.find_funct tge v = Some tf /\ transf_fundef f = OK tf. + Genv.find_funct tge v = Some tf /\ transf_fundef params f = OK tf. Proof. apply (Genv.find_funct_transf_partial TRANSF). Qed. @@ -120,7 +122,7 @@ Lemma function_ptr_translated: forall (b: block) (f: RTL.fundef), Genv.find_funct_ptr ge b = Some f -> exists tf, - Genv.find_funct_ptr tge b = Some tf /\ transf_fundef f = OK tf. + Genv.find_funct_ptr tge b = Some tf /\ transf_fundef params f = OK tf. Proof. apply (Genv.find_funct_ptr_transf_partial TRANSF). Qed. @@ -139,7 +141,7 @@ Proof. Qed. Lemma sig_preserved: - forall f tf, transf_fundef f = OK tf -> funsig tf = funsig f. + forall f tf, transf_fundef params f = OK tf -> funsig tf = funsig f. Proof. destruct f; simpl; intros. - monadInv H. @@ -154,7 +156,7 @@ Proof. Qed. Lemma stacksize_preserved: - forall f tf, transf_function f = OK tf -> fn_stacksize tf = fn_stacksize f. + forall f tf, transf_function params f = OK tf -> fn_stacksize tf = fn_stacksize f. Proof. unfold transf_function; destruct f; simpl; intros. monadInv H. @@ -166,7 +168,7 @@ Proof. Qed. Lemma params_preserved: - forall f tf, transf_function f = OK tf -> fn_params tf = fn_params f. + forall f tf, transf_function params f = OK tf -> fn_params tf = fn_params f. Proof. unfold transf_function; destruct f; simpl; intros. monadInv H. @@ -178,7 +180,7 @@ Proof. Qed. Lemma entrypoint_preserved: - forall f tf, transf_function f = OK tf -> fn_entrypoint tf = fn_entrypoint f. + forall f tf, transf_function params f = OK tf -> fn_entrypoint tf = fn_entrypoint f. Proof. unfold transf_function; destruct f; simpl; intros. monadInv H. @@ -190,7 +192,7 @@ Proof. Qed. Lemma sig_preserved2: - forall f tf, transf_function f = OK tf -> fn_sig tf = fn_sig f. + forall f tf, transf_function params f = OK tf -> fn_sig tf = fn_sig f. Proof. unfold transf_function; destruct f; simpl; intros. monadInv H. @@ -202,7 +204,7 @@ Proof. Qed. Lemma transf_function_is_typable: - forall f tf, transf_function f = OK tf -> + forall f tf, transf_function params f = OK tf -> exists tenv, type_function f = OK tenv. Proof. unfold transf_function; destruct f; simpl; intros. @@ -211,7 +213,7 @@ Proof. assumption. Qed. Lemma transf_function_invariants_inductive: - forall f tf tenv, transf_function f = OK tf -> + forall f tf tenv, transf_function params f = OK tf -> type_function f = OK tenv -> check_inductiveness (ctx:=(context_from_hints (snd (preanalysis tenv f)))) f tenv (fst (preanalysis tenv f)) = true. @@ -228,7 +230,7 @@ Lemma find_function_translated: forall ros rs fd, find_function ge ros rs = Some fd -> exists tfd, - find_function tge ros rs = Some tfd /\ transf_fundef fd = OK tfd. + find_function tge ros rs = Some tfd /\ transf_fundef params fd = OK tfd. Proof. unfold find_function; intros. destruct ros as [r|id]. eapply functions_translated; eauto. @@ -243,7 +245,7 @@ Inductive match_stackframes: list stackframe -> list stackframe -> signature -> | match_stackframes_cons: forall res f sp pc rs s tf ts sg tenv (STACKS: match_stackframes s ts (fn_sig tf)) - (FUN: transf_function f = OK tf) + (FUN: transf_function params f = OK tf) (WTF: type_function f = OK tenv) (WTRS: wt_regset tenv rs) (WTRES: tenv res = proj_sig_res sg) @@ -260,7 +262,7 @@ Inductive match_states: state -> state -> Prop := | match_states_intro: forall s f sp pc rs m ts tf tenv (STACKS: match_stackframes s ts (fn_sig tf)) - (FUN: transf_function f = OK tf) + (FUN: transf_function params f = OK tf) (WTF: type_function f = OK tenv) (WTRS: wt_regset tenv rs) (REL: sem_rel_b sp (context_from_hints (snd (preanalysis tenv f))) ((fst (preanalysis tenv f))#pc) rs m), @@ -269,7 +271,7 @@ Inductive match_states: state -> state -> Prop := | match_states_call: forall s f args m ts tf (STACKS: match_stackframes s ts (funsig tf)) - (FUN: transf_fundef f = OK tf) + (FUN: transf_fundef params f = OK tf) (WTARGS: Val.has_type_list args (sig_args (funsig tf))), match_states (Callstate s f args m) (Callstate ts tf args m) @@ -294,12 +296,12 @@ Qed. Lemma transf_function_at: forall f tf pc tenv instr - (TF : transf_function f = OK tf) + (TF : transf_function params f = OK tf) (TYPE : type_function f = OK tenv) (PC : (fn_code f) ! pc = Some instr), (fn_code tf) ! pc = Some (transf_instr (ctx := (context_from_hints (snd (preanalysis tenv f)))) - (fst (preanalysis tenv f)) + params (fst (preanalysis tenv f)) pc instr). Proof. intros. @@ -498,8 +500,8 @@ Proof. - (* Iop *) exists (State ts tf sp pc' (rs # res <- v) m). split. - + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iop op args res pc')) as instr'. - assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iop op args res pc'))) by reflexivity. + + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iop op args res pc')) as instr'. + assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iop op args res pc'))) by reflexivity. unfold transf_instr, find_op_in_fmap in instr'. destruct (@PMap.get (option RELATION.t) pc) eqn:INV_PC. pose proof (rhs_find_sound (sp:=sp) (genv:=ge) (ctx:=(context_from_hints (snd (preanalysis tenv f)))) pc (SOp op) @@ -581,8 +583,8 @@ Proof. (* END INVARIANT *) - (* Iload *) exists (State ts tf sp pc' (rs # dst <- v) m). split. - + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload trap chunk addr args dst pc')) as instr'. - assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload trap chunk addr args dst pc'))) by reflexivity. + + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload trap chunk addr args dst pc')) as instr'. + assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload trap chunk addr args dst pc'))) by reflexivity. unfold transf_instr, find_load_in_fmap in instr'. destruct (@PMap.get (option RELATION.t) pc) eqn:INV_PC. pose proof (rhs_find_sound (sp:=sp) (genv:=ge) (ctx:=(context_from_hints (snd (preanalysis tenv f)))) pc (SLoad chunk addr) @@ -659,8 +661,8 @@ Proof. - (* Iload notrap1 *) exists (State ts tf sp pc' (rs # dst <- Vundef) m). split. - + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc')) as instr'. - assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc'))) by reflexivity. + + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc')) as instr'. + assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc'))) by reflexivity. unfold transf_instr, find_load_in_fmap in instr'. destruct (@PMap.get (option RELATION.t) pc) eqn:INV_PC. pose proof (rhs_find_sound (sp:=sp) (genv:=ge) (ctx:=(context_from_hints (snd (preanalysis tenv f)))) pc (SLoad chunk addr) @@ -735,8 +737,8 @@ Proof. - (* Iload notrap2 *) exists (State ts tf sp pc' (rs # dst <- Vundef) m). split. - + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc')) as instr'. - assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc'))) by reflexivity. + + pose (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc')) as instr'. + assert (instr' = (transf_instr (ctx:=(context_from_hints (snd (preanalysis tenv f)))) params (fst (preanalysis tenv f)) pc (Iload NOTRAP chunk addr args dst pc'))) by reflexivity. unfold transf_instr, find_load_in_fmap in instr'. destruct (@PMap.get (option RELATION.t) pc) eqn:INV_PC. pose proof (rhs_find_sound (sp:=sp) (genv:=ge) (ctx:=(context_from_hints (snd (preanalysis tenv f)))) pc (SLoad chunk addr) @@ -941,7 +943,7 @@ Proof. eapply external_call_sound; unfold ctx; eauto with cse3. - (* Icond *) - destruct (find_cond_in_fmap (ctx := ctx) invs pc cond args) as [bfound | ] eqn:FIND_COND. + destruct (find_cond_in_fmap (ctx := ctx) params invs pc cond args) as [bfound | ] eqn:FIND_COND. + econstructor; split. * eapply exec_Inop; try eassumption. TR_AT. unfold transf_instr. fold invs. fold ctx. rewrite FIND_COND. reflexivity. @@ -983,7 +985,7 @@ Proof. unfold find_cond_in_fmap in FIND_COND. change (@PMap.get (option RELATION.t)) with (@Regmap.get RB.t) in FIND_COND. rewrite FIND_REL in FIND_COND. - destruct (Compopts.optim_CSE3_conditions tt). + destruct (cse3_conditions params). 2: discriminate. destruct (is_condition_present pc rel cond args). { rewrite COND_PRESENT_TRUE in H0 by trivial. @@ -1214,3 +1216,4 @@ Proof. Qed. End PRESERVATION. +End PARAMS. -- cgit