Exemplo n.º 1
0
 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, 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 getkind(v.concretetype) == self.kind]
         # 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
                 getkind(op.result.concretetype) == self.kind):
                 dg.add_node(op.result)
                 for v in livevars:
                     if getkind(v.concretetype) == self.kind:
                         dg.add_edge(v, op.result)
                 livevars.add(op.result)
     self._depgraph = dg
Exemplo n.º 2
0
 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
Exemplo n.º 3
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