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.
This commit is contained in:
Björn Steinbrink 2015-08-24 22:51:57 +02:00
parent 110a34cd84
commit 5d9c250fe4
6 changed files with 15 additions and 15 deletions

View 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) => {

View 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);

View 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(..) => {

View 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) {

View File

@ -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);
}

View 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()