Author: Maciej Fijalkowski <[email protected]>
Branch:
Changeset: r44971:f430562b29e8
Date: 2011-06-16 14:35 +0200
http://bitbucket.org/pypy/pypy/changeset/f430562b29e8/
Log: merge jitcounter-on-function, branch that always attempts to start
tracing from the beginning
diff --git a/pypy/jit/metainterp/test/test_ajit.py
b/pypy/jit/metainterp/test/test_ajit.py
--- a/pypy/jit/metainterp/test/test_ajit.py
+++ b/pypy/jit/metainterp/test/test_ajit.py
@@ -500,7 +500,7 @@
y -= x
return y
#
- res = self.meta_interp(f, [3, 6], repeat=7)
+ res = self.meta_interp(f, [3, 6], repeat=7, function_threshold=0)
assert res == 6 - 4 - 5
self.check_history(call=0) # because the trace starts in the middle
#
diff --git a/pypy/jit/metainterp/test/test_jitdriver.py
b/pypy/jit/metainterp/test/test_jitdriver.py
--- a/pypy/jit/metainterp/test/test_jitdriver.py
+++ b/pypy/jit/metainterp/test/test_jitdriver.py
@@ -113,6 +113,7 @@
return n
#
def loop2(g, r):
+ myjitdriver1.set_param('function_threshold', 0)
while r > 0:
myjitdriver2.can_enter_jit(g=g, r=r)
myjitdriver2.jit_merge_point(g=g, r=r)
diff --git a/pypy/jit/metainterp/test/test_recursive.py
b/pypy/jit/metainterp/test/test_recursive.py
--- a/pypy/jit/metainterp/test/test_recursive.py
+++ b/pypy/jit/metainterp/test/test_recursive.py
@@ -483,6 +483,7 @@
def main(inline):
myjitdriver.set_param("threshold", 10)
+ myjitdriver.set_param('function_threshold', 60)
if inline:
myjitdriver.set_param('inlining', True)
else:
@@ -1193,6 +1194,51 @@
i -= 1
self.meta_interp(portal, [0, 10], inline=True)
+ def test_trace_from_start_always(self):
+ from pypy.rlib.nonconst import NonConstant
+
+ driver = JitDriver(greens = ['c'], reds = ['i', 'v'])
+
+ def portal(c, i, v):
+ while i > 0:
+ driver.jit_merge_point(c=c, i=i, v=v)
+ portal(c, i - 1, v)
+ if v:
+ driver.can_enter_jit(c=c, i=i, v=v)
+ break
+
+ def main(c, i, set_param, v):
+ if set_param:
+ driver.set_param('function_threshold', 0)
+ portal(c, i, v)
+
+ self.meta_interp(main, [10, 10, False, False], inline=True)
+ self.check_tree_loop_count(1)
+ self.check_loop_count(0)
+ self.meta_interp(main, [3, 10, True, False], inline=True)
+ self.check_tree_loop_count(0)
+ self.check_loop_count(0)
+
+ def test_trace_from_start_does_not_prevent_inlining(self):
+ driver = JitDriver(greens = ['c', 'bc'], reds = ['i'])
+
+ def portal(bc, c, i):
+ while True:
+ driver.jit_merge_point(c=c, bc=bc, i=i)
+ if bc == 0:
+ portal(1, 8, 0)
+ c += 1
+ else:
+ return
+ if c == 10: # bc == 0
+ c = 0
+ if i >= 100:
+ return
+ driver.can_enter_jit(c=c, bc=bc, i=i)
+ i += 1
+
+ self.meta_interp(portal, [0, 0, 0], inline=True)
+ self.check_loops(call=0, call_may_force=0)
class TestLLtype(RecursiveTests, LLJitMixin):
pass
diff --git a/pypy/jit/metainterp/warmspot.py b/pypy/jit/metainterp/warmspot.py
--- a/pypy/jit/metainterp/warmspot.py
+++ b/pypy/jit/metainterp/warmspot.py
@@ -66,6 +66,7 @@
def jittify_and_run(interp, graph, args, repeat=1,
backendopt=False, trace_limit=sys.maxint,
inline=False, loop_longevity=0, retrace_limit=5,
+ function_threshold=4,
enable_opts=ALL_OPTS_NAMES, **kwds):
from pypy.config.config import ConfigError
translator = interp.typer.annotator.translator
@@ -80,6 +81,7 @@
warmrunnerdesc = WarmRunnerDesc(translator, backendopt=backendopt, **kwds)
for jd in warmrunnerdesc.jitdrivers_sd:
jd.warmstate.set_param_threshold(3) # for tests
+ jd.warmstate.set_param_function_threshold(function_threshold)
jd.warmstate.set_param_trace_eagerness(2) # for tests
jd.warmstate.set_param_trace_limit(trace_limit)
jd.warmstate.set_param_inlining(inline)
@@ -422,7 +424,7 @@
if self.translator.rtyper.type_system.name == 'lltypesystem':
def maybe_enter_jit(*args):
try:
- maybe_compile_and_run(*args)
+ maybe_compile_and_run(state.increment_threshold, *args)
except JitException:
raise # go through
except Exception, e:
@@ -430,15 +432,13 @@
maybe_enter_jit._always_inline_ = True
else:
def maybe_enter_jit(*args):
- maybe_compile_and_run(*args)
+ maybe_compile_and_run(state.increment_threshold, *args)
maybe_enter_jit._always_inline_ = True
jd._maybe_enter_jit_fn = maybe_enter_jit
- can_inline = state.can_inline_greenargs
num_green_args = jd.num_green_args
def maybe_enter_from_start(*args):
- if not can_inline(*args[:num_green_args]):
- maybe_compile_and_run(*args)
+ maybe_compile_and_run(state.increment_function_threshold, *args)
maybe_enter_from_start._always_inline_ = True
jd._maybe_enter_from_start_fn = maybe_enter_from_start
diff --git a/pypy/jit/metainterp/warmstate.py b/pypy/jit/metainterp/warmstate.py
--- a/pypy/jit/metainterp/warmstate.py
+++ b/pypy/jit/metainterp/warmstate.py
@@ -208,15 +208,20 @@
meth = getattr(self, 'set_param_' + name)
meth(default_value)
- def set_param_threshold(self, threshold):
+ def _compute_threshold(self, threshold):
if threshold <= 0:
- self.increment_threshold = 0 # never reach the THRESHOLD_LIMIT
- return
+ return 0 # never reach the THRESHOLD_LIMIT
if threshold < 2:
threshold = 2
- self.increment_threshold = (self.THRESHOLD_LIMIT // threshold) + 1
+ return (self.THRESHOLD_LIMIT // threshold) + 1
# the number is at least 1, and at most about half THRESHOLD_LIMIT
+ def set_param_threshold(self, threshold):
+ self.increment_threshold = self._compute_threshold(threshold)
+
+ def set_param_function_threshold(self, threshold):
+ self.increment_function_threshold = self._compute_threshold(threshold)
+
def set_param_trace_eagerness(self, value):
self.trace_eagerness = value
@@ -291,7 +296,7 @@
self.make_jitdriver_callbacks()
confirm_enter_jit = self.confirm_enter_jit
- def maybe_compile_and_run(*args):
+ def maybe_compile_and_run(threshold, *args):
"""Entry point to the JIT. Called at the point with the
can_enter_jit() hint.
"""
@@ -307,7 +312,7 @@
if cell.counter >= 0:
# update the profiling counter
- n = cell.counter + self.increment_threshold
+ n = cell.counter + threshold
if n <= self.THRESHOLD_LIMIT: # bound not reached
cell.counter = n
return
diff --git a/pypy/rlib/jit.py b/pypy/rlib/jit.py
--- a/pypy/rlib/jit.py
+++ b/pypy/rlib/jit.py
@@ -274,6 +274,7 @@
"""Inconsistency in the JIT hints."""
PARAMETERS = {'threshold': 1000,
+ 'function_threshold': 1000,
'trace_eagerness': 200,
'trace_limit': 12000,
'inlining': 0,
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit