[pypy-commit] pypy jitframe-on-heap: move shared initialization of the assembler classes to llsupport

bivab noreply at buildbot.pypy.org
Fri Feb 15 15:36:24 CET 2013


Author: David Schneider <david.schneider at picle.org>
Branch: jitframe-on-heap
Changeset: r61265:1767fd94f261
Date: 2013-02-15 15:35 +0100
http://bitbucket.org/pypy/pypy/changeset/1767fd94f261/

Log:	move shared initialization of the assembler classes to llsupport

diff --git a/rpython/jit/backend/arm/assembler.py b/rpython/jit/backend/arm/assembler.py
--- a/rpython/jit/backend/arm/assembler.py
+++ b/rpython/jit/backend/arm/assembler.py
@@ -33,7 +33,6 @@
 from rpython.rlib.objectmodel import compute_unique_id
 from rpython.rlib.rarithmetic import intmask, r_uint
 
-from rpython.jit.backend.arm.support import memcpy_fn
 
 DEBUG_COUNTER = lltype.Struct('DEBUG_COUNTER', ('i', lltype.Signed),
                               ('type', lltype.Char),  # 'b'ridge, 'l'abel or
@@ -46,10 +45,9 @@
     debug = True
 
     def __init__(self, cpu, translate_support_code=False):
-        self.cpu = cpu
+        ResOpAssembler.__init__(self, cpu, translate_support_code)
         self.setup_failure_recovery()
         self.mc = None
-        self.memcpy_addr = 0
         self.pending_guards = None
         self._exit_code_addr = 0
         self.current_clt = None
@@ -87,40 +85,6 @@
         self.pending_guards = None
         assert self.datablockwrapper is None
 
-    def setup_once(self):
-        # Addresses of functions called by new_xxx operations
-        gc_ll_descr = self.cpu.gc_ll_descr
-        gc_ll_descr.initialize()
-        self.memcpy_addr = self.cpu.cast_ptr_to_int(memcpy_fn)
-        self._build_failure_recovery(exc=True, withfloats=False)
-        self._build_failure_recovery(exc=False, withfloats=False)
-        self._build_wb_slowpath(False)
-        self._build_wb_slowpath(True)
-        self._build_stack_check_failure()
-        if self.cpu.supports_floats:
-            self._build_wb_slowpath(False, withfloats=True)
-            self._build_wb_slowpath(True, withfloats=True)
-            self._build_failure_recovery(exc=True, withfloats=True)
-            self._build_failure_recovery(exc=False, withfloats=True)
-        self._build_propagate_exception_path()
-        if gc_ll_descr.get_malloc_slowpath_addr is not None:
-            self._build_malloc_slowpath()
-        self._build_stack_check_slowpath()
-        if gc_ll_descr.gcrootmap and gc_ll_descr.gcrootmap.is_shadow_stack:
-            self._build_release_gil(gc_ll_descr.gcrootmap)
-
-        if not self._debug:
-            # if self._debug is already set it means that someone called
-            # set_debug by hand before initializing the assembler. Leave it
-            # as it is
-            debug_start('jit-backend-counts')
-            self.set_debug(have_debug_prints())
-            debug_stop('jit-backend-counts')
-        # when finishing, we only have one value at [0], the rest dies
-        self.gcmap_for_finish = lltype.malloc(jitframe.GCMAP, 1,
-                                              flavor='raw', immortal=True)
-        self.gcmap_for_finish[0] = r_uint(1)
-
     def setup_failure_recovery(self):
         self.failure_recovery_code = [0, 0, 0, 0]
 
@@ -302,7 +266,7 @@
         rawstart = mc.materialize(self.cpu.asmmemmgr, [])
         self.stack_check_slowpath = rawstart
 
-    def _build_wb_slowpath(self, withcards, withfloats=False):
+    def _build_wb_slowpath(self, withcards, withfloats=False, for_frame=False):
         descr = self.cpu.gc_ll_descr.write_barrier_descr
         if descr is None:
             return
diff --git a/rpython/jit/backend/arm/support.py b/rpython/jit/backend/arm/support.py
--- a/rpython/jit/backend/arm/support.py
+++ b/rpython/jit/backend/arm/support.py
@@ -52,10 +52,3 @@
                         _callable=arm_int_mod_emulator,
                         compilation_info=eci,
                         _nowrapper=True, elidable_function=True)
-# ____________________________________________________________
-
-memcpy_fn = rffi.llexternal('memcpy', [llmemory.Address, llmemory.Address,
-                                       rffi.SIZE_T], lltype.Void,
-                            sandboxsafe=True, _nowrapper=True)
-
-# ____________________________________________________________
diff --git a/rpython/jit/backend/llsupport/assembler.py b/rpython/jit/backend/llsupport/assembler.py
--- a/rpython/jit/backend/llsupport/assembler.py
+++ b/rpython/jit/backend/llsupport/assembler.py
@@ -2,9 +2,13 @@
 from rpython.rlib import rgc
 from rpython.rlib.rarithmetic import r_uint
 from rpython.jit.backend.llsupport.symbolic import WORD
+from rpython.jit.backend.llsupport import jitframe
 from rpython.jit.metainterp.history import INT, REF, FLOAT, JitCellToken
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.jit.backend.llsupport.memcpy import memcpy_fn
+from rpython.rlib.debug import (debug_print, debug_start, debug_stop,
+                                have_debug_prints)
 
 class GuardToken(object):
     def __init__(self, cpu, gcmap, faildescr, failargs, fail_locs, exc,
@@ -43,6 +47,47 @@
 class BaseAssembler(object):
     """ Base class for Assembler generator in real backends
     """
+
+    def __init__(self, cpu, translate_support_code=False):
+        self.cpu = cpu
+        self.memcpy_addr = 0
+        self.rtyper = cpu.rtyper
+
+    def setup_once(self):
+        # the address of the function called by 'new'
+        gc_ll_descr = self.cpu.gc_ll_descr
+        gc_ll_descr.initialize()
+        self.memcpy_addr = self.cpu.cast_ptr_to_int(memcpy_fn)
+        self._build_failure_recovery(False, withfloats=False)
+        self._build_failure_recovery(True, withfloats=False)
+        self._build_wb_slowpath(False)
+        self._build_wb_slowpath(True)
+        self._build_wb_slowpath(False, for_frame=True)
+        # only one of those
+        self._build_stack_check_failure()
+        if self.cpu.supports_floats:
+            self._build_failure_recovery(False, withfloats=True)
+            self._build_failure_recovery(True, withfloats=True)
+            self._build_wb_slowpath(False, withfloats=True)
+            self._build_wb_slowpath(True, withfloats=True)
+        self._build_propagate_exception_path()
+        if gc_ll_descr.get_malloc_slowpath_addr is not None:
+            self._build_malloc_slowpath()
+        self._build_stack_check_slowpath()
+        if gc_ll_descr.gcrootmap:
+            self._build_release_gil(gc_ll_descr.gcrootmap)
+        if not self._debug:
+            # if self._debug is already set it means that someone called
+            # set_debug by hand before initializing the assembler. Leave it
+            # as it is
+            debug_start('jit-backend-counts')
+            self.set_debug(have_debug_prints())
+            debug_stop('jit-backend-counts')
+        # when finishing, we only have one value at [0], the rest dies
+        self.gcmap_for_finish = lltype.malloc(jitframe.GCMAP, 1,
+                                              flavor='raw', immortal=True)
+        self.gcmap_for_finish[0] = r_uint(1)
+
     def rebuild_faillocs_from_descr(self, descr, inputargs):
         locs = []
         GPR_REGS = len(self.cpu.gen_regs)
diff --git a/rpython/jit/backend/llsupport/memcpy.py b/rpython/jit/backend/llsupport/memcpy.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/memcpy.py
@@ -0,0 +1,5 @@
+from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+
+memcpy_fn = rffi.llexternal('memcpy', [llmemory.Address, llmemory.Address,
+                                       rffi.SIZE_T], lltype.Void,
+                            sandboxsafe=True, _nowrapper=True)
diff --git a/rpython/jit/backend/x86/assembler.py b/rpython/jit/backend/x86/assembler.py
--- a/rpython/jit/backend/x86/assembler.py
+++ b/rpython/jit/backend/x86/assembler.py
@@ -54,15 +54,13 @@
     _second_tmp_reg = ecx
 
     def __init__(self, cpu, translate_support_code=False):
-        self.cpu = cpu
+        BaseAssembler.__init__(self, cpu, translate_support_code)
         self.verbose = False
-        self.rtyper = cpu.rtyper
         self.loop_run_counters = []
         self.float_const_neg_addr = 0
         self.float_const_abs_addr = 0
         self.malloc_slowpath = 0
         self.wb_slowpath = [0, 0, 0, 0, 0]
-        self.memcpy_addr = 0
         self.setup_failure_recovery()
         self._debug = False
         self.debug_counter_descr = cpu.fielddescrof(DEBUG_COUNTER, 'i')
@@ -78,41 +76,10 @@
         return r
 
     def setup_once(self):
-        # the address of the function called by 'new'
-        gc_ll_descr = self.cpu.gc_ll_descr
-        gc_ll_descr.initialize()
-        self.memcpy_addr = self.cpu.cast_ptr_to_int(support.memcpy_fn)
-        self._build_failure_recovery(False)
-        self._build_failure_recovery(True)
-        self._build_wb_slowpath(False)
-        self._build_wb_slowpath(True)
-        self._build_wb_slowpath(False, for_frame=True)
-        # only one of those
-        self._build_stack_check_failure()
+        BaseAssembler.setup_once(self)
         if self.cpu.supports_floats:
-            self._build_failure_recovery(False, withfloats=True)
-            self._build_failure_recovery(True, withfloats=True)
-            self._build_wb_slowpath(False, withfloats=True)
-            self._build_wb_slowpath(True, withfloats=True)
             support.ensure_sse2_floats()
             self._build_float_constants()
-        self._build_propagate_exception_path()
-        if gc_ll_descr.get_malloc_slowpath_addr is not None:
-            self._build_malloc_slowpath()
-        self._build_stack_check_slowpath()
-        if gc_ll_descr.gcrootmap:
-            self._build_release_gil(gc_ll_descr.gcrootmap)
-        if not self._debug:
-            # if self._debug is already set it means that someone called
-            # set_debug by hand before initializing the assembler. Leave it
-            # as it is
-            debug_start('jit-backend-counts')
-            self.set_debug(have_debug_prints())
-            debug_stop('jit-backend-counts')
-        # when finishing, we only have one value at [0], the rest dies
-        self.gcmap_for_finish = lltype.malloc(jitframe.GCMAP, 1,
-                                              flavor='raw', immortal=True)
-        self.gcmap_for_finish[0] = r_uint(1)
 
     def setup(self, looptoken):
         assert self.memcpy_addr != 0, "setup_once() not called?"
diff --git a/rpython/jit/backend/x86/support.py b/rpython/jit/backend/x86/support.py
--- a/rpython/jit/backend/x86/support.py
+++ b/rpython/jit/backend/x86/support.py
@@ -1,16 +1,8 @@
 import sys
-from rpython.rtyper.lltypesystem import lltype, rffi, llmemory
+from rpython.rtyper.lltypesystem import rffi
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.jit.backend.x86.arch import WORD
 
-# ____________________________________________________________
-
-memcpy_fn = rffi.llexternal('memcpy', [llmemory.Address, llmemory.Address,
-                                       rffi.SIZE_T], lltype.Void,
-                            sandboxsafe=True, _nowrapper=True)
-
-# ____________________________________________________________
-
 if WORD == 4:
     extra = ['-DPYPY_X86_CHECK_SSE2']
 else:


More information about the pypy-commit mailing list