Commits

Armin Rigo committed b09fe84

Revert the last 4 commits, up to c292d7b6630f. It should be
done with a proper merge of the branch r15-for-exception, at
some point.

Comments (0)

Files changed (6)

pypy/rlib/register.py

-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-from pypy.rpython.tool import rffi_platform
-
-# On platforms with enough hardware registers and with gcc, we can
-# (ab)use gcc to globally assign a register to a single global void*
-# variable.  We use it with a double meaning:
-#
-# - when it is NULL upon return from a function, it means that an
-#   exception occurred.  It allows the caller to quickly check for
-#   exceptions.
-#
-# - in other cases, with --gcrootfinder=shadowstack, it points to
-#   the top of the shadow stack.
-
-
-# For now, only for x86-64.  Tries to use the register r15.
-eci = ExternalCompilationInfo(
-    post_include_bits=[
-        'register void *pypy_r15 asm("r15");\n'
-        '#define PYPY_GET_SPECIAL_REG() pypy_r15\n'
-        '#define PYPY_SPECIAL_REG_NONNULL() (pypy_r15 != NULL)\n'
-        '#define PYPY_SET_SPECIAL_REG(x) (pypy_r15 = x)\n'
-        ],
-    )
-
-_test_eci = eci.merge(ExternalCompilationInfo(
-    post_include_bits=["""
-            void f(void) {
-                pypy_r15 = &f;
-            }
-    """]))
-
-try:
-    rffi_platform.verify_eci(_test_eci)
-    register_number = 15      # r15
-except rffi_platform.CompilationError:
-    eci = None
-    register_number = None
-else:
-
-    from pypy.rpython.lltypesystem import lltype, llmemory, rffi
-
-    # use addr=load_from_reg() and store_into_reg(addr) to load and store
-    # an Address out of the special register.  When running on top of Python,
-    # the behavior is emulated.
-
-    _value_reg = None
-
-    def _pypy_get_special_reg():
-        assert _value_reg is not None
-        return _value_reg
-
-    def _pypy_special_reg_nonnull():
-        assert _value_reg is not None
-        return bool(_value_reg)
-
-    def _pypy_set_special_reg(addr):
-        global _value_reg
-        _value_reg = addr
-
-    load_from_reg = rffi.llexternal('PYPY_GET_SPECIAL_REG', [],
-                                    llmemory.Address,
-                                    _callable=_pypy_get_special_reg,
-                                    compilation_info=eci,
-                                    _nowrapper=True)
-
-    reg_is_nonnull = rffi.llexternal('PYPY_SPECIAL_REG_NONNULL', [],
-                                     lltype.Bool,
-                                     _callable=_pypy_special_reg_nonnull,
-                                     compilation_info=eci,
-                                     _nowrapper=True)
-
-    store_into_reg = rffi.llexternal('PYPY_SET_SPECIAL_REG',
-                                     [llmemory.Address],
-                                     lltype.Void,
-                                     _callable=_pypy_set_special_reg,
-                                     compilation_info=eci,
-                                     _nowrapper=True)
-
-    # xxx temporary
-    nonnull = llmemory.cast_int_to_adr(-1)

pypy/rlib/test/test_register.py

