[pypy-commit] pypy stm-thread-2: External calls.
arigo
noreply at buildbot.pypy.org
Sun Sep 2 16:19:42 CEST 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm-thread-2
Changeset: r57082:c4fc5e3bae42
Date: 2012-09-02 16:19 +0200
http://bitbucket.org/pypy/pypy/changeset/c4fc5e3bae42/
Log: External calls.
diff --git a/pypy/translator/backendopt/writeanalyze.py b/pypy/translator/backendopt/writeanalyze.py
--- a/pypy/translator/backendopt/writeanalyze.py
+++ b/pypy/translator/backendopt/writeanalyze.py
@@ -1,6 +1,7 @@
from pypy.objspace.flow.model import Variable
from pypy.translator.backendopt import graphanalyze
from pypy.rpython.ootypesystem import ootype
+from pypy.translator.simplify import get_funcobj
top_set = object()
empty_set = frozenset()
@@ -42,7 +43,14 @@
def _array_result(self, TYPE):
return frozenset([("array", TYPE)])
+ def analyze_external_call(self, op, seen=None):
+ funcobj = get_funcobj(op.args[0].value)
+ if funcobj.random_effects_on_gcobjs:
+ return self.top_result()
+ return graphanalyze.GraphAnalyzer.analyze_external_call(self, op, seen)
+
def analyze_external_method(self, op, TYPE, meth):
+ # XXX random_effects_on_gcobjs
if isinstance(TYPE, ootype.Array):
methname = op.args[0].value
if methname == 'll_setitem_fast':
diff --git a/pypy/translator/stm/test/test_transform2.py b/pypy/translator/stm/test/test_transform2.py
--- a/pypy/translator/stm/test/test_transform2.py
+++ b/pypy/translator/stm/test/test_transform2.py
@@ -1,4 +1,4 @@
-from pypy.rpython.lltypesystem import lltype
+from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rpython.llinterp import LLFrame
from pypy.rpython.test.test_llinterp import get_interpreter, clear_tcache
from pypy.objspace.flow.model import Constant
@@ -181,3 +181,37 @@
res = self.interpret(f1, [x, y])
assert res == 36
assert self.barriers == ['P2R', 'P2W']
+
+ def test_call_external_random_effects(self):
+ X = lltype.GcStruct('X', ('foo', lltype.Signed))
+ external_stuff = rffi.llexternal('external_stuff', [], lltype.Void,
+ _callable=lambda: None,
+ random_effects_on_gcobjs=True,
+ threadsafe=False)
+ def f1(p):
+ x1 = p.foo
+ external_stuff()
+ x2 = p.foo
+ return x1 * x2
+
+ x = lltype.malloc(X, immortal=True); x.foo = 6
+ res = self.interpret(f1, [x])
+ assert res == 36
+ assert self.barriers == ['P2R', 'P2R']
+
+ def test_call_external_no_random_effects(self):
+ X = lltype.GcStruct('X', ('foo', lltype.Signed))
+ external_stuff = rffi.llexternal('external_stuff2', [], lltype.Void,
+ _callable=lambda: None,
+ random_effects_on_gcobjs=False,
+ threadsafe=False)
+ def f1(p):
+ x1 = p.foo
+ external_stuff()
+ x2 = p.foo
+ return x1 * x2
+
+ x = lltype.malloc(X, immortal=True); x.foo = 6
+ res = self.interpret(f1, [x])
+ assert res == 36
+ assert self.barriers == ['P2R']
More information about the pypy-commit
mailing list