@@ -68,7 +68,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
6868 target : mir:: BasicBlock ,
6969 ) -> ( Bx :: BasicBlock , bool ) {
7070 let span = self . terminator . source_info . span ;
71- let lltarget = fx. blocks [ target] ;
71+ let lltarget = fx. llbb ( target) ;
7272 let target_funclet = fx. cleanup_kinds [ target] . funclet_bb ( target) ;
7373 match ( self . funclet_bb , target_funclet) {
7474 ( None , None ) => ( lltarget, false ) ,
@@ -133,13 +133,13 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
133133 // If there is a cleanup block and the function we're calling can unwind, then
134134 // do an invoke, otherwise do a call.
135135 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)
138138 } else {
139139 fx. unreachable_block ( )
140140 } ;
141141 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) ) ;
143143 bx. apply_attrs_callsite ( & fn_abi, invokeret) ;
144144
145145 if let Some ( ( ret_dest, target) ) = destination {
@@ -1205,7 +1205,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12051205
12061206 // FIXME(eddyb) rename this to `eh_pad_for_uncached`.
12071207 fn landing_pad_for_uncached ( & mut self , bb : mir:: BasicBlock ) -> Bx :: BasicBlock {
1208- let llbb = self . blocks [ bb ] ;
1208+ let llbb = self . llbb ( bb ) ;
12091209 if base:: wants_msvc_seh ( self . cx . sess ( ) ) {
12101210 let funclet;
12111211 let ret_llbb;
@@ -1293,9 +1293,23 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12931293 Bx :: new_block ( self . cx , self . llfn , name)
12941294 }
12951295
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 {
12971311 let mut bx = Bx :: with_cx ( self . cx ) ;
1298- bx. position_at_end ( self . blocks [ bb ] ) ;
1312+ bx. position_at_end ( self . llbb ( bb ) ) ;
12991313 bx
13001314 }
13011315
0 commit comments