[pypy-commit] pypy optresult: hack hack hack until we start passing more tests from test_loop

fijal noreply at buildbot.pypy.org
Fri Nov 21 09:11:16 CET 2014


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: optresult
Changeset: r74629:e2f4be5fe8dc
Date: 2014-11-21 10:11 +0200
http://bitbucket.org/pypy/pypy/changeset/e2f4be5fe8dc/

Log:	hack hack hack until we start passing more tests from test_loop

diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -912,7 +912,7 @@
         # cond_call can't have a return value
         self.execute_call(calldescr, func, *args)
 
-    def execute_call(self, calldescr, func, *args):
+    def _execute_call(self, calldescr, func, *args):
         effectinfo = calldescr.get_extra_info()
         if effectinfo is not None and hasattr(effectinfo, 'oopspecindex'):
             oopspecindex = effectinfo.oopspecindex
@@ -928,6 +928,11 @@
             res = _example_res[getkind(TP.RESULT)[0]]
         return res
 
+    execute_call_i = _execute_call
+    execute_call_r = _execute_call
+    execute_call_f = _execute_call
+    execute_call_n = _execute_call
+
     def execute_call_may_force(self, calldescr, func, *args):
         call_op = self.lltrace.operations[self.current_index]
         guard_op = self.lltrace.operations[self.current_index + 1]
diff --git a/rpython/jit/metainterp/compile.py b/rpython/jit/metainterp/compile.py
--- a/rpython/jit/metainterp/compile.py
+++ b/rpython/jit/metainterp/compile.py
@@ -785,7 +785,6 @@
     """Try to compile a new bridge leading from the beginning of the history
     to some existing place.
     """
-    xxx
     from rpython.jit.metainterp.optimizeopt import optimize_trace
 
     # The history contains new operations to attach as the code for the
@@ -797,7 +796,9 @@
     new_trace.inputargs = metainterp.history.inputargs[:]
     # clone ops, as optimize_bridge can mutate the ops
 
-    new_trace.operations = [op.clone() for op in metainterp.history.operations]
+    memo = Memo()
+    new_trace.operations = [op.clone(memo) for op in
+                            metainterp.history.operations]
     metainterp_sd = metainterp.staticdata
     state = metainterp.jitdriver_sd.warmstate
     if isinstance(resumekey, ResumeAtPositionDescr):
@@ -805,7 +806,8 @@
     else:
         inline_short_preamble = True
     try:
-        optimize_trace(metainterp_sd, new_trace, state.enable_opts, inline_short_preamble)
+        optimize_trace(metainterp_sd, new_trace, state.enable_opts,
+                       inline_short_preamble)
     except InvalidLoop:
         debug_print("compile_new_bridge: got an InvalidLoop")
         # XXX I am fairly convinced that optimize_bridge cannot actually raise
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
@@ -1,7 +1,7 @@
 """This implements pyjitpl's execution of operations.
 """
 
-from rpython.rtyper.lltypesystem import lltype, rstr
+from rpython.rtyper.lltypesystem import lltype, rstr, llmemory
 from rpython.rlib.rarithmetic import ovfcheck, r_longlong, is_valid_int
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rlib.objectmodel import specialize
@@ -15,81 +15,81 @@
 
 # ____________________________________________________________
 
