diff --git a/Makefile b/Makefile index 5f76e2ad46918d484ae379fad85635e135afc2b7..d9ba4649b301d08fe470cc0bc098f6716b82fd7a 100644 --- a/Makefile +++ b/Makefile @@ -64,3 +64,7 @@ clean: rm -rf $(LIBD) rm -rf $(TESTD) +.PHONY: style +style: + astyle $(SRCD)/*.cpp ./include/*.hpp -n -A1 -p -xj -J -xg -H -k3 -O -xC80 \ + -t2 -xt1 -m0 diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp index 1e87186bc0031bf4be12adf8a59d69e73cc81926..79b3c97e2c1c915c773a8f17fae208355196b3d5 100644 --- a/include/pass_mpi_collective.hpp +++ b/include/pass_mpi_collective.hpp @@ -5,7 +5,8 @@ /* Enum to represent the collective operations */ -enum mpi_collective_code { +enum mpi_collective_code +{ #define DEFMPICOLLECTIVES( CODE, NAME ) CODE, #include "mpi_collectives.def" LAST_AND_UNUSED_MPI_COLLECTIVE_CODE @@ -14,34 +15,36 @@ enum mpi_collective_code { /* Name of each MPI collective operations */ #define DEFMPICOLLECTIVES( CODE, NAME ) NAME, -const char *const mpi_collective_name[] = { +const char *const mpi_collective_name[] = +{ #include "mpi_collectives.def" } ; #undef DEFMPICOLLECTIVES -class pass_mpi_collective : public opt_pass { +class pass_mpi_collective : public opt_pass +{ - public: +public: - pass_mpi_collective(gcc::context *ctxt); - pass_mpi_collective* clone(); + pass_mpi_collective(gcc::context *ctxt); + pass_mpi_collective *clone(); - bool gate(function *fun); - unsigned int execute(function *fun); + bool gate(function *fun); + unsigned int execute(function *fun); - void print_tree(function *fun); - bool is_func(gimple *stmt); - bool is_mpi_func(gimple *stmt); - mpi_collective_code is_mpi_collec(gimple *stmt); - void split_blocks(function *fun); + void print_tree(function *fun); + bool is_func(gimple *stmt); + bool is_mpi_func(gimple *stmt); + mpi_collective_code is_mpi_collec(gimple *stmt); + void split_blocks(function *fun); - private: - bool __is_mpi_func(gimple *stmt); - mpi_collective_code __is_mpi_collec(gimple *stmt); +private: + bool __is_mpi_func(gimple *stmt); + mpi_collective_code __is_mpi_collec(gimple *stmt); - char *cfgviz_generate_filename(function *fun, - const char *suffix); - void cfgviz_internal_dump(function *fun, FILE *out); - void cfgviz_dump(function *fun, const char *suffix); + char *cfgviz_generate_filename(function *fun, + const char *suffix); + void cfgviz_internal_dump(function *fun, FILE *out); + void cfgviz_dump(function *fun, const char *suffix); }; diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp index 62c16f749c11ee3afa9b5344482fe51d1e48bf50..636be5d34e6998a7b979d747bab4cb14a3617e5b 100644 --- a/src/pass_mpi_collective.cpp +++ b/src/pass_mpi_collective.cpp @@ -15,7 +15,8 @@ // Definitions -const pass_data my_pass_data = { +const pass_data my_pass_data = +{ GIMPLE_PASS, /* type */ "my new ppass", /* name */ OPTGROUP_NONE, /* optinfo_flags */ @@ -30,15 +31,15 @@ const pass_data my_pass_data = { // Class functions pass_mpi_collective::pass_mpi_collective(gcc::context *ctxt) - : opt_pass(my_pass_data, ctxt){} + : opt_pass(my_pass_data, ctxt) {} -pass_mpi_collective* pass_mpi_collective::clone(){ - return new pass_mpi_collective(g); -} +pass_mpi_collective *pass_mpi_collective::clone() +{return new pass_mpi_collective(g);} -bool pass_mpi_collective::gate(function *fun){ +bool pass_mpi_collective::gate(function *fun) +{ //printf("In gate of: %s\n", fndecl_name(fun->decl)); printf("In gate of: %s\n", function_name(fun)); //printf("In gate of: %s\n", current_function_name()); @@ -46,9 +47,10 @@ bool pass_mpi_collective::gate(function *fun){ } -unsigned int pass_mpi_collective::execute(function *fun){ +unsigned int pass_mpi_collective::execute(function *fun) +{ printf("In execute of: %s\n", function_name(fun)); - + print_tree(fun); split_blocks(fun); print_tree(fun); @@ -57,24 +59,33 @@ unsigned int pass_mpi_collective::execute(function *fun){ } -void pass_mpi_collective::print_tree(function *fun){ +void pass_mpi_collective::print_tree(function *fun) +{ basic_block bb; gimple_stmt_iterator gsi; gimple *stmt; //size_t line; - FOR_EACH_BB_FN(bb, fun){ + FOR_EACH_BB_FN(bb, fun) + { printf("\tBasic block: %d\n", bb->index); - for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)){ + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) + { stmt = gsi_stmt(gsi); //line = gimple_lineno(stmt); //printf("\tstatement at line = %lu\n", line); - if(is_func(stmt)){ - printf("\t\tStatement is a function call (%s)\n", fndecl_name(gimple_call_fndecl(stmt))); - if(__is_mpi_func(stmt)){ - printf("\t\t\tStatement is a MPI function call (%s)\n", fndecl_name(gimple_call_fndecl(stmt))); - if(__is_mpi_collec(stmt)){ - printf("\t\t\t\tStatement is a MPI statement (%s)\n", fndecl_name(gimple_call_fndecl(stmt))); + if (is_func(stmt)) + { + printf("\t\tStatement is a function call (%s)\n", + fndecl_name(gimple_call_fndecl(stmt))); + if (__is_mpi_func(stmt)) + { + printf("\t\t\tStatement is a MPI function call (%s)\n", + fndecl_name(gimple_call_fndecl(stmt))); + if (__is_mpi_collec(stmt)) + { + printf("\t\t\t\tStatement is a MPI statement (%s)\n", + fndecl_name(gimple_call_fndecl(stmt))); } } } @@ -82,38 +93,38 @@ void pass_mpi_collective::print_tree(function *fun){ } } -bool pass_mpi_collective::is_func(gimple *stmt){ - return is_gimple_call(stmt); -} +bool pass_mpi_collective::is_func(gimple *stmt) +{return is_gimple_call(stmt);} -bool pass_mpi_collective::__is_mpi_func(gimple *stmt){ - return strncmp(fndecl_name(gimple_call_fndecl(stmt)), "MPI_", 4) == 0; -} +bool pass_mpi_collective::__is_mpi_func(gimple *stmt) +{return strncmp(fndecl_name(gimple_call_fndecl(stmt)), "MPI_", 4) == 0;} -bool pass_mpi_collective::is_mpi_func(gimple *stmt){ - return is_func(stmt) && __is_mpi_func(stmt); -} +bool pass_mpi_collective::is_mpi_func(gimple *stmt) +{return is_func(stmt) && __is_mpi_func(stmt);} -mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt){ +mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt) +{ size_t i; - const char * callee_name; + const char *callee_name; i = 0; callee_name = fndecl_name(gimple_call_fndecl(stmt)); - - while(i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE){ - if(strcmp(mpi_collective_name[i], callee_name) == 0) - return (enum mpi_collective_code) i; + + while (i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) + { + if (strcmp(mpi_collective_name[i], callee_name) == 0) + { return (enum mpi_collective_code) i; } ++i; } return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; } -mpi_collective_code pass_mpi_collective::is_mpi_collec(gimple *stmt){ - if(!is_mpi_func(stmt)) - return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; +mpi_collective_code pass_mpi_collective::is_mpi_collec(gimple *stmt) +{ + if (!is_mpi_func(stmt)) + { return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; } return __is_mpi_collec(stmt); } @@ -128,20 +139,23 @@ mpi_collective_code pass_mpi_collective::is_mpi_collec(gimple *stmt){ //} -void pass_mpi_collective::split_blocks(function *fun){ +void pass_mpi_collective::split_blocks(function *fun) +{ basic_block bb; gimple_stmt_iterator gsi; gimple *stmt; size_t nb_collective; - FOR_EACH_BB_FN(bb, fun){ + FOR_EACH_BB_FN(bb, fun) + { nb_collective = 0; - for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)){ + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) + { stmt = gsi_stmt(gsi); - if(is_mpi_collec(stmt) != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) - ++nb_collective; - if(nb_collective >= 2) - split_block(bb, stmt); + if (is_mpi_collec(stmt) != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) + { ++nb_collective; } + if (nb_collective >= 2) + { split_block(bb, stmt); } } } } @@ -149,24 +163,25 @@ void pass_mpi_collective::split_blocks(function *fun){ /* Build a filename (as a string) based on function name */ -char *pass_mpi_collective::cfgviz_generate_filename(function *fun, const char *suffix) +char *pass_mpi_collective::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); + 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 pass_mpi_collective::cfgviz_internal_dump( - function *fun, FILE *out) + function *fun, FILE *out) { basic_block bb; mpi_collective_code code; @@ -178,24 +193,24 @@ void pass_mpi_collective::cfgviz_internal_dump( FOR_ALL_BB_FN(bb, fun) { code = LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; - if(bb->aux != NULL) - code = *((mpi_collective_code*) bb->aux); + if (bb->aux != NULL) + { code = *((mpi_collective_code *) bb->aux); } fprintf(out, "%d [label=\"BB %d %s\" shape=ellipse]\n", - bb->index, bb->index, - (code == LAST_AND_UNUSED_MPI_COLLECTIVE_CODE ? "" : - mpi_collective_name[code])); + bb->index, bb->index, + (code == LAST_AND_UNUSED_MPI_COLLECTIVE_CODE ? "" : + mpi_collective_name[code])); 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"; + 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); + bb->index, e->dest->index, label); } } @@ -203,7 +218,7 @@ void pass_mpi_collective::cfgviz_internal_dump( } void pass_mpi_collective::cfgviz_dump(function *fun, - const char *suffix) + const char *suffix) { char *target_filename; FILE *out; @@ -211,7 +226,7 @@ void pass_mpi_collective::cfgviz_dump(function *fun, target_filename = cfgviz_generate_filename(fun, suffix); printf("[GRAPHVIZ] Generating CFG of function %s in file <%s>\n", - current_function_name(), target_filename); + current_function_name(), target_filename); out = fopen(target_filename, "w"); diff --git a/src/plugin.cpp b/src/plugin.cpp index 2003aca74741f4462507444248e44f4ea0aec67c..481a9ebd67529ef367ea7ab2938fce7c39402b1f 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -17,7 +17,7 @@ int plugin_is_GPL_compatible; /* Main entry point for plugin */ int plugin_init(struct plugin_name_args *plugin_info, - struct plugin_gcc_version *version) + struct plugin_gcc_version *version) { printf("plugin_init: Entering...\n"); printf("\tbasever = %s\n", version->basever); @@ -28,16 +28,15 @@ plugin_init(struct plugin_name_args *plugin_info, printf("\tbase_name = %s\n", plugin_info->base_name); printf("\tfull_name = %s\n", plugin_info->full_name); - for(int i = 0; i < plugin_info->argc; ++i) + for (int i = 0; i < plugin_info->argc; ++i) printf("\t\targ %d: %s = %s\n", i, plugin_info->argv[i].key, - plugin_info->argv[i].value); + plugin_info->argv[i].value); printf("\tversion = %s\n", plugin_info->version); printf("\thelp = %s\n", plugin_info->help); printf("\n\n"); - pass_mpi_collective p(g); struct register_pass_info pass_info; @@ -48,9 +47,9 @@ plugin_init(struct plugin_name_args *plugin_info, pass_info.pos_op = PASS_POS_INSERT_AFTER; register_callback( plugin_info->base_name, - PLUGIN_PASS_MANAGER_SETUP, - NULL, - &pass_info); + PLUGIN_PASS_MANAGER_SETUP, + NULL, + &pass_info); return 0; }