예제 #1
0
파일: regalloc.py 프로젝트: sbw111/lab4
 def make_dependencies(self):
     dg = DependencyGraph()
     for block in self.graph.iterblocks():
         # Compute die_at = {Variable: index_of_operation_with_last_usage}
         die_at = dict.fromkeys(block.inputargs, 0)
         for i, op in enumerate(block.operations):
             for v in op.args:
                 if isinstance(v, Variable):
                     die_at[v] = i
                 elif isinstance(v, self.ListOfKind):
                     for v1 in v:
                         if isinstance(v1, Variable):
                             die_at[v1] = i
             if op.result is not None:
                 die_at[op.result] = i + 1
         if isinstance(block.exitswitch, tuple):
             for x in block.exitswitch:
                 die_at.pop(x, None)
         else:
             die_at.pop(block.exitswitch, None)
         for link in block.exits:
             for v in link.args:
                 die_at.pop(v, None)
         die_at = [(value, key) for (key, value) in die_at.items()]
         die_at.sort()
         die_at.append((sys.maxint,))
         # Done.  XXX the code above this line runs 3 times
         # (for kind in KINDS) to produce the same result...
         livevars = [v for v in block.inputargs
                       if self.consider_var(v)]
         # Add the variables of this block to the dependency graph
         for i, v in enumerate(livevars):
             dg.add_node(v)
             for j in range(i):
                 dg.add_edge(livevars[j], v)
         livevars = set(livevars)
         die_index = 0
         for i, op in enumerate(block.operations):
             while die_at[die_index][0] == i:
                 try:
                     livevars.remove(die_at[die_index][1])
                 except KeyError:
                     pass
                 die_index += 1
             if (op.result is not None and
                     self.consider_var(op.result)):
                 dg.add_node(op.result)
                 for v in livevars:
                     if self.consider_var(v):
                         dg.add_edge(v, op.result)
                 livevars.add(op.result)
     self._depgraph = dg
예제 #2
0
파일: regalloc.py 프로젝트: Darriall/pypy
 def make_dependencies(self):
     dg = DependencyGraph()
     for block in self.graph.iterblocks():
         # Compute die_at = {Variable: index_of_operation_with_last_usage}
         die_at = dict.fromkeys(block.inputargs, 0)
         for i, op in enumerate(block.operations):
             for v in op.args:
                 if isinstance(v, Variable):
                     die_at[v] = i
                 elif isinstance(v, self.ListOfKind):
                     for v1 in v:
                         if isinstance(v1, Variable):
                             die_at[v1] = i
             if op.result is not None:
                 die_at[op.result] = i + 1
         if isinstance(block.exitswitch, tuple):
             for x in block.exitswitch:
                 die_at.pop(x, None)
         else:
             die_at.pop(block.exitswitch, None)
         for link in block.exits:
             for v in link.args:
                 die_at.pop(v, None)
         die_at = [(value, key) for (key, value) in die_at.items()]
         die_at.sort()
         die_at.append((sys.maxint,))
         # Done.  XXX the code above this line runs 3 times
         # (for kind in KINDS) to produce the same result...
         livevars = [v for v in block.inputargs
                       if self.consider_var(v)]
         # Add the variables of this block to the dependency graph
         for i, v in enumerate(livevars):
             dg.add_node(v)
             for j in range(i):
                 dg.add_edge(livevars[j], v)
         livevars = set(livevars)
         die_index = 0
         for i, op in enumerate(block.operations):
             while die_at[die_index][0] == i:
                 try:
                     livevars.remove(die_at[die_index][1])
                 except KeyError:
                     pass
                 die_index += 1
             if (op.result is not None and
                     self.consider_var(op.result)):
                 dg.add_node(op.result)
                 for v in livevars:
                     if self.consider_var(v):
                         dg.add_edge(v, op.result)
                 livevars.add(op.result)
     self._depgraph = dg
예제 #3
0
파일: test_color.py 프로젝트: Darriall/pypy
def test_find_node_coloring_empty():
    dg = DependencyGraph()
    coloring = dg.find_node_coloring()
    assert coloring == {}
예제 #4
0
파일: test_color.py 프로젝트: Darriall/pypy
def graph1():
    dg = DependencyGraph()
    dg.add_node('a')
    dg.add_node('b')
    dg.add_node('c')
    dg.add_node('d')
    dg.add_node('e')
    dg.add_edge('a', 'b')       #       d---e
    dg.add_edge('a', 'd')       #      / \ / \
    dg.add_edge('d', 'b')       #     a---b---c
    dg.add_edge('d', 'e')
    dg.add_edge('b', 'c')
    dg.add_edge('b', 'e')
    dg.add_edge('e', 'c')
    return dg
예제 #5
0
파일: test_color.py 프로젝트: Darriall/pypy
def test_lexicographic_order_empty():
    dg = DependencyGraph()
    order = list(dg.lexicographic_order())
    assert order == []
예제 #6
0
def test_find_node_coloring_empty():
    dg = DependencyGraph()
    coloring = dg.find_node_coloring()
    assert coloring == {}
예제 #7
0
def test_lexicographic_order_empty():
    dg = DependencyGraph()
    order = list(dg.lexicographic_order())
    assert order == []
예제 #8
0
def graph1():
    dg = DependencyGraph()
    dg.add_node('a')
    dg.add_node('b')
    dg.add_node('c')
    dg.add_node('d')
    dg.add_node('e')
    dg.add_edge('a', 'b')  #       d---e
    dg.add_edge('a', 'd')  #      / \ / \
    dg.add_edge('d', 'b')  #     a---b---c
    dg.add_edge('d', 'e')
    dg.add_edge('b', 'c')
    dg.add_edge('b', 'e')
    dg.add_edge('e', 'c')
    return dg