Skip to content

Commit 737377e

Browse files
committed
---
yaml --- r: 273279 b: refs/heads/beta c: d9277b1 h: refs/heads/master i: 273277: 9952605 273275: 12d2f97 273271: ca97ccd 273263: 19135c0 273247: 216fd9f 273215: 79ca569 273151: 2e9fba5
1 parent cc7ec4b commit 737377e

File tree

13 files changed

+170
-143
lines changed

13 files changed

+170
-143
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 82fad1dfc70c641c28f8a422934b89bf983925b8
26+
refs/heads/beta: d9277b163c36448c5fbc39fa089a78256b45ffc1
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_trans/trans/abi.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
use llvm::{self, ValueRef};
1212
use trans::base;
13-
use trans::build::B;
1413
use trans::builder::Builder;
15-
use trans::common::{type_is_fat_ptr, Block};
14+
use trans::common::{type_is_fat_ptr, BlockAndBuilder};
1615
use trans::context::CrateContext;
1716
use trans::cabi_x86;
1817
use trans::cabi_x86_64;
@@ -169,18 +168,16 @@ impl ArgType {
169168
}
170169
}
171170

172-
pub fn store_fn_arg(&self, bcx: Block, idx: &mut usize, dst: ValueRef) {
171+
pub fn store_fn_arg(&self, bcx: &BlockAndBuilder, idx: &mut usize, dst: ValueRef) {
173172
if self.pad.is_some() {
174173
*idx += 1;
175174
}
176175
if self.is_ignore() {
177176
return;
178177
}
179-
let val = llvm::get_param(bcx.fcx.llfn, *idx as c_uint);
178+
let val = llvm::get_param(bcx.fcx().llfn, *idx as c_uint);
180179
*idx += 1;
181-
if !bcx.unreachable.get() {
182-
self.store(&B(bcx), val, dst);
183-
}
180+
self.store(bcx, val, dst);
184181
}
185182
}
186183

branches/beta/src/librustc_trans/trans/adt.rs

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,15 @@ pub fn num_args(r: &Repr, discr: Disr) -> usize {
10651065
/// Access a field, at a point when the value's case is known.
10661066
pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
10671067
val: MaybeSizedValue, discr: Disr, ix: usize) -> ValueRef {
1068+
trans_field_ptr_builder(&bcx.build(), r, val, discr, ix)
1069+
}
1070+
1071+
/// Access a field, at a point when the value's case is known.
1072+
pub fn trans_field_ptr_builder<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
1073+
r: &Repr<'tcx>,
1074+
val: MaybeSizedValue,
1075+
discr: Disr, ix: usize)
1076+
-> ValueRef {
10681077
// Note: if this ever needs to generate conditionals (e.g., if we
10691078
// decide to do some kind of cdr-coding-like non-unique repr
10701079
// someday), it will need to return a possibly-new bcx as well.
@@ -1087,13 +1096,15 @@ pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
10871096
assert_eq!(machine::llsize_of_alloc(bcx.ccx(), ty), 0);
10881097
// The contents of memory at this pointer can't matter, but use
10891098
// the value that's "reasonable" in case of pointer comparison.
1090-
PointerCast(bcx, val.value, ty.ptr_to())
1099+
if bcx.is_unreachable() { return C_undef(ty.ptr_to()); }
1100+
bcx.pointercast(val.value, ty.ptr_to())
10911101
}
10921102
RawNullablePointer { nndiscr, nnty, .. } => {
10931103
assert_eq!(ix, 0);
10941104
assert_eq!(discr, nndiscr);
10951105
let ty = type_of::type_of(bcx.ccx(), nnty);
1096-
PointerCast(bcx, val.value, ty.ptr_to())
1106+
if bcx.is_unreachable() { return C_undef(ty.ptr_to()); }
1107+
bcx.pointercast(val.value, ty.ptr_to())
10971108
}
10981109
StructWrappedNullablePointer { ref nonnull, nndiscr, .. } => {
10991110
assert_eq!(discr, nndiscr);
@@ -1102,33 +1113,39 @@ pub fn trans_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, r: &Repr<'tcx>,
11021113
}
11031114
}
11041115

1105-
pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, val: MaybeSizedValue,
1106-
ix: usize, needs_cast: bool) -> ValueRef {
1116+
fn struct_field_ptr<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
1117+
st: &Struct<'tcx>, val: MaybeSizedValue,
1118+
ix: usize, needs_cast: bool) -> ValueRef {
11071119
let ccx = bcx.ccx();
1120+
let fty = st.fields[ix];
1121+
let ll_fty = type_of::in_memory_type_of(bcx.ccx(), fty);
1122+
if bcx.is_unreachable() {
1123+
return C_undef(ll_fty.ptr_to());
1124+
}
1125+
11081126
let ptr_val = if needs_cast {
11091127
let fields = st.fields.iter().map(|&ty| {
11101128
type_of::in_memory_type_of(ccx, ty)
11111129
}).collect::<Vec<_>>();
11121130
let real_ty = Type::struct_(ccx, &fields[..], st.packed);
1113-
PointerCast(bcx, val.value, real_ty.ptr_to())
1131+
bcx.pointercast(val.value, real_ty.ptr_to())
11141132
} else {
11151133
val.value
11161134
};
11171135

1118-
let fty = st.fields[ix];
11191136
// Simple case - we can just GEP the field
11201137
// * First field - Always aligned properly
11211138
// * Packed struct - There is no alignment padding
11221139
// * Field is sized - pointer is properly aligned already
11231140
if ix == 0 || st.packed || type_is_sized(bcx.tcx(), fty) {
1124-
return StructGEP(bcx, ptr_val, ix);
1141+
return bcx.struct_gep(ptr_val, ix);
11251142
}
11261143

11271144
// If the type of the last field is [T] or str, then we don't need to do
11281145
// any adjusments
11291146
match fty.sty {
11301147
ty::TySlice(..) | ty::TyStr => {
1131-
return StructGEP(bcx, ptr_val, ix);
1148+
return bcx.struct_gep(ptr_val, ix);
11321149
}
11331150
_ => ()
11341151
}
@@ -1137,7 +1154,7 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
11371154
if !val.has_meta() {
11381155
debug!("Unsized field `{}`, of `{:?}` has no metadata for adjustment",
11391156
ix, Value(ptr_val));
1140-
return StructGEP(bcx, ptr_val, ix);
1157+
return bcx.struct_gep(ptr_val, ix);
11411158
}
11421159

11431160
let dbloc = DebugLoc::None;
@@ -1178,22 +1195,21 @@ pub fn struct_field_ptr<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, st: &Struct<'tcx>, v
11781195
// (unaligned offset + (align - 1)) & -align
11791196

11801197
// Calculate offset
1181-
let align_sub_1 = Sub(bcx, align, C_uint(bcx.ccx(), 1u64), dbloc);
1182-
let offset = And(bcx,
1183-
Add(bcx, unaligned_offset, align_sub_1, dbloc),
1184-
Neg(bcx, align, dbloc),
1185-
dbloc);
1198+
dbloc.apply(bcx.fcx());
1199+
let align_sub_1 = bcx.sub(align, C_uint(bcx.ccx(), 1u64));
1200+
let offset = bcx.and(bcx.add(unaligned_offset, align_sub_1),
1201+
bcx.neg(align));
11861202

11871203
debug!("struct_field_ptr: DST field offset: {:?}", Value(offset));
11881204

11891205
// Cast and adjust pointer
1190-
let byte_ptr = PointerCast(bcx, ptr_val, Type::i8p(bcx.ccx()));
1191-
let byte_ptr = GEP(bcx, byte_ptr, &[offset]);
1206+
let byte_ptr = bcx.pointercast(ptr_val, Type::i8p(bcx.ccx()));
1207+
let byte_ptr = bcx.gep(byte_ptr, &[offset]);
11921208

11931209
// Finally, cast back to the type expected
11941210
let ll_fty = type_of::in_memory_type_of(bcx.ccx(), fty);
11951211
debug!("struct_field_ptr: Field type is {:?}", ll_fty);
1196-
PointerCast(bcx, byte_ptr, ll_fty.ptr_to())
1212+
bcx.pointercast(byte_ptr, ll_fty.ptr_to())
11971213
}
11981214

