[pypy-svn] r77134 - in pypy/branch/resoperation-refactoring/pypy/jit: backend/cli backend/llgraph backend/llsupport backend/llsupport/test backend/llvm backend/test backend/x86 metainterp metainterp/optimizeopt metainterp/test tool

antocuni at codespeak.net antocuni at codespeak.net
Fri Sep 17 14:29:51 CEST 2010


Author: antocuni
Date: Fri Sep 17 14:29:40 2010
New Revision: 77134

Modified:
   pypy/branch/resoperation-refactoring/pypy/jit/backend/cli/method.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/llgraph/runner.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/gc.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/test/test_gc.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/llvm/compile.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/test/test_random.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/assembler.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/regalloc.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/history.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/logger.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/intbounds.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_oparser.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_optimizeopt.py
   pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_virtualref.py
   pypy/branch/resoperation-refactoring/pypy/jit/tool/showstats.py
Log:
(david, antocuni): introduce an official interface to get the opnum, and remove the old "opnum" attribute (well, not so far :-))



Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/cli/method.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/cli/method.py	Fri Sep 17 14:29:40 2010
@@ -207,7 +207,7 @@
 
     def _collect_types(self, operations, box2classes):
         for op in operations:
-            if op.opnum in (rop.GETFIELD_GC, rop.SETFIELD_GC):
+            if op.getopnum() in (rop.GETFIELD_GC, rop.SETFIELD_GC):
                 box = op.args[0]
                 descr = op.descr
                 assert isinstance(descr, runner.FieldDescr)
@@ -335,7 +335,7 @@
         while self.i < N:
             op = oplist[self.i]
             self.emit_debug(op.repr())
-            func = self.operations[op.opnum]
+            func = self.operations[op.getopnum()]
             assert func is not None
             func(self, op)
             self.i += 1
@@ -410,7 +410,7 @@
 
     def emit_ovf_op(self, op, emit_op):
         next_op = self.oplist[self.i+1]
-        if next_op.opnum == rop.GUARD_NO_OVERFLOW:
+        if next_op.getopnum() == rop.GUARD_NO_OVERFLOW:
                 self.i += 1
                 self.emit_ovf_op_and_guard(op, next_op, emit_op)
                 return

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/llgraph/runner.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/llgraph/runner.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/llgraph/runner.py	Fri Sep 17 14:29:40 2010
@@ -151,11 +151,11 @@
 
     def _compile_operations(self, c, operations, var2index):
         for op in operations:
-            llimpl.compile_add(c, op.opnum)
+            llimpl.compile_add(c, op.getopnum())
             descr = op.descr
             if isinstance(descr, Descr):
                 llimpl.compile_add_descr(c, descr.ofs, descr.typeinfo)
-            if isinstance(descr, history.LoopToken) and op.opnum != rop.JUMP:
+            if isinstance(descr, history.LoopToken) and op.getopnum() != rop.JUMP:
                 llimpl.compile_add_loop_token(c, descr)
             if self.is_oo and isinstance(descr, (OODescr, MethDescr)):
                 # hack hack, not rpython
@@ -204,12 +204,12 @@
                                                                x))
         op = operations[-1]
         assert op.is_final()
-        if op.opnum == rop.JUMP:
+        if op.getopnum() == rop.JUMP:
             targettoken = op.descr
             assert isinstance(targettoken, history.LoopToken)
             compiled_version = targettoken._llgraph_compiled_version
             llimpl.compile_add_jump_target(c, compiled_version)
-        elif op.opnum == rop.FINISH:
+        elif op.getopnum() == rop.FINISH:
             faildescr = op.descr
             index = self.get_fail_descr_number(faildescr)
             llimpl.compile_add_fail(c, index)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/gc.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/gc.py	Fri Sep 17 14:29:40 2010
@@ -559,7 +559,7 @@
         #
         newops = []
         for op in operations:
-            if op.opnum == rop.DEBUG_MERGE_POINT:
+            if op.getopnum() == rop.DEBUG_MERGE_POINT:
                 continue
             # ---------- replace ConstPtrs with GETFIELD_RAW ----------
             # xxx some performance issue here
@@ -576,7 +576,7 @@
                                                    self.single_gcref_descr))
                         op.setarg(i, box)
             # ---------- write barrier for SETFIELD_GC ----------
-            if op.opnum == rop.SETFIELD_GC:
+            if op.getopnum() == rop.SETFIELD_GC:
                 v = op.getarg(1)
                 if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
                                              bool(v.value)): # store a non-NULL
@@ -584,7 +584,7 @@
                     op = ResOperation(rop.SETFIELD_RAW, op._args, None,
                                       descr=op.descr)
             # ---------- write barrier for SETARRAYITEM_GC ----------
-            if op.opnum == rop.SETARRAYITEM_GC:
+            if op.getopnum() == rop.SETARRAYITEM_GC:
                 v = op.getarg(2)
                 if isinstance(v, BoxPtr) or (isinstance(v, ConstPtr) and
                                              bool(v.value)): # store a non-NULL

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/test/test_gc.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/test/test_gc.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/llsupport/test/test_gc.py	Fri Sep 17 14:29:40 2010
@@ -258,7 +258,7 @@
         gc_ll_descr._gen_write_barrier(newops, v_base, v_value)
         assert llop1.record == []
         assert len(newops) == 1
-        assert newops[0].opnum == rop.COND_CALL_GC_WB
+        assert newops[0].getopnum() == rop.COND_CALL_GC_WB
         assert newops[0].getarg(0) == v_base
         assert newops[0].getarg(1) == v_value
         assert newops[0].result is None
@@ -298,12 +298,12 @@
         gc_ll_descr.gcrefs = MyFakeGCRefList()
         gc_ll_descr.rewrite_assembler(MyFakeCPU(), operations)
         assert len(operations) == 2
-        assert operations[0].opnum == rop.GETFIELD_RAW
+        assert operations[0].getopnum() == rop.GETFIELD_RAW
         assert operations[0].getarg(0) == ConstInt(43)
         assert operations[0].descr == gc_ll_descr.single_gcref_descr
         v_box = operations[0].result
         assert isinstance(v_box, BoxPtr)
-        assert operations[1].opnum == rop.PTR_EQ
+        assert operations[1].getopnum() == rop.PTR_EQ
         assert operations[1].getarg(0) == v_random_box
         assert operations[1].getarg(1) == v_box
         assert operations[1].result == v_result
@@ -337,7 +337,7 @@
         finally:
             rgc.can_move = old_can_move
         assert len(operations) == 1
-        assert operations[0].opnum == rop.PTR_EQ
+        assert operations[0].getopnum() == rop.PTR_EQ
         assert operations[0].getarg(0) == v_random_box
         assert operations[0].getarg(1) == ConstPtr(s_gcref)
         assert operations[0].result == v_result
@@ -358,12 +358,12 @@
         gc_ll_descr.rewrite_assembler(self.fake_cpu, operations)
         assert len(operations) == 2
         #
-        assert operations[0].opnum == rop.COND_CALL_GC_WB
+        assert operations[0].getopnum() == rop.COND_CALL_GC_WB
         assert operations[0].getarg(0) == v_base
         assert operations[0].getarg(1) == v_value
         assert operations[0].result is None
         #
-        assert operations[1].opnum == rop.SETFIELD_RAW
+        assert operations[1].getopnum() == rop.SETFIELD_RAW
         assert operations[1].getarg(0) == v_base
         assert operations[1].getarg(1) == v_value
         assert operations[1].descr == field_descr
@@ -382,12 +382,12 @@
         gc_ll_descr.rewrite_assembler(self.fake_cpu, operations)
         assert len(operations) == 2
         #
-        assert operations[0].opnum == rop.COND_CALL_GC_WB
+        assert operations[0].getopnum() == rop.COND_CALL_GC_WB
         assert operations[0].getarg(0) == v_base
         assert operations[0].getarg(1) == v_value
         assert operations[0].result is None
         #
-        assert operations[1].opnum == rop.SETARRAYITEM_RAW
+        assert operations[1].getopnum() == rop.SETARRAYITEM_RAW
         assert operations[1].getarg(0) == v_base
         assert operations[1].getarg(1) == v_index
         assert operations[1].getarg(2) == v_value

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/llvm/compile.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/llvm/compile.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/llvm/compile.py	Fri Sep 17 14:29:40 2010
@@ -107,7 +107,7 @@
         # store away the exception into self.backup_exc_xxx, *unless* the
         # branch starts with a further GUARD_EXCEPTION/GUARD_NO_EXCEPTION.
         if exc:
-            opnum = operations[0].opnum
+            opnum = operations[0].getopnum()
             if opnum not in (rop.GUARD_EXCEPTION, rop.GUARD_NO_EXCEPTION):
                 self._store_away_exception()
         # Normal handling of the operations follows.
@@ -115,7 +115,7 @@
             self._generate_op(op)
 
     def _generate_op(self, op):
-        opnum = op.opnum
+        opnum = op.getopnum()
         for i, name in all_operations:
             if opnum == i:
                 meth = getattr(self, name)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/test/test_random.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/test/test_random.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/test/test_random.py	Fri Sep 17 14:29:40 2010
@@ -580,7 +580,7 @@
             assert self.should_fail_by.fail_args is not None
             return self.should_fail_by.fail_args
         else:
-            assert self.should_fail_by.opnum == rop.FINISH
+            assert self.should_fail_by.getopnum() == rop.FINISH
             return self.should_fail_by.getarglist()
 
     def clear_state(self):
@@ -620,7 +620,7 @@
         exc = cpu.grab_exc_value()
         if (self.guard_op is not None and
             self.guard_op.is_guard_exception()):
-            if self.guard_op.opnum == rop.GUARD_NO_EXCEPTION:
+            if self.guard_op.getopnum() == rop.GUARD_NO_EXCEPTION:
                 assert exc
         else:
             assert not exc

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/assembler.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/assembler.py	Fri Sep 17 14:29:40 2010
@@ -389,7 +389,7 @@
     def _find_debug_merge_point(self, operations):
 
         for op in operations:
-            if op.opnum == rop.DEBUG_MERGE_POINT:
+            if op.getopnum() == rop.DEBUG_MERGE_POINT:
                 funcname = op.getarg(0)._get_str()
                 break
         else:
@@ -681,10 +681,10 @@
             self.mc.POP(loc)
 
     def regalloc_perform(self, op, arglocs, resloc):
-        genop_list[op.opnum](self, op, arglocs, resloc)
+        genop_list[op.getopnum()](self, op, arglocs, resloc)
 
     def regalloc_perform_discard(self, op, arglocs):
-        genop_discard_list[op.opnum](self, op, arglocs)
+        genop_discard_list[op.getopnum()](self, op, arglocs)
 
     def regalloc_perform_with_guard(self, op, guard_op, faillocs,
                                     arglocs, resloc, current_depths):
@@ -692,14 +692,14 @@
         assert isinstance(faildescr, AbstractFailDescr)
         faildescr._x86_current_depths = current_depths
         failargs = guard_op.fail_args
-        guard_opnum = guard_op.opnum
+        guard_opnum = guard_op.getopnum()
         guard_token = self.implement_guard_recovery(guard_opnum,
                                                     faildescr, failargs,
                                                     faillocs)
         if op is None:
             dispatch_opnum = guard_opnum
         else:
-            dispatch_opnum = op.opnum
+            dispatch_opnum = op.getopnum()
         res = genop_guard_list[dispatch_opnum](self, op, guard_op, guard_token,
                                                arglocs, resloc)
         faildescr._x86_adr_jump_offset = res
@@ -755,7 +755,7 @@
 
     def _cmpop_guard(cond, rev_cond, false_cond, false_rev_cond):
         def genop_cmp_guard(self, op, guard_op, guard_token, arglocs, result_loc):
-            guard_opnum = guard_op.opnum
+            guard_opnum = guard_op.getopnum()
             if isinstance(op.getarg(0), Const):
                 self.mc.CMP(arglocs[1], arglocs[0])
                 if guard_opnum == rop.GUARD_FALSE:
@@ -773,7 +773,7 @@
     def _cmpop_guard_float(cond, false_cond, need_jp):
         def genop_cmp_guard_float(self, op, guard_op, guard_token, arglocs,
                                   result_loc):
-            guard_opnum = guard_op.opnum
+            guard_opnum = guard_op.getopnum()
             self.mc.UCOMISD(arglocs[0], arglocs[1])
             # 16 is enough space for the rel8 jumps below and the rel32
             # jump in implement_guard
@@ -942,7 +942,7 @@
     genop_guard_float_ge = _cmpop_guard_float("AE", "B", False)
 
     def genop_guard_float_ne(self, op, guard_op, guard_token, arglocs, result_loc):
-        guard_opnum = guard_op.opnum
+        guard_opnum = guard_op.getopnum()
         self.mc.UCOMISD(arglocs[0], arglocs[1])
         # 16 is enough space for the rel8 jumps below and the rel32
         # jump in implement_guard
@@ -970,7 +970,7 @@
         self.mc.CVTSI2SD(resloc, arglocs[0])
 
     def genop_guard_int_is_true(self, op, guard_op, guard_token, arglocs, resloc):
-        guard_opnum = guard_op.opnum
+        guard_opnum = guard_op.getopnum()
         self.mc.CMP(arglocs[0], imm(0))
         if guard_opnum == rop.GUARD_TRUE:
             return self.implement_guard(guard_token, 'Z')
@@ -984,7 +984,7 @@
         self.mc.MOVZX8(resloc, rl)
 
     def genop_guard_int_is_zero(self, op, guard_op, guard_token, arglocs, resloc):
-        guard_opnum = guard_op.opnum
+        guard_opnum = guard_op.getopnum()
         self.mc.CMP(arglocs[0], imm(0))
         if guard_opnum == rop.GUARD_TRUE:
             return self.implement_guard(guard_token, 'NZ')
@@ -1216,7 +1216,7 @@
         return addr
 
     def _gen_guard_overflow(self, guard_op, guard_token):
-        guard_opnum = guard_op.opnum
+        guard_opnum = guard_op.getopnum()
         if guard_opnum == rop.GUARD_NO_OVERFLOW:
             return self.implement_guard(guard_token, 'O')
         elif guard_opnum == rop.GUARD_OVERFLOW:

Modified: pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/regalloc.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/regalloc.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/regalloc.py	Fri Sep 17 14:29:40 2010
@@ -268,7 +268,7 @@
                                               selected_reg, need_lower_byte)
 
     def _compute_loop_consts(self, inputargs, jump, looptoken):
-        if jump.opnum != rop.JUMP or jump.descr is not looptoken:
+        if jump.getopnum() != rop.JUMP or jump.descr is not looptoken:
             loop_consts = {}
         else:
             loop_consts = {}
@@ -352,19 +352,19 @@
         self.assembler.regalloc_perform_discard(op, arglocs)
 
     def can_merge_with_next_guard(self, op, i, operations):
-        if op.opnum == rop.CALL_MAY_FORCE or op.opnum == rop.CALL_ASSEMBLER:
-            assert operations[i + 1].opnum == rop.GUARD_NOT_FORCED
+        if op.getopnum() == rop.CALL_MAY_FORCE or op.getopnum() == rop.CALL_ASSEMBLER:
+            assert operations[i + 1].getopnum() == rop.GUARD_NOT_FORCED
             return True
         if not op.is_comparison():
             if op.is_ovf():
