1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. *)
9 (* *)
10 (* All rights reserved. This file is distributed under the terms of *)
11 (* the GNU Lesser General Public License version 2.1, with the *)
12 (* special exception on linking described in the file LICENSE. *)
13 (* *)
14 (**************************************************************************)
15
16 (* Representation of machine code by sequences of pseudoinstructions *)
17
18 (** N.B. Backends vary in their treatment of call gc and checkbound
19 points. If the positioning of any labels associated with these is
20 important for some new feature in the compiler, the relevant backends'
21 behaviour should be checked. *)
22 type label = Cmm.label
23
24 type integer_comparison =
25 Isigned of Cmm.integer_comparison
26 | Iunsigned of Cmm.integer_comparison
27
28 type integer_operation =
29 Iadd | Isub | Imul | Imulh | Idiv | Imod
30 | Iand | Ior | Ixor | Ilsl | Ilsr | Iasr
31 | Icomp of integer_comparison
32 | Icheckbound of { label_after_error : label option;
33 spacetime_index : int; }
34 (** For Spacetime only, [Icheckbound] operations take two arguments, the
35 second being the pointer to the trie node for the current function
36 (and the first being as per non-Spacetime mode). *)
37
38 type float_comparison = Cmm.float_comparison
39
40 type test =
41 Itruetest
42 | Ifalsetest
43 | Iinttest of integer_comparison
44 | Iinttest_imm of integer_comparison * int
45 | Ifloattest of float_comparison
46 | Ioddtest
47 | Ieventest
48
49 type operation =
50 Imove
51 | Ispill
52 | Ireload
53 | Iconst_int of nativeint
54 | Iconst_float of int64
55 | Iconst_symbol of string
56 | Icall_ind of { label_after : label; }
57 | Icall_imm of { func : string; label_after : label; }
58 | Itailcall_ind of { label_after : label; }
59 | Itailcall_imm of { func : string; label_after : label; }
60 | Iextcall of { func : string; alloc : bool; label_after : label; }
61 | Istackoffset of int
62 | Iload of Cmm.memory_chunk * Arch.addressing_mode
63 | Istore of Cmm.memory_chunk * Arch.addressing_mode * bool
64 (* false = initialization, true = assignment *)
65 | Ialloc of { bytes : int; label_after_call_gc : label option;
66 spacetime_index : int; }
67 (** For Spacetime only, Ialloc instructions take one argument, being the
68 pointer to the trie node for the current function. *)
69 | Iintop of integer_operation
70 | Iintop_imm of integer_operation * int
71 | Inegf | Iabsf | Iaddf | Isubf | Imulf | Idivf
72 | Ifloatofint | Iintoffloat
73 | Ispecific of Arch.specific_operation
74 | Iname_for_debugger of { ident : Backend_var.t; which_parameter : int option;
75 provenance : unit option; is_assignment : bool; }
76 (** [Iname_for_debugger] has the following semantics:
77 (a) The argument register(s) is/are deemed to contain the value of the
78 given identifier.
79 (b) If [is_assignment] is [true], any information about other [Reg.t]s
80 that have been previously deemed to hold the value of that
81 identifier is forgotten. *)
82
83 type instruction =
84 { desc: instruction_desc;
85 next: instruction;
86 arg: Reg.t array;
87 res: Reg.t array;
88 dbg: Debuginfo.t;
89 mutable live: Reg.Set.t;
90 mutable available_before: Reg_availability_set.t;
91 mutable available_across: Reg_availability_set.t option;
92 }
93
94 and instruction_desc =
95 Iend
96 | Iop of operation
97 | Ireturn
98 | Iifthenelse of test * instruction * instruction
99 | Iswitch of int array * instruction array
100 | Icatch of Cmm.rec_flag * (int * instruction) list * instruction
101 | Iexit of int
102 | Itrywith of instruction * instruction
103 | Iraise of Lambda.raise_kind
104
105 type spacetime_part_of_shape =
106 | Direct_call_point of { callee : string; (* the symbol *) }
107 | Indirect_call_point
108 | Allocation_point
109
110 (** A description of the layout of a Spacetime profiling node associated with
111 a given function. Each call and allocation point instrumented within
112 the function is marked with a label in the code and assigned a place
113 within the node. This information is stored within the executable and
114 extracted when the user saves a profile. The aim is to minimise runtime
115 memory usage within the nodes and increase performance. *)
116 type spacetime_shape = (spacetime_part_of_shape * Cmm.label) list
117
118 type fundecl =
119 { fun_name: string;
120 fun_args: Reg.t array;
121 fun_body: instruction;
122 fun_codegen_options : Cmm.codegen_option list;
123 fun_dbg : Debuginfo.t;
124 fun_spacetime_shape : spacetime_shape option;
125 fun_num_stack_slots: int array;
126 fun_contains_calls: bool;
127 }
128
129 val dummy_instr: instruction
130 val end_instr: unit -> instruction
131 val instr_cons:
132 instruction_desc -> Reg.t array -> Reg.t array -> instruction ->
133 instruction
134 val instr_cons_debug:
135 instruction_desc -> Reg.t array -> Reg.t array -> Debuginfo.t ->
136 instruction -> instruction
137 val instr_iter: (instruction -> unit) -> instruction -> unit
138
139 val spacetime_node_hole_pointer_is_live_before : instruction -> bool
140
141 val operation_can_raise : operation -> bool
142