-import py
-from pypy.rlib import register
-from pypy.rpython.lltypesystem import lltype, llmemory, rffi
-from pypy.translator.c.test.test_standalone import StandaloneTests
-
-
-def test_register():
-    #
-    from pypy.jit.backend.detect_cpu import autodetect
-    if autodetect() == 'x86_64':
-        assert register.eci is not None
-        assert register.register_number == 15        # r15
-    else:
-        assert register.eci is None
-        assert register.register_number is None
-
-
-class TestLoadStore(object):
-    def setup_class(cls):
-        if register.register_number is None:
-            py.test.skip("rlib/register not supported on this platform")
-
-    def test_direct(self):
-        a = rffi.cast(llmemory.Address, 27)
-        register.store_into_reg(a)
-        b = register.load_from_reg()
-        assert lltype.typeOf(b) == llmemory.Address
-        assert rffi.cast(lltype.Signed, b) == 27
-
-    def test_llinterp(self):
-        from pypy.rpython.test.test_llinterp import interpret
-        def f(n):
-            a = rffi.cast(llmemory.Address, n)
-            register.store_into_reg(a)
-            b = register.load_from_reg()
-            return rffi.cast(lltype.Signed, b)
-        res = interpret(f, [41])
-        assert res == 41
-
-
-class TestLoadStoreCompiled(StandaloneTests):
-    def setup_class(cls):
-        if register.register_number is None:
-            py.test.skip("rlib/register not supported on this platform")
-
-    def test_compiled(self):
-        def f(argv):
-            a = rffi.cast(llmemory.Address, 43)
-            register.store_into_reg(a)
-            b = register.load_from_reg()
-            print rffi.cast(lltype.Signed, b)
-            return 0
-        t, cbuilder = self.compile(f)
-        data = cbuilder.cmdexec('')
-        assert data.startswith('43\n')

pypy/translator/c/database.py

         if translator is None or translator.rtyper is None:
             self.exctransformer = None
         else:
-            self.exctransformer = translator.getexceptiontransformer(
-                standalone=standalone)
+            self.exctransformer = translator.getexceptiontransformer()
         if translator is not None:
             self.gctransformer = self.gcpolicy.transformerclass(translator)
         self.completed = False

pypy/translator/c/src/main.h

     char *errmsg;
     int i, exitcode;
     RPyListOfString *list;
-#ifdef PYPY_GET_SPECIAL_REG
-    void *pypy_reg_oldvalue = PYPY_GET_SPECIAL_REG();
-    PYPY_SET_SPECIAL_REG((void*)-1);
-#endif
 
     pypy_asm_stack_bottom();
     instrument_setup();
         pypy_debug_catch_fatal_exception();
     }
 
-#ifdef PYPY_GET_SPECIAL_REG
-    PYPY_SET_SPECIAL_REG(pypy_reg_oldvalue);
-#endif
-
     return exitcode;
 
  memory_out:
     fprintf(stderr, "Fatal error during initialization: %s\n", errmsg);
 #endif
     abort();
-    return 1;   /* not actually reachable */
+    return 1;
 }
 
 int PYPY_MAIN_FUNCTION(int argc, char *argv[])

pypy/translator/exceptiontransform.py

 from pypy.rlib.rarithmetic import r_singlefloat
 from pypy.rlib.debug import ll_assert
 from pypy.rlib.rstackovf import _StackOverflow
-from pypy.rlib import register
 from pypy.annotation import model as annmodel
 from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
 from pypy.tool.sourcetools import func_with_new_name
 
 class BaseExceptionTransformer(object):
 
-    def __init__(self, translator, standalone):
+    def __init__(self, translator):
         self.translator = translator
-        self.standalone = standalone
         self.raise_analyzer = canraise.RaiseAnalyzer(translator)
         edata = translator.rtyper.getexceptiondata()
         self.lltype_of_exception_value = edata.lltype_of_exception_value
             assertion_error_ll_exc_type)
         self.c_n_i_error_ll_exc_type = constant_value(n_i_error_ll_exc_type)
 
-        use_special_reg = standalone and register.register_number is not None
-        self.use_special_reg = use_special_reg
-        if use_special_reg:
-            self.c_nonnull_specialregister = constant_value(register.nonnull)
-            self.c_load_from_reg = constant_value(register.load_from_reg)
-            self.c_reg_is_nonnull = constant_value(register.reg_is_nonnull)
-            self.c_store_into_reg = constant_value(register.store_into_reg)
-
         def rpyexc_occured():
-            if use_special_reg:
-                # an exception occurred iff the special register is 0
-                return register.load_from_reg() == llmemory.NULL
-            else:
-                exc_type = exc_data.exc_type
-                return bool(exc_type)
+            exc_type = exc_data.exc_type
+            return bool(exc_type)
 
         def rpyexc_fetch_type():
             return exc_data.exc_type
             return exc_data.exc_value
 
         def rpyexc_clear():
