summaryrefslogtreecommitdiff
path: root/powerpc
diff options
context:
space:
mode:
authorGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-03-16 16:51:42 +0000
committerGravatar xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e>2013-03-16 16:51:42 +0000
commit707b6a1ae9660b13cf6f68c7c0ce74017f5981c5 (patch)
tree166a21d507612d60db40737333ddec5003fc81aa /powerpc
parente44df4563f1cb893ab25b2a8b25d5b83095205be (diff)
Assorted changes to reduce stack and heap requirements when compiling very big functions.
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@2151 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'powerpc')
-rw-r--r--powerpc/Asmgen.v28
-rw-r--r--powerpc/Asmgenproof.v10
2 files changed, 29 insertions, 9 deletions
diff --git a/powerpc/Asmgen.v b/powerpc/Asmgen.v
index 0035dff..39b84e0 100644
--- a/powerpc/Asmgen.v
+++ b/powerpc/Asmgen.v
@@ -621,7 +621,7 @@ Definition transl_instr (f: Mach.function) (i: Mach.instruction)
(** Translation of a code sequence *)
-Definition r11_is_parent (before: bool) (i: Mach.instruction) : bool :=
+Definition it1_is_parent (before: bool) (i: Mach.instruction) : bool :=
match i with
| Msetstack src ofs ty => before
| Mgetparam ofs ty dst => negb (mreg_eq dst IT1)
@@ -629,21 +629,39 @@ Definition r11_is_parent (before: bool) (i: Mach.instruction) : bool :=
| _ => false
end.
-Fixpoint transl_code (f: Mach.function) (il: list Mach.instruction) (r11p: bool) :=
+(** This is the naive definition that we no longer use because it
+ is not tail-recursive. It is kept as specification. *)
+
+Fixpoint transl_code (f: Mach.function) (il: list Mach.instruction) (it1p: bool) :=
match il with
| nil => OK nil
| i1 :: il' =>
- do k <- transl_code f il' (r11_is_parent r11p i1);
- transl_instr f i1 r11p k
+ do k <- transl_code f il' (it1_is_parent it1p i1);
+ transl_instr f i1 it1p k
end.
+(** This is an equivalent definition in continuation-passing style
+ that runs in constant stack space. *)
+
+Fixpoint transl_code_rec (f: Mach.function) (il: list Mach.instruction)
+ (it1p: bool) (k: code -> res code) :=
+ match il with
+ | nil => k nil
+ | i1 :: il' =>
+ transl_code_rec f il' (it1_is_parent it1p i1)
+ (fun c1 => do c2 <- transl_instr f i1 it1p c1; k c2)
+ end.
+
+Definition transl_code' (f: Mach.function) (il: list Mach.instruction) (it1p: bool) :=
+ transl_code_rec f il it1p (fun c => OK c).
+
(** Translation of a whole function. Note that we must check
that the generated code contains less than [2^32] instructions,
otherwise the offset part of the [PC] code pointer could wrap
around, leading to incorrect executions. *)
Definition transl_function (f: Mach.function) :=
- do c <- transl_code f f.(Mach.fn_code) false;
+ do c <- transl_code' f f.(Mach.fn_code) false;
OK (Pallocframe f.(fn_stacksize) f.(fn_link_ofs) ::
Pmflr GPR0 ::
Pstw GPR0 (Cint f.(fn_retaddr_ofs)) GPR1 :: c).
diff --git a/powerpc/Asmgenproof.v b/powerpc/Asmgenproof.v
index 658653f..07e66cf 100644
--- a/powerpc/Asmgenproof.v
+++ b/powerpc/Asmgenproof.v
@@ -317,7 +317,8 @@ Lemma transl_find_label:
end.
Proof.
intros. monadInv H. destruct (zlt Int.max_unsigned (list_length_z x)); inv EQ0.
- monadInv EQ. simpl. eapply transl_code_label; eauto.
+ monadInv EQ. rewrite transl_code'_transl_code in EQ0.
+ simpl. eapply transl_code_label; eauto.
Qed.
End TRANSL_LABEL.
@@ -360,6 +361,7 @@ Proof.
destruct i; try (intros [A B]; apply A). intros. subst c0. repeat constructor.
- intros. monadInv H0.
destruct (zlt Int.max_unsigned (list_length_z x)); inv EQ0. monadInv EQ.
+ rewrite transl_code'_transl_code in EQ0.
exists x; exists false; split; auto. unfold fn_code. repeat constructor.
- exact transf_function_no_overflow.
Qed.
@@ -421,7 +423,7 @@ Lemma exec_straight_steps:
exists rs2,
exec_straight tge tf c rs1 m1' k rs2 m2'
/\ agree ms2 sp rs2
- /\ (r11_is_parent ep i = true -> rs2#GPR11 = parent_sp s)) ->
+ /\ (it1_is_parent ep i = true -> rs2#GPR11 = parent_sp s)) ->
exists st',
plus step tge (State rs1 m1') E0 st' /\
match_states (Mach.State s fb sp c ms2 m2) st'.
@@ -440,7 +442,7 @@ Lemma exec_straight_steps_goto:
Genv.find_funct_ptr ge fb = Some (Internal f) ->
Mach.find_label lbl f.(Mach.fn_code) = Some c' ->
transl_code_at_pc ge (rs1 PC) fb f (i :: c) ep tf tc ->
- r11_is_parent ep i = false ->
+ it1_is_parent ep i = false ->
(forall k c (TR: transl_instr f i ep k = OK c),
exists jmp, exists k', exists rs2,
exec_straight tge tf c rs1 m1' (jmp :: k') rs2 m2'
@@ -897,7 +899,7 @@ Hint Resolve agree_nextinstr agree_set_other: asmgen.
exploit Mem.storev_extends. eexact G. eexact H2. eauto. eauto.
intros [m3' [P Q]].
(* Execution of function prologue *)
- monadInv EQ0.
+ monadInv EQ0. rewrite transl_code'_transl_code in EQ1.
set (rs2 := nextinstr (rs0#GPR1 <- sp #GPR0 <- Vundef)).
set (rs3 := nextinstr (rs2#GPR0 <- (rs0#LR))).
set (rs4 := nextinstr rs3).