1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Caml Special Light *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1995 Institut National de Recherche en Informatique et *)
|
|
|
|
(* Automatique. Distributed only by permission. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Description of the Alpha processor *)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Cmm
|
|
|
|
open Reg
|
|
|
|
open Arch
|
|
|
|
open Mach
|
|
|
|
|
|
|
|
(* Exceptions raised to signal cases not handled here *)
|
|
|
|
|
|
|
|
exception Use_default
|
|
|
|
|
|
|
|
(* Instruction selection *)
|
|
|
|
|
|
|
|
let select_addressing = function
|
1995-07-02 09:41:48 -07:00
|
|
|
Cconst_symbol s ->
|
1995-06-15 01:17:29 -07:00
|
|
|
(Ibased(s, 0), Ctuple [])
|
1995-07-02 09:41:48 -07:00
|
|
|
| Cop(Cadda, [Cconst_symbol s; Cconst_int n]) ->
|
1995-06-15 01:17:29 -07:00
|
|
|
(Ibased(s, n), Ctuple [])
|
1995-07-02 09:41:48 -07:00
|
|
|
| Cop(Cadda, [arg; Cconst_int n]) ->
|
1995-06-15 01:17:29 -07:00
|
|
|
(Iindexed n, arg)
|
1995-07-10 02:48:27 -07:00
|
|
|
| Cop(Cadda, [arg1; Cop(Caddi, [arg2; Cconst_int n])]) ->
|
|
|
|
(Iindexed n, Cop(Cadda, [arg1; arg2]))
|
1995-06-15 01:17:29 -07:00
|
|
|
| arg ->
|
|
|
|
(Iindexed 0, arg)
|
|
|
|
|
|
|
|
let select_oper op args =
|
|
|
|
match (op, args) with
|
|
|
|
((Caddi|Cadda),
|
1995-07-02 09:41:48 -07:00
|
|
|
[arg2; Cop(Clsl, [arg1; Cconst_int(2|3 as shift)])]) ->
|
|
|
|
(Ispecific(if shift = 2 then Iadd4 else Iadd8), [arg1; arg2])
|
1995-06-15 01:17:29 -07:00
|
|
|
| ((Caddi|Cadda),
|
1995-07-02 09:41:48 -07:00
|
|
|
[arg2; Cop(Cmuli, [arg1; Cconst_int(4|8 as mult)])]) ->
|
|
|
|
(Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2])
|
1995-06-15 01:17:29 -07:00
|
|
|
| ((Caddi|Cadda),
|
1995-07-02 09:41:48 -07:00
|
|
|
[arg2; Cop(Cmuli, [Cconst_int(4|8 as mult); arg1])]) ->
|
|
|
|
(Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2])
|
|
|
|
| (Caddi, [Cop(Clsl, [arg1; Cconst_int(2|3 as shift)]); arg2]) ->
|
|
|
|
(Ispecific(if shift = 2 then Iadd4 else Iadd8), [arg1; arg2])
|
|
|
|
| (Caddi, [Cop(Cmuli, [arg1; Cconst_int(4|8 as mult)]); arg2]) ->
|
|
|
|
(Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2])
|
|
|
|
| (Caddi, [Cop(Cmuli, [Cconst_int(4|8 as mult); arg1]); arg2]) ->
|
|
|
|
(Ispecific(if mult = 4 then Iadd4 else Iadd8), [arg1; arg2])
|
|
|
|
| (Csubi, [Cop(Clsl, [arg1; Cconst_int(2|3 as shift)]); arg2]) ->
|
|
|
|
(Ispecific(if shift = 2 then Isub4 else Isub8), [arg1; arg2])
|
1995-11-19 08:53:12 -08:00
|
|
|
| (Csubi, [Cop(Cmuli, [Cconst_int(4|8 as mult); arg1]); arg2]) ->
|
|
|
|
(Ispecific(if mult = 4 then Isub4 else Isub8), [arg1; arg2])
|
1995-06-15 01:17:29 -07:00
|
|
|
| _ ->
|
|
|
|
raise Use_default
|
|
|
|
|
1995-07-02 09:41:48 -07:00
|
|
|
let select_store addr exp = raise Use_default
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
let pseudoregs_for_operation op arg res = raise Use_default
|
|
|
|
|
|
|
|
let is_immediate (n:int) = true
|
|
|
|
|
1995-07-25 04:37:38 -07:00
|
|
|
let word_addressed = true
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
(* Registers available for register allocation *)
|
|
|
|
|
|
|
|
(* Register map:
|
|
|
|
$0 - $7 0 - 7 function results
|
1995-07-07 05:07:07 -07:00
|
|
|
$8 - $12 8 - 12 general purpose ($9 - $15 are preserved by C)
|
1995-06-15 01:17:29 -07:00
|
|
|
$13 allocation pointer
|
|
|
|
$14 allocation limit
|
|
|
|
$15 trap pointer
|
1995-08-24 06:21:58 -07:00
|
|
|
$16 - $22 13 - 19 function arguments
|
|
|
|
$23 - $25 temporaries (for the code gen and for the asm)
|
1995-07-11 01:51:10 -07:00
|
|
|
$26 - $30 stack ptr, global ptr, etc
|
|
|
|
$31 always zero
|
1995-06-15 01:17:29 -07:00
|
|
|
|
1995-07-07 05:07:07 -07:00
|
|
|
$f0 - $f7 100 - 107 function results
|
|
|
|
$f8 - $f15 108 - 115 general purpose ($f2 - $f9 preserved by C)
|
|
|
|
$f16 - $f23 116 - 123 function arguments
|
|
|
|
$f24 - $f29 124 - 129 general purpose
|
1995-06-15 01:17:29 -07:00
|
|
|
$f30 temporary
|
|
|
|
$f31 always zero *)
|
|
|
|
|
|
|
|
let int_reg_name = [|
|
1995-07-07 05:07:07 -07:00
|
|
|
(* 0-7 *) "$0"; "$1"; "$2"; "$3"; "$4"; "$5"; "$6"; "$7";
|
|
|
|
(* 8-12 *) "$8"; "$9"; "$10"; "$11"; "$12";
|
1995-08-24 06:21:58 -07:00
|
|
|
(* 13-19 *) "$16"; "$17"; "$18"; "$19"; "$20"; "$21"; "$22"
|
1995-06-15 01:17:29 -07:00
|
|
|
|]
|
|
|
|
|
|
|
|
let float_reg_name = [|
|
1995-07-07 05:07:07 -07:00
|
|
|
(* 100-107 *) "$f0"; "$f1"; "$f2"; "$f3"; "$f4"; "$f5"; "$f6"; "$f7";
|
|
|
|
(* 108-115 *) "$f8"; "$f9"; "$f10"; "$f11"; "$f12"; "$f13"; "$f14"; "$f15";
|
|
|
|
(* 116-123 *) "$f16"; "$f17"; "$f18"; "$f19"; "$f20"; "$f21"; "$f22"; "$f23";
|
|
|
|
(* 124-129 *) "$f24"; "$f25"; "$f26"; "$f27"; "$f28"; "$f29"
|
1995-06-15 01:17:29 -07:00
|
|
|
|]
|
|
|
|
|
|
|
|
let num_register_classes = 2
|
|
|
|
|
|
|
|
let register_class r =
|
|
|
|
match r.typ with
|
|
|
|
Int -> 0
|
|
|
|
| Addr -> 0
|
|
|
|
| Float -> 1
|
|
|
|
|
1995-08-24 06:21:58 -07:00
|
|
|
let num_available_registers = [| 20; 30 |]
|
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 =
|
1995-08-24 06:21:58 -07:00
|
|
|
let v = Array.new 20 Reg.dummy in
|
|
|
|
for i = 0 to 19 do v.(i) <- Reg.at_location Int (Reg i) done;
|
1995-06-15 01:17:29 -07:00
|
|
|
v
|
|
|
|
|
|
|
|
let hard_float_reg =
|
|
|
|
let v = Array.new 30 Reg.dummy in
|
|
|
|
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 hard_float_reg
|
|
|
|
|
|
|
|
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 =
|
|
|
|
let loc = Array.new (Array.length arg) Reg.dummy in
|
|
|
|
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 16) (* Keep stack 16-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 =
|
1995-07-07 05:07:07 -07:00
|
|
|
calling_conventions 13 18 116 123 outgoing arg
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc_parameters arg =
|
1995-07-07 05:07:07 -07:00
|
|
|
let (loc, ofs) = calling_conventions 13 18 116 123 incoming arg in loc
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc_results res =
|
|
|
|
let (loc, ofs) = calling_conventions 0 7 100 107 not_supported res in loc
|
|
|
|
|
|
|
|
(* On the Alpha, C functions have calling conventions similar to those
|
|
|
|
for Caml functions, except that integer and floating-point registers
|
|
|
|
for arguments are allocated "in sequence". E.g. a function
|
|
|
|
taking a float f1 and two ints i2 and i3 will put f1 in the
|
|
|
|
first float reg, i2 in the second int reg and i3 in the third int reg. *)
|
|
|
|
|
1995-10-23 09:55:01 -07:00
|
|
|
let ext_calling_conventions first_int last_int first_float last_float
|
|
|
|
make_stack arg =
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc = Array.new (Array.length arg) Reg.dummy in
|
|
|
|
let int = ref first_int in
|
|
|
|
let float = ref first_float in
|
1995-10-23 09:55:01 -07:00
|
|
|
let ofs = ref 0 in
|
1995-06-15 01:17:29 -07:00
|
|
|
for i = 0 to Array.length arg - 1 do
|
|
|
|
match arg.(i).typ with
|
1995-10-23 09:55:01 -07:00
|
|
|
Int | Addr as ty ->
|
1995-06-15 01:17:29 -07:00
|
|
|
if !int <= last_int then begin
|
|
|
|
loc.(i) <- phys_reg !int; incr int; incr float
|
1995-10-23 09:55:01 -07:00
|
|
|
end else begin
|
|
|
|
loc.(i) <- stack_slot (make_stack !ofs) ty;
|
|
|
|
ofs := !ofs + size_int
|
|
|
|
end
|
1995-06-15 01:17:29 -07:00
|
|
|
| Float ->
|
|
|
|
if !float <= last_float then begin
|
|
|
|
loc.(i) <- phys_reg !float; incr int; incr float
|
1995-10-23 09:55:01 -07:00
|
|
|
end else begin
|
|
|
|
loc.(i) <- stack_slot (make_stack !ofs) Float;
|
|
|
|
ofs := !ofs + size_float
|
|
|
|
end
|
1995-06-15 01:17:29 -07:00
|
|
|
done;
|
1995-10-23 09:55:01 -07:00
|
|
|
(loc, Misc.align !ofs 16) (* Keep stack 16-aligned *)
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
let loc_external_arguments arg =
|
1995-10-23 09:55:01 -07:00
|
|
|
ext_calling_conventions 13 18 116 121 outgoing arg
|
1995-06-15 01:17:29 -07:00
|
|
|
let loc_external_results res =
|
1995-10-23 09:55:01 -07:00
|
|
|
let (loc, ofs) = ext_calling_conventions 0 0 100 100 not_supported res in loc
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
let loc_exn_bucket = phys_reg 0 (* $0 *)
|
|
|
|
|
|
|
|
(* Registers destroyed by operations *)
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
let destroyed_at_c_call = (* $9 - $12, $f2 - $f9 preserved *)
|
|
|
|
Array.of_list(List.map phys_reg
|
1995-08-24 06:21:58 -07:00
|
|
|
[0;1;2;3;4;5;6;7;8;13;14;15;16;17;18;19;
|
1995-07-10 02:48:27 -07:00
|
|
|
100;101;110;111;112;113;114;115;116;117;118;119;120;121;122;123;124;
|
|
|
|
125;126;127;128;129])
|
|
|
|
|
1995-07-02 09:41:48 -07:00
|
|
|
let destroyed_at_oper = function
|
1995-07-10 02:48:27 -07:00
|
|
|
Iop(Icall_ind | Icall_imm _ | Iextcall(_, true)) -> all_phys_regs
|
|
|
|
| Iop(Iextcall(_, false)) -> destroyed_at_c_call
|
1995-07-02 09:41:48 -07:00
|
|
|
| _ -> [||]
|
|
|
|
|
1995-06-15 01:17:29 -07:00
|
|
|
let destroyed_at_raise = all_phys_regs
|
|
|
|
|
1995-07-02 09:41:48 -07:00
|
|
|
(* Maximal register pressure *)
|
|
|
|
|
1995-07-10 02:48:27 -07:00
|
|
|
let safe_register_pressure = function
|
|
|
|
Iextcall(_, _) -> 4
|
1995-08-24 06:21:58 -07:00
|
|
|
| _ -> 19
|
1995-07-10 02:48:27 -07:00
|
|
|
let max_register_pressure = function
|
|
|
|
Iextcall(_, _) -> [| 4; 8 |]
|
1995-08-24 06:21:58 -07:00
|
|
|
| _ -> [| 19; 29 |]
|
1995-06-15 01:17:29 -07:00
|
|
|
|
|
|
|
(* Reloading *)
|
|
|
|
|
|
|
|
let reload_test makereg tst args = raise Use_default
|
|
|
|
let reload_operation makereg op args res = raise Use_default
|
|
|
|
|
1995-08-24 06:21:58 -07:00
|
|
|
(* No scheduling is needed, the assembler does it better than us. *)
|
|
|
|
|
|
|
|
let need_scheduling = false
|
|
|
|
|
|
|
|
let oper_latency _ = 1
|
1995-08-13 02:31:50 -07:00
|
|
|
|
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-02 09:41:48 -07:00
|
|
|
(* Calling the assembler *)
|
|
|
|
|
|
|
|
let assemble_file infile outfile =
|
1995-12-05 05:07:08 -08:00
|
|
|
Sys.command ("as -O2 -nocpp -o " ^ outfile ^ " " ^ infile)
|
1995-07-11 11:03:29 -07:00
|
|
|
|
|
|
|
(* Calling the archiver *)
|
|
|
|
|
|
|
|
let create_archive archive file_list =
|
|
|
|
Misc.remove_file archive;
|
|
|
|
Sys.command ("ar rcs " ^ archive ^ " " ^ String.concat " " file_list)
|