Commit 232461d0 authored by Carl Friedrich Bolz's avatar Carl Friedrich Bolz

back out 658f358e5f30

(breaks translation)
parent b904d16b
......@@ -47,15 +47,21 @@ class OptRewrite(Optimization):
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 @@ class OptRewrite(Optimization):
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
......
......@@ -185,7 +185,7 @@ class OptimizeOptTest(BaseTestWithUnroll):
op = opname[opnum]
except KeyError:
continue
if 'float' in op:
if 'FLOAT' in op:
continue
args = []
for _ in range(oparity[opnum]):
......
......@@ -19,7 +19,7 @@ def _findall(Class, name_prefix, op_prefix=None):
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):
......
......@@ -126,7 +126,10 @@ class AbstractResOp(object):
['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 @@ class rop(object):
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 @@ def setup(debug_print=False):
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 @@ def create_class_for_op(name, opnum, arity, withdescr):
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 @@ opboolinvers = opdict_to_list({
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 @@ opboolreflex = opdict_to_list({
rop.PTR_EQ: rop.PTR_EQ,
rop.PTR_NE: rop.PTR_NE,
})
}
def get_deep_immutable_oplist(operations):
......
......@@ -326,13 +326,13 @@ def test_float_ops():
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 make_args_for_op(op, a, b):
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_opboolinvers():
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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment