Skip to content

Commit f67e7d6

Browse files
Add method, new_block, to MirContext for block construction.
This makes a slow transition to block construction happening only from MirContext easier.
1 parent 937e8da commit f67e7d6

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

src/librustc_trans/mir/block.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use super::operand::OperandValue::{Pair, Ref, Immediate};
4444
impl<'a, 'tcx> MirContext<'a, 'tcx> {
4545
pub fn trans_block(&mut self, bb: mir::BasicBlock,
4646
funclets: &IndexVec<mir::BasicBlock, Option<Funclet>>) {
47-
let mut bcx = self.build_block(bb);
47+
let mut bcx = self.get_builder(bb);
4848
let data = &self.mir[bb];
4949

5050
debug!("trans_block({:?}={:?})", bb, data);
@@ -75,7 +75,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
7575
}
7676
};
7777

78-
let llblock = |this: &mut Self, bcx: &Builder, target: mir::BasicBlock| {
78+
let llblock = |this: &mut Self, target: mir::BasicBlock| {
7979
let lltarget = this.blocks[target];
8080

8181
if let Some(cp) = cleanup_pad {
@@ -85,7 +85,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
8585

8686
debug!("llblock: creating cleanup trampoline for {:?}", target);
8787
let name = &format!("{:?}_cleanup_trampoline_{:?}", bb, target);
88-
let trampoline = bcx.build_new_block(name);
88+
let trampoline = this.new_block(name);
8989
trampoline.cleanup_ret(cp, Some(lltarget));
9090
trampoline.llbb()
9191
}
@@ -139,8 +139,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
139139
mir::TerminatorKind::If { ref cond, targets: (true_bb, false_bb) } => {
140140
let cond = self.trans_operand(&bcx, cond);
141141

142-
let lltrue = llblock(self, &bcx, true_bb);
143-
let llfalse = llblock(self, &bcx, false_bb);
142+
let lltrue = llblock(self, true_bb);
143+
let llfalse = llblock(self, false_bb);
144144
bcx.cond_br(cond.immediate(), lltrue, llfalse);
145145
}
146146

@@ -159,7 +159,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
159159
// code. This is especially helpful in cases like an if-let on a huge enum.
160160
// Note: This optimization is only valid for exhaustive matches.
161161
Some((&&bb, &c)) if c > targets.len() / 2 => {
162-
(Some(bb), llblock(self, &bcx, bb))
162+
(Some(bb), llblock(self, bb))
163163
}
164164
// We're generating an exhaustive switch, so the else branch
165165
// can't be hit. Branching to an unreachable instruction
@@ -170,7 +170,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
170170
assert_eq!(adt_def.variants.len(), targets.len());
171171
for (adt_variant, &target) in adt_def.variants.iter().zip(targets) {
172172
if default_bb != Some(target) {
173-
let llbb = llblock(self, &bcx, target);
173+
let llbb = llblock(self, target);
174174
let llval = adt::trans_case(&bcx, ty, Disr::from(adt_variant.disr_val));
175175
bcx.add_case(switch, llval, llbb)
176176
}
@@ -181,10 +181,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
181181
let (otherwise, targets) = targets.split_last().unwrap();
182182
let discr = bcx.load(self.trans_lvalue(&bcx, discr).llval);
183183
let discr = base::to_immediate(&bcx, discr, switch_ty);
184-
let switch = bcx.switch(discr, llblock(self, &bcx, *otherwise), values.len());
184+
let switch = bcx.switch(discr, llblock(self, *otherwise), values.len());
185185
for (value, target) in values.iter().zip(targets) {
186186
let val = Const::from_constval(bcx.ccx, value.clone(), switch_ty);
187-
let llbb = llblock(self, &bcx, *target);
187+
let llbb = llblock(self, *target);
188188
bcx.add_case(switch, val.llval, llbb)
189189
}
190190
}
@@ -261,7 +261,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
261261
drop_fn,
262262
args,
263263
self.blocks[target],
264-
llblock(self, &bcx, unwind),
264+
llblock(self, unwind),
265265
cleanup_bundle
266266
);
267267
} else {
@@ -301,8 +301,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
301301
let cond = bcx.call(expect, &[cond, C_bool(bcx.ccx, expected)], None);
302302

303303
// Create the failure block and the conditional branch to it.
304-
let lltarget = llblock(self, &bcx, target);
305-
let panic_block = bcx.build_new_block("panic");
304+
let lltarget = llblock(self, target);
305+
let panic_block = self.new_block("panic");
306306
if expected {
307307
bcx.cond_br(cond, lltarget, panic_block.llbb());
308308
} else {
@@ -382,7 +382,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
382382
bcx.invoke(llfn,
383383
&args,
384384
self.unreachable_block(),
385-
llblock(self, &bcx, unwind),
385+
llblock(self, unwind),
386386
cleanup_bundle);
387387
} else {
388388
bcx.call(llfn, &args, cleanup_bundle);
@@ -580,12 +580,12 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
580580
let invokeret = bcx.invoke(fn_ptr,
581581
&llargs,
582582
ret_bcx,
583-
llblock(self, &bcx, cleanup),
583+
llblock(self, cleanup),
584584
cleanup_bundle);
585585
fn_ty.apply_attrs_callsite(invokeret);
586586

587587
if let Some((_, target)) = *destination {
588-
let ret_bcx = self.build_block(target);
588+
let ret_bcx = self.get_builder(target);
589589
ret_bcx.position_at_start(ret_bcx.llbb());
590590
self.set_debug_loc(&ret_bcx, terminator.source_info);
591591
let op = OperandRef {
@@ -791,9 +791,9 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
791791
return self.blocks[target_bb];
792792
}
793793

794-
let target = self.build_block(target_bb);
794+
let target = self.get_builder(target_bb);
795795

796-
let bcx = target.build_new_block("cleanup");
796+
let bcx = self.new_block("cleanup");
797797
self.landing_pads[target_bb] = Some(bcx.llbb());
798798

799799
let ccx = bcx.ccx;
@@ -809,14 +809,18 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
809809

810810
fn unreachable_block(&mut self) -> BasicBlockRef {
811811
self.unreachable_block.unwrap_or_else(|| {
812-
let bl = self.build_block(mir::START_BLOCK).build_new_block("unreachable");
812+
let bl = self.new_block("unreachable");
813813
bl.unreachable();
814814
self.unreachable_block = Some(bl.llbb());
815815
bl.llbb()
816816
})
817817
}
818818

819-
pub fn build_block(&self, bb: mir::BasicBlock) -> Builder<'a, 'tcx> {
819+
pub fn new_block(&self, name: &str) -> Builder<'a, 'tcx> {
820+
Builder::new_block(self.ccx, self.llfn, name)
821+
}
822+
823+
pub fn get_builder(&self, bb: mir::BasicBlock) -> Builder<'a, 'tcx> {
820824
let builder = Builder::with_ccx(self.ccx);
821825
builder.position_at_end(self.blocks[bb]);
822826
builder

src/librustc_trans/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
326326
let funclets: IndexVec<mir::BasicBlock, Option<Funclet>> =
327327
mircx.cleanup_kinds.iter_enumerated().map(|(bb, cleanup_kind)| {
328328
if let CleanupKind::Funclet = *cleanup_kind {
329-
let bcx = mircx.build_block(bb);
329+
let bcx = mircx.get_builder(bb);
330330
bcx.set_personality_fn(mircx.ccx.eh_personality());
331331
if base::wants_msvc_seh(ccx.sess()) {
332332
return Some(Funclet::new(bcx.cleanup_pad(None, &[])));

0 commit comments

Comments
 (0)