[pypy-commit] pypy jit-leaner-frontend: clean up the calling convention of rop vs op

fijal pypy.commits at gmail.com
Tue Mar 22 14:12:28 EDT 2016


Author: fijal
Branch: jit-leaner-frontend
Changeset: r83264:d2202ec34cb6
Date: 2016-03-22 20:11 +0200
http://bitbucket.org/pypy/pypy/changeset/d2202ec34cb6/

Log:	clean up the calling convention of rop vs op

diff --git a/rpython/jit/metainterp/optimizeopt/heap.py b/rpython/jit/metainterp/optimizeopt/heap.py
--- a/rpython/jit/metainterp/optimizeopt/heap.py
+++ b/rpython/jit/metainterp/optimizeopt/heap.py
@@ -347,7 +347,7 @@
             opnum == rop.COPYSTRCONTENT or       # no effect on GC struct/array
             opnum == rop.COPYUNICODECONTENT):    # no effect on GC struct/array
             return
-        if op.is_call():
+        if rop.is_call(op.opnum):
             if rop.is_call_assembler(op.getopnum()):
                 self._seen_guard_not_invalidated = False
             else:
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
@@ -464,8 +464,9 @@
         else:
             last_guard_pos = -1
         assert opinfo is None or opinfo.__class__ is info.NonNullPtrInfo
-        if (op.is_getfield() or op.getopnum() == rop.SETFIELD_GC or
-            op.getopnum() == rop.QUASIIMMUT_FIELD):
+        opnum = op.opnum
+        if (rop.is_getfield(opnum) or opnum == rop.SETFIELD_GC or
+            opnum == rop.QUASIIMMUT_FIELD):
             descr = op.getdescr()
             parent_descr = descr.get_parent_descr()
             if parent_descr.is_object():
@@ -473,14 +474,14 @@
             else:
                 opinfo = info.StructPtrInfo(parent_descr)
             opinfo.init_fields(parent_descr, descr.get_index())
-        elif (op.is_getarrayitem() or op.getopnum() == rop.SETARRAYITEM_GC or
-              op.getopnum() == rop.ARRAYLEN_GC):
+        elif (rop.is_getarrayitem(opnum) or opnum == rop.SETARRAYITEM_GC or
+              opnum == rop.ARRAYLEN_GC):
             opinfo = info.ArrayPtrInfo(op.getdescr())
-        elif op.getopnum() in (rop.GUARD_CLASS, rop.GUARD_NONNULL_CLASS):
+        elif opnum in (rop.GUARD_CLASS, rop.GUARD_NONNULL_CLASS):
             opinfo = info.InstancePtrInfo()
-        elif op.getopnum() in (rop.STRLEN,):
+        elif opnum in (rop.STRLEN,):
             opinfo = vstring.StrPtrInfo(vstring.mode_string)            
-        elif op.getopnum() in (rop.UNICODELEN,):
+        elif opnum in (rop.UNICODELEN,):
             opinfo = vstring.StrPtrInfo(vstring.mode_unicode)
         else:
             assert False, "operations %s unsupported" % op
@@ -542,7 +543,7 @@
         dispatch_opt(self, op)
 
     def emit_operation(self, op):
-        if op.returns_bool_result():
+        if rop.returns_bool_result(op.opnum):
             self.getintbound(op).make_bool()
         self._emit_operation(op)
         op = self.get_box_replacement(op)
@@ -561,8 +562,8 @@
         if op.is_constant():
             return # can happen e.g. if we postpone the operation that becomes
             # constant
-        # XXX kill
-        op = self.replace_op_with(op, op.getopnum())
+        # XXX kill, requires thinking
+        op = self.replace_op_with(op, op.opnum)
         for i in range(op.numargs()):
             arg = self.force_box(op.getarg(i))
             op.setarg(i, arg)
@@ -580,8 +581,10 @@
                 op = self.emit_guard_operation(op, pendingfields)
         elif op.can_raise():
             self.exception_might_have_happened = True
