diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp index d883b48b360234aa12ac700cd4e7dab4a7093956..a433ea683edebe073c88ab0863b969dff9a44f1c 100644 --- a/include/pass_mpi_collective.hpp +++ b/include/pass_mpi_collective.hpp @@ -20,6 +20,13 @@ const char *const mpi_collective_name[] = }; #undef DEFMPICOLLECTIVES +enum domination_status +{ + NOT_DOMINATED, + DOMINATED, + NOT_APPLICABLE +}; + struct bb_data { mpi_collective_code mpi_code; @@ -31,7 +38,7 @@ struct bb_data bitmap_head seens; int mark1; // for graph parkour int mark2; - + domination_status dom_status; }; struct edge_data @@ -97,10 +104,11 @@ public: mpi_collective_code mpi_code, int rank); //post-dom set of same-rank collectives - bool __is_post_dom_mpi_coll_rank( - function *fun, basic_block bb, int rank, int mpi_code, bitmap pds); - void get_post_dom_mpi_coll_rank( - function *fun, int rank, int mpi_code, bitmap pds); + void get_mpi_coll_rank( + function *fun, int rank, int mpi_code, bitmap mpi_coll); + void __is_post_dom_bitmap( + function *fun, basic_block bb, bitmap nodes, bitmap pds); + void get_post_dom_bitmap(function *fun, bitmap nodes, bitmap pds); //post-dom set frontier void get_post_dom_frontier(function *fun, bitmap pds, bitmap pdf); diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp index b0a2a163db7142437337a19b0f9de6586263e0a1..74baed20a5b5f719bb66a04226424774c76497f1 100644 --- a/src/pass_mpi_collective.cpp +++ b/src/pass_mpi_collective.cpp @@ -57,12 +57,18 @@ bool pass_mpi_collective::gate(function *fun) unsigned int pass_mpi_collective::execute(function *fun) { + // need because pass objectis reused + for (int i = 0; i < LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; ++i) + { + collective_max_rank[i] = 0; + } + printf("In execute of: %s\n", function_name(fun)); - print_tree(fun); + //print_tree(fun); split_blocks(fun); - printf("\t--------------------------[split]---------------------------\n"); - print_tree(fun); + //printf("\t--------------------------[split]---------------------------\n"); + //print_tree(fun); alloc_bb_aux(fun); label_collec(fun); @@ -594,6 +600,8 @@ void pass_mpi_collective::__rank_collective(basic_block bb) collective_max_rank[mpi_code] = std::max(collective_max_rank[mpi_code], ((bb_data *) bb->aux)->collective_rank[mpi_code]); + //printf("collective max rank for %i up to %i\n", + // mpi_code, collective_max_rank[mpi_code]); } } } @@ -653,29 +661,49 @@ int pass_mpi_collective::__better_rank_collective(basic_block bb, return next_rank; } -bool pass_mpi_collective::__is_post_dom_mpi_coll_rank(function *fun, - basic_block bb, int rank, int mpi_code, bitmap pds) +void pass_mpi_collective::get_mpi_coll_rank(function *fun, + int rank, int mpi_code, bitmap mpi_coll) +{ + basic_block bb; + + FOR_ALL_BB_FN(bb, fun) + { + if (((bb_data *) bb->aux)->mpi_code == mpi_code + && ((bb_data *) bb->aux)->collective_rank[mpi_code] == rank) + { + //printf("bb %i is coll %i of rank %i\n", + // bb->index, mpi_code, rank); + bitmap_set_bit(mpi_coll, bb->index); + } + } +} + +void pass_mpi_collective::__is_post_dom_bitmap(function *fun, + basic_block bb, bitmap nodes, bitmap pds) { edge e; edge_iterator ei; - bool is_pd_by_set;//is postdominated by set - int count_edges;// nb. of succs that are not loop. + domination_status bb_dom_status; + domination_status cursor_dom_status; //printf("entered bb->index : %i\n",bb->index); ((bb_data *) bb->aux)->mark1 = 1; - // if we are on an MPI collective of the requiered rank. - if (((bb_data *) bb->aux)->mpi_code == mpi_code - && ((bb_data *) bb->aux)->collective_rank[mpi_code] - == rank) //if we are in the pd set + if (bitmap_bit_p(nodes, bb->index)) { - //printf("They are my people, %i is 1\n", bb->index); bitmap_set_bit(pds, bb->index); - return true; + ((bb_data *) bb->aux)->dom_status = DOMINATED; + return; } - is_pd_by_set = true; - count_edges = 0; + if (EXIT_BLOCK_PTR_FOR_FN(fun) == bb) + { + ((bb_data *) bb->aux)->dom_status = NOT_DOMINATED; + return; + } + + // in case we are in a leaf it will return NOT_APPLICABLE + bb_dom_status = NOT_APPLICABLE; FOR_EACH_EDGE(e, ei, bb->succs) { @@ -685,44 +713,37 @@ bool pass_mpi_collective::__is_post_dom_mpi_coll_rank(function *fun, continue; //if marked as a loop or already visited, ignore } - count_edges++; - //printf("%i: %i\n",bb->index, count_edges); - // cache or travell - if (((bb_data *) e->dest->aux)->mark1) + if (! ((bb_data *) e->dest->aux)->mark1) { - //printf("node %i already visited.. jumping out...\n", - // e->dest->index); - is_pd_by_set = is_pd_by_set && bitmap_bit_p(pds, e->dest->index); + __is_post_dom_bitmap(fun, e->dest, nodes, pds); } - else + + cursor_dom_status = ((bb_data *) e->dest->aux)->dom_status; + + if (cursor_dom_status == NOT_DOMINATED) { - is_pd_by_set = - __is_post_dom_mpi_coll_rank(fun, e->dest, rank, mpi_code, pds) - && is_pd_by_set; + bb_dom_status = NOT_DOMINATED; + } + else if (cursor_dom_status == DOMINATED && bb_dom_status != NOT_DOMINATED) + { + bb_dom_status = DOMINATED; } } - if (count_edges == 0) - { - //printf("Leaf ; %i is 0\n", bb->index); - return false; //we are in a leaf - } - - if (is_pd_by_set) + if (bb_dom_status == DOMINATED) { // add the bb to the pdset if it is post dominated by set bitmap_set_bit(pds, bb->index); } - //printf("I now know that %i is %b\n", bb->index, is_pd_by_set); - return is_pd_by_set; + ((bb_data *) bb->aux)->dom_status = bb_dom_status; } -void pass_mpi_collective::get_post_dom_mpi_coll_rank(function *fun, - int rank, int mpi_code, bitmap pds) +void pass_mpi_collective::get_post_dom_bitmap(function *fun, + bitmap nodes, bitmap pds) { - __is_post_dom_mpi_coll_rank(fun, ENTRY_BLOCK_PTR_FOR_FN(fun), - rank, mpi_code, pds); + __is_post_dom_bitmap(fun, ENTRY_BLOCK_PTR_FOR_FN(fun), + nodes, pds); reset_bb_mark(fun); } @@ -761,41 +782,60 @@ void pass_mpi_collective::raise_warning_if_mpi_wrong(function *fun) { bitmap_head pds_head; bitmap_head pdf_head; + bitmap_head nodes_head; + bitmap pds = &pds_head; bitmap pdf = &pdf_head; + bitmap nodes = &nodes_head; bitmap tmp = NULL; bitmap_initialize(pds, &bitmap_default_obstack); bitmap_initialize(pdf, &bitmap_default_obstack); + bitmap_initialize(nodes, &bitmap_default_obstack); int stop = 0; for (int i = 1 ; i < collective_max_rank[mpi_code] + 1 ; i++) { printf("mpi_code: %i at rank: %i\n", mpi_code, i); - // TODO: split in 2, get mpi set & find set post dom - get_post_dom_mpi_coll_rank(fun, i, mpi_code, pds); + // DONE: split in 2, get mpi set & find set post dom + get_mpi_coll_rank(fun, i, mpi_code, nodes); + get_post_dom_bitmap(fun, nodes, pds); + get_post_dom_frontier(fun, pds, pdf); - while (! bitmap_empty_p(pds)) + printf("----\n"); + debug_bitmap(nodes); + debug_bitmap(pds); + debug_bitmap(pdf); + + while (! bitmap_empty_p(pdf)) { stop++; if (stop > 10) { return; } - get_post_dom_frontier(fun, pds, pdf); - printf("----\n"); - debug_bitmap(pds); - debug_bitmap(pdf); + printf("WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + // print warning here + bitmap_clear(nodes); bitmap_clear(pds); - // swap pds & pdf + // swap nodes & pdf { - tmp = pdf; - pdf = pds; - pds = tmp; + tmp = nodes; + nodes = pdf; + pdf = tmp; } - // pds = + get_post_dom_bitmap(fun, nodes, pds); + get_post_dom_frontier(fun, pds, pdf); + + printf("----\n"); + debug_bitmap(nodes); + debug_bitmap(pds); + debug_bitmap(pdf); } + bitmap_clear(nodes); + bitmap_clear(pds); + bitmap_clear(pdf); } } } diff --git a/src/plugin.cpp b/src/plugin.cpp index 29cc8aa906d072fe2ab98e6560c1506f3710e29d..7c3a517fc8b7a1ac7123d585e3e12a97b3c79c9a 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -13,10 +13,8 @@ /* Global variable required for plugin to execute */ int plugin_is_GPL_compatible; -/* Main entry point for plugin */ -int -plugin_init(struct plugin_name_args *plugin_info, - struct plugin_gcc_version *version) +void print_plugin_infos(struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) { printf("plugin_init: Entering...\n"); printf("\tbasever = %s\n", version->basever); @@ -33,6 +31,20 @@ plugin_init(struct plugin_name_args *plugin_info, printf("\tversion = %s\n", plugin_info->version); printf("\thelp = %s\n", plugin_info->help); printf("\n\n"); +} + +/* Main entry point for plugin */ +int +plugin_init(struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + bool debug; + debug = false; + + if (debug) + { + print_plugin_infos(plugin_info, version); + } pass_mpi_collective p(g);