<s> from pypy . rpython . lltypesystem import lltype <EOL> relevant_ops = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def filter_for_ptr ( arg ) : <EOL> return isinstance ( arg . concretetype , lltype . Ptr ) <EOL> def filter_for_nongcptr ( arg ) : <EOL> return isinstance ( arg . concretetype , lltype . Ptr ) and not arg . concretetype . _needsgc ( ) <EOL> def relevant_gcvars_block ( block , filter = filter_for_ptr ) : <EOL> result = [ ] <EOL> def filter_ptr ( args ) : <EOL> return [ arg for arg in args if filter ( arg ) ] <EOL> def live_vars_before ( index ) : <EOL> if index == <NUM_LIT:0> : <EOL> return set ( filter_ptr ( block . inputargs ) ) <EOL> op = block . operations [ index - <NUM_LIT:1> ] <EOL> result = live_vars_before ( index - <NUM_LIT:1> ) . union ( filter_ptr ( op . args + [ op . result ] ) ) <EOL> return result <EOL> def live_vars_after ( index ) : <EOL> if index == len ( block . operations ) - <NUM_LIT:1> : <EOL> result = set ( ) <EOL> for exit in block . exits : <EOL> result = result . union ( filter_ptr ( exit . args ) ) <EOL> return result <EOL> op = block . operations [ index + <NUM_LIT:1> ] <EOL> result = live_vars_after ( index + <NUM_LIT:1> ) . union ( filter_ptr ( op . args + [ op . result ] ) ) <EOL> return result <EOL> for i , op in enumerate ( block . operations ) : <EOL> if op . opname not in relevant_ops : <EOL> continue <EOL> live_before = live_vars_before ( i ) <EOL> live_after = live_vars_after ( i ) <EOL> result . append ( len ( live_before . intersection ( live_after ) ) ) <EOL> return result <EOL> def relevant_gcvars_graph ( graph , filter = filter_for_ptr ) : <EOL> result = [ ] <EOL> for block in graph . iterblocks ( ) : <EOL> result += relevant_gcvars_block ( block , filter ) <EOL> return result <EOL> def relevant_gcvars ( t , filter = filter_for_ptr ) : <EOL> result = [ ] <EOL> for graph in t . graphs : <EOL> result . extend ( relevant_gcvars_graph ( graph , filter ) ) <EOL> return result </s>
