Skip to content

Commit

Permalink
fexpr: Add %begin_region and %end_region, tests6.ml (ocaml-flambd…
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemaurer authored Mar 7, 2023
1 parent 4e1ffbf commit e2711ac
Show file tree
Hide file tree
Showing 18 changed files with 1,664 additions and 1,324 deletions.
4 changes: 4 additions & 0 deletions middle_end/flambda2/compare/compare.ml
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ let unary_prim_ops env (prim_op1 : Flambda_primitive.unary_primitive)

let primitives env prim1 prim2 : Flambda_primitive.t Comparison.t =
match (prim1 : Flambda_primitive.t), (prim2 : Flambda_primitive.t) with
| Nullary prim_op1, Nullary prim_op2 ->
if Flambda_primitive.equal_nullary_primitive prim_op1 prim_op2
then Equivalent
else Different { approximant = prim1 }
| Unary (prim_op1, arg1), Unary (prim_op2, arg2) ->
pairs ~f1:unary_prim_ops ~f2:simple_exprs ~subst2:subst_simple env
(prim_op1, arg1) (prim_op2, arg2)
Expand Down
4 changes: 4 additions & 0 deletions middle_end/flambda2/parser/fexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,12 @@ type signed_or_unsigned = Flambda_primitive.signed_or_unsigned =
| Signed
| Unsigned

type nullop = Begin_region

type unop =
| Array_length
| Box_number of box_kind
| End_region
| Get_tag
| Is_flat_float_array
| Is_int
Expand Down Expand Up @@ -312,6 +315,7 @@ type ternop = Array_set of array_kind * init_or_assign
type varop = Make_block of tag_scannable * mutability

type prim =
| Nullary of nullop
| Unary of unop * simple
| Binary of binop * simple * simple
| Ternary of ternop * simple * simple * simple
Expand Down
8 changes: 7 additions & 1 deletion middle_end/flambda2/parser/fexpr_to_flambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,17 @@ let or_variable f env (ov : _ Fexpr.or_variable) : _ Or_variable.t =
| Const c -> Const (f c)
| Var v -> Var (find_var env v, Debuginfo.none)

let nullop (nullop : Fexpr.nullop) : Flambda_primitive.nullary_primitive =
match nullop with Begin_region -> Begin_region

let unop env (unop : Fexpr.unop) : Flambda_primitive.unary_primitive =
match unop with
| Array_length -> Array_length
| Box_number bk -> Box_number (bk, Alloc_mode.For_allocations.heap)
| Unbox_number bk -> Unbox_number bk
| Tag_immediate -> Tag_immediate
| Untag_immediate -> Untag_immediate
| End_region -> End_region
| Get_tag -> Get_tag
| Is_flat_float_array -> Is_flat_float_array
| Is_int -> Is_int { variant_only = true } (* CR vlaviron: discuss *)
Expand Down Expand Up @@ -436,6 +440,7 @@ let varop (varop : Fexpr.varop) n : Flambda_primitive.variadic_primitive =

let prim env (p : Fexpr.prim) : Flambda_primitive.t =
match p with
| Nullary op -> Nullary (nullop op)
| Unary (op, arg) -> Unary (unop env op, simple env arg)
| Binary (op, a1, a2) -> Binary (binop op, simple env a1, simple env a2)
| Ternary (op, a1, a2, a3) ->
Expand Down Expand Up @@ -977,7 +982,8 @@ let bind_all_code_ids env (unit : Fexpr.flambda_unit) =
env bindings
in
go env body
| Let _ | Let_cont _ | Apply _ | Apply_cont _ | Switch _ | Invalid _ -> env
| Let { body; _ } | Let_cont { body; _ } -> go env body
| Apply _ | Apply_cont _ | Switch _ | Invalid _ -> env
in
go env unit.body

Expand Down
Loading

0 comments on commit e2711ac

Please sign in to comment.