aboutsummaryrefslogtreecommitdiffstats
path: root/arm/Conventions1.v
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2016-04-27 16:43:20 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2016-04-27 16:43:20 +0200
commit5978342d71db7d1bca162962c70e6fcdd5c1e96c (patch)
tree3b13b56d9067558ab706c4e95cea1d036f2ceeef /arm/Conventions1.v
parentcf3f9615d79e0cbe4eb146c08e2c0802e1e3f033 (diff)
downloadcompcert-kvx-5978342d71db7d1bca162962c70e6fcdd5c1e96c.tar.gz
compcert-kvx-5978342d71db7d1bca162962c70e6fcdd5c1e96c.zip
Revise the Stacking pass and its proof to make it easier to adapt to 64-bit architectures
The original Stacking pass and its proof hard-wire assumptions about the processor and the register allocation, namely that integer registers are 32 bit wide and that all stack slots have natural alignment 4, which precludes having stack slots of type Tlong. Those assumptions become false if the target processor has 64-bit integer registers. This commit makes minimal adjustments to the Stacking pass so as to lift these assumptions: - Stack slots of type Tlong (or more generally of natural alignment 8) are supported. For slots produced by register allocation, the alignment is validated a posteriori in Lineartyping. For slots produced by the calling conventions, alignment is proved as part of the "loc_argument_acceptable" property in Conventions1. - The code generated by Stacking to save and restore used callee-save registers no longer assumes 32-bit integer registers. Actually, it supports any combination of sizes for registers. - To support the new save/restore code, Bounds was changed to record the set of all callee-save registers used, rather than just the max index of callee-save registers used. On CompCert's current 32-bit target architectures, the new Stacking pass should generate pretty much the same code as the old one, modulo minor differences in the layout of the stack frame. (E.g. padding could be introduced at different places.) The bulk of this big commit is related to the proof of the Stacking phase. The old proof strategy was painful and not obviously adaptable to the new Stacking phase, so I rewrote Stackingproof entirely, using an approach inspired by separation logic. The new library common/Separation.v defines assertions about memory states that can be composed using a separating conjunction, just like pre- and post-conditions in separation logic. Those assertions are used in Stackingproof to describe the contents of the stack frames during the execution of the generated Mach code, and relate them with the Linear location maps. As a further simplification, the callee-save/caller-save distinction is now defined in Conventions1 by a function is_callee_save: mreg -> bool, instead of lists of registers of either kind as before. This eliminates many boring classification lemmas from Conventions1. LTL and Lineartyping were adapted accordingly. Finally, this commit introduces a new library called Decidableplus to prove some propositions by reflection as Boolean computations. It is used to further simplify the proofs in Conventions1.
Diffstat (limited to 'arm/Conventions1.v')
-rw-r--r--arm/Conventions1.v235
1 files changed, 44 insertions, 191 deletions
diff --git a/arm/Conventions1.v b/arm/Conventions1.v
index e27a9293..abd28b18 100644
--- a/arm/Conventions1.v
+++ b/arm/Conventions1.v
@@ -14,6 +14,7 @@
machine registers and stack slots. *)
Require Import Coqlib.
+Require Import Decidableplus.
Require Import AST.
Require Import Events.
Require Import Locations.
@@ -33,6 +34,14 @@ Require Archi.
of callee- and caller-save registers.
*)
+Definition is_callee_save (r: mreg): bool :=
+ match r with
+ | R0 | R1 | R2 | R3 | R12 => false
+ | R4 | R5 | R6 | R7 | R8 | R9 | R10 | R11 => true
+ | F0 | F1 | F2 | F3 | F4 | F5 | F6 | F7 => false
+ | F8 | F9 | F10 | F11 | F12 | F13 | F14 | F15 => true
+ end.
+
Definition int_caller_save_regs :=
R0 :: R1 :: R2 :: R3 :: R12 :: nil.
@@ -46,171 +55,11 @@ Definition float_callee_save_regs :=
F8 :: F9 :: F10 :: F11 :: F12 :: F13 :: F14 :: F15 :: nil.
Definition destroyed_at_call :=
- int_caller_save_regs ++ float_caller_save_regs.
+ List.filter (fun r => negb (is_callee_save r)) all_mregs.
Definition dummy_int_reg := R0. (**r Used in [Coloring]. *)
Definition dummy_float_reg := F0. (**r Used in [Coloring]. *)
-(** The [index_int_callee_save] and [index_float_callee_save] associate
- a unique positive integer to callee-save registers. This integer is
- used in [Stacking] to determine where to save these registers in
- the activation record if they are used by the current function. *)
-
-Definition index_int_callee_save (r: mreg) :=
- match r with
- | R4 => 0 | R5 => 1 | R6 => 2 | R7 => 3
- | R8 => 4 | R9 => 5 | R10 => 6 | R11 => 7
- | _ => -1
- end.
-
-Definition index_float_callee_save (r: mreg) :=
- match r with
- | F8 => 0 | F9 => 1 | F10 => 2 | F11 => 3
- | F12 => 4 | F13 => 5 | F14 => 6 | F15 => 7
- | _ => -1
- end.
-
-Ltac ElimOrEq :=
- match goal with
- | |- (?x = ?y) \/ _ -> _ =>
- let H := fresh in
- (intro H; elim H; clear H;
- [intro H; rewrite <- H; clear H | ElimOrEq])
- | |- False -> _ =>
- let H := fresh in (intro H; contradiction)
- end.
-
-Ltac OrEq :=
- match goal with
- | |- (?x = ?x) \/ _ => left; reflexivity
- | |- (?x = ?y) \/ _ => right; OrEq
- | |- False => fail
- end.
-
-Ltac NotOrEq :=
- match goal with
- | |- (?x = ?y) \/ _ -> False =>
- let H := fresh in (
- intro H; elim H; clear H; [intro; discriminate | NotOrEq])
- | |- False -> False =>
- contradiction
- end.
-
-Lemma index_int_callee_save_pos:
- forall r, In r int_callee_save_regs -> index_int_callee_save r >= 0.
-Proof.
- intro r. simpl; ElimOrEq; unfold index_int_callee_save; omega.
-Qed.
-
-Lemma index_float_callee_save_pos:
- forall r, In r float_callee_save_regs -> index_float_callee_save r >= 0.
-Proof.
- intro r. simpl; ElimOrEq; unfold index_float_callee_save; omega.
-Qed.
-
-Lemma index_int_callee_save_pos2:
- forall r, index_int_callee_save r >= 0 -> In r int_callee_save_regs.
-Proof.
- destruct r; simpl; intro; omegaContradiction || OrEq.
-Qed.
-
-Lemma index_float_callee_save_pos2:
- forall r, index_float_callee_save r >= 0 -> In r float_callee_save_regs.
-Proof.
- destruct r; simpl; intro; omegaContradiction || OrEq.
-Qed.
-
-Lemma index_int_callee_save_inj:
- forall r1 r2,
- In r1 int_callee_save_regs ->
- In r2 int_callee_save_regs ->
- r1 <> r2 ->
- index_int_callee_save r1 <> index_int_callee_save r2.
-Proof.
- intros r1 r2.
- simpl; ElimOrEq; ElimOrEq; unfold index_int_callee_save;
- intros; congruence.
-Qed.
-
-Lemma index_float_callee_save_inj:
- forall r1 r2,
- In r1 float_callee_save_regs ->
- In r2 float_callee_save_regs ->
- r1 <> r2 ->
- index_float_callee_save r1 <> index_float_callee_save r2.
-Proof.
- intros r1 r2.
- simpl; ElimOrEq; ElimOrEq; unfold index_float_callee_save;
- intros; congruence.
-Qed.
-
-(** The following lemmas show that
- (temporaries, destroyed at call, integer callee-save, float callee-save)
- is a partition of the set of machine registers. *)
-
-Lemma int_float_callee_save_disjoint:
- list_disjoint int_callee_save_regs float_callee_save_regs.
-Proof.
- red; intros r1 r2. simpl; ElimOrEq; ElimOrEq; discriminate.
-Qed.
-
-Lemma register_classification:
- forall r,
- In r destroyed_at_call \/ In r int_callee_save_regs \/ In r float_callee_save_regs.
-Proof.
- destruct r;
- try (left; simpl; OrEq);
- try (right; left; simpl; OrEq);
- try (right; right; simpl; OrEq).
-Qed.
-
-
-Lemma int_callee_save_not_destroyed:
- forall r,
- In r destroyed_at_call -> In r int_callee_save_regs -> False.
-Proof.
- intros. revert H0 H. simpl. ElimOrEq; NotOrEq.
-Qed.
-
-Lemma float_callee_save_not_destroyed:
- forall r,
- In r destroyed_at_call -> In r float_callee_save_regs -> False.
-Proof.
- intros. revert H0 H. simpl. ElimOrEq; NotOrEq.
-Qed.
-
-Lemma int_callee_save_type:
- forall r, In r int_callee_save_regs -> mreg_type r = Tany32.
-Proof.
- intro. simpl; ElimOrEq; reflexivity.
-Qed.
-
-Lemma float_callee_save_type:
- forall r, In r float_callee_save_regs -> mreg_type r = Tany64.
-Proof.
- intro. simpl; ElimOrEq; reflexivity.
-Qed.
-
-Ltac NoRepet :=
- match goal with
- | |- list_norepet nil =>
- apply list_norepet_nil
- | |- list_norepet (?a :: ?b) =>
- apply list_norepet_cons; [simpl; intuition discriminate | NoRepet]
- end.
-
-Lemma int_callee_save_norepet:
- list_norepet int_callee_save_regs.
-Proof.
- unfold int_callee_save_regs; NoRepet.
-Qed.
-
-Lemma float_callee_save_norepet:
- list_norepet float_callee_save_regs.
-Proof.
- unfold float_callee_save_regs; NoRepet.
-Qed.
-
(** * Function calling conventions *)
(** The functions in this section determine the locations (machine registers
@@ -260,12 +109,12 @@ Qed.
Lemma loc_result_caller_save:
forall (s: signature) (r: mreg),
- In r (loc_result s) -> In r destroyed_at_call.
+ In r (loc_result s) -> is_callee_save r = false.
Proof.
intros.
assert (r = R0 \/ r = R1 \/ r = F0).
unfold loc_result in H. destruct (sig_res s); [destruct t|idtac]; simpl in H; intuition.
- destruct H0 as [A | [A | A]]; subst r; simpl; OrEq.
+ destruct H0 as [A | [A | A]]; subst r; auto.
Qed.
(** ** Location of function arguments *)
@@ -425,8 +274,8 @@ Definition size_arguments (s: signature) : Z :=
Definition loc_argument_acceptable (l: loc) : Prop :=
match l with
- | R r => In r destroyed_at_call
- | S Outgoing ofs ty => ofs >= 0 /\ ty <> Tlong
+ | R r => is_callee_save r = false
+ | S Outgoing ofs ty => ofs >= 0 /\ (typealign ty | ofs)
| _ => False
end.
@@ -451,20 +300,20 @@ Remark loc_arguments_hf_charact:
In l (loc_arguments_hf tyl ir fr ofs) ->
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= ofs /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= ofs /\ typealign ty = 1
| S _ _ _ => False
end.
Proof.
assert (INCR: forall l ofs1 ofs2,
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= ofs2 /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= ofs2 /\ typealign ty = 1
| S _ _ _ => False
end ->
ofs1 <= ofs2 ->
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= ofs1 /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= ofs1 /\ typealign ty = 1
| S _ _ _ => False
end).
{
@@ -477,13 +326,13 @@ Proof.
destruct (zlt ir 4); destruct H.
subst. left; apply ireg_param_in_params.
eapply IHtyl; eauto.
- subst. split; [omega | congruence].
+ subst. split; [omega | auto].
eapply INCR. eapply IHtyl; eauto. omega.
- (* float *)
destruct (zlt fr 8); destruct H.
subst. right; apply freg_param_in_params.
eapply IHtyl; eauto.
- subst. split. apply Zle_ge. apply align_le. omega. congruence.
+ subst. split. apply Zle_ge. apply align_le. omega. auto.
eapply INCR. eapply IHtyl; eauto.
apply Zle_trans with (align ofs 2). apply align_le; omega. omega.
- (* long *)
@@ -493,26 +342,26 @@ Proof.
destruct H. subst l; left; apply ireg_param_in_params.
destruct H. subst l; left; apply ireg_param_in_params.
eapply IHtyl; eauto.
- destruct H. subst l; split; [ omega | congruence ].
- destruct H. subst l; split; [ omega | congruence ].
+ destruct H. subst l; split; [ omega | auto ].
+ destruct H. subst l; split; [ omega | auto ].
eapply INCR. eapply IHtyl; eauto. omega.
- (* single *)
destruct (zlt fr 8); destruct H.
subst. right; apply freg_param_in_params.
eapply IHtyl; eauto.
- subst. split; [omega | congruence].
+ subst. split; [omega | auto].
eapply INCR. eapply IHtyl; eauto. omega.
- (* any32 *)
destruct (zlt ir 4); destruct H.
subst. left; apply ireg_param_in_params.
eapply IHtyl; eauto.
- subst. split; [omega | congruence].
+ subst. split; [omega | auto].
eapply INCR. eapply IHtyl; eauto. omega.
- (* any64 *)
destruct (zlt fr 8); destruct H.
subst. right; apply freg_param_in_params.
eapply IHtyl; eauto.
- subst. split. apply Zle_ge. apply align_le. omega. congruence.
+ subst. split. apply Zle_ge. apply align_le. omega. auto.
eapply INCR. eapply IHtyl; eauto.
apply Zle_trans with (align ofs 2). apply align_le; omega. omega.
Qed.
@@ -522,20 +371,20 @@ Remark loc_arguments_sf_charact:
In l (loc_arguments_sf tyl ofs) ->
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs /\ typealign ty = 1
| S _ _ _ => False
end.
Proof.
assert (INCR: forall l ofs1 ofs2,
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs2 /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs2 /\ typealign ty = 1
| S _ _ _ => False
end ->
ofs1 <= ofs2 ->
match l with
| R r => In r int_param_regs \/ In r float_param_regs
- | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs1 /\ ty <> Tlong
+ | S Outgoing ofs' ty => ofs' >= Zmax 0 ofs1 /\ typealign ty = 1
| S _ _ _ => False
end).
{
@@ -548,7 +397,7 @@ Proof.
destruct H.
destruct (zlt ofs 0); subst l.
left; apply ireg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
- (* float *)
set (ofs' := align ofs 2) in *.
@@ -556,7 +405,7 @@ Proof.
destruct H.
destruct (zlt ofs' 0); subst l.
right; apply freg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
- (* long *)
set (ofs' := align ofs 2) in *.
@@ -564,23 +413,23 @@ Proof.
destruct H.
destruct (zlt ofs' 0); subst l.
left; apply ireg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
destruct H.
destruct (zlt ofs' 0); subst l.
left; apply ireg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
- (* single *)
destruct H.
destruct (zlt ofs 0); subst l.
right; apply freg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
- (* any32 *)
destruct H.
destruct (zlt ofs 0); subst l.
left; apply ireg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
- (* any64 *)
set (ofs' := align ofs 2) in *.
@@ -588,7 +437,7 @@ Proof.
destruct H.
destruct (zlt ofs' 0); subst l.
right; apply freg_param_in_params.
- split. xomega. congruence.
+ split. xomega. auto.
eapply INCR. eapply IHtyl; eauto. omega.
Qed.
@@ -597,14 +446,18 @@ Lemma loc_arguments_acceptable:
In l (loc_arguments s) -> loc_argument_acceptable l.
Proof.
unfold loc_arguments; intros.
- assert (forall r, In r int_param_regs \/ In r float_param_regs -> In r destroyed_at_call).
- {
- intros. elim H0; simpl; ElimOrEq; OrEq.
- }
+ assert (A: forall r, In r int_param_regs -> is_callee_save r = false) by decide_goal.
+ assert (B: forall r, In r float_param_regs -> is_callee_save r = false) by decide_goal.
+ assert (C: forall r, In r int_param_regs \/ In r float_param_regs -> is_callee_save r = false).
+ { intros. destruct H0; auto. }
assert (In l (loc_arguments_sf (sig_args s) (-4)) -> loc_argument_acceptable l).
- { intros. red. exploit loc_arguments_sf_charact; eauto. destruct l; auto. }
+ { intros. red. exploit loc_arguments_sf_charact; eauto.
+ destruct l as [r | [] ofs ty]; auto.
+ intros [P Q]. rewrite Q; split. auto. apply Z.divide_1_l. }
assert (In l (loc_arguments_hf (sig_args s) 0 0 0) -> loc_argument_acceptable l).
- { intros. red. exploit loc_arguments_hf_charact; eauto. destruct l; auto. }
+ { intros. red. exploit loc_arguments_hf_charact; eauto.
+ destruct l as [r | [] ofs ty]; auto.
+ intros [P Q]. rewrite Q; split. auto. apply Z.divide_1_l. }
destruct Archi.abi; [ | destruct (cc_vararg (sig_cc s)) ]; auto.
Qed.