-                if (operations[i + 1].opnum != rop.GUARD_NO_OVERFLOW and
-                    operations[i + 1].opnum != rop.GUARD_OVERFLOW):
+                if (operations[i + 1].getopnum() != rop.GUARD_NO_OVERFLOW and
+                    operations[i + 1].getopnum() != rop.GUARD_OVERFLOW):
                     print "int_xxx_ovf not followed by guard_(no)_overflow"
                     raise AssertionError
                 return True
             return False
-        if (operations[i + 1].opnum != rop.GUARD_TRUE and
-            operations[i + 1].opnum != rop.GUARD_FALSE):
+        if (operations[i + 1].getopnum() != rop.GUARD_TRUE and
+            operations[i + 1].getopnum() != rop.GUARD_FALSE):
             return False
         if operations[i + 1].getarg(0) is not op.result:
             return False
@@ -385,10 +385,10 @@
                 self.possibly_free_vars_for_op(op)
                 continue
             if self.can_merge_with_next_guard(op, i, operations):
-                oplist_with_guard[op.opnum](self, op, operations[i + 1])
+                oplist_with_guard[op.getopnum()](self, op, operations[i + 1])
                 i += 1
             else:
-                oplist[op.opnum](self, op)
+                oplist[op.getopnum()](self, op)
             if op.result is not None:
                 self.possibly_free_var(op.result)
             self.rm._check_invariants()
@@ -412,7 +412,7 @@
                 arg = op.getarg(j)
                 if isinstance(arg, Box):
                     if arg not in start_live:
-                        print "Bogus arg in operation %d at %d" % (op.opnum, i)
+                        print "Bogus arg in operation %d at %d" % (op.getopnum(), i)
                         raise AssertionError
                     longevity[arg] = (start_live[arg], i)
             if op.is_guard():
@@ -421,7 +421,7 @@
                         continue
                     assert isinstance(arg, Box)
                     if arg not in start_live:
-                        print "Bogus arg in guard %d at %d" % (op.opnum, i)
+                        print "Bogus arg in guard %d at %d" % (op.getopnum(), i)
                         raise AssertionError
                     longevity[arg] = (start_live[arg], i)
         for arg in inputargs:

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/compile.py	Fri Sep 17 14:29:40 2010
@@ -234,10 +234,10 @@
 
     def store_final_boxes(self, guard_op, boxes):
         guard_op.fail_args = boxes
-        self.guard_opnum = guard_op.opnum
+        self.guard_opnum = guard_op.getopnum()
 
     def make_a_counter_per_value(self, guard_value_op):
-        assert guard_value_op.opnum == rop.GUARD_VALUE
+        assert guard_value_op.getopnum() == rop.GUARD_VALUE
         box = guard_value_op.getarg(0)
         try:
             i = guard_value_op.fail_args.index(box)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/graphpage.py	Fri Sep 17 14:29:40 2010
@@ -76,7 +76,7 @@
             for i, op in enumerate(graph.get_operations()):
                 if is_interesting_guard(op):
                     self.mark_starter(graphindex, i+1)
-                if op.opnum == rop.DEBUG_MERGE_POINT:
+                if op.getopnum() == rop.DEBUG_MERGE_POINT:
                     if not last_was_mergepoint:
                         last_was_mergepoint = True
                         self.mark_starter(graphindex, i)
@@ -167,7 +167,7 @@
                 self.genedge((graphindex, opstartindex),
                              (graphindex, opindex))
                 break
-        if op.opnum == rop.JUMP:
+        if op.getopnum() == rop.JUMP:
             tgt = op.descr
             tgt_g = -1
             if tgt is None:

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/history.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/history.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/history.py	Fri Sep 17 14:29:40 2010
@@ -785,7 +785,7 @@
                 assert box not in seen
                 seen[box] = True
         assert operations[-1].is_final()
-        if operations[-1].opnum == rop.JUMP:
+        if operations[-1].getopnum() == rop.JUMP:
             target = operations[-1].descr
             if target is not None:
                 assert isinstance(target, LoopToken)
@@ -811,7 +811,7 @@
         return '<%s>' % (self.name,)
 
 def _list_all_operations(result, operations, omit_finish=True):
-    if omit_finish and operations[-1].opnum == rop.FINISH:
+    if omit_finish and operations[-1].getopnum() == rop.FINISH:
         # xxx obscure
         return
     result.extend(operations)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/logger.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/logger.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/logger.py	Fri Sep 17 14:29:40 2010
@@ -79,7 +79,7 @@
             debug_print('[' + args + ']')
         for i in range(len(operations)):
             op = operations[i]
-            if op.opnum == rop.DEBUG_MERGE_POINT:
+            if op.getopnum() == rop.DEBUG_MERGE_POINT:
                 loc = op.getarg(0)._get_str()
                 debug_print("debug_merge_point('%s')" % (loc,))
                 continue

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizefindnode.py	Fri Sep 17 14:29:40 2010
@@ -144,7 +144,7 @@
 
     def find_nodes(self, operations):
         for op in operations:
-            opnum = op.opnum
+            opnum = op.getopnum()
             for value, func in find_nodes_ops:
                 if opnum == value:
                     func(self, op)
@@ -163,7 +163,7 @@
                 argboxes = [self.get_constant_box(op.getarg(i))
                             for i in range(op.numargs())]
                 resbox = execute_nonspec(self.cpu, None,
-                                         op.opnum, argboxes, op.descr)
+                                         op.getopnum(), argboxes, op.descr)
                 self.set_constant_node(op.result, resbox.constbox())
         # default case: mark the arguments as escaping
         for i in range(op.numargs()):
@@ -328,7 +328,7 @@
     def show(self):
         from pypy.jit.metainterp.viewnode import viewnodes, view
         op = self._loop.operations[-1]
-        assert op.opnum == rop.JUMP
+        assert op.getopnum() == rop.JUMP
         exitnodes = [self.getnode(arg) for arg in op.args]
         viewnodes(self.inputnodes, exitnodes)
         if hasattr(self._loop.token, "specnodes"):
@@ -347,7 +347,7 @@
         # Build the list of specnodes based on the result
         # computed by NodeFinder.find_nodes().
         op = loop.operations[-1]
-        assert op.opnum == rop.JUMP
+        assert op.getopnum() == rop.JUMP
         assert len(self.inputnodes) == op.numargs()
         while True:
             self.restart_needed = False

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/heap.py	Fri Sep 17 14:29:40 2010
@@ -105,7 +105,7 @@
         if op.is_guard():
             self.optimizer.pendingfields = self.force_lazy_setfields_for_guard()
             return
-        opnum = op.opnum
+        opnum = op.getopnum()
         if (opnum == rop.SETFIELD_GC or
             opnum == rop.SETARRAYITEM_GC or
             opnum == rop.DEBUG_MERGE_POINT):
@@ -142,7 +142,7 @@
                 return
             self.force_all_lazy_setfields()
         elif op.is_final() or (not we_are_translated() and
-                               op.opnum < 0):   # escape() operations
+                               op.getopnum() < 0):   # escape() operations
             self.force_all_lazy_setfields()
         self.clean_caches()
 
@@ -166,7 +166,7 @@
             # - is_comparison() for cases like "int_eq/setfield_gc/guard_true"
             # - CALL_MAY_FORCE: "call_may_force/setfield_gc/guard_not_forced"
             # - is_ovf(): "int_add_ovf/setfield_gc/guard_no_overflow"
-            opnum = prevop.opnum
+            opnum = prevop.getopnum()
             lastop_args = lastop.getarglist()
             if ((prevop.is_comparison() or opnum == rop.CALL_MAY_FORCE
                  or prevop.is_ovf())
@@ -257,7 +257,7 @@
                                    write=True)
 
     def propagate_forward(self, op):
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in optimize_ops:
             if opnum == value:
                 func(self, op)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/intbounds.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/intbounds.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/intbounds.py	Fri Sep 17 14:29:40 2010
@@ -9,7 +9,7 @@
        remove redundant guards"""
 
     def propagate_forward(self, op):
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in optimize_ops:
             if opnum == value:
                 func(self, op)
@@ -30,7 +30,7 @@
             op = self.optimizer.producer[box]
         except KeyError:
             return
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in propagate_bounds_ops:
             if opnum == value:
                 func(self, op)
@@ -84,9 +84,9 @@
         v2 = self.getvalue(op.getarg(1))
         resbound = v1.intbound.add_bound(v2.intbound)
         if resbound.has_lower and resbound.has_upper and \
-           self.nextop().opnum == rop.GUARD_NO_OVERFLOW:
+           self.nextop().getopnum() == rop.GUARD_NO_OVERFLOW:
             # Transform into INT_ADD and remove guard
-            op.opnum = rop.INT_ADD
+            op._opnum = rop.INT_ADD
             self.skip_nextop()
             self.optimize_INT_ADD(op)
         else:
@@ -99,9 +99,9 @@
         v2 = self.getvalue(op.getarg(1))
         resbound = v1.intbound.sub_bound(v2.intbound)
         if resbound.has_lower and resbound.has_upper and \
-               self.nextop().opnum == rop.GUARD_NO_OVERFLOW:
+               self.nextop().getopnum() == rop.GUARD_NO_OVERFLOW:
             # Transform into INT_SUB and remove guard
-            op.opnum = rop.INT_SUB
+            op._opnum = rop.INT_SUB
             self.skip_nextop()
             self.optimize_INT_SUB(op)
         else:
@@ -114,9 +114,9 @@
         v2 = self.getvalue(op.getarg(1))
         resbound = v1.intbound.mul_bound(v2.intbound)
         if resbound.has_lower and resbound.has_upper and \
-               self.nextop().opnum == rop.GUARD_NO_OVERFLOW:
+               self.nextop().getopnum() == rop.GUARD_NO_OVERFLOW:
             # Transform into INT_MUL and remove guard
-            op.opnum = rop.INT_MUL
+            op._opnum = rop.INT_MUL
             self.skip_nextop()
             self.optimize_INT_MUL(op)
         else:

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/optimizer.py	Fri Sep 17 14:29:40 2010
@@ -308,7 +308,7 @@
 
     def propagate_forward(self, op):
         self.producer[op.result] = op
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in optimize_ops:
             if opnum == value:
                 func(self, op)
@@ -348,7 +348,7 @@
             compile.giveup()
         descr.store_final_boxes(op, newboxes)
         #
-        if op.opnum == rop.GUARD_VALUE:
+        if op.getopnum() == rop.GUARD_VALUE:
             if self.getvalue(op.getarg(0)) in self.bool_boxes:
                 # Hack: turn guard_value(bool) into guard_true/guard_false.
                 # This is done after the operation is emitted, to let
@@ -377,7 +377,7 @@
                 args.append(self.values[arg].get_key_box())
             else:
                 args.append(arg)
-        args.append(ConstInt(op.opnum))
+        args.append(ConstInt(op.getopnum()))
         return args
 
     def optimize_default(self, op):
@@ -385,7 +385,7 @@
         is_ovf = op.is_ovf()
         if is_ovf:
             nextop = self.loop.operations[self.i + 1]
-            canfold = nextop.opnum == rop.GUARD_NO_OVERFLOW
+            canfold = nextop.getopnum() == rop.GUARD_NO_OVERFLOW
         if canfold:
             for i in range(op.numargs()):
                 if self.get_constant_box(op.getarg(i)) is None:
@@ -395,7 +395,7 @@
                 argboxes = [self.get_constant_box(op.getarg(i))
                             for i in range(op.numargs())]
                 resbox = execute_nonspec(self.cpu, None,
-                                         op.opnum, argboxes, op.descr)
+                                         op.getopnum(), argboxes, op.descr)
                 self.make_constant(op.result, resbox.constbox())
                 if is_ovf:
                     self.i += 1 # skip next operation, it is the unneeded guard
@@ -405,7 +405,7 @@
             args = self.make_args_key(op)
             oldop = self.pure_operations.get(args, None)
             if oldop is not None and oldop.descr is op.descr:
-                assert oldop.opnum == op.opnum
+                assert oldop.getopnum() == op.getopnum()
                 self.make_equal_to(op.result, self.getvalue(oldop.result))
                 if is_ovf:
                     self.i += 1 # skip next operation, it is the unneeded guard

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/rewrite.py	Fri Sep 17 14:29:40 2010
@@ -14,7 +14,7 @@
         if self.find_rewritable_bool(op, args):
             return
 
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in optimize_ops:
             if opnum == value:
                 func(self, op)
@@ -39,7 +39,7 @@
 
     def find_rewritable_bool(self, op, args):
         try:
-            oldopnum = opboolinvers[op.opnum]
+            oldopnum = opboolinvers[op.getopnum()]
             targs = [args[0], args[1], ConstInt(oldopnum)]
             if self.try_boolinvers(op, targs):
                 return True
@@ -47,7 +47,7 @@
             pass
 
         try:
-            oldopnum = opboolreflex[op.opnum] # FIXME: add INT_ADD, INT_MUL
+            oldopnum = opboolreflex[op.getopnum()] # FIXME: add INT_ADD, INT_MUL
             targs = [args[1], args[0], ConstInt(oldopnum)]
             oldop = self.optimizer.pure_operations.get(targs, None)
             if oldop is not None and oldop.descr is op.descr:
@@ -57,7 +57,7 @@
             pass
 
         try:
-            oldopnum = opboolinvers[opboolreflex[op.opnum]]
+            oldopnum = opboolinvers[opboolreflex[op.getopnum()]]
             targs = [args[1], args[0], ConstInt(oldopnum)]
             if self.try_boolinvers(op, targs):
                 return True
@@ -215,7 +215,7 @@
             # there already has been a guard_nonnull or guard_class or
             # guard_nonnull_class on this value.
             old_guard_op = self.optimizer.newoperations[value.last_guard_index]
-            if old_guard_op.opnum == rop.GUARD_NONNULL:
+            if old_guard_op.getopnum() == rop.GUARD_NONNULL:
                 # it was a guard_nonnull, which we replace with a
                 # guard_nonnull_class.
                 new_guard_op = old_guard_op.copy_and_change (rop.GUARD_NONNULL_CLASS,
@@ -253,7 +253,7 @@
             return
         # change the op to be a normal call, from the backend's point of view
         # there is no reason to have a separate operation for this
-        op.opnum = rop.CALL
+        op._opnum = rop.CALL
         self.emit_operation(op)
         resvalue = self.getvalue(op.result)
         self.optimizer.loop_invariant_results[key] = resvalue

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/optimizeopt/virtualize.py	Fri Sep 17 14:29:40 2010
@@ -446,7 +446,7 @@
                                          descr))
 
     def propagate_forward(self, op):
-        opnum = op.opnum
+        opnum = op.getopnum()
         for value, func in optimize_ops:
             if opnum == value:
                 func(self, op)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/pyjitpl.py	Fri Sep 17 14:29:40 2010
@@ -1922,7 +1922,7 @@
         vrefbox = self.virtualref_boxes[i+1]
         # record VIRTUAL_REF_FINISH just before the current CALL_MAY_FORCE
         call_may_force_op = self.history.operations.pop()
-        assert call_may_force_op.opnum == rop.CALL_MAY_FORCE
+        assert call_may_force_op.getopnum() == rop.CALL_MAY_FORCE
         self.history.record(rop.VIRTUAL_REF_FINISH,
                             [vrefbox, virtualbox], None)
         self.history.operations.append(call_may_force_op)
@@ -2088,7 +2088,7 @@
         """ Patch a CALL into a CALL_PURE.
         """
         op = self.history.operations[-1]
-        assert op.opnum == rop.CALL
+        assert op.getopnum() == rop.CALL
         resbox_as_const = resbox.constbox()
         for i in range(op.numargs()):
             if not isinstance(op.getarg(i), Const):
@@ -2100,7 +2100,7 @@
             return resbox_as_const
         # not all constants (so far): turn CALL into CALL_PURE, which might
         # be either removed later by optimizeopt or turned back into CALL.
-        op.opnum = rop.CALL_PURE
+        op._opnum = rop.CALL_PURE
         # XXX XXX replace when the resoperation refactoring has been finished
         op._args = [resbox_as_const] + op._args
         return resbox
@@ -2110,7 +2110,7 @@
         patching the CALL_MAY_FORCE that occurred just now.
         """
         op = self.history.operations.pop()
