Author: Armin Rigo <ar...@tunes.org> Branch: py3k Changeset: r86427:7b46c6327f13 Date: 2016-08-22 22:05 +0200 http://bitbucket.org/pypy/pypy/changeset/7b46c6327f13/
Log: hg merge default diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py --- a/lib_pypy/cffi/recompiler.py +++ b/lib_pypy/cffi/recompiler.py @@ -515,7 +515,7 @@ tovar, errcode) return # - elif isinstance(tp, (model.StructOrUnion, model.EnumType)): + elif isinstance(tp, model.StructOrUnionOrEnum): # a struct (not a struct pointer) as a function argument self._prnt(' if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)' % (tovar, self._gettypenum(tp), fromvar)) @@ -572,7 +572,7 @@ elif isinstance(tp, model.ArrayType): return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( var, self._gettypenum(model.PointerType(tp.item))) - elif isinstance(tp, model.StructType): + elif isinstance(tp, model.StructOrUnion): if tp.fldnames is None: raise TypeError("'%s' is used as %s, but is opaque" % ( tp._get_c_name(), context)) diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py --- a/lib_pypy/cffi/vengine_cpy.py +++ b/lib_pypy/cffi/vengine_cpy.py @@ -308,7 +308,7 @@ elif isinstance(tp, model.ArrayType): return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % ( var, self._gettypenum(model.PointerType(tp.item))) - elif isinstance(tp, model.StructType): + elif isinstance(tp, model.StructOrUnion): if tp.fldnames is None: raise TypeError("'%s' is used as %s, but is opaque" % ( tp._get_c_name(), context)) diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -144,3 +144,9 @@ ``type.__dict__`` now returns a ``dict_proxy`` object, like on CPython. Previously it returned what looked like a regular dict object (but it was already read-only). + + +.. branch: const-fold-we-are-jitted + +Reduce the size of the generated C code by constant-folding ``we_are_jitted`` +in non-jitcode. diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py @@ -1963,3 +1963,21 @@ ffi, "test_function_returns_opaque", "?") assert str(e.value) == ("function foo: 'struct a' is used as result type," " but is opaque") + +def test_function_returns_union(): + ffi = FFI() + ffi.cdef("union u1 { int a, b; }; union u1 f1(int);") + lib = verify(ffi, "test_function_returns_union", """ + union u1 { int a, b; }; + static union u1 f1(int x) { union u1 u; u.b = x; return u; } + """) + assert lib.f1(51).a == 51 + +def test_function_returns_partial_struct(): + ffi = FFI() + ffi.cdef("struct a { int a; ...; }; struct a f1(int);") + lib = verify(ffi, "test_function_returns_partial_struct", """ + struct a { int b, a, c; }; + static struct a f1(int x) { struct a s = {0}; s.a = x; return s; } + """) + assert lib.f1(52).a == 52 diff --git a/rpython/config/translationoption.py b/rpython/config/translationoption.py --- a/rpython/config/translationoption.py +++ b/rpython/config/translationoption.py @@ -261,6 +261,9 @@ "stack based virtual machines (only for backends that support it)", default=True), BoolOption("storesink", "Perform store sinking", default=True), + BoolOption("replace_we_are_jitted", + "Replace we_are_jitted() calls by False", + default=False, cmdline=None), BoolOption("none", "Do not run any backend optimizations", requires=[('translation.backendopt.inline', False), diff --git a/rpython/jit/codewriter/support.py b/rpython/jit/codewriter/support.py --- a/rpython/jit/codewriter/support.py +++ b/rpython/jit/codewriter/support.py @@ -582,6 +582,14 @@ return lltype.malloc(ARRAY, n, flavor='raw', zero=zero, add_memory_pressure=add_memory_pressure, track_allocation=track_allocation) + name = '_ll_1_raw_malloc_varsize' + if zero: + name += '_zero' + if add_memory_pressure: + name += '_mpressure' + if not track_allocation: + name += '_notrack' + _ll_1_raw_malloc_varsize.func_name = name return _ll_1_raw_malloc_varsize return build_ll_1_raw_malloc_varsize @@ -610,6 +618,14 @@ return lltype.malloc(STRUCT, flavor='raw', zero=zero, add_memory_pressure=add_memory_pressure, track_allocation=track_allocation) + name = '_ll_0_raw_malloc_fixedsize' + if zero: + name += '_zero' + if add_memory_pressure: + name += '_mpressure' + if not track_allocation: + name += '_notrack' + _ll_0_raw_malloc_fixedsize.func_name = name return _ll_0_raw_malloc_fixedsize return build_ll_0_raw_malloc_fixedsize diff --git a/rpython/jit/metainterp/warmspot.py b/rpython/jit/metainterp/warmspot.py --- a/rpython/jit/metainterp/warmspot.py +++ b/rpython/jit/metainterp/warmspot.py @@ -452,7 +452,8 @@ merge_if_blocks=True, constfold=True, remove_asserts=True, - really_remove_asserts=True) + really_remove_asserts=True, + replace_we_are_jitted=False) def prejit_optimizations_minimal_inline(self, policy, graphs): from rpython.translator.backendopt.inline import auto_inline_graphs diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py --- a/rpython/rlib/rmmap.py +++ b/rpython/rlib/rmmap.py @@ -799,8 +799,8 @@ rffi.cast(size_t, map_size), rffi.cast(rffi.INT, use_flag)) else: - def madvice_free(addr, map_size): - "No madvice() on this platform" + def madvise_free(addr, map_size): + "No madvise() on this platform" elif _MS_WINDOWS: def mmap(fileno, length, tagname="", access=_ACCESS_DEFAULT, offset=0): diff --git a/rpython/rlib/rposix_scandir.py b/rpython/rlib/rposix_scandir.py --- a/rpython/rlib/rposix_scandir.py +++ b/rpython/rlib/rposix_scandir.py @@ -17,7 +17,7 @@ def closedir(dirp): rposix.c_closedir(dirp) -NULL_DIRP = lltype.nullptr(rposix.DIRENT) +NULL_DIRP = lltype.nullptr(rposix.DIRP.TO) def nextentry(dirp): """Read the next entry and returns an opaque object. diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py --- a/rpython/rlib/rvmprof/rvmprof.py +++ b/rpython/rlib/rvmprof/rvmprof.py @@ -90,6 +90,9 @@ CodeClass._vmprof_unique_id = 0 # default value: "unknown" immut = CodeClass.__dict__.get('_immutable_fields_', []) CodeClass._immutable_fields_ = list(immut) + ['_vmprof_unique_id'] + attrs = CodeClass.__dict__.get('_attrs_', None) + if attrs is not None: + CodeClass._attrs_ = list(attrs) + ['_vmprof_unique_id'] self._code_classes.add(CodeClass) # class WeakCodeObjectList(RWeakListMixin): @@ -189,7 +192,7 @@ def decorated_function(*args): unique_id = get_code_fn(*args)._vmprof_unique_id - unique_id = rffi.cast(lltype.Signed, unique_id) + unique_id = rffi.cast(lltype.Signed, unique_id) # ^^^ removes the "known non-negative" hint for annotation if not jit.we_are_jitted(): x = enter_code(unique_id) diff --git a/rpython/rtyper/lltypesystem/rstr.py b/rpython/rtyper/lltypesystem/rstr.py --- a/rpython/rtyper/lltypesystem/rstr.py +++ b/rpython/rtyper/lltypesystem/rstr.py @@ -648,6 +648,7 @@ @staticmethod @jit.elidable + @signature(types.any(), types.any(), types.int(), types.int(), returns=types.int()) def ll_rfind_char(s, ch, start, end): if end > len(s.chars): end = len(s.chars) diff --git a/rpython/translator/backendopt/all.py b/rpython/translator/backendopt/all.py --- a/rpython/translator/backendopt/all.py +++ b/rpython/translator/backendopt/all.py @@ -2,6 +2,7 @@ from rpython.translator.backendopt import inline from rpython.translator.backendopt.malloc import remove_mallocs from rpython.translator.backendopt.constfold import constant_fold_graph +from rpython.translator.backendopt.constfold import replace_we_are_jitted from rpython.translator.backendopt.stat import print_statistics from rpython.translator.backendopt.merge_if_blocks import merge_if_blocks from rpython.translator import simplify @@ -36,6 +37,7 @@ # inline_threshold, mallocs # merge_if_blocks, constfold, heap2stack # clever_malloc_removal, remove_asserts + # replace_we_are_jitted config = translator.config.translation.backendopt.copy(as_default=True) config.set(**kwds) @@ -49,6 +51,10 @@ print "before optimizations:" print_statistics(translator.graphs[0], translator, "per-graph.txt") + if config.replace_we_are_jitted: + for graph in graphs: + replace_we_are_jitted(graph) + if config.remove_asserts: constfold(config, graphs) remove_asserts(translator, graphs) diff --git a/rpython/translator/backendopt/constfold.py b/rpython/translator/backendopt/constfold.py --- a/rpython/translator/backendopt/constfold.py +++ b/rpython/translator/backendopt/constfold.py @@ -276,3 +276,25 @@ rewire_links(splitblocks, graph) if not diffused and not splitblocks: break # finished + +def replace_symbolic(graph, symbolic, value): + result = False + for block in graph.iterblocks(): + for op in block.operations: + for i, arg in enumerate(op.args): + if isinstance(arg, Constant) and arg.value is symbolic: + op.args[i] = value + result = True + if block.exitswitch is symbolic: + block.exitswitch = value + result = True + return result + +def replace_we_are_jitted(graph): + from rpython.rlib import jit + replacement = Constant(0) + replacement.concretetype = lltype.Signed + did_replacement = replace_symbolic(graph, jit._we_are_jitted, replacement) + if did_replacement: + constant_fold_graph(graph) + return did_replacement diff --git a/rpython/translator/backendopt/test/test_all.py b/rpython/translator/backendopt/test/test_all.py --- a/rpython/translator/backendopt/test/test_all.py +++ b/rpython/translator/backendopt/test/test_all.py @@ -289,3 +289,19 @@ llinterp = LLInterpreter(t.rtyper) res = llinterp.eval_graph(later_graph, [10]) assert res == 1 + + def test_replace_we_are_jitted(self): + from rpython.rlib import jit + def f(): + if jit.we_are_jitted(): + return 1 + return 2 + jit.we_are_jitted() + + t = self.translateopt(f, []) + graph = graphof(t, f) + # by default, replace_we_are_jitted is off + assert graph.startblock.operations[0].args[0].value is jit._we_are_jitted + + t = self.translateopt(f, [], replace_we_are_jitted=True) + graph = graphof(t, f) + assert graph.startblock.exits[0].args[0].value == 2 diff --git a/rpython/translator/backendopt/test/test_constfold.py b/rpython/translator/backendopt/test/test_constfold.py --- a/rpython/translator/backendopt/test/test_constfold.py +++ b/rpython/translator/backendopt/test/test_constfold.py @@ -7,6 +7,7 @@ from rpython.rtyper import rclass from rpython.rlib import objectmodel from rpython.translator.backendopt.constfold import constant_fold_graph +from rpython.translator.backendopt.constfold import replace_we_are_jitted from rpython.conftest import option def get_graph(fn, signature): @@ -343,3 +344,18 @@ merge_if_blocks.merge_if_blocks_once(graph) constant_fold_graph(graph) check_graph(graph, [], 66, t) + +def test_replace_we_are_jitted(): + from rpython.rlib import jit + def fn(): + if jit.we_are_jitted(): + return 1 + return 2 + jit.we_are_jitted() + graph, t = get_graph(fn, []) + result = replace_we_are_jitted(graph) + assert result + checkgraph(graph) + # check shape of graph + assert len(graph.startblock.operations) == 0 + assert graph.startblock.exitswitch is None + assert graph.startblock.exits[0].target.exits[0].args[0].value == 2 diff --git a/rpython/translator/driver.py b/rpython/translator/driver.py --- a/rpython/translator/driver.py +++ b/rpython/translator/driver.py @@ -381,7 +381,7 @@ """ Run all backend optimizations - lltype version """ from rpython.translator.backendopt.all import backend_optimizations - backend_optimizations(self.translator) + backend_optimizations(self.translator, replace_we_are_jitted=True) STACKCHECKINSERTION = 'stackcheckinsertion_lltype' diff --git a/rpython/translator/test/test_interactive.py b/rpython/translator/test/test_interactive.py --- a/rpython/translator/test/test_interactive.py +++ b/rpython/translator/test/test_interactive.py @@ -78,3 +78,15 @@ dll = ctypes.CDLL(str(t.driver.c_entryp)) f = dll.pypy_g_f assert f(2, 3) == 5 + +def test_check_that_driver_uses_replace_we_are_jitted(): + from rpython.rlib import jit + def f(): + if jit.we_are_jitted(): + return 1 + return 2 + jit.we_are_jitted() + + t = Translation(f, []) + t.backendopt() + graph = t.driver.translator.graphs[0] + assert graph.startblock.exits[0].args[0].value == 2 _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit