1(**************************************************************************)
2(*                                                                        *)
3(*                                 OCaml                                  *)
4(*                                                                        *)
5(*                 Benedikt Meurer, University of Siegen                  *)
6(*                                                                        *)
7(*   Copyright 1998 Institut National de Recherche en Informatique et     *)
8(*     en Automatique.                                                    *)
9(*   Copyright 2012 Benedikt Meurer.                                      *)
10(*                                                                        *)
11(*   All rights reserved.  This file is distributed under the terms of    *)
12(*   the GNU Lesser General Public License version 2.1, with the          *)
13(*   special exception on linking described in the file LICENSE.          *)
14(*                                                                        *)
15(**************************************************************************)
16
17open Arch
18open Mach
19
20(* Instruction scheduling for the ARM *)
21
22class scheduler = object
23
24inherit Schedgen.scheduler_generic as super
25
26(* Scheduling -- based roughly on the ARM11 (ARMv6) *)
27
28method oper_latency = function
29  (* Loads have a latency of two cycles in general *)
30    Iconst_symbol _
31  | Iconst_float _
32  | Iload(_, _)
33  | Ireload
34  | Ifloatofint       (* mcr/mrc count as memory access *)
35  | Iintoffloat -> 2
36  (* Multiplys have a latency of two cycles *)
37  | Iintop (Imul | Imulh)
38  | Ispecific(Imuladd | Imulsub | Imulhadd) -> 2
39  (* VFP instructions *)
40  | Iaddf
41  | Isubf
42  | Idivf
43  | Imulf | Ispecific Inegmulf
44  | Ispecific(Imuladdf | Inegmuladdf | Imulsubf | Inegmulsubf)
45  | Ispecific Isqrtf
46  | Inegf | Iabsf when !fpu >= VFPv2 -> 2
47  (* Everything else *)
48  | _ -> 1
49
50method! is_checkbound = function
51    Ispecific(Ishiftcheckbound _) -> true
52  | op -> super#is_checkbound op
53
54(* Issue cycles. Rough approximations *)
55
56method oper_issue_cycles = function
57    Ialloc _ -> 4
58  | Iintop(Ilsl | Ilsr | Iasr) -> 2
59  | Iintop(Icomp _)
60  | Iintop_imm(Icomp _, _) -> 3
61  | Iintop(Icheckbound _)
62  | Iintop_imm(Icheckbound _, _) -> 2
63  | Ispecific(Ishiftcheckbound _) -> 3
64  | Iintop(Imul | Imulh)
65  | Ispecific(Imuladd | Imulsub | Imulhadd) -> 2
66  (* VFP instructions *)
67  | Iaddf
68  | Isubf -> 7
69  | Imulf
70  | Ispecific Inegmulf -> 9
71  | Ispecific(Imuladdf | Inegmuladdf | Imulsubf | Inegmulsubf) -> 17
72  | Idivf
73  | Ispecific Isqrtf -> 27
74  | Inegf | Iabsf | Iconst_float _ when !fpu >= VFPv2 -> 4
75  (* Everything else *)
76  | _ -> 1
77
78end
79
80let fundecl f = (new scheduler)#schedule_fundecl f
81