[pypy-svn] r18178 - in pypy/dist/pypy: rpython translator/backendopt translator/backendopt/test translator/c
pedronis at codespeak.net
pedronis at codespeak.net
Wed Oct 5 01:28:23 CEST 2005
Author: pedronis
Date: Wed Oct 5 01:28:19 2005
New Revision: 18178
Modified:
pypy/dist/pypy/rpython/llinterp.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/translator/backendopt/inline.py
pypy/dist/pypy/translator/backendopt/test/test_all.py
pypy/dist/pypy/translator/backendopt/test/test_propagate.py
pypy/dist/pypy/translator/c/funcgen.py
Log:
keepalive space op should take just one variable,
change inline to insert keepalive ops to preserve the lifetime properties
Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py (original)
+++ pypy/dist/pypy/rpython/llinterp.py Wed Oct 5 01:28:19 2005
@@ -259,7 +259,7 @@
# __________________________________________________________
# misc LL operation implementations
- def op_keepalive(self, *values):
+ def op_keepalive(self, value):
pass
def op_same_as(self, x):
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Wed Oct 5 01:28:19 2005
@@ -398,6 +398,8 @@
# keepalive
def rtype_keepalive(hop):
- return hop.genop('keepalive', hop.args_v, resulttype=lltype.Void)
+ for v in hop.args_v:
+ hop.genop('keepalive', hop.args_v, resulttype=lltype.Void)
+ return hop.inputconst(lltype.Void, None)
BUILTIN_TYPER[objectmodel.keepalive] = rtype_keepalive
Modified: pypy/dist/pypy/translator/backendopt/inline.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/inline.py (original)
+++ pypy/dist/pypy/translator/backendopt/inline.py Wed Oct 5 01:28:19 2005
@@ -6,7 +6,7 @@
from pypy.objspace.flow.model import SpaceOperation, last_exception
from pypy.objspace.flow.model import traverse, mkentrymap, checkgraph, flatten
from pypy.annotation import model as annmodel
-from pypy.rpython.lltype import Bool, typeOf
+from pypy.rpython.lltype import Bool, typeOf, Void
from pypy.rpython import rmodel
from pypy.tool.algo import sparsemat
from pypy.translator.backendopt.support import log
@@ -62,7 +62,7 @@
def _find_exception_type(block):
#XXX slightly brittle: find the exception type for simple cases
#(e.g. if you do only raise XXXError) by doing pattern matching
- ops = block.operations
+ ops = [op for op in block.operations if op.opname != 'keepalive']
if (len(ops) < 6 or
ops[-6].opname != "malloc" or ops[-5].opname != "cast_pointer" or
ops[-4].opname != "setfield" or ops[-3].opname != "cast_pointer" or
@@ -129,6 +129,14 @@
if hasattr(link, 'llexitcase'):
newlink.llexitcase = link.llexitcase
return newlink
+ def generate_keepalive(vars):
+ keepalive_ops = []
+ for v in vars:
+ v_keepalive = Variable()
+ v_keepalive.concretetype = Void
+ keepalive_ops.append(SpaceOperation('keepalive', [v], v_keepalive))
+ return keepalive_ops
+
linktoinlined = beforeblock.exits[0]
assert linktoinlined.target is afterblock
copiedstartblock = copy_block(graph_to_inline.startblock)
@@ -146,7 +154,7 @@
linktoinlined.target = copiedstartblock
linktoinlined.args = passon_args
afterblock.inputargs = [op.result] + afterblock.inputargs
- afterblock.operations = afterblock.operations[1:]
+ afterblock.operations = generate_keepalive(afterblock.inputargs) + afterblock.operations[1:]
if graph_to_inline.returnblock in entrymap:
copiedreturnblock = copied_blocks[graph_to_inline.returnblock]
linkfrominlined = Link([copiedreturnblock.inputargs[0]] + passon_vars[graph_to_inline.returnblock], afterblock)
@@ -193,6 +201,7 @@
#try to match the exceptions for simple cases
for link in entrymap[graph_to_inline.exceptblock]:
copiedblock = copied_blocks[link.prevblock]
+ copiedblock.operations += generate_keepalive(passon_vars[link.prevblock])
copiedlink = copiedblock.exits[0]
eclass = _find_exception_type(copiedblock)
#print copiedblock.operations
@@ -242,6 +251,7 @@
blocks[-1].exitswitch = None
linkargs = copiedexceptblock.inputargs
copiedexceptblock.closeblock(Link(linkargs, blocks[0]))
+ copiedexceptblock.operations += generate_keepalive(linkargs)
afterblock.exits = [afterblock.exits[0]]
afterblock.exitswitch = None
#cleaning up -- makes sense to be here, because I insert quite
Modified: pypy/dist/pypy/translator/backendopt/test/test_all.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_all.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_all.py Wed Oct 5 01:28:19 2005
@@ -90,7 +90,7 @@
res = interp.eval_function(f, [11, 22])
assert res == 33
-def inprogress_test_premature_death():
+def test_premature_death():
import os
from pypy.annotation import listdef
Modified: pypy/dist/pypy/translator/backendopt/test/test_propagate.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_propagate.py (original)
+++ pypy/dist/pypy/translator/backendopt/test/test_propagate.py Wed Oct 5 01:28:19 2005
@@ -66,7 +66,7 @@
graph, t = get_graph(g, [int])
while constant_folding(graph, t):
pass
- assert len(graph.startblock.operations) == 1
+ assert len(graph.startblock.operations) == 4
check_graph(graph, [10], g(10), t)
def test_fold_const_blocks():
@@ -82,7 +82,7 @@
graph, t = get_graph(g, [int])
partial_folding(graph, t)
constant_folding(graph, t)
- assert len(graph.startblock.operations) == 1
+ assert len(graph.startblock.operations) == 3
check_graph(graph, [10], g(10), t)
def getitem(l, i): #LookupError, KeyError
Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py (original)
+++ pypy/dist/pypy/translator/c/funcgen.py Wed Oct 5 01:28:19 2005
@@ -539,7 +539,7 @@
return '\t'.join(result)
def OP_KEEPALIVE(self, op, err): # xxx what should be the sematics consequences of this
- return "/* kept alive: %s */ ;" % ''.join([self.expr(v, special_case_void=False) for v in op.args])
+ return "/* kept alive: %s */ ;" % self.expr(op.args[0], special_case_void=False)
def pyobj_incref(self, v):
T = self.lltypemap(v)
More information about the Pypy-commit
mailing list