Skip to content
Extraits de code Groupes Projets
Valider 2d9239c5 rédigé par Nicolas MARIE's avatar Nicolas MARIE
Parcourir les fichiers

add dominance fnction and reformat

parent f784e801
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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);
......
......@@ -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);
}
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]
}
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]
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter