[pypy-commit] pypy jit-leaner-frontend: start working on a much simplified encoder
fijal
pypy.commits at gmail.com
Sun Feb 14 13:16:45 EST 2016
Author: fijal
Branch: jit-leaner-frontend
Changeset: r82243:1ce0ba36d602
Date: 2016-02-14 15:34 +0100
http://bitbucket.org/pypy/pypy/changeset/1ce0ba36d602/
Log: start working on a much simplified encoder
diff --git a/rpython/jit/metainterp/opencoder.py b/rpython/jit/metainterp/opencoder.py
--- a/rpython/jit/metainterp/opencoder.py
+++ b/rpython/jit/metainterp/opencoder.py
@@ -2,10 +2,10 @@
from rpython.jit.metainterp.history import ConstInt, Const, AbstractDescr,\
AbstractValue
from rpython.jit.metainterp.resoperation import AbstractResOp, AbstractInputArg,\
- ResOperation, oparity, opname, rop
+ ResOperation, oparity, opname, rop, ResOperation, opwithdescr
from rpython.rlib.rarithmetic import intmask
-TAGINT, TAGCONST, TAGBOX, TAGOUTPUT = range(4)
+TAGINT, TAGCONST, TAGBOX = range(3)
TAGMASK = 0x3
TAGSHIFT = 2
MAXINT = 65536
@@ -13,8 +13,18 @@
class TraceIterator(object):
def __init__(self, trace, end):
self.trace = trace
- self.pos = trace._start
+ self.inpargs = trace._inpargs
+ self.pos = 0
+ self._count = 0
self.end = end
+ self._cache = [None] * trace._count
+
+ def _get(self, i):
+ if i < 0:
+ return self.inpargs[-i-1]
+ res = self._cache[i]
+ assert res is not None
+ return res
def done(self):
return self.pos >= self.end
@@ -24,69 +34,46 @@
self.pos += 1
return res
+ def _untag(self, tagged):
+ tag, v = untag(tagged)
+ if tag == TAGBOX:
+ return self._get(v)
+ elif tag == TAGINT:
+ return ConstInt(v)
+ else:
+ yyyy
+
def next(self):
pos = self.pos
opnum = self._next()
- self._next() # forwarding
if oparity[opnum] == -1:
argnum = self._next()
else:
argnum = oparity[opnum]
args = []
for i in range(argnum):
- args.append(self._next())
- return RecordedOp(pos, opnum, args)
-
-class RecordedOp(AbstractValue):
- def __init__(self, pos, opnum, args, descr=None):
- self.opnum = opnum
- self.args = args
- self._pos = pos
- self.descr = descr
-
- def get_tag(self):
- return tag(TAGBOX, self._pos)
-
- def getarglist(self):
- return self.args
-
- def getdescr(self):
- return self.descr
-
- def numargs(self):
- return len(self.args)
-
- def getopnum(self):
- return self.opnum
-
- def getarg(self, i):
- return self.args[i]
-
- def getopname(self):
- try:
- return opname[self.getopnum()].lower()
- except KeyError:
- return '<%d>' % self.getopnum()
-
- def __hash__(self):
- raise NotImplementedError
-
+ args.append(self._untag(self._next()))
+ if opwithdescr[opnum]:
+ xxx
+ else:
+ descr = None
+ res = ResOperation(opnum, args, -1, descr=descr)
+ self._cache[self._count] = res
+ self._count += 1
+ return res
class Trace(object):
def __init__(self, inputargs):
- self._ops = [0] * (2 * len(inputargs)) # place for forwarding inputargs
- # plus infos
+ self._ops = []
for i, inparg in enumerate(inputargs):
- self._ops[i * 2 + i] = i
- inparg.position = i * 2
- self._start = len(inputargs) * 2
- self._count = len(inputargs)
+ inparg.position = -i - 1
+ self._count = 0
+ self._inpargs = inputargs
def _record_op(self, opnum, argboxes, descr=None):
operations = self._ops
pos = len(operations)
operations.append(opnum)
- operations.append(self._count) # here we keep the index into infos
if oparity[opnum] == -1:
operations.append(len(argboxes))
operations.extend([encode(box) for box in argboxes])
@@ -99,7 +86,6 @@
operations = self._ops
pos = len(operations)
operations.append(opnum)
- operations.append(self._count) # here we keep the index into infos
if oparity[opnum] == -1:
operations.append(len(tagged_args))
operations.extend(tagged_args)
@@ -120,20 +106,18 @@
def record_op_tag(self, opnum, tagged_args, descr=None):
return tag(TAGBOX, self._record_raw(opnum, tagged_args, descr))
- def record_op_output_tag(self, opnum, tagged_args, descr=None):
- return tag(TAGOUTPUT, self._record_raw(opnum, tagged_args, descr))
-
- def get_info(self, infos, pos):
- index = self._ops[pos + 1]
- return infos[index]
-
- def set_info(self, infos, pos, info):
- index = self._ops[pos + 1]
- infos[index] = info
-
def get_iter(self):
return TraceIterator(self, len(self._ops))
+ def _get_operations(self):
+ """ NOT_RPYTHON
+ """
+ l = []
+ i = self.get_iter()
+ while not i.done():
+ l.append(i.next())
+ return l
+
def tag(kind, pos):
return (pos << TAGSHIFT) | kind
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
@@ -1448,13 +1448,6 @@
opnum == rop.CALL_N)
@staticmethod
- def is_call_assembler(opnum):
- return (opnum == rop.CALL_ASSEMBLER_I or
- opnum == rop.CALL_ASSEMBLER_R or
- opnum == rop.CALL_ASSEMBLER_F or
- opnum == rop.CALL_ASSEMBLER_N)
-
- @staticmethod
def is_call_loopinvariant(opnum):
return (opnum == rop.CALL_LOOPINVARIANT_I or
opnum == rop.CALL_LOOPINVARIANT_R or
@@ -1462,20 +1455,6 @@
opnum == rop.CALL_LOOPINVARIANT_N)
@staticmethod
- def is_call_may_force(opnum):
- return (opnum == rop.CALL_MAY_FORCE_I or
- opnum == rop.CALL_MAY_FORCE_R or
- opnum == rop.CALL_MAY_FORCE_F or
- opnum == rop.CALL_MAY_FORCE_N)
-
- @staticmethod
- def is_call_release_gil(opnum):
- # no R returning call_release_gil
- return (opnum == rop.CALL_RELEASE_GIL_I or
- opnum == rop.CALL_RELEASE_GIL_F or
- opnum == rop.CALL_RELEASE_GIL_N)
-
- @staticmethod
def inputarg_from_tp(tp):
if tp == 'i':
return InputArgInt()
diff --git a/rpython/jit/metainterp/test/test_opencoder.py b/rpython/jit/metainterp/test/test_opencoder.py
--- a/rpython/jit/metainterp/test/test_opencoder.py
+++ b/rpython/jit/metainterp/test/test_opencoder.py
@@ -34,35 +34,7 @@
assert len(l) == 2
assert l[0].opnum == rop.INT_ADD
assert l[1].opnum == rop.INT_ADD
- assert untag(l[1].args[1]) == (TAGINT, 1)
- assert untag(l[1].args[0]) == (TAGBOX, l[0]._pos)
- assert untag(l[0].args[0]) == (TAGBOX, 0)
- assert untag(l[0].args[1]) == (TAGBOX, 1)
-
- def test_forwarding(self):
- i0, i1 = InputArgInt(), InputArgInt()
- t = Trace([i0, i1])
- add = t.record_op(rop.INT_ADD, [i0, i1])
- t.record_op(rop.INT_ADD, [add, ConstInt(1)])
- opt = SimpleOptimizer(t)
- add, add2 = self.unpack(t)
- assert (untag(opt.get_box_replacement(add.get_tag())) == TAGBOX, add._pos)
- newtag = opt.replace_op_with(add, rop.INT_NEG, [i0])
- assert opt.get_box_replacement(add.get_tag()) == newtag
-
- def test_infos(self):
- i0 = InputArgInt()
- t = Trace([i0])
- t.record_op(rop.INT_ADD, [i0, ConstInt(1)])
- opt = SimpleOptimizer(t)
- add, = self.unpack(t)
- assert opt.getintbound(add.get_tag())
-
- def test_output(self):
- i0 = InputArgInt()
- t = Trace([i0])
- t.record_op(rop.INT_ADD, [i0, ConstInt(1)])
- opt = SimpleOptimizer(t)
- add, = self.unpack(t)
- opt.emit_operation(add)
-# xxx
\ No newline at end of file
+ assert l[1].getarg(1).getint() == 1
+ assert l[1].getarg(0) is l[0]
+ assert l[0].getarg(0) is i0
+ assert l[0].getarg(1) is i1
diff --git a/rpython/jit/tool/test/test_oparser.py b/rpython/jit/tool/test/test_oparser.py
--- a/rpython/jit/tool/test/test_oparser.py
+++ b/rpython/jit/tool/test/test_oparser.py
@@ -24,8 +24,9 @@
finish() # (tricky)
"""
loop = self.parse(x)
- assert len(loop.operations) == 3
- assert [op.getopnum() for op in loop.operations] == [rop.INT_ADD, rop.INT_SUB,
+ ops = loop._get_operations()
+ assert len(ops) == 3
+ assert [op.getopnum() for op in ops] == [rop.INT_ADD, rop.INT_SUB,
rop.FINISH]
assert len(loop.inputargs) == 2
assert loop.operations[-1].getdescr()
More information about the pypy-commit
mailing list