[pypy-commit] pypy default: replace a number of _annspecialcase_ by @specialize in rlib/
cfbolz
pypy.commits at gmail.com
Wed Sep 21 16:14:47 EDT 2016
Author: Carl Friedrich Bolz <cfbolz at gmx.de>
Branch:
Changeset: r87291:f4db251591bc
Date: 2016-09-21 22:13 +0200
http://bitbucket.org/pypy/pypy/changeset/f4db251591bc/
Log: replace a number of _annspecialcase_ by @specialize in rlib/
diff --git a/rpython/rlib/clibffi.py b/rpython/rlib/clibffi.py
--- a/rpython/rlib/clibffi.py
+++ b/rpython/rlib/clibffi.py
@@ -359,12 +359,13 @@
tpe.members[n] = lltype.nullptr(FFI_TYPE_P.TO)
return tpe
+ at specialize.memo()
def cast_type_to_ffitype(tp):
""" This function returns ffi representation of rpython type tp
"""
return TYPE_MAP[tp]
-cast_type_to_ffitype._annspecialcase_ = 'specialize:memo'
+ at specialize.argtype(1)
def push_arg_as_ffiptr(ffitp, arg, ll_buf):
# This is for primitive types. Note that the exact type of 'arg' may be
# different from the expected 'c_size'. To cope with that, we fall back
@@ -396,7 +397,6 @@
arg >>= 8
else:
raise AssertionError
-push_arg_as_ffiptr._annspecialcase_ = 'specialize:argtype(1)'
# type defs for callback and closure userdata
@@ -470,12 +470,12 @@
FUNCFLAG_USE_ERRNO = 8
FUNCFLAG_USE_LASTERROR = 16
+ at specialize.arg(1) # hack :-/
def get_call_conv(flags, from_jit):
if _WIN32 and not _WIN64 and (flags & FUNCFLAG_CDECL == 0):
return FFI_STDCALL
else:
return FFI_DEFAULT_ABI
-get_call_conv._annspecialcase_ = 'specialize:arg(1)' # hack :-/
class AbstractFuncPtr(object):
@@ -599,6 +599,7 @@
else:
self.restype_size = -1
+ @specialize.argtype(1)
def push_arg(self, value):
#if self.pushed_args == self.argnum:
# raise TypeError("Too many arguments, eats %d, pushed %d" %
@@ -618,7 +619,6 @@
push_arg_as_ffiptr(self.argtypes[self.pushed_args], value,
self.ll_args[self.pushed_args])
self.pushed_args += 1
- push_arg._annspecialcase_ = 'specialize:argtype(1)'
def _check_args(self):
if self.pushed_args < self.argnum:
@@ -627,6 +627,7 @@
def _clean_args(self):
self.pushed_args = 0
+ @specialize.arg(1)
def call(self, RES_TP):
self._check_args()
ffires = c_ffi_call(self.ll_cif, self.funcsym,
@@ -645,7 +646,6 @@
self._clean_args()
check_fficall_result(ffires, self.flags)
return res
- call._annspecialcase_ = 'specialize:arg(1)'
def __del__(self):
if self.ll_args:
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -280,6 +280,7 @@
@oopspec("jit.isconstant(value)")
+ at specialize.call_location()
def isconstant(value):
"""
While tracing, returns whether or not the value is currently known to be
@@ -289,9 +290,9 @@
This is for advanced usage only.
"""
return NonConstant(False)
-isconstant._annspecialcase_ = "specialize:call_location"
@oopspec("jit.isvirtual(value)")
+ at specialize.call_location()
def isvirtual(value):
"""
Returns if this value is virtual, while tracing, it's relatively
@@ -300,7 +301,6 @@
This is for advanced usage only.
"""
return NonConstant(False)
-isvirtual._annspecialcase_ = "specialize:call_location"
@specialize.call_location()
def loop_unrolling_heuristic(lst, size, cutoff=2):
@@ -401,28 +401,27 @@
hop.exception_cannot_occur()
return hop.inputconst(lltype.Signed, _we_are_jitted)
-
+ at oopspec('jit.current_trace_length()')
def current_trace_length():
"""During JIT tracing, returns the current trace length (as a constant).
If not tracing, returns -1."""
if NonConstant(False):
return 73
return -1
-current_trace_length.oopspec = 'jit.current_trace_length()'
+ at oopspec('jit.debug(string, arg1, arg2, arg3, arg4)')
def jit_debug(string, arg1=-sys.maxint-1, arg2=-sys.maxint-1,
arg3=-sys.maxint-1, arg4=-sys.maxint-1):
"""When JITted, cause an extra operation JIT_DEBUG to appear in
the graphs. Should not be left after debugging."""
keepalive_until_here(string) # otherwise the whole function call is removed
-jit_debug.oopspec = 'jit.debug(string, arg1, arg2, arg3, arg4)'
+ at oopspec('jit.assert_green(value)')
+ at specialize.argtype(0)
def assert_green(value):
"""Very strong assert: checks that 'value' is a green
(a JIT compile-time constant)."""
keepalive_until_here(value)
-assert_green._annspecialcase_ = 'specialize:argtype(0)'
-assert_green.oopspec = 'jit.assert_green(value)'
class AssertGreenFailed(Exception):
pass
@@ -457,6 +456,7 @@
# ____________________________________________________________
# VRefs
+ at oopspec('virtual_ref(x)')
@specialize.argtype(0)
def virtual_ref(x):
"""Creates a 'vref' object that contains a reference to 'x'. Calls
@@ -467,14 +467,13 @@
dereferenced (by the call syntax 'vref()'), it returns 'x', which is
then forced."""
return DirectJitVRef(x)
-virtual_ref.oopspec = 'virtual_ref(x)'
+ at oopspec('virtual_ref_finish(x)')
@specialize.argtype(1)
def virtual_ref_finish(vref, x):
"""See docstring in virtual_ref(x)"""
keepalive_until_here(x) # otherwise the whole function call is removed
_virtual_ref_finish(vref, x)
-virtual_ref_finish.oopspec = 'virtual_ref_finish(x)'
def non_virtual_ref(x):
"""Creates a 'vref' that just returns x when called; nothing more special.
@@ -831,6 +830,7 @@
jit_opencoder_model
"""
+ at specialize.arg(0)
def set_user_param(driver, text):
"""Set the tunable JIT parameters from a user-supplied string
following the format 'param=value,param=value', or 'off' to
@@ -866,7 +866,6 @@
break
else:
raise ValueError
-set_user_param._annspecialcase_ = 'specialize:arg(0)'
# ____________________________________________________________
#
diff --git a/rpython/rlib/listsort.py b/rpython/rlib/listsort.py
--- a/rpython/rlib/listsort.py
+++ b/rpython/rlib/listsort.py
@@ -1,4 +1,5 @@
from rpython.rlib.rarithmetic import ovfcheck
+from rpython.rlib.objectmodel import specialize
## ------------------------------------------------------------------------
@@ -141,6 +142,12 @@
# or, IOW, the first k elements of a should precede key, and the last
# n-k should follow key.
+ # hint for the annotator: the argument 'rightmost' is always passed in as
+ # a constant (either True or False), so we can specialize the function for
+ # the two cases. (This is actually needed for technical reasons: the
+ # variable 'lower' must contain a known method, which is the case in each
+ # specialized version but not in the unspecialized one.)
+ @specialize.arg(4)
def gallop(self, key, a, hint, rightmost):
assert 0 <= hint < a.len
if rightmost:
@@ -212,12 +219,6 @@
assert lastofs == ofs # so a[ofs-1] < key <= a[ofs]
return ofs
- # hint for the annotator: the argument 'rightmost' is always passed in as
- # a constant (either True or False), so we can specialize the function for
- # the two cases. (This is actually needed for technical reasons: the
- # variable 'lower' must contain a known method, which is the case in each
- # specialized version but not in the unspecialized one.)
- gallop._annspecialcase_ = "specialize:arg(4)"
# ____________________________________________________________
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -37,6 +37,7 @@
from rpython.rlib import objectmodel
from rpython.flowspace.model import Constant, const
from rpython.flowspace.specialcase import register_flow_sc
+from rpython.rlib.objectmodel import specialize
"""
Long-term target:
@@ -135,14 +136,15 @@
# We deal directly with overflow there anyway.
return r_longlonglong(n)
+ at specialize.argtype(0)
def widen(n):
from rpython.rtyper.lltypesystem import lltype
if _should_widen_type(lltype.typeOf(n)):
return intmask(n)
else:
return n
-widen._annspecialcase_ = 'specialize:argtype(0)'
+ at specialize.memo()
def _should_widen_type(tp):
from rpython.rtyper.lltypesystem import lltype, rffi
if tp is lltype.Bool:
@@ -153,19 +155,18 @@
assert issubclass(r_class, base_int)
return r_class.BITS < LONG_BIT or (
r_class.BITS == LONG_BIT and r_class.SIGNED)
-_should_widen_type._annspecialcase_ = 'specialize:memo'
# the replacement for sys.maxint
maxint = int(LONG_TEST - 1)
# for now, it should be equal to sys.maxint on all supported platforms
assert maxint == sys.maxint
+ at specialize.argtype(0)
def is_valid_int(r):
if objectmodel.we_are_translated():
return isinstance(r, int)
return isinstance(r, (base_int, int, long, bool)) and (
-maxint - 1 <= r <= maxint)
-is_valid_int._annspecialcase_ = 'specialize:argtype(0)'
def ovfcheck(r):
"NOT_RPYTHON"
@@ -225,12 +226,12 @@
return build_int(None, self_type.SIGNED, max(self_type.BITS, other_type.BITS))
raise AssertionError("Merging these types (%s, %s) is not supported" % (self_type, other_type))
+ at specialize.memo()
def signedtype(t):
if t in (bool, int, long):
return True
else:
return t.SIGNED
-signedtype._annspecialcase_ = 'specialize:memo'
def normalizedinttype(t):
if t is int:
@@ -241,11 +242,12 @@
assert t.BITS <= r_longlong.BITS
return build_int(None, t.SIGNED, r_longlong.BITS)
+ at specialize.argtype(0)
def most_neg_value_of_same_type(x):
from rpython.rtyper.lltypesystem import lltype
return most_neg_value_of(lltype.typeOf(x))
-most_neg_value_of_same_type._annspecialcase_ = 'specialize:argtype(0)'
+ at specialize.memo()
def most_neg_value_of(tp):
from rpython.rtyper.lltypesystem import lltype, rffi
if tp is lltype.Signed:
@@ -256,13 +258,13 @@
return r_class(-(r_class.MASK >> 1) - 1)
else:
return r_class(0)
-most_neg_value_of._annspecialcase_ = 'specialize:memo'
+ at specialize.argtype(0)
def most_pos_value_of_same_type(x):
from rpython.rtyper.lltypesystem import lltype
return most_pos_value_of(lltype.typeOf(x))
-most_pos_value_of_same_type._annspecialcase_ = 'specialize:argtype(0)'
+ at specialize.memo()
def most_pos_value_of(tp):
from rpython.rtyper.lltypesystem import lltype, rffi
if tp is lltype.Signed:
@@ -273,8 +275,8 @@
return r_class(r_class.MASK >> 1)
else:
return r_class(r_class.MASK)
-most_pos_value_of._annspecialcase_ = 'specialize:memo'
+ at specialize.memo()
def is_signed_integer_type(tp):
from rpython.rtyper.lltypesystem import lltype, rffi
if tp is lltype.Signed:
@@ -284,7 +286,6 @@
return r_class.SIGNED
except KeyError:
return False # not an integer type
-is_signed_integer_type._annspecialcase_ = 'specialize:memo'
def highest_bit(n):
"""
@@ -676,7 +677,7 @@
from rpython.rtyper.lltypesystem.lloperation import llop
return llop.int_mod(lltype.Signed, x, y)
- at objectmodel.specialize.ll()
+ at specialize.ll()
def byteswap(arg):
""" Convert little->big endian and the opposite
"""
diff --git a/rpython/rlib/rbigint.py b/rpython/rlib/rbigint.py
--- a/rpython/rlib/rbigint.py
+++ b/rpython/rlib/rbigint.py
@@ -90,16 +90,16 @@
FIVEARY_CUTOFF = 8
+ at specialize.argtype(0)
def _mask_digit(x):
return UDIGIT_MASK(x & MASK)
-_mask_digit._annspecialcase_ = 'specialize:argtype(0)'
def _widen_digit(x):
return rffi.cast(LONG_TYPE, x)
+ at specialize.argtype(0)
def _store_digit(x):
return rffi.cast(STORE_TYPE, x)
-_store_digit._annspecialcase_ = 'specialize:argtype(0)'
def _load_unsigned_digit(x):
return rffi.cast(UNSIGNED_TYPE, x)
@@ -175,11 +175,11 @@
return _load_unsigned_digit(self._digits[x])
udigit._always_inline_ = True
+ @specialize.argtype(2)
def setdigit(self, x, val):
val = _mask_digit(val)
assert val >= 0
self._digits[x] = _store_digit(val)
- setdigit._annspecialcase_ = 'specialize:argtype(2)'
setdigit._always_inline_ = True
def numdigits(self):
@@ -1312,6 +1312,7 @@
return res
+ at specialize.argtype(0)
def digits_from_nonneg_long(l):
digits = []
while True:
@@ -1319,8 +1320,8 @@
l = l >> SHIFT
if not l:
return digits[:] # to make it non-resizable
-digits_from_nonneg_long._annspecialcase_ = "specialize:argtype(0)"
-
+
+ at specialize.argtype(0)
def digits_for_most_neg_long(l):
# This helper only works if 'l' is the most negative integer of its
# type, which in base 2 looks like: 1000000..0000
@@ -1335,8 +1336,8 @@
assert l & MASK == l
digits.append(_store_digit(l))
return digits[:] # to make it non-resizable
-digits_for_most_neg_long._annspecialcase_ = "specialize:argtype(0)"
-
+
+ at specialize.argtype(0)
def args_from_rarith_int1(x):
if x > 0:
return digits_from_nonneg_long(x), 1
@@ -1348,11 +1349,10 @@
else:
# the most negative integer! hacks needed...
return digits_for_most_neg_long(x), -1
-args_from_rarith_int1._annspecialcase_ = "specialize:argtype(0)"
-
+
+ at specialize.argtype(0)
def args_from_rarith_int(x):
return args_from_rarith_int1(widen(x))
-args_from_rarith_int._annspecialcase_ = "specialize:argtype(0)"
# ^^^ specialized by the precise type of 'x', which is typically a r_xxx
# instance from rlib.rarithmetic
@@ -1909,6 +1909,7 @@
i += 1
return borrow
+ at specialize.argtype(2)
def _muladd1(a, n, extra=0):
"""Multiply by a single digit and add a single digit, ignoring the sign.
"""
@@ -1926,7 +1927,7 @@
z.setdigit(i, carry)
z._normalize()
return z
-_muladd1._annspecialcase_ = "specialize:argtype(2)"
+
def _v_lshift(z, a, m, d):
""" Shift digit vector a[0:m] d bits left, with 0 <= d < SHIFT. Put
* result in z[0:m], and return the d bits shifted out of the top.
@@ -2178,6 +2179,7 @@
ad = -ad
return ad
+ at specialize.arg(0)
def _loghelper(func, arg):
"""
A decent logarithm is easy to compute even for huge bigints, but libm can't
@@ -2195,7 +2197,6 @@
# CAUTION: e*SHIFT may overflow using int arithmetic,
# so force use of double. */
return func(x) + (e * float(SHIFT) * func(2.0))
-_loghelper._annspecialcase_ = 'specialize:arg(0)'
# ____________________________________________________________
@@ -2519,6 +2520,7 @@
return output.build()
+ at specialize.arg(1)
def _bitwise(a, op, b): # '&', '|', '^'
""" Bitwise and/or/xor operations """
@@ -2598,8 +2600,8 @@
return z
return z.invert()
-_bitwise._annspecialcase_ = "specialize:arg(1)"
-
+
+ at specialize.arg(1)
def _int_bitwise(a, op, b): # '&', '|', '^'
""" Bitwise and/or/xor operations """
@@ -2682,7 +2684,6 @@
return z
return z.invert()
-_int_bitwise._annspecialcase_ = "specialize:arg(1)"
ULONGLONG_BOUND = r_ulonglong(1L << (r_longlong.BITS-1))
LONGLONG_MIN = r_longlong(-(1L << (r_longlong.BITS-1)))
diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -10,7 +10,7 @@
from rpython.rtyper.lltypesystem import rffi, lltype
from rpython.rlib import rposix
from rpython.translator.tool.cbuild import ExternalCompilationInfo
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.rlib.nonconst import NonConstant
from rpython.rlib.rarithmetic import intmask
@@ -239,12 +239,12 @@
_, _VirtualProtect_safe = winexternal('VirtualProtect',
[rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD],
BOOL)
+ @specialize.ll()
def VirtualProtect(addr, size, mode, oldmode_ptr):
return _VirtualProtect_safe(addr,
rffi.cast(rffi.SIZE_T, size),
rffi.cast(DWORD, mode),
oldmode_ptr)
- VirtualProtect._annspecialcase_ = 'specialize:ll'
VirtualFree, VirtualFree_safe = winexternal('VirtualFree',
[rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL)
diff --git a/rpython/rlib/rstruct/runpack.py b/rpython/rlib/rstruct/runpack.py
--- a/rpython/rlib/rstruct/runpack.py
+++ b/rpython/rlib/rstruct/runpack.py
@@ -7,6 +7,7 @@
from struct import unpack
from rpython.rlib.rstruct.formatiterator import FormatIterator
from rpython.rlib.rstruct.error import StructError
+from rpython.rlib.objectmodel import specialize
class MasterReader(object):
def __init__(self, s):
@@ -99,14 +100,14 @@
self._create_unpacking_func()
return True
+ at specialize.memo()
def create_unpacker(unpack_str):
fmtiter = FrozenUnpackIterator(unpack_str)
fmtiter.interpret(unpack_str)
assert fmtiter._freeze_()
return fmtiter
-create_unpacker._annspecialcase_ = 'specialize:memo'
+ at specialize.arg(0)
def runpack(fmt, input):
unpacker = create_unpacker(fmt)
return unpacker.unpack(input)
-runpack._annspecialcase_ = 'specialize:arg(0)'
More information about the pypy-commit
mailing list