Author: Carl Friedrich Bolz <[email protected]>
Branch: const-fold-we-are-jitted
Changeset: r86347:02fc2f32a831
Date: 2016-08-20 14:43 +0200
http://bitbucket.org/pypy/pypy/changeset/02fc2f32a831/
Log: add the corresponding code in all.py
diff --git a/rpython/config/translationoption.py
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -261,6 +261,9 @@
"stack based virtual machines (only for backends that
support it)",
default=True),
BoolOption("storesink", "Perform store sinking", default=True),
+ BoolOption("replace_we_are_jitted",
+ "Replace we_are_jitted() calls by False",
+ default=False, cmdline=None),
BoolOption("none",
"Do not run any backend optimizations",
requires=[('translation.backendopt.inline', False),
diff --git a/rpython/translator/backendopt/all.py
b/rpython/translator/backendopt/all.py
--- a/rpython/translator/backendopt/all.py
+++ b/rpython/translator/backendopt/all.py
@@ -2,6 +2,7 @@
from rpython.translator.backendopt import inline
from rpython.translator.backendopt.malloc import remove_mallocs
from rpython.translator.backendopt.constfold import constant_fold_graph
+from rpython.translator.backendopt.constfold import replace_we_are_jitted
from rpython.translator.backendopt.stat import print_statistics
from rpython.translator.backendopt.merge_if_blocks import merge_if_blocks
from rpython.translator import simplify
@@ -36,6 +37,7 @@
# inline_threshold, mallocs
# merge_if_blocks, constfold, heap2stack
# clever_malloc_removal, remove_asserts
+ # replace_we_are_jitted
config = translator.config.translation.backendopt.copy(as_default=True)
config.set(**kwds)
@@ -49,6 +51,10 @@
print "before optimizations:"
print_statistics(translator.graphs[0], translator, "per-graph.txt")
+ if config.replace_we_are_jitted:
+ for graph in graphs:
+ replace_we_are_jitted(graph)
+
if config.remove_asserts:
constfold(config, graphs)
remove_asserts(translator, graphs)
diff --git a/rpython/translator/backendopt/test/test_all.py
b/rpython/translator/backendopt/test/test_all.py
--- a/rpython/translator/backendopt/test/test_all.py
+++ b/rpython/translator/backendopt/test/test_all.py
@@ -289,3 +289,19 @@
llinterp = LLInterpreter(t.rtyper)
res = llinterp.eval_graph(later_graph, [10])
assert res == 1
+
+ def test_replace_we_are_jitted(self):
+ from rpython.rlib import jit
+ def f():
+ if jit.we_are_jitted():
+ return 1
+ return 2 + jit.we_are_jitted()
+
+ t = self.translateopt(f, [])
+ graph = graphof(t, f)
+ # by default, replace_we_are_jitted is off
+ assert graph.startblock.operations[0].args[0].value is
jit._we_are_jitted
+
+ t = self.translateopt(f, [], replace_we_are_jitted=True)
+ graph = graphof(t, f)
+ assert graph.startblock.exits[0].args[0].value == 2
diff --git a/rpython/translator/backendopt/test/test_constfold.py
b/rpython/translator/backendopt/test/test_constfold.py
--- a/rpython/translator/backendopt/test/test_constfold.py
+++ b/rpython/translator/backendopt/test/test_constfold.py
@@ -346,8 +346,6 @@
check_graph(graph, [], 66, t)
def test_replace_we_are_jitted():
- from rpython.flowspace import model
- from rpython.rtyper.lltypesystem import lltype
from rpython.rlib import jit
def fn():
if jit.we_are_jitted():
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit