1. Pypy
  2. Untitled project
  3. pypy

Commits

Alex Gaynor  committed 9d2f1ac

(alex, fijal): start refactoring to remove duplication

  • Participants
  • Parent commits 4160eab
  • Branches asm-backend-dupe-removal

Comments (0)

Files changed (7)

File rpython/jit/backend/arm/assembler.py

View file
         self.loop_run_counters.append(struct)
         return struct
 
-    @specialize.argtype(1)
-    def _inject_debugging_code(self, looptoken, operations, tp, number):
-        if self._debug:
-            # before doing anything, let's increase a counter
-            s = 0
-            for op in operations:
-                s += op.getopnum()
-            looptoken._arm_debug_checksum = s
-
-            newoperations = []
-            self._append_debugging_code(newoperations, tp, number,
-                                        None)
-            for op in operations:
-                newoperations.append(op)
-                if op.getopnum() == rop.LABEL:
-                    self._append_debugging_code(newoperations, 'l', number,
-                                                op.getdescr())
-            operations = newoperations
-        return operations
-
     @staticmethod
     def _release_gil_shadowstack():
         before = rffi.aroundstate.before

File rpython/jit/backend/llsupport/assembler.py

View file
 from rpython.jit.backend.llsupport import jitframe
 from rpython.jit.backend.llsupport.memcpy import memcpy_fn
 from rpython.jit.backend.llsupport.symbolic import WORD
-from rpython.jit.metainterp.history import (INT, REF, FLOAT, JitCellToken,
-    ConstInt, BoxInt)
-from rpython.jit.metainterp.resoperation import ResOperation, rop
+from rpython.jit.metainterp.history import INT, REF, FLOAT, JitCellToken
 from rpython.rlib import rgc
 from rpython.rlib.debug import debug_start, debug_stop, have_debug_prints
 from rpython.rlib.rarithmetic import r_uint
         # XXX here should be emitted guard_not_forced, but due
         #     to incompatibilities in how it's done, we leave it for the
         #     caller to deal with
-
-    def _append_debugging_code(self, operations, tp, number, token):
-        counter = self._register_counter(tp, number, token)
-        c_adr = ConstInt(rffi.cast(lltype.Signed, counter))
-        box = BoxInt()
-        box2 = BoxInt()
-        ops = [ResOperation(rop.GETFIELD_RAW, [c_adr],
-                            box, descr=self.debug_counter_descr),
-               ResOperation(rop.INT_ADD, [box, ConstInt(1)], box2),
-               ResOperation(rop.SETFIELD_RAW, [c_adr, box2],
-                            None, descr=self.debug_counter_descr)]
-        operations.extend(ops)

File rpython/jit/backend/llsupport/gc.py

View file
             rgc._make_sure_does_not_move(llref)
             gcrefs_output_list.append(llref)
 
-    def rewrite_assembler(self, cpu, operations, gcrefs_output_list):
+    def rewrite_assembler(self, cpu, operations, looptoken, tp, number, gcrefs_output_list):
         rewriter = GcRewriterAssembler(self, cpu)
-        newops = rewriter.rewrite(operations)
+        newops = rewriter.rewrite(operations, looptoken, tp, number)
         # record all GCREFs, because the GC (or Boehm) cannot see them and
         # keep them alive if they end up as constants in the assembler
         for op in newops:

File rpython/jit/backend/llsupport/rewrite.py

View file
+from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr
+from rpython.jit.backend.llsupport.symbolic import WORD
+from rpython.jit.codewriter import heaptracker
+from rpython.jit.metainterp import history
+from rpython.jit.metainterp.resoperation import ResOperation, rop
+from rpython.jit.metainterp.history import BoxInt, ConstInt, BoxPtr, ConstPtr, JitCellToken
 from rpython.rlib.rarithmetic import ovfcheck
-from rpython.rtyper.lltypesystem import lltype, llmemory
-from rpython.jit.metainterp import history
-from rpython.jit.metainterp.history import ConstInt, BoxPtr, ConstPtr
-from rpython.jit.metainterp.resoperation import ResOperation, rop
-from rpython.jit.codewriter import heaptracker
-from rpython.jit.backend.llsupport.symbolic import WORD
-from rpython.jit.backend.llsupport.descr import SizeDescr, ArrayDescr
-from rpython.jit.metainterp.history import JitCellToken
+from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
+
 
 class GcRewriterAssembler(object):
     # This class performs the following rewrites on the list of operations:
         self.known_lengths = {}
         self.recent_mallocs = {}     # set of variables
 
-    def rewrite(self, operations):
+    def rewrite(self, operations, looptoken, tp, number):
         # we can only remember one malloc since the next malloc can possibly
         # collect; but we can try to collapse several known-size mallocs into
         # one, both for performance and to reduce the number of write
         # barriers.  We do this on each "basic block" of operations, which in
         # this case means between CALLs or unknown-size mallocs.
         #
+        self._append_debugging_code(looptoken, tp, number)
         for op in operations:
             if op.getopnum() == rop.DEBUG_MERGE_POINT:
                 continue
+            if op.getopnum() == rop.LABEL:
+                self._append_debugging_code(looptoken, 'l', number)
             # ---------- turn NEWxxx into CALL_MALLOC_xxx ----------
             if op.is_malloc():
                 self.handle_malloc_operation(op)
             self.newops.append(op)
         return self.newops
 
-    # ----------
+    def _append_debugging_code(self, token, tp, number):
+        if self.debug:
+            counter = self._register_counter(tp, number, token)
+            c_adr = ConstInt(rffi.cast(lltype.Signed, counter))
+            box = BoxInt()
+            box2 = BoxInt()
+            ops = [
+                ResOperation(rop.GETFIELD_RAW, [c_adr], box, descr=self.debug_counter_descr),
+                ResOperation(rop.INT_ADD, [box, ConstInt(1)], box2),
+                ResOperation(rop.SETFIELD_RAW, [c_adr, box2], None, descr=self.debug_counter_descr)
+            ]
+            self.newops.extend(ops)
 
     def handle_malloc_operation(self, op):
         opnum = op.getopnum()

File rpython/jit/backend/x86/assembler.py

View file
     r12, r13, r14, r15, X86_64_SCRATCH_REG, X86_64_XMM_SCRATCH_REG,
     RegLoc, FrameLoc, ConstFloatLoc, ImmedLoc, AddressLoc, imm,
     imm0, imm1, FloatImmedLoc, RawEbpLoc, RawEspLoc)
-from rpython.rlib.objectmodel import we_are_translated, specialize
+from rpython.rlib.objectmodel import we_are_translated
 from rpython.jit.backend.x86 import rx86, codebuf
 from rpython.jit.metainterp.resoperation import rop
 from rpython.jit.backend.x86 import support
                                        self._release_gil_asmgcc)
             reacqgil_func = llhelper(self._CLOSESTACK_FUNC,
                                      self._reacquire_gil_asmgcc)
-        self.releasegil_addr  = self.cpu.cast_ptr_to_int(releasegil_func)
+        self.releasegil_addr = self.cpu.cast_ptr_to_int(releasegil_func)
         self.reacqgil_addr = self.cpu.cast_ptr_to_int(reacqgil_func)
 
-    def assemble_loop(self, loopname, inputargs, operations, looptoken, log):
+    def assemble_loop(self, loopname, inputargs, operations, looptoken):
         '''adds the following attributes to looptoken:
                _ll_function_addr    (address of the generated func, as an int)
                _ll_loop_code       (debug: addr of the start of the ResOps)
         clt.allgcrefs = []
         clt.frame_info.clear() # for now
 
-        if log:
-            operations = self._inject_debugging_code(looptoken, operations,
-                                                     'e', looptoken.number)
-
         regalloc = RegAlloc(self, self.cpu.translate_support_code)
         #
         self._call_header_with_stack_check()
             targettoken._ll_loop_code += rawstart
         self.target_tokens_currently_compiling = None
 
-    @specialize.argtype(1)
-    def _inject_debugging_code(self, looptoken, operations, tp, number):
-        if self._debug:
-            s = 0
-            for op in operations:
-                s += op.getopnum()
-
-            newoperations = []
-            self._append_debugging_code(newoperations, tp, number,
-                                        None)
-            for op in operations:
-                newoperations.append(op)
-                if op.getopnum() == rop.LABEL:
-                    self._append_debugging_code(newoperations, 'l', number,
-                                                op.getdescr())
-            operations = newoperations
-        return operations
-
     def _assemble(self, regalloc, inputargs, operations):
         self._regalloc = regalloc
         regalloc.compute_hint_frame_locations(operations)

File rpython/jit/backend/x86/regalloc.py

View file
 for _i, _reg in enumerate(gpr_reg_mgr_cls.all_regs):
     gpr_reg_mgr_cls.all_reg_indexes[_reg.value] = _i
 
+
 class RegAlloc(BaseRegalloc):
-
     def __init__(self, assembler, translate_support_code=False):
         assert isinstance(translate_support_code, bool)
         # variables that have place in register
         self.jump_target_descr = None
         self.final_jump_op = None
 
-    def _prepare(self, inputargs, operations, allgcrefs):
+    def _prepare(self, inputargs, operations, allgcrefs, tp, number):
         cpu = self.assembler.cpu
         self.fm = X86FrameManager(cpu.get_baseofs_of_frame_field())
-        operations = cpu.gc_ll_descr.rewrite_assembler(cpu, operations,
-                                                       allgcrefs)
+        operations = cpu.gc_ll_descr.rewrite_assembler(
+            cpu, operations, self.assembler.current_clt, tp, number, allgcrefs
+        )
         # compute longevity of variables
-        longevity, last_real_usage = compute_vars_longevity(
-                                                    inputargs, operations)
+        longevity, last_real_usage = compute_vars_longevity(inputargs, operations)
         self.longevity = longevity
         self.last_real_usage = last_real_usage
         self.rm = gpr_reg_mgr_cls(self.longevity,
-                                  frame_manager = self.fm,
-                                  assembler = self.assembler)
-        self.xrm = xmm_reg_mgr_cls(self.longevity, frame_manager = self.fm,
-                                   assembler = self.assembler)
+                                  frame_manager=self.fm,
+                                  assembler=self.assembler)
+        self.xrm = xmm_reg_mgr_cls(self.longevity, frame_manager=self.fm,
+                                   assembler=self.assembler)
         return operations
 
     def prepare_loop(self, inputargs, operations, looptoken, allgcrefs):
-        operations = self._prepare(inputargs, operations, allgcrefs)
+        operations = self._prepare(inputargs, operations, allgcrefs, 'e', looptoken.number)
         self._set_initial_bindings(inputargs, looptoken)
         # note: we need to make a copy of inputargs because possibly_free_vars
         # is also used on op args, which is a non-resizable list

File rpython/jit/backend/x86/runner.py

View file
         lines = machine_code_dump(data, addr, self.backend_name, label_list)
         print ''.join(lines)
 
-    def compile_loop(self, inputargs, operations, looptoken, log=True, name=''):
+    def compile_loop(self, inputargs, operations, looptoken, name=''):
         return self.assembler.assemble_loop(name, inputargs, operations,
-                                            looptoken, log=log)
+                                            looptoken)
 
     def compile_bridge(self, faildescr, inputargs, operations,
                        original_loop_token, log=True):