Author: Carl Friedrich Bolz <cfb...@gmx.de> Branch: Changeset: r72936:936da5f1c6fc Date: 2014-08-20 17:56 +0200 http://bitbucket.org/pypy/pypy/changeset/936da5f1c6fc/
Log: back out 658f358e5f30 (breaks translation) diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py b/rpython/jit/metainterp/optimizeopt/rewrite.py --- a/rpython/jit/metainterp/optimizeopt/rewrite.py +++ b/rpython/jit/metainterp/optimizeopt/rewrite.py @@ -47,15 +47,21 @@ def find_rewritable_bool(self, op, args): - oldopnum = opboolinvers[op.getopnum()] - if oldopnum != -1: + try: + oldopnum = opboolinvers[op.getopnum()] + except KeyError: + pass + else: targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[0], args[1]], None)) if self.try_boolinvers(op, targs): return True - oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL - if oldopnum != -1: + try: + oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL + except KeyError: + pass + else: targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]], None)) oldop = self.get_pure_result(targs) @@ -63,14 +69,15 @@ self.make_equal_to(op.result, self.getvalue(oldop.result)) return True - reflex = opboolreflex[op.getopnum()] - if reflex != -1: - oldopnum = opboolinvers[reflex] - if oldopnum != -1: - targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]], - None)) - if self.try_boolinvers(op, targs): - return True + try: + oldopnum = opboolinvers[opboolreflex[op.getopnum()]] + except KeyError: + pass + else: + targs = self.optimizer.make_args_key(ResOperation(oldopnum, [args[1], args[0]], + None)) + if self.try_boolinvers(op, targs): + return True return False diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py --- a/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizeopt.py @@ -185,7 +185,7 @@ op = opname[opnum] except KeyError: continue - if 'float' in op: + if 'FLOAT' in op: continue args = [] for _ in range(oparity[opnum]): diff --git a/rpython/jit/metainterp/optimizeopt/util.py b/rpython/jit/metainterp/optimizeopt/util.py --- a/rpython/jit/metainterp/optimizeopt/util.py +++ b/rpython/jit/metainterp/optimizeopt/util.py @@ -19,7 +19,7 @@ opname = name[len(name_prefix):] if opname.isupper(): assert hasattr(resoperation.rop, opname) - for value, name in enumerate(resoperation.opname): + for value, name in resoperation.opname.items(): if op_prefix and not name.startswith(op_prefix): continue if hasattr(Class, name_prefix + name): diff --git a/rpython/jit/metainterp/resoperation.py b/rpython/jit/metainterp/resoperation.py --- a/rpython/jit/metainterp/resoperation.py +++ b/rpython/jit/metainterp/resoperation.py @@ -126,7 +126,10 @@ ['descr=%r' % descr])) def getopname(self): - return opname[self.getopnum()] + try: + return opname[self.getopnum()].lower() + except KeyError: + return '<%d>' % self.getopnum() def is_guard(self): return rop._GUARD_FIRST <= self.getopnum() <= rop._GUARD_LAST @@ -546,7 +549,7 @@ pass opclasses = [] # mapping numbers to the concrete ResOp class -opname = [] # mapping numbers to the original names, for debugging +opname = {} # mapping numbers to the original names, for debugging oparity = [] # mapping numbers to the arity of the operation or -1 opwithdescr = [] # mapping numbers to a flag "takes a descr" @@ -568,16 +571,15 @@ arity, withdescr, boolresult = -1, True, False # default setattr(rop, name, i) if not name.startswith('_'): + opname[i] = name cls = create_class_for_op(name, i, arity, withdescr) cls._cls_has_bool_result = boolresult else: - name = '<%d>' % i cls = None - opname.append(name.lower()) opclasses.append(cls) oparity.append(arity) opwithdescr.append(withdescr) - assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist) == len(opname) + assert len(opclasses) == len(oparity) == len(opwithdescr) == len(_oplist) def get_base_class(mixin, base): try: @@ -617,10 +619,7 @@ setup(__name__ == '__main__') # print out the table when run directly del _oplist -def opdict_to_list(d, default=-1): - return [d.get(i, default) for i in range(len(opname))] - -opboolinvers = opdict_to_list({ +opboolinvers = { rop.INT_EQ: rop.INT_NE, rop.INT_NE: rop.INT_EQ, rop.INT_LT: rop.INT_GE, @@ -642,9 +641,9 @@ rop.PTR_EQ: rop.PTR_NE, rop.PTR_NE: rop.PTR_EQ, -}) +} -opboolreflex = opdict_to_list({ +opboolreflex = { rop.INT_EQ: rop.INT_EQ, rop.INT_NE: rop.INT_NE, rop.INT_LT: rop.INT_GT, @@ -666,7 +665,7 @@ rop.PTR_EQ: rop.PTR_EQ, rop.PTR_NE: rop.PTR_NE, -}) +} def get_deep_immutable_oplist(operations): diff --git a/rpython/jit/metainterp/test/test_executor.py b/rpython/jit/metainterp/test/test_executor.py --- a/rpython/jit/metainterp/test/test_executor.py +++ b/rpython/jit/metainterp/test/test_executor.py @@ -326,13 +326,13 @@ def make_args_for_op(op, a, b): n=opname[op] - if n[0:3] == 'int' or n[0:4] == 'uint': + if n[0:3] == 'INT' or n[0:4] == 'UINT': arg1 = ConstInt(a) arg2 = ConstInt(b) - elif n[0:5] == 'float': + elif n[0:5] == 'FLOAT': arg1 = constfloat(float(a)) arg2 = constfloat(float(b)) - elif n[0:3] == 'ptr': + elif n[0:3] == 'PTR': arg1 = ConstPtr(rffi.cast(llmemory.GCREF, a)) arg2 = ConstPtr(rffi.cast(llmemory.GCREF, b)) else: @@ -343,9 +343,7 @@ def test_opboolinvers(): cpu = FakeCPU() - for op1, op2 in enumerate(opboolinvers): - if op2 == -1: - continue + for op1, op2 in opboolinvers.items(): for a in (1,2,3): for b in (1,2,3): arg1, arg2 = make_args_for_op(op1, a, b) @@ -355,9 +353,7 @@ def test_opboolreflex(): cpu = FakeCPU() - for op1, op2 in enumerate(opboolreflex): - if op2 == -1: - continue + for op1, op2 in opboolreflex.items(): for a in (1,2,3): for b in (1,2,3): arg1, arg2 = make_args_for_op(op1, a, b) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit