Skip to content

Additional cleanup to rustc_trans #38756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Replace BlockAndBuilder with Builder.
  • Loading branch information
Mark-Simulacrum committed Jan 4, 2017
commit 1be170b01addf84534b51d68e2d5ac76a1a42ac6
13 changes: 8 additions & 5 deletions src/librustc_trans/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

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

// We instead thus allocate some scratch space...
let llscratch = bcx.fcx().alloca(ty, "abi_cast");
let llscratch = bcx.alloca(ty, "abi_cast");
base::Lifetime::Start.call(bcx, llscratch);

// ...where we first store the value...
Expand All @@ -293,14 +294,16 @@ impl ArgType {
}
}

pub fn store_fn_arg(&self, bcx: &BlockAndBuilder, idx: &mut usize, dst: ValueRef) {
pub fn store_fn_arg(
&self, bcx: &Builder, idx: &mut usize, dst: ValueRef
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: style

) {
if self.pad.is_some() {
*idx += 1;
}
if self.is_ignore() {
return;
}
let val = llvm::get_param(bcx.fcx().llfn, *idx as c_uint);
let val = llvm::get_param(bcx.llfn(), *idx as c_uint);
*idx += 1;
self.store(bcx, val, dst);
}
Expand Down
21 changes: 11 additions & 10 deletions src/librustc_trans/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use llvm::{ValueRef, True, IntEQ, IntNE};
use rustc::ty::layout;
use rustc::ty::{self, Ty, AdtKind};
use common::*;
use builder::Builder;
use glue;
use base;
use machine;
Expand Down Expand Up @@ -303,7 +304,7 @@ fn struct_llfields<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fields: &Vec<Ty<'tcx>>
/// Obtain a representation of the discriminant sufficient to translate
/// destructuring; this may or may not involve the actual discriminant.
pub fn trans_switch<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
t: Ty<'tcx>,
scrutinee: ValueRef,
range_assert: bool
Expand Down Expand Up @@ -331,7 +332,7 @@ pub fn is_discr_signed<'tcx>(l: &layout::Layout) -> bool {

/// Obtain the actual discriminant of a value.
pub fn trans_get_discr<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
t: Ty<'tcx>,
scrutinee: ValueRef,
cast_to: Option<Type>,
Expand Down Expand Up @@ -374,7 +375,7 @@ pub fn trans_get_discr<'a, 'tcx>(
}

fn struct_wrapped_nullable_bitdiscr(
bcx: &BlockAndBuilder,
bcx: &Builder,
nndiscr: u64,
discrfield: &layout::FieldPath,
scrutinee: ValueRef
Expand All @@ -387,7 +388,7 @@ fn struct_wrapped_nullable_bitdiscr(
}

/// Helper for cases where the discriminant is simply loaded.
fn load_discr(bcx: &BlockAndBuilder, ity: layout::Integer, ptr: ValueRef, min: u64, max: u64,
fn load_discr(bcx: &Builder, ity: layout::Integer, ptr: ValueRef, min: u64, max: u64,
range_assert: bool)
-> ValueRef {
let llty = Type::from_integer(bcx.ccx, ity);
Expand Down Expand Up @@ -415,7 +416,7 @@ fn load_discr(bcx: &BlockAndBuilder, ity: layout::Integer, ptr: ValueRef, min: u
/// discriminant-like value returned by `trans_switch`.
///
/// This should ideally be less tightly tied to `_match`.
pub fn trans_case<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, value: Disr) -> ValueRef {
pub fn trans_case<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, value: Disr) -> ValueRef {
let l = bcx.ccx.layout_of(t);
match *l {
layout::CEnum { discr, .. }
Expand All @@ -436,7 +437,7 @@ pub fn trans_case<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, value:
/// Set the discriminant for a new value of the given case of the given
/// representation.
pub fn trans_set_discr<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>, t: Ty<'tcx>, val: ValueRef, to: Disr
bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, val: ValueRef, to: Disr
) {
let l = bcx.ccx.layout_of(t);
match *l {
Expand Down Expand Up @@ -484,8 +485,8 @@ pub fn trans_set_discr<'a, 'tcx>(
}
}

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

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

/// Access a field, at a point when the value's case is known.
pub fn trans_field_ptr<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
t: Ty<'tcx>,
val: MaybeSizedValue,
discr: Disr,
Expand Down Expand Up @@ -560,7 +561,7 @@ pub fn trans_field_ptr<'a, 'tcx>(
}

fn struct_field_ptr<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
st: &layout::Struct,
fields: &Vec<Ty<'tcx>>,
val: MaybeSizedValue,
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_trans/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use base;
use common::*;
use type_of;
use type_::Type;
use builder::Builder;

use rustc::hir;
use rustc::ty::Ty;
Expand All @@ -25,7 +26,7 @@ use libc::{c_uint, c_char};

// Take an inline assembly expression and splat it out via LLVM
pub fn trans_inline_asm<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
ia: &hir::InlineAsm,
outputs: Vec<(ValueRef, Ty<'tcx>)>,
mut inputs: Vec<ValueRef>
Expand Down Expand Up @@ -61,7 +62,7 @@ pub fn trans_inline_asm<'a, 'tcx>(

// Default per-arch clobbers
// Basically what clang does
let arch_clobbers = match &bcx.sess().target.target.arch[..] {
let arch_clobbers = match &bcx.ccx.sess().target.target.arch[..] {
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
_ => Vec::new()
};
Expand Down
50 changes: 21 additions & 29 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use rustc::hir::def_id::{DefId, LOCAL_CRATE};
use middle::lang_items::StartFnLangItem;
use rustc::ty::subst::Substs;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::ty::adjustment::CustomCoerceUnsized;
use rustc::dep_graph::{DepNode, WorkProduct};
use rustc::hir::map as hir_map;
Expand All @@ -51,7 +51,7 @@ use adt;
use attributes;
use builder::Builder;
use callee::{Callee};
use common::{BlockAndBuilder, C_bool, C_bytes_in_context, C_i32, C_uint};
use common::{C_bool, C_bytes_in_context, C_i32, C_uint};
use collector::{self, TransItemCollectionMode};
use common::{C_struct_in_context, C_u64, C_undef};
use common::{CrateContext, FunctionContext};
Expand Down Expand Up @@ -161,7 +161,7 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOp_) -> llvm::RealPredicate {
}

pub fn compare_simd_types<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
lhs: ValueRef,
rhs: ValueRef,
t: Ty<'tcx>,
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,

/// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer.
pub fn unsize_thin_ptr<'a, 'tcx>(
bcx: &BlockAndBuilder<'a, 'tcx>,
bcx: &Builder<'a, 'tcx>,
src: ValueRef,
src_ty: Ty<'tcx>,
dst_ty: Ty<'tcx>
Expand All @@ -242,7 +242,7 @@ pub fn unsize_thin_ptr<'a, 'tcx>(

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

let src_fields = def_a.variants[0].fields.iter().map(|f| {
monomorphize::field_ty(bcx.tcx(), substs_a, f)
monomorphize::field_ty(bcx.ccx.tcx(), substs_a, f)
});
let dst_fields = def_b.variants[0].fields.iter().map(|f| {
monomorphize::field_ty(bcx.tcx(), substs_b, f)
monomorphize::field_ty(bcx.ccx.tcx(), substs_b, f)
});

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

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

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

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

pub fn store_fat_ptr<'a, 'tcx>(cx: &BlockAndBuilder<'a, 'tcx>,
pub fn store_fat_ptr<'a, 'tcx>(cx: &Builder<'a, 'tcx>,
data: ValueRef,
extra: ValueRef,
dst: ValueRef,
Expand All @@ -459,15 +459,15 @@ pub fn load_fat_ptr<'a, 'tcx>(
(ptr, meta)
}

pub fn from_immediate(bcx: &BlockAndBuilder, val: ValueRef) -> ValueRef {
pub fn from_immediate(bcx: &Builder, val: ValueRef) -> ValueRef {
if val_ty(val) == Type::i1(bcx.ccx) {
bcx.zext(val, Type::i8(bcx.ccx))
} else {
val
}
}

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

pub fn memcpy_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>,
dst: ValueRef,
src: ValueRef,
t: Ty<'tcx>,
align: Option<u32>) {
pub fn memcpy_ty<'a, 'tcx>(
bcx: &Builder<'a, 'tcx>,
dst: ValueRef,
src: ValueRef,
t: Ty<'tcx>,
align: Option<u32>,
) {
let ccx = bcx.ccx;

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

pub fn alloc_ty<'a, 'tcx>(bcx: &BlockAndBuilder<'a, 'tcx>, ty: Ty<'tcx>, name: &str) -> ValueRef {
assert!(!ty.has_param_types());
bcx.fcx().alloca(type_of::type_of(bcx.ccx, ty), name)
}

pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
let _s = if ccx.sess().trans_stats() {
let mut instance_name = String::new();
Expand Down Expand Up @@ -623,7 +620,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// We create an alloca to hold a pointer of type `ret.original_ty`
// which will hold the pointer to the right alloca which has the
// final ret value
fcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
bcx.alloca(fn_ty.ret.memory_ty(ccx), "sret_slot")
};
let dest_val = adt::MaybeSizedValue::sized(dest); // Can return unsized value
let mut llarg_idx = fn_ty.ret.is_indirect() as usize;
Expand Down Expand Up @@ -756,12 +753,7 @@ pub fn maybe_create_entry_wrapper(ccx: &CrateContext) {
// `main` should respect same config for frame pointer elimination as rest of code
attributes::set_frame_pointer_elimination(ccx, llfn);

let llbb = unsafe {
let name = CString::new("top").unwrap();
llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), llfn, name.as_ptr())
};
let bld = Builder::with_ccx(ccx);
bld.position_at_end(llbb);
let bld = Builder::new_block(ccx, llfn, "top");

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

Expand Down
Loading