[pypy-svn] r35238 - in pypy/branch/jit-real-world/pypy/jit: codegen/i386 goal hintannotator timeshifter timeshifter/test
arigo at codespeak.net
arigo at codespeak.net
Mon Dec 4 01:32:49 CET 2006
Author: arigo
Date: Mon Dec 4 01:32:45 2006
New Revision: 35238
Modified:
pypy/branch/jit-real-world/pypy/jit/codegen/i386/rgenop.py
pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py
pypy/branch/jit-real-world/pypy/jit/hintannotator/bookkeeper.py
pypy/branch/jit-real-world/pypy/jit/hintannotator/model.py
pypy/branch/jit-real-world/pypy/jit/timeshifter/hrtyper.py
pypy/branch/jit-real-world/pypy/jit/timeshifter/rcontainer.py
pypy/branch/jit-real-world/pypy/jit/timeshifter/test/test_timeshift.py
Log:
(pedronis, arigo)
More and more fun with Voids.
Modified: pypy/branch/jit-real-world/pypy/jit/codegen/i386/rgenop.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/codegen/i386/rgenop.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/codegen/i386/rgenop.py Mon Dec 4 01:32:45 2006
@@ -956,12 +956,18 @@
@staticmethod
@specialize.memo()
def kindToken(T):
+ if T is lltype.Float:
+ raise NotImplementedError("floats in the i386 back-end")
return None # for now
@staticmethod
@specialize.memo()
def sigToken(FUNCTYPE):
- return len(FUNCTYPE.ARGS) # for now
+ numargs = 0
+ for ARG in FUNCTYPE.ARGS:
+ if ARG is not lltype.Void:
+ numargs += 1
+ return numargs # for now
@staticmethod
def erasedType(T):
Modified: pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/goal/jitstep.py Mon Dec 4 01:32:45 2006
@@ -63,4 +63,4 @@
t.graphs.append(graph)
# XXX temp
- drv.compile()
+ drv.source()
Modified: pypy/branch/jit-real-world/pypy/jit/hintannotator/bookkeeper.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/hintannotator/bookkeeper.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/hintannotator/bookkeeper.py Mon Dec 4 01:32:45 2006
@@ -145,14 +145,6 @@
def immutablevalue(self, value):
return self.immutableconstant(Constant(value, lltype.typeOf(value)))
- def valueoftype(self, TYPE):
- # the union of all annotations of the given TYPE - that's a
- # SomeLLAbstractVariable, unless TYPE is Void
- if TYPE is lltype.Void:
- return hintmodel.s_void
- else:
- return hintmodel.SomeLLAbstractVariable(TYPE)
-
def current_op_concretetype(self):
_, block, i = self.position_key
op = block.operations[i]
Modified: pypy/branch/jit-real-world/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/hintannotator/model.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/hintannotator/model.py Mon Dec 4 01:32:45 2006
@@ -204,6 +204,14 @@
SomeLLAbstractValue.__init__(self, T, deepfrozen)
assert T is not lltype.Void # use bookkeeper.valueoftype()
+def variableoftype(TYPE, deepfrozen=False):
+ # the union of all annotations of the given TYPE - that's a
+ # SomeLLAbstractVariable, unless TYPE is Void
+ if TYPE is lltype.Void:
+ return s_void
+ else:
+ return SomeLLAbstractVariable(TYPE, deepfrozen=deepfrozen)
+
class SomeLLAbstractContainer(SomeLLAbstractValue):
deepfrozen = False # XXX for now
@@ -299,7 +307,7 @@
def getfield(hs_v1, hs_fieldname):
S = hs_v1.concretetype.TO
FIELD_TYPE = getattr(S, hs_fieldname.const)
- return SomeLLAbstractVariable(FIELD_TYPE, hs_v1.deepfrozen)
+ return variableoftype(FIELD_TYPE, hs_v1.deepfrozen)
def setfield(hs_v1, hs_fieldname, hs_value):
pass
@@ -309,17 +317,6 @@
FIELD_TYPE = getattr(S, hs_fieldname.const)
return SomeLLAbstractVariable(lltype.Ptr(FIELD_TYPE), hs_v1.deepfrozen)
-## def getarrayitem(hs_v1, hs_index):
-## ARRAY = hs_v1.concretetype.TO
-## return SomeLLAbstractVariable(ARRAY.OF)
-
-## def setarrayitem(hs_v1, hs_index, hs_value):
-## pass
-
-## def getarraysubstruct(hs_v1, hs_index):
-## ARRAY = hs_v1.concretetype.TO
-## return SomeLLAbstractVariable(lltype.Ptr(ARRAY.OF))
-
def indirect_call(hs_v1, *args_hs):
hs_graph_list = args_hs[-1]
args_hs = args_hs[:-1]
@@ -329,7 +326,7 @@
bookkeeper = getbookkeeper()
if not bookkeeper.annotator.policy.look_inside_graphs(graph_list):
# cannot follow
- return bookkeeper.valueoftype(hs_v1.concretetype.TO.RESULT)
+ return variableoftype(hs_v1.concretetype.TO.RESULT)
fixed = bookkeeper.myorigin().read_fixed()
hs_res = bookkeeper.graph_family_call(graph_list, fixed, args_hs)
@@ -379,19 +376,19 @@
pass
# don't try to annotate suggested_primitive graphs
if getattr(getattr(fnobj, '_callable', None), 'suggested_primitive', False):
- return SomeLLAbstractVariable(lltype.typeOf(fnobj).RESULT)
+ return variableoftype(lltype.typeOf(fnobj).RESULT)
# normal call
if not hasattr(fnobj, 'graph'):
raise NotImplementedError("XXX call to externals or primitives")
if not bookkeeper.annotator.policy.look_inside_graph(fnobj.graph):
- return bookkeeper.valueoftype(lltype.typeOf(fnobj).RESULT)
+ return variableoftype(lltype.typeOf(fnobj).RESULT)
# recursive call from the entry point to itself: ignore them and
# just hope the annotations are correct
if (bookkeeper.getdesc(fnobj.graph)._cache.get(None, None) is
bookkeeper.annotator.translator.graphs[0]):
- return SomeLLAbstractVariable(lltype.typeOf(fnobj).RESULT)
+ return variableoftype(lltype.typeOf(fnobj).RESULT)
fixed = bookkeeper.myorigin().read_fixed()
hs_res = bookkeeper.graph_call(fnobj.graph, fixed, args_hs)
@@ -421,7 +418,7 @@
myorigin=origin,
deepfrozen=hs_c1.deepfrozen)
else:
- return SomeLLAbstractVariable(FIELD_TYPE)
+ return variableoftype(FIELD_TYPE)
def getsubstruct(hs_c1, hs_fieldname):
S = hs_c1.concretetype.TO
@@ -468,8 +465,7 @@
class __extend__(pairtype(SomeLLAbstractValue, SomeLLAbstractValue)):
def getarrayitem((hs_v1, hs_v2)):
- return SomeLLAbstractVariable(hs_v1.concretetype.TO.OF,
- hs_v1.deepfrozen)
+ return variableoftype(hs_v1.concretetype.TO.OF, hs_v1.deepfrozen)
def setarrayitem((hs_v1, hs_v2), hs_v3):
pass
@@ -500,7 +496,7 @@
if (getattr(hs_v1, 'eager_concrete', False) or
getattr(hs_v2, 'eager_concrete', False)):
pair(hs_v1, hs_v2).invalid_union()
- return SomeLLAbstractVariable(hs_v1.concretetype, hs_v1.deepfrozen)
+ return variableoftype(hs_v1.concretetype, hs_v1.deepfrozen)
class __extend__(pairtype(SomeLLAbstractConstant, SomeLLAbstractConstant)):
@@ -530,7 +526,7 @@
myorigin=origin,
deepfrozen=hs_c1.deepfrozen)
else:
- return SomeLLAbstractVariable(READ_TYPE)
+ return variableoftype(READ_TYPE)
def getarraysubstruct((hs_c1, hs_index)):
A = hs_c1.concretetype.TO
@@ -588,10 +584,7 @@
if bookkeeper.annotator.policy.novirtualcontainer:
# "blue variables" disabled, we just return a red var all the time.
RESULT = bookkeeper.current_op_concretetype()
- if RESULT is lltype.Void:
- return None
- else:
- return SomeLLAbstractVariable(RESULT)
+ return variableoftype(RESULT)
# parse the oopspec and fill in the arguments
operation_name, args = ll_func.oopspec.split('(', 1)
Modified: pypy/branch/jit-real-world/pypy/jit/timeshifter/hrtyper.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/timeshifter/hrtyper.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/timeshifter/hrtyper.py Mon Dec 4 01:32:45 2006
@@ -677,6 +677,8 @@
c_deepfrozen = inputconst(lltype.Bool, hop.args_s[0].deepfrozen)
structdesc = rcontainer.StructTypeDesc(self.RGenOp, PTRTYPE.TO)
fielddesc = structdesc.getfielddesc(c_fieldname.value)
+ if fielddesc is None: # Void field
+ return
c_fielddesc = inputconst(lltype.Void, fielddesc)
s_fielddesc = ts.rtyper.annotator.bookkeeper.immutablevalue(fielddesc)
v_jitstate = hop.llops.getjitstate()
@@ -687,6 +689,8 @@
def translate_op_getarrayitem(self, hop):
PTRTYPE = originalconcretetype(hop.args_s[0])
+ if PTRTYPE.TO.OF is lltype.Void:
+ return
ts = self
v_argbox, v_index = hop.inputargs(self.getredrepr(PTRTYPE),
self.getredrepr(lltype.Signed))
@@ -751,6 +755,7 @@
v_destbox = hop.llops.as_ptrredbox(v_destbox)
structdesc = rcontainer.StructTypeDesc(self.RGenOp, PTRTYPE.TO)
fielddesc = structdesc.getfielddesc(c_fieldname.value)
+ assert fielddesc is not None # skipped above
c_fielddesc = inputconst(lltype.Void, fielddesc)
s_fielddesc = ts.rtyper.annotator.bookkeeper.immutablevalue(fielddesc)
v_jitstate = hop.llops.getjitstate()
Modified: pypy/branch/jit-real-world/pypy/jit/timeshifter/rcontainer.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/timeshifter/rcontainer.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/timeshifter/rcontainer.py Mon Dec 4 01:32:45 2006
@@ -73,7 +73,7 @@
desc = None
else:
desc = StructFieldDesc(RGenOp, self.PTRTYPE, name, index)
- fielddescs.append(desc)
+ fielddescs.append(desc)
fielddesc_by_name[name] = desc
self.fielddescs = fielddescs
self.fielddesc_by_name = fielddesc_by_name
@@ -120,6 +120,7 @@
# XXX basic field descs for now
class FieldDesc(object):
__metaclass__ = cachedtype
+ allow_void = False
def __init__(self, RGenOp, PTRTYPE, RESTYPE):
self.PTRTYPE = PTRTYPE
@@ -128,7 +129,10 @@
self.RESTYPE = RESTYPE
self.ptrkind = RGenOp.kindToken(PTRTYPE)
self.kind = RGenOp.kindToken(RESTYPE)
- self.redboxcls = rvalue.ll_redboxcls(RESTYPE)
+ if RESTYPE is lltype.Void and self.allow_void:
+ pass # no redboxcls at all
+ else:
+ self.redboxcls = rvalue.ll_redboxcls(RESTYPE)
self.immutable = PTRTYPE.TO._hints.get('immutable', False)
def _freeze_(self):
@@ -165,6 +169,8 @@
self.defaultbox = self.redboxcls(self.kind, self.gv_default)
class ArrayFieldDesc(FieldDesc):
+ allow_void = True
+
def __init__(self, RGenOp, TYPE):
assert isinstance(TYPE, lltype.Array)
FieldDesc.__init__(self, RGenOp, lltype.Ptr(TYPE), TYPE.OF)
Modified: pypy/branch/jit-real-world/pypy/jit/timeshifter/test/test_timeshift.py
==============================================================================
--- pypy/branch/jit-real-world/pypy/jit/timeshifter/test/test_timeshift.py (original)
+++ pypy/branch/jit-real-world/pypy/jit/timeshifter/test/test_timeshift.py Mon Dec 4 01:32:45 2006
@@ -681,6 +681,16 @@
res = self.timeshift(ll_function, [0], [])
assert res == 4 * 4
+ def test_degenerate_with_voids(self):
+ S = lltype.GcStruct('S', ('y', lltype.Void),
+ ('x', lltype.Signed))
+ def ll_function():
+ s = lltype.malloc(S)
+ s.x = 123
+ return s
+ res = self.timeshift(ll_function, [], [], policy=P_NOVIRTUAL)
+ assert res.x == 123
+
def test_plus_minus_all_inlined(self):
def ll_plus_minus(s, x, y):
acc = x
@@ -793,6 +803,20 @@
assert res == -42
self.check_insns(malloc_varsize=1)
+ def test_array_of_voids(self):
+ A = lltype.GcArray(lltype.Void)
+ def ll_function(n):
+ a = lltype.malloc(A, 3)
+ a[1] = None
+ b = a[n]
+ res = a, b
+ keepalive_until_here(b) # to keep getarrayitem around
+ return res
+
+ res = self.timeshift(ll_function, [2], [], policy=P_NOVIRTUAL)
+ assert lltype.typeOf(res.item0) == lltype.Ptr(A)
+ assert res.item1 is None
+
def test_red_propagate(self):
S = lltype.GcStruct('S', ('n', lltype.Signed))
def ll_function(n, k):
More information about the Pypy-commit
mailing list