-        if ((op.has_no_side_effect() or op.is_guard() or op.is_jit_debug() or
-             op.is_ovf()) and not self.is_call_pure_pure_canraise(op)):
+        opnum = op.opnum
+        if ((rop.has_no_side_effect(opnum) or rop.is_guard(opnum) or
+             rop.is_jit_debug(opnum) or
+             rop.is_ovf(opnum)) and not self.is_call_pure_pure_canraise(op)):
             pass
         else:
             self._last_guard_op = None
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
@@ -75,8 +75,8 @@
         dispatch_opt(self, op)
 
     def optimize_default(self, op):
-        canfold = op.is_always_pure()
-        if op.is_ovf():
+        canfold = rop.is_always_pure(op.opnum)
+        if rop.is_ovf(op.opnum):
             self.postponed_op = op
             return
         if self.postponed_op:
@@ -110,7 +110,7 @@
 
         # otherwise, the operation remains
         self.emit_operation(op)
-        if op.returns_bool_result():
+        if rop.returns_bool_result(op.opnum):
             self.getintbound(op).make_bool()
         if save:
             recentops = self.getrecentops(op.getopnum())
@@ -221,9 +221,9 @@
     def produce_potential_short_preamble_ops(self, sb):
         ops = self.optimizer._newoperations
         for i, op in enumerate(ops):
-            if op.is_always_pure():
+            if rop.is_always_pure(op.opnum):
                 sb.add_pure_op(op)
-            if op.is_ovf() and ops[i + 1].getopnum() == rop.GUARD_NO_OVERFLOW:
+            if rop.is_ovf(op.opnum) and ops[i + 1].getopnum() == rop.GUARD_NO_OVERFLOW:
                 sb.add_pure_op(op)
         for i in self.call_pure_positions:
             op = ops[i]
@@ -232,7 +232,7 @@
 
             effectinfo = op.getdescr().get_extra_info()
             if not effectinfo.check_can_raise(ignore_memoryerror=True):
-                assert op.is_call()
+                assert rop.is_call(op.opnum)
                 sb.add_pure_op(op)
 
 dispatch_opt = make_dispatcher_method(OptPure, 'optimize_',
diff --git a/rpython/jit/metainterp/optimizeopt/shortpreamble.py b/rpython/jit/metainterp/optimizeopt/shortpreamble.py
--- a/rpython/jit/metainterp/optimizeopt/shortpreamble.py
+++ b/rpython/jit/metainterp/optimizeopt/shortpreamble.py
@@ -72,7 +72,7 @@
         pop = PreambleOp(self.res, preamble_op, invented_name)
         assert not opinfo.is_virtual()
         descr = self.getfield_op.getdescr()
-        if g.is_getfield():
+        if rop.is_getfield(g.opnum):
             cf = optheap.field_cache(descr)
             opinfo.setfield(preamble_op.getdescr(), self.res, pop,
                             optheap, cf)
@@ -92,7 +92,7 @@
         preamble_arg = sb.produce_arg(sop.getarg(0))
         if preamble_arg is None:
             return None
-        if sop.is_getfield():
+        if rop.is_getfield(sop.opnum):
             preamble_op = ResOperation(sop.getopnum(), [preamble_arg],
                                        descr=sop.getdescr())
         else:
@@ -117,7 +117,7 @@
             op.set_forwarded(self.res)
         else:
             op = self.res
-        if preamble_op.is_call():
+        if rop.is_call(preamble_op.opnum):
             optpure.extra_call_pure.append(PreambleOp(op, preamble_op,
                                                       invented_name))
         else:
@@ -132,7 +132,7 @@
             if newarg is None:
                 return None
             arglist.append(newarg)
-        if op.is_call():
+        if rop.is_call(op.opnum):
             opnum = OpHelpers.call_pure_for_descr(op.getdescr())
         else:
             opnum = op.getopnum()
diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -391,7 +391,7 @@
                 for box in self._map_args(mapping, short_jump_args)]
 
     def _expand_info(self, arg, infos):
-        if isinstance(arg, AbstractResOp) and arg.is_same_as():
+        if isinstance(arg, AbstractResOp) and rop.is_same_as(arg.opnum):
             info = self.optimizer.getinfo(arg.getarg(0))
         else:
             info = self.optimizer.getinfo(arg)
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
@@ -205,7 +205,7 @@
                             type = vecinfo.datatype
                             signed = vecinfo.signed
                             bytesize = vecinfo.bytesize
