diff --git a/include/pass_mpi_collective.hpp b/include/pass_mpi_collective.hpp index 3da54fb6a547b8e588855e5e242f3fc1cfbd2b9d..976856638334b81a6659cf566c2f2df86d9e9c58 100644 --- a/include/pass_mpi_collective.hpp +++ b/include/pass_mpi_collective.hpp @@ -32,18 +32,28 @@ public: unsigned int execute(function *fun); void print_tree(function *fun); + + // MPI function / collectives detections bool is_func(gimple *stmt); bool is_mpi_func(gimple *stmt); mpi_collective_code is_mpi_collec(gimple *stmt); + + // split blocks according to mpi collectives void split_blocks(function *fun); + // gestions des aux void label_bb(function *fun); - void clean_aux(function *fun); + void clean_bb(function *fun); + + // calculate dominances + void dominance(function *fun); private: + // MPI function / collectives detections bool __is_mpi_func(gimple *stmt); mpi_collective_code __is_mpi_collec(gimple *stmt); + // GRAPHVIZ char *cfgviz_generate_filename(function *fun, const char *suffix); void cfgviz_internal_dump(function *fun, FILE *out); diff --git a/src/pass_mpi_collective.cpp b/src/pass_mpi_collective.cpp index bfca0c49a4b58954b5bee363321afe298b7cb47b..0cab788e6770d92c8ff8b1704caf59104194abe3 100644 --- a/src/pass_mpi_collective.cpp +++ b/src/pass_mpi_collective.cpp @@ -33,7 +33,9 @@ pass_mpi_collective::pass_mpi_collective(gcc::context *ctxt) : opt_pass(my_pass_data, ctxt) {} pass_mpi_collective *pass_mpi_collective::clone() -{return new pass_mpi_collective(g);} +{ + return new pass_mpi_collective(g); +} bool pass_mpi_collective::gate(function *fun) { @@ -49,11 +51,12 @@ unsigned int pass_mpi_collective::execute(function *fun) print_tree(fun); split_blocks(fun); - printf("\t------------------------------[split]-------------------------------\n"); + printf("\t--------------------------[split]---------------------------\n"); print_tree(fun); + label_bb(fun); cfgviz_dump(fun, "_split"); - clean_aux(fun); + clean_bb(fun); return 0; } @@ -92,16 +95,22 @@ void pass_mpi_collective::print_tree(function *fun) } } - +// MPI function / collectives detections bool pass_mpi_collective::is_func(gimple *stmt) -{return is_gimple_call(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;} +{ + 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);} +{ + return is_func(stmt) && __is_mpi_func(stmt); +} mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt) { @@ -110,11 +119,12 @@ mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt) 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; } + { + return (enum mpi_collective_code) i; + } ++i; } return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; @@ -123,19 +133,13 @@ mpi_collective_code pass_mpi_collective::__is_mpi_collec(gimple *stmt) mpi_collective_code pass_mpi_collective::is_mpi_collec(gimple *stmt) { if (!is_mpi_func(stmt)) - { return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; } + { + return LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; + } return __is_mpi_collec(stmt); } -// TODO tag blocks and set bb->data -//void pass_mpi_collective::tag_blocks(){ - -//} - -// TODO clear blocks TAGs -//void pass_mpi_collective::clear_blocks_tag(){ - -//} +// split blocks according to mpi collectives void pass_mpi_collective::split_blocks(function *fun) { @@ -156,74 +160,124 @@ void pass_mpi_collective::split_blocks(function *fun) prev_stmt = stmt; stmt = gsi_stmt(gsi); if (is_mpi_collec(stmt) != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) - { ++nb_collective; } + { + ++nb_collective; + } if (nb_collective >= 2) { split_block(bb, prev_stmt); split = true; - //The inner for doesn't stop naturally, whereas the FOR_EACH_BB_FN - //*will* iterate on the new bb we just split. hence the split=true + //The inner for doesn't stop naturally, whereas the + //FOR_EACH_BB_FN *will* iterate on the new bb we just split. + //hence the split=true } } } } -/* Build a filename (as a string) based on function name */ -char *pass_mpi_collective::cfgviz_generate_filename(function *fun, - const char *suffix) -{ - char *target_filename; - - target_filename = (char *)xmalloc(1024 * sizeof(char)); - int line = LOCATION_LINE(fun->function_start_locus); - const char *mfilename = - std::filesystem::path(LOCATION_FILE(fun->function_start_locus)) - .filename().c_str(); - - snprintf(target_filename, 1024, "%s%s_%s_%d_%s.dot", - "dot/", - mfilename, - function_name(fun), - line, - suffix); - - return target_filename; -} +// gestions des aux void pass_mpi_collective::label_bb(function *fun) { basic_block bb; gimple_stmt_iterator gsi; gimple *stmt; - //size_t line; 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)) { stmt = gsi_stmt(gsi); int mpi_code = is_mpi_collec(stmt); if (mpi_code != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE) - {bb->aux = (void *) (new int(mpi_code));} + { + bb->aux = (void *) (new int(mpi_code)); + } } } } -void pass_mpi_collective::clean_aux(function *fun) +void pass_mpi_collective::clean_bb(function *fun) { basic_block bb; FOR_ALL_BB_FN(bb, fun) { if (bb->aux != NULL) - {delete (int *) bb->aux; bb->aux = NULL;} + { + delete (int *) bb->aux; + bb->aux = NULL; + } + } +} + +// calculate dominance +void pass_mpi_collective::dominance(function *fun) +{ + basic_block bb; + auto_vec<basic_block> dominated; + auto_vec<basic_block> post_dominated; + size_t size_dom; + size_t size_post_dom; + + calculate_dominance_info(CDI_POST_DOMINATORS); + calculate_dominance_info(CDI_DOMINATORS); + + FOR_ALL_BB_FN(bb, fun) + { + dominated = get_all_dominated_blocks(CDI_DOMINATORS, bb); + size_dom = dominated.length(); + for (size_t i = 0; i < size_dom; ++i) + { + if (dominated[i]->index != bb->index) + { + printf("%d domine %d\n", + bb->index, dominated[i]->index); + } + } + + post_dominated = get_all_dominated_blocks(CDI_POST_DOMINATORS, bb); + size_post_dom = post_dominated.length(); + for (size_t i = 0; i < size_post_dom; ++i) + { + if (post_dominated[i]->index != bb->index) + { + printf("%d post domine %d\n", + bb->index, post_dominated[i]->index); + } + } } + + free_dominance_info(CDI_DOMINATORS); + free_dominance_info(CDI_POST_DOMINATORS); } //============================ GRAPHVIZ ===================================== + +/* Build a filename (as a string) based on function name */ +char *pass_mpi_collective::cfgviz_generate_filename(function *fun, + const char *suffix) +{ + char *target_filename; + int line; + + target_filename = (char *)xmalloc(1024 * sizeof(char)); + line = LOCATION_LINE(fun->function_start_locus); + const char *mfilename = + std::filesystem::path(LOCATION_FILE(fun->function_start_locus)) + .filename().c_str(); + + snprintf(target_filename, 1024, "%s%s_%s_%d_%s.dot", + "dot/", + mfilename, + function_name(fun), + line, + 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) +void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out) { basic_block bb; mpi_collective_code code; @@ -231,12 +285,13 @@ void pass_mpi_collective::cfgviz_internal_dump( edge e; fprintf(out, "Digraph G{\n"); - FOR_ALL_BB_FN(bb, fun) { code = LAST_AND_UNUSED_MPI_COLLECTIVE_CODE; if (bb->aux != NULL) - { code = *((mpi_collective_code *) bb->aux); } + { + code = *((mpi_collective_code *) bb->aux); + } fprintf(out, "%d [label=\"BB %d %s\" shape=ellipse]\n", bb->index, bb->index, @@ -247,15 +302,18 @@ void pass_mpi_collective::cfgviz_internal_dump( { const char *label = ""; if (e->flags == EDGE_TRUE_VALUE) - { label = "true"; } + { + label = "true"; + } else if (e->flags == EDGE_FALSE_VALUE) - { label = "false"; } + { + label = "false"; + } fprintf(out, "%d -> %d [color=red label=\"%s\"]\n", bb->index, e->dest->index, label); } } - fprintf(out, "}\n"); } @@ -277,4 +335,3 @@ void pass_mpi_collective::cfgviz_dump(function *fun, fclose(out); free(target_filename); } - diff --git a/test2.c b/test2.c deleted file mode 100644 index aebdc6d8c4d4359896f6668105a0a8f8dd629f36..0000000000000000000000000000000000000000 --- a/test2.c +++ /dev/null @@ -1,16 +0,0 @@ -Digraph G{ -0 [label="BB 0 " shape=ellipse] -0 -> 2 [color=red label=""] -2 [label="BB 2 MPI_Init" shape=ellipse] -2 -> 4 [color=red label=""] -3 [label="BB 3 " shape=ellipse] -3 -> 4 [color=red label=""] -4 [label="BB 4 " shape=ellipse] -4 -> 3 [color=red label="true"] -4 -> 5 [color=red label="false"] -5 [label="BB 5 MPI_Finalize" shape=ellipse] -5 -> 6 [color=red label=""] -6 [label="BB 6 " shape=ellipse] -6 -> 1 [color=red label=""] -1 [label="BB 1 " shape=ellipse] -} diff --git a/test3.c b/test3.c deleted file mode 100644 index 0be728d7de6e23706d70faa8d5753772cecb4daf..0000000000000000000000000000000000000000 --- a/test3.c +++ /dev/null @@ -1,33 +0,0 @@ -Digraph G{ -0 [label="BB 0 " shape=ellipse] -0 -> 2 [color=red label=""] -2 [label="BB 2 MPI_Init" shape=ellipse] -2 -> 10 [color=red label=""] -3 [label="BB 3 MPI_Barrier" shape=ellipse] -3 -> 4 [color=red label="true"] -3 -> 8 [color=red label="false"] -4 [label="BB 4 MPI_Barrier" shape=ellipse] -4 -> 13 [color=red label=""] -13 [label="BB 13 MPI_Barrier" shape=ellipse] -13 -> 5 [color=red label="true"] -13 -> 6 [color=red label="false"] -5 [label="BB 5 " shape=ellipse] -5 -> 9 [color=red label=""] -6 [label="BB 6 " shape=ellipse] -6 -> 7 [color=red label="true"] -6 -> 9 [color=red label="false"] -7 [label="BB 7 " shape=ellipse] -7 -> 12 [color=red label=""] -8 [label="BB 8 MPI_Barrier" shape=ellipse] -8 -> 12 [color=red label=""] -9 [label="BB 9 " shape=ellipse] -9 -> 10 [color=red label=""] -10 [label="BB 10 " shape=ellipse] -10 -> 3 [color=red label="true"] -10 -> 11 [color=red label="false"] -11 [label="BB 11 MPI_Finalize" shape=ellipse] -11 -> 12 [color=red label=""] -12 [label="BB 12 " shape=ellipse] -12 -> 1 [color=red label=""] -1 [label="BB 1 " shape=ellipse] -}