-            if use_special_reg:
-                register.store_into_reg(register.nonnull)
             exc_data.exc_type = null_type
             exc_data.exc_value = null_value
 
             exc_data.exc_type = etype
             exc_data.exc_value = evalue
             lloperation.llop.debug_start_traceback(lltype.Void, etype)
-            if use_special_reg:
-                register.store_into_reg(llmemory.NULL)
 
         def rpyexc_reraise(etype, evalue):
             exc_data.exc_type = etype
             exc_data.exc_value = evalue
             lloperation.llop.debug_reraise_traceback(lltype.Void, etype)
-            if use_special_reg:
-                register.store_into_reg(llmemory.NULL)
 
         def rpyexc_fetch_exception():
             evalue = rpyexc_fetch_value()
             if evalue:
                 exc_data.exc_type = rclass.ll_inst_type(evalue)
                 exc_data.exc_value = evalue
-                if use_special_reg:
-                    register.store_into_reg(llmemory.NULL)
 
         def rpyexc_raise_stack_overflow():
             rpyexc_raise(stackovf_ll_exc_type, stackovf_ll_exc)
         #
         self.gen_setfield('exc_value', self.c_null_evalue, llops)
         self.gen_setfield('exc_type',  self.c_null_etype,  llops)
-        if self.use_special_reg:
-            self.gen_setspecialregister(self.c_nonnull_specialregister, llops)
         excblock.operations[:] = llops
         newgraph.exceptblock.inputargs[0].concretetype = self.lltype_of_exception_type
         newgraph.exceptblock.inputargs[1].concretetype = self.lltype_of_exception_value
         if alloc_shortcut:
             T = spaceop.result.concretetype
             var_no_exc = self.gen_nonnull(spaceop.result, llops)
-        elif self.use_special_reg:
-            var_no_exc = self.gen_specialreg_no_exc(llops)
         else:
             v_exc_type = self.gen_getfield('exc_type', llops)
             var_no_exc = self.gen_isnull(v_exc_type, llops)
     def gen_nonnull(self, v, llops):
         return llops.genop('ptr_nonzero', [v], lltype.Bool)
 
-    def gen_getspecialregister(self, llops):
-        return llops.genop('direct_call', [self.c_load_from_reg],
-                           resulttype = llmemory.Address)
-
-    def gen_specialreg_no_exc(self, llops):
-        return llops.genop('direct_call', [self.c_reg_is_nonnull],
-                           resulttype = lltype.Bool)
-
-    def gen_setspecialregister(self, v, llops):
-        llops.genop('direct_call', [self.c_store_into_reg, v])
-
     def same_obj(self, ptr1, ptr2):
         return ptr1._same_obj(ptr2)
 
     def build_extra_funcs(self):
         pass
 
-def ExceptionTransformer(translator, standalone):
+def ExceptionTransformer(translator):
     type_system = translator.rtyper.type_system.name
     if type_system == 'lltypesystem':
-        return LLTypeExceptionTransformer(translator, standalone)
+        return LLTypeExceptionTransformer(translator)
     else:
         assert type_system == 'ootypesystem'
-        return OOTypeExceptionTransformer(translator, standalone)
+        return OOTypeExceptionTransformer(translator)

pypy/translator/translator.py

                                    type_system = type_system)
         return self.rtyper
 
-    def getexceptiontransformer(self, standalone):
+    def getexceptiontransformer(self):
         if self.rtyper is None:
             raise ValueError("no rtyper")
         if self.exceptiontransformer is not None:
-            assert self.exceptiontransformer.standalone == standalone
             return self.exceptiontransformer
         from pypy.translator.exceptiontransform import ExceptionTransformer
-        self.exceptiontransformer = ExceptionTransformer(self, standalone)
+        self.exceptiontransformer = ExceptionTransformer(self)
         return self.exceptiontransformer
 
     def checkgraphs(self):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.