Skip to content

Commit

Permalink
Use StructGEP instead of GEPi where appropriate
Browse files Browse the repository at this point in the history
StructGEP seems clearer and probably does an even better job of the
micro-optimization that we have in GEPi.
  • Loading branch information
dotdash committed Aug 24, 2015
1 parent 110a34c commit 5d9c250
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/librustc_trans/trans/adt.rs
Expand Up @@ -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),
Expand Down Expand Up @@ -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, ..} => {
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/base.rs
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/closure.rs
Expand Up @@ -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(..) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/expr.rs
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_trans/trans/foreign.rs
Expand Up @@ -821,10 +821,10 @@ pub fn trans_rust_fn_with_foreign_abi<'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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/tvec.rs
Expand Up @@ -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))
}
};
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5d9c250

Please sign in to comment.