auto merge of #15439 : dotdash/rust/remove_entry_bcx, r=pcwalton

We no longer need to refer to the entry block from arbitrary places, so
we can drop it from FunctionContext.
This commit is contained in:
bors 2014-07-06 04:01:39 +00:00
commit 0fa8a598f6
7 changed files with 11 additions and 28 deletions

View File

@ -1112,8 +1112,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
llvm::LLVMGetParam(fcx.llfn, 0)
} else {
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
Alloca(bcx, lloutputtype, "__make_return_pointer")
AllocaFcx(fcx, lloutputtype, "__make_return_pointer")
}
}
}
@ -1154,7 +1153,6 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
llfn: llfndecl,
llenv: None,
llretptr: Cell::new(None),
entry_bcx: RefCell::new(None),
alloca_insert_pt: Cell::new(None),
llreturn: Cell::new(None),
personality: Cell::new(None),
@ -1184,11 +1182,9 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
/// and allocating space for the return pointer.
pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
skip_retptr: bool,
output_type: ty::t) {
output_type: ty::t) -> &'a Block<'a> {
let entry_bcx = fcx.new_temp_block("entry-block");
*fcx.entry_bcx.borrow_mut() = Some(entry_bcx);
// Use a dummy instruction as the insertion point for all allocas.
// This is later removed in FunctionContext::cleanup.
fcx.alloca_insert_pt.set(Some(unsafe {
@ -1210,6 +1206,8 @@ pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
fcx.llretptr.set(Some(make_return_pointer(fcx, substd_output_type)));
}
}
entry_bcx
}
// NB: must keep 4 fns in sync:
@ -1364,15 +1362,11 @@ pub fn trans_closure(ccx: &CrateContext,
param_substs,
Some(body.span),
&arena);
init_function(&fcx, false, output_type);
let mut bcx = init_function(&fcx, false, output_type);
// cleanup scope for the incoming arguments
let arg_scope = fcx.push_custom_cleanup_scope();
// Create the first basic block in the function and keep a handle on it to
// pass to finish_fn later.
let bcx_top = fcx.entry_bcx.borrow().clone().unwrap();
let mut bcx = bcx_top;
let block_ty = node_id_type(bcx, body.id);
// Set up arguments to the function.
@ -1499,14 +1493,12 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
let arena = TypedArena::new();
let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
param_substs, None, &arena);
init_function(&fcx, false, result_ty);
let bcx = init_function(&fcx, false, result_ty);
let arg_tys = ty::ty_fn_args(ctor_ty);
let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice());
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
if !type_is_zero_size(fcx.ccx, result_ty) {
let repr = adt::represent_type(ccx, result_ty);
adt::trans_start_init(bcx, &*repr, fcx.llretptr.get().unwrap(), disr);

View File

@ -277,10 +277,9 @@ pub fn trans_unboxing_shim(bcx: &Block,
&empty_param_substs,
None,
&block_arena);
init_function(&fcx, false, return_type);
let mut bcx = init_function(&fcx, false, return_type);
// Create the substituted versions of the self type.
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
let arg_scope = fcx.push_custom_cleanup_scope();
let arg_scope_id = cleanup::CustomScope(arg_scope);
let boxed_arg_types = ty::ty_fn_args(boxed_function_type);

View File

@ -424,8 +424,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
let empty_param_substs = param_substs::empty();
let fcx = new_fn_ctxt(ccx, llfn, -1, true, f.sig.output,
&empty_param_substs, None, &arena);
init_function(&fcx, true, f.sig.output);
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
let bcx = init_function(&fcx, true, f.sig.output);
let args = create_datums_for_fn_args(&fcx,
ty::ty_fn_args(closure_ty)

View File

@ -239,8 +239,6 @@ pub struct FunctionContext<'a> {
// always be Some.
pub llretptr: Cell<Option<ValueRef>>,
pub entry_bcx: RefCell<Option<&'a Block<'a>>>,
// These pub elements: "hoisted basic blocks" containing
// administrative activities that have to happen in only one place in
// the function, due to LLVM's quirks.
@ -322,8 +320,6 @@ impl<'a> FunctionContext<'a> {
.get()
.unwrap());
}
// Remove the cycle between fcx and bcx, so memory can be freed
*self.entry_bcx.borrow_mut() = None;
}
pub fn get_llreturn(&self) -> BasicBlockRef {

View File

@ -490,7 +490,7 @@ fn make_generic_glue(ccx: &CrateContext,
let fcx = new_fn_ctxt(ccx, llfn, -1, false, ty::mk_nil(),
&empty_param_substs, None, &arena);
init_function(&fcx, false, ty::mk_nil());
let bcx = init_function(&fcx, false, ty::mk_nil());
lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage);
ccx.stats.n_glues_created.set(ccx.stats.n_glues_created.get() + 1u);
@ -502,7 +502,6 @@ fn make_generic_glue(ccx: &CrateContext,
// llfn is expected be declared to take a parameter of the appropriate
// type, so we don't need to explicitly cast the function parameter.
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, fcx.arg_pos(0) as c_uint) };
let bcx = helper(bcx, llrawptr0, t);
finish_fn(&fcx, bcx);

View File

@ -188,11 +188,10 @@ pub fn trans_intrinsic(ccx: &CrateContext,
let arena = TypedArena::new();
let fcx = new_fn_ctxt(ccx, decl, item.id, false, output_type,
substs, Some(item.span), &arena);
init_function(&fcx, true, output_type);
let mut bcx = init_function(&fcx, true, output_type);
set_always_inline(fcx.llfn);
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
let first_real_arg = fcx.arg_pos(0u);
let name = token::get_ident(item.ident);

View File

@ -313,7 +313,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
let fcx = new_fn_ctxt(ccx, llfdecl, -1, false,
ty::mk_u64(), &empty_param_substs,
None, &arena);
init_function(&fcx, false, ty::mk_u64());
let bcx = init_function(&fcx, false, ty::mk_u64());
let arg = unsafe {
//
@ -323,7 +323,6 @@ impl<'a, 'b> Reflector<'a, 'b> {
//
llvm::LLVMGetParam(llfdecl, fcx.arg_pos(0u) as c_uint)
};
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
let arg = BitCast(bcx, arg, llptrty);
let ret = adt::trans_get_discr(bcx, &*repr, arg, Some(Type::i64(ccx)));
Store(bcx, ret, fcx.llretptr.get().unwrap());