[pypy-commit] pypy default: Add many checks and tests until I found where to insert the two lines that fix 'r_int' support
arigo
pypy.commits at gmail.com
Tue Jan 3 04:43:53 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r89330:ba112f125696
Date: 2017-01-03 10:43 +0100
http://bitbucket.org/pypy/pypy/changeset/ba112f125696/
Log: Add many checks and tests until I found where to insert the two
lines that fix 'r_int' support
diff --git a/rpython/jit/codewriter/assembler.py b/rpython/jit/codewriter/assembler.py
--- a/rpython/jit/codewriter/assembler.py
+++ b/rpython/jit/codewriter/assembler.py
@@ -5,6 +5,7 @@
from rpython.jit.codewriter.jitcode import SwitchDictDescr, JitCode
from rpython.jit.codewriter import heaptracker, longlong
from rpython.rlib.objectmodel import ComputedIntSymbolic
+from rpython.rlib.rarithmetic import r_int
from rpython.flowspace.model import Constant
from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
from rpython.rtyper import rclass
@@ -82,6 +83,8 @@
if not isinstance(value, (llmemory.AddressAsInt,
ComputedIntSymbolic)):
value = lltype.cast_primitive(lltype.Signed, value)
+ if type(value) is r_int:
+ value = int(value)
if allow_short:
try:
short_num = -128 <= value <= 127
diff --git a/rpython/jit/codewriter/jitcode.py b/rpython/jit/codewriter/jitcode.py
--- a/rpython/jit/codewriter/jitcode.py
+++ b/rpython/jit/codewriter/jitcode.py
@@ -1,6 +1,7 @@
from rpython.jit.metainterp.history import AbstractDescr, ConstInt
from rpython.jit.codewriter import heaptracker
from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.rarithmetic import base_int
class JitCode(AbstractDescr):
@@ -21,6 +22,10 @@
liveness=None, startpoints=None, alllabels=None,
resulttypes=None):
self.code = code
+ for x in constants_i:
+ assert not isinstance(x, base_int), (
+ "found constant %r of type %r, must not appear in "
+ "JitCode.constants_i" % (x, type(x)))
# if the following lists are empty, use a single shared empty list
self.constants_i = constants_i or self._empty_i
self.constants_r = constants_r or self._empty_r
diff --git a/rpython/jit/codewriter/test/test_assembler.py b/rpython/jit/codewriter/test/test_assembler.py
--- a/rpython/jit/codewriter/test/test_assembler.py
+++ b/rpython/jit/codewriter/test/test_assembler.py
@@ -7,6 +7,7 @@
from rpython.jit.metainterp.history import AbstractDescr
from rpython.flowspace.model import Constant
from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rlib.rarithmetic import r_int, r_uint
def test_assemble_simple():
@@ -239,3 +240,17 @@
]
assembler = Assembler()
py.test.raises(AssemblerError, assembler.assemble, ssarepr)
+
+def test_assemble_r_int():
+ # r_int is a strange type, which the jit should replace with int.
+ # r_uint is also replaced with int.
+ ssarepr = SSARepr("test")
+ i0, i1, i2 = Register('int', 0), Register('int', 1), Register('int', 2)
+ ssarepr.insns = [
+ ('uint_add', i0, Constant(r_uint(42424242), lltype.Unsigned), '->', i1),
+ ('int_add', i0, Constant(r_int(42424243), lltype.Signed), '->', i2),
+ ]
+ assembler = Assembler()
+ jitcode = assembler.assemble(ssarepr)
+ assert jitcode.constants_i == [42424242, 42424243]
+ assert map(type, jitcode.constants_i) == [int, int]
diff --git a/rpython/jit/metainterp/blackhole.py b/rpython/jit/metainterp/blackhole.py
--- a/rpython/jit/metainterp/blackhole.py
+++ b/rpython/jit/metainterp/blackhole.py
@@ -6,6 +6,7 @@
from rpython.jit.metainterp.history import MissingValue
from rpython.rlib import longlong2float
from rpython.rlib.debug import ll_assert, make_sure_not_resized
+from rpython.rlib.debug import check_annotation
from rpython.rlib.objectmodel import we_are_translated, specialize
from rpython.rlib.rarithmetic import intmask, LONG_BIT, r_uint, ovfcheck
from rpython.rlib.unroll import unrolling_iterable
@@ -183,7 +184,7 @@
if lltype.typeOf(result) is lltype.Bool:
result = int(result)
assert lltype.typeOf(result) is lltype.Signed
- self.registers_i[ord(code[position])] = result
+ self.registers_i[ord(code[position])] = plain_int(result)
position += 1
elif resulttype == 'r':
# argcode should be 'r' too
@@ -213,7 +214,7 @@
if lltype.typeOf(result) is lltype.Bool:
result = int(result)
assert lltype.typeOf(result) is lltype.Signed
- self.registers_i[ord(code[position])] = result
+ self.registers_i[ord(code[position])] = plain_int(result)
position += 1
elif resulttype == 'L':
assert result >= 0
@@ -251,6 +252,23 @@
if b < 0 or b >= LONG_BIT:
raise ValueError("Shift count, %d, not in valid range, 0 .. %d." % (b, LONG_BIT-1))
+def check_list_of_plain_integers(s_arg, bookkeeper):
+ """Check that 'BlackhopeInterpreter.registers_i' is annotated as a
+ non-resizable list of plain integers (and not r_int's for example)."""
+ from rpython.annotator import model as annmodel
+ assert isinstance(s_arg, annmodel.SomeList)
+ s_arg.listdef.never_resize()
+ assert s_arg.listdef.listitem.s_value.knowntype is int
+
+def _check_int(s_arg, bookkeeper):
+ assert s_arg.knowntype is int
+
+def plain_int(x):
+ """Check that 'x' is annotated as a plain integer (and not r_int)"""
+ check_annotation(x, _check_int)
+ return x
+
+
class BlackholeInterpreter(object):
def __init__(self, builder, count_interpreter):
@@ -277,6 +295,7 @@
self.tmpreg_r = default_r
self.tmpreg_f = default_f
self.jitcode = None
+ check_annotation(self.registers_i, check_list_of_plain_integers)
def __repr__(self):
return '<BHInterp #%d>' % self.count_interpreter
@@ -295,7 +314,7 @@
def setarg_i(self, index, value):
assert lltype.typeOf(value) is lltype.Signed
- self.registers_i[index] = value
+ self.registers_i[index] = plain_int(value)
def setarg_r(self, index, value):
assert lltype.typeOf(value) == llmemory.GCREF
@@ -1573,7 +1592,8 @@
# 'xxx_call_yyy' instructions from the caller frame
def _setup_return_value_i(self, result):
assert lltype.typeOf(result) is lltype.Signed
- self.registers_i[ord(self.jitcode.code[self.position-1])] = result
+ self.registers_i[ord(self.jitcode.code[self.position-1])] = plain_int(
+ result)
def _setup_return_value_r(self, result):
assert lltype.typeOf(result) == llmemory.GCREF
self.registers_r[ord(self.jitcode.code[self.position-1])] = result
More information about the pypy-commit
mailing list