-        assert op.opnum == rop.CALL_MAY_FORCE
+        assert op.getopnum() == rop.CALL_MAY_FORCE
         num_green_args = targetjitdriver_sd.num_green_args
         arglist = op.getarglist()
         greenargs = arglist[1:num_green_args+1]
@@ -2124,7 +2124,7 @@
             # ^^^ and not "+=", which makes 'args' a resizable list
         warmrunnerstate = targetjitdriver_sd.warmstate
         token = warmrunnerstate.get_assembler_token(greenargs, args)
-        op.opnum = rop.CALL_ASSEMBLER
+        op._opnum = rop.CALL_ASSEMBLER
         op.setarglist(args)
         op.descr = token
         self.history.operations.append(op)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/resoperation.py	Fri Sep 17 14:29:40 2010
@@ -17,19 +17,13 @@
     def __init__(self, opnum, args, result, descr=None):
         make_sure_not_resized(args)
         assert isinstance(opnum, int)
-        self.opnum = opnum
+        self._opnum = opnum
         self._args = list(args)
         make_sure_not_resized(self._args)
         assert not isinstance(result, list)
         self.result = result
         self.setdescr(descr)
 
-    # XXX: just for debugging during the refactoring, kill me
-    def __setattr__(self, attr, value):
-        if attr == 'args':
-            import pdb;pdb.set_trace()
-        object.__setattr__(self, attr, value)
-
     def copy_and_change(self, opnum, args=None, result=None, descr=None):
         "shallow copy: the returned operation is meant to be used in place of self"
         if args is None:
@@ -43,6 +37,9 @@
         newop.setfailargs(self.getfailargs())
         return newop
 
+    def getopnum(self):
+        return self._opnum
+
     def getarg(self, i):
         return self._args[i]
 
@@ -81,7 +78,7 @@
         descr = self.descr
         if descr is not None:
             descr = descr.clone_if_mutable()
-        op = ResOperation(self.opnum, self._args, self.result, descr)
+        op = ResOperation(self._opnum, self._args, self.result, descr)
         op.fail_args = self.fail_args
         op.name = self.name
         if not we_are_translated():
@@ -110,44 +107,44 @@
 
     def getopname(self):
         try:
-            return opname[self.opnum].lower()
+            return opname[self._opnum].lower()
         except KeyError:
-            return '<%d>' % self.opnum
+            return '<%d>' % self._opnum
 
     def is_guard(self):
-        return rop._GUARD_FIRST <= self.opnum <= rop._GUARD_LAST
+        return rop._GUARD_FIRST <= self._opnum <= rop._GUARD_LAST
 
     def is_foldable_guard(self):
-        return rop._GUARD_FOLDABLE_FIRST <= self.opnum <= rop._GUARD_FOLDABLE_LAST
+        return rop._GUARD_FOLDABLE_FIRST <= self._opnum <= rop._GUARD_FOLDABLE_LAST
 
     def is_guard_exception(self):
-        return (self.opnum == rop.GUARD_EXCEPTION or
-                self.opnum == rop.GUARD_NO_EXCEPTION)
+        return (self._opnum == rop.GUARD_EXCEPTION or
+                self._opnum == rop.GUARD_NO_EXCEPTION)
 
     def is_guard_overflow(self):
-        return (self.opnum == rop.GUARD_OVERFLOW or
-                self.opnum == rop.GUARD_NO_OVERFLOW)
+        return (self._opnum == rop.GUARD_OVERFLOW or
+                self._opnum == rop.GUARD_NO_OVERFLOW)
 
     def is_always_pure(self):
-        return rop._ALWAYS_PURE_FIRST <= self.opnum <= rop._ALWAYS_PURE_LAST
+        return rop._ALWAYS_PURE_FIRST <= self._opnum <= rop._ALWAYS_PURE_LAST
 
     def has_no_side_effect(self):
