[pypy-commit] pypy stm: (antocuni, arigo)
arigo
noreply at buildbot.pypy.org
Mon Jan 16 14:59:36 CET 2012
Author: Armin Rigo <arigo at tunes.org>
Branch: stm
Changeset: r51343:2965c13c2427
Date: 2012-01-16 14:59 +0100
http://bitbucket.org/pypy/pypy/changeset/2965c13c2427/
Log: (antocuni, arigo)
Start to refactor the world. The idea is not to build on RPython
threads any more.
diff --git a/pypy/rpython/lltypesystem/lloperation.py b/pypy/rpython/lltypesystem/lloperation.py
--- a/pypy/rpython/lltypesystem/lloperation.py
+++ b/pypy/rpython/lltypesystem/lloperation.py
@@ -401,13 +401,7 @@
'stm_setarrayitem': LLOp(),
'stm_getinteriorfield': LLOp(sideeffects=False, canrun=True),
'stm_setinteriorfield': LLOp(),
-
- 'stm_begin_transaction': LLOp(),
- 'stm_commit_transaction': LLOp(),
- 'stm_begin_inevitable_transaction': LLOp(),
- 'stm_transaction_boundary': LLOp(),
- 'stm_declare_variable': LLOp(),
- 'stm_try_inevitable': LLOp(),
+ 'stm_become_inevitable':LLOp(),
# __________ address operations __________
diff --git a/pypy/translator/c/funcgen.py b/pypy/translator/c/funcgen.py
--- a/pypy/translator/c/funcgen.py
+++ b/pypy/translator/c/funcgen.py
@@ -227,6 +227,7 @@
yield '\treturn NULL;'
yield '}'
if self.exception_policy == "stm":
+ xxxx
yield 'STM_MAKE_INEVITABLE();'
retval = self.expr(block.inputargs[0])
if self.exception_policy != "exc_helper":
@@ -608,12 +609,6 @@
OP_STM_SETARRAYITEM = _OP_STM
OP_STM_GETINTERIORFIELD = _OP_STM
OP_STM_SETINTERIORFIELD = _OP_STM
- OP_STM_BEGIN_TRANSACTION = _OP_STM
- OP_STM_COMMIT_TRANSACTION = _OP_STM
- OP_STM_BEGIN_INEVITABLE_TRANSACTION = _OP_STM
- OP_STM_TRANSACTION_BOUNDARY = _OP_STM
- OP_STM_DECLARE_VARIABLE = _OP_STM
- OP_STM_TRY_INEVITABLE = _OP_STM
def OP_PTR_NONZERO(self, op):
diff --git a/pypy/translator/c/genc.py b/pypy/translator/c/genc.py
--- a/pypy/translator/c/genc.py
+++ b/pypy/translator/c/genc.py
@@ -134,7 +134,7 @@
if self.config.translation.stm:
from pypy.translator.stm import transform
transformer = transform.STMTransformer(self.translator)
- transformer.transform(self.getentrypointptr())
+ transformer.transform()
log.info("Software Transactional Memory transformation applied")
gcpolicyclass = self.get_gcpolicyclass()
diff --git a/pypy/translator/stm/_rffi_stm.py b/pypy/translator/stm/_rffi_stm.py
--- a/pypy/translator/stm/_rffi_stm.py
+++ b/pypy/translator/stm/_rffi_stm.py
@@ -26,16 +26,16 @@
descriptor_init = llexternal('stm_descriptor_init', [], lltype.Void)
descriptor_done = llexternal('stm_descriptor_done', [], lltype.Void)
-begin_transaction = llexternal('STM_begin_transaction', [], lltype.Void)
-begin_inevitable_transaction = llexternal('stm_begin_inevitable_transaction',
- [], lltype.Void)
-commit_transaction = llexternal('stm_commit_transaction', [], lltype.Signed)
+##begin_transaction = llexternal('STM_begin_transaction', [], lltype.Void)
+##begin_inevitable_transaction = llexternal('stm_begin_inevitable_transaction',
+## [], lltype.Void)
+##commit_transaction = llexternal('stm_commit_transaction', [], lltype.Signed)
try_inevitable = llexternal('stm_try_inevitable', [], lltype.Void)
-descriptor_init_and_being_inevitable_transaction = llexternal(
- 'stm_descriptor_init_and_being_inevitable_transaction', [], lltype.Void)
-commit_transaction_and_descriptor_done = llexternal(
- 'stm_commit_transaction_and_descriptor_done', [], lltype.Void)
+##descriptor_init_and_being_inevitable_transaction = llexternal(
+## 'stm_descriptor_init_and_being_inevitable_transaction', [], lltype.Void)
+##commit_transaction_and_descriptor_done = llexternal(
+## 'stm_commit_transaction_and_descriptor_done', [], lltype.Void)
stm_read_word = llexternal('stm_read_word', [SignedP], lltype.Signed)
stm_write_word = llexternal('stm_write_word', [SignedP, lltype.Signed],
diff --git a/pypy/translator/stm/funcgen.py b/pypy/translator/stm/funcgen.py
--- a/pypy/translator/stm/funcgen.py
+++ b/pypy/translator/stm/funcgen.py
@@ -1,7 +1,7 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.objspace.flow.model import Constant
from pypy.translator.c.support import cdecl, c_string_constant
-from pypy.translator.stm.rstm import size_of_voidp
+from pypy.translator.stm.llstm import size_of_voidp
def _stm_generic_get(funcgen, op, expr, simple_struct=False):
diff --git a/pypy/translator/stm/rstm.py b/pypy/translator/stm/llstm.py
rename from pypy/translator/stm/rstm.py
rename to pypy/translator/stm/llstm.py
--- a/pypy/translator/stm/rstm.py
+++ b/pypy/translator/stm/llstm.py
@@ -1,11 +1,20 @@
+"""
+This file is mostly here for testing. Usually, transform.py will transform
+the getfields (etc) that occur in the graphs directly into stm_getfields,
+which are operations that are recognized by the C backend. See funcgen.py
+which contains similar logic, which is run by the C backend.
+"""
import sys
-from pypy.rpython.lltypesystem import lltype, rffi
+from pypy.rpython.lltypesystem import lltype, rffi, rclass
from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.translator.stm import _rffi_stm
from pypy.annotation import model as annmodel
from pypy.objspace.flow.model import Constant
from pypy.rlib.rarithmetic import r_uint, r_ulonglong
from pypy.rlib import longlong2float
+from pypy.rlib.objectmodel import specialize
+from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
+from pypy.rpython.annlowlevel import cast_base_ptr_to_instance
size_of_voidp = rffi.sizeof(rffi.VOIDP)
assert size_of_voidp & (size_of_voidp - 1) == 0
@@ -83,21 +92,9 @@
"NOT_RPYTHON"
raise NotImplementedError("sorry")
-def begin_transaction():
- "NOT_RPYTHON. For tests only"
- raise NotImplementedError("hard to really emulate")
-
-def commit_transaction():
- "NOT_RPYTHON. For tests only"
- raise NotImplementedError("hard to really emulate")
-
-def begin_inevitable_transaction():
- "NOT_RPYTHON. For tests only, and at start up, but not in normal code."
- raise NotImplementedError("hard to really emulate")
-
-def transaction_boundary():
- "NOT_RPYTHON. This is the one normally used"
- raise NotImplementedError("hard to really emulate")
+##def stm_setarrayitem(arrayptr, index, value):
+## "NOT_RPYTHON"
+## raise NotImplementedError("sorry")
# ____________________________________________________________
@@ -149,13 +146,13 @@
resulttype = hop.r_result)
-class ExtEntry(ExtRegistryEntry):
- _about_ = (begin_transaction, commit_transaction,
- begin_inevitable_transaction, transaction_boundary)
+##class ExtEntry(ExtRegistryEntry):
+## _about_ = (begin_transaction, commit_transaction,
+## begin_inevitable_transaction, transaction_boundary)
- def compute_result_annotation(self):
- return None
+## def compute_result_annotation(self):
+## return None
- def specialize_call(self, hop):
- hop.exception_cannot_occur()
- hop.genop("stm_" + self.instance.__name__, [])
+## def specialize_call(self, hop):
+## hop.exception_cannot_occur()
+## hop.genop("stm_" + self.instance.__name__, [])
diff --git a/pypy/translator/stm/llstminterp.py b/pypy/translator/stm/llstminterp.py
--- a/pypy/translator/stm/llstminterp.py
+++ b/pypy/translator/stm/llstminterp.py
@@ -1,6 +1,6 @@
from pypy.rpython.lltypesystem import lltype
from pypy.rpython.llinterp import LLFrame, LLException
-from pypy.translator.stm import rstm
+##from pypy.translator.stm import rstm
from pypy.translator.stm.transform import op_in_set, ALWAYS_ALLOW_OPERATIONS
diff --git a/pypy/translator/stm/src_stm/et.c b/pypy/translator/stm/src_stm/et.c
--- a/pypy/translator/stm/src_stm/et.c
+++ b/pypy/translator/stm/src_stm/et.c
@@ -515,6 +515,8 @@
long stm_read_word(long* addr)
{
struct tx_descriptor *d = thread_descriptor;
+ if (!d)
+ return *addr;
#ifdef RPY_STM_ASSERT
assert(d->transaction_active);
#endif
@@ -579,6 +581,11 @@
void stm_write_word(long* addr, long val)
{
struct tx_descriptor *d = thread_descriptor;
+ if (!d)
+ {
+ *addr = val;
+ return;
+ }
#ifdef RPY_STM_ASSERT
assert(d->transaction_active);
#endif
diff --git a/pypy/translator/stm/test/test_funcgen.py b/pypy/translator/stm/test/test_funcgen.py
--- a/pypy/translator/stm/test/test_funcgen.py
+++ b/pypy/translator/stm/test/test_funcgen.py
@@ -1,9 +1,55 @@
from pypy.rpython.lltypesystem import lltype, rffi
from pypy.rlib.rarithmetic import r_longlong, r_singlefloat
from pypy.translator.stm.test.test_transform import CompiledSTMTests
-from pypy.translator.stm import rstm
+#from pypy.rlib import rstm
+from pypy.translator.c.test.test_standalone import StandaloneTests
+from pypy.rlib.debug import debug_print
+class TestRStm(object):
+
+ def compile(self, entry_point):
+ from pypy.translator.translator import TranslationContext
+ from pypy.annotation.listdef import s_list_of_strings
+ from pypy.translator.c.genc import CStandaloneBuilder
+ from pypy.translator.tool.cbuild import ExternalCompilationInfo
+ t = TranslationContext()
+ t.config.translation.gc = 'boehm'
+ t.buildannotator().build_types(entry_point, [s_list_of_strings])
+ t.buildrtyper().specialize()
+ t.stm_transformation_applied = True # not really, but for these tests
+ cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+ force_debug = ExternalCompilationInfo(pre_include_bits=[
+ "#define RPY_ASSERT 1\n"
+ "#define RPY_LL_ASSERT 1\n"
+ ])
+ cbuilder.eci = cbuilder.eci.merge(force_debug)
+ cbuilder.generate_source()
+ cbuilder.compile()
+ return t, cbuilder
+
+ def test_compiled_stm_getfield(self):
+ from pypy.translator.stm.test import test_llstm
+ def entry_point(argv):
+ test_llstm.test_stm_getfield()
+ debug_print('ok!')
+ return 0
+ t, cbuilder = self.compile(entry_point)
+ _, data = cbuilder.cmdexec('', err=True)
+ assert data.endswith('ok!\n')
+
+ def test_compiled_stm_setfield(self):
+ from pypy.translator.stm.test import test_llstm
+ def entry_point(argv):
+ test_llstm.test_stm_setfield()
+ debug_print('ok!')
+ return 0
+ t, cbuilder = self.compile(entry_point)
+ _, data = cbuilder.cmdexec('', err=True)
+ assert data.endswith('ok!\n')
+
+# ____________________________________________________________
+
A = lltype.GcStruct('A', ('x', lltype.Signed), ('y', lltype.Signed),
('c1', lltype.Char), ('c2', lltype.Char),
('c3', lltype.Char), ('l', lltype.SignedLongLong),
diff --git a/pypy/translator/stm/test/test_rstm.py b/pypy/translator/stm/test/test_llstm.py
rename from pypy/translator/stm/test/test_rstm.py
rename to pypy/translator/stm/test/test_llstm.py
--- a/pypy/translator/stm/test/test_rstm.py
+++ b/pypy/translator/stm/test/test_llstm.py
@@ -1,9 +1,8 @@
import py
from pypy.translator.stm._rffi_stm import *
-from pypy.translator.stm.rstm import *
+from pypy.translator.stm.llstm import *
from pypy.rpython.annlowlevel import llhelper
from pypy.rlib.rarithmetic import r_longlong, r_singlefloat
-from pypy.rlib.debug import debug_print
A = lltype.Struct('A', ('x', lltype.Signed), ('y', lltype.Signed),
@@ -146,50 +145,3 @@
assert float(a.sb) == float(rs2b)
assert a.y == 10
lltype.free(a, flavor='raw')
-
-# ____________________________________________________________
-
-from pypy.translator.translator import TranslationContext
-from pypy.annotation.listdef import s_list_of_strings
-from pypy.translator.c.genc import CStandaloneBuilder
-from pypy.translator.tool.cbuild import ExternalCompilationInfo
-
-class StmTests(object):
- config = None
-
- def compile(self, entry_point):
- t = TranslationContext(self.config)
- t.config.translation.gc = 'boehm'
- t.buildannotator().build_types(entry_point, [s_list_of_strings])
- t.buildrtyper().specialize()
- t.stm_transformation_applied = True # not really, but for these tests
- cbuilder = CStandaloneBuilder(t, entry_point, t.config)
- force_debug = ExternalCompilationInfo(pre_include_bits=[
- "#define RPY_ASSERT 1\n"
- "#define RPY_LL_ASSERT 1\n"
- ])
- cbuilder.eci = cbuilder.eci.merge(force_debug)
- cbuilder.generate_source()
- cbuilder.compile()
- return t, cbuilder
-
-
-class TestRStm(StmTests):
-
- def test_compiled_stm_getfield(self):
- def entry_point(argv):
- test_stm_getfield()
- debug_print('ok!')
- return 0
- t, cbuilder = self.compile(entry_point)
- _, data = cbuilder.cmdexec('', err=True)
- assert data.endswith('ok!\n')
-
- def test_compiled_stm_setfield(self):
- def entry_point(argv):
- test_stm_setfield()
- debug_print('ok!')
- return 0
- t, cbuilder = self.compile(entry_point)
- _, data = cbuilder.cmdexec('', err=True)
- assert data.endswith('ok!\n')
diff --git a/pypy/translator/stm/test/test_transform.py b/pypy/translator/stm/test/test_transform.py
--- a/pypy/translator/stm/test/test_transform.py
+++ b/pypy/translator/stm/test/test_transform.py
@@ -3,7 +3,7 @@
from pypy.objspace.flow.model import summary
from pypy.translator.stm.llstminterp import eval_stm_graph
from pypy.translator.stm.transform import transform_graph
-from pypy.translator.stm import rstm
+##from pypy.translator.stm import rstm
from pypy.translator.c.test.test_standalone import StandaloneTests
from pypy.rlib.debug import debug_print
from pypy.conftest import option
@@ -198,7 +198,7 @@
try:
res = StandaloneTests.compile(self, entry_point, debug=True)
finally:
- del RaiseAnalyzer.fail_on_unknown_operation
+ RaiseAnalyzer.fail_on_unknown_operation = False
return res
diff --git a/pypy/translator/stm/transform.py b/pypy/translator/stm/transform.py
--- a/pypy/translator/stm/transform.py
+++ b/pypy/translator/stm/transform.py
@@ -23,18 +23,18 @@
def __init__(self, translator=None):
self.translator = translator
- def transform(self, entrypointptr):
+ def transform(self): ##, entrypointptr):
assert not hasattr(self.translator, 'stm_transformation_applied')
- entrypointgraph = entrypointptr._obj.graph
+## entrypointgraph = entrypointptr._obj.graph
for graph in self.translator.graphs:
- self.seen_transaction_boundary = False
- self.seen_gc_stack_bottom = False
+## self.seen_transaction_boundary = False
+## self.seen_gc_stack_bottom = False
self.transform_graph(graph)
- if self.seen_transaction_boundary:
- self.add_stm_declare_variable(graph)
- if self.seen_gc_stack_bottom:
- self.add_descriptor_init_stuff(graph)
- self.add_descriptor_init_stuff(entrypointgraph, main=True)
+## if self.seen_transaction_boundary:
+## self.add_stm_declare_variable(graph)
+## if self.seen_gc_stack_bottom:
+## self.add_descriptor_init_stuff(graph)
+## self.add_descriptor_init_stuff(entrypointgraph, main=True)
self.translator.stm_transformation_applied = True
def transform_block(self, block):
@@ -68,42 +68,42 @@
for block in graph.iterblocks():
self.transform_block(block)
- def add_descriptor_init_stuff(self, graph, main=False):
- if main:
- self._add_calls_around(graph,
- _rffi_stm.begin_inevitable_transaction,
- _rffi_stm.commit_transaction)
- self._add_calls_around(graph,
- _rffi_stm.descriptor_init,
- _rffi_stm.descriptor_done)
+## def add_descriptor_init_stuff(self, graph, main=False):
+## if main:
+## self._add_calls_around(graph,
+## _rffi_stm.begin_inevitable_transaction,
+## _rffi_stm.commit_transaction)
+## self._add_calls_around(graph,
+## _rffi_stm.descriptor_init,
+## _rffi_stm.descriptor_done)
- def _add_calls_around(self, graph, f_init, f_done):
- c_init = Constant(f_init, lltype.typeOf(f_init))
- c_done = Constant(f_done, lltype.typeOf(f_done))
- #
- block = graph.startblock
- v = varoftype(lltype.Void)
- op = SpaceOperation('direct_call', [c_init], v)
- block.operations.insert(0, op)
- #
- v = copyvar(self.translator.annotator, graph.getreturnvar())
- extrablock = Block([v])
- v_none = varoftype(lltype.Void)
- newop = SpaceOperation('direct_call', [c_done], v_none)
- extrablock.operations = [newop]
- extrablock.closeblock(Link([v], graph.returnblock))
- for block in graph.iterblocks():
- if block is not extrablock:
- for link in block.exits:
- if link.target is graph.returnblock:
- link.target = extrablock
- checkgraph(graph)
+## def _add_calls_around(self, graph, f_init, f_done):
+## c_init = Constant(f_init, lltype.typeOf(f_init))
+## c_done = Constant(f_done, lltype.typeOf(f_done))
+## #
+## block = graph.startblock
+## v = varoftype(lltype.Void)
+## op = SpaceOperation('direct_call', [c_init], v)
+## block.operations.insert(0, op)
+## #
+## v = copyvar(self.translator.annotator, graph.getreturnvar())
+## extrablock = Block([v])
+## v_none = varoftype(lltype.Void)
+## newop = SpaceOperation('direct_call', [c_done], v_none)
+## extrablock.operations = [newop]
+## extrablock.closeblock(Link([v], graph.returnblock))
+## for block in graph.iterblocks():
+## if block is not extrablock:
+## for link in block.exits:
+## if link.target is graph.returnblock:
+## link.target = extrablock
+## checkgraph(graph)
- def add_stm_declare_variable(self, graph):
- block = graph.startblock
- v = varoftype(lltype.Void)
- op = SpaceOperation('stm_declare_variable', [], v)
- block.operations.insert(0, op)
+## def add_stm_declare_variable(self, graph):
+## block = graph.startblock
+## v = varoftype(lltype.Void)
+## op = SpaceOperation('stm_declare_variable', [], v)
+## block.operations.insert(0, op)
# ----------
@@ -173,22 +173,22 @@
op1 = SpaceOperation('stm_setinteriorfield', op.args, op.result)
newoperations.append(op1)
- def stt_stm_transaction_boundary(self, newoperations, op):
- self.seen_transaction_boundary = True
- v_result = op.result
- # record in op.args the list of variables that are alive across
- # this call
- block = self.current_block
- vars = set()
- for op in block.operations[:self.current_op_index:-1]:
- vars.discard(op.result)
- vars.update(op.args)
- for link in block.exits:
- vars.update(link.args)
- vars.update(link.getextravars())
- livevars = [v for v in vars if isinstance(v, Variable)]
- newop = SpaceOperation('stm_transaction_boundary', livevars, v_result)
- newoperations.append(newop)
+## def stt_stm_transaction_boundary(self, newoperations, op):
+## self.seen_transaction_boundary = True
+## v_result = op.result
+## # record in op.args the list of variables that are alive across
+## # this call
+## block = self.current_block
+## vars = set()
+## for op in block.operations[:self.current_op_index:-1]:
+## vars.discard(op.result)
+## vars.update(op.args)
+## for link in block.exits:
+## vars.update(link.args)
+## vars.update(link.getextravars())
+## livevars = [v for v in vars if isinstance(v, Variable)]
+## newop = SpaceOperation('stm_transaction_boundary', livevars, v_result)
+## newoperations.append(newop)
def stt_malloc(self, newoperations, op):
flags = op.args[1].value
@@ -199,7 +199,7 @@
return flags['flavor'] == 'gc'
def stt_gc_stack_bottom(self, newoperations, op):
- self.seen_gc_stack_bottom = True
+## self.seen_gc_stack_bottom = True
newoperations.append(op)
@@ -210,7 +210,7 @@
def turn_inevitable(newoperations, info):
c_info = Constant(info, lltype.Void)
- op1 = SpaceOperation('stm_try_inevitable', [c_info],
+ op1 = SpaceOperation('stm_become_inevitable', [c_info],
varoftype(lltype.Void))
newoperations.append(op1)
More information about the pypy-commit
mailing list