[sledge] Remove Exp.size_of and Term.size_of

Summary:
Having `val size_of : Typ.t -> t` in the signature of `Term` and `val
size_of : t -> t` in the signature of `Exp` gives the impression that
`Term` and `Exp` know something about `Typ`. But they don't, those
functions are only trivial convenience wrappers, and only have a few
uses, so just inline them to clarify that it is `Typ` that knows about
the sizes of types.

Reviewed By: jvillard

Differential Revision: D21441535

fbshipit-source-id: 09b135a8c
master
Josh Berdine 5 years ago committed by Facebook GitHub Bot
parent 0953444c24
commit 849c61221d

@ -864,6 +864,9 @@ let rec xlate_func_name x llv =
let ignored_callees = Hash_set.create (module String) let ignored_callees = Hash_set.create (module String)
let exp_size_of exp =
Exp.integer Typ.siz (Z.of_int (Typ.size_of (Exp.typ exp)))
let xlate_instr : let xlate_instr :
pop_thunk pop_thunk
-> x -> x
@ -902,12 +905,12 @@ let xlate_instr :
match opcode with match opcode with
| Load -> | Load ->
let reg = xlate_name x instr in let reg = xlate_name x instr in
let len = Exp.size_of (Exp.reg reg) in let len = exp_size_of (Exp.reg reg) in
let ptr = xlate_value x (Llvm.operand instr 0) in let ptr = xlate_value x (Llvm.operand instr 0) in
emit_inst (Llair.Inst.load ~reg ~ptr ~len ~loc) emit_inst (Llair.Inst.load ~reg ~ptr ~len ~loc)
| Store -> | Store ->
let exp = xlate_value x (Llvm.operand instr 0) in let exp = xlate_value x (Llvm.operand instr 0) in
let len = Exp.size_of exp in let len = exp_size_of exp in
let ptr = xlate_value x (Llvm.operand instr 1) in let ptr = xlate_value x (Llvm.operand instr 1) in
emit_inst (Llair.Inst.store ~ptr ~exp ~len ~loc) emit_inst (Llair.Inst.store ~ptr ~exp ~len ~loc)
| Alloca -> | Alloca ->
@ -919,7 +922,7 @@ let xlate_instr :
(xlate_value x rand) (xlate_value x rand)
in in
assert (Poly.(Llvm.classify_type (Llvm.type_of instr) = Pointer)) ; assert (Poly.(Llvm.classify_type (Llvm.type_of instr) = Pointer)) ;
let len = Exp.size_of (Exp.reg reg) in let len = exp_size_of (Exp.reg reg) in
emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc) emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)
| Call -> ( | Call -> (
let maybe_llfunc = Llvm.operand instr (Llvm.num_operands instr - 1) in let maybe_llfunc = Llvm.operand instr (Llvm.num_operands instr - 1) in
@ -970,7 +973,7 @@ let xlate_instr :
(* operator new(unsigned long, std::align_val_t) *) ] -> (* operator new(unsigned long, std::align_val_t) *) ] ->
let reg = xlate_name x instr in let reg = xlate_name x instr in
let num = xlate_value x (Llvm.operand instr 0) in let num = xlate_value x (Llvm.operand instr 0) in
let len = Exp.size_of (Exp.reg reg) in let len = exp_size_of (Exp.reg reg) in
emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc) emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)
| ["_ZdlPv" (* operator delete(void* ptr) *)] | ["_ZdlPv" (* operator delete(void* ptr) *)]
|[ "_ZdlPvSt11align_val_t" |[ "_ZdlPvSt11align_val_t"
@ -1086,7 +1089,7 @@ let xlate_instr :
when num_actuals > 0 -> when num_actuals > 0 ->
let reg = xlate_name x instr in let reg = xlate_name x instr in
let num = xlate_value x (Llvm.operand instr 0) in let num = xlate_value x (Llvm.operand instr 0) in
let len = Exp.size_of (Exp.reg reg) in let len = exp_size_of (Exp.reg reg) in
let dst, blocks = xlate_jump x instr return_blk loc [] in let dst, blocks = xlate_jump x instr return_blk loc [] in
emit_term emit_term
~prefix:[Llair.Inst.alloc ~reg ~num ~len ~loc] ~prefix:[Llair.Inst.alloc ~reg ~num ~len ~loc]

@ -20,7 +20,7 @@ let init globals =
IArray.fold globals ~init:Sh.emp ~f:(fun q -> function IArray.fold globals ~init:Sh.emp ~f:(fun q -> function
| {Global.reg; init= Some arr} -> | {Global.reg; init= Some arr} ->
let loc = Term.var (Reg.var reg) in let loc = Term.var (Reg.var reg) in
let len = Term.size_of (Exp.typ arr) in let len = Term.integer (Z.of_int (Typ.size_of (Exp.typ arr))) in
let arr = arr.term in let arr = arr.term in
Sh.star q (Sh.seg {loc; bas= loc; len; siz= len; arr}) Sh.star q (Sh.seg {loc; bas= loc; len; siz= len; arr})
| _ -> q ) | _ -> q )

@ -315,7 +315,7 @@ let calloc_spec us reg num len =
let post = Sh.or_ (null_eq (Term.var reg)) (Sh.seg seg) in let post = Sh.or_ (null_eq (Term.var reg)) (Sh.seg seg) in
{xs; foot; sub; ms; post} {xs; foot; sub; ms; post}
let size_of_ptr = Term.size_of Typ.ptr let size_of_ptr = Term.integer (Z.of_int (Typ.size_of Typ.ptr))
(* { p-[_;_)->⟨W,_⟩ } (* { p-[_;_)->⟨W,_⟩ }
* posix_memalign r p s * posix_memalign r p s
@ -487,7 +487,8 @@ let nallocx_spec us reg siz =
let post = Sh.or_ (null_eq loc) (Sh.pure (Term.eq loc siz)) in let post = Sh.or_ (null_eq loc) (Sh.pure (Term.eq loc siz)) in
{xs; foot; sub; ms; post} {xs; foot; sub; ms; post}
let size_of_int_mul = Term.mul (Term.size_of Typ.siz) let size_of_int_mul =
Term.mul (Term.integer (Z.of_int (Typ.size_of Typ.siz)))
(* { r-[_;_)->⟨m,_⟩ * i-[_;_)->⟨_,m⟩ * w=0 * n=0 } (* { r-[_;_)->⟨m,_⟩ * i-[_;_)->⟨_,m⟩ * w=0 * n=0 }
* mallctl r i w n * mallctl r i w n

@ -497,8 +497,6 @@ let struct_rec key =
forcing the recursive thunks also updates this value. *) forcing the recursive thunks also updates this value. *)
{desc= ApN (Struct_rec, typ, elts); term= rec_app ~id IArray.empty} {desc= ApN (Struct_rec, typ, elts); term= rec_app ~id IArray.empty}
let size_of exp = integer Typ.siz (Z.of_int (Typ.size_of (typ exp)))
(** Traverse *) (** Traverse *)
let fold_exps e ~init ~f = let fold_exps e ~init ~f =

@ -200,8 +200,6 @@ val struct_rec :
one point on each cycle. Failure to obey these requirements will lead to one point on each cycle. Failure to obey these requirements will lead to
stack overflow. *) stack overflow. *)
val size_of : t -> t
(** Traverse *) (** Traverse *)
val fold_regs : t -> init:'a -> f:('a -> Reg.t -> 'a) -> 'a val fold_regs : t -> init:'a -> f:('a -> Reg.t -> 'a) -> 'a

@ -1124,7 +1124,6 @@ let concat xs = normN Concat (IArray.of_array xs)
let record elts = normN Record elts let record elts = normN Record elts
let select ~rcd ~idx = norm1 (Select idx) rcd let select ~rcd ~idx = norm1 (Select idx) rcd
let update ~rcd ~idx ~elt = norm2 (Update idx) rcd elt let update ~rcd ~idx ~elt = norm2 (Update idx) rcd elt
let size_of t = integer (Z.of_int (Typ.size_of t))
let eq_concat (siz, arr) ms = let eq_concat (siz, arr) ms =
eq (memory ~siz ~arr) eq (memory ~siz ~arr)

@ -248,8 +248,6 @@ val rec_app :
(module Hashtbl.Key_plain with type t = 'id) (module Hashtbl.Key_plain with type t = 'id)
-> (id:'id -> recN -> t lazy_t iarray -> t) Staged.t -> (id:'id -> recN -> t lazy_t iarray -> t) Staged.t
val size_of : Typ.t -> t
(** Transform *) (** Transform *)
val map : t -> f:(t -> t) -> t val map : t -> f:(t -> t) -> t

Loading…
Cancel
Save