Author: Maciej Fijalkowski <[email protected]>
Branch: optresult
Changeset: r74521:38b07f93b97a
Date: 2014-11-14 18:15 +0200
http://bitbucket.org/pypy/pypy/changeset/38b07f93b97a/
Log: hack hack hack
diff --git a/rpython/jit/metainterp/executor.py
b/rpython/jit/metainterp/executor.py
--- a/rpython/jit/metainterp/executor.py
+++ b/rpython/jit/metainterp/executor.py
@@ -4,8 +4,10 @@
from rpython.rtyper.lltypesystem import lltype, rstr
from rpython.rlib.rarithmetic import ovfcheck, r_longlong, is_valid_int
from rpython.rlib.unroll import unrolling_iterable
-from rpython.jit.metainterp.history import BoxInt, BoxPtr, BoxFloat,
check_descr
+from rpython.rlib.objectmodel import specialize
+from rpython.jit.metainterp.history import check_descr
from rpython.jit.metainterp.history import INT, REF, FLOAT, VOID, AbstractDescr
+from rpython.jit.metainterp.history import ConstInt, ConstFloat, ConstPtr
from rpython.jit.metainterp import resoperation
from rpython.jit.metainterp.resoperation import rop
from rpython.jit.metainterp.blackhole import BlackholeInterpreter, NULL
@@ -14,6 +16,7 @@
# ____________________________________________________________
def do_call(cpu, metainterp, argboxes, descr):
+ xxx
assert metainterp is not None
# count the number of arguments of the different types
count_i = count_r = count_f = 0
@@ -141,6 +144,7 @@
cpu.bh_setarrayitem_raw_i(array, index, itembox.getint(), arraydescr)
def do_getinteriorfield_gc(cpu, _, arraybox, indexbox, descr):
+ xxxx
array = arraybox.getref_base()
index = indexbox.getint()
if descr.is_pointer_field():
@@ -175,6 +179,7 @@
return cpu.bh_getfield_gc_f(struct, fielddescr)
def do_getfield_raw(cpu, _, structbox, fielddescr):
+ xxxx
check_descr(fielddescr)
struct = structbox.getint()
if fielddescr.is_pointer_field():
@@ -212,6 +217,7 @@
cpu.bh_raw_store_i(addr, offset, valuebox.getint(), arraydescr)
def do_raw_load(cpu, _, addrbox, offsetbox, arraydescr):
+ xxx
addr = addrbox.getint()
offset = offsetbox.getint()
if arraydescr.is_array_of_pointers():
@@ -228,7 +234,7 @@
return cpu.bh_new_with_vtable(vtable, descr)
def do_new_with_vtable(cpu, _, clsbox):
- return BoxPtr(exec_new_with_vtable(cpu, clsbox))
+ return exec_new_with_vtable(cpu, clsbox)
def do_int_add_ovf(cpu, metainterp, box1, box2):
# the overflow operations can be called without a metainterp, if an
@@ -241,7 +247,7 @@
assert metainterp is not None
metainterp.execute_raised(OverflowError(), constant=True)
z = 0
- return BoxInt(z)
+ return z
def do_int_sub_ovf(cpu, metainterp, box1, box2):
a = box1.getint()
@@ -252,7 +258,7 @@
assert metainterp is not None
metainterp.execute_raised(OverflowError(), constant=True)
z = 0
- return BoxInt(z)
+ return z
def do_int_mul_ovf(cpu, metainterp, box1, box2):
a = box1.getint()
@@ -263,16 +269,16 @@
assert metainterp is not None
metainterp.execute_raised(OverflowError(), constant=True)
z = 0
- return BoxInt(z)
+ return z
def do_same_as_i(cpu, _, v):
- return v
+ return v.getint()
def do_same_as_r(cpu, _, v):
- return v
+ return v.getref_base()
def do_same_as_f(cpu, _, v):
- return v
+ return v.getfloatstorage()
def do_copystrcontent(cpu, _, srcbox, dstbox,
srcstartbox, dststartbox, lengthbox):
@@ -339,7 +345,7 @@
# parameters.
name = 'bhimpl_' + key.lower()
if hasattr(BlackholeInterpreter, name):
- func = make_execute_function_with_boxes(
+ func = make_execute_function(
key.lower(),
getattr(BlackholeInterpreter, name).im_func)
if func is not None:
@@ -374,7 +380,7 @@
raise AssertionError("missing %r" % (key,))
return execute_by_num_args
-def make_execute_function_with_boxes(name, func):
+def make_execute_function(name, func):
# Make a wrapper for 'func'. The func is a simple bhimpl_xxx function
# from the BlackholeInterpreter class. The wrapper is a new function
# that receives and returns boxed values.
@@ -454,8 +460,22 @@
execute_varargs._annspecialcase_ = 'specialize:arg(2)'
-def execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None):
- xxxx
+def execute_nonspec_const(cpu, metainterp, opnum, argboxes, descr=None,
+ type='i'):
+ if type == 'i':
+ return ConstInt(_execute_nonspec(cpu, metainterp, opnum, argboxes,
+ descr, 'i'))
+ elif type == 'f':
+ return ConstFloat(_execute_nonspec(cpu, metainterp, opnum, argboxes,
+ descr, 'f'))
+ elif type == 'r':
+ return ConstPtr(_execute_nonspec(cpu, metainterp, opnum, argboxes,
+ descr, 'r'))
+ else:
+ assert False
+
[email protected](5)
+def _execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None, type='i'):
arity = resoperation.oparity[opnum]
assert arity == -1 or len(argboxes) == arity
if resoperation.opwithdescr[opnum]:
diff --git a/rpython/jit/metainterp/history.py
b/rpython/jit/metainterp/history.py
--- a/rpython/jit/metainterp/history.py
+++ b/rpython/jit/metainterp/history.py
@@ -202,6 +202,9 @@
def same_constant(self, other):
raise NotImplementedError
+ def repr(self, memo):
+ return self.repr_rpython()
+
def __repr__(self):
return 'Const(%s)' % self._getrepr_()
diff --git a/rpython/jit/metainterp/optimizeopt/intbounds.py
b/rpython/jit/metainterp/optimizeopt/intbounds.py
--- a/rpython/jit/metainterp/optimizeopt/intbounds.py
+++ b/rpython/jit/metainterp/optimizeopt/intbounds.py
@@ -151,6 +151,7 @@
# nonneg % power-of-two ==> nonneg & (power-of-two - 1)
arg1 = op.getarg(0)
arg2 = ConstInt(val-1)
+ xxx
op = op.copy_and_change(rop.INT_AND, args=[arg1, arg2])
self.emit_operation(op)
if v2.is_constant():
@@ -197,7 +198,7 @@
if lastop is not None:
opnum = lastop.getopnum()
args = lastop.getarglist()
- result = lastop.result
+ result = lastop
# If the INT_xxx_OVF was replaced with INT_xxx or removed
# completely, then we can kill the GUARD_NO_OVERFLOW.
if (opnum != rop.INT_ADD_OVF and
@@ -236,13 +237,14 @@
v1 = self.getvalue(op.getarg(0))
v2 = self.getvalue(op.getarg(1))
resbound = v1.intbound.add_bound(v2.intbound)
+ r = self.getvalue(op)
if resbound.bounded():
# Transform into INT_ADD. The following guard will be killed
# by optimize_GUARD_NO_OVERFLOW; if we see instead an
# optimize_GUARD_OVERFLOW, then InvalidLoop.
op = op.copy_and_change(rop.INT_ADD)
self.emit_operation(op) # emit the op
- r = self.getvalue(op)
+ r.box = op
r.intbound.intersect(resbound)
def optimize_INT_SUB_OVF(self, op):
@@ -253,6 +255,7 @@
return
resbound = v1.intbound.sub_bound(v2.intbound)
if resbound.bounded():
+ xxxx
op = op.copy_and_change(rop.INT_SUB)
self.emit_operation(op) # emit the op
r = self.getvalue(op)
@@ -263,6 +266,7 @@
v2 = self.getvalue(op.getarg(1))
resbound = v1.intbound.mul_bound(v2.intbound)
if resbound.bounded():
+ xxx
op = op.copy_and_change(rop.INT_MUL)
self.emit_operation(op)
r = self.getvalue(op)
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -1,5 +1,5 @@
from rpython.jit.metainterp import jitprof, resume, compile
-from rpython.jit.metainterp.executor import execute_nonspec
+from rpython.jit.metainterp.executor import execute_nonspec_const
from rpython.jit.metainterp.history import BoxInt, BoxFloat, Const, ConstInt,
REF
from rpython.jit.metainterp.optimizeopt.intutils import IntBound,
IntUnbounded, \
ImmutableIntUnbounded, \
@@ -542,7 +542,7 @@
def emit_operation(self, op):
if op.returns_bool_result():
- self.bool_boxes[self.getvalue(op.result)] = None
+ self.bool_boxes[self.getvalue(op)] = None
self._emit_operation(op)
@specialize.argtype(0)
@@ -640,9 +640,9 @@
def constant_fold(self, op):
argboxes = [self.get_constant_box(op.getarg(i))
for i in range(op.numargs())]
- resbox = execute_nonspec(self.cpu, None,
- op.getopnum(), argboxes, op.getdescr())
- return resbox.constbox()
+ return execute_nonspec_const(self.cpu, None,
+ op.getopnum(), argboxes,
+ op.getdescr(), op.type)
#def optimize_GUARD_NO_OVERFLOW(self, op):
# # otherwise the default optimizer will clear fields, which is unwanted
diff --git a/rpython/jit/metainterp/optimizeopt/pure.py
b/rpython/jit/metainterp/optimizeopt/pure.py
--- a/rpython/jit/metainterp/optimizeopt/pure.py
+++ b/rpython/jit/metainterp/optimizeopt/pure.py
@@ -34,7 +34,7 @@
resbox = self.optimizer.constant_fold(op)
# note that INT_xxx_OVF is not done from here, and the
# overflows in the INT_xxx operations are ignored
- self.optimizer.make_constant(op.result, resbox)
+ self.optimizer.make_constant(op, resbox)
return
# did we do the exact same operation already?
@@ -43,8 +43,7 @@
oldop = self.pure_operations.get(args, None)
if oldop is not None and oldop.getdescr() is op.getdescr():
assert oldop.getopnum() == op.getopnum()
- self.optimizer.make_equal_to(op.result,
self.getvalue(oldop.result),
- True)
+ self.optimizer.make_equal_to(op, self.getvalue(oldop), True)
return
else:
self.pure_operations[args] = op
@@ -53,7 +52,7 @@
# otherwise, the operation remains
self.emit_operation(op)
if op.returns_bool_result():
- self.optimizer.bool_boxes[self.getvalue(op.result)] = None
+ self.optimizer.bool_boxes[self.getvalue(op)] = None
if nextop:
self.emit_operation(nextop)
@@ -62,7 +61,7 @@
result = self._can_optimize_call_pure(op)
if result is not None:
# this removes a CALL_PURE with all constant arguments.
- self.make_constant(op.result, result)
+ self.make_constant(op, result)
self.last_emitted_operation = REMOVED
return
@@ -74,7 +73,7 @@
assert oldop.getopnum() == op.getopnum()
# this removes a CALL_PURE that has the same (non-constant)
# arguments as a previous CALL_PURE.
- self.make_equal_to(op.result, self.getvalue(oldop.result))
+ self.make_equal_to(op, self.getvalue(oldop))
self.last_emitted_operation = REMOVED
return
else:
@@ -83,8 +82,7 @@
# replace CALL_PURE with just CALL
args = op.getarglist()
- self.emit_operation(ResOperation(rop.CALL, args, op.result,
- op.getdescr()))
+ self.emit_operation(ResOperation(rop.CALL, args, op.getdescr()))
optimize_CALL_PURE_R = optimize_CALL_PURE_I
optimize_CALL_PURE_F = optimize_CALL_PURE_I
optimize_CALL_PURE_N = optimize_CALL_PURE_I
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
@@ -38,10 +38,10 @@
value = self.getvalue(oldop.result)
if value.is_constant():
if value.box.same_constant(CONST_1):
- self.make_constant(op.result, CONST_0)
+ self.make_constant(op, CONST_0)
return True
elif value.box.same_constant(CONST_0):
- self.make_constant(op.result, CONST_1)
+ self.make_constant(op, CONST_1)
return True
return False
@@ -79,19 +79,19 @@
v1 = self.getvalue(op.getarg(0))
v2 = self.getvalue(op.getarg(1))
if v1.is_null() or v2.is_null():
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
return
elif v2.is_constant():
val = v2.box.getint()
if val == -1 or v1.intbound.lower >= 0 \
and v1.intbound.upper <= val & ~(val + 1):
- self.make_equal_to(op.result, v1)
+ self.make_equal_to(op, v1)
return
elif v1.is_constant():
val = v1.box.getint()
if val == -1 or v2.intbound.lower >= 0 \
and v2.intbound.upper <= val & ~(val + 1):
- self.make_equal_to(op.result, v2)
+ self.make_equal_to(op, v2)
return
self.emit_operation(op)
@@ -115,7 +115,7 @@
op = op.copy_and_change(rop.INT_NEG, args=[v2.box])
self.emit_operation(op)
elif v1 is v2:
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
else:
self.emit_operation(op)
# Synthesize the reverse ops for optimize_default to reuse
@@ -149,7 +149,7 @@
self.make_equal_to(op.result, v1)
elif (v1.is_constant() and v1.box.getint() == 0) or \
(v2.is_constant() and v2.box.getint() == 0):
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
else:
for lhs, rhs in [(v1, v2), (v2, v1)]:
if lhs.is_constant():
@@ -177,7 +177,7 @@
if v2.is_constant() and v2.box.getint() == 0:
self.make_equal_to(op.result, v1)
elif v1.is_constant() and v1.box.getint() == 0:
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
else:
self.emit_operation(op)
@@ -188,7 +188,7 @@
if v2.is_constant() and v2.box.getint() == 0:
self.make_equal_to(op.result, v1)
elif v1.is_constant() and v1.box.getint() == 0:
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
else:
self.emit_operation(op)
@@ -418,9 +418,9 @@
def _optimize_nullness(self, op, box, expect_nonnull):
value = self.getvalue(box)
if value.is_nonnull():
- self.make_constant_int(op.result, expect_nonnull)
+ self.make_constant_int(op, expect_nonnull)
elif value.is_null():
- self.make_constant_int(op.result, not expect_nonnull)
+ self.make_constant_int(op, not expect_nonnull)
else:
self.emit_operation(op)
@@ -439,17 +439,17 @@
if value0.is_virtual():
if value1.is_virtual():
intres = (value0 is value1) ^ expect_isnot
- self.make_constant_int(op.result, intres)
+ self.make_constant_int(op, intres)
else:
- self.make_constant_int(op.result, expect_isnot)
+ self.make_constant_int(op, expect_isnot)
elif value1.is_virtual():
- self.make_constant_int(op.result, expect_isnot)
+ self.make_constant_int(op, expect_isnot)
elif value1.is_null():
self._optimize_nullness(op, op.getarg(0), expect_isnot)
elif value0.is_null():
self._optimize_nullness(op, op.getarg(1), expect_isnot)
elif value0 is value1:
- self.make_constant_int(op.result, not expect_isnot)
+ self.make_constant_int(op, not expect_isnot)
else:
if instance:
cls0 = value0.get_constant_class(self.optimizer.cpu)
@@ -458,7 +458,7 @@
if cls1 is not None and not cls0.same_constant(cls1):
# cannot be the same object, as we know that their
# class is different
- self.make_constant_int(op.result, expect_isnot)
+ self.make_constant_int(op, expect_isnot)
return
self.emit_operation(op)
@@ -539,7 +539,7 @@
# Note that it's also done in pure.py. For now we need both...
result = self._can_optimize_call_pure(op)
if result is not None:
- self.make_constant(op.result, result)
+ self.make_constant(op, result)
self.last_emitted_operation = REMOVED
return
self.emit_operation(op)
@@ -565,7 +565,7 @@
self.make_equal_to(op.result, v1)
return
elif v1.is_constant() and v1.box.getint() == 0:
- self.make_constant_int(op.result, 0)
+ self.make_constant_int(op, 0)
return
if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant():
val = v2.box.getint()
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -19,7 +19,7 @@
opt = optimizeopt.Optimizer(FakeMetaInterpStaticData(LLtypeMixin.cpu),
None)
fdescr = ResumeGuardDescr()
- op = ResOperation(rop.GUARD_TRUE, ['dummy'], None, descr=fdescr)
+ op = ResOperation(rop.GUARD_TRUE, ['dummy'], descr=fdescr)
# setup rd data
fi0 = resume.FrameInfo(None, "code0", 11)
fdescr.rd_frame_info_list = resume.FrameInfo(fi0, "code1", 33)
@@ -99,7 +99,7 @@
def optimize_loop(self, ops, optops, call_pure_results=None):
loop = self.parse(ops)
token = JitCellToken()
- loop.operations = [ResOperation(rop.LABEL, loop.inputargs, None,
descr=TargetToken(token))] + \
+ loop.operations = [ResOperation(rop.LABEL, loop.inputargs,
descr=TargetToken(token))] + \
loop.operations
if loop.operations[-1].getopnum() == rop.JUMP:
loop.operations[-1].setdescr(token)
@@ -232,7 +232,7 @@
def test_remove_guard_class_constant(self):
ops = """
[i0]
- p0 = same_as(ConstPtr(myptr))
+ p0 = same_as_r(ConstPtr(myptr))
guard_class(p0, ConstClass(node_vtable)) []
jump(i0)
"""
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py
b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -410,9 +410,9 @@
preamble.inputargs = inputargs
token = JitCellToken()
- preamble.operations = [ResOperation(rop.LABEL, inputargs, None,
descr=TargetToken(token))] + \
+ preamble.operations = [ResOperation(rop.LABEL, inputargs,
descr=TargetToken(token))] + \
operations + \
- [ResOperation(rop.LABEL, jump_args, None,
descr=token)]
+ [ResOperation(rop.LABEL, jump_args, descr=token)]
self._do_optimize_loop(preamble, call_pure_results)
assert preamble.operations[-1].getopnum() == rop.LABEL
@@ -451,11 +451,11 @@
def convert_old_style_to_targets(loop, jump):
newloop = TreeLoop(loop.name)
newloop.inputargs = loop.inputargs
- newloop.operations = [ResOperation(rop.LABEL, loop.inputargs, None,
descr=FakeDescr())] + \
+ newloop.operations = [ResOperation(rop.LABEL, loop.inputargs,
descr=FakeDescr())] + \
loop.operations
if not jump:
assert newloop.operations[-1].getopnum() == rop.JUMP
- newloop.operations[-1] = ResOperation(rop.LABEL,
newloop.operations[-1].getarglist(), None, descr=FakeDescr())
+ newloop.operations[-1] = ResOperation(rop.LABEL,
newloop.operations[-1].getarglist(), descr=FakeDescr())
return newloop
# ____________________________________________________________
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
@@ -134,10 +134,17 @@
width = totwidth / 2 - 1
print ' Comparing lists '.center(totwidth, '-')
text_right = text_right or 'expected'
+ memo = {}
print '%s| %s' % ('optimized'.center(width), text_right.center(width))
for op1, op2 in itertools.izip_longest(oplist1, oplist2, fillvalue=''):
- txt1 = str(op1)
- txt2 = str(op2)
+ if op1:
+ txt1 = op1.repr(memo)
+ else:
+ txt1 = ''
+ if op2:
+ txt2 = op2.repr(memo)
+ else:
+ txt2 = ''
while txt1 or txt2:
part1 = txt1[:width]
part2 = txt2[:width]
diff --git a/rpython/jit/metainterp/optimizeopt/virtualize.py
b/rpython/jit/metainterp/optimizeopt/virtualize.py
--- a/rpython/jit/metainterp/optimizeopt/virtualize.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualize.py
@@ -15,15 +15,13 @@
class AbstractVirtualValue(optimizer.OptValue):
_attrs_ = ('keybox', 'source_op', '_cached_vinfo')
- box = None
level = optimizer.LEVEL_NONNULL
is_about_raw = False
+ box = None
_cached_vinfo = None
- def __init__(self, keybox, source_op=None):
- self.keybox = keybox # only used as a key in dictionaries
- self.source_op = source_op # the NEW_WITH_VTABLE/NEW_ARRAY operation
- # that builds this box
+ def __init__(self, source_op):
+ self.source_op = source_op
def is_forced_virtual(self):
return self.box is not None
@@ -35,7 +33,7 @@
def force_box(self, optforce):
if self.box is None:
- optforce.forget_numberings(self.keybox)
+ optforce.forget_numberings(self.source_op)
self._really_force(optforce)
return self.box
@@ -75,8 +73,8 @@
class AbstractVirtualStructValue(AbstractVirtualValue):
_attrs_ = ('_fields', 'cpu', '_cached_sorted_fields')
- def __init__(self, cpu, keybox, source_op=None):
- AbstractVirtualValue.__init__(self, keybox, source_op)
+ def __init__(self, cpu, source_op):
+ AbstractVirtualValue.__init__(self, source_op)
self.cpu = cpu
self._fields = {}
self._cached_sorted_fields = None
@@ -151,7 +149,7 @@
# keep self._fields, because it's all immutable anyway
else:
optforce.emit_operation(op)
- self.box = box = op.result
+ self.box = box = op
#
iteritems = self._fields.iteritems()
if not we_are_translated(): #random order is fine, except for tests
@@ -200,8 +198,8 @@
class VirtualValue(AbstractVirtualStructValue):
level = optimizer.LEVEL_KNOWNCLASS
- def __init__(self, cpu, known_class, keybox, source_op=None):
- AbstractVirtualStructValue.__init__(self, cpu, keybox, source_op)
+ def __init__(self, cpu, known_class, source_op):
+ AbstractVirtualStructValue.__init__(self, cpu, source_op)
assert isinstance(known_class, Const)
self.known_class = known_class
@@ -522,9 +520,9 @@
_last_guard_not_forced_2 = None
- def make_virtual(self, known_class, box, source_op=None):
- vvalue = VirtualValue(self.optimizer.cpu, known_class, box, source_op)
- self.make_equal_to(box, vvalue)
+ def make_virtual(self, known_class, source_op):
+ vvalue = VirtualValue(self.optimizer.cpu, known_class, source_op)
+ self.make_equal_to(source_op, vvalue)
return vvalue
def make_varray(self, arraydescr, size, box, source_op=None,
@@ -702,10 +700,10 @@
self.emit_operation(op)
def optimize_NEW_WITH_VTABLE(self, op):
- self.make_virtual(op.getarg(0), op.result, op)
+ self.make_virtual(op.getarg(0), op)
def optimize_NEW(self, op):
- self.make_vstruct(op.getdescr(), op.result, op)
+ self.make_vstruct(op.getdescr(), op)
def optimize_NEW_ARRAY(self, op):
sizebox = self.get_constant_box(op.getarg(0))
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
@@ -1,5 +1,6 @@
from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.rlib.objectmodel import compute_identity_hash
+from rpython.rtyper.lltypesystem import lltype, llmemory
class AbstractValue(object):
def _get_hash_(self):
@@ -8,8 +9,10 @@
def same_box(self, other):
return self is other
[email protected](2)
-def ResOperation(opnum, args, result, descr=None):
+ def repr_short(self, memo):
+ return self.repr(memo)
+
+def ResOperation(opnum, args, descr=None):
cls = opclasses[opnum]
op = cls()
op.initarglist(args)
@@ -20,16 +23,6 @@
elif op.is_guard():
assert not descr.final_descr
op.setdescr(descr)
- if isinstance(result, int):
- op._resint = result
- elif isinstance(result, float):
- op._resfloat = result
- elif result is None:
- pass
- else:
- from rpython.rtyper.lltypesystem import lltype, llmemory
- assert lltype.typeOf(result) == llmemory.GCREF
- op._resref = result
return op
@@ -97,13 +90,25 @@
"shallow copy: the returned operation is meant to be used in place of
self"
if args is None:
args = self.getarglist()
- if result is None:
- result = self.result
if descr is None:
descr = self.getdescr()
- newop = ResOperation(opnum, args, result, descr)
+ newop = ResOperation(opnum, args, descr)
+ newop.copy_value_from(self)
return newop
+ @specialize.argtype(1)
+ def setvalue(self, value):
+ if isinstance(value, int):
+ self._resint = value
+ elif isinstance(value, float):
+ self._resfloat = value
+ elif value is None:
+ pass
+ else:
+ assert lltype.typeOf(value) == llmemory.GCREF
+ self._resref = value
+
+
def clone(self):
args = self.getarglist()
descr = self.getdescr()
@@ -117,9 +122,15 @@
def repr(self, memo, graytext=False):
# RPython-friendly version
- XXX
- if self.result is not None:
- sres = '%s = ' % (self.result,)
+ if self.type != 'v':
+ try:
+ sres = '%s = ' % memo[self]
+ except KeyError:
+ name = self.type + str(len(memo))
+ memo[self] = name
+ sres = name + ' = '
+ #if self.result is not None:
+ # sres = '%s = ' % (self.result,)
else:
sres = ''
if self.name:
@@ -132,12 +143,15 @@
descr = self.getdescr()
if descr is None or we_are_translated():
return '%s%s%s(%s)' % (prefix, sres, self.getopname(),
- ', '.join([str(a) for a in args]))
+ ', '.join([a.repr_short(memo) for a in
args]))
else:
return '%s%s%s(%s)' % (prefix, sres, self.getopname(),
- ', '.join([str(a) for a in args] +
+ ', '.join([a.repr_short(memo) for a in
args] +
['descr=%r' % descr]))
+ def repr_short(self, memo):
+ return memo[self]
+
def getopname(self):
try:
return opname[self.getopnum()].lower()
@@ -274,43 +288,67 @@
type = 'i'
+ _resint = 0
+
def getint(self):
return self._resint
def setint(self, intval):
self._resint = intval
+ def copy_value_from(self, other):
+ self.setint(other.getint())
+
class FloatOp(object):
_mixin_ = True
type = 'f'
+ _resfloat = 0.0
+
def getfloatstorage(self):
return self._resfloat
def setfloatstorage(self, floatval):
self._resfloat = floatval
+ def copy_value_from(self, other):
+ self.setfloatstorage(other.getfloatstorage())
+
class RefOp(object):
_mixin_ = True
type = 'r'
+ _resref = lltype.nullptr(llmemory.GCREF.TO)
+
def getref_base(self):
return self._resref
def setref_base(self, refval):
self._resref = refval
-class InputArgInt(IntOp, AbstractValue):
+ def copy_value_from(self, other):
+ self.setref_base(other.getref_base())
+
+class AbstractInputArg(AbstractValue):
+ def repr(self, memo):
+ try:
+ return memo[self]
+ except KeyError:
+ name = self.type + str(len(memo))
+ memo[self] = name
+ return name
+
+class InputArgInt(IntOp, AbstractInputArg):
def __init__(self, intval):
- self.setint(intval)
+ self.setint(intval)
-class InputArgFloat(FloatOp, AbstractValue):
+class InputArgFloat(FloatOp, AbstractInputArg):
def __init__(self, f):
self.setfloatstorage(f)
-class InputArgRef(RefOp, AbstractValue):
+class InputArgRef(RefOp, AbstractInputArg):
def __init__(self, r):
self.setref_base(r)
diff --git a/rpython/jit/tool/oparser.py b/rpython/jit/tool/oparser.py
--- a/rpython/jit/tool/oparser.py
+++ b/rpython/jit/tool/oparser.py
@@ -275,18 +275,7 @@
assert descr is None
return op
else:
- tp = optypes[opnum]
- if tp == 'i':
- result = 0
- elif tp == 'r':
- from rpython.rtyper.lltypesystem import lltype, llmemory
- result = lltype.nullptr(llmemory.GCREF.TO)
- elif tp == 'f':
- result = 0.0
- else:
- assert tp == 'n'
- result = None
- return ResOperation(opnum, args, result, descr)
+ return ResOperation(opnum, args, descr)
def parse_result_op(self, line):
res, op = line.split("=", 1)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit