[pypy-svn] r77115 - pypy/branch/resoperation-refactoring/pypy/jit/backend/x86

antocuni at codespeak.net antocuni at codespeak.net
Thu Sep 16 15:20:25 CEST 2010


Author: antocuni
Date: Thu Sep 16 15:20:24 2010
New Revision: 77115

Modified:
   pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/assembler.py
   pypy/branch/resoperation-refactoring/pypy/jit/backend/x86/regalloc.py
Log:
(david, antocuni) start refactoring ResOperation in the x86 backend


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	Thu Sep 16 15:20:24 2010
@@ -390,7 +390,7 @@
 
         for op in operations:
             if op.opnum == rop.DEBUG_MERGE_POINT:
-                funcname = op.args[0]._get_str()
+                funcname = op.getarg(0)._get_str()
                 break
         else:
             funcname = "<loop %d>" % len(self.loop_run_counters)
@@ -725,7 +725,7 @@
     def _cmpop(cond, rev_cond):
         def genop_cmp(self, op, arglocs, result_loc):
             rl = result_loc.lowest8bits()
-            if isinstance(op.args[0], Const):
+            if isinstance(op.getarg(0), Const):
                 self.mc.CMP(arglocs[1], arglocs[0])
                 self.mc.SET_ir(rx86.Conditions[rev_cond], rl.value)
             else:
@@ -756,7 +756,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
-            if isinstance(op.args[0], Const):
+            if isinstance(op.getarg(0), Const):
                 self.mc.CMP(arglocs[1], arglocs[0])
                 if guard_opnum == rop.GUARD_FALSE:
                     return self.implement_guard(guard_token, rev_cond)
@@ -1120,7 +1120,7 @@
         assert isinstance(baseofs, ImmedLoc)
         assert isinstance(scale_loc, ImmedLoc)
         dest_addr = AddressLoc(base_loc, ofs_loc, scale_loc.value, baseofs.value)
-        if op.args[2].type == FLOAT:
+        if op.getarg(2).type == FLOAT:
             self.mc.MOVSD(dest_addr, value_loc)
         else:
             if IS_X86_64 and scale_loc.value == 3:
@@ -1244,8 +1244,8 @@
     genop_guard_guard_isnull = genop_guard_guard_false
 
     def genop_guard_guard_value(self, ign_1, guard_op, guard_token, locs, ign_2):
-        if guard_op.args[0].type == FLOAT:
-            assert guard_op.args[1].type == FLOAT
+        if guard_op.getarg(0).type == FLOAT:
+            assert guard_op.getarg(1).type == FLOAT
             self.mc.UCOMISD(locs[0], locs[1])
         else:
             self.mc.CMP(locs[0], locs[1])
@@ -1636,8 +1636,8 @@
         assert isinstance(sizeloc, ImmedLoc)
         size = sizeloc.value
 
-        if isinstance(op.args[0], Const):
-            x = imm(op.args[0].getint())
+        if isinstance(op.getarg(0), Const):
+            x = imm(op.getarg(0).getint())
         else:
             x = arglocs[1]
         if x is eax:

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	Thu Sep 16 15:20:24 2010
@@ -267,7 +267,7 @@
         else:
             loop_consts = {}
             for i in range(len(inputargs)):
-                if inputargs[i] is jump.args[i]:
+                if inputargs[i] is jump.getarg(i):
                     loop_consts[inputargs[i]] = i
         return loop_consts
 
@@ -360,7 +360,7 @@
         if (operations[i + 1].opnum != rop.GUARD_TRUE and
             operations[i + 1].opnum != rop.GUARD_FALSE):
             return False
-        if operations[i + 1].args[0] is not op.result:
+        if operations[i + 1].getarg(0) is not op.result:
             return False
         if (self.longevity[op.result][1] > i + 1 or
             op.result in operations[i + 1].fail_args):
@@ -402,7 +402,8 @@
             op = operations[i]
             if op.result is not None:
                 start_live[op.result] = i
-            for arg in op.args:
+            for j in range(op.numargs()):
+                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)
@@ -432,9 +433,9 @@
         return self.rm.loc(v)
 
     def _consider_guard(self, op):
-        loc = self.rm.make_sure_var_in_reg(op.args[0])
+        loc = self.rm.make_sure_var_in_reg(op.getarg(0))
         self.perform_guard(op, [loc], None)
-        self.rm.possibly_free_var(op.args[0])
+        self.rm.possibly_free_var(op.getarg(0))
 
     consider_guard_true = _consider_guard
     consider_guard_false = _consider_guard
@@ -453,7 +454,7 @@
         self.perform_guard(op, [], None)
 
     def consider_guard_exception(self, op):
-        loc = self.rm.make_sure_var_in_reg(op.args[0])
+        loc = self.rm.make_sure_var_in_reg(op.getarg(0))
         box = TempBox()
         loc1 = self.rm.force_allocate_reg(box, op.args)
         if op.result in self.longevity:
@@ -469,25 +470,25 @@
     consider_guard_overflow    = consider_guard_no_exception
 
     def consider_guard_value(self, op):
-        x = self.make_sure_var_in_reg(op.args[0])
-        y = self.loc(op.args[1])
+        x = self.make_sure_var_in_reg(op.getarg(0))
+        y = self.loc(op.getarg(1))
         self.perform_guard(op, [x, y], None)
         self.possibly_free_vars(op.args)
 
     def consider_guard_class(self, op):
-        assert isinstance(op.args[0], Box)
-        x = self.rm.make_sure_var_in_reg(op.args[0])
-        y = self.loc(op.args[1])
+        assert isinstance(op.getarg(0), Box)
+        x = self.rm.make_sure_var_in_reg(op.getarg(0))
+        y = self.loc(op.getarg(1))
         self.perform_guard(op, [x, y], None)
         self.rm.possibly_free_vars(op.args)
 
     consider_guard_nonnull_class = consider_guard_class
 
     def _consider_binop_part(self, op):
-        x = op.args[0]
-        argloc = self.loc(op.args[1])
+        x = op.getarg(0)
+        argloc = self.loc(op.getarg(1))
         loc = self.rm.force_result_in_reg(op.result, x, op.args)
-        self.rm.possibly_free_var(op.args[1])
+        self.rm.possibly_free_var(op.getarg(1))
         return loc, argloc
 
     def _consider_binop(self, op):
@@ -510,17 +511,17 @@
     consider_int_add_ovf = _consider_binop_with_guard
 
     def consider_int_neg(self, op):
-        res = self.rm.force_result_in_reg(op.result, op.args[0])
+        res = self.rm.force_result_in_reg(op.result, op.getarg(0))
         self.Perform(op, [res], res)
 
     consider_int_invert = consider_int_neg
 
     def consider_int_lshift(self, op):
-        if isinstance(op.args[1], Const):
-            loc2 = self.rm.convert_to_imm(op.args[1])
+        if isinstance(op.getarg(1), Const):
+            loc2 = self.rm.convert_to_imm(op.getarg(1))
         else:
-            loc2 = self.rm.make_sure_var_in_reg(op.args[1], selected_reg=ecx)
-        loc1 = self.rm.force_result_in_reg(op.result, op.args[0], op.args)
+            loc2 = self.rm.make_sure_var_in_reg(op.getarg(1), selected_reg=ecx)
+        loc1 = self.rm.force_result_in_reg(op.result, op.getarg(0), op.args)
         self.Perform(op, [loc1, loc2], loc1)
         self.rm.possibly_free_vars(op.args)
 
@@ -528,8 +529,8 @@
     consider_uint_rshift = consider_int_lshift
 
     def _consider_int_div_or_mod(self, op, resultreg, trashreg):
-        l0 = self.rm.make_sure_var_in_reg(op.args[0], selected_reg=eax)
-        l1 = self.rm.make_sure_var_in_reg(op.args[1], selected_reg=ecx)
+        l0 = self.rm.make_sure_var_in_reg(op.getarg(0), selected_reg=eax)
+        l1 = self.rm.make_sure_var_in_reg(op.getarg(1), selected_reg=ecx)
         l2 = self.rm.force_allocate_reg(op.result, selected_reg=resultreg)
         # the register (eax or edx) not holding what we are looking for
         # will be just trash after that operation
@@ -552,8 +553,8 @@
     consider_uint_floordiv = consider_int_floordiv
 
     def _consider_compop(self, op, guard_op):
-        vx = op.args[0]
-        vy = op.args[1]
+        vx = op.getarg(0)
+        vy = op.getarg(1)
         arglocs = [self.loc(vx), self.loc(vy)]
         if (vx in self.rm.reg_bindings or vy in self.rm.reg_bindings or
             isinstance(vx, Const) or isinstance(vy, Const)):
@@ -582,8 +583,8 @@
     consider_ptr_ne = _consider_compop
 
     def _consider_float_op(self, op):
-        loc1 = self.xrm.loc(op.args[1])
-        loc0 = self.xrm.force_result_in_reg(op.result, op.args[0], op.args)
+        loc1 = self.xrm.loc(op.getarg(1))
+        loc0 = self.xrm.force_result_in_reg(op.result, op.getarg(0), op.args)
         self.Perform(op, [loc0, loc1], loc0)
         self.xrm.possibly_free_vars(op.args)
 
@@ -593,9 +594,9 @@
     consider_float_truediv = _consider_float_op
 
     def _consider_float_cmp(self, op, guard_op):
-        loc0 = self.xrm.make_sure_var_in_reg(op.args[0], op.args,
+        loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0), op.args,
                                              imm_fine=False)
-        loc1 = self.xrm.loc(op.args[1])
+        loc1 = self.xrm.loc(op.getarg(1))
         arglocs = [loc0, loc1]
         self.xrm.possibly_free_vars(op.args)
         if guard_op is None:
@@ -612,26 +613,26 @@
     consider_float_ge = _consider_float_cmp
 
     def consider_float_neg(self, op):
-        loc0 = self.xrm.force_result_in_reg(op.result, op.args[0])
+        loc0 = self.xrm.force_result_in_reg(op.result, op.getarg(0))
         self.Perform(op, [loc0], loc0)
-        self.xrm.possibly_free_var(op.args[0])
+        self.xrm.possibly_free_var(op.getarg(0))
 
     def consider_float_abs(self, op):
-        loc0 = self.xrm.force_result_in_reg(op.result, op.args[0])
+        loc0 = self.xrm.force_result_in_reg(op.result, op.getarg(0))
         self.Perform(op, [loc0], loc0)
-        self.xrm.possibly_free_var(op.args[0])
+        self.xrm.possibly_free_var(op.getarg(0))
 
     def consider_cast_float_to_int(self, op):
-        loc0 = self.xrm.make_sure_var_in_reg(op.args[0], imm_fine=False)
+        loc0 = self.xrm.make_sure_var_in_reg(op.getarg(0), imm_fine=False)
         loc1 = self.rm.force_allocate_reg(op.result)
         self.Perform(op, [loc0], loc1)
-        self.xrm.possibly_free_var(op.args[0])
+        self.xrm.possibly_free_var(op.getarg(0))
 
     def consider_cast_int_to_float(self, op):
-        loc0 = self.rm.loc(op.args[0])
+        loc0 = self.rm.loc(op.getarg(0))
         loc1 = self.xrm.force_allocate_reg(op.result)
         self.Perform(op, [loc0], loc1)
-        self.rm.possibly_free_var(op.args[0])
+        self.rm.possibly_free_var(op.getarg(0))
 
     def _call(self, op, arglocs, force_store=[], guard_not_forced_op=None):
         save_all_regs = guard_not_forced_op is not None
@@ -682,11 +683,11 @@
         
     def consider_cond_call_gc_wb(self, op):
         assert op.result is None
-        loc_newvalue = self.rm.make_sure_var_in_reg(op.args[1], op.args)
+        loc_newvalue = self.rm.make_sure_var_in_reg(op.getarg(1), op.args)
         # ^^^ we force loc_newvalue in a reg (unless it's a Const),
         # because it will be needed anyway by the following setfield_gc.
         # It avoids loading it twice from the memory.
-        loc_base = self.rm.make_sure_var_in_reg(op.args[0], op.args,
+        loc_base = self.rm.make_sure_var_in_reg(op.getarg(0), op.args,
                                                 imm_fine=False)
         arglocs = [loc_base, loc_newvalue]
         # add eax, ecx and edx as extra "arguments" to ensure they are
@@ -733,7 +734,7 @@
             return self._call(op, arglocs)
 
     def consider_new_with_vtable(self, op):
-        classint = op.args[0].getint()
+        classint = op.getarg(0).getint()
         descrsize = heaptracker.vtable2descr(self.assembler.cpu, classint)
         if self.assembler.cpu.gc_ll_descr.can_inline_malloc(descrsize):
             self._fastpath_malloc(op, descrsize)
@@ -742,34 +743,34 @@
         else:
             args = self.assembler.cpu.gc_ll_descr.args_for_new(descrsize)
             arglocs = [imm(x) for x in args]
-            arglocs.append(self.loc(op.args[0]))
+            arglocs.append(self.loc(op.getarg(0)))
             return self._call(op, arglocs)
 
     def consider_newstr(self, op):
         gc_ll_descr = self.assembler.cpu.gc_ll_descr
         if gc_ll_descr.get_funcptr_for_newstr is not None:
             # framework GC
-            loc = self.loc(op.args[0])
+            loc = self.loc(op.getarg(0))
             return self._call(op, [loc])
         # boehm GC (XXX kill the following code at some point)
         ofs_items, itemsize, ofs = symbolic.get_array_token(rstr.STR, self.translate_support_code)
         assert itemsize == 1
-        return self._malloc_varsize(ofs_items, ofs, 0, op.args[0],
+        return self._malloc_varsize(ofs_items, ofs, 0, op.getarg(0),
                                     op.result)
 
     def consider_newunicode(self, op):
         gc_ll_descr = self.assembler.cpu.gc_ll_descr
         if gc_ll_descr.get_funcptr_for_newunicode is not None:
             # framework GC
-            loc = self.loc(op.args[0])
+            loc = self.loc(op.getarg(0))
             return self._call(op, [loc])
         # boehm GC (XXX kill the following code at some point)
         ofs_items, itemsize, ofs = symbolic.get_array_token(rstr.UNICODE, self.translate_support_code)
         if itemsize == 4:
-            return self._malloc_varsize(ofs_items, ofs, 2, op.args[0],
+            return self._malloc_varsize(ofs_items, ofs, 2, op.getarg(0),
                                         op.result)
         elif itemsize == 2:
-            return self._malloc_varsize(ofs_items, ofs, 1, op.args[0],
+            return self._malloc_varsize(ofs_items, ofs, 1, op.getarg(0),
                                         op.result)
         else:
             assert False, itemsize
@@ -801,13 +802,13 @@
             # framework GC
             args = self.assembler.cpu.gc_ll_descr.args_for_new_array(op.descr)
             arglocs = [imm(x) for x in args]
-            arglocs.append(self.loc(op.args[0]))
+            arglocs.append(self.loc(op.getarg(0)))
             return self._call(op, arglocs)
         # boehm GC (XXX kill the following code at some point)
         scale_of_field, basesize, ofs_length, _ = (
             self._unpack_arraydescr(op.descr))
         return self._malloc_varsize(basesize, ofs_length, scale_of_field,
-                                    op.args[0], op.result)
+                                    op.getarg(0), op.result)
 
     def _unpack_arraydescr(self, arraydescr):
         assert isinstance(arraydescr, BaseArrayDescr)
@@ -835,8 +836,8 @@
             need_lower_byte = True
         else:
             need_lower_byte = False
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
-        value_loc = self.make_sure_var_in_reg(op.args[1], op.args,
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
+        value_loc = self.make_sure_var_in_reg(op.getarg(1), op.args,
                                               need_lower_byte=need_lower_byte)
         self.possibly_free_vars(op.args)
         self.PerformDiscard(op, [base_loc, ofs_loc, size_loc, value_loc])
@@ -844,9 +845,9 @@
     consider_setfield_raw = consider_setfield_gc
 
     def consider_strsetitem(self, op):
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
-        ofs_loc = self.rm.make_sure_var_in_reg(op.args[1], op.args)
-        value_loc = self.rm.make_sure_var_in_reg(op.args[2], op.args,
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), op.args)
+        value_loc = self.rm.make_sure_var_in_reg(op.getarg(2), op.args,
                                                  need_lower_byte=True)
         self.rm.possibly_free_vars(op.args)
         self.PerformDiscard(op, [base_loc, ofs_loc, value_loc])
@@ -855,14 +856,14 @@
 
     def consider_setarrayitem_gc(self, op):
         scale, ofs, _, ptr = self._unpack_arraydescr(op.descr)
-        base_loc  = self.rm.make_sure_var_in_reg(op.args[0], op.args)
+        base_loc  = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
         if scale == 0:
             need_lower_byte = True
         else:
             need_lower_byte = False
-        value_loc = self.make_sure_var_in_reg(op.args[2], op.args,
+        value_loc = self.make_sure_var_in_reg(op.getarg(2), op.args,
                                           need_lower_byte=need_lower_byte)
-        ofs_loc = self.rm.make_sure_var_in_reg(op.args[1], op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), op.args)
         self.possibly_free_vars(op.args)
         self.PerformDiscard(op, [base_loc, ofs_loc, value_loc,
                                  imm(scale), imm(ofs)])
@@ -871,7 +872,7 @@
 
     def consider_getfield_gc(self, op):
         ofs_loc, size_loc, _ = self._unpack_fielddescr(op.descr)
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
         self.rm.possibly_free_vars(op.args)
         result_loc = self.force_allocate_reg(op.result)
         self.Perform(op, [base_loc, ofs_loc, size_loc], result_loc)
@@ -882,8 +883,8 @@
 
     def consider_getarrayitem_gc(self, op):
         scale, ofs, _, _ = self._unpack_arraydescr(op.descr)
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
-        ofs_loc = self.rm.make_sure_var_in_reg(op.args[1], op.args)
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), op.args)
         self.rm.possibly_free_vars(op.args)
         result_loc = self.force_allocate_reg(op.result)
         self.Perform(op, [base_loc, ofs_loc, imm(scale), imm(ofs)], result_loc)
@@ -893,8 +894,8 @@
 
     def consider_int_is_true(self, op, guard_op):
         # doesn't need arg to be in a register
-        argloc = self.loc(op.args[0])
-        self.rm.possibly_free_var(op.args[0])
+        argloc = self.loc(op.getarg(0))
+        self.rm.possibly_free_var(op.getarg(0))
         if guard_op is not None:
             self.perform_with_guard(op, guard_op, [argloc], None)
         else:
@@ -904,14 +905,14 @@
     consider_int_is_zero = consider_int_is_true
 
     def consider_same_as(self, op):
-        argloc = self.loc(op.args[0])
-        self.possibly_free_var(op.args[0])
+        argloc = self.loc(op.getarg(0))
+        self.possibly_free_var(op.getarg(0))
         resloc = self.force_allocate_reg(op.result)
         self.Perform(op, [argloc], resloc)
     #consider_cast_ptr_to_int = consider_same_as
 
     def consider_strlen(self, op):
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
         self.rm.possibly_free_vars(op.args)
         result_loc = self.rm.force_allocate_reg(op.result)
         self.Perform(op, [base_loc], result_loc)
@@ -922,14 +923,14 @@
         arraydescr = op.descr
         assert isinstance(arraydescr, BaseArrayDescr)
         ofs = arraydescr.get_ofs_length(self.translate_support_code)
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
         self.rm.possibly_free_vars(op.args)
         result_loc = self.rm.force_allocate_reg(op.result)
         self.Perform(op, [base_loc, imm(ofs)], result_loc)
 
     def consider_strgetitem(self, op):
-        base_loc = self.rm.make_sure_var_in_reg(op.args[0], op.args)
-        ofs_loc = self.rm.make_sure_var_in_reg(op.args[1], op.args)
+        base_loc = self.rm.make_sure_var_in_reg(op.getarg(0), op.args)
+        ofs_loc = self.rm.make_sure_var_in_reg(op.getarg(1), op.args)
         self.rm.possibly_free_vars(op.args)
         result_loc = self.rm.force_allocate_reg(op.result)
         self.Perform(op, [base_loc, ofs_loc], result_loc)



More information about the Pypy-commit mailing list