11991215
pub fn fold_variants<'blk, 'tcx, F>(bcx: Block<'blk, 'tcx>,
@@ -1284,7 +1300,8 @@ pub fn trans_drop_flag_ptr<'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
12841300
}
12851301
));
12861302
bcx = fold_variants(bcx, r, val, |variant_cx, st, value| {
1287-
let ptr = struct_field_ptr(variant_cx, st, MaybeSizedValue::sized(value),
1303+
let ptr = struct_field_ptr(&variant_cx.build(), st,
1304+
MaybeSizedValue::sized(value),
12881305
(st.fields.len() - 1), false);
12891306
datum::Datum::new(ptr, ptr_ty, datum::Lvalue::new("adt::trans_drop_flag_ptr"))
12901307
.store_to(variant_cx, scratch.val)

branches/beta/src/librustc_trans/trans/base.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -911,33 +911,43 @@ pub fn load_if_immediate<'blk, 'tcx>(cx: Block<'blk, 'tcx>, v: ValueRef, t: Ty<'
911911
/// differs from the type used for SSA values. Also handles various special cases where the type
912912
/// gives us better information about what we are loading.
913913
pub fn load_ty<'blk, 'tcx>(cx: Block<'blk, 'tcx>, ptr: ValueRef, t: Ty<'tcx>) -> ValueRef {
914-
if cx.unreachable.get() || type_is_zero_size(cx.ccx(), t) {
914+
if cx.unreachable.get() {
915915
return C_undef(type_of::type_of(cx.ccx(), t));
916916
}
917+
load_ty_builder(&B(cx), ptr, t)
918+
}
919+
920+
pub fn load_ty_builder<'a, 'tcx>(b: &Builder<'a, 'tcx>, ptr: ValueRef, t: Ty<'tcx>) -> ValueRef {
921+
let ccx = b.ccx;
922+
if type_is_zero_size(ccx, t) {
923+
return C_undef(type_of::type_of(ccx, t));
924+
}
917925

918926
unsafe {
919927
let global = llvm::LLVMIsAGlobalVariable(ptr);
920928
if !global.is_null() && llvm::LLVMIsGlobalConstant(global) == llvm::True {
921929
let val = llvm::LLVMGetInitializer(global);
922930
if !val.is_null() {
923-
return to_immediate(cx, val, t);
931+
if t.is_bool() {
932+
return llvm::LLVMConstTrunc(val, Type::i1(ccx).to_ref());
933+
}
934+
return val;
924935
}
925936
}
926937
}
927938

928-
let val = if t.is_bool() {
929-
LoadRangeAssert(cx, ptr, 0, 2, llvm::False)
939+
if t.is_bool() {
940+
b.trunc(b.load_range_assert(ptr, 0, 2, llvm::False), Type::i1(ccx))
930941
} else if t.is_char() {
931942
// a char is a Unicode codepoint, and so takes values from 0
932943
// to 0x10FFFF inclusive only.
933-
LoadRangeAssert(cx, ptr, 0, 0x10FFFF + 1, llvm::False)
934-
} else if (t.is_region_ptr() || t.is_unique()) && !common::type_is_fat_ptr(cx.tcx(), t) {
935-
LoadNonNull(cx, ptr)
944+
b.load_range_assert(ptr, 0, 0x10FFFF + 1, llvm::False)
945+
} else if (t.is_region_ptr() || t.is_unique()) &&
946+
!common::type_is_fat_ptr(ccx.tcx(), t) {
947+
b.load_nonnull(ptr)
936948
} else {
937-
Load(cx, ptr)
938-
};
939-
940-
to_immediate(cx, val, t)
949+
b.load(ptr)
950+
}
941951
}
942952

943953
/// Helper for storing values in memory. Does the necessary conversion if the in-memory type
@@ -1644,13 +1654,14 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
16441654
uninit_reason,
16451655
arg_scope_id, |bcx, dst| {
16461656
debug!("FunctionContext::bind_args: {:?}: {:?}", hir_arg, arg_ty);
1657+
let b = &bcx.build();
16471658
if common::type_is_fat_ptr(bcx.tcx(), arg_ty) {
16481659
let meta = &self.fn_ty.args[idx];
16491660
idx += 1;
1650-
arg.store_fn_arg(bcx, &mut llarg_idx, expr::get_dataptr(bcx, dst));
1651-
meta.store_fn_arg(bcx, &mut llarg_idx, expr::get_meta(bcx, dst));
1661+
arg.store_fn_arg(b, &mut llarg_idx, expr::get_dataptr(bcx, dst));
1662+
meta.store_fn_arg(b, &mut llarg_idx, expr::get_meta(bcx, dst));
16521663
} else {
1653-
arg.store_fn_arg(bcx, &mut llarg_idx, dst);
1664+
arg.store_fn_arg(b, &mut llarg_idx, dst);
16541665
}
16551666
bcx
16561667
}))
@@ -1672,13 +1683,14 @@ impl<'blk, 'tcx> FunctionContext<'blk, 'tcx> {
16721683
for (j, &tupled_arg_ty) in tupled_arg_tys.iter().enumerate() {
16731684
let dst = StructGEP(bcx, llval, j);
16741685
let arg = &self.fn_ty.args[idx];
1686+
let b = &bcx.build();
16751687
if common::type_is_fat_ptr(bcx.tcx(), tupled_arg_ty) {
16761688
let meta = &self.fn_ty.args[idx];
16771689
idx += 1;
1678-
arg.store_fn_arg(bcx, &mut llarg_idx, expr::get_dataptr(bcx, dst));
1679-
meta.store_fn_arg(bcx, &mut llarg_idx, expr::get_meta(bcx, dst));
1690+
arg.store_fn_arg(b, &mut llarg_idx, expr::get_dataptr(bcx, dst));
1691+
meta.store_fn_arg(b, &mut llarg_idx, expr::get_meta(bcx, dst));
16801692
} else {
1681-
arg.store_fn_arg(bcx, &mut llarg_idx, dst);
1693+
arg.store_fn_arg(b, &mut llarg_idx, dst);
16821694
}
16831695
}
16841696
bcx
@@ -2024,13 +2036,14 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
20242036
let lldestptr = adt::trans_field_ptr(bcx, &repr, dest_val, Disr::from(disr), i);
20252037
let arg = &fcx.fn_ty.args[arg_idx];
20262038
arg_idx += 1;
2039+
let b = &bcx.build();
20272040
if common::type_is_fat_ptr(bcx.tcx(), arg_ty) {
20282041
let meta = &fcx.fn_ty.args[arg_idx];
20292042
arg_idx += 1;
2030-
arg.store_fn_arg(bcx, &mut llarg_idx, expr::get_dataptr(bcx, lldestptr));
2031-
meta.store_fn_arg(bcx, &mut llarg_idx, expr::get_meta(bcx, lldestptr));
2043+
arg.store_fn_arg(b, &mut llarg_idx, expr::get_dataptr(bcx, lldestptr));
2044+
meta.store_fn_arg(b, &mut llarg_idx, expr::get_meta(bcx, lldestptr));
20322045
} else {
2033-
arg.store_fn_arg(bcx, &mut llarg_idx, lldestptr);
2046+
arg.store_fn_arg(b, &mut llarg_idx, lldestptr);
20342047
}
20352048
}
20362049
adt::trans_set_discr(bcx, &repr, dest, disr);

branches/beta/src/librustc_trans/trans/closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn load_closure_environment<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
5353
let llenv = if kind == ty::ClosureKind::FnOnce && !env_arg.is_indirect() {
5454
let closure_ty = node_id_type(bcx, id);
5555
let llenv = rvalue_scratch_datum(bcx, closure_ty, "closure_env").val;
56-
env_arg.store_fn_arg(bcx, &mut env_idx, llenv);
56+
env_arg.store_fn_arg(&bcx.build(), &mut env_idx, llenv);
5757
llenv
5858
} else {
5959
get_param(bcx.fcx.llfn, env_idx as c_uint)
@@ -410,7 +410,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
410410
InitAlloca::Dropped,
411411
self_scope_id, |bcx, llval| {
412412
let mut llarg_idx = self_idx;
413-
env_arg.store_fn_arg(bcx, &mut llarg_idx, llval);
413+
env_arg.store_fn_arg(&bcx.build(), &mut llarg_idx, llval);
414414
bcx.fcx.schedule_lifetime_end(self_scope_id, llval);
415415
bcx
416416
})).val

branches/beta/src/librustc_trans/trans/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ impl<'blk, 'tcx> BlockAndBuilder<'blk, 'tcx> {
688688

689689
// Methods delegated to bcx
690690

691+
pub fn is_unreachable(&self) -> bool {
692+
self.bcx.unreachable.get()
693+
}
694+
691695
pub fn ccx(&self) -> &'blk CrateContext<'blk, 'tcx> {
692696
self.bcx.ccx()
693697
}

0 commit comments

Comments
 (0)