Skip to content

Commit 0fa8a59

Browse files
committed
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.
2 parents 832731d + f463a19 commit 0fa8a59

File tree

7 files changed

+11
-28
lines changed

7 files changed

+11
-28
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
11121112
llvm::LLVMGetParam(fcx.llfn, 0)
11131113
} else {
11141114
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
1115-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
1116-
Alloca(bcx, lloutputtype, "__make_return_pointer")
1115+
AllocaFcx(fcx, lloutputtype, "__make_return_pointer")
11171116
}
11181117
}
11191118
}
@@ -1154,7 +1153,6 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
11541153
llfn: llfndecl,
11551154
llenv: None,
11561155
llretptr: Cell::new(None),
1157-
entry_bcx: RefCell::new(None),
11581156
alloca_insert_pt: Cell::new(None),
11591157
llreturn: Cell::new(None),
11601158
personality: Cell::new(None),
@@ -1184,11 +1182,9 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
11841182
/// and allocating space for the return pointer.
11851183
pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
11861184
skip_retptr: bool,
1187-
output_type: ty::t) {
1185+
output_type: ty::t) -> &'a Block<'a> {
11881186
let entry_bcx = fcx.new_temp_block("entry-block");
11891187

1190-
*fcx.entry_bcx.borrow_mut() = Some(entry_bcx);
1191-
11921188
// Use a dummy instruction as the insertion point for all allocas.
11931189
// This is later removed in FunctionContext::cleanup.
11941190
fcx.alloca_insert_pt.set(Some(unsafe {
@@ -1210,6 +1206,8 @@ pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
12101206
fcx.llretptr.set(Some(make_return_pointer(fcx, substd_output_type)));
12111207
}
12121208
}
1209+
1210+
entry_bcx
12131211
}
12141212

12151213
// NB: must keep 4 fns in sync:
@@ -1364,15 +1362,11 @@ pub fn trans_closure(ccx: &CrateContext,
13641362
param_substs,
13651363
Some(body.span),
13661364
&arena);
1367-
init_function(&fcx, false, output_type);
1365+
let mut bcx = init_function(&fcx, false, output_type);
13681366

13691367
// cleanup scope for the incoming arguments
13701368
let arg_scope = fcx.push_custom_cleanup_scope();
13711369

1372-
// Create the first basic block in the function and keep a handle on it to
1373-
// pass to finish_fn later.
1374-
let bcx_top = fcx.entry_bcx.borrow().clone().unwrap();
1375-
let mut bcx = bcx_top;
13761370
let block_ty = node_id_type(bcx, body.id);
13771371

13781372
// Set up arguments to the function.
@@ -1499,14 +1493,12 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
14991493
let arena = TypedArena::new();
15001494
let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
15011495
param_substs, None, &arena);
1502-
init_function(&fcx, false, result_ty);
1496+
let bcx = init_function(&fcx, false, result_ty);
15031497

15041498
let arg_tys = ty::ty_fn_args(ctor_ty);
15051499

15061500
let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice());
15071501

