Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 0c4487505c1b9c6170f37c22e56f4fcc98f49a8d
  • master par défaut
  • script
  • new-devel
  • devel
  • timingView-edit
  • fix-mpv
7 résultats

MpvContainer.cc

Blame
  • graph.c 3,33 Kio
    #include "graph.h"
    
    /* Build a filename (as a string) based on function name */
    char * cfgviz_generate_filename( function * fun, const char * suffix )
    {
            char * target_filename ;
    
            target_filename = (char *)xmalloc( 1024 * sizeof( char ) ) ;
    
            snprintf( target_filename, 1024, "%s_%s_%d_%s.dot",
                            current_function_name(),
                            LOCATION_FILE( fun->function_start_locus ),
                            LOCATION_LINE( fun->function_start_locus ),
                            suffix ) ;
    
            return target_filename ;
    }
    
    /* Dump the graphviz representation of function 'fun' in file 'out' */
    void cfgviz_internal_dump( function * fun, FILE * out, int td )
    {
            basic_block bb;
    
            // Print the header line and open the main graph
            fprintf(out, "Digraph G{\n");
    
    
            FOR_ALL_BB_FN(bb,cfun)
            {
    
                    //
                    // Print the basic block BB, with the MPI call if necessary
                    //
    
                    //printf("before test aux : %p\n",bb->aux);
                    //printf("now testing if MPI call...\n");
    		if ((bb->aux != NULL) && (*((int *)bb->aux) != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) && (*((int *)bb->aux) >= 0))
                    {
                            //printf("Printing MPI function name\n");
                            //printf("after test aux : %p\n",bb->aux);
                            int code = *((int *)bb->aux);
                            const char *name = mpi_collective_name[code];
                            //printf("Function name to be added to graph : %s, code : %i\n",name,code);
                            fprintf( out,
                                            "%d [label=\"BB %d %s\" shape=ellipse]\n",
                                            bb->index,
                                            bb->index,
                                            name
                                       ) ;
                    } else {
                            fprintf( out,
                                            "%d [label=\"BB %d\" shape=ellipse]\n",
                                            bb->index,
                                            bb->index
                                       ) ;
                    }
                    //
                    // Process output edges 
                    //
                    edge_iterator eit;
    		edge e;
    
                    FOR_EACH_EDGE( e, eit, bb->succs )
                    {
                            const char *label = "";
                            if( e->flags == EDGE_TRUE_VALUE )
                                    label = "true";
                            else if( e->flags == EDGE_FALSE_VALUE )
                                    label = "false";
    
                            fprintf( out, "%d -> %d [color=red label=\"%s\"]\n",
                                            bb->index, e->dest->index, label ) ;
    
                    }
            }
    
            // Close the main graph
            fprintf(out, "}\n");
    }
    
    void cfgviz_dump( function * fun, const char * suffix, int td )
    {
            char * target_filename ;
            FILE * out ;
    
            target_filename = cfgviz_generate_filename( fun, suffix ) ;
    
            printf( "[GRAPHVIZ] Generating CFG of function %s in file <%s>\n",
                            current_function_name(), target_filename ) ;
    
            out = fopen( target_filename, "w" ) ;
    
            cfgviz_internal_dump( fun, out, td ) ;
    
            fclose( out ) ;
            free( target_filename ) ;
    }