Author: Carl Friedrich Bolz <[email protected]>
Branch: guard-compatible
Changeset: r83257:d948bc9b9400
Date: 2016-03-22 15:11 +0100
http://bitbucket.org/pypy/pypy/changeset/d948bc9b9400/

Log:    temporary?: add some jit_debug operations into the log after the
        trace to show the conditions of a guard_compatible

diff --git a/rpython/jit/metainterp/compatible.py 
b/rpython/jit/metainterp/compatible.py
--- a/rpython/jit/metainterp/compatible.py
+++ b/rpython/jit/metainterp/compatible.py
@@ -49,16 +49,16 @@
             cond.activate_secondary(ref, loop_token)
         return True
 
-    def prepare_const_arg_call(self, op):
+    def prepare_const_arg_call(self, op, optimizer):
         from rpython.jit.metainterp.quasiimmut import QuasiImmutDescr
         copied_op = op.copy()
         copied_op.setarg(1, self.known_valid)
         if op.numargs() == 2:
-            return copied_op, PureCallCondition(op)
+            return copied_op, PureCallCondition(op, optimizer.metainterp_sd)
         arg2 = copied_op.getarg(2)
         if arg2.is_constant():
             # already a constant, can just use PureCallCondition
-            return copied_op, PureCallCondition(op)
+            return copied_op, PureCallCondition(op, optimizer.metainterp_sd)
 
         # really simple-minded pattern matching
         # the order of things is like this:
@@ -83,9 +83,17 @@
             return None, None
         copied_op.setarg(2, qmutdescr.constantfieldbox)
         self.last_quasi_immut_field_op = None
-        return copied_op, QuasiimmutGetfieldAndPureCallCondition(op, qmutdescr)
+        return copied_op, QuasiimmutGetfieldAndPureCallCondition(
+                op, qmutdescr, optimizer.metainterp_sd)
+
+    def repr_of_conditions(self, argrepr="?"):
+        return "\n".join([cond.repr(argrepr) for cond in self.conditions])
+
 
 class Condition(object):
+    def __init__(self, metainterp_sd):
+        self.metainterp_sd = metainterp_sd
+
     def check(self, cpu, ref):
         raise NotImplementedError
 
@@ -98,9 +106,22 @@
     def same_cond(self, other, res):
         return False
 
+    def repr(self):
+        return ""
+
+    @staticmethod
+    def _repr_const(arg):
+        from rpython.jit.metainterp.history import ConstInt, ConstFloat, 
ConstPtr
+        if isinstance(arg, ConstInt):
+            return str(arg.value)
+        elif isinstance(arg, ConstPtr):
+            return arg._getrepr_()
+        elif isinstance(arg, ConstFloat):
+            return str(arg.getfloat())
 
 class PureCallCondition(Condition):
-    def __init__(self, op):
+    def __init__(self, op, metainterp_sd):
+        Condition.__init__(self, metainterp_sd)
         args = op.getarglist()[:]
         args[1] = None
         self.args = args
@@ -142,9 +163,22 @@
                 return False
         return True
 
+    def repr(self, argrepr="?"):
+        addr = self.args[0].getaddr()
+        funcname = self.metainterp_sd.get_name_from_address(addr)
+        if not funcname:
+            funcname = hex(self.args[0].getint())
+        result = self._repr_const(self.res)
+        if len(self.args) == 2:
+            extra = ''
+        else:
+            extra = ', ' + ', '.join([self._repr_const(arg) for arg in 
self.args[2:]])
+        return "compatible if %s == %s(%s%s)" % (result, funcname, argrepr, 
extra)
+
 
 class QuasiimmutGetfieldAndPureCallCondition(PureCallCondition):
-    def __init__(self, op, qmutdescr):
+    def __init__(self, op, qmutdescr, metainterp_sd):
+        Condition.__init__(self, metainterp_sd)
         args = op.getarglist()[:]
         args[1] = None
         args[2] = None
@@ -209,3 +243,15 @@
             if not self.args[i].same_constant(other.args[i]):
                 return False
         return True
+
+    def repr(self, argrepr="?"):
+        addr = self.args[0].getaddr()
+        funcname = self.metainterp_sd.get_name_from_address(addr)
+        result = self._repr_const(self.res)
+        if len(self.args) == 3:
+            extra = ''
+        else:
+            extra = ', ' + ', '.join([self._repr_const(arg) for arg in 
self.args[3:]])
+        attrname = self.fielddescr.repr_of_descr()
+        return "compatible if %s == %s(%s, %s.%s%s)" % (
+                result, funcname, argrepr, argrepr, attrname, extra)
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
@@ -1139,6 +1139,11 @@
                 guard_value_op.getarg(0))
         ResumeGuardDescr.make_a_counter_per_value(self, guard_value_op, index)
 
+    def repr_of_conditions(self, argrepr="?"):
+        if self._compatibility_conditions:
+            return self._compatibility_conditions.repr_of_conditions(argrepr)
+        return ''
+
 # ____________________________________________________________
 
 memory_error = MemoryError()
diff --git a/rpython/jit/metainterp/logger.py b/rpython/jit/metainterp/logger.py
--- a/rpython/jit/metainterp/logger.py
+++ b/rpython/jit/metainterp/logger.py
@@ -181,7 +181,8 @@
             s_offset = ""
         else:
             s_offset = "+%d: " % offset
-        args = ", ".join([self.repr_of_arg(op.getarg(i)) for i in 
range(op.numargs())])
+        argreprs = [self.repr_of_arg(op.getarg(i)) for i in 
range(op.numargs())]
+        args = ", ".join(argreprs)
 
         if op.type != 'v':
             res = self.repr_of_arg(op) + " = "
@@ -204,6 +205,17 @@
                                           for arg in op.getfailargs()]) + ']'
         else:
             fail_args = ''
+        if op.getopnum() == rop.GUARD_COMPATIBLE and op.getdescr() is not None:
+            from rpython.jit.metainterp.compile import GuardCompatibleDescr
+            descr = op.getdescr()
+            assert isinstance(descr, GuardCompatibleDescr)
+            conditions = descr.repr_of_conditions(argreprs[0])
+            if conditions:
+                # make fake jit-debug ops to print
+                conditions = conditions.split("\n")
+                for i in range(len(conditions)):
+                    conditions[i] = "jit_debug('%s')" % (conditions[i], )
+                fail_args += "\n" + "\n".join(conditions)
         return s_offset + res + op.getopname() + '(' + args + ')' + fail_args
 
 
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
@@ -142,7 +142,8 @@
                     ccond = info._compatibility_conditions
                     if ccond:
                         # it's subject to guard_compatible
-                        copied_op, cond = ccond.prepare_const_arg_call(op)
+                        copied_op, cond = ccond.prepare_const_arg_call(
+                                op, self.optimizer)
                         if copied_op:
                             result = self._can_optimize_call_pure(copied_op)
                             if result is not None:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to