33"""
44
55
6- from numba .core . config import MACHINE_BITS
6+ from numba .core import config
77from numba .core import types , cgutils
88from llvmlite import ir , binding
99
10- # Flag to enable debug print in NRT_incref and NRT_decref
11- _debug_print = False
1210
13- _word_type = ir .IntType (MACHINE_BITS )
11+ _word_type = ir .IntType (config . MACHINE_BITS )
1412_pointer_type = ir .PointerType (ir .IntType (8 ))
1513
1614_meminfo_struct_type = ir .LiteralStructType ([
@@ -54,10 +52,11 @@ def _define_nrt_incref(module, atomic_incr):
5452 with cgutils .if_unlikely (builder , is_null ):
5553 builder .ret_void ()
5654
57- if _debug_print :
58- cgutils .printf (builder , "*** NRT_Incref %zu [%p]\n " , builder .load (ptr ),
55+ word_ptr = builder .bitcast (ptr , atomic_incr .args [0 ].type )
56+ if config .DEBUG_NRT :
57+ cgutils .printf (builder , "*** NRT_Incref %zu [%p]\n " , builder .load (word_ptr ),
5958 ptr )
60- builder .call (atomic_incr , [builder . bitcast ( ptr , atomic_incr . args [ 0 ]. type ) ])
59+ builder .call (atomic_incr , [word_ptr ])
6160 builder .ret_void ()
6261
6362
@@ -79,17 +78,20 @@ def _define_nrt_decref(module, atomic_decr):
7978 with cgutils .if_unlikely (builder , is_null ):
8079 builder .ret_void ()
8180
82- if _debug_print :
83- cgutils .printf (builder , "*** NRT_Decref %zu [%p]\n " , builder .load (ptr ),
84- ptr )
8581
8682 # For memory fence usage, see https://llvm.org/docs/Atomics.html
8783
8884 # A release fence is used before the relevant write operation.
8985 # No-op on x86. On POWER, it lowers to lwsync.
9086 builder .fence ("release" )
87+
88+ word_ptr = builder .bitcast (ptr , atomic_decr .args [0 ].type )
89+
90+ if config .DEBUG_NRT :
91+ cgutils .printf (builder , "*** NRT_Decref %zu [%p]\n " , builder .load (word_ptr ),
92+ ptr )
9193 newrefct = builder .call (atomic_decr ,
92- [builder . bitcast ( ptr , atomic_decr . args [ 0 ]. type ) ])
94+ [word_ptr ])
9395
9496 refct_eq_0 = builder .icmp_unsigned ("==" , newrefct ,
9597 ir .Constant (newrefct .type , 0 ))
0 commit comments