Skip to content

Commit f29a884

Browse files
authored
Rename Un_cps -> To_cmm (#261)
1 parent d1eadd8 commit f29a884

23 files changed

+76
-81
lines changed

driver/flambda_backend_main.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let () =
66
| Native -> Memtrace.trace_if_requested ~context:"ocamlopt" ()
77
| Bytecode | Other _ -> ());
88
exit (Optmaindriver.main Sys.argv Format.err_formatter
9-
~flambda2_backend ~flambda2_to_cmm:Flambda2_to_cmm.Un_cps.unit)
9+
~flambda2_backend ~flambda2_to_cmm:Flambda2_to_cmm.To_cmm.unit)

middle_end/flambda2/cmx/exported_offsets.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
(** Offsets for closures and environment variables inside sets of closures.
1818
They're computed for elements defined in the current compilation unit by
19-
[Un_cps_closure], and read from cmx files for external symbols. Because an
19+
[To_cmm_closure], and read from cmx files for external symbols. Because an
2020
external cmx can reference elements from another cmx that the current
2121
compilation cannot see, all offsets read from external cmx files must be
2222
re-exported. *)

middle_end/flambda2/cmx/flambda_cmx.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ let prepare_cmx_file_contents ~return_cont_env:cont_uses_env
124124
in
125125
let exported_offsets =
126126
(* The offsets computations for newly defined elements will be added after
127-
Un_cps_closure *)
127+
To_cmm_closure *)
128128
Exported_offsets.imported_offsets ()
129129
in
130130
Some

middle_end/flambda2/docs/to_cmm.md

+21-26
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ existing translation from clambda to cmm. However, that gave very little control
77
to flambda in terms of unboxing, since most optimizations relating to unboxing
88
happens during the clambda to cmm translation.
99

10-
The translation from flambda2 to cmm is currently named `un_cps` for historical
11-
reasons (because it `un`does the `cps` form of flambda2), but it is expected to
12-
change toward a less obscure name at one point.
13-
14-
1510
## Overview
1611

1712
See [this file](term_language.md) for a description of the flamdba2 language,
1813
and [the cmm doc](cmm.md) for an overview of the cmm language.
1914

20-
This section provides an overview of the main tasks of the `un_cps`
15+
This section provides an overview of the main tasks of the `to_cmm`
2116
translation. First these "tasks" are listed, and then are explained in details,
2217
together with their motivations and requirements. The technical aspect of how
2318
these tasks are implemented will be discussed in the following section).
@@ -70,7 +65,7 @@ and lower these operations are explicit, e.g.:
7065

7166
One good point compared to cmmgen is that we can assume that the flambda
7267
simplifier will already have unboxed things that can be unboxed, so contrary to
73-
`cmmgen`, `un_cps` does not need to do the work of trying to find unboxing
68+
`cmmgen`, `to_cmm` does not need to do the work of trying to find unboxing
7469
optimizations.
7570

7671
#### "Big" and "small" values
@@ -93,7 +88,7 @@ ocaml values across functions.
9388

9489
"small" values are values which are strictly smaller than register, and whose
9590
semantics usually need this smaller value space; typically, these are 32-bit
96-
integers on 64-bit platforms. For these values, `un_cps` need to choose one
91+
integers on 64-bit platforms. For these values, `to_cmm` need to choose one
9792
encoding into 64-bits registers, and translate the abstract operations from
9893
flambda2 on these types to concrete operations on registers in a way that
9994
preserve the expected semantics.
@@ -132,7 +127,7 @@ compared to generating A-normal forms; some of these reasons are:
132127
Conversely, when this is not the case, the compiler pipeline will
133128
automatically add a (= 0) comparison, resulting in a few more instructions.
134129

135-
Thus `un_cps` does the following:
130+
Thus `to_cmm` does the following:
136131
- remove pure and co-effectful-only expressions which are never used
137132
- substitute pure and co-effectful-only expressions which are used exactly once
138133
- if the option is set, substitute effectful expressions which are used exactly once
@@ -178,7 +173,7 @@ not inline sets of closures across modules anymore, and thus all sharing are
178173
restricted to the current module, there should not be any instance where
179174
the offset computation can fail.
180175

