[pypy-svn] r52361 - in pypy/branch/jit-hotpath/pypy/jit/hintannotator: . test
arigo at codespeak.net
arigo at codespeak.net
Mon Mar 10 17:27:50 CET 2008
Author: arigo
Date: Mon Mar 10 17:27:49 2008
New Revision: 52361
Added:
pypy/branch/jit-hotpath/pypy/jit/hintannotator/hotpath.py (contents, props changed)
pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py (contents, props changed)
Modified:
pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py
pypy/branch/jit-hotpath/pypy/jit/hintannotator/policy.py
pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_annotator.py
Log:
The "hotpath" hint-annotation policy, creating a hint-annotated
graph that starts directly at the global_merge_point.
Added: pypy/branch/jit-hotpath/pypy/jit/hintannotator/hotpath.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/hotpath.py Mon Mar 10 17:27:49 2008
@@ -0,0 +1,47 @@
+from pypy.objspace.flow.model import copygraph
+from pypy.translator.unsimplify import split_block
+from pypy.jit.hintannotator.annotator import HintAnnotator
+from pypy.jit.hintannotator.model import SomeLLAbstractConstant, OriginFlags
+
+
+class HotPathHintAnnotator(HintAnnotator):
+
+ def find_global_merge_point(self, graph):
+ found_at = []
+ for block in graph.iterblocks():
+ for op in block.operations:
+ if op.opname == 'hint':
+ hints = op.args[1].value
+ if hints.get('global_merge_point'):
+ found_at.append((graph, block, op))
+ if len(found_at) > 1:
+ raise Exception("multiple global_merge_point not supported")
+ if found_at:
+ return found_at[0]
+ else:
+ return None
+
+ def build_hotpath_types(self):
+ # find the graph with the global_merge_point
+ found_at = []
+ for graph in self.base_translator.graphs:
+ place = self.find_global_merge_point(graph)
+ if place is not None:
+ found_at.append(place)
+ if len(found_at) != 1:
+ raise Exception("found %d graphs with a global_merge_point,"
+ " expected 1 (for now)" % len(found_at))
+ portalgraph, _, _ = found_at[0]
+ # make a copy of the portalgraph before mutating it
+ portalgraph = copygraph(portalgraph)
+ _, portalblock, portalop = self.find_global_merge_point(portalgraph)
+ portalopindex = portalblock.operations.index(portalop)
+ # split the block across the global_merge_point
+ link = split_block(None, portalblock, portalopindex)
+ # rewire the graph to start at the global_merge_point
+ portalgraph.startblock = link.target
+ self.portalgraph = portalgraph
+ input_args_hs = [SomeLLAbstractConstant(v.concretetype,
+ {OriginFlags(): True})
+ for v in portalgraph.getargs()]
+ return self.build_types(portalgraph, input_args_hs)
Modified: pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/model.py Mon Mar 10 17:27:49 2008
@@ -348,7 +348,7 @@
hs_clone.deepfrozen = True
return hs_clone
for name in ["reverse_split_queue", "global_merge_point",
- "access_directly"]:
+ "access_directly", "can_enter_jit"]:
if hs_flags.const.get(name, False):
return
Modified: pypy/branch/jit-hotpath/pypy/jit/hintannotator/policy.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/hintannotator/policy.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/policy.py Mon Mar 10 17:27:49 2008
@@ -6,16 +6,20 @@
novirtualcontainer = False
oopspec = False
entrypoint_returns_red = True
+ hotpath = False
def __init__(self, novirtualcontainer = None,
oopspec = None,
- entrypoint_returns_red = None):
+ entrypoint_returns_red = None,
+ hotpath = None):
if novirtualcontainer is not None:
self.novirtualcontainer = novirtualcontainer
if oopspec is not None:
self.oopspec = oopspec
if entrypoint_returns_red is not None:
self.entrypoint_returns_red = entrypoint_returns_red
+ if hotpath is not None:
+ self.hotpath = hotpath
def look_inside_graph(self, graph):
return True
Modified: pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_annotator.py
==============================================================================
--- pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_annotator.py (original)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_annotator.py Mon Mar 10 17:27:49 2008
@@ -72,10 +72,16 @@
# build hint annotator types
policy = self.fixpolicy(policy)
- hannotator = HintAnnotator(base_translator=t, policy=policy)
- hs = hannotator.build_types(graph1, [SomeLLAbstractConstant(v.concretetype,
- {OriginFlags(): True})
- for v in graph1.getargs()])
+ if policy.hotpath:
+ from pypy.jit.hintannotator.hotpath import HotPathHintAnnotator
+ hannotator = HotPathHintAnnotator(base_translator=t, policy=policy)
+ self.hannotator = hannotator
+ hs = hannotator.build_hotpath_types()
+ else:
+ hannotator = HintAnnotator(base_translator=t, policy=policy)
+ hs = hannotator.build_types(graph1,
+ [SomeLLAbstractConstant(v.concretetype, {OriginFlags(): True})
+ for v in graph1.getargs()])
hannotator.simplify()
t = hannotator.translator
if conftest.option.view:
Added: pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-hotpath/pypy/jit/hintannotator/test/test_hotpath.py Mon Mar 10 17:27:49 2008
@@ -0,0 +1,38 @@
+from pypy.objspace.flow.model import summary
+from pypy.rlib.jit import hint, we_are_jitted
+from pypy.jit.hintannotator.policy import HintAnnotatorPolicy
+from pypy.jit.hintannotator.test.test_annotator import AbstractAnnotatorTest
+
+
+P_HOTPATH = HintAnnotatorPolicy(oopspec=True,
+ novirtualcontainer=True,
+ hotpath=True)
+
+class TestHotPath(AbstractAnnotatorTest):
+ type_system = 'lltype'
+
+ def hannotate(self, func, argtypes, policy=P_HOTPATH):
+ # change default policy
+ AbstractAnnotatorTest.hannotate(self, func, argtypes, policy=policy)
+
+ def test_simple_loop(self):
+ def ll_function(n):
+ n1 = n * 2
+ total = 0
+ while n1 > 0:
+ hint(None, can_enter_jit=True)
+ hint(None, global_merge_point=True)
+ if we_are_jitted():
+ total += 1000
+ total += n1
+ n1 -= 1
+ return total
+
+ def main(n, m):
+ return ll_function(n * m)
+
+ self.hannotate(main, [int, int])
+ graphs = self.hannotator.translator.graphs
+ assert len(graphs) == 1
+ assert ll_function is graphs[0].func
+ assert 'int_mul' not in summary(graphs[0])
More information about the Pypy-commit
mailing list