@@ -68,7 +68,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
68
68
target : mir:: BasicBlock ,
69
69
) -> ( Bx :: BasicBlock , bool ) {
70
70
let span = self . terminator . source_info . span ;
71
- let lltarget = fx. blocks [ target] ;
71
+ let lltarget = fx. llbb ( target) ;
72
72
let target_funclet = fx. cleanup_kinds [ target] . funclet_bb ( target) ;
73
73
match ( self . funclet_bb , target_funclet) {
74
74
( None , None ) => ( lltarget, false ) ,
@@ -133,13 +133,13 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
133
133
// If there is a cleanup block and the function we're calling can unwind, then
134
134
// do an invoke, otherwise do a call.
135
135
if let Some ( cleanup) = cleanup. filter ( |_| fn_abi. can_unwind ) {
136
- let ret_bx = if let Some ( ( _, target) ) = destination {
137
- fx. blocks [ target]
136
+ let ret_llbb = if let Some ( ( _, target) ) = destination {
137
+ fx. llbb ( target)
138
138
} else {
139
139
fx. unreachable_block ( )
140
140
} ;
141
141
let invokeret =
142
- bx. invoke ( fn_ptr, & llargs, ret_bx , self . llblock ( fx, cleanup) , self . funclet ( fx) ) ;
142
+ bx. invoke ( fn_ptr, & llargs, ret_llbb , self . llblock ( fx, cleanup) , self . funclet ( fx) ) ;
143
143
bx. apply_attrs_callsite ( & fn_abi, invokeret) ;
144
144
145
145
if let Some ( ( ret_dest, target) ) = destination {
@@ -1205,7 +1205,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1205
1205
1206
1206
// FIXME(eddyb) rename this to `eh_pad_for_uncached`.
1207
1207
fn landing_pad_for_uncached ( & mut self , bb : mir:: BasicBlock ) -> Bx :: BasicBlock {
1208
- let llbb = self . blocks [ bb ] ;
1208
+ let llbb = self . llbb ( bb ) ;
1209
1209
if base:: wants_msvc_seh ( self . cx . sess ( ) ) {
1210
1210
let funclet;
1211
1211
let ret_llbb;
@@ -1293,9 +1293,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
1293
1293
Bx :: new_block ( self . cx , self . llfn , name)
1294
1294
}
1295
1295
1296
- pub fn build_block ( & self , bb : mir:: BasicBlock ) -> Bx {
1296
+ /// Get the backend `BasicBlock` for a MIR `BasicBlock`, either already
1297
+ /// cached in `self.cached_llbbs`, or created on demand (and cached).
1298
+ // FIXME(eddyb) rename `llbb` and other `ll`-prefixed things to use a
1299
+ // more backend-agnostic prefix such as `cg` (i.e. this would be `cgbb`).
1300
+ pub fn llbb ( & mut self , bb : mir:: BasicBlock ) -> Bx :: BasicBlock {
1301
+ self . cached_llbbs [ bb] . unwrap_or_else ( || {
1302
+ // FIXME(eddyb) only name the block if `fewer_names` is `false`.
1303
+ // FIXME(eddyb) create the block directly, without a builder.
1304
+ let llbb = self . new_block ( & format ! ( "{:?}" , bb) ) . llbb ( ) ;
1305
+ self . cached_llbbs [ bb] = Some ( llbb) ;
1306
+ llbb
1307
+ } )
1308
+ }
1309
+
1310
+ pub fn build_block ( & mut self , bb : mir:: BasicBlock ) -> Bx {
1297
1311
let mut bx = Bx :: with_cx ( self . cx ) ;
1298
- bx. position_at_end ( self . blocks [ bb ] ) ;
1312
+ bx. position_at_end ( self . llbb ( bb ) ) ;
1299
1313
bx
1300
1314
}
1301
1315
0 commit comments