Author: Richard Plangger <r...@pasra.at> Branch: vecopt2 Changeset: r77060:edcb3f85bb31 Date: 2015-03-04 11:49 +0100 http://bitbucket.org/pypy/pypy/changeset/edcb3f85bb31/
Log: added simple version that calcualtes the dependencies on a ssa trace. added test to check if label definition creates dependencies correctly diff --git a/rpython/jit/metainterp/optimizeopt/dependency.py b/rpython/jit/metainterp/optimizeopt/dependency.py --- a/rpython/jit/metainterp/optimizeopt/dependency.py +++ b/rpython/jit/metainterp/optimizeopt/dependency.py @@ -2,8 +2,9 @@ from rpython.jit.metainterp.resoperation import rop class Dependency(object): - def __init__(self, index): + def __init__(self, index, is_definition): self.index = index + self.is_definition = is_definition class CrossIterationDependency(Dependency): pass @@ -22,6 +23,35 @@ self.optimizer = optimizer self.adjacent_list = [ [] ] * len(self.operations) + self.build_dependencies(loop.operations) + + def build_dependencies(self, operations): + """ This is basically building the definition-use chain and saving this + information in a graph structure. This is the same as calculating + the reaching definitions and the 'looking back' whenever it is used. + """ + defining_indices = {} + + for i,op in enumerate(operations): + # the label operation defines all operations at the beginning of the loop + if op.getopnum() == rop.LABEL: + for arg in op.getarglist(): + defining_indices[arg] = 0 + + if op.result is not None: + # overwrites redefinition. This is not a problem + # if the trace is in SSA form. + defining_indices[op.result] = i + + for arg in op.getarglist(): + if arg in defining_indices: + idx = defining_indices[arg] + self._put_edge(idx, i) + + def _put_edge(self, idx_from, idx_to): + self.adjacent_list[idx_from].append(Dependency(idx_to, True)) + self.adjacent_list[idx_to].append(Dependency(idx_from, False)) + def instr_dependency(self, from_instr_idx, to_instr_idx): """ Does there exist a dependency from the instruction to another? Returns None if there is no dependency or the Dependency object in diff --git a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py --- a/rpython/jit/metainterp/optimizeopt/test/test_dependency.py +++ b/rpython/jit/metainterp/optimizeopt/test/test_dependency.py @@ -13,9 +13,9 @@ from rpython.jit.metainterp.resoperation import rop, ResOperation from rpython.rlib.rarithmetic import LONG_BIT -class BaseTestDependecyGraph(BaseTest): +class DepTestHelper(BaseTest): - enable_opts = "intbounds:rewrite:virtualize:string:earlyforce:pure:heap:vectorize" + enable_opts = "vectorize" def build_dependency(self, ops): loop = self.parse(ops, postprocess=self.postprocess) @@ -37,7 +37,7 @@ " %d depend on instr on index %d but it is not" \ % (from_instr_index, to_instr_index) -class TestDependencyGraph(BaseTestDependecyGraph): +class BaseTestDependencyGraph(DepTestHelper): def test_simple(self): ops = """ [] @@ -50,5 +50,17 @@ self.assert_def_use(dep_graph, 1, 2) self.assert_def_use(dep_graph, 2, 3) -class TestLLtype(TestDependencyGraph, LLtypeMixin): + def test_label_def(self): + ops = """ + [i3] + i1 = int_add(i3,1) + guard_value(i1,0) [] + jump(i1) + """ + dep_graph = self.build_dependency(ops) + self.assert_def_use(dep_graph, 0, 1) + self.assert_def_use(dep_graph, 1, 2) + self.assert_def_use(dep_graph, 1, 3) + +class TestLLtype(BaseTestDependencyGraph, LLtypeMixin): pass _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit