@@ -80,15 +80,15 @@ impl EnumClone for AtomicOrdering {
8080
8181pub struct Builder < ' a : ' gcc , ' gcc , ' tcx > {
8282 pub cx : & ' a CodegenCx < ' gcc , ' tcx > ,
83- pub block : Option < Block < ' gcc > > ,
83+ pub block : Block < ' gcc > ,
8484 stack_var_count : Cell < usize > ,
8585}
8686
8787impl < ' a , ' gcc , ' tcx > Builder < ' a , ' gcc , ' tcx > {
88- fn with_cx ( cx : & ' a CodegenCx < ' gcc , ' tcx > ) -> Self {
88+ fn with_cx ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Self {
8989 Builder {
9090 cx,
91- block : None ,
91+ block,
9292 stack_var_count : Cell :: new ( 0 ) ,
9393 }
9494 }
@@ -243,7 +243,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
243243 }
244244
245245 pub fn current_func ( & self ) -> Function < ' gcc > {
246- self . block . expect ( "block" ) . get_function ( )
246+ self . block . get_function ( )
247247 }
248248
249249 fn function_call ( & mut self , func : RValue < ' gcc > , args : & [ RValue < ' gcc > ] , _funclet : Option < & Funclet > ) -> RValue < ' gcc > {
@@ -254,17 +254,16 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
254254 // gccjit requires to use the result of functions, even when it's not used.
255255 // That's why we assign the result to a local or call add_eval().
256256 let return_type = func. get_return_type ( ) ;
257- let current_block = self . current_block . borrow ( ) . expect ( "block" ) ;
258257 let void_type = self . context . new_type :: < ( ) > ( ) ;
259- let current_func = current_block . get_function ( ) ;
258+ let current_func = self . block . get_function ( ) ;
260259 if return_type != void_type {
261260 unsafe { RETURN_VALUE_COUNT += 1 } ;
262261 let result = current_func. new_local ( None , return_type, & format ! ( "returnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ) ;
263- current_block . add_assignment ( None , result, self . cx . context . new_call ( None , func, & args) ) ;
262+ self . block . add_assignment ( None , result, self . cx . context . new_call ( None , func, & args) ) ;
264263 result. to_rvalue ( )
265264 }
266265 else {
267- current_block . add_eval ( None , self . cx . context . new_call ( None , func, & args) ) ;
266+ self . block . add_eval ( None , self . cx . context . new_call ( None , func, & args) ) ;
268267 // Return dummy value when not having return value.
269268 self . context . new_rvalue_from_long ( self . isize_type , 0 )
270269 }
@@ -277,9 +276,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
277276 // That's why we assign the result to a local or call add_eval().
278277 let gcc_func = func_ptr. get_type ( ) . dyncast_function_ptr_type ( ) . expect ( "function ptr" ) ;
279278 let mut return_type = gcc_func. get_return_type ( ) ;
280- let current_block = self . current_block . borrow ( ) . expect ( "block" ) ;
281279 let void_type = self . context . new_type :: < ( ) > ( ) ;
282- let current_func = current_block . get_function ( ) ;
280+ let current_func = self . block . get_function ( ) ;
283281
284282 // FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
285283 if gcc_func. get_param_count ( ) == 0 && format ! ( "{:?}" , func_ptr) == "__builtin_ia32_pmovmskb128" {
@@ -289,20 +287,20 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
289287 if return_type != void_type {
290288 unsafe { RETURN_VALUE_COUNT += 1 } ;
291289 let result = current_func. new_local ( None , return_type, & format ! ( "ptrReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ) ;
292- current_block . add_assignment ( None , result, self . cx . context . new_call_through_ptr ( None , func_ptr, & args) ) ;
290+ self . block . add_assignment ( None , result, self . cx . context . new_call_through_ptr ( None , func_ptr, & args) ) ;
293291 result. to_rvalue ( )
294292 }
295293 else {
296294 if gcc_func. get_param_count ( ) == 0 {
297295 // FIXME(antoyo): As a temporary workaround for unsupported LLVM intrinsics.
298- current_block . add_eval ( None , self . cx . context . new_call_through_ptr ( None , func_ptr, & [ ] ) ) ;
296+ self . block . add_eval ( None , self . cx . context . new_call_through_ptr ( None , func_ptr, & [ ] ) ) ;
299297 }
300298 else {
301- current_block . add_eval ( None , self . cx . context . new_call_through_ptr ( None , func_ptr, & args) ) ;
299+ self . block . add_eval ( None , self . cx . context . new_call_through_ptr ( None , func_ptr, & args) ) ;
302300 }
303301 // Return dummy value when not having return value.
304302 let result = current_func. new_local ( None , self . isize_type , "dummyValueThatShouldNeverBeUsed" ) ;
305- current_block . add_assignment ( None , result, self . context . new_rvalue_from_long ( self . isize_type , 0 ) ) ;
303+ self . block . add_assignment ( None , result, self . context . new_rvalue_from_long ( self . isize_type , 0 ) ) ;
306304 result. to_rvalue ( )
307305 }
308306 }
@@ -311,12 +309,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
311309 // gccjit requires to use the result of functions, even when it's not used.
312310 // That's why we assign the result to a local.
313311 let return_type = self . context . new_type :: < bool > ( ) ;
314- let current_block = self . current_block . borrow ( ) . expect ( "block" ) ;
315- let current_func = current_block. get_function ( ) ;
312+ let current_func = self . block . get_function ( ) ;
316313 // TODO(antoyo): return the new_call() directly? Since the overflow function has no side-effects.
317314 unsafe { RETURN_VALUE_COUNT += 1 } ;
318315 let result = current_func. new_local ( None , return_type, & format ! ( "overflowReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ) ;
319- current_block . add_assignment ( None , result, self . cx . context . new_call ( None , func, & args) ) ;
316+ self . block . add_assignment ( None , result, self . cx . context . new_call ( None , func, & args) ) ;
320317 result. to_rvalue ( )
321318 }
322319}
@@ -382,14 +379,13 @@ impl<'gcc, 'tcx> BackendTypes for Builder<'_, 'gcc, 'tcx> {
382379
383380impl < ' a , ' gcc , ' tcx > BuilderMethods < ' a , ' tcx > for Builder < ' a , ' gcc , ' tcx > {
384381 fn build ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Self {
385- let mut bx = Builder :: with_cx ( cx) ;
382+ let bx = Builder :: with_cx ( cx, block ) ;
386383 * cx. current_block . borrow_mut ( ) = Some ( block) ;
387- bx. block = Some ( block) ;
388384 bx
389385 }
390386
391387 fn llbb ( & self ) -> Block < ' gcc > {
392- self . block . expect ( "block" )
388+ self . block
393389 }
394390
395391 fn append_block ( cx : & ' a CodegenCx < ' gcc , ' tcx > , func : RValue < ' gcc > , name : & str ) -> Block < ' gcc > {
@@ -404,7 +400,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
404400
405401 fn switch_to_block ( & mut self , block : Self :: BasicBlock ) {
406402 * self . cx . current_block . borrow_mut ( ) = Some ( block) ;
407- self . block = Some ( block) ;
403+ self . block = block;
408404 }
409405
410406 fn ret_void ( & mut self ) {
@@ -439,7 +435,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
439435 let on_val = self . const_uint_big ( typ, on_val) ;
440436 gcc_cases. push ( self . context . new_case ( on_val, on_val, dest) ) ;
441437 }
442- self . block . expect ( "block" ) . end_with_switch ( None , value, default_block, & gcc_cases) ;
438+ self . block . end_with_switch ( None , value, default_block, & gcc_cases) ;
443439 }
444440
445441 fn invoke ( & mut self , _typ : Type < ' gcc > , _func : RValue < ' gcc > , _args : & [ RValue < ' gcc > ] , then : Block < ' gcc > , catch : Block < ' gcc > , _funclet : Option < & Funclet > ) -> RValue < ' gcc > {
@@ -452,17 +448,16 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
452448
453449 fn unreachable ( & mut self ) {
454450 let func = self . context . get_builtin_function ( "__builtin_unreachable" ) ;
455- let block = self . block . expect ( "block" ) ;
456- block. add_eval ( None , self . context . new_call ( None , func, & [ ] ) ) ;
457- let return_type = block. get_function ( ) . get_return_type ( ) ;
451+ self . block . add_eval ( None , self . context . new_call ( None , func, & [ ] ) ) ;
452+ let return_type = self . block . get_function ( ) . get_return_type ( ) ;
458453 let void_type = self . context . new_type :: < ( ) > ( ) ;
459454 if return_type == void_type {
460- block. end_with_void_return ( None )
455+ self . block . end_with_void_return ( None )
461456 }
462457 else {
463458 let return_value = self . current_func ( )
464459 . new_local ( None , return_type, "unreachableReturn" ) ;
465- block. end_with_return ( None , return_value)
460+ self . block . end_with_return ( None , return_value)
466461 }
467462 }
468463
@@ -909,11 +904,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
909904 }
910905
911906 fn ptrtoint ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
912- self . cx . ptrtoint ( self . block . expect ( "block" ) , value, dest_ty)
907+ self . cx . ptrtoint ( self . block , value, dest_ty)
913908 }
914909
915910 fn inttoptr ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
916- self . cx . inttoptr ( self . block . expect ( "block" ) , value, dest_ty)
911+ self . cx . inttoptr ( self . block , value, dest_ty)
917912 }
918913
919914 fn bitcast ( & mut self , value : RValue < ' gcc > , dest_ty : Type < ' gcc > ) -> RValue < ' gcc > {
@@ -965,9 +960,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
965960 let dst = self . pointercast ( dst, self . type_i8p ( ) ) ;
966961 let src = self . pointercast ( src, self . type_ptr_to ( self . type_void ( ) ) ) ;
967962 let memcpy = self . context . get_builtin_function ( "memcpy" ) ;
968- let block = self . block . expect ( "block" ) ;
969963 // TODO(antoyo): handle aligns and is_volatile.
970- block. add_eval ( None , self . context . new_call ( None , memcpy, & [ dst, src, size] ) ) ;
964+ self . block . add_eval ( None , self . context . new_call ( None , memcpy, & [ dst, src, size] ) ) ;
971965 }
972966
973967 fn memmove ( & mut self , dst : RValue < ' gcc > , dst_align : Align , src : RValue < ' gcc > , src_align : Align , size : RValue < ' gcc > , flags : MemFlags ) {
@@ -984,20 +978,18 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
984978 let src = self . pointercast ( src, self . type_ptr_to ( self . type_void ( ) ) ) ;
985979
986980 let memmove = self . context . get_builtin_function ( "memmove" ) ;
987- let block = self . block . expect ( "block" ) ;
988981 // TODO(antoyo): handle is_volatile.
989- block. add_eval ( None , self . context . new_call ( None , memmove, & [ dst, src, size] ) ) ;
982+ self . block . add_eval ( None , self . context . new_call ( None , memmove, & [ dst, src, size] ) ) ;
990983 }
991984
992985 fn memset ( & mut self , ptr : RValue < ' gcc > , fill_byte : RValue < ' gcc > , size : RValue < ' gcc > , _align : Align , flags : MemFlags ) {
993986 let _is_volatile = flags. contains ( MemFlags :: VOLATILE ) ;
994987 let ptr = self . pointercast ( ptr, self . type_i8p ( ) ) ;
995988 let memset = self . context . get_builtin_function ( "memset" ) ;
996- let block = self . block . expect ( "block" ) ;
997989 // TODO(antoyo): handle align and is_volatile.
998990 let fill_byte = self . context . new_cast ( None , fill_byte, self . i32_type ) ;
999991 let size = self . intcast ( size, self . type_size_t ( ) , false ) ;
1000- block. add_eval ( None , self . context . new_call ( None , memset, & [ ptr, fill_byte, size] ) ) ;
992+ self . block . add_eval ( None , self . context . new_call ( None , memset, & [ ptr, fill_byte, size] ) ) ;
1001993 }
1002994
1003995 fn select ( & mut self , cond : RValue < ' gcc > , then_val : RValue < ' gcc > , mut else_val : RValue < ' gcc > ) -> RValue < ' gcc > {
0 commit comments