Example #1
0
    def construct_loop_info(self, enhanced_icfg, lnt, ipg):
        for v in ipg:
            for succID in v.successors.keys():
                succe = v.get_successor_edge(succID)
                for program_point in succe.edge_label:
                    if isinstance(program_point, vertices.CFGEdge):
                        the_edge = program_point.edge
                        if lnt.is_loop_back_edge(the_edge[0], the_edge[1]):
                            self.loop_back_edges[the_edge[1]].add(
                                (v.vertexID, succID))

        for treev in self.enhanced_lnt:
            if isinstance(treev, vertices.HeaderVertex):
                debug.debug_message("Analysing header %d" % treev.headerID,
                                    __name__, 1)
                enhanced_icfg_of_loop = self.enhanced_lnt.induce_subgraph(
                    treev)
                self.enhanced_icfgs_per_loop[
                    treev.headerID] = enhanced_icfg_of_loop
                self.loop_exit_regions[
                    treev.
                    headerID] = self.compute_reachable_program_points_from_loop_exits(
                        treev)
                udraw.make_file(
                    enhanced_icfg_of_loop, "%s.header_%d.%s" %
                    (enhanced_icfg.name, treev.headerID, "icfg"))
                self.ipgs_per_loop[treev.headerID] = ipgs.IPGLoopInformation(
                    self, treev.headerID, enhanced_icfg_of_loop, self.lnt,
                    self.enhanced_lnt, ipg)
def create_path_expression_for_all_loops(cfg):
    print("%s CFG: %s %s" % ('*' * 10, cfg.name, '*' * 10))
    transition_graph = cfg.get_transition_graph()
    transition_graph_lnt = transition_graph.get_LNT()
    for the_vertices in transition_graph_lnt.level_by_level_iterator(True):
        for v_header in [
                v_tree for v_tree in the_vertices
                if isinstance(v_tree, vertices.HeaderVertex)
        ]:
            v_state = transition_graph.get_vertex(v_header.headerID)
            e_succ = v_state.successors.values()[0]
            real_headerID = e_succ.the_program_point[0]

            iteration_subgraph = create_induced_subgraph_for_loop_iteration_space(
                transition_graph, transition_graph_lnt, v_header)

            udraw.make_file(iteration_subgraph,
                            "%s.induced.L_%d" % (cfg.name, real_headerID))

            iteration_subgraph_path_expression = PathExpression(
                transition_graph, transition_graph_lnt, iteration_subgraph,
                v_header.vertexID != transition_graph_lnt.rootID)

            print("P(L_%d)::\n%s\n" %
                  (real_headerID,
                   iteration_subgraph_path_expression.get_textual_format()))

            udraw.make_file(iteration_subgraph_path_expression,
                            "%s.re.L_%d" % (cfg.name, real_headerID))
Example #3
0
 def create_LNTs(self):
     for name, icfg in self.icfgs.iteritems():
         self.lnts[name] = trees.LoopNests(icfg, icfg.get_entryID())
         self.enhanced_lnts[name] = trees.LoopNests(self.enhanced_icfgs[name], 
                                                    self.enhanced_icfgs[name].get_entryID())
         udraw.make_file(self.lnts[name], "%s.lnt" % (name))
         udraw.make_file(self.enhanced_lnts[name], "%s.enhanced_lnt" % (name))
Example #4
0
 def create_loop_by_loop_information(self):
     for name, enhanced_icfg in self.enhanced_icfgs.iteritems():
         self.loop_by_loop_info[name] = LoopByLoopInformation(enhanced_icfg, 
                                                              self.enhanced_lnts[name], 
                                                              self.lnts[name],
                                                              self.ipgs[name])
         udraw.make_file(self.ipgs[name], "%s.ipg" % (name))
Example #5
0
 def instrument(self):
     for icfg in self.icfgs.values():
         if config.Arguments.add_path_reconstructible_instrumentation:
             icfg.instrument_using_depth_first_spanning_tree()
         else:
             icfg.add_edges_between_ipoints()
         udraw.make_file(icfg, "%s.icfg" % (icfg.name))
Example #6
0
 def instrument(self):
     for icfg in self.icfgs.values():
         if config.Arguments.add_path_reconstructible_instrumentation:
             icfg.instrument_using_depth_first_spanning_tree()
         else:
             icfg.add_edges_between_ipoints()
         udraw.make_file(icfg, "%s.icfg" % (icfg.name))
Example #7
0
def create_path_expression_for_all_loops(cfg):
    print("%s CFG: %s %s" % ('*' * 10, cfg.name, '*' * 10))
    transition_graph     = cfg.get_transition_graph()
    transition_graph_lnt = transition_graph.get_LNT()
    for the_vertices in transition_graph_lnt.level_by_level_iterator(True):
        for v_header in [v_tree for v_tree in the_vertices if isinstance(v_tree, vertices.HeaderVertex)]:
            v_state       = transition_graph.get_vertex(v_header.headerID)
            e_succ        = v_state.successors.values()[0]
            real_headerID = e_succ.the_program_point[0]
            
            iteration_subgraph = create_induced_subgraph_for_loop_iteration_space(transition_graph, 
                                                                                  transition_graph_lnt,
                                                                                  v_header)
            
            udraw.make_file(iteration_subgraph, "%s.induced.L_%d" % (cfg.name, real_headerID))
            
            iteration_subgraph_path_expression = PathExpression(transition_graph,
                                                                transition_graph_lnt,
                                                                iteration_subgraph,
                                                                v_header.vertexID != transition_graph_lnt.rootID)
            
            print("P(L_%d)::\n%s\n" % (real_headerID, iteration_subgraph_path_expression.get_textual_format()))
        
            udraw.make_file(iteration_subgraph_path_expression, "%s.re.L_%d" % (cfg.name, real_headerID))
            
            
Example #8
0
def do_it():
    program = programs.Program()
    for functionID in xrange(1, config.Arguments.subprograms+1):
        name = "f%d" % functionID
        cfg  = CreateCFG(name).cfg
        program.add_CFG(cfg)
    create_call_graph(program)
    udraw.make_file(program.callg, "callg")
    return program
Example #9
0
 def create_LNTs(self):
     for name, icfg in self.icfgs.iteritems():
         self.lnts[name] = trees.LoopNests(icfg, icfg.get_entryID())
         self.enhanced_lnts[name] = trees.LoopNests(
             self.enhanced_icfgs[name],
             self.enhanced_icfgs[name].get_entryID())
         udraw.make_file(self.lnts[name], "%s.lnt" % (name))
         udraw.make_file(self.enhanced_lnts[name],
                         "%s.enhanced_lnt" % (name))
Example #10
0
def do_instrumentation(cfg, program_points_to_profile):
    enhanced_cfg = cfg.get_enhanced_cfg()
    if config.Arguments.instrument == "vertices":
        eliminate_cfg_edge_vertices(enhanced_cfg)
    elif config.Arguments.instrument == "edges":
        eliminate_cfg_vertex_vertices(enhanced_cfg)
    eliminate_program_points_which_are_not_profiled(enhanced_cfg, program_points_to_profile)    
    reduce_enhanced_cfg(enhanced_cfg)
    udraw.make_file(enhanced_cfg, "%s.enhanced" % enhanced_cfg.name)
Example #11
0
def read_file(filename):
    program = first_pass(filename)
    data    = second_pass(filename, program)
    program.callg.find_and_set_root()
    for cfg in program.cfgs.values():
        cfg.add_predecessor_edges()
        cfg.set_entry_and_exit()
        cfg.set_edgeIDs()
        udraw.make_file(cfg, "%s.cfg" % (cfg.name))
    return data, program     
Example #12
0
def read_file(filename):
    program = first_pass(filename)
    data = second_pass(filename, program)
    program.callg.find_and_set_root()
    for cfg in program.cfgs.values():
        cfg.add_predecessor_edges()
        cfg.set_entry_and_exit()
        cfg.set_edgeIDs()
        udraw.make_file(cfg, "%s.cfg" % (cfg.name))
    return data, program
def read_file(filename):
    program = programs.Program()
    cfg = None
    bb = None
    with open(filename) as the_file:
        for line in the_file:
            line = line.lower()
            if line.startswith(cfg_lexeme):
                names = name_regex.findall(line)
                assert len(
                    names) == 2, "Too many names found '%s'" % ' '.join(names)
                cfg = directed_graphs.CFG()
                cfg.name = names[1]
                program.add_CFG(cfg)
                debug.debug_message("Found new CFG '%s'" % cfg.name, __name__,
                                    1)
            elif line.startswith(basic_block_lexeme):
                assert cfg, "Found basic block but current CFG is null"
                ids = int_regex.findall(line)
                assert len(
                    ids
                ) == 1, "Too many identifiers found '%s'" % ' '.join(ids)
                assert ids[0].isdigit(
                ), "Vertex identifier '%s' is not an integer" % ids[0]
                bb = vertices.Vertex(int(ids[0]))
                cfg.add_vertex(bb)
            elif line.startswith(successors_lexeme):
                assert bb, "Found edge but current basic block is null"
                edges = edges_regex.findall(line)
                for edge in edges:
                    a_tuple = edge_tuple_regex.findall(edge)
                    assert len(
                        a_tuple
                    ) == 2, "Too many components in edge tuple: %s" % edge
                    assert a_tuple[
                        0] == cfg.name, "Call edge found which is currently not handled"
                    assert a_tuple[1].isdigit(
                    ), "Successor identifier '%s' is not an integer" % a_tuple[
                        1]
                    bb.add_successor(int(a_tuple[1]))
    for cfg in program.cfgs.values():
        cfg.add_predecessor_edges()
        cfg.set_entry_and_exit()
        cfg.add_dummy_loop_between_exit_and_entry()
        udraw.make_file(cfg, "%s.cfg" % (cfg.name))
    return program
def create_path_expression(cfg, query_pair):
    transition_graph = cfg.get_transition_graph()
    transition_graph_lnt = transition_graph.get_LNT()
    v_lnt_source = transition_graph_lnt.get_vertex(
        transition_graph_lnt.program_point_to_lnt_vertexID[query_pair[0]])
    source_stateID = transition_graph.program_point_to_predecessor_stateID[
        query_pair[0]]
    destination_stateID = transition_graph.program_point_to_successor_stateID[
        query_pair[1]]
    transition_graph_induced = directed_graphs.StateTransitionGraph()

    if transition_graph.is_reachable(source_stateID, {destination_stateID}):
        if v_lnt_source.parentID == transition_graph_lnt.rootID:
            induce_subgraph_from_source_to_destination(
                transition_graph, transition_graph_lnt,
                transition_graph_induced, source_stateID, destination_stateID)
        else:
            v_pred_stateID = induce_subgraph_from_source_to_outermost_header(
                transition_graph, transition_graph_lnt,
                transition_graph_induced, query_pair)

            v_succ_stateID = induce_subgraph_from_source_to_destination(
                transition_graph, transition_graph_lnt,
                transition_graph_induced,
                transition_graph_lnt.get_vertex(
                    v_lnt_source.parentID).headerID, destination_stateID)

            transition_graph_induced.add_edge(v_pred_stateID, v_succ_stateID,
                                              (), False)

        transition_graph_induced.set_entry_and_exit()
        transition_graph_induced.set_edgeIDs()

    udraw_suffix = "%s-%s" % (('_'.join(map(str, query_pair[0]))),
                              ('_'.join(map(str, query_pair[1]))))

    udraw.make_file(transition_graph_induced,
                    "%s.transition.%s" % (cfg.name, udraw_suffix))

    expressiont = PathExpression(transition_graph, transition_graph_lnt,
                                 transition_graph_induced)

    udraw.make_file(expressiont, "%s.re.%s" % (cfg.name, udraw_suffix))

    print("P(%s) = %s" % (udraw_suffix, expressiont.get_textual_format()))
Example #15
0
def create_path_expression(cfg, query_pair):
    transition_graph         = cfg.get_transition_graph()
    transition_graph_lnt     = transition_graph.get_LNT()
    v_lnt_source             = transition_graph_lnt.get_vertex(transition_graph_lnt.program_point_to_lnt_vertexID[query_pair[0]])
    source_stateID           = transition_graph.program_point_to_predecessor_stateID[query_pair[0]]
    destination_stateID      = transition_graph.program_point_to_successor_stateID[query_pair[1]]
    transition_graph_induced = directed_graphs.StateTransitionGraph()
    
    if transition_graph.is_reachable(source_stateID, {destination_stateID}):
        if v_lnt_source.parentID == transition_graph_lnt.rootID:
            induce_subgraph_from_source_to_destination(transition_graph, 
                                                       transition_graph_lnt,
                                                       transition_graph_induced,
                                                       source_stateID,
                                                       destination_stateID)
        else:
            v_pred_stateID = induce_subgraph_from_source_to_outermost_header(transition_graph,
                                                                             transition_graph_lnt,
                                                                             transition_graph_induced,
                                                                             query_pair)
            
            v_succ_stateID = induce_subgraph_from_source_to_destination(transition_graph,
                                                                        transition_graph_lnt,
                                                                        transition_graph_induced,
                                                                        transition_graph_lnt.get_vertex(v_lnt_source.parentID).headerID,
                                                                        destination_stateID)
            
            transition_graph_induced.add_edge(v_pred_stateID, v_succ_stateID, (), False)
            
        transition_graph_induced.set_entry_and_exit() 
        transition_graph_induced.set_edgeIDs()
        
    udraw_suffix = "%s-%s" % (('_'.join(map(str, query_pair[0]))), ('_'.join(map(str, query_pair[1]))))
    
    udraw.make_file(transition_graph_induced, 
                    "%s.transition.%s" % (cfg.name, udraw_suffix)) 
    
    expressiont = PathExpression(transition_graph,
                                 transition_graph_lnt,
                                 transition_graph_induced)
    
    udraw.make_file(expressiont, 
                    "%s.re.%s" % (cfg.name, udraw_suffix))  
    
    print("P(%s) = %s" % (udraw_suffix, expressiont.get_textual_format()))
def read_file(filename):
    program = programs.Program()
    cfg     = None
    bb      = None
    with open(filename) as the_file:
        for line in the_file:
            line = line.lower()
            if line.startswith(cfg_lexeme):
                names = name_regex.findall(line)
                assert len(names) == 2, "Too many names found '%s'" % ' '.join(names)
                cfg      = directed_graphs.CFG()
                cfg.name = names[1]
                program.add_CFG(cfg)
                debug.debug_message("Found new CFG '%s'" % cfg.name, __name__, 1)
            elif line.startswith(basic_block_lexeme):
                assert cfg, "Found basic block but current CFG is null"
                ids = int_regex.findall(line) 
                assert len(ids) == 1, "Too many identifiers found '%s'" % ' '.join(ids)
                assert ids[0].isdigit(), "Vertex identifier '%s' is not an integer" % ids[0]
                bb = vertices.Vertex(int(ids[0]))
                cfg.add_vertex(bb)
            elif line.startswith(successors_lexeme):
                assert bb, "Found edge but current basic block is null"
                edges = edges_regex.findall(line)
                for edge in edges:
                    a_tuple = edge_tuple_regex.findall(edge)
                    assert len(a_tuple) == 2, "Too many components in edge tuple: %s" % edge
                    assert a_tuple[1].isdigit(), "Successor identifier '%s' is not an integer" % a_tuple[1]
                    if a_tuple[0] == cfg.name:
                        bb.add_successor(int(a_tuple[1])) 
                    else:
                        program.callg.add_edge(cfg.name, a_tuple[0], bb.vertexID)
    for cfg in program.cfgs.values():
        cfg.add_predecessor_edges()
        cfg.set_entry_and_exit()
        cfg.add_dummy_loop_between_exit_and_entry()
        udraw.make_file(cfg, "%s.cfg" % (cfg.name))
    return program     
Example #17
0
 def construct_loop_info(self, enhanced_icfg, lnt, ipg):
     for v in ipg:
         for succID in v.successors.keys():
             succe = v.get_successor_edge(succID)
             for program_point in succe.edge_label:
                 if isinstance(program_point, vertices.CFGEdge):
                     the_edge = program_point.edge
                     if lnt.is_loop_back_edge(the_edge[0], the_edge[1]):
                         self.loop_back_edges[the_edge[1]].add((v.vertexID, succID))
     
     for treev in self.enhanced_lnt:
         if isinstance(treev, vertices.HeaderVertex):
             debug.debug_message("Analysing header %d" % treev.headerID, __name__, 1)
             enhanced_icfg_of_loop = self.enhanced_lnt.induce_subgraph(treev)
             self.enhanced_icfgs_per_loop[treev.headerID] = enhanced_icfg_of_loop
             self.loop_exit_regions[treev.headerID] = self.compute_reachable_program_points_from_loop_exits(treev)
             udraw.make_file(enhanced_icfg_of_loop, "%s.header_%d.%s" % (enhanced_icfg.name, treev.headerID, "icfg"))
             self.ipgs_per_loop[treev.headerID] = ipgs.IPGLoopInformation(self, 
                                                                          treev.headerID, 
                                                                          enhanced_icfg_of_loop, 
                                                                          self.lnt,
                                                                          self.enhanced_lnt, 
                                                                          ipg)
Example #18
0
 def get_transition_graph(self):
     if not self.transition_graph:
         self.transition_graph = StateTransitionGraph(self)
         udraw.make_file(self.transition_graph, "%s.transition" % self.name)
     return self.transition_graph
Example #19
0
 def create_IPGs(self):
     for name, enhanced_icfg in self.enhanced_icfgs.iteritems():
         self.ipgs[name] = ipgs.IPG(enhanced_icfg)
         udraw.make_file(self.ipgs[name], "%s.ipg" % (name))
Example #20
0
 def create_enhanced_ICFGs(self):
     for name, icfg in self.icfgs.iteritems():
         self.enhanced_icfgs[name] = cfgs.EnhancedICFG(icfg)
         udraw.make_file(self.enhanced_icfgs[icfg.name], "%s.enhanced_icfg" % (icfg.name))
Example #21
0
 def add_ICFG(self, icfg):
     assert icfg.name
     self.icfgs[icfg.name] = icfg
     udraw.make_file(icfg, "%s.icfg" % (icfg.name))
Example #22
0
 def get_enhanced_cfg(self):
     if not self.enhanced_cfg:
         self.enhanced_cfg = EnhancedCFG(self)
         udraw.make_file(self.enhanced_cfg, "%s.enhanced" % self.name)
     return self.enhanced_cfg
Example #23
0
 def create_loop_by_loop_information(self):
     for name, enhanced_icfg in self.enhanced_icfgs.iteritems():
         self.loop_by_loop_info[name] = LoopByLoopInformation(
             enhanced_icfg, self.enhanced_lnts[name], self.lnts[name],
             self.ipgs[name])
         udraw.make_file(self.ipgs[name], "%s.ipg" % (name))
Example #24
0
 def create_enhanced_ICFGs(self):
     for name, icfg in self.icfgs.iteritems():
         self.enhanced_icfgs[name] = cfgs.EnhancedICFG(icfg)
         udraw.make_file(self.enhanced_icfgs[icfg.name],
                         "%s.enhanced_icfg" % (icfg.name))
Example #25
0
 def add_ICFG(self, icfg):
     assert icfg.name
     self.icfgs[icfg.name] = icfg
     udraw.make_file(icfg, "%s.icfg" % (icfg.name))
Example #26
0
 def create_IPGs(self):
     for name, enhanced_icfg in self.enhanced_icfgs.iteritems():
         self.ipgs[name] = ipgs.IPG(enhanced_icfg)
         udraw.make_file(self.ipgs[name], "%s.ipg" % (name))
Example #27
0
 def get_transition_graph(self):
     if not self.transition_graph:
         self.transition_graph = StateTransitionGraph(self)
         udraw.make_file(self.transition_graph, "%s.transition" % self.name)
     return self.transition_graph