forked from ocaml-flambda/flambda-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler_hooks.ml
176 lines (166 loc) · 7.49 KB
/
compiler_hooks.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Copyright 2021 Jane Street Group LLC *)
(* *)
(* 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. *)
(* *)
(**************************************************************************)
type _ pass =
| Parse_tree_intf : Parsetree.signature pass
| Parse_tree_impl : Parsetree.structure pass
| Typed_tree_intf : Typedtree.signature pass
| Typed_tree_impl : Typedtree.implementation pass
| Raw_lambda : Lambda.program pass
| Lambda : Lambda.program pass
| Raw_flambda2 : Flambda2_terms.Flambda_unit.t pass
| Flambda2 : Flambda2_terms.Flambda_unit.t pass
| Mach_polling : Mach.fundecl pass
| Mach_combine : Mach.fundecl pass
| Mach_cse : Mach.fundecl pass
| Mach_spill : Mach.fundecl pass
| Mach_live : Mach.fundecl pass
| Mach_reload : Mach.fundecl pass
| Mach_sel : Mach.fundecl pass
| Mach_split : Mach.fundecl pass
| Linear : Linear.fundecl pass
| Cfg_combine : Cfg_with_layout.t pass
| Cfg_cse : Cfg_with_layout.t pass
| Cfg : Cfg_with_layout.t pass
| Cmm : Cmm.phrase list pass
| Inlining_tree : Flambda2_simplify_shared.Inlining_report.Inlining_tree.t pass
| Check_allocations : Zero_alloc_checker.iter_witnesses pass
type t = {
mutable parse_tree_intf : (Parsetree.signature -> unit) list;
mutable parse_tree_impl : (Parsetree.structure -> unit) list;
mutable typed_tree_intf : (Typedtree.signature -> unit) list;
mutable typed_tree_impl : (Typedtree.implementation -> unit) list;
mutable raw_lambda : (Lambda.program -> unit) list;
mutable lambda : (Lambda.program -> unit) list;
mutable raw_flambda2 : (Flambda2_terms.Flambda_unit.t -> unit) list;
mutable flambda2 : (Flambda2_terms.Flambda_unit.t -> unit) list;
mutable mach_polling : (Mach.fundecl -> unit) list;
mutable mach_combine : (Mach.fundecl -> unit) list;
mutable mach_cse : (Mach.fundecl -> unit) list;
mutable mach_spill : (Mach.fundecl -> unit) list;
mutable mach_live : (Mach.fundecl -> unit) list;
mutable mach_reload : (Mach.fundecl -> unit) list;
mutable mach_sel : (Mach.fundecl -> unit) list;
mutable mach_split : (Mach.fundecl -> unit) list;
mutable linear : (Linear.fundecl -> unit) list;
mutable cfg_combine : (Cfg_with_layout.t -> unit) list;
mutable cfg_cse : (Cfg_with_layout.t -> unit) list;
mutable cfg : (Cfg_with_layout.t -> unit) list;
mutable cmm : (Cmm.phrase list -> unit) list;
mutable inlining_tree : (Flambda2_simplify_shared.Inlining_report.Inlining_tree.t -> unit) list;
mutable check_allocations : (Zero_alloc_checker.iter_witnesses -> unit) list
}
let hooks : t = {
parse_tree_intf = [];
parse_tree_impl = [];
typed_tree_intf = [];
typed_tree_impl = [];
raw_lambda = [];
lambda = [];
raw_flambda2 = [];
flambda2 = [];
mach_polling = [];
mach_combine = [];
mach_cse = [];
mach_spill = [];
mach_live = [];
mach_reload = [];
mach_sel = [];
mach_split = [];
linear = [];
cfg_combine = [];
cfg_cse = [];
cfg = [];
cmm = [];
inlining_tree = [];
check_allocations = [];
}
let execute_hooks : type a. (a -> unit) list -> a -> unit = fun hooks arg ->
List.iter (fun f -> f arg) hooks
let register : type a. a pass -> (a -> unit) -> unit =
fun representation f ->
match representation with
| Parse_tree_intf -> hooks.parse_tree_intf <- f :: hooks.parse_tree_intf
| Parse_tree_impl -> hooks.parse_tree_impl <- f :: hooks.parse_tree_impl
| Typed_tree_intf -> hooks.typed_tree_intf <- f :: hooks.typed_tree_intf
| Typed_tree_impl -> hooks.typed_tree_impl <- f :: hooks.typed_tree_impl
| Raw_lambda -> hooks.raw_lambda <- f :: hooks.raw_lambda
| Lambda -> hooks.lambda <- f :: hooks.lambda
| Raw_flambda2 -> hooks.raw_flambda2 <- f :: hooks.raw_flambda2
| Flambda2 -> hooks.flambda2 <- f :: hooks.flambda2
| Mach_combine -> hooks.mach_combine <- f :: hooks.mach_combine
| Mach_polling -> hooks.mach_polling <- f :: hooks.mach_polling
| Mach_cse -> hooks.mach_cse <- f :: hooks.mach_cse
| Mach_spill -> hooks.mach_spill <- f :: hooks.mach_spill
| Mach_live -> hooks.mach_live <- f :: hooks.mach_live
| Mach_reload -> hooks.mach_reload <- f :: hooks.mach_reload
| Mach_sel -> hooks.mach_sel <- f :: hooks.mach_sel
| Mach_split -> hooks.mach_split <- f :: hooks.mach_split
| Linear -> hooks.linear <- f :: hooks.linear
| Cfg_combine -> hooks.cfg_combine <- f :: hooks.cfg_combine
| Cfg_cse -> hooks.cfg_cse <- f :: hooks.cfg_cse
| Cfg -> hooks.cfg <- f :: hooks.cfg
| Cmm -> hooks.cmm <- f :: hooks.cmm
| Inlining_tree -> hooks.inlining_tree <- f :: hooks.inlining_tree
| Check_allocations ->
hooks.check_allocations <- f :: hooks.check_allocations
let execute : type a. a pass -> a -> unit =
fun representation arg ->
match representation with
| Parse_tree_intf -> execute_hooks hooks.parse_tree_intf arg
| Parse_tree_impl -> execute_hooks hooks.parse_tree_impl arg
| Typed_tree_intf -> execute_hooks hooks.typed_tree_intf arg
| Typed_tree_impl -> execute_hooks hooks.typed_tree_impl arg
| Raw_lambda -> execute_hooks hooks.raw_lambda arg
| Lambda -> execute_hooks hooks.lambda arg
| Raw_flambda2 -> execute_hooks hooks.raw_flambda2 arg
| Flambda2 -> execute_hooks hooks.flambda2 arg
| Mach_polling -> execute_hooks hooks.mach_polling arg
| Mach_combine -> execute_hooks hooks.mach_combine arg
| Mach_cse -> execute_hooks hooks.mach_cse arg
| Mach_spill -> execute_hooks hooks.mach_spill arg
| Mach_live -> execute_hooks hooks.mach_live arg
| Mach_reload -> execute_hooks hooks.mach_reload arg
| Mach_sel -> execute_hooks hooks.mach_sel arg
| Mach_split -> execute_hooks hooks.mach_split arg
| Linear -> execute_hooks hooks.linear arg
| Cfg_combine -> execute_hooks hooks.cfg_combine arg
| Cfg_cse -> execute_hooks hooks.cfg_cse arg
| Cfg -> execute_hooks hooks.cfg arg
| Cmm -> execute_hooks hooks.cmm arg
| Inlining_tree -> execute_hooks hooks.inlining_tree arg
| Check_allocations -> execute_hooks hooks.check_allocations arg
let execute_and_pipe r a = execute r a; a
let clear : type a. a pass -> unit =
function
| Parse_tree_intf -> hooks.parse_tree_intf <- []
| Parse_tree_impl -> hooks.parse_tree_impl <- []
| Typed_tree_intf -> hooks.typed_tree_intf <- []
| Typed_tree_impl -> hooks.typed_tree_impl <- []
| Raw_lambda -> hooks.raw_lambda <- []
| Lambda -> hooks.lambda <- []
| Raw_flambda2 -> hooks.raw_flambda2 <- []
| Flambda2 -> hooks.flambda2 <- []
| Mach_polling -> hooks.mach_polling <- []
| Mach_combine -> hooks.mach_combine <- []
| Mach_cse -> hooks.mach_cse <- []
| Mach_spill -> hooks.mach_spill <- []
| Mach_live -> hooks.mach_live <- []
| Mach_reload -> hooks.mach_reload <- []
| Mach_sel -> hooks.mach_sel <- []
| Mach_split -> hooks.mach_split <- []
| Linear -> hooks.linear <- []
| Cfg_combine -> hooks.cfg_combine <- []
| Cfg_cse -> hooks.cfg_cse <- []
| Cfg -> hooks.cfg <- []
| Cmm -> hooks.cmm <- []
| Inlining_tree -> hooks.inlining_tree <- []
| Check_allocations -> hooks.check_allocations <- []