-        return rop._NOSIDEEFFECT_FIRST <= self.opnum <= rop._NOSIDEEFFECT_LAST
+        return rop._NOSIDEEFFECT_FIRST <= self._opnum <= rop._NOSIDEEFFECT_LAST
 
     def can_raise(self):
-        return rop._CANRAISE_FIRST <= self.opnum <= rop._CANRAISE_LAST
+        return rop._CANRAISE_FIRST <= self._opnum <= rop._CANRAISE_LAST
 
     def is_ovf(self):
-        return rop._OVF_FIRST <= self.opnum <= rop._OVF_LAST
+        return rop._OVF_FIRST <= self._opnum <= rop._OVF_LAST
 
     def is_comparison(self):
         return self.is_always_pure() and self.returns_bool_result()
 
     def is_final(self):
-        return rop._FINAL_FIRST <= self.opnum <= rop._FINAL_LAST
+        return rop._FINAL_FIRST <= self._opnum <= rop._FINAL_LAST
 
     def returns_bool_result(self):
-        opnum = self.opnum
+        opnum = self._opnum
         if we_are_translated():
             assert opnum >= 0
         elif opnum < 0:

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/simple_optimize.py	Fri Sep 17 14:29:40 2010
@@ -11,17 +11,17 @@
     from pypy.jit.metainterp.history import AbstractDescr
     # change ARRAYCOPY to call, so we don't have to pass around
     # unnecessary information to the backend.  Do the same with VIRTUAL_REF_*.
-    if op.opnum == rop.ARRAYCOPY:
+    if op.getopnum() == rop.ARRAYCOPY:
         descr = op.getarg(0)
         assert isinstance(descr, AbstractDescr)
         args = op.getarglist()[1:]
         op = ResOperation(rop.CALL, args, op.result, descr=descr)
-    elif op.opnum == rop.CALL_PURE:
+    elif op.getopnum() == rop.CALL_PURE:
         args = op.getarglist()[1:]
         op = ResOperation(rop.CALL, args, op.result, op.descr)
-    elif op.opnum == rop.VIRTUAL_REF:
+    elif op.getopnum() == rop.VIRTUAL_REF:
         op = ResOperation(rop.SAME_AS, [op.getarg(0)], op.result)
-    elif op.opnum == rop.VIRTUAL_REF_FINISH:
+    elif op.getopnum() == rop.VIRTUAL_REF_FINISH:
         return []
     return [op]
 

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_oparser.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_oparser.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_oparser.py	Fri Sep 17 14:29:40 2010
@@ -16,7 +16,7 @@
     """
     loop = parse(x)
     assert len(loop.operations) == 3
-    assert [op.opnum for op in loop.operations] == [rop.INT_ADD, rop.INT_SUB,
+    assert [op.getopnum() for op in loop.operations] == [rop.INT_ADD, rop.INT_SUB,
                                                     rop.FINISH]
     assert len(loop.inputargs) == 2
     assert loop.operations[-1].descr

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_optimizeopt.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_optimizeopt.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_optimizeopt.py	Fri Sep 17 14:29:40 2010
@@ -140,7 +140,7 @@
             print '%-39s| %s' % (txt1[:39], txt2[:39])
             txt1 = txt1[39:]
             txt2 = txt2[39:]
-        assert op1.opnum == op2.opnum
+        assert op1.getopnum() == op2.getopnum()
         assert op1.numargs() == op2.numargs()
         for i in range(op1.numargs()):
             x = op1.getarg(i)
@@ -150,7 +150,7 @@
             assert op1.result == remap[op2.result]
         else:
             remap[op2.result] = op1.result
-        if op1.opnum != rop.JUMP:      # xxx obscure
+        if op1.getopnum() != rop.JUMP:      # xxx obscure
             assert op1.descr == op2.descr
         if op1.fail_args or op2.fail_args:
             assert len(op1.fail_args) == len(op2.fail_args)

Modified: pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_virtualref.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_virtualref.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/metainterp/test/test_virtualref.py	Fri Sep 17 14:29:40 2010
@@ -71,7 +71,7 @@
         #
         ops = self.metainterp.staticdata.stats.loops[0].operations
         [guard_op] = [op for op in ops
-                         if op.opnum == rop.GUARD_NOT_FORCED]
+                         if op.getopnum() == rop.GUARD_NOT_FORCED]
         bxs1 = [box for box in guard_op.fail_args
                   if str(box._getrepr_()).endswith('.X')]
         assert len(bxs1) == 1

Modified: pypy/branch/resoperation-refactoring/pypy/jit/tool/showstats.py
==============================================================================
--- pypy/branch/resoperation-refactoring/pypy/jit/tool/showstats.py	(original)
+++ pypy/branch/resoperation-refactoring/pypy/jit/tool/showstats.py	Fri Sep 17 14:29:40 2010
@@ -17,7 +17,7 @@
         num_dmp = 0
         num_guards = 0
         for op in loop.operations:
-            if op.opnum == rop.DEBUG_MERGE_POINT:
+            if op.getopnum() == rop.DEBUG_MERGE_POINT:
                 num_dmp += 1
             else:
                 num_ops += 1



More information about the Pypy-commit mailing list