Skip to content

Commit f463a19

Browse files
committed
Remove entry_bcx from FunctionContext
We no longer need to refer to the entry block from arbitrary places, so we can drop it from FunctionContext.
1 parent db44468 commit f463a19

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
@@ -1113,8 +1113,7 @@ pub fn make_return_pointer(fcx: &FunctionContext, output_type: ty::t)
11131113
llvm::LLVMGetParam(fcx.llfn, 0)
11141114
} else {
11151115
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
1116-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
1117-
Alloca(bcx, lloutputtype, "__make_return_pointer")
1116+
AllocaFcx(fcx, lloutputtype, "__make_return_pointer")
11181117
}
11191118
}
11201119
}
@@ -1155,7 +1154,6 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
11551154
llfn: llfndecl,
11561155
llenv: None,
11571156
llretptr: Cell::new(None),
1158-
entry_bcx: RefCell::new(None),
11591157
alloca_insert_pt: Cell::new(None),
11601158
llreturn: Cell::new(None),
11611159
personality: Cell::new(None),
@@ -1185,11 +1183,9 @@ pub fn new_fn_ctxt<'a>(ccx: &'a CrateContext,
11851183
/// and allocating space for the return pointer.
11861184
pub fn init_function<'a>(fcx: &'a FunctionContext<'a>,
11871185
skip_retptr: bool,
1188-
output_type: ty::t) {
1186+
output_type: ty::t) -> &'a Block<'a> {
11891187
let entry_bcx = fcx.new_temp_block("entry-block");
11901188

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

12161214
// NB: must keep 4 fns in sync:
@@ -1365,15 +1363,11 @@ pub fn trans_closure(ccx: &CrateContext,
13651363
param_substs,
13661364
Some(body.span),
13671365
&arena);
1368-
init_function(&fcx, false, output_type);
1366+
let mut bcx = init_function(&fcx, false, output_type);
13691367

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

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

13791373
// Set up arguments to the function.
@@ -1500,14 +1494,12 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
15001494
let arena = TypedArena::new();
15011495
let fcx = new_fn_ctxt(ccx, llfndecl, ctor_id, false, result_ty,
15021496
param_substs, None, &arena);
1503-
init_function(&fcx, false, result_ty);
1497+
let bcx = init_function(&fcx, false, result_ty);
15041498

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

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

1509-
let bcx = fcx.entry_bcx.borrow().clone().unwrap();
1510-
15111503
if !type_is_zero_size(fcx.ccx, result_ty) {
15121504
let repr = adt::represent_type(ccx, result_ty);
15131505
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
@@ -279,10 +279,9 @@ pub fn trans_unboxing_shim(bcx: &Block,
279279
&empty_param_substs,
280280
None,
281281
&block_arena);
282-
init_function(&fcx, false, return_type);
282+
let mut bcx = init_function(&fcx, false, return_type);
283283

284284
// Create the substituted versions of the self type.
285-
let mut bcx = fcx.entry_bcx.borrow().clone().unwrap();
286285
let arg_scope = fcx.push_custom_cleanup_scope();
287286
let arg_scope_id = cleanup::CustomScope(arg_scope);
288287
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)