diff --git a/include/mpi_collective.hpp b/include/mpi_collective.hpp index b5b471231e84bed5dfd58a3c109e6c895e725d58..e9e3bc15681a3057e3c86eb6f428ad750cce3ed8 100644 --- a/include/mpi_collective.hpp +++ b/include/mpi_collective.hpp @@ -151,11 +151,14 @@ public: // // mpi collective pragma -// +//gcc wrapper for pragma* void register_mpicoll_check_pragma(void *event_data, void *data); +//reading pragmas and adding them to fun_vec and loc_vec void mpicoll_check_pragma(cpp_reader *); +//raising warning for unprocessed fun in pragma and freeing memory void verify_mpicoll_list(void *event_data, void *data); -extern vec<tree> fun_vec; //function vector in pragma. +extern vec<tree> *fun_vec; //function vector in pragma. +extern vec<location_t> *loc_vec; //function of the location of the token #endif diff --git a/src/mpi_collective_pass.cpp b/src/mpi_collective_pass.cpp index 6325e9321911b3909ff17395ab1dfd9fbe3327bd..a258da5771123ce5a1d6bd3e716c17d9e3b48f88 100644 --- a/src/mpi_collective_pass.cpp +++ b/src/mpi_collective_pass.cpp @@ -8,7 +8,8 @@ #include <gimple.h> // gsi #include <gimple-iterator.h> - +//strcmp +#include <string.h> // our pass #include "mpi_collective.hpp" @@ -43,8 +44,10 @@ pass_mpi_collective *pass_mpi_collective::clone() bool pass_mpi_collective::gate(function *fun) { - (void) fun; - //printf("In gate of: %s\n", function_name(fun)); + //{ printf("In gate of: %s\n", function_name(fun)); } + //iterating over our fun_vec seeing if fun is in there.. by comparing strings + //tree x; + (void) fun; //warning shut-up return true; } @@ -58,6 +61,20 @@ unsigned int pass_mpi_collective::execute(function *fun) collective_max_rank[i] = 0; } + bool to_process = false; + tree x; + for (unsigned int ix = 0; fun_vec->iterate(ix, &x); ix++) + { + if (!strcmp(IDENTIFIER_POINTER(x), function_name(fun))) + { + printf("Verifying %s...\n", function_name(fun)); + to_process = true; + } + } + + if (!to_process) + { return 0; }//skip processing if function not in pragma + //print_tree(fun); split_blocks(fun); //printf("\t--------------------------[split]---------------------------\n"); @@ -92,7 +109,17 @@ unsigned int pass_mpi_collective::execute(function *fun) free_dom_data(); free_bb_aux(fun); free_edge_aux(fun); - + + //remove function that was processed in fun_vec + for (unsigned int ix = 0; fun_vec->iterate(ix, &x); ix++) + { + if (!strcmp(IDENTIFIER_POINTER(x), function_name(fun))) + { + printf("Finished processing %s...\n", function_name(fun)); + fun_vec->ordered_remove(ix); //cannot do unordered due to locations.. sry + loc_vec->ordered_remove(ix); + } + } return 0; } diff --git a/src/mpi_collective_pragma.cpp b/src/mpi_collective_pragma.cpp index d89c3af15bf1dd3f4b51b9fb984d14ce49a1295d..2807741db571c22975831b9ae89f1d1c7a55e50e 100644 --- a/src/mpi_collective_pragma.cpp +++ b/src/mpi_collective_pragma.cpp @@ -17,7 +17,7 @@ void register_mpicoll_check_pragma(void *event_data, void *data) { (void) event_data; (void) data; - printf("registering pragma: \"ProjectCA\"\n"); + //printf("registering pragma: \"ProjectCA\"\n"); c_register_pragma("ProjetCA", "mpicoll_check", mpicoll_check_pragma); } @@ -25,27 +25,29 @@ void register_mpicoll_check_pragma(void *event_data, void *data) void print_fun_vec() { tree x; - for (unsigned int ix=0;fun_vec.iterate(ix, &x);ix++) + for (unsigned int ix = 0; fun_vec->iterate(ix, &x); ix++) { - printf("%s ",IDENTIFIER_POINTER(x)); + printf("%s ", IDENTIFIER_POINTER(x)); } - printf("\n%i",fun_vec.length()); + printf("\n%i", fun_vec->length()); printf("\n"); } //add x if not present in fun_vec -void add_to_fun_vec(tree x) +void add_to_fun_vec(tree x, location_t loc) { - //verify if a newly added name is not already present in fun_vec. + //verify if a newly added name is not already present in fun_vec-> //raise warning if so. - if (fun_vec.contains(x)) + if (fun_vec->contains(x)) { - warning (0,"repetition of function name %s in pragma" - , IDENTIFIER_POINTER(x)); + warning_at (loc,0 + , "repetition of function name %<%s%> in %<#pragma ProjetCA mpicoll_check%>" + , IDENTIFIER_POINTER(x)); return; - } - fun_vec.quick_push(x); -} + } + fun_vec->safe_push(x); + loc_vec->safe_push(loc); +} //By "taking inspiration", I just cc/cv and modified what was needed for //our needs. @@ -55,13 +57,12 @@ void mpicoll_check_pragma(cpp_reader *) enum cpp_ttype token; tree x; bool close_paren_needed_p = false; - + //not possible to use pragma inside function if (cfun) { error_at (cfun->function_start_locus - , "pragma ProjetCA %s is not allowed inside functions" - , "mpicoll_check"); + , "%<#pragma ProjetCA mpicoll_check%> is not allowed inside functions"); return; } @@ -78,84 +79,65 @@ void mpicoll_check_pragma(cpp_reader *) /* Strings are user options. */ else { - //tree args = NULL_TREE; - do { /* Build up the strings now as a tree linked list. Skip empty strings. */ - if (IDENTIFIER_LENGTH (x) > 0) - //I have no idea what type is CPP_NAME; But it doesn't seem to create - //a string since TREE_STRING_LENGTH fails ; IDENTIFIER_LENGTH works - //just fine for what we want. - // - //The Tree structure stuff is a mess. - { + if (IDENTIFIER_LENGTH (x) > 0) + //IDENTIFIER_LENGTH works + //just fine for just checking if we have a non-null token thingy here + { if (token != CPP_NAME) { //turns out this never happens.. - warning_at (loc, 0,"Unrecognized name %s", IDENTIFIER_POINTER(x)); + warning_at (loc, 0, "Unrecognized name %s", IDENTIFIER_POINTER(x)); } - //args = tree_cons (NULL_TREE, x, args); - inform (loc, "Registering name %s", IDENTIFIER_POINTER(x)); - add_to_fun_vec(x); + //inform (loc, "Registering name %s", IDENTIFIER_POINTER(x)); + add_to_fun_vec(x,loc); print_fun_vec(); } - token = pragma_lex (&x); + token = pragma_lex (&x,&loc); while (token == CPP_COMMA) - { token = pragma_lex (&x); } + { token = pragma_lex (&x,&loc); } } while (token == CPP_NAME); if (close_paren_needed_p) { if (token == CPP_CLOSE_PAREN) - { token = pragma_lex (&x,&loc); } + { token = pragma_lex (&x, &loc); } else - error ("%<#pragma ProjetCA %s (string [,string]...)%> does " - "not have a final %<)%>", "mpicoll_check"); + error ("%<#pragma ProjetCA mpicoll_check (string [,string]...)%> does " + "not have a final %<)%>"); } if (token != CPP_EOF) { - error_at (loc,"%<#pragma ProjetCA %s%> string is badly formed" - , "mpicoll_check"); + error_at (loc + , "%<#pragma ProjetCA mpicoll_check%> string is badly formed"); return; } - - /* put arguments in the order the user typed them. */ - //args = nreverse (args); } } -/* OLD - TODO : delete this -void mpicoll_check_pragma(cpp_reader *) -{ - location_t loc; - cpp_ttype token; - tree x; - - // on a pas acces a la fonction courante sans passer par cfun - if (cfun) - { - error_at (cfun->function_start_locus - , "pragma ProjectCA %s is not allowed inside functions" - , "mpicoll_check"); - return; - } - - token = pragma_lex(&x, &loc); - if (token == CPP_NAME) - { - printf("adding %s to function to parse.\n", IDENTIFIER_POINTER(x)); - } -} -*/ - void verify_mpicoll_list(void *event_data, void *data) { (void) event_data; (void) data; - printf("In verify mpicoll list\n"); + //printf("There are %i elm left in fun_vec\n",fun_vec->length()); + + //if there a still functions in fun_vec, it means it was not found + //while processing ; warn user about that. + tree x; + if (!fun_vec->is_empty()) + { + for (unsigned int ix = 0; fun_vec->iterate(ix, &x); ix++) + { + warning_at ((*loc_vec)[ix], 0 + , "function %<%s%> was declared in a %<#pragma ProjetCA mpicoll_check%> but not found in file", IDENTIFIER_POINTER(x)); + } + } + fun_vec->release(); + loc_vec->release(); } diff --git a/src/mpi_collective_warnings.cpp b/src/mpi_collective_warnings.cpp index 5f33a295b663a922bb870806a511e618a7e3fcca..522787afb89d15fcb35017cbd9fe7a368783f9a7 100644 --- a/src/mpi_collective_warnings.cpp +++ b/src/mpi_collective_warnings.cpp @@ -231,7 +231,7 @@ void pass_mpi_collective::raise_warning_mpi_rank(function *fun) get_first_non_mpi_stmt(get_bb_from_index(fun, bb_pdf_indx_stack.top()))); warning_at (loc , 0 - , "The MPI Collective %s(%i) might be unmatched in some MPI processes, diverging from here:" + , "The MPI Collective %<%s%>(%i) might be unmatched in some MPI processes, diverging from here:" , mpi_collective_name[mpi_code], rank); bb_pdf_indx_stack.pop(); @@ -239,7 +239,7 @@ void pass_mpi_collective::raise_warning_mpi_rank(function *fun) { loc = gimple_location( get_mpi_stmt(get_bb_from_index(fun, bb_call_indx_stack.top()))); - inform (loc, "MPI collective %s(%i) called here." + inform (loc, "MPI collective %<%s%>(%i) called here." , mpi_collective_name[mpi_code], rank); bb_call_indx_stack.pop(); } @@ -346,7 +346,7 @@ void pass_mpi_collective::raise_warning_mpi_order(function *fun) warning_at (loc , 0 - , "MPI Collective %s(%i) might not be reachable due to a precedent %s call:" + , "MPI Collective %<%s%>(%i) might not be reachable due to a precedent %<%s%> call:" , mpi_collective_name[mpi_code] , rank, mpi_collective_name[cursor_code]); @@ -357,7 +357,7 @@ void pass_mpi_collective::raise_warning_mpi_order(function *fun) loc = gimple_location( get_mpi_stmt(get_bb_from_index(fun, index))); inform (loc - , "reachable %s(%i) without a prior %s call:" + , "reachable %<%s%>(%i) without a prior %<%s%> call:" , mpi_collective_name[mpi_code] , rank, mpi_collective_name[cursor_code]); } diff --git a/src/plugin.cpp b/src/plugin.cpp index edd224189f3aaf9f7f123e9b5f4e910be0aa65d8..c25775cc0f332592d07230c3b9067cfa751b67d1 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -33,7 +33,8 @@ void print_plugin_infos(struct plugin_name_args *plugin_info, printf("\n\n"); } -vec<tree> fun_vec; +vec<tree> *fun_vec; +vec<location_t> *loc_vec; /* Main entry point for plugin */ int @@ -49,6 +50,12 @@ plugin_init(struct plugin_name_args *plugin_info, } pass_mpi_collective p(g); + //irresponsible code + fun_vec = new vec<tree>; + loc_vec = new vec<location_t>; + fun_vec->create(0); + loc_vec->create(0); + //fun_vec.release(); //FIXME release memory in last callback struct register_pass_info pass_info; @@ -61,9 +68,8 @@ plugin_init(struct plugin_name_args *plugin_info, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info); - - fun_vec.create(1); - //fun_vec.quick_grow_cleared(20); + + register_callback(plugin_info->base_name, PLUGIN_PRAGMAS, register_mpicoll_check_pragma, @@ -73,6 +79,6 @@ plugin_init(struct plugin_name_args *plugin_info, PLUGIN_FINISH_UNIT, verify_mpicoll_list, NULL); - //fun_vec.release(); //FIXME release memory in last pass + return 0; } diff --git a/src/test/test.c b/src/test/test.c index c4be068f00b67b6ae241adf745700803b26f48c3..b4571fad4ae13b03440b5a8c8bd92922247fb294 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -3,6 +3,8 @@ #include <mpi.h> +#pragma ProjetCA mpicoll_check main mpi_call + void mpi_call(int c) { MPI_Barrier(MPI_COMM_WORLD); diff --git a/src/test/test2.c b/src/test/test2.c index ee2edf07ee44cf6a77b79e0090cc04a357ae950a..bad6fc77c647d0fab8eb5c7201669b8fe6e6966f 100644 --- a/src/test/test2.c +++ b/src/test/test2.c @@ -3,6 +3,8 @@ #include <mpi.h> +#pragma ProjetCA mpicoll_check main mpi_call + void mpi_call(int c) { MPI_Barrier(MPI_COMM_WORLD); diff --git a/src/test/test3.c b/src/test/test3.c index cf8758f6db3c4bcbe49b4fc2bc371540b76bfaef..88b6bf42abe0594893b58b5c6b3ea545c5841c71 100644 --- a/src/test/test3.c +++ b/src/test/test3.c @@ -3,6 +3,7 @@ #include <mpi.h> +#pragma ProjetCA mpicoll_check main int main(int argc, char * argv[]) { diff --git a/src/test/test4.c b/src/test/test4.c index 969e1bebbfd349b6b2be240975f60a76f6dbf2a2..2364f32613aa74c325b29eb100f6b7c045da3dd4 100644 --- a/src/test/test4.c +++ b/src/test/test4.c @@ -1,5 +1,6 @@ #include <mpi.h> +#pragma ProjetCA mpicoll_check main int main(int argc, char **argv) { diff --git a/src/test/test_pragma2.c b/src/test/test_pragma2.c index 31bd1733b327fc8f38a760786c87de9f3f96b02d..b7771d04e5846c7c01d152ac9b95400faee0815e 100644 --- a/src/test/test_pragma2.c +++ b/src/test/test_pragma2.c @@ -1,9 +1,9 @@ -#pragma ProjetCA mpicoll_check (main,nothingdoing,bab,,bab,) +#pragma ProjetCA mpicoll_check (main,nothing,noexstingfun,,noexstingfun,) int main(){ return 0; } -void nothingdoing(){ +void nothing(){ }