Skip to content

Commit 1be170b

Browse files
Replace BlockAndBuilder with Builder.
1 parent d40d01b commit 1be170b

File tree

21 files changed

+344
-357
lines changed

21 files changed

+344
-357
lines changed

src/librustc_trans/abi.rs

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

1111
use llvm::{self, ValueRef, Integer, Pointer, Float, Double, Struct, Array, Vector, AttributePlace};
1212
use base;
13-
use common::{type_is_fat_ptr, BlockAndBuilder, C_uint};
13+
use builder::Builder;
14+
use common::{type_is_fat_ptr, C_uint};
1415
use context::CrateContext;
1516
use cabi_x86;
1617
use cabi_x86_64;
@@ -236,7 +237,7 @@ impl ArgType {
236237
/// lvalue for the original Rust type of this argument/return.
237238
/// Can be used for both storing formal arguments into Rust variables
238239
/// or results of call/invoke instructions into their destinations.
239-
pub fn store(&self, bcx: &BlockAndBuilder, mut val: ValueRef, dst: ValueRef) {
240+
pub fn store(&self, bcx: &Builder, mut val: ValueRef, dst: ValueRef) {
240241
if self.is_ignore() {
241242
return;
242243
}
@@ -269,7 +270,7 @@ impl ArgType {
269270
// bitcasting to the struct type yields invalid cast errors.
270271

271272
// We instead thus allocate some scratch space...
272-
let llscratch = bcx.fcx().alloca(ty, "abi_cast");
273+
let llscratch = bcx.alloca(ty, "abi_cast");
273274
base::Lifetime::Start.call(bcx, llscratch);
274275

275276
// ...where we first store the value...
@@ -293,14 +294,16 @@ impl ArgType {
293294
}
294295
}
295296

296-
pub fn store_fn_arg(&self, bcx: &BlockAndBuilder, idx: &mut usize, dst: ValueRef) {
297+
pub fn store_fn_arg(
298+
&self, bcx: &Builder, idx: &mut usize, dst: ValueRef
299+
) {
297300
if self.pad.is_some() {
298301
*idx += 1;
299302
}
300303
if self.is_ignore() {
301304
return;
302305
}
303-
let val = llvm::get_param(bcx.fcx().llfn, *idx as c_uint);
306+
let val = llvm::get_param(bcx.llfn(), *idx as c_uint);
304307
*idx += 1;
305308
self.store(bcx, val, dst);
306309
}

src/librustc_trans/adt.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use llvm::{ValueRef, True, IntEQ, IntNE};
4949
use rustc::ty::layout;
5050
use rustc::ty::{self, Ty, AdtKind};
5151
use common::*;
52+
use builder::Builder;
5253
use glue;
5354
use base;
5455
use machine;
@@ -303,7 +304,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fields: &Vec<Ty<'tcx>>
303304
/// Obtain a representation of the discriminant sufficient to translate
304305
/// destructuring; this may or may not involve the actual discriminant.
305306
pub fn trans_switch<'a, 'tcx>(
306-
bcx: &BlockAndBuilder<'a, 'tcx>,
307+
bcx: &Builder<'a, 'tcx>,
307308
t: Ty<'tcx>,
308309
scrutinee: ValueRef,
309310
range_assert: bool
@@ -331,7 +332,7 @@ pub fn is_discr_signed<'tcx>(l: &layout::Layout) -> bool {
331332

332333
/// Obtain the actual discriminant of a value.
333334
pub fn trans_get_discr<'a, 'tcx>(
334-
bcx: &BlockAndBuilder<'a, 'tcx>,
335+
bcx: &Builder<'a, 'tcx>,
335336
t: Ty<'tcx>,
336337
scrutinee: ValueRef,
337338
cast_to: Option<Type>,
@@ -374,7 +375,7 @@ pub fn trans_get_discr<'a, 'tcx>(
374375
}
375376

376377
fn struct_wrapped_nullable_bitdiscr(
377-
bcx: &BlockAndBuilder,
378+
bcx: &Builder,
378379
nndiscr: u64,
379380
discrfield: &layout::FieldPath,
380381
scrutinee: ValueRef
@@ -387,7 +388,7 @@ fn struct_wrapped_nullable_bitdiscr(
387388
}
388389

389390
/// Helper for cases where the discriminant is simply loaded.
390-
fn load_discr(bcx: &BlockAndBuilder, ity: layout::Integer, ptr: ValueRef, min: u64, max: u64,
391+
fn load_discr(bcx: &Builder, ity: layout::Integer, ptr: ValueRef, min: u64, max: u64,
391392
range_assert: bool)
392393
-> ValueRef {
393394
let llty = Type::from_integer(bcx.ccx, ity);
@@ -415,7 +416,7 @@ fn load_discr(bcx: &BlockAndBuilder, ity: layout::Integer, ptr: ValueRef, min: u
415416
/// discriminant-like value returned by `trans_switch`.
416417
///
417418
/// This should ideally be less tightly tied to `_match`.
418-
pub fn trans_case<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, value: Disr) -> ValueRef {
419+
pub fn trans_case<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, value: Disr) -> ValueRef {
419420
let l = bcx.ccx.layout_of(t);
420421
match *l {
421422
layout::CEnum { discr, .. }
@@ -436,7 +437,7 @@ pub fn trans_case<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, value:
436437
/// Set the discriminant for a new value of the given case of the given
437438
/// representation.
438439
pub fn trans_set_discr<'a, 'tcx>(
439-
bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, val: ValueRef, to: Disr
440+
bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: ValueRef, to: Disr
440441
) {
441442
let l = bcx.ccx.layout_of(t);
442443
match *l {
@@ -484,8 +485,8 @@ pub fn trans_set_discr<'a, 'tcx>(
484485
}
485486
}
486487

487-
fn target_sets_discr_via_memset<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>) -> bool {
488-
bcx.sess().target.target.arch == "arm" || bcx.sess().target.target.arch == "aarch64"
488+
fn target_sets_discr_via_memset<'a, 'tcx>(bcx: &Builder<'a, 'tcx>) -> bool {
489+
bcx.ccx.sess().target.target.arch == "arm" || bcx.ccx.sess().target.target.arch == "aarch64"
489490
}
490491

491492
fn assert_discr_in_range(min: Disr, max: Disr, discr: Disr) {
@@ -498,7 +499,7 @@ fn assert_discr_in_range(min: Disr, max: Disr, discr: Disr) {
498499

499500
/// Access a field, at a point when the value's case is known.
500501
pub fn trans_field_ptr<'a, 'tcx>(
501-
bcx: &BlockAndBuilder<'a, 'tcx>,
502+
bcx: &Builder<'a, 'tcx>,
502503
t: Ty<'tcx>,
503504
val: MaybeSizedValue,
504505
discr: Disr,
@@ -560,7 +561,7 @@ pub fn trans_field_ptr<'a, 'tcx>(
560561
}
561562

562563
fn struct_field_ptr<'a, 'tcx>(
563-
bcx: &BlockAndBuilder<'a, 'tcx>,
564+
bcx: &Builder<'a, 'tcx>,
564565
st: &layout::Struct,
565566
fields: &Vec<Ty<'tcx>>,
566567
val: MaybeSizedValue,

src/librustc_trans/asm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use base;
1515
use common::*;
1616
use type_of;
1717
use type_::Type;
18+
use builder::Builder;
1819

1920
use rustc::hir;
2021
use rustc::ty::Ty;
@@ -25,7 +26,7 @@ use libc::{c_uint, c_char};
2526

2627
// Take an inline assembly expression and splat it out via LLVM
2728
pub fn trans_inline_asm<'a, 'tcx>(
28-
bcx: &BlockAndBuilder<'a, 'tcx>,
29+
bcx: &Builder<'a, 'tcx>,
2930
ia: &hir::InlineAsm,
3031
outputs: Vec<(ValueRef, Ty<'tcx>)>,
3132
mut inputs: Vec<ValueRef>
@@ -61,7 +62,7 @@ pub fn trans_inline_asm<'a, 'tcx>(
6162

6263
// Default per-arch clobbers
6364
// Basically what clang does
64-
let arch_clobbers = match &bcx.sess().target.target.arch[..] {
65+
let arch_clobbers = match &bcx.ccx.sess().target.target.arch[..] {
6566
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
6667
_ => Vec::new()
6768
};

src/librustc_trans/base.rs

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
3838
use middle::lang_items::StartFnLangItem;
3939
use rustc::ty::subst::Substs;
4040
use rustc::traits;
41-
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
41+
use rustc::ty::{self, Ty, TyCtxt};
4242
use rustc::ty::adjustment::CustomCoerceUnsized;
4343
use rustc::dep_graph::{DepNode, WorkProduct};
4444
use rustc::hir::map as hir_map;
@@ -51,7 +51,7 @@ use adt;
5151
use attributes;
5252
use builder::Builder;
5353
use callee::{Callee};
54-
use common::{BlockAndBuilder, C_bool, C_bytes_in_context, C_i32, C_uint};
54+
use common::{C_bool, C_bytes_in_context, C_i32, C_uint};
5555
use collector::{self, TransItemCollectionMode};
5656
use common::{C_struct_in_context, C_u64, C_undef};
5757
use common::{CrateContext, FunctionContext};
@@ -161,7 +161,7 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOp_) -> llvm::RealPredicate {
161161
}
162162

163163
pub fn compare_simd_types<'a, 'tcx>(
164-
bcx: &BlockAndBuilder<'a, 'tcx>,
164+
bcx: &Builder<'a, 'tcx>,
165165
lhs: ValueRef,
166166
rhs: ValueRef,
167167
t: Ty<'tcx>,
@@ -218,7 +218,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
218218

219219
/// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer.
220220
pub fn unsize_thin_ptr<'a, 'tcx>(
221-
bcx: &BlockAndBuilder<'a, 'tcx>,
221+
bcx: &Builder<'a, 'tcx>,
222222
src: ValueRef,
223223
src_ty: Ty<'tcx>,
224224
dst_ty: Ty<'tcx>
@@ -242,7 +242,7 @@ pub fn unsize_thin_ptr<'a, 'tcx>(
242242

243243
/// Coerce `src`, which is a reference to a value of type `src_ty`,
244244
/// to a value of type `dst_ty` and store the result in `dst`
245-
pub fn coerce_unsized_into<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
245+
pub fn coerce_unsized_into<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
246246
src: ValueRef,
247247
src_ty: Ty<'tcx>,
248248
dst: ValueRef,
@@ -272,10 +272,10 @@ pub fn coerce_unsized_into<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
272272
assert_eq!(def_a, def_b);
273273

274274
let src_fields = def_a.variants[0].fields.iter().map(|f| {
275-
monomorphize::field_ty(bcx.tcx(), substs_a, f)
275+
monomorphize::field_ty(bcx.ccx.tcx(), substs_a, f)
276276
});
277277
let dst_fields = def_b.variants[0].fields.iter().map(|f| {
278-
monomorphize::field_ty(bcx.tcx(), substs_b, f)
278+
monomorphize::field_ty(bcx.ccx.tcx(), substs_b, f)
279279
});
280280

281281
let src = adt::MaybeSizedValue::sized(src);
@@ -322,7 +322,7 @@ pub fn custom_coerce_unsize_info<'scx, 'tcx>(scx: &SharedCrateContext<'scx, 'tcx
322322
}
323323

324324
pub fn cast_shift_expr_rhs(
325-
cx: &BlockAndBuilder, op: hir::BinOp_, lhs: ValueRef, rhs: ValueRef
325+
cx: &Builder, op: hir::BinOp_, lhs: ValueRef, rhs: ValueRef
326326
) -> ValueRef {
327327
cast_shift_rhs(op, lhs, rhs, |a, b| cx.trunc(a, b), |a, b| cx.zext(a, b))
328328
}
@@ -421,7 +421,7 @@ pub fn load_ty<'a, 'tcx>(b: &Builder<'a, 'tcx>, ptr: ValueRef, t: Ty<'tcx>) -> V
421421

422422
/// Helper for storing values in memory. Does the necessary conversion if the in-memory type
423423
/// differs from the type used for SSA values.
424-
pub fn store_ty<'a, 'tcx>(cx: &BlockAndBuilder<'a, 'tcx>, v: ValueRef, dst: ValueRef, t: Ty<'tcx>) {
424+
pub fn store_ty<'a, 'tcx>(cx: &Builder<'a, 'tcx>, v: ValueRef, dst: ValueRef, t: Ty<'tcx>) {
425425
debug!("store_ty: {:?} : {:?} <- {:?}", Value(dst), t, Value(v));
426426

427427
if common::type_is_fat_ptr(cx.ccx, t) {
@@ -433,7 +433,7 @@ pub fn store_ty<'a, 'tcx>(cx: &BlockAndBuilder<'a, 'tcx>, v: ValueRef, dst: Valu
433433
}
434434
}
435435

436-
pub fn store_fat_ptr<'a, 'tcx>(cx: &BlockAndBuilder<'a, 'tcx>,
436+
pub fn store_fat_ptr<'a, 'tcx>(cx: &Builder<'a, 'tcx>,
437437
data: ValueRef,
438438
extra: ValueRef,
439439
dst: ValueRef,
@@ -459,15 +459,15 @@ pub fn load_fat_ptr<'a, 'tcx>(
459459
(ptr, meta)
460460
}
461461

462-
pub fn from_immediate(bcx: &BlockAndBuilder, val: ValueRef) -> ValueRef {
462+
pub fn from_immediate(bcx: &Builder, val: ValueRef) -> ValueRef {
463463
if val_ty(val) == Type::i1(bcx.ccx) {
464464
bcx.zext(val, Type::i8(bcx.ccx))
465465
} else {
466466
val
467467
}
468468
}
469469

470-
pub fn to_immediate(bcx: &BlockAndBuilder, val: ValueRef, ty: Ty) -> ValueRef {
470+
pub fn to_immediate(bcx: &Builder, val: ValueRef, ty: Ty) -> ValueRef {
471471
if ty.is_bool() {
472472
bcx.trunc(val, Type::i1(bcx.ccx))
473473
} else {
@@ -523,11 +523,13 @@ pub fn call_memcpy<'a, 'tcx>(b: &Builder<'a, 'tcx>,
523523
b.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
524524
}
525525

526-
pub fn memcpy_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
527-
dst: ValueRef,
528-
src: ValueRef,
529-
t: Ty<'tcx>,
530-
align: Option<u32>) {
526+
pub fn memcpy_ty<'a, 'tcx>(
527+
bcx: &Builder<'a, 'tcx>,
528+
dst: ValueRef,
529+
src: ValueRef,
530+
t: Ty<'tcx>,
531+
align: Option<u32>,
532+
) {
531533
let ccx = bcx.ccx;
532534

533535
if type_is_zero_size(ccx, t) {
@@ -553,11 +555,6 @@ pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
553555
b.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None)
554556
}
555557

556-
pub fn alloc_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, ty: Ty<'tcx>, name: &str) -> ValueRef {
557-
assert!(!ty.has_param_types());
558-
bcx.fcx().alloca(type_of::type_of(bcx.ccx, ty), name)
559-
}
560-
561558
pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
562559
let _s = if ccx.sess().trans_stats() {
563560
let mut instance_name = String::new();
@@ -623,7 +620,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
623620
// We create an alloca to hold a pointer of type `ret.original_ty`
624621
// which will hold the pointer to the right alloca which has the
625622
// final ret value
626-
fcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
623+
bcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
627624
};
628625
let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
629626
let mut llarg_idx = fn_ty.ret.is_indirect() as usize;
@@ -756,12 +753,7 @@ pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
756753
// `main` should respect same config for frame pointer elimination as rest of code
757754
attributes::set_frame_pointer_elimination(ccx, llfn);
758755

759-
let llbb = unsafe {
760-
let name = CString::new("top").unwrap();
761-
llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llfn, name.as_ptr())
762-
};
763-
let bld = Builder::with_ccx(ccx);
764-
bld.position_at_end(llbb);
756+
let bld = Builder::new_block(ccx, llfn, "top");
765757

766758
debuginfo::gdb::insert_reference_to_gdb_debug_scripts_section_global(ccx, &bld);
767759

0 commit comments

Comments
 (0)