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

CRTPLuaScriptObject.hh

Blame
  • MPI_functions.c 4,63 Kio
    #include "MPI_functions.h"
    
    void write_mpi_code(function * fun)
    {
    	basic_block bb;
            gimple_stmt_iterator gsi;
    
            FOR_EACH_BB_FN( bb,fun )
            {
                    for (gsi = gsi_start_bb(bb); !gsi_end_p (gsi); gsi_next(&gsi))
                    {
                            gimple *stmt = gsi_stmt(gsi);
                            mpi_collective_code *current_enum = (mpi_collective_code*)xmalloc(sizeof (mpi_collective_code));
    
                            *current_enum = get_mpi_code(stmt);
    			//printf("current_enum : %i\n",*((int*)current_enum));
                            if (*current_enum != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
                            {
                                    edit_aux_value(bb,(int*)current_enum);
    
                            }			
                    }
    
            }
    }
    
    void detect_same_bb_mpi_call(function * fun)
    {
            basic_block bb;
            gimple_stmt_iterator gsi;
            FOR_EACH_BB_FN(bb,fun)
            {
                    int call_counter = 0;
                    for (gsi = gsi_start_bb(bb); !gsi_end_p (gsi); gsi_next(&gsi))
                    {
                            gimple *stmt = gsi_stmt(gsi);
                            mpi_collective_code *current_enum = (mpi_collective_code*)xmalloc(sizeof (mpi_collective_code));
    
                            *current_enum = get_mpi_code(stmt);
                            if (*current_enum != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
                            {
                                    //printf("Current mpi code : %i\n",(int)*current_enum);
                                    call_counter++;
    
                            }
                    }
                    printf("number of MPI calls in current basic_block : %i\n",call_counter);
            }
    }
    
    int are_there_several_mpi_call(function * fun)
    {
            basic_block bb;
            gimple_stmt_iterator gsi;
            FOR_EACH_BB_FN(bb,fun)
            {
                    int call_counter = 0;
                    for (gsi = gsi_start_bb(bb); !gsi_end_p (gsi); gsi_next(&gsi))
                    {
                            gimple *stmt = gsi_stmt(gsi);
                            mpi_collective_code *current_enum = (mpi_collective_code*)xmalloc(sizeof (mpi_collective_code));
    
                            *current_enum = get_mpi_code(stmt);
                            if (*current_enum != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
                            {
                                    call_counter++;
    
                            }
                    }
                    if (call_counter >= 2)
                    {
                            return 1;
                    }
            }
            return 0;
    }
    
    mpi_collective_code get_mpi_code(gimple * stmt)
    {
            if (is_gimple_call(stmt))
            {
                    tree t;
                    const char * callee_name;
                    t = gimple_call_fndecl(stmt);
                    callee_name = IDENTIFIER_POINTER(DECL_NAME(t));
                    for (int i = 0; i< LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; i++)
                    {
                            if (strcmp(callee_name,mpi_collective_name[i])==0)
                            {
                                    return static_cast<mpi_collective_code>(i);
                            }
                    }
            }
            return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE;
    }
    
    void split_mpi_block(function * fun)
    {
    	if (are_there_several_mpi_call(fun) == 1)
    	{
    		basic_block bb;
    		gimple_stmt_iterator gsi;
    
    		FOR_EACH_BB_FN(bb,fun)
    		{
    
    			int call_counter = 0;
    			for (gsi = gsi_start_bb(bb); !gsi_end_p (gsi); gsi_next(&gsi))
    			{
    				gimple *stmt = gsi_stmt(gsi);
    				mpi_collective_code *current_enum = (mpi_collective_code*)xmalloc(sizeof (mpi_collective_code));
    				
    			 	*current_enum = get_mpi_code(stmt);
    				if (*current_enum != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
    				{
    					call_counter++; 
    					
    				}
    				if (call_counter == 1 && *((int *)bb->aux)>=2)
    				{
    					split_block(bb, stmt);
    					int *edit_value = (int*)xmalloc(sizeof(int));
    					*edit_value = *((int *)bb->aux)-1; 
    					call_counter--;
    					edit_aux_value(bb,edit_value);
    					split_mpi_block(fun);
    					return;	
    					//free(edit_value);
    				}
    			}
    		}
    	}
    }
    
    void mark_number_of_calls(function * fun)
    {
    	basic_block bb;	
    	gimple_stmt_iterator gsi;
    	FOR_EACH_BB_FN(bb,fun)
    	{
    		int call_counter = 0;
    		int *aux_counter = (int*)xmalloc(sizeof(int));
    		for (gsi = gsi_start_bb(bb); !gsi_end_p (gsi); gsi_next(&gsi))
    		{
    			gimple *stmt = gsi_stmt(gsi);
    			mpi_collective_code *current_enum = (mpi_collective_code*)xmalloc(sizeof (mpi_collective_code));
    			
    		 	*current_enum = get_mpi_code(stmt);
    			if (*current_enum != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
    			{
    				//printf("Current mpi code : %i\n",(int)*current_enum);
    				call_counter++; 
    				
    			}
    		}
    		*aux_counter = call_counter;
    		edit_aux_value(bb,aux_counter);
    	}
    }