-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
-    for i in range(1, len(argboxes)):
-        type = argboxes[i].type
-        if   type == INT:   count_i += 1
-        elif type == REF:   count_r += 1
-        elif type == FLOAT: count_f += 1
-    # allocate lists for each type that has at least one argument
-    if count_i: args_i = [0] * count_i
-    else:       args_i = None
-    if count_r: args_r = [NULL] * count_r
-    else:       args_r = None
-    if count_f: args_f = [longlong.ZEROF] * count_f
-    else:       args_f = None
-    # fill in the lists
-    count_i = count_r = count_f = 0
-    for i in range(1, len(argboxes)):
-        box = argboxes[i]
-        if   box.type == INT:
-            args_i[count_i] = box.getint()
-            count_i += 1
-        elif box.type == REF:
-            args_r[count_r] = box.getref_base()
-            count_r += 1
-        elif box.type == FLOAT:
-            args_f[count_f] = box.getfloatstorage()
-            count_f += 1
-    # get the function address as an integer
-    func = argboxes[0].getint()
-    # do the call using the correct function from the cpu
-    rettype = descr.get_result_type()
-    if rettype == INT or rettype == 'S':       # *S*ingle float
-        try:
-            result = cpu.bh_call_i(func, args_i, args_r, args_f, descr)
-        except Exception, e:
-            metainterp.execute_raised(e)
-            result = 0
-        return BoxInt(result)
-    if rettype == REF:
-        try:
-            result = cpu.bh_call_r(func, args_i, args_r, args_f, descr)
-        except Exception, e:
-            metainterp.execute_raised(e)
-            result = NULL
-        return BoxPtr(result)
-    if rettype == FLOAT or rettype == 'L':     # *L*ong long
-        try:
-            result = cpu.bh_call_f(func, args_i, args_r, args_f, descr)
-        except Exception, e:
-            metainterp.execute_raised(e)
-            result = longlong.ZEROF
-        return BoxFloat(result)
-    if rettype == VOID:
-        try:
-            cpu.bh_call_v(func, args_i, args_r, args_f, descr)
-        except Exception, e:
-            metainterp.execute_raised(e)
-        return None
-    raise AssertionError("bad rettype")
+def new_do_call(rettype):
+    def do_call(cpu, metainterp, argboxes, descr):
+        assert metainterp is not None
+        # count the number of arguments of the different types
+        count_i = count_r = count_f = 0
+        for i in range(1, len(argboxes)):
+            type = argboxes[i].type
+            if   type == INT:   count_i += 1
+            elif type == REF:   count_r += 1
+            elif type == FLOAT: count_f += 1
+        # allocate lists for each type that has at least one argument
+        if count_i: args_i = [0] * count_i
+        else:       args_i = None
+        if count_r: args_r = [NULL] * count_r
+        else:       args_r = None
+        if count_f: args_f = [longlong.ZEROF] * count_f
+        else:       args_f = None
+        # fill in the lists
+        count_i = count_r = count_f = 0
+        for i in range(1, len(argboxes)):
+            box = argboxes[i]
+            if   box.type == INT:
+                args_i[count_i] = box.getint()
+                count_i += 1
+            elif box.type == REF:
+                args_r[count_r] = box.getref_base()
+                count_r += 1
+            elif box.type == FLOAT:
+                args_f[count_f] = box.getfloatstorage()
+                count_f += 1
+        # get the function address as an integer
+        func = argboxes[0].getint()
+        # do the call using the correct function from the cpu
+        if rettype == INT or rettype == 'S':       # *S*ingle float
+            try:
+                result = cpu.bh_call_i(func, args_i, args_r, args_f, descr)
+            except Exception, e:
+                metainterp.execute_raised(e)
+                result = 0
+            return result
+        if rettype == REF:
+            try:
+                result = cpu.bh_call_r(func, args_i, args_r, args_f, descr)
+            except Exception, e:
+                metainterp.execute_raised(e)
+                result = NULL
+            return result
+        if rettype == FLOAT:
+            try:
+                result = cpu.bh_call_f(func, args_i, args_r, args_f, descr)
+            except Exception, e:
+                metainterp.execute_raised(e)
+                result = longlong.ZEROF
+            return result
+        if rettype == VOID:
+            try:
+                cpu.bh_call_v(func, args_i, args_r, args_f, descr)
+            except Exception, e:
+                metainterp.execute_raised(e)
+            return None
+        raise AssertionError("bad rettype")
+    return do_call
 
-do_call_r = do_call
-do_call_i = do_call
-do_call_f = do_call
-do_call_n = do_call
-do_call_loopinvariant_r = do_call
-do_call_loopinvariant_i = do_call
-do_call_loopinvariant_f = do_call
-do_call_loopinvariant_n = do_call
-do_call_may_force_r = do_call
-do_call_may_force_i = do_call
-do_call_may_force_f = do_call
-do_call_may_force_n = do_call
+do_call_r = new_do_call("r")
+do_call_i = new_do_call("i")
+do_call_f = new_do_call("f")
+do_call_n = new_do_call("v")
+do_call_loopinvariant_r = do_call_r
+do_call_loopinvariant_i = do_call_i
+do_call_loopinvariant_f = do_call_f
+do_call_loopinvariant_n = do_call_n
+do_call_may_force_r = do_call_r
+do_call_may_force_i = do_call_i
+do_call_may_force_f = do_call_f
+do_call_may_force_n = do_call_n
 
 def do_cond_call(cpu, metainterp, argboxes, descr):
     condbox = argboxes[0]
@@ -451,27 +451,26 @@
 execute._annspecialcase_ = 'specialize:arg(2)'
 
 def execute_varargs(cpu, metainterp, opnum, argboxes, descr):
-    xxxx
     # only for opnums with a variable arity (calls, typically)
     check_descr(descr)
     func = get_execute_function(opnum, -1, True)
     return func(cpu, metainterp, argboxes, descr)
 execute_varargs._annspecialcase_ = 'specialize:arg(2)'
 
-
+ at specialize.argtype(0)
+def wrap_constant(value):
+    if isinstance(value, int):
+        return ConstInt(value)
+    elif isinstance(value, float):
+        return ConstFloat(value)
+    else:
+        assert lltype.typeOf(value) == llmemory.GCREF
+        return ConstPtr(value)
+    
 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
+    return wrap_constant(_execute_nonspec(cpu, metainterp, opnum, argboxes,
+                                          descr, type))
 
 @specialize.arg(5)
 def _execute_nonspec(cpu, metainterp, opnum, argboxes, descr=None, type='i'):
diff --git a/rpython/jit/metainterp/heapcache.py b/rpython/jit/metainterp/heapcache.py
--- a/rpython/jit/metainterp/heapcache.py
+++ b/rpython/jit/metainterp/heapcache.py
@@ -141,7 +141,7 @@
             rop._NOSIDEEFFECT_FIRST <= opnum <= rop._NOSIDEEFFECT_LAST or
             rop._GUARD_FIRST <= opnum <= rop._GUARD_LAST):
             return
-        if opnum == rop.CALL or opnum == rop.CALL_LOOPINVARIANT or opnum == rop.COND_CALL:
+        if rop._CALL_FIRST <= opnum <= rop._CALL_LAST:
             effectinfo = descr.get_extra_info()
             ef = effectinfo.extraeffect
             if (ef == effectinfo.EF_LOOPINVARIANT or
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
@@ -354,17 +354,6 @@
             return rop.GETARRAYITEM_GC_PURE_F
         return rop.GETARRAYITEM_GC_PURE_I
 
-    def call_for_descr(self, descr):
-        tp = descr.get_result_type()
-        if tp == 'i':
-            return rop.CALL_I
-        elif tp == 'r':
-            return rop.CALL_R
-        elif tp == 'f':
-            return rop.CALL_F
-        assert tp == 'v'
-        return rop.CALL_N
-
     def setup(self):
         pass
 
diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -13,7 +13,7 @@
 from rpython.jit.metainterp.logger import Logger
 from rpython.jit.metainterp.optimizeopt.util import args_dict
 from rpython.jit.metainterp.resoperation import rop, InputArgInt,\
-     InputArgFloat, InputArgRef
+     InputArgFloat, InputArgRef, OpHelpers
 from rpython.rlib import nonconst, rstack
 from rpython.rlib.debug import debug_start, debug_stop, debug_print
 from rpython.rlib.debug import have_debug_prints, make_sure_not_resized
@@ -602,12 +602,17 @@
         return indexbox
 
     @arguments("box", "descr")
-    def _opimpl_getfield_gc_any(self, box, fielddescr):
+    def opimpl_getfield_gc_i(self, box, fielddescr):
         return self._opimpl_getfield_gc_any_pureornot(
-                rop.GETFIELD_GC, box, fielddescr)
-    opimpl_getfield_gc_i = _opimpl_getfield_gc_any
-    opimpl_getfield_gc_r = _opimpl_getfield_gc_any
-    opimpl_getfield_gc_f = _opimpl_getfield_gc_any
+                rop.GETFIELD_GC_I, box, fielddescr, 'i')
+    @arguments("box", "descr")
+    def opimpl_getfield_gc_r(self, box, fielddescr):
+        return self._opimpl_getfield_gc_any_pureornot(
+                rop.GETFIELD_GC_R, box, fielddescr, 'r')
+    @arguments("box", "descr")
+    def opimpl_getfield_gc_f(self, box, fielddescr):
+        return self._opimpl_getfield_gc_any_pureornot(
+                rop.GETFIELD_GC_F, box, fielddescr, 'f')
 
     @arguments("box", "descr")
     def _opimpl_getfield_gc_pure_any(self, box, fielddescr):
@@ -630,15 +635,21 @@
     opimpl_getinteriorfield_gc_f = _opimpl_getinteriorfield_gc_any
     opimpl_getinteriorfield_gc_r = _opimpl_getinteriorfield_gc_any
 
-    @specialize.arg(1)
-    def _opimpl_getfield_gc_any_pureornot(self, opnum, box, fielddescr):
+    @specialize.arg(1, 4)
+    def _opimpl_getfield_gc_any_pureornot(self, opnum, box, fielddescr, type):
         tobox = self.metainterp.heapcache.getfield(box, fielddescr)
         if tobox is not None:
             # sanity check: see whether the current struct value
             # corresponds to what the cache thinks the value is
-            resbox = executor.execute(self.metainterp.cpu, self.metainterp,
-                                      rop.GETFIELD_GC, fielddescr, box)
-            assert resbox.constbox().same_constant(tobox.constbox())
+            resvalue = executor.execute(self.metainterp.cpu, self.metainterp,
+                                        opnum, fielddescr, box)
+            if type == 'i':
+                assert resvalue == tobox.getint()
+            elif type == 'r':
+                assert resvalue == tobox.getref_base()
+            else:
+                assert type == 'f'
+                assert resvalue == tobox.getfloatstorage()
             return tobox
         resbox = self.execute_with_descr(opnum, fielddescr, box)
         self.metainterp.heapcache.getfield_now_known(box, fielddescr, resbox)
@@ -1460,7 +1471,8 @@
                                                 descr, False, False)
                 exc = effectinfo.check_can_raise()
                 pure = effectinfo.check_is_elidable()
-                return self.execute_varargs(rop.CALL, allboxes, descr, exc, pure)
+                opnum = OpHelpers.call_for_descr(descr)
+                return self.execute_varargs(opnum, allboxes, descr, exc, pure)
         finally:
             debug_stop("jit-residual-call")
 
@@ -1896,16 +1908,15 @@
         # execute the operation
         profiler = self.staticdata.profiler
         profiler.count_ops(opnum)
-        xxx
-        resbox = executor.execute_varargs(self.cpu, self,
-                                          opnum, argboxes, descr)
+        resvalue = executor.execute_varargs(self.cpu, self,
+                                            opnum, argboxes, descr)
         # check if the operation can be constant-folded away
         argboxes = list(argboxes)
         if rop._ALWAYS_PURE_FIRST <= opnum <= rop._ALWAYS_PURE_LAST:
-            resbox = self._record_helper_pure_varargs(opnum, resbox, descr, argboxes)
-        else:
-            resbox = self._record_helper_nonpure_varargs(opnum, resbox, descr, argboxes)
-        return resbox
+            return self._record_helper_pure_varargs(opnum, resvalue, descr,
+                                                    argboxes)
+        return self._record_helper_nonpure_varargs(opnum, resvalue, descr,
+                                                   argboxes)
 
     @specialize.argtype(2)
     def _record_helper_pure(self, opnum, resvalue, descr, *argboxes):
