Author: Remi Meier Branch: stmgc-c7 Changeset: r69960:955bfd905138 Date: 2014-03-14 17:07 +0100 http://bitbucket.org/pypy/pypy/changeset/955bfd905138/
Log: don't add stm_read for immutable operations (still very bad) diff --git a/rpython/translator/stm/readbarrier.py b/rpython/translator/stm/readbarrier.py --- a/rpython/translator/stm/readbarrier.py +++ b/rpython/translator/stm/readbarrier.py @@ -1,4 +1,4 @@ -from rpython.flowspace.model import SpaceOperation +from rpython.flowspace.model import SpaceOperation, Constant, Variable from rpython.translator.unsimplify import varoftype from rpython.rtyper.lltypesystem import lltype @@ -9,6 +9,31 @@ def is_gc_ptr(T): return isinstance(T, lltype.Ptr) and T.TO._gckind == 'gc' +def unwraplist(list_v): + for v in list_v: + if isinstance(v, Constant): + yield v.value + elif isinstance(v, Variable): + yield None # unknown + else: + raise AssertionError(v) + +def is_immutable(op): + if op.opname in ('getfield', 'setfield'): + STRUCT = op.args[0].concretetype.TO + return STRUCT._immutable_field(op.args[1].value) + if op.opname in ('getarrayitem', 'setarrayitem'): + ARRAY = op.args[0].concretetype.TO + return ARRAY._immutable_field() + if op.opname == 'getinteriorfield': + OUTER = op.args[0].concretetype.TO + return OUTER._immutable_interiorfield(unwraplist(op.args[1:])) + if op.opname == 'setinteriorfield': + OUTER = op.args[0].concretetype.TO + return OUTER._immutable_interiorfield(unwraplist(op.args[1:-1])) + if op.opname in ('raw_load', 'raw_store'): + return False + def insert_stm_read_barrier(transformer, graph): # We need to put enough 'stm_read' in the graph so that any @@ -19,13 +44,29 @@ # XXX this can be optimized a lot, but for now we go with the # simplest possible solution... # + gcremovetypeptr = transformer.translator.config.translation.gcremovetypeptr + for block in graph.iterblocks(): if not block.operations: continue newops = [] stm_ignored = False for op in block.operations: - if op.opname in READ_OPS and is_gc_ptr(op.args[0].concretetype): + is_getter = (op.opname in READ_OPS and + op.result.concretetype is not lltype.Void and + is_gc_ptr(op.args[0].concretetype)) + + if (gcremovetypeptr and op.opname in ('getfield', 'setfield') and + op.args[1].value == 'typeptr' and + op.args[0].concretetype.TO._hints.get('typeptr')): + # typeptr is always immutable + pass + elif ((op.opname in ('getarraysize', 'getinteriorarraysize', 'weakref_deref') and + is_gc_ptr(op.args[0].concretetype)) or + (is_getter and is_immutable(op))): + # immutable getters + pass + elif is_getter: if not stm_ignored: v_none = varoftype(lltype.Void) newops.append(SpaceOperation('stm_read', _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit