Exemple #1
0
def place_declarations(graph, dvars, du, ud):
    idom = graph.immediate_dominators()
    for node in graph.post_order():
        for loc, ins in node.get_loc_with_ins():
            for var in ins.get_used_vars():
                if (not isinstance(dvars[var], Variable) or
                        isinstance(dvars[var], Param)):
                    continue
                var_defs_locs = ud[var, loc]
                def_nodes = set()
                for def_loc in var_defs_locs:
                    def_node = graph.get_node_from_loc(def_loc)
                    # TODO: place declarations in catch if needed
                    if def_node.in_catch:
                        continue
                    def_nodes.add(def_node)
                if not def_nodes:
                    continue
                common_dominator = def_nodes.pop()
                for def_node in def_nodes:
                    common_dominator = common_dom(
                        idom, common_dominator, def_node)
                if any(var in range(*common_dominator.ins_range)
                       for var in ud[var, loc]):
                    continue
                common_dominator.add_variable_declaration(dvars[var])
Exemple #2
0
def place_declarations(graph, dvars, du, ud):
    idom = graph.immediate_dominators()
    for node in graph.post_order():
        for loc, ins in node.get_loc_with_ins():
            for var in ins.get_used_vars():
                if (not isinstance(dvars[var], Variable)
                        or isinstance(dvars[var], Param)):
                    continue
                var_defs_locs = ud[var, loc]
                def_nodes = set()
                for def_loc in var_defs_locs:
                    def_node = graph.get_node_from_loc(def_loc)
                    # TODO: place declarations in catch if needed
                    if def_node.in_catch:
                        continue
                    def_nodes.add(def_node)
                if not def_nodes:
                    continue
                common_dominator = def_nodes.pop()
                for def_node in def_nodes:
                    common_dominator = common_dom(idom, common_dominator,
                                                  def_node)
                if any(var in range(*common_dominator.ins_range)
                       for var in ud[var, loc]):
                    continue
                common_dominator.add_variable_declaration(dvars[var])
Exemple #3
0
 def immediate_dominators(self):
     '''
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     '''
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         for pred in self.preds(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
Exemple #4
0
 def immediate_dominators(self):
     '''
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     '''
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         for pred in self.preds(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
Exemple #5
0
 def immediate_dominators(self):
     """
     Create a mapping of the nodes of a graph with their corresponding
     immediate dominator
     """
     idom = dict((n, None) for n in self.nodes)
     for node in self.rpo:
         if node.in_catch:
             predecessor = self.all_preds
         else:
             predecessor = self.preds
         for pred in predecessor(node):
             if pred.num < node.num:
                 idom[node] = common_dom(idom, idom[node], pred)
     return idom
Exemple #6
0
def switch_struct(graph, idoms):
    unresolved = set()
    for node in graph.post_order():
        if node.is_switch():
            m = node
            for suc in graph.sucs(node):
                if idoms[suc] is not node:
                    m = common_dom(idoms, node, suc)
            ldominates = []
            for n, dom in idoms.iteritems():
                if m is dom and len(graph.preds(n)) > 1:
                    ldominates.append(n)
            if len(ldominates) > 0:
                n = max(ldominates, key=lambda x: x.num)
                node.set_switch_follow(n)
                for x in unresolved:
                    x.set_switch_follow(n)
                unresolved = set()
            else:
                unresolved.add(node)
            node.order_cases()
Exemple #7
0
def switch_struct(graph, idoms):
    unresolved = set()
    for node in graph.post_order():
        if node.type.is_switch:
            m = node
            for suc in graph.sucs(node):
                if idoms[suc] is not node:
                    m = common_dom(idoms, node, suc)
            ldominates = []
            for n, dom in idoms.iteritems():
                if m is dom and len(graph.preds(n)) > 1:
                    ldominates.append(n)
            if len(ldominates) > 0:
                n = max(ldominates, key=lambda x: x.num)
                node.follow['switch'] = n
                for x in unresolved:
                    x.follow['switch'] = n
                unresolved = set()
            else:
                unresolved.add(node)
            node.order_cases()