From 9bbe9dbba14d4b598438a8b11c8138fc4b9f0911 Mon Sep 17 00:00:00 2001
From: Josh Berdine <jjb@fb.com>
Date: Sun, 7 Jun 2020 04:59:20 -0700
Subject: [PATCH] [sledge] Change: Rely on llvm size_of instead of Typ.size_of
 from llair

Summary:
Rather than translate an llvm type to a llair one and then compute the
size of the llair type, obtain the size of the llvm type directly.

Reviewed By: ngorogiannis

Differential Revision: D21720968

fbshipit-source-id: ad98112a7
---
 sledge/bin/frontend.ml | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/sledge/bin/frontend.ml b/sledge/bin/frontend.ml
index c6e74cb2f..339ff8b0b 100644
--- a/sledge/bin/frontend.ml
+++ b/sledge/bin/frontend.ml
@@ -847,8 +847,8 @@ let rec xlate_func_name x llv =
 
 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_size_of x llv =
+  Exp.integer Typ.siz (Z.of_int (size_of x (Llvm.type_of llv)))
 
 let xlate_instr :
        pop_thunk
@@ -888,12 +888,13 @@ let xlate_instr :
   match opcode with
   | Load ->
       let reg = xlate_name x instr in
-      let len = exp_size_of (Exp.reg reg) in
+      let len = xlate_size_of x instr in
       let ptr = xlate_value x (Llvm.operand instr 0) in
       emit_inst (Llair.Inst.load ~reg ~ptr ~len ~loc)
   | Store ->
-      let exp = xlate_value x (Llvm.operand instr 0) in
-      let len = exp_size_of exp in
+      let rand0 = Llvm.operand instr 0 in
+      let exp = xlate_value x rand0 in
+      let len = xlate_size_of x rand0 in
       let ptr = xlate_value x (Llvm.operand instr 1) in
       emit_inst (Llair.Inst.store ~ptr ~exp ~len ~loc)
   | Alloca ->
@@ -905,7 +906,7 @@ let xlate_instr :
           (xlate_value x rand)
       in
       assert (Poly.(Llvm.classify_type (Llvm.type_of instr) = Pointer)) ;
-      let len = exp_size_of (Exp.reg reg) in
+      let len = xlate_size_of x instr in
       emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)
   | Call -> (
       let maybe_llfunc = Llvm.operand instr (Llvm.num_operands instr - 1) in
@@ -956,7 +957,7 @@ let xlate_instr :
             (* operator new(unsigned long, std::align_val_t) *) ] ->
             let reg = xlate_name x instr in
             let num = xlate_value x (Llvm.operand instr 0) in
-            let len = exp_size_of (Exp.reg reg) in
+            let len = xlate_size_of x instr in
             emit_inst (Llair.Inst.alloc ~reg ~num ~len ~loc)
         | ["_ZdlPv" (* operator delete(void* ptr) *)]
          |[ "_ZdlPvSt11align_val_t"
@@ -1072,7 +1073,7 @@ let xlate_instr :
         when num_actuals > 0 ->
           let reg = xlate_name x instr in
           let num = xlate_value x (Llvm.operand instr 0) in
-          let len = exp_size_of (Exp.reg reg) in
+          let len = xlate_size_of x instr in
           let dst, blocks = xlate_jump x instr return_blk loc [] in
           emit_term
             ~prefix:[Llair.Inst.alloc ~reg ~num ~len ~loc]