1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Description of the Sparc processor *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Cmm
|
|
|
|
open Reg
|
|
|
|
open Arch
|
|
|
|
open Mach
|
|
|
|
|
|
|
|
(* Instruction selection *)
|
|
|
|
|
1995-07-25 04:37:38 -07:00
|
|
|
let word_addressed = false
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Registers available for register allocation *)
|
|
|
|
|
|
|
|
(* Register map:
|
1997-07-18 06:35:00 -07:00
|
|
|
%o0 - %o5 0 - 5 function results, C functions args / res
|
|
|
|
%i0 - %i5 6 - 11 function arguments, preserved by C
|
1997-07-18 08:16:19 -07:00
|
|
|
%l0 - %l4 12 - 16 general purpose, preserved by C
|
|
|
|
%g3 - %g4 17 - 18 general purpose, not preserved by C
|
|
|
|
|
|
|
|
%l5 exception pointer
|
|
|
|
%l6 allocation pointer
|
|
|
|
%l7 address of allocation limit
|
1997-07-18 06:35:00 -07:00
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
%g0 always zero
|
1997-07-18 08:16:19 -07:00
|
|
|
%g1 - %g2 temporaries
|
|
|
|
%g5 - %g7 reserved for system libraries
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
%f0 - %f10 100 - 105 function arguments and results
|
|
|
|
%f12 - %f28 106 - 114 general purpose
|
|
|
|
%f30 temporary *)
|
|
|
|
|
|
|
|
let int_reg_name = [|
|
1997-07-18 06:35:00 -07:00
|
|
|
(* 0-5 *) "%o0"; "%o1"; "%o2"; "%o3"; "%o4"; "%o5";
|
|
|
|
(* 6-11 *) "%i0"; "%i1"; "%i2"; "%i3"; "%i4"; "%i5";
|
1997-07-18 08:16:19 -07:00
|
|
|
(* 12-16 *) "%l0"; "%l1"; "%l2"; "%l3"; "%l4";
|
|
|
|
(* 17-18 *) "%g3"; "%g4"
|
1995-06-15 01:17:29 -07:00
|
|
|
|]
|
|
|
|
|
|
|
|
let float_reg_name = [|
|
|
|
|
(* 100-105 *) "%f0"; "%f2"; "%f4"; "%f6"; "%f8"; "%f10";
|
|
|
|
(* 106-109 *) "%f12"; "%f14"; "%f16"; "%f18";
|
|
|
|
(* 110-114 *) "%f20"; "%f22"; "%f24"; "%f26"; "%f28";
|
|
|
|
(* Odd parts of register pairs *)
|
|
|
|
(* 115-120 *) "%f1"; "%f3"; "%f5"; "%f7"; "%f9"; "%f11";
|
|
|
|
(* 121-124 *) "%f13"; "%f15"; "%f17"; "%f19";
|
|
|
|
(* 125-129 *) "%f21"; "%f23"; "%f25"; "%f27"; "%f29"
|
|
|
|
|]
|
|
|
|
|
|
|
|
let num_register_classes = 2
|
|
|
|
|
|
|
|
let register_class r =
|
|
|
|
match r.typ with
|
|
|
|
Int -> 0
|
|
|
|
| Addr -> 0
|
|
|
|
| Float -> 1
|
|
|
|
|
1997-07-18 08:16:19 -07:00
|
|
|
let num_available_registers = [| 19; 15 |]
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
let first_available_register = [| 0; 100 |]
|
|
|
|
|
|
|
|
let register_name r =
|
|
|
|
if r < 100 then int_reg_name.(r) else float_reg_name.(r - 100)
|
|
|
|
|
1995-10-25 07:54:47 -07:00
|
|
|
let rotate_registers = true
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Representation of hard registers by pseudo-registers *)
|
|
|
|
|
|
|
|
let hard_int_reg =
|
1997-07-18 08:16:19 -07:00
|
|
|
let v = Array.create 19 Reg.dummy in
|
|
|
|
for i = 0 to 18 do v.(i) <- Reg.at_location Int (Reg i) done;
|
1995-06-15 01:17:29 -07:00
|
|
|
v
|
|
|
|
|
|
|
|
let hard_float_reg =
|
1996-04-22 04:15:41 -07:00
|
|
|
let v = Array.create 30 Reg.dummy in
|
1995-06-15 01:17:29 -07:00
|
|
|
for i = 0 to 29 do v.(i) <- Reg.at_location Float (Reg(100 + i)) done;
|
|
|
|
v
|
|
|
|
|
|
|
|
let all_phys_regs =
|
|
|
|
Array.append hard_int_reg (Array.sub hard_float_reg 0 15)
|
|
|
|
(* No need to include the odd parts of float register pairs *)
|
|
|
|
|
|
|
|
let phys_reg n =
|
|
|
|
if n < 100 then hard_int_reg.(n) else hard_float_reg.(n - 100)
|
|
|
|
|
|
|
|
let stack_slot slot ty =
|
|
|
|
Reg.at_location ty (Stack slot)
|
|
|
|
|
|
|
|
(* Calling conventions *)
|
|
|
|
|
|
|
|
let calling_conventions first_int last_int first_float last_float make_stack
|
|
|
|
arg =
|
1996-04-22 04:15:41 -07:00
|
|
|
let loc = Array.create (Array.length arg) Reg.dummy in
|
1995-06-15 01:17:29 -07:00
|
|
|
let int = ref first_int in
|
|
|
|
let float = ref first_float in
|
|
|
|
let ofs = ref 0 in
|
|
|
|
for i = 0 to Array.length arg - 1 do
|
|
|
|
match arg.(i).typ with
|
|
|
|
Int | Addr as ty ->
|
|
|
|
if !int <= last_int then begin
|
|
|
|
loc.(i) <- phys_reg !int;
|
|
|
|
incr int
|
|
|
|
end else begin
|
|
|
|
loc.(i) <- stack_slot (make_stack !ofs) ty;
|
|
|
|
ofs := !ofs + size_int
|
|
|
|
end
|
|
|
|
| Float ->
|
|
|
|
if !float <= last_float then begin
|
|
|
|
loc.(i) <- phys_reg !float;
|
|
|
|
incr float
|
|
|
|
end else begin
|
|
|
|
loc.(i) <- stack_slot (make_stack !ofs) Float;
|
|
|
|
ofs := !ofs + size_float
|
|
|
|
end
|
|
|
|
done;
|
|
|
|
(loc, Misc.align !ofs 8) (* Keep stack 8-aligned *)
|
|
|
|
|
|
|
|
let incoming ofs = Incoming ofs
|
|
|
|
let outgoing ofs = Outgoing ofs
|
|
|
|
let not_supported ofs = fatal_error "Proc.loc_results: cannot call"
|
|
|
|
|
|
|
|
let loc_arguments arg =
|
1997-07-18 06:35:00 -07:00
|
|
|
calling_conventions 6 15 100 105 outgoing arg
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc_parameters arg =
|
1997-07-18 06:35:00 -07:00
|
|
|
let (loc, ofs) = calling_conventions 6 15 100 105 incoming arg in loc
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc_results res =
|
1997-07-18 06:35:00 -07:00
|
|
|
let (loc, ofs) = calling_conventions 0 5 100 105 not_supported res in loc
|
1995-06-15 01:17:29 -07:00
|
|
|
|
1995-10-23 09:55:01 -07:00
|
|
|
(* On the Sparc, all arguments to C functions, even floating-point arguments,
|
1995-12-17 05:18:37 -08:00
|
|
|
are passed in %o0..%o5, then on the stack *)
|
1995-06-15 01:17:29 -07:00
|
|
|
|
1995-10-23 09:55:01 -07:00
|
|
|
let loc_external_arguments arg =
|
1998-02-13 08:32:12 -08:00
|
|
|
let loc = ref [] in
|
1997-07-18 06:35:00 -07:00
|
|
|
let reg = ref 0 (* %o0 *) in
|
1995-10-23 09:55:01 -07:00
|
|
|
let ofs = ref (-4) in (* start at sp + 92 = sp + 96 - 4 *)
|
1995-06-15 01:17:29 -07:00
|
|
|
for i = 0 to Array.length arg - 1 do
|
1997-07-18 06:35:00 -07:00
|
|
|
if !reg <= 5 (* %o5 *) then begin
|
1995-10-23 09:55:01 -07:00
|
|
|
match arg.(i).typ with
|
1998-02-13 08:32:12 -08:00
|
|
|
Int | Addr ->
|
|
|
|
loc := phys_reg !reg :: !loc;
|
|
|
|
incr reg
|
|
|
|
| Float ->
|
|
|
|
if !reg = 5 then fatal_error "Proc_sparc: cannot call";
|
|
|
|
loc := phys_reg (!reg + 1) :: phys_reg !reg :: !loc;
|
|
|
|
reg := !reg + 2
|
1995-10-23 09:55:01 -07:00
|
|
|
end else begin
|
1998-02-13 08:32:12 -08:00
|
|
|
loc := stack_slot (outgoing !ofs) arg.(i).typ :: !loc;
|
1995-10-23 09:55:01 -07:00
|
|
|
ofs := !ofs + size_component arg.(i).typ
|
|
|
|
end
|
1995-06-15 01:17:29 -07:00
|
|
|
done;
|
1998-02-13 08:32:12 -08:00
|
|
|
(* Keep stack 8-aligned *)
|
|
|
|
(Array.of_list(List.rev !loc), Misc.align (!ofs + 4) 8)
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
let loc_external_results res =
|
1997-07-18 06:35:00 -07:00
|
|
|
let (loc, ofs) = calling_conventions 0 0 100 100 not_supported res in loc
|
1995-06-15 01:17:29 -07:00
|
|
|
|
1997-07-18 06:35:00 -07:00
|
|
|
let loc_exn_bucket = phys_reg 0 (* $o0 *)
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
(* Registers destroyed by operations *)
|
|
|
|
|
1997-07-18 08:16:19 -07:00
|
|
|
let destroyed_at_c_call = (* %l0-%l4, %i0-%i5 preserved *)
|
1995-11-05 09:28:42 -08:00
|
|
|
Array.of_list(List.map phys_reg
|
1997-07-18 08:16:19 -07:00
|
|
|
[0; 1; 2; 3; 4; 5; 17; 18;
|
1997-07-18 06:35:00 -07:00
|
|
|
100; 101; 102; 103; 104; 105; 106; 107;
|
1995-11-05 09:28:42 -08:00
|
|
|
108; 109; 110; 111; 112; 113; 114])
|
1995-07-18 10:40:23 -07:00
|
|
|
|
|
|
|
let destroyed_at_oper = function
|
|
|
|
Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs
|
|
|
|
| Iop(Iextcall(_, false)) -> destroyed_at_c_call
|
|
|
|
| _ -> [||]
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
let destroyed_at_raise = all_phys_regs
|
|
|
|
|
1995-07-18 10:40:23 -07:00
|
|
|
(* Maximal register pressure *)
|
|
|
|
|
|
|
|
let safe_register_pressure = function
|
|
|
|
Iextcall(_, _) -> 0
|
|
|
|
| _ -> 15
|
|
|
|
|
|
|
|
let max_register_pressure = function
|
1997-07-18 08:16:19 -07:00
|
|
|
Iextcall(_, _) -> [| 11; 0 |]
|
|
|
|
| _ -> [| 19; 15 |]
|
1995-06-15 01:17:29 -07:00
|
|
|
|
1995-08-13 02:31:50 -07:00
|
|
|
(* Latencies (in cycles). Wild guesses. *)
|
|
|
|
|
|
|
|
let need_scheduling = true
|
|
|
|
|
|
|
|
let oper_latency = function
|
|
|
|
Ireload -> 3
|
1995-08-24 06:21:58 -07:00
|
|
|
| Iload(_, _) -> 3
|
1995-08-24 08:12:05 -07:00
|
|
|
| Iconst_float _ -> 3 (* turned into a load *)
|
1995-08-13 02:31:50 -07:00
|
|
|
| Iaddf | Isubf -> 3
|
|
|
|
| Imulf -> 5
|
|
|
|
| Idivf -> 15
|
|
|
|
| _ -> 1
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Layout of the stack *)
|
|
|
|
|
|
|
|
let num_stack_slots = [| 0; 0 |]
|
|
|
|
let contains_calls = ref false
|
|
|
|
|
1995-07-18 06:09:02 -07:00
|
|
|
(* Calling the assembler and the archiver *)
|
|
|
|
|
|
|
|
let assemble_file infile outfile =
|
1997-05-15 06:22:08 -07:00
|
|
|
Ccomp.command ("as -o " ^ outfile ^ " " ^ infile)
|
1995-07-18 06:09:02 -07:00
|
|
|
|