2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1997-07-24 04:49:12 -07:00
|
|
|
|
|
|
|
(* Selection of pseudo-instructions, assignment of pseudo-registers,
|
|
|
|
sequentialization. *)
|
|
|
|
|
2016-10-25 08:09:53 -07:00
|
|
|
type environment
|
|
|
|
|
2018-09-26 01:50:42 -07:00
|
|
|
val env_add
|
2020-02-25 07:01:51 -08:00
|
|
|
: ?mut:Asttypes.mutable_flag
|
|
|
|
-> Backend_var.With_provenance.t
|
2018-09-26 01:50:42 -07:00
|
|
|
-> Reg.t array
|
|
|
|
-> environment
|
|
|
|
-> environment
|
2016-10-25 08:09:53 -07:00
|
|
|
|
2018-09-26 01:50:42 -07:00
|
|
|
val env_find : Backend_var.t -> environment -> Reg.t array
|
1997-07-24 04:49:12 -07:00
|
|
|
|
|
|
|
val size_expr : environment -> Cmm.expression -> int
|
|
|
|
|
2017-02-15 03:14:10 -08:00
|
|
|
module Effect : sig
|
|
|
|
type t =
|
|
|
|
| None
|
|
|
|
| Raise
|
|
|
|
| Arbitrary
|
|
|
|
end
|
|
|
|
|
|
|
|
module Coeffect : sig
|
|
|
|
type t =
|
|
|
|
| None
|
|
|
|
| Read_mutable
|
|
|
|
| Arbitrary
|
|
|
|
end
|
|
|
|
|
|
|
|
module Effect_and_coeffect : sig
|
|
|
|
type t
|
|
|
|
|
|
|
|
val none : t
|
|
|
|
val arbitrary : t
|
|
|
|
|
|
|
|
val effect : t -> Effect.t
|
|
|
|
val coeffect : t -> Coeffect.t
|
|
|
|
|
|
|
|
val effect_only : Effect.t -> t
|
|
|
|
val coeffect_only : Coeffect.t -> t
|
|
|
|
|
|
|
|
val join : t -> t -> t
|
|
|
|
val join_list_map : 'a list -> ('a -> t) -> t
|
|
|
|
end
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
class virtual selector_generic : object
|
2010-05-21 05:00:49 -07:00
|
|
|
(* The following methods must or can be overridden by the processor
|
1997-07-24 04:49:12 -07:00
|
|
|
description *)
|
2020-09-17 01:48:25 -07:00
|
|
|
method is_immediate : Mach.integer_operation -> int -> bool
|
|
|
|
(* Must be overriden to indicate whether a constant is a suitable
|
|
|
|
immediate operand to the given integer arithmetic instruction.
|
|
|
|
The default implementation handles shifts by immediate amounts,
|
|
|
|
but produces no immediate operations otherwise. *)
|
2020-08-26 02:58:51 -07:00
|
|
|
method virtual is_immediate_test : Mach.integer_comparison -> int -> bool
|
|
|
|
(* Must be defined to indicate whether a constant is a suitable
|
|
|
|
immediate operand to the given integer test *)
|
1998-06-24 12:22:26 -07:00
|
|
|
method virtual select_addressing :
|
2012-02-04 01:43:33 -08:00
|
|
|
Cmm.memory_chunk -> Cmm.expression -> Arch.addressing_mode * Cmm.expression
|
1997-07-24 04:49:12 -07:00
|
|
|
(* Must be defined to select addressing modes *)
|
2006-04-16 16:28:22 -07:00
|
|
|
method is_simple_expr: Cmm.expression -> bool
|
2017-02-15 03:14:10 -08:00
|
|
|
method effects_of : Cmm.expression -> Effect_and_coeffect.t
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to reflect special extcalls known to be pure *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method select_operation :
|
|
|
|
Cmm.operation ->
|
2016-10-12 06:13:05 -07:00
|
|
|
Cmm.expression list ->
|
|
|
|
Debuginfo.t ->
|
|
|
|
Mach.operation * Cmm.expression list
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with special arithmetic instructions *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method select_condition : Cmm.expression -> Mach.test * Cmm.expression
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with special test instructions *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method select_store :
|
2014-04-26 03:40:22 -07:00
|
|
|
bool -> Arch.addressing_mode -> Cmm.expression ->
|
|
|
|
Mach.operation * Cmm.expression
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with special store constant instructions *)
|
2009-03-31 02:44:50 -07:00
|
|
|
method regs_for : Cmm.machtype -> Reg.t array
|
|
|
|
(* Return an array of fresh registers of the given type.
|
|
|
|
Default implementation is like Reg.createv.
|
2010-05-21 05:00:49 -07:00
|
|
|
Can be overridden if float values are stored as pairs of
|
2009-03-31 02:44:50 -07:00
|
|
|
integer registers. *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method insert_op :
|
2019-03-08 05:06:31 -08:00
|
|
|
environment -> Mach.operation -> Reg.t array -> Reg.t array -> Reg.t array
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with 2-address instructions
|
1997-07-24 04:49:12 -07:00
|
|
|
or instructions with hardwired input/output registers *)
|
2007-01-29 04:11:18 -08:00
|
|
|
method insert_op_debug :
|
2019-03-08 05:06:31 -08:00
|
|
|
environment -> Mach.operation -> Debuginfo.t -> Reg.t array
|
|
|
|
-> Reg.t array -> Reg.t array
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with 2-address instructions
|
2007-01-29 04:11:18 -08:00
|
|
|
or instructions with hardwired input/output registers *)
|
2020-07-07 11:03:57 -07:00
|
|
|
method insert_move_extcall_arg :
|
|
|
|
environment -> Cmm.exttype -> Reg.t array -> Reg.t array -> unit
|
2020-07-28 04:22:03 -07:00
|
|
|
(* Can be overridden to deal with unusual unboxed calling conventions,
|
2020-07-07 11:03:57 -07:00
|
|
|
e.g. on a 64-bit platform, passing unboxed 32-bit arguments
|
|
|
|
in 32-bit stack slots. *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method emit_extcall_args :
|
2020-07-07 11:03:57 -07:00
|
|
|
environment -> Cmm.exttype list -> Cmm.expression list -> Reg.t array * int
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Can be overridden to deal with stack-based calling conventions *)
|
2000-06-29 04:44:36 -07:00
|
|
|
method emit_stores :
|
|
|
|
environment -> Cmm.expression list -> Reg.t array -> unit
|
2010-05-21 05:00:49 -07:00
|
|
|
(* Fill a freshly allocated block. Can be overridden for architectures
|
2000-06-29 04:44:36 -07:00
|
|
|
that do not provide Arch.offset_addressing. *)
|
2014-04-16 01:34:19 -07:00
|
|
|
|
|
|
|
method mark_call : unit
|
|
|
|
(* informs the code emitter that the current function is non-leaf:
|
|
|
|
it may perform a (non-tail) call; by default, sets
|
2019-08-14 04:52:05 -07:00
|
|
|
[contains_calls := true] *)
|
2014-04-16 01:34:19 -07:00
|
|
|
|
|
|
|
method mark_tailcall : unit
|
|
|
|
(* informs the code emitter that the current function may end with
|
|
|
|
a tail-call; by default, does nothing *)
|
|
|
|
|
|
|
|
method mark_c_tailcall : unit
|
|
|
|
(* informs the code emitter that the current function may call
|
|
|
|
a C function that never returns; by default, does nothing.
|
|
|
|
|
2017-02-13 08:09:50 -08:00
|
|
|
It is unnecessary to save the stack pointer in this situation
|
2014-04-16 01:34:19 -07:00
|
|
|
(which is the main purpose of tracking leaf functions) but some
|
|
|
|
architectures still need to ensure that the stack is properly
|
|
|
|
aligned when the C function is called. This is achieved by
|
2019-08-14 04:52:05 -07:00
|
|
|
overloading this method to set [contains_calls := true] *)
|
2014-04-16 01:34:19 -07:00
|
|
|
|
|
|
|
method mark_instr : Mach.instruction_desc -> unit
|
|
|
|
(* dispatches on instructions to call one of the marking function
|
|
|
|
above; overloading this is useful if Ispecific instructions need
|
|
|
|
marking *)
|
1997-07-24 04:49:12 -07:00
|
|
|
|
2020-10-08 06:19:31 -07:00
|
|
|
(* The following method is the entry point and should not be overridden. *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method emit_fundecl : Cmm.fundecl -> Mach.fundecl
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2010-05-21 05:00:49 -07:00
|
|
|
(* The following methods should not be overridden. They cannot be
|
1997-11-06 09:25:24 -08:00
|
|
|
declared "private" in the current implementation because they
|
|
|
|
are not always applied to "self", but ideally they should be private. *)
|
1997-07-24 04:49:12 -07:00
|
|
|
method extract : Mach.instruction
|
2019-03-08 05:06:31 -08:00
|
|
|
method insert :
|
|
|
|
environment -> Mach.instruction_desc -> Reg.t array -> Reg.t array -> unit
|
|
|
|
method insert_debug :
|
|
|
|
environment -> Mach.instruction_desc -> Debuginfo.t ->
|
|
|
|
Reg.t array -> Reg.t array -> unit
|
|
|
|
method insert_move : environment -> Reg.t -> Reg.t -> unit
|
|
|
|
method insert_move_args :
|
|
|
|
environment -> Reg.t array -> Reg.t array -> int -> unit
|
|
|
|
method insert_move_results :
|
|
|
|
environment -> Reg.t array -> Reg.t array -> int -> unit
|
|
|
|
method insert_moves : environment -> Reg.t array -> Reg.t array -> unit
|
1997-11-06 09:25:24 -08:00
|
|
|
method emit_expr :
|
2016-10-25 08:09:53 -07:00
|
|
|
environment -> Cmm.expression -> Reg.t array option
|
|
|
|
method emit_tail : environment -> Cmm.expression -> unit
|
2016-07-29 07:07:10 -07:00
|
|
|
|
2019-09-12 03:23:33 -07:00
|
|
|
(* [contains_calls] is declared as a reference instance variable,
|
|
|
|
instead of a mutable boolean instance variable,
|
|
|
|
because the traversal uses functional object copies. *)
|
|
|
|
val contains_calls : bool ref
|
1997-07-24 04:49:12 -07:00
|
|
|
end
|
2014-05-09 05:01:21 -07:00
|
|
|
|
|
|
|
val reset : unit -> unit
|