]> git.lizzy.rs Git - rust.git/commitdiff
Use StructGEP instead of GEPi where appropriate
authorBjörn Steinbrink <bsteinbr@gmail.com>
Mon, 24 Aug 2015 20:51:57 +0000 (22:51 +0200)
committerBjörn Steinbrink <bsteinbr@gmail.com>
Mon, 24 Aug 2015 21:39:56 +0000 (23:39 +0200)
StructGEP seems clearer and probably does an even better job of the
micro-optimization that we have in GEPi.

src/librustc_trans/trans/adt.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/closure.rs
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/tvec.rs

index 0d34cce919a64993b5208924be3b5366f80be141..46211e6bd01ae0d4e40fda8f51130f115a8a56ad 100644 (file)
@@ -892,7 +892,7 @@ pub fn trans_get_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
     let val = match *r {
         CEnum(ity, min, max) => load_discr(bcx, ity, scrutinee, min, max),
         General(ity, ref cases, _) => {
-            let ptr = GEPi(bcx, scrutinee, &[0, 0]);
+            let ptr = StructGEP(bcx, scrutinee, 0);
             load_discr(bcx, ity, ptr, 0, (cases.len() - 1) as Disr)
         }
         Univariant(..) => C_u8(bcx.ccx(), 0),
@@ -986,13 +986,13 @@ pub fn trans_set_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
                 Store(bcx, C_u8(bcx.ccx(), DTOR_NEEDED), ptr);
             }
             Store(bcx, C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true),
-                  GEPi(bcx, val, &[0, 0]));
+                  StructGEP(bcx, val, 0));
         }
         Univariant(ref st, dtor) => {
             assert_eq!(discr, 0);
             if dtor_active(dtor) {
                 Store(bcx, C_u8(bcx.ccx(), DTOR_NEEDED),
-                    GEPi(bcx, val, &[0, st.fields.len() - 1]));
+                      StructGEP(bcx, val, st.fields.len() - 1));
             }
         }
         RawNullablePointer { nndiscr, nnty, ..} => {
@@ -1091,7 +1091,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
         val
     };
 
-    GEPi(bcx, val, &[0, ix])
+    StructGEP(bcx, val, ix)
 }
 
 pub fn fold_variants<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
@@ -1162,7 +1162,7 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
     let ptr_ty = bcx.tcx().mk_imm_ptr(tcx.dtor_type());
     match *r {
         Univariant(ref st, dtor) if dtor_active(dtor) => {
-            let flag_ptr = GEPi(bcx, val, &[0, st.fields.len() - 1]);
+            let flag_ptr = StructGEP(bcx, val, st.fields.len() - 1);
             datum::immediate_rvalue_bcx(bcx, flag_ptr, ptr_ty).to_expr_datumblock()
         }
         General(_, _, dtor) if dtor_active(dtor) => {
index 955a777bbbe70800cf52f172098a5ea39437b9ed..e8b669894a70587b7e7d2db3a3aab81dce85045d 100644 (file)
@@ -1415,7 +1415,7 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
                                                                llval| {
                         for (j, &tupled_arg_ty) in
                                     tupled_arg_tys.iter().enumerate() {
-                            let lldest = GEPi(bcx, llval, &[0, j]);
+                            let lldest = StructGEP(bcx, llval, j);
                             if common::type_is_fat_ptr(bcx.tcx(), tupled_arg_ty) {
                                 let data = get_param(bcx.fcx.llfn, idx);
                                 let extra = get_param(bcx.fcx.llfn, idx + 1);
index d97872310966beed76b4f87a6a4c448cc4917868..d29a5f0f746e9ed0f751497b07aaa061cf48e7bc 100644 (file)
@@ -70,7 +70,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         let upvar_id = ty::UpvarId { var_id: freevar.def.local_node_id(),
                                      closure_expr_id: closure_id.node };
         let upvar_capture = bcx.tcx().upvar_capture(upvar_id).unwrap();
-        let mut upvar_ptr = GEPi(bcx, llenv, &[0, i]);
+        let mut upvar_ptr = StructGEP(bcx, llenv, i);
         let captured_by_ref = match upvar_capture {
             ty::UpvarCapture::ByValue => false,
             ty::UpvarCapture::ByRef(..) => {
index 68f79dc386ac2da81cf2f871d5697758d1653a4e..273192e97142dd02caef9582babe396c8e6572ba 100644 (file)
@@ -283,11 +283,11 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 }
 
 pub fn get_meta(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
-    GEPi(bcx, fat_ptr, &[0, abi::FAT_PTR_EXTRA])
+    StructGEP(bcx, fat_ptr, abi::FAT_PTR_EXTRA)
 }
 
 pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
-    GEPi(bcx, fat_ptr, &[0, abi::FAT_PTR_ADDR])
+    StructGEP(bcx, fat_ptr, abi::FAT_PTR_ADDR)
 }
 
 pub fn copy_fat_ptr(bcx: Block, src_ptr: ValueRef, dst_ptr: ValueRef) {
index 929061b08b8b8a33c3dd5276e91d8fd46d667ac2..b1c85ce54b73fff86a5944386c400f598500c044 100644 (file)
@@ -821,10 +821,10 @@ unsafe fn build_wrap_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                    i, ccx.tn().val_to_string(llrust_arg));
             if type_is_fat_ptr(ccx.tcx(), rust_ty) {
                 let next_llrust_ty = rust_param_tys.next().expect("Not enough parameter types!");
-                llrust_args.push(builder.load(builder.bitcast(builder.gepi(
-                                llrust_arg, &[0, abi::FAT_PTR_ADDR]), llrust_ty.ptr_to())));
-                llrust_args.push(builder.load(builder.bitcast(builder.gepi(
-                                llrust_arg, &[0, abi::FAT_PTR_EXTRA]), next_llrust_ty.ptr_to())));
+                llrust_args.push(builder.load(builder.bitcast(builder.struct_gep(
+                                llrust_arg, abi::FAT_PTR_ADDR), llrust_ty.ptr_to())));
+                llrust_args.push(builder.load(builder.bitcast(builder.struct_gep(
+                                llrust_arg, abi::FAT_PTR_EXTRA), next_llrust_ty.ptr_to())));
             } else {
                 llrust_args.push(llrust_arg);
             }
index 57e7cc4b02e17a7d5e4bda2ca99db47b90bd7ae1..f3a3268bebbd535d3578345993fe32aaa453bd01 100644 (file)
@@ -66,7 +66,7 @@ pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         SaveIn(lldest) => {
             // lldest will have type *[T x N], but we want the type *T,
             // so use GEP to convert:
-            let lldest = GEPi(bcx, lldest, &[0, 0]);
+            let lldest = StructGEP(bcx, lldest, 0);
             write_content(bcx, &vt, expr, expr, SaveIn(lldest))
         }
     };
@@ -122,7 +122,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
         // llfixed has type *[T x N], but we want the type *T,
         // so use GEP to convert
         bcx = write_content(bcx, &vt, slice_expr, content_expr,
-                            SaveIn(GEPi(bcx, llfixed, &[0, 0])));
+                            SaveIn(StructGEP(bcx, llfixed, 0)));
     };
 
     immediate_rvalue_bcx(bcx, llfixed, vec_ty).to_expr_datumblock()