summaryrefslogtreecommitdiff
path: root/asmcomp/amd64/emit.mlp
diff options
context:
space:
mode:
Diffstat (limited to 'asmcomp/amd64/emit.mlp')
-rw-r--r--asmcomp/amd64/emit.mlp28
1 files changed, 20 insertions, 8 deletions
diff --git a/asmcomp/amd64/emit.mlp b/asmcomp/amd64/emit.mlp
index 447f63d6e3..2b598dbea9 100644
--- a/asmcomp/amd64/emit.mlp
+++ b/asmcomp/amd64/emit.mlp
@@ -23,6 +23,8 @@ open Emitaux
let macosx = (Config.system = "macosx")
let mingw64 = (Config.system = "mingw64")
+let fp() = Config.with_frame_pointers
+
(* Tradeoff between code size and code speed *)
let fastcode_flag = ref true
@@ -32,12 +34,13 @@ let stack_offset = ref 0
(* Layout of the stack frame *)
let frame_required () =
- !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0
+ fp() || !contains_calls || num_stack_slots.(0) > 0 || num_stack_slots.(1) > 0
let frame_size () = (* includes return address *)
if frame_required() then begin
let sz =
- (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8)
+ (!stack_offset + 8 * (num_stack_slots.(0) + num_stack_slots.(1)) + 8
+ + (if fp() then 8 else 0) )
in Misc.align sz 16
end else
!stack_offset + 8
@@ -107,13 +110,13 @@ let emit_reg = function
let reg_low_8_name =
[| "%al"; "%bl"; "%dil"; "%sil"; "%dl"; "%cl"; "%r8b"; "%r9b";
- "%r12b"; "%r13b"; "%bpl"; "%r10b"; "%r11b" |]
+ "%r12b"; "%r13b"; "%r10b"; "%r11b"; "%bpl" |]
let reg_low_16_name =
[| "%ax"; "%bx"; "%di"; "%si"; "%dx"; "%cx"; "%r8w"; "%r9w";
- "%r12w"; "%r13w"; "%bp"; "%r10w"; "%r11w" |]
+ "%r12w"; "%r13w"; "%r10w"; "%r11w"; "%bp" |]
let reg_low_32_name =
[| "%eax"; "%ebx"; "%edi"; "%esi"; "%edx"; "%ecx"; "%r8d"; "%r9d";
- "%r12d"; "%r13d"; "%ebp"; "%r10d"; "%r11d" |]
+ "%r12d"; "%r13d"; "%r10d"; "%r11d"; "%ebp" |]
let emit_subreg tbl r =
match r.loc with
@@ -316,9 +319,12 @@ let emit_float_test cmp neg arg lbl =
let output_epilogue f =
if frame_required() then begin
- let n = frame_size() - 8 in
+ let n = frame_size() - 8 - (if fp() then 8 else 0) in
` addq ${emit_int n}, %rsp\n`;
cfi_adjust_cfa_offset (-n);
+ if fp() then begin
+ ` popq %rbp\n`
+ end;
f ();
(* reset CFA back cause function body may continue *)
cfi_adjust_cfa_offset n
@@ -696,7 +702,8 @@ let emit_profile () =
need to preserve other regs. We do need to initialize rbp
like mcount expects it, though. *)
` pushq %r10\n`;
- ` movq %rsp, %rbp\n`;
+ if not Config.with_frame_pointers then
+ ` movq %rsp, %rbp\n`;
` {emit_call "mcount"}\n`;
` popq %r10\n`
| _ ->
@@ -724,9 +731,14 @@ let fundecl fundecl =
`{emit_symbol fundecl.fun_name}:\n`;
emit_debug_info fundecl.fun_dbg;
cfi_startproc ();
+ if fp() then begin
+ ` pushq %rbp\n`;
+ cfi_adjust_cfa_offset 8;
+ ` movq %rsp, %rbp\n`;
+ end;
if !Clflags.gprofile then emit_profile();
if frame_required() then begin
- let n = frame_size() - 8 in
+ let n = frame_size() - 8 - (if fp() then 8 else 0) in
` subq ${emit_int n}, %rsp\n`;
cfi_adjust_cfa_offset n;
end;