181-
Currently, `un_cps` implements a greedy algorithm for filling out sets of
176+
Currently, `to_cmm` implements a greedy algorithm for filling out sets of
182177
closures and assign offsets. It iterates over closures, assigning the lowest
183178
offset that is free in all sets of closures where it appears, and then does the
184179
same for all env vars. While not optimal as it may leave gaps, this should
@@ -198,24 +193,24 @@ flambda2.
198193

199194
### Organization of the code and main control flow of the translation
200195

201-
`un_cps` translate flambda2 expressions using two traversals of an flambda2
196+
`to_cmm` translate flambda2 expressions using two traversals of an flambda2
202197
body.
203198

204199
The first traversal iterates over all sets of closures defined by the body.
205200
This allows to assign offsets to all members of sets of closures (taking into
206201
account constraints due to a potential sharing of closures of env vars beetween
207-
sets of closures), using the code in `un_cps_closure.ml`.
202+
sets of closures), using the code in `to_cmm_closure.ml`.
208203

209-
After that, `un_cps` operates the second, and main traversal of the
204+
After that, `to_cmm` operates the second, and main traversal of the
210205
expression, accumulating information (about continuations, substitutions, etc)
211-
in an environment (defined in `un_cps_env.ml`), and then returning two
206+
in an environment (defined in `to_cmm_env.ml`), and then returning two
212207
values: the resulting cmm expression, and a static result that contains all
213208
the constants that should be pre-allocated (in comparison, `cmmgen` uses a global
214209
reference to store that information during translation). This static result
215-
(defined in `un_cps_result.ml`) will be grown by the translation, by either
210+
(defined in `to_cmm_result.ml`) will be grown by the translation, by either
216211
`let_symbol` bindings or sets of closures bindings. Translations of flambda2
217212
expression that can result in pre-allocation of static constants go through
218-
the `un_cps_static.ml` file.
213+
the `to_cmm_static.ml` file.
219214

220215
### Tagging and unboxing
221216

@@ -225,7 +220,7 @@ of values, e.g. boxed integers are identified with their size, tagged integers
225220
are differentiated from untagged integers, ... . Together with information
226221
about what the cmm primitives expect (i.e. which primitive expect or return
227222
a tagged integer, and which deal with untagged integers), this offers a
228-
rather comprehensive way for `un_cps` to know when or where to tag/untag
223+
rather comprehensive way for `to_cmm` to know when or where to tag/untag
229224
things. See the following for more details:
230225
- `middle_end/flambda/terms/flambda_primitive.ml` for the data about kinds
231226
consumed/returned by flambda primitives (particularly the
@@ -234,11 +229,11 @@ things. See the following for more details:
234229
(this is still a TODO)
235230

236231
Unboxing is also straightforward: as mentioned earlier, flambda2 already
237-
takes care of identifying and applying all the unboxing we want, so `un_cps`
232+
takes care of identifying and applying all the unboxing we want, so `to_cmm`
238233
only introduces the boxing and unboxing as needed, using the same information
239234
as for tagging/untagging.
240235

241-
For the concrete implementation, `un_cps` mostly re-uses code from
236+
For the concrete implementation, `to_cmm` mostly re-uses code from
242237
`cmm_helpers`.
243238

244239
### "Big" and "small" values
@@ -254,13 +249,13 @@ bits and its higher bits, and then carried on two registers. Handling these
254249
is relatively straightforward since the low-level operations are already
255250
written in `cmm_helpers`.
256251

257-
A difference between `cmmgen` and `un_cps` is that flambda2 has explicit
252+
A difference between `cmmgen` and `to_cmm` is that flambda2 has explicit
258253
box/unbox operations on these, and as such, where `cmmgen` is in control of the
259254
boxing and thus most of the time generate calls to function that handle the
260-
boxed version of Int64s, `un_cps` actually has to mostly deal with unboxed
255+
boxed version of Int64s, `to_cmm` actually has to mostly deal with unboxed
261256
Int64, and generate calls that handle the unboxed variant.
262257

263-
Currently, there may be some cases in `un_cps` that will raise a fatal error
258+
Currently, there may be some cases in `to_cmm` that will raise a fatal error
264259
because there was not yet an unboxed version of the required function in the
265260
runtime.
266261

@@ -298,8 +293,8 @@ a trap mechanism to mirror that of flambda2.
298293

299294
### Let-binding substitution
300295

301-
This is the most complex part of `un_cps` and also the part most sensitive
302-
to changes (even innocuous changes in `un_cps` might break becasue of this).
296+
This is the most complex part of `to_cmm` and also the part most sensitive
297+
to changes (even innocuous changes in `to_cmm` might break becasue of this).
303298
The goal is to substitute let-bound variable's bodies during translation, because
304299
it allows for more optimizations. There are two technical challenges
305300
with this:
@@ -309,7 +304,7 @@ with this:
309304
continuations, in which case the expression might be evaluated more than once).
310305

311306
Most of the code to deal with this is in the definition of the translation
312-
environment in `un_cps_env`: the environment accumulates all let-bindings
307+
environment in `to_cmm_env`: the environment accumulates all let-bindings
313308
(whether that can be substituted or not), since we have to be able to
314309
substitute through a non-substitutable binding. A nice consequence of that is
315310
that translating a let-binding can then be tail-rec, which is very useful.
@@ -322,7 +317,7 @@ Let-bindings are stored in the environment in a few structures:
322317
or a single effectful binding.
323318
These two structures are used to store enough information to perform substitution
324319
if needed. Additionally, another map is used to relate all flambda2 variables to
325-
corresponding cmm variables. This mapping is used when `un_cps` decides not to
320+
corresponding cmm variables. This mapping is used when `to_cmm` decides not to
326321
substitute a variable's body.
327322

328323
When a let-bound variable has to be translated, a special env lookup is used,

middle_end/flambda2/from_lambda/closure_conversion.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ let close_c_call acc ~let_bound_var
219219
let prim_name =
220220
if String.equal prim_native_name "" then prim_name else prim_native_name
221221
in
222-
(* CR mshinwell: fix "extern" mess (see Un_cps) *)
222+
(* CR mshinwell: fix "extern" mess (see To_cmm) *)
223223
Symbol.create
224224
(Compilation_unit.external_symbols ())
225225
(Linkage_name.create prim_name)

middle_end/flambda2/simplify/expr_builder.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ let create_let_symbols uacc lifted_constant ~body =
419419
symbol" that we've just created, we'll always end up here, avoiding
420420
any problem about where to do the projection versus the
421421
initialisation of a possibly-recursive group of symbols. We may end
422-
up with a "variable = variable" [Let] here, but [Un_cps] (or a
422+
up with a "variable = variable" [Let] here, but [To_cmm] (or a
423423
subsequent pass of [Simplify]) will remove it. This is the same
424424
situation as when continuations are inlined; we can't use a name
425425
permutation to resolve the problem as both [var] and [var'] may

middle_end/flambda2/simplify/simplify_apply_cont_expr.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let inline_linearly_used_continuation uacc ~create_apply_cont ~params ~handler
3030
isn't the correct accumulator and environment any more. However there's
3131
no need to simplify the inlined body except to make use of
3232
parameter-to-argument bindings; we just leave them for a subsequent round
33-
of [Simplify] or [Un_cps] to clean up. *)
33+
of [Simplify] or [To_cmm] to clean up. *)
3434
let args = AC.args apply_cont in
3535
if List.compare_lengths params args <> 0
3636
then

middle_end/flambda2/simplify/simplify_expr.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let rec simplify_expr dacc expr ~down_to_up =
3939
Simplify_switch_expr.simplify_switch ~simplify_let dacc switch ~down_to_up
4040
| Invalid _ ->
4141
(* CR mshinwell: Make sure that a program can be simplified to just
42-
[Invalid]. [Un_cps] should translate any [Invalid] that it sees as if it
42+
[Invalid]. [To_cmm] should translate any [Invalid] that it sees as if it
4343
were [Halt_and_catch_fire]. *)
4444
down_to_up dacc ~rebuild:EB.rebuild_invalid
4545

middle_end/flambda2/terms/flambda_primitive.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ let reading_from_an_array (array_kind : Array_kind.t)
302302
match array_kind with
303303
| Immediates | Values | Naked_floats -> No_effects
304304
| Float_array_opt_dynamic ->
305-
(* See [Un_cps_helpers.array_load] and [Cmm_helpers.float_array_ref]. If
305+
(* See [To_cmm_helpers.array_load] and [Cmm_helpers.float_array_ref]. If
306306
the array (dynamically) has tag [Double_array_tag], then the read will
307307
allocate. [Immutable] here means that the returned float itself is
308308
immutable. *)

middle_end/flambda2/to_cmm/un_cps.ml renamed to middle_end/flambda2/to_cmm/to_cmm.ml

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
[@@@ocaml.warning "+a-4-30-40-41-42"]
1616

1717
open! Flambda.Import
18-
module Env = Un_cps_env
18+
module Env = To_cmm_env
1919
module Ece = Effects_and_coeffects
20-
module R = Un_cps_result
20+
module R = To_cmm_result
2121

2222
(* Notes:
2323
@@ -32,7 +32,7 @@ module R = Un_cps_result
3232
(* Cmm helpers *)
3333
module C = struct
3434
include Cmm_helpers
35-
include Un_cps_helper
35+
include To_cmm_helper
3636
end
3737

3838
(* Shortcuts for useful cmm machtypes *)
@@ -397,7 +397,7 @@ let binary_float_comp_primitive_yielding_int _env dbg x y =
397397

398398
let nullary_primitive _env dbg prim : _ * Cmm.expression =
399399
match (prim : Flambda_primitive.nullary_primitive) with
400-
| Optimised_out _ -> Misc.fatal_errorf "TODO: phantom let-bindings in un_cps"
400+
| Optimised_out _ -> Misc.fatal_errorf "TODO: phantom let-bindings in to_cmm"
401401
| Probe_is_enabled { name } -> None, Cop (Cprobe_is_enabled { name }, [], dbg)
402402

403403
let unary_primitive env dbg f arg =
@@ -452,7 +452,7 @@ let unary_primitive env dbg f arg =
452452
| Some _, None | None, Some _ | None, None ->
453453
(* Note that if a closure var is missing from a set of closures
454454
environment, then [Env.closure_offset] might return [None], even though
455-
the set of closures has been seen by [Un_cps_closure]. *)
455+
the set of closures has been seen by [To_cmm_closure]. *)
456456
None, C.unreachable)
457457

458458
let binary_primitive env dbg f x y =
@@ -715,7 +715,7 @@ and let_symbol env res bound_symbols consts body =
715715
Env.add_to_scope env (Bound_symbols.everything_being_defined bound_symbols)
716716
in
717717
let env, res, update_opt =
718-
Un_cps_static.static_consts env res ~params_and_body bound_symbols consts
718+
To_cmm_static.static_consts env res ~params_and_body bound_symbols consts
719719
in
720720
match update_opt with
721721
| None ->
@@ -730,7 +730,7 @@ and let_set_of_closures env res body closure_vars
730730
let fun_decls = Set_of_closures.function_decls s in
731731
let decls = Function_declarations.funs_in_order fun_decls in
732732
let elts =
733-
Un_cps_closure.filter_closure_vars s
733+
To_cmm_closure.filter_closure_vars s
734734
~used_closure_vars:(Env.used_closure_vars env)
735735
in
736736
if Var_within_closure.Map.is_empty elts
@@ -967,7 +967,7 @@ and apply_call env e =
967967
if not (check_arity param_arity args)
968968
then
969969
Misc.fatal_errorf
970-
"Un_cps expects indirect_known_arity calls to be full applications in \
970+
"To_cmm expects indirect_known_arity calls to be full applications in \
971971
order to translate it"
972972
else
973973
let f, env, _ = simple env f in
@@ -1328,7 +1328,7 @@ and let_static_set_of_closures env res body closure_vars s =
13281328
in
13291329
(* Statically allocate the set of closures *)
13301330
let env, static_data, updates =
1331-
Un_cps_static.static_set_of_closures env closure_symbols s None
1331+
To_cmm_static.static_set_of_closures env closure_symbols s None
13321332
in
13331333
(* As there is no env vars for the set of closures, there must be no
13341334
updates *)
@@ -1341,7 +1341,7 @@ and let_static_set_of_closures env res body closure_vars s =
13411341
(* update the result with the new static data *)
13421342
let res = R.archive_data (R.set_data res static_data) in
13431343
(* Bind the variables to the symbols for closure ids. CR gbury: inline the
1344-
variables (require to extend un_cps_enc to inline pure variables more than
1344+
variables (require to extend to_cmm_enc to inline pure variables more than
13451345
once). *)
13461346
let env =
13471347
List.fold_left2
@@ -1410,7 +1410,7 @@ and fill_layout decls startenv elts env effs acc i = function
14101410
fill_layout decls startenv elts env effs acc offset r
14111411

14121412
and fill_slot decls startenv elts env acc offset slot =
1413-
match (slot : Un_cps_closure.layout_slot) with
1413+
match (slot : To_cmm_closure.layout_slot) with
14141414
| Infix_header ->
14151415
let field = C.alloc_infix_header (offset + 1) Debuginfo.none in
14161416
field :: acc, offset + 1, env, Ece.pure
@@ -1444,7 +1444,7 @@ and fill_slot decls startenv elts env acc offset slot =
14441444
acc, offset + 3, env, Ece.pure
14451445

14461446
and fill_up_to j acc i =
1447-
if i > j then Misc.fatal_errorf "Problem while filling up a closure in un_cps";
1447+
if i > j then Misc.fatal_errorf "Problem while filling up a closure in to_cmm";
14481448
if i = j then acc else fill_up_to j (C.int 1 :: acc) (i + 1)
14491449

14501450
(* Translate a function declaration. *)
@@ -1504,7 +1504,7 @@ let unit (middle_end_result : Flambda_middle_end.middle_end_result) =
15041504
let functions_info = middle_end_result.all_code in
15051505
Profile.record_call "flambda_to_cmm" (fun () ->
15061506
let offsets =
1507-
Un_cps_closure.compute_offsets offsets functions_info unit
1507+
To_cmm_closure.compute_offsets offsets functions_info unit
15081508
in
15091509
begin
15101510
match middle_end_result.cmx with

middle_end/flambda2/to_cmm/un_cps_env.ml renamed to middle_end/flambda2/to_cmm/to_cmm_env.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ let gen_variable v =
207207

208208
let add_variable env v v' =
209209
let v'' = Backend_var.With_provenance.var v' in
210-
let vars = Variable.Map.add v (Un_cps_helper.var v'') env.vars in
210+
let vars = Variable.Map.add v (To_cmm_helper.var v'') env.vars in
211211
{ env with vars }
212212

213213
let create_variable env v =
@@ -245,7 +245,7 @@ let get_jump_id env k =
245245
let get_k env k =
246246
match Continuation.Map.find k env.conts with
247247
| exception Not_found ->
248-
Misc.fatal_errorf "Could not find continuation %a in env during un_cps"
248+
Misc.fatal_errorf "Could not find continuation %a in env during to_cmm"
249249
Continuation.print k
250250
| res -> res
251251

@@ -300,7 +300,7 @@ let env_var_offset env env_var =
300300
Exported_offsets.env_var_offset env.offsets env_var
301301

302302
let layout env closures env_vars =
303-
Un_cps_closure.layout env.offsets closures env_vars
303+
To_cmm_closure.layout env.offsets closures env_vars
304304

305305
(* Printing
306306
@@ -321,7 +321,7 @@ let next_order =
321321

322322
let classify effs =
323323
match (effs : Effects_and_coeffects.t) with
324-
(* For the purpose of un_cps, generative effects, i.e. allocations, will be
324+
(* For the purpose of to_cmm, generative effects, i.e. allocations, will be
325325
considered to have effects because the mutable state of the gc that
326326
allocations actually effect can be observed by coeffects performed by
327327
function calls (particularly coming from the Gc module). *)
@@ -341,7 +341,7 @@ let mk_binding ?extra env inline effs var cmm_expr =
341341
let cmm_var = gen_variable var in
342342
let b = { order; inline; effs; cmm_var; cmm_expr } in
343343
let v = Backend_var.With_provenance.var cmm_var in
344-
let e = Un_cps_helper.var v in
344+
let e = To_cmm_helper.var v in
345345
let env = { env with vars = Variable.Map.add var e env.vars } in
346346
let env =
347347
match extra with
@@ -377,7 +377,7 @@ let inline_res env b = b.cmm_expr, env, b.effs
377377

378378
let inline_not env b =
379379
let v' = Backend_var.With_provenance.var b.cmm_var in
380-
Un_cps_helper.var v', env, Effects_and_coeffects.pure
380+
To_cmm_helper.var v', env, Effects_and_coeffects.pure
381381

382382
let inline_not_found env v =
383383
match Variable.Map.find v env.vars with
@@ -453,7 +453,7 @@ let flush_delayed_lets env =
453453
order_map stages
454454
in
455455
M.fold
456-
(fun _ b acc -> Un_cps_helper.letin b.cmm_var b.cmm_expr acc)
456+
(fun _ b acc -> To_cmm_helper.letin b.cmm_var b.cmm_expr acc)
457457
order_map e
458458
in
459459
let wrap e = wrap_aux env.pures env.stages e in

0 commit comments

Comments
 (0)