@@ -44,7 +44,7 @@ use super::operand::OperandValue::{Pair, Ref, Immediate};
44
44
impl < ' a , ' tcx > MirContext < ' a , ' tcx > {
45
45
pub fn trans_block ( & mut self , bb : mir:: BasicBlock ,
46
46
funclets : & IndexVec < mir:: BasicBlock , Option < Funclet > > ) {
47
- let mut bcx = self . build_block ( bb) ;
47
+ let mut bcx = self . get_builder ( bb) ;
48
48
let data = & self . mir [ bb] ;
49
49
50
50
debug ! ( "trans_block({:?}={:?})" , bb, data) ;
@@ -75,7 +75,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
75
75
}
76
76
} ;
77
77
78
- let llblock = |this : & mut Self , bcx : & Builder , target : mir:: BasicBlock | {
78
+ let llblock = |this : & mut Self , target : mir:: BasicBlock | {
79
79
let lltarget = this. blocks [ target] ;
80
80
81
81
if let Some ( cp) = cleanup_pad {
@@ -85,7 +85,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
85
85
86
86
debug ! ( "llblock: creating cleanup trampoline for {:?}" , target) ;
87
87
let name = & format ! ( "{:?}_cleanup_trampoline_{:?}" , bb, target) ;
88
- let trampoline = bcx . build_new_block ( name) ;
88
+ let trampoline = this . new_block ( name) ;
89
89
trampoline. cleanup_ret ( cp, Some ( lltarget) ) ;
90
90
trampoline. llbb ( )
91
91
}
@@ -139,8 +139,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
139
139
mir:: TerminatorKind :: If { ref cond, targets : ( true_bb, false_bb) } => {
140
140
let cond = self . trans_operand ( & bcx, cond) ;
141
141
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) ;
144
144
bcx. cond_br ( cond. immediate ( ) , lltrue, llfalse) ;
145
145
}
146
146
@@ -159,7 +159,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
159
159
// code. This is especially helpful in cases like an if-let on a huge enum.
160
160
// Note: This optimization is only valid for exhaustive matches.
161
161
Some ( ( & & bb, & c) ) if c > targets. len ( ) / 2 => {
162
- ( Some ( bb) , llblock ( self , & bcx , bb) )
162
+ ( Some ( bb) , llblock ( self , bb) )
163
163
}
164
164
// We're generating an exhaustive switch, so the else branch
165
165
// can't be hit. Branching to an unreachable instruction
@@ -170,7 +170,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
170
170
assert_eq ! ( adt_def. variants. len( ) , targets. len( ) ) ;
171
171
for ( adt_variant, & target) in adt_def. variants . iter ( ) . zip ( targets) {
172
172
if default_bb != Some ( target) {
173
- let llbb = llblock ( self , & bcx , target) ;
173
+ let llbb = llblock ( self , target) ;
174
174
let llval = adt:: trans_case ( & bcx, ty, Disr :: from ( adt_variant. disr_val ) ) ;
175
175
bcx. add_case ( switch, llval, llbb)
176
176
}
@@ -181,10 +181,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
181
181
let ( otherwise, targets) = targets. split_last ( ) . unwrap ( ) ;
182
182
let discr = bcx. load ( self . trans_lvalue ( & bcx, discr) . llval ) ;
183
183
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 ( ) ) ;
185
185
for ( value, target) in values. iter ( ) . zip ( targets) {
186
186
let val = Const :: from_constval ( bcx. ccx , value. clone ( ) , switch_ty) ;
187
- let llbb = llblock ( self , & bcx , * target) ;
187
+ let llbb = llblock ( self , * target) ;
188
188
bcx. add_case ( switch, val. llval , llbb)
189
189
}
190
190
}
@@ -261,7 +261,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
261
261
drop_fn,
262
262
args,
263
263
self . blocks [ target] ,
264
- llblock ( self , & bcx , unwind) ,
264
+ llblock ( self , unwind) ,
265
265
cleanup_bundle
266
266
) ;
267
267
} else {
@@ -301,8 +301,8 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
301
301
let cond = bcx. call ( expect, & [ cond, C_bool ( bcx. ccx , expected) ] , None ) ;
302
302
303
303
// 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" ) ;
306
306
if expected {
307
307
bcx. cond_br ( cond, lltarget, panic_block. llbb ( ) ) ;
308
308
} else {
@@ -382,7 +382,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
382
382
bcx. invoke ( llfn,
383
383
& args,
384
384
self . unreachable_block ( ) ,
385
- llblock ( self , & bcx , unwind) ,
385
+ llblock ( self , unwind) ,
386
386
cleanup_bundle) ;
387
387
} else {
388
388
bcx. call ( llfn, & args, cleanup_bundle) ;
@@ -580,12 +580,12 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
580
580
let invokeret = bcx. invoke ( fn_ptr,
581
581
& llargs,
582
582
ret_bcx,
583
- llblock ( self , & bcx , cleanup) ,
583
+ llblock ( self , cleanup) ,
584
584
cleanup_bundle) ;
585
585
fn_ty. apply_attrs_callsite ( invokeret) ;
586
586
587
587
if let Some ( ( _, target) ) = * destination {
588
- let ret_bcx = self . build_block ( target) ;
588
+ let ret_bcx = self . get_builder ( target) ;
589
589
ret_bcx. position_at_start ( ret_bcx. llbb ( ) ) ;
590
590
self . set_debug_loc ( & ret_bcx, terminator. source_info ) ;
591
591
let op = OperandRef {
@@ -791,9 +791,9 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
791
791
return self . blocks [ target_bb] ;
792
792
}
793
793
794
- let target = self . build_block ( target_bb) ;
794
+ let target = self . get_builder ( target_bb) ;
795
795
796
- let bcx = target . build_new_block ( "cleanup" ) ;
796
+ let bcx = self . new_block ( "cleanup" ) ;
797
797
self . landing_pads [ target_bb] = Some ( bcx. llbb ( ) ) ;
798
798
799
799
let ccx = bcx. ccx ;
@@ -809,14 +809,18 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
809
809
810
810
fn unreachable_block ( & mut self ) -> BasicBlockRef {
811
811
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" ) ;
813
813
bl. unreachable ( ) ;
814
814
self . unreachable_block = Some ( bl. llbb ( ) ) ;
815
815
bl. llbb ( )
816
816
} )
817
817
}
818
818
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 > {
820
824
let builder = Builder :: with_ccx ( self . ccx ) ;
821
825
builder. position_at_end ( self . blocks [ bb] ) ;
822
826
builder
0 commit comments