Author: Armin Rigo <ar...@tunes.org> Branch: conditional_call_value_4 Changeset: r88600:19979eb85207 Date: 2016-11-24 09:11 +0100 http://bitbucket.org/pypy/pypy/changeset/19979eb85207/
Log: Tracing: constant-fold strhash(). Makes test_virtual_dict_constant_keys pass. Also, in bh_strhash(), always compute the hash, never returns zero. diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py --- a/rpython/jit/backend/llgraph/runner.py +++ b/rpython/jit/backend/llgraph/runner.py @@ -15,11 +15,12 @@ from rpython.rtyper.llinterp import LLInterpreter, LLException from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rstr from rpython.rtyper.lltypesystem.lloperation import llop +from rpython.rtyper.annlowlevel import hlstr, hlunicode from rpython.rtyper import rclass from rpython.rlib.clibffi import FFI_DEFAULT_ABI from rpython.rlib.rarithmetic import ovfcheck, r_uint, r_ulonglong, intmask -from rpython.rlib.objectmodel import Symbolic +from rpython.rlib.objectmodel import Symbolic, compute_hash class LLAsmInfo(object): def __init__(self, lltrace): @@ -789,7 +790,8 @@ rstr.copy_string_contents(src, dst, srcstart, dststart, length) def bh_strhash(self, s): - return s._obj.container.hash + lls = s._obj.container + return compute_hash(hlstr(lls._as_ptr())) def bh_newunicode(self, length): return lltype.cast_opaque_ptr(llmemory.GCREF, @@ -814,7 +816,8 @@ rstr.copy_unicode_contents(src, dst, srcstart, dststart, length) def bh_unicodehash(self, s): - return s._obj.container.hash + lls = s._obj.container + return compute_hash(hlunicode(lls._as_ptr())) def bh_new(self, sizedescr): return lltype.cast_opaque_ptr(llmemory.GCREF, diff --git a/rpython/jit/backend/llsupport/llmodel.py b/rpython/jit/backend/llsupport/llmodel.py --- a/rpython/jit/backend/llsupport/llmodel.py +++ b/rpython/jit/backend/llsupport/llmodel.py @@ -3,8 +3,9 @@ from rpython.rtyper.lltypesystem.lloperation import llop from rpython.rtyper.llinterp import LLInterpreter from rpython.rtyper.annlowlevel import llhelper, MixLevelHelperAnnotator +from rpython.rtyper.annlowlevel import hlstr, hlunicode from rpython.rtyper.llannotation import lltype_to_annotation -from rpython.rlib.objectmodel import we_are_translated, specialize +from rpython.rlib.objectmodel import we_are_translated, specialize, compute_hash from rpython.jit.metainterp import history, compile from rpython.jit.metainterp.optimize import SpeculativeError from rpython.jit.codewriter import heaptracker, longlong @@ -665,11 +666,11 @@ def bh_strhash(self, string): s = lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), string) - return s.hash + return compute_hash(hlstr(s)) def bh_unicodehash(self, string): u = lltype.cast_opaque_ptr(lltype.Ptr(rstr.UNICODE), string) - return u.hash + return compute_hash(hlunicode(u)) def bh_strgetitem(self, string, index): s = lltype.cast_opaque_ptr(lltype.Ptr(rstr.STR), string) diff --git a/rpython/jit/metainterp/pyjitpl.py b/rpython/jit/metainterp/pyjitpl.py --- a/rpython/jit/metainterp/pyjitpl.py +++ b/rpython/jit/metainterp/pyjitpl.py @@ -1164,10 +1164,16 @@ @arguments("box") def opimpl_strhash(self, strbox): + if isinstance(strbox, ConstPtr): + h = self.metainterp.cpu.bh_strhash(strbox.getref_base()) + return ConstInt(h) return self.execute(rop.STRHASH, strbox) @arguments("box") def opimpl_unicodehash(self, unicodebox): + if isinstance(unicodebox, ConstPtr): + h = self.metainterp.cpu.bh_unicodehash(unicodebox.getref_base()) + return ConstInt(h) return self.execute(rop.UNICODEHASH, unicodebox) @arguments("box") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit