summaryrefslogtreecommitdiff
path: root/asmcomp
diff options
context:
space:
mode:
Diffstat (limited to 'asmcomp')
-rw-r--r--asmcomp/amd64/emit.mlp28
-rw-r--r--asmcomp/amd64/proc.ml53
-rw-r--r--asmcomp/arm/proc.ml3
-rw-r--r--asmcomp/asmgen.ml1
-rw-r--r--asmcomp/emitaux.ml3
-rw-r--r--asmcomp/i386/proc.ml3
-rw-r--r--asmcomp/power/proc.ml2
-rw-r--r--asmcomp/proc.mli3
-rw-r--r--asmcomp/sparc/proc.ml2
9 files changed, 73 insertions, 25 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;
diff --git a/asmcomp/amd64/proc.ml b/asmcomp/amd64/proc.ml
index 351770b281..3d065bc0bf 100644
--- a/asmcomp/amd64/proc.ml
+++ b/asmcomp/amd64/proc.ml
@@ -45,9 +45,9 @@ let masm =
r9 7
r12 8
r13 9
- rbp 10
- r10 11
- r11 12
+ r10 10
+ r11 11
+ rbp 12
r14 trap pointer
r15 allocation pointer
@@ -77,10 +77,10 @@ let int_reg_name =
match Config.ccomp_type with
| "msvc" ->
[| "rax"; "rbx"; "rdi"; "rsi"; "rdx"; "rcx"; "r8"; "r9";
- "r12"; "r13"; "rbp"; "r10"; "r11" |]
+ "r12"; "r13"; "r10"; "r11"; "rbp" |]
| _ ->
[| "%rax"; "%rbx"; "%rdi"; "%rsi"; "%rdx"; "%rcx"; "%r8"; "%r9";
- "%r12"; "%r13"; "%rbp"; "%r10"; "%r11" |]
+ "%r12"; "%r13"; "%r10"; "%r11"; "%rbp" |]
let float_reg_name =
match Config.ccomp_type with
@@ -133,6 +133,7 @@ let phys_reg n =
let rax = phys_reg 0
let rcx = phys_reg 5
let rdx = phys_reg 4
+let rbp = phys_reg 12
let rxmm15 = phys_reg 115
let stack_slot slot ty =
@@ -242,12 +243,12 @@ let destroyed_at_c_call =
if win64 then
(* Win64: rbx, rbp, rsi, rdi, r12-r15, xmm6-xmm15 preserved *)
Array.of_list(List.map phys_reg
- [0;4;5;6;7;11;12;
+ [0;4;5;6;7;10;11;
100;101;102;103;104;105])
else
(* Unix: rbp, rbx, r12-r15 preserved *)
Array.of_list(List.map phys_reg
- [0;2;3;4;5;6;7;11;12;
+ [0;2;3;4;5;6;7;10;11;
100;101;102;103;104;105;106;107;
108;109;110;111;112;113;114;115])
@@ -259,23 +260,37 @@ let destroyed_at_oper = function
| Iop(Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _))
-> [| rax |]
| Iswitch(_, _) -> [| rax; rdx |]
- | _ -> [||]
+ | _ ->
+ if Config.with_frame_pointers then
+(* prevent any use of the frame pointer ! *)
+ [| rbp |]
+ else
+ [||]
+
let destroyed_at_raise = all_phys_regs
(* Maximal register pressure *)
+let fp() = Config.with_frame_pointers
+
let safe_register_pressure = function
- Iextcall(_,_) -> if win64 then 8 else 0
- | _ -> 11
+ Iextcall(_,_) -> if win64 then if fp() then 7 else 8 else 0
+ | _ -> if fp() then 10 else 11
let max_register_pressure = function
- Iextcall(_, _) -> if win64 then [| 8; 10 |] else [| 4; 0 |]
- | Iintop(Idiv | Imod) -> [| 11; 16 |]
- | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _)
- -> [| 12; 16 |]
- | Istore(Single, _) -> [| 13; 15 |]
- | _ -> [| 13; 16 |]
+ Iextcall(_, _) ->
+ if win64 then
+ if fp() then [| 7; 10 |] else [| 8; 10 |]
+ else
+ if fp() then [| 3; 0 |] else [| 4; 0 |]
+ | Iintop(Idiv | Imod) ->
+ if fp() then [| 10; 16 |] else [| 11; 16 |]
+ | Ialloc _ | Iintop(Icomp _) | Iintop_imm((Idiv|Imod|Icomp _), _) ->
+ if fp() then [| 11; 16 |] else [| 12; 16 |]
+ | Istore(Single, _) ->
+ if fp() then [| 12; 15 |] else [| 13; 15 |]
+ | _ -> if fp() then [| 12; 16 |] else [| 13; 16 |]
(* Layout of the stack frame *)
@@ -292,3 +307,9 @@ let assemble_file infile outfile =
else
Ccomp.command (Config.asm ^ " -o " ^
Filename.quote outfile ^ " " ^ Filename.quote infile)
+
+let init () =
+ if fp () then begin
+ num_available_registers.(0) <- 12
+ end else
+ num_available_registers.(0) <- 13
diff --git a/asmcomp/arm/proc.ml b/asmcomp/arm/proc.ml
index b8ff779b63..dbb13173a9 100644
--- a/asmcomp/arm/proc.ml
+++ b/asmcomp/arm/proc.ml
@@ -233,3 +233,6 @@ let contains_calls = ref false
let assemble_file infile outfile =
Ccomp.command (Config.asm ^ " -o " ^
Filename.quote outfile ^ " " ^ Filename.quote infile)
+
+
+let init () = ()
diff --git a/asmcomp/asmgen.ml b/asmcomp/asmgen.ml
index 448980740c..40f7dafbd0 100644
--- a/asmcomp/asmgen.ml
+++ b/asmcomp/asmgen.ml
@@ -57,6 +57,7 @@ let rec regalloc ppf round fd =
let (++) x f = f x
let compile_fundecl (ppf : formatter) fd_cmm =
+ Proc.init ();
Reg.reset();
fd_cmm
++ Selection.fundecl
diff --git a/asmcomp/emitaux.ml b/asmcomp/emitaux.ml
index c3f8888515..3ad467cbff 100644
--- a/asmcomp/emitaux.ml
+++ b/asmcomp/emitaux.ml
@@ -220,7 +220,8 @@ let reset_debug_info () =
display .loc for every instruction. *)
let emit_debug_info dbg =
if is_cfi_enabled () &&
- !Clflags.debug && not (Debuginfo.is_none dbg) then begin
+ (!Clflags.debug || Config.with_frame_pointers)
+ && not (Debuginfo.is_none dbg) then begin
let line = dbg.Debuginfo.dinfo_line in
assert (line <> 0); (* clang errors out on zero line numbers *)
let file_name = dbg.Debuginfo.dinfo_file in
diff --git a/asmcomp/i386/proc.ml b/asmcomp/i386/proc.ml
index bb510bbf40..4cecb2d44f 100644
--- a/asmcomp/i386/proc.ml
+++ b/asmcomp/i386/proc.ml
@@ -198,3 +198,6 @@ let assemble_file infile outfile =
else
Ccomp.command (Config.asm ^ " -o " ^
Filename.quote outfile ^ " " ^ Filename.quote infile)
+
+let init () = ()
+
diff --git a/asmcomp/power/proc.ml b/asmcomp/power/proc.ml
index feb38f2538..38adadc05a 100644
--- a/asmcomp/power/proc.ml
+++ b/asmcomp/power/proc.ml
@@ -237,3 +237,5 @@ let assemble_file infile outfile =
open Clflags;;
open Config;;
+
+let init () = ()
diff --git a/asmcomp/proc.mli b/asmcomp/proc.mli
index 91a480b097..6cc6aedc90 100644
--- a/asmcomp/proc.mli
+++ b/asmcomp/proc.mli
@@ -46,3 +46,6 @@ val contains_calls: bool ref
(* Calling the assembler *)
val assemble_file: string -> string -> int
+
+(* Called before translating a fundecl. *)
+val init : unit -> unit
diff --git a/asmcomp/sparc/proc.ml b/asmcomp/sparc/proc.ml
index b88d5aaae4..ed107a82a7 100644
--- a/asmcomp/sparc/proc.ml
+++ b/asmcomp/sparc/proc.ml
@@ -211,3 +211,5 @@ let assemble_file infile outfile =
end in
Ccomp.command (Config.asm ^ asflags ^
Filename.quote outfile ^ " " ^ Filename.quote infile)
+
+let init () = ()