Skip to content

Commit 5d9c250

Browse files
committed
Use StructGEP instead of GEPi where appropriate
StructGEP seems clearer and probably does an even better job of the micro-optimization that we have in GEPi.
1 parent 110a34c commit 5d9c250

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/librustc_trans/trans/adt.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ pub fn trans_get_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
892892
let val = match *r {
893893
CEnum(ity, min, max) => load_discr(bcx, ity, scrutinee, min, max),
894894
General(ity, ref cases, _) => {
895-
let ptr = GEPi(bcx, scrutinee, &[0, 0]);
895+
let ptr = StructGEP(bcx, scrutinee, 0);
896896
load_discr(bcx, ity, ptr, 0, (cases.len() - 1) as Disr)
897897
}
898898
Univariant(..) => C_u8(bcx.ccx(), 0),
@@ -986,13 +986,13 @@ pub fn trans_set_discr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
986986
Store(bcx, C_u8(bcx.ccx(), DTOR_NEEDED), ptr);
987987
}
988988
Store(bcx, C_integral(ll_inttype(bcx.ccx(), ity), discr as u64, true),
989-
GEPi(bcx, val, &[0, 0]));
989+
StructGEP(bcx, val, 0));
990990
}
991991
Univariant(ref st, dtor) => {
992992
assert_eq!(discr, 0);
993993
if dtor_active(dtor) {
994994
Store(bcx, C_u8(bcx.ccx(), DTOR_NEEDED),
995-
GEPi(bcx, val, &[0, st.fields.len() - 1]));
995+
StructGEP(bcx, val, st.fields.len() - 1));
996996
}
997997
}
998998
RawNullablePointer { nndiscr, nnty, ..} => {
@@ -1091,7 +1091,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
10911091
val
10921092
};
10931093

1094-
GEPi(bcx, val, &[0, ix])
1094+
StructGEP(bcx, val, ix)
10951095
}
10961096

10971097
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>,
11621162
let ptr_ty = bcx.tcx().mk_imm_ptr(tcx.dtor_type());
11631163
match *r {
11641164
Univariant(ref st, dtor) if dtor_active(dtor) => {
1165-
let flag_ptr = GEPi(bcx, val, &[0, st.fields.len() - 1]);
1165+
let flag_ptr = StructGEP(bcx, val, st.fields.len() - 1);
11661166
datum::immediate_rvalue_bcx(bcx, flag_ptr, ptr_ty).to_expr_datumblock()
11671167
}
11681168
General(_, _, dtor) if dtor_active(dtor) => {

src/librustc_trans/trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ pub fn create_datums_for_fn_args<'a, 'tcx>(mut bcx: Block<'a, 'tcx>,
14151415
llval| {
14161416
for (j, &tupled_arg_ty) in
14171417
tupled_arg_tys.iter().enumerate() {
1418-
let lldest = GEPi(bcx, llval, &[0, j]);
1418+
let lldest = StructGEP(bcx, llval, j);
14191419
if common::type_is_fat_ptr(bcx.tcx(), tupled_arg_ty) {
14201420
let data = get_param(bcx.fcx.llfn, idx);
14211421
let extra = get_param(bcx.fcx.llfn, idx + 1);

src/librustc_trans/trans/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
7070
let upvar_id = ty::UpvarId { var_id: freevar.def.local_node_id(),
7171
closure_expr_id: closure_id.node };
7272
let upvar_capture = bcx.tcx().upvar_capture(upvar_id).unwrap();
73-
let mut upvar_ptr = GEPi(bcx, llenv, &[0, i]);
73+
let mut upvar_ptr = StructGEP(bcx, llenv, i);
7474
let captured_by_ref = match upvar_capture {
7575
ty::UpvarCapture::ByValue => false,
7676
ty::UpvarCapture::ByRef(..) => {

src/librustc_trans/trans/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ pub fn trans<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
283283
}
284284

285285
pub fn get_meta(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
286-
GEPi(bcx, fat_ptr, &[0, abi::FAT_PTR_EXTRA])
286+
StructGEP(bcx, fat_ptr, abi::FAT_PTR_EXTRA)
287287
}
288288

289289
pub fn get_dataptr(bcx: Block, fat_ptr: ValueRef) -> ValueRef {
290-
GEPi(bcx, fat_ptr, &[0, abi::FAT_PTR_ADDR])
290+
StructGEP(bcx, fat_ptr, abi::FAT_PTR_ADDR)
291291
}
292292

293293
pub fn copy_fat_ptr(bcx: Block, src_ptr: ValueRef, dst_ptr: ValueRef) {

src/librustc_trans/trans/foreign.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,10 @@ pub fn trans_rust_fn_with_foreign_abi<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
821821
i, ccx.tn().val_to_string(llrust_arg));
822822
if type_is_fat_ptr(ccx.tcx(), rust_ty) {
823823
let next_llrust_ty = rust_param_tys.next().expect("Not enough parameter types!");
824-
llrust_args.push(builder.load(builder.bitcast(builder.gepi(
825-
llrust_arg, &[0, abi::FAT_PTR_ADDR]), llrust_ty.ptr_to())));
826-
llrust_args.push(builder.load(builder.bitcast(builder.gepi(
827-
llrust_arg, &[0, abi::FAT_PTR_EXTRA]), next_llrust_ty.ptr_to())));
824+
llrust_args.push(builder.load(builder.bitcast(builder.struct_gep(
825+
llrust_arg, abi::FAT_PTR_ADDR), llrust_ty.ptr_to())));
826+
llrust_args.push(builder.load(builder.bitcast(builder.struct_gep(
827+
llrust_arg, abi::FAT_PTR_EXTRA), next_llrust_ty.ptr_to())));
828828
} else {
829829
llrust_args.push(llrust_arg);
830830
}

src/librustc_trans/trans/tvec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn trans_fixed_vstore<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
6666
SaveIn(lldest) => {
6767
// lldest will have type *[T x N], but we want the type *T,
6868
// so use GEP to convert:
69-
let lldest = GEPi(bcx, lldest, &[0, 0]);
69+
let lldest = StructGEP(bcx, lldest, 0);
7070
write_content(bcx, &vt, expr, expr, SaveIn(lldest))
7171
}
7272
};
@@ -122,7 +122,7 @@ pub fn trans_slice_vec<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
122122
// llfixed has type *[T x N], but we want the type *T,
123123
// so use GEP to convert
124124
bcx = write_content(bcx, &vt, slice_expr, content_expr,
125-
SaveIn(GEPi(bcx, llfixed, &[0, 0])));
125+
SaveIn(StructGEP(bcx, llfixed, 0)));
126126
};
127127

128128
immediate_rvalue_bcx(bcx, llfixed, vec_ty).to_expr_datumblock()

0 commit comments

Comments
 (0)