-            if op.returns_bool_result():
+            if rop.returns_bool_result(op.opnum):
                 type = 'i'
             self.setinfo(type, bytesize, signed)
 
@@ -402,58 +402,10 @@
     def is_foldable_guard(self):
         return rop.is_foldable_guard(self.getopnun())
 
-    def is_guard_exception(self):
-        return rop.is_guard_
-        return (self.getopnum() == rop.GUARD_EXCEPTION or
-                self.getopnum() == rop.GUARD_NO_EXCEPTION)
-
-    def is_guard_overflow(self):
-        return (self.getopnum() == rop.GUARD_OVERFLOW or
-                self.getopnum() == rop.GUARD_NO_OVERFLOW)
-
-    def is_jit_debug(self):
-        return rop._JIT_DEBUG_FIRST <= self.getopnum() <= rop._JIT_DEBUG_LAST
-
-    def is_always_pure(self):
-        # Tells whether an operation is pure based solely on the opcode.
-        # Other operations (e.g. getfield ops) may be pure in some cases are well.
-        return rop._ALWAYS_PURE_FIRST <= self.getopnum() <= rop._ALWAYS_PURE_LAST
-
-    def has_no_side_effect(self):
-        return rop._NOSIDEEFFECT_FIRST <= self.getopnum() <= rop._NOSIDEEFFECT_LAST
-
-    def is_malloc(self):
-        # a slightly different meaning from can_malloc
-        return rop._MALLOC_FIRST <= self.getopnum() <= rop._MALLOC_LAST
-
-    def can_malloc(self):
-        return self.is_call() or self.is_malloc()
-
-    def is_call(self):
-        return rop._CALL_FIRST <= self.getopnum() <= rop._CALL_LAST
-
-    def is_same_as(self):
-        return self.opnum in (rop.SAME_AS_I, rop.SAME_AS_F, rop.SAME_AS_R)
-
-    def is_getfield(self):
-        return self.opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F, rop.GETFIELD_GC_R)
-
-    def is_getarrayitem(self):
-        return self.opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F,
-                              rop.GETARRAYITEM_GC_R, rop.GETARRAYITEM_GC_PURE_I,
-                              rop.GETARRAYITEM_GC_PURE_F,
-                              rop.GETARRAYITEM_GC_PURE_R)
-
-    def is_vector_arithmetic(self):
-        return rop._VEC_ARITHMETIC_FIRST <= self.getopnum() <= rop._VEC_ARITHMETIC_LAST
-
-    def is_raw_array_access(self):
-        return self.is_raw_load() or self.is_raw_store()
-
     def is_primitive_array_access(self):
         """ Indicates that this operations loads/stores a
         primitive type (int,float) """
-        if self.is_primitive_load() or self.is_primitive_store():
+        if rop.is_primitive_load(self.opnum) or rop.is_primitive_store(self.opnum):
             descr = self.getdescr()
             if not we_are_translated():
                 from rpython.jit.backend.llgraph.runner import _getdescr
@@ -462,24 +414,6 @@
                 return True
         return False
 
-    def is_primitive_load(self):
-        return rop._RAW_LOAD_FIRST < self.getopnum() < rop._RAW_LOAD_LAST
-
-    def is_primitive_store(self):
-        return rop._RAW_STORE_FIRST < self.getopnum() < rop._RAW_STORE_LAST
-
-    def is_final(self):
-        return rop._FINAL_FIRST <= self.getopnum() <= rop._FINAL_LAST
-
-    def returns_bool_result(self):
-        return self._cls_has_bool_result
-
-    #def forget_value(self): -- in the base class, AbstractResOpOrInputArg
-    #    pass
-
-    def is_label(self):
-        return self.getopnum() == rop.LABEL
-
     def is_vector(self):
         return False
 
@@ -1442,27 +1376,30 @@
     def can_raise(opnum):
         return rop._CANRAISE_FIRST <= opnum <= rop._CANRAISE_LAST
 
-    def is_malloc(self):
+    @staticmethod
+    def is_malloc(opnum):
         # a slightly different meaning from can_malloc
-        return rop._MALLOC_FIRST <= self.getopnum() <= rop._MALLOC_LAST
+        return rop._MALLOC_FIRST <= opnum <= rop._MALLOC_LAST
 
-    def can_malloc(self):
-        return self.is_call() or self.is_malloc()
+    @staticmethod
+    def can_malloc(opnum):
+        return rop.is_call(opnum) or rop.is_malloc(opnum)
 
     @staticmethod
     def is_same_as(opnum):
         return opnum in (rop.SAME_AS_I, rop.SAME_AS_F, rop.SAME_AS_R)
 
-    def is_getfield(self):
-        return self.opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F,
-                              rop.GETFIELD_GC_R, rop.GETFIELD_GC_PURE_I,
-                              rop.GETFIELD_GC_PURE_R, rop.GETFIELD_GC_PURE_F)
+    @staticmethod
+    def is_getfield(opnum):
+        return opnum in (rop.GETFIELD_GC_I, rop.GETFIELD_GC_F,
+                              rop.GETFIELD_GC_R)
 
-    def is_getarrayitem(self):
-        return self.opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F,
-                              rop.GETARRAYITEM_GC_R, rop.GETARRAYITEM_GC_PURE_I,
-                              rop.GETARRAYITEM_GC_PURE_F,
-                              rop.GETARRAYITEM_GC_PURE_R)
+    @staticmethod
+    def is_getarrayitem(opnum):
+        return opnum in (rop.GETARRAYITEM_GC_I, rop.GETARRAYITEM_GC_F,
+                         rop.GETARRAYITEM_GC_R, rop.GETARRAYITEM_GC_PURE_I,
+                         rop.GETARRAYITEM_GC_PURE_F,
+                         rop.GETARRAYITEM_GC_PURE_R)
 
     @staticmethod
     def is_real_call(opnum):
@@ -1503,42 +1440,33 @@
     def is_ovf(opnum):
         return rop._OVF_FIRST <= opnum <= rop._OVF_LAST
 
-    def is_vector_arithmetic(self):
-        return rop._VEC_ARITHMETIC_FIRST <= self.getopnum() <= rop._VEC_ARITHMETIC_LAST
+    @staticmethod
+    def is_vector_arithmetic(opnum):
+        return rop._VEC_ARITHMETIC_FIRST <= opnum <= rop._VEC_ARITHMETIC_LAST
 
-    def is_raw_array_access(self):
-        return self.is_raw_load() or self.is_raw_store()
+    @staticmethod
+    def is_raw_array_access(opnum):
+        return rop.is_raw_load(opnum) or rop.is_raw_store(opnum)
 
-    def is_primitive_array_access(self):
-        """ Indicates that this operations loads/stores a
-        primitive type (int,float) """
-        if self.is_primitive_load() or self.is_primitive_store():
-            descr = self.getdescr()
-            if not we_are_translated():
-                from rpython.jit.backend.llgraph.runner import _getdescr
-                descr = _getdescr(self)
-            if descr and descr.is_array_of_primitives():
-                return True
-        return False
+    @staticmethod
+    def is_primitive_load(opnum):
+        return rop._RAW_LOAD_FIRST < opnum < rop._RAW_LOAD_LAST
 
-    def is_primitive_load(self):
-        return rop._RAW_LOAD_FIRST < self.getopnum() < rop._RAW_LOAD_LAST
+    @staticmethod
+    def is_primitive_store(opnum):
+        return rop._RAW_STORE_FIRST < opnum < rop._RAW_STORE_LAST
 
-    def is_primitive_store(self):
-        return rop._RAW_STORE_FIRST < self.getopnum() < rop._RAW_STORE_LAST
-
-    def is_final(self):
-        return rop._FINAL_FIRST <= self.getopnum() <= rop._FINAL_LAST
+    @staticmethod
+    def is_final(opnum):
+        return rop._FINAL_FIRST <= opnum <= rop._FINAL_LAST
 
     @staticmethod
     def returns_bool_result(opnum):
         return opclasses[opnum]._cls_has_bool_result
 
-    #def forget_value(self): -- in the base class, AbstractResOpOrInputArg
-    #    pass
-
-    def is_label(self):
-        return self.getopnum() == rop.LABEL
+    @staticmethod
+    def is_label(opnum):
+        return opnum == rop.LABEL
 
     @staticmethod
     def is_call(opnum):


More information about the pypy-commit mailing list