1508-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
1509-
15101502
if !type_is_zero_size(fcx.ccx, result_ty) {
15111503
let repr = adt::represent_type(ccx, result_ty);
15121504
adt::trans_start_init(bcx, &*repr, fcx.llretptr.get().unwrap(), disr);

src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,9 @@ pub fn trans_unboxing_shim(bcx: &Block,
277277
&empty_param_substs,
278278
None,
279279
&block_arena);
280-
init_function(&fcx, false, return_type);
280+
let mut bcx = init_function(&fcx, false, return_type);
281281

282282
// Create the substituted versions of the self type.
283-
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
284283
let arg_scope = fcx.push_custom_cleanup_scope();
285284
let arg_scope_id = cleanup::CustomScope(arg_scope);
286285
let boxed_arg_types = ty::ty_fn_args(boxed_function_type);

src/librustc/middle/trans/closure.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
424424
let empty_param_substs = param_substs::empty();
425425
let fcx = new_fn_ctxt(ccx, llfn, -1, true, f.sig.output,
426426
&empty_param_substs, None, &arena);
427-
init_function(&fcx, true, f.sig.output);
428-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
427+
let bcx = init_function(&fcx, true, f.sig.output);
429428

430429
let args = create_datums_for_fn_args(&fcx,
431430
ty::ty_fn_args(closure_ty)

src/librustc/middle/trans/common.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,6 @@ pub struct FunctionContext<'a> {
239239
// always be Some.
240240
pub llretptr: Cell<Option<ValueRef>>,
241241

242-
pub entry_bcx: RefCell<Option<&'a Block<'a>>>,
243-
244242
// These pub elements: "hoisted basic blocks" containing
245243
// administrative activities that have to happen in only one place in
246244
// the function, due to LLVM's quirks.
@@ -322,8 +320,6 @@ impl<'a> FunctionContext<'a> {
322320
.get()
323321
.unwrap());
324322
}
325-
// Remove the cycle between fcx and bcx, so memory can be freed
326-
*self.entry_bcx.borrow_mut() = None;
327323
}
328324

329325
pub fn get_llreturn(&self) -> BasicBlockRef {

src/librustc/middle/trans/glue.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ fn make_generic_glue(ccx: &CrateContext,
490490
let fcx = new_fn_ctxt(ccx, llfn, -1, false, ty::mk_nil(),
491491
&empty_param_substs, None, &arena);
492492

493-
init_function(&fcx, false, ty::mk_nil());
493+
let bcx = init_function(&fcx, false, ty::mk_nil());
494494

495495
lib::llvm::SetLinkage(llfn, lib::llvm::InternalLinkage);
496496
ccx.stats.n_glues_created.set(ccx.stats.n_glues_created.get() + 1u);
@@ -502,7 +502,6 @@ fn make_generic_glue(ccx: &CrateContext,
502502
// llfn is expected be declared to take a parameter of the appropriate
503503
// type, so we don't need to explicitly cast the function parameter.
504504

505-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
506505
let llrawptr0 = unsafe { llvm::LLVMGetParam(llfn, fcx.arg_pos(0) as c_uint) };
507506
let bcx = helper(bcx, llrawptr0, t);
508507
finish_fn(&fcx, bcx);

src/librustc/middle/trans/intrinsic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,10 @@ pub fn trans_intrinsic(ccx: &CrateContext,
188188
let arena = TypedArena::new();
189189
let fcx = new_fn_ctxt(ccx, decl, item.id, false, output_type,
190190
substs, Some(item.span), &arena);
191-
init_function(&fcx, true, output_type);
191+
let mut bcx = init_function(&fcx, true, output_type);
192192

193193
set_always_inline(fcx.llfn);
194194

195-
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
196195
let first_real_arg = fcx.arg_pos(0u);
197196

198197
let name = token::get_ident(item.ident);

src/librustc/middle/trans/reflect.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ impl<'a, 'b> Reflector<'a, 'b> {
313313
let fcx = new_fn_ctxt(ccx, llfdecl, -1, false,
314314
ty::mk_u64(), &empty_param_substs,
315315
None, &arena);
316-
init_function(&fcx, false, ty::mk_u64());
316+
let bcx = init_function(&fcx, false, ty::mk_u64());
317317

318318
let arg = unsafe {
319319
//
@@ -323,7 +323,6 @@ impl<'a, 'b> Reflector<'a, 'b> {
323323
//
324324
llvm::LLVMGetParam(llfdecl, fcx.arg_pos(0u) as c_uint)
325325
};
326-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
327326
let arg = BitCast(bcx, arg, llptrty);
328327
let ret = adt::trans_get_discr(bcx, &*repr, arg, Some(Type::i64(ccx)));
329328
Store(bcx, ret, fcx.llretptr.get().unwrap());

0 commit comments

Comments
 (0)