@@ -1917,15 +1928,13 @@
                                                        list(argboxes))
 
     @specialize.argtype(2)
-    def _record_helper_pure_varargs(self, opnum, resbox, descr, argboxes):
-        xxx
+    def _record_helper_pure_varargs(self, opnum, resvalue, descr, argboxes):
         canfold = self._all_constants_varargs(argboxes)
         if canfold:
-            resbox = resbox.constbox()       # ensure it is a Const
-            return resbox
+            return executor.wrap_constant(resvalue)
         else:
-            resbox = resbox.nonconstbox()    # ensure it is a Box
-            return self._record_helper_nonpure_varargs(opnum, resbox, descr, argboxes)
+            return self._record_helper_nonpure_varargs(opnum, resvalue, descr,
+                                                       argboxes)
 
     @specialize.argtype(2)
     def _record_helper_nonpure_varargs(self, opnum, resvalue, descr, argboxes):
@@ -1939,7 +1948,8 @@
         self.heapcache.invalidate_caches(opnum, descr, argboxes)
         op = self.history.record(opnum, argboxes, resvalue, descr)
         self.attach_debug_info(op)
-        return op
+        if op.type != 'v':
+            return op
 
     def execute_new_with_vtable(self, known_class):
         resbox = self.execute_and_record(rop.NEW_WITH_VTABLE, None,
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
@@ -867,3 +867,16 @@
         op.setarg = setarg
         op.setdescr = setdescr
     return newops
+
+class OpHelpers(object):
+    @staticmethod
+    def call_for_descr(descr):
+        tp = descr.get_result_type()
+        if tp == 'i':
+            return rop.CALL_I
+        elif tp == 'r':
+            return rop.CALL_R
+        elif tp == 'f':
+            return rop.CALL_F
+        assert tp == 'v'
+        return rop.CALL_N
diff --git a/rpython/jit/metainterp/resume.py b/rpython/jit/metainterp/resume.py
--- a/rpython/jit/metainterp/resume.py
+++ b/rpython/jit/metainterp/resume.py
@@ -1,13 +1,13 @@
 from rpython.jit.codewriter.effectinfo import EffectInfo
 from rpython.jit.metainterp import jitprof
-from rpython.jit.metainterp.history import (Box, Const, ConstInt, getkind,
-    BoxInt, BoxPtr, BoxFloat, INT, REF, FLOAT, AbstractDescr)
-from rpython.jit.metainterp.resoperation import rop
+from rpython.jit.metainterp.history import (Const, ConstInt, getkind,
+    INT, REF, FLOAT, AbstractDescr)
+from rpython.jit.metainterp.resoperation import rop, InputArgInt,\
+     InputArgFloat, InputArgRef
 from rpython.rlib import rarithmetic, rstack
 from rpython.rlib.objectmodel import (we_are_translated, specialize,
-        compute_unique_id, import_from_mixin)
-from rpython.rlib.debug import (have_debug_prints, ll_assert, debug_start,
-    debug_stop, debug_print)
+        compute_unique_id)
+from rpython.rlib.debug import ll_assert, debug_print
 from rpython.rtyper import annlowlevel
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rstr
 from rpython.rtyper.rclass import OBJECTPTR
@@ -1160,11 +1160,11 @@
             num += len(self.liveboxes)
             assert num >= 0
         if kind == INT:
-            box = BoxInt(self.cpu.get_int_value(self.deadframe, num))
+            box = InputArgInt(self.cpu.get_int_value(self.deadframe, num))
         elif kind == REF:
-            box = BoxPtr(self.cpu.get_ref_value(self.deadframe, num))
+            box = InputArgRef(self.cpu.get_ref_value(self.deadframe, num))
         elif kind == FLOAT:
-            box = BoxFloat(self.cpu.get_float_value(self.deadframe, num))
+            box = InputArgFloat(self.cpu.get_float_value(self.deadframe, num))
         else:
             assert 0, "bad kind: %d" % ord(kind)
         self.liveboxes[num] = box


More information about the pypy-commit mailing list