Skip to content

Commit b9a0593

Browse files
committed
Port #493
1 parent 0a872d9 commit b9a0593

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

asmcomp/cmm.ml

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ and operation =
167167
| Cprobe of { name: string; handler_code_sym: string; }
168168
| Cprobe_is_enabled of { name: string }
169169
| Copaque
170+
| Cbeginregion | Cendregion
170171

171172
type expression =
172173
Cconst_int of int * Debuginfo.t

asmcomp/cmm.mli

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ and operation =
165165
| Cprobe of { name: string; handler_code_sym: string; }
166166
| Cprobe_is_enabled of { name: string }
167167
| Copaque (* Sys.opaque_identity *)
168+
| Cbeginregion | Cendregion
168169

169170
(** Every basic block should have a corresponding [Debuginfo.t] for its
170171
beginning. *)

asmcomp/cmm_helpers.ml

+7-6
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ let unboxed_float_array_ref arr ofs dbg =
762762
let float_array_ref arr ofs dbg =
763763
box_float dbg Alloc_heap (unboxed_float_array_ref arr ofs dbg)
764764

765-
(* TODO support mutation of local arrays *)
766765
let addr_array_set arr ofs newval dbg =
767766
Cop(Cextcall("caml_modify", typ_void, [], false),
768767
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
@@ -773,6 +772,10 @@ let float_array_set arr ofs newval dbg =
773772
Cop(Cstore (Double, Lambda.Assignment),
774773
[array_indexing log2_size_float arr ofs dbg; newval], dbg)
775774

775+
let addr_array_set_local arr ofs newval dbg =
776+
Cop(Cextcall("caml_modify_local", typ_void, [], false),
777+
[arr; untag_int ofs dbg; newval], dbg)
778+
776779
(* String length *)
777780

778781
(* Length of string block *)
@@ -844,14 +847,14 @@ let make_alloc_generic ~mode set_fn dbg tag wordsize args =
844847
fill_fields 1 args)
845848
end
846849

847-
let make_alloc ?(mode=Lambda.Alloc_heap) dbg tag args =
850+
let make_alloc ~mode dbg tag args =
848851
let addr_array_init arr ofs newval dbg =
849852
Cop(Cextcall("caml_initialize", typ_void, [], false),
850853
[array_indexing log2_size_addr arr ofs dbg; newval], dbg)
851854
in
852855
make_alloc_generic ~mode addr_array_init dbg tag (List.length args) args
853856

854-
let make_float_alloc ?(mode=Lambda.Alloc_heap) dbg tag args =
857+
let make_float_alloc ~mode dbg tag args =
855858
make_alloc_generic ~mode float_array_set dbg tag
856859
(List.length args * size_float / size_addr) args
857860

@@ -2489,9 +2492,7 @@ let setfield_computed ptr init arg1 arg2 arg3 dbg =
24892492
| Caml_modify ->
24902493
return_unit dbg (addr_array_set arg1 arg2 arg3 dbg)
24912494
| Caml_modify_local ->
2492-
(* TODO: support this, if there are any uses.
2493-
(Currently, setfield_computed is only used by classes) *)
2494-
Misc.fatal_error "setfield_computed: local"
2495+
return_unit dbg (addr_array_set_local arg1 arg2 arg3 dbg)
24952496
| Simple ->
24962497
return_unit dbg (int_array_set arg1 arg2 arg3 dbg)
24972498

asmcomp/cmm_helpers.mli

+4-2
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ val unboxed_float_array_ref :
247247
val float_array_ref : expression -> expression -> Debuginfo.t -> expression
248248
val addr_array_set :
249249
expression -> expression -> expression -> Debuginfo.t -> expression
250+
val addr_array_set_local :
251+
expression -> expression -> expression -> Debuginfo.t -> expression
250252
val int_array_set :
251253
expression -> expression -> expression -> Debuginfo.t -> expression
252254
val float_array_set :
@@ -287,11 +289,11 @@ val call_cached_method :
287289

288290
(** Allocate a block of regular values with the given tag *)
289291
val make_alloc :
290-
?mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
292+
mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
291293

292294
(** Allocate a block of unboxed floats with the given tag *)
293295
val make_float_alloc :
294-
?mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
296+
mode:Lambda.alloc_mode -> Debuginfo.t -> int -> expression list -> expression
295297

296298
(** Bounds checking *)
297299

asmcomp/printcmm.ml

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ let operation d = function
161161
Printf.sprintf "probe[%s %s]" name handler_code_sym
162162
| Cprobe_is_enabled {name} -> Printf.sprintf "probe_is_enabled[%s]" name
163163
| Copaque -> "opaque"
164+
| Cbeginregion -> "beginregion"
165+
| Cendregion -> "endregion"
164166

165167
let rec expr ppf = function
166168
| Cconst_int (n, _dbg) -> fprintf ppf "%i" n

asmcomp/selectgen.ml

+9
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ let oper_result_type = function
109109
| Cprobe _ -> typ_void
110110
| Cprobe_is_enabled _ -> typ_int
111111
| Copaque -> typ_val
112+
| Cbeginregion ->
113+
(* This must not be typ_val; the begin-region operation returns a
114+
naked pointer into the local allocation stack. *)
115+
typ_int
116+
| Cendregion -> typ_void
112117

113118
(* Infer the size in bytes of the result of an expression whose evaluation
114119
may be deferred (cf. [emit_parts]). *)
@@ -349,6 +354,7 @@ method is_simple_expr = function
349354
| Capply _ | Cextcall _ | Calloc _ | Cstore _
350355
| Craise _ | Ccheckbound
351356
| Cprobe _ | Cprobe_is_enabled _ | Copaque -> false
357+
| Cbeginregion | Cendregion -> false (* avoid reordering *)
352358
(* The remaining operations are simple if their args are *)
353359
| Cload _ | Caddi | Csubi | Cmuli | Cmulhi | Cdivi | Cmodi | Cand | Cor
354360
| Cxor | Clsl | Clsr | Casr | Ccmpi _ | Caddv | Cadda | Ccmpa _ | Cnegf
@@ -391,6 +397,7 @@ method effects_of exp =
391397
| Calloc Alloc_heap -> EC.none
392398
| Calloc Alloc_local -> EC.coeffect_only Coeffect.Arbitrary
393399
| Cstore _ -> EC.effect_only Effect.Arbitrary
400+
| Cbeginregion | Cendregion -> EC.arbitrary
394401
| Craise _ | Ccheckbound -> EC.effect_only Effect.Raise
395402
| Cload (_, Asttypes.Immutable) -> EC.none
396403
| Cload (_, Asttypes.Mutable) -> EC.coeffect_only Coeffect.Read_mutable
@@ -519,6 +526,8 @@ method select_operation op args _dbg =
519526
| (Cprobe { name; handler_code_sym; }, _) ->
520527
Iprobe { name; handler_code_sym; }, args
521528
| (Cprobe_is_enabled {name}, _) -> Iprobe_is_enabled {name}, []
529+
| (Cbeginregion, _) -> Ibeginregion, []
530+
| (Cendregion, _) -> Iendregion, args
522531
| _ -> Misc.fatal_error "Selection.select_oper"
523532

524533
method private select_arith_comm op = function

0 commit comments

Comments
 (0)