@@ -41,9 +41,6 @@ use crate::type_of::LayoutGccExt;
41
41
// TODO(antoyo)
42
42
type Funclet = ( ) ;
43
43
44
- // TODO(antoyo): remove this variable.
45
- static mut RETURN_VALUE_COUNT : usize = 0 ;
46
-
47
44
enum ExtremumOperation {
48
45
Max ,
49
46
Min ,
@@ -52,13 +49,18 @@ enum ExtremumOperation {
52
49
pub struct Builder < ' a : ' gcc , ' gcc , ' tcx > {
53
50
pub cx : & ' a CodegenCx < ' gcc , ' tcx > ,
54
51
pub block : Block < ' gcc > ,
55
- stack_var_count : Cell < usize > ,
56
52
pub location : Option < Location < ' gcc > > ,
53
+ value_counter : Cell < u64 > ,
57
54
}
58
55
59
56
impl < ' a , ' gcc , ' tcx > Builder < ' a , ' gcc , ' tcx > {
60
57
fn with_cx ( cx : & ' a CodegenCx < ' gcc , ' tcx > , block : Block < ' gcc > ) -> Self {
61
- Builder { cx, block, stack_var_count : Cell :: new ( 0 ) , location : None }
58
+ Builder { cx, block, location : None , value_counter : Cell :: new ( 0 ) }
59
+ }
60
+
61
+ fn next_value_counter ( & self ) -> u64 {
62
+ self . value_counter . set ( self . value_counter . get ( ) + 1 ) ;
63
+ self . value_counter . get ( )
62
64
}
63
65
64
66
fn atomic_extremum (
@@ -324,11 +326,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
324
326
let void_type = self . context . new_type :: < ( ) > ( ) ;
325
327
let current_func = self . block . get_function ( ) ;
326
328
if return_type != void_type {
327
- unsafe { RETURN_VALUE_COUNT += 1 } ;
328
329
let result = current_func. new_local (
329
330
self . location ,
330
331
return_type,
331
- & format ! ( "returnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
332
+ & format ! ( "returnValue{}" , self . next_value_counter ( ) ) ,
332
333
) ;
333
334
self . block . add_assignment (
334
335
self . location ,
@@ -384,7 +385,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
384
385
let current_func = self . block . get_function ( ) ;
385
386
386
387
if return_type != void_type {
387
- unsafe { RETURN_VALUE_COUNT += 1 } ;
388
388
let return_value = self . cx . context . new_call_through_ptr ( self . location , func_ptr, & args) ;
389
389
let return_value = llvm:: adjust_intrinsic_return_value (
390
390
self ,
@@ -397,7 +397,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
397
397
let result = current_func. new_local (
398
398
self . location ,
399
399
return_value. get_type ( ) ,
400
- & format ! ( "ptrReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
400
+ & format ! ( "ptrReturnValue{}" , self . next_value_counter ( ) ) ,
401
401
) ;
402
402
self . block . add_assignment ( self . location , result, return_value) ;
403
403
result. to_rvalue ( )
@@ -446,11 +446,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
446
446
let return_type = self . context . new_type :: < bool > ( ) ;
447
447
let current_func = self . block . get_function ( ) ;
448
448
// TODO(antoyo): return the new_call() directly? Since the overflow function has no side-effects.
449
- unsafe { RETURN_VALUE_COUNT += 1 } ;
450
449
let result = current_func. new_local (
451
450
self . location ,
452
451
return_type,
453
- & format ! ( "overflowReturnValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
452
+ & format ! ( "overflowReturnValue{}" , self . next_value_counter ( ) ) ,
454
453
) ;
455
454
self . block . add_assignment (
456
455
self . location ,
@@ -934,9 +933,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
934
933
fn alloca ( & mut self , size : Size , align : Align ) -> RValue < ' gcc > {
935
934
let ty = self . cx . type_array ( self . cx . type_i8 ( ) , size. bytes ( ) ) . get_aligned ( align. bytes ( ) ) ;
936
935
// TODO(antoyo): It might be better to return a LValue, but fixing the rustc API is non-trivial.
937
- self . stack_var_count . set ( self . stack_var_count . get ( ) + 1 ) ;
938
936
self . current_func ( )
939
- . new_local ( self . location , ty, & format ! ( "stack_var_{}" , self . stack_var_count . get ( ) ) )
937
+ . new_local ( self . location , ty, & format ! ( "stack_var_{}" , self . next_value_counter ( ) ) )
940
938
. get_address ( self . location )
941
939
}
942
940
@@ -959,11 +957,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
959
957
} ;
960
958
let ptr = self . context . new_cast ( self . location , ptr, aligned_type. make_pointer ( ) ) ;
961
959
let deref = ptr. dereference ( self . location ) . to_rvalue ( ) ;
962
- unsafe { RETURN_VALUE_COUNT += 1 } ;
963
960
let loaded_value = function. new_local (
964
961
self . location ,
965
962
aligned_type,
966
- & format ! ( "loadedValue{}" , unsafe { RETURN_VALUE_COUNT } ) ,
963
+ & format ! ( "loadedValue{}" , self . next_value_counter ( ) ) ,
967
964
) ;
968
965
block. add_assignment ( self . location , loaded_value, deref) ;
969
966
loaded_value. to_rvalue ( )
0 commit comments