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

change dominance system to add dominance infos to graphs

parent 2d9239c5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -40,7 +40,8 @@ OBJS=$(addprefix $(OBJD)/, $(SRCS:cpp=o))
all:
$(MAKE) plugin
$(MAKE) test
$(MAKE) dots
.PHONY: plugin
plugin:
mkdir -p $(OBJD)
......@@ -54,6 +55,11 @@ test:
$(MAKE) $(TESTD)/test2
$(MAKE) $(TESTD)/test3
.PHONY: dots
dots:
touch $(DOTD)/lock.dot
$(MAKE) $(shell find $(DOTD) -name "*.dot" | sed 's/\.dot/\.svg/')
$(TESTD)/%: $(TESTSRCD)/%.c
$(CC) $(TEST_FLAGS) $(PLUGIN_FLAGS) $^ -o $@
......@@ -65,8 +71,8 @@ $(LIBD)/libplugin.so: $(OBJD)/plugin.o $(OBJD)/pass_mpi_collective.o
# removing test scince plugin was rebuild
rm -rf $(TESTD)
%.png: %.dot
dot -Tpng $< -o $@
%.svg: %.dot
dot -Tsvg $< -o $@
.PHONY: clean
clean:
......
......@@ -2,6 +2,8 @@
#include <gcc-plugin.h>
// declare opt_pass
#include <tree-pass.h>
// vector
#include <vector>
/* Enum to represent the collective operations */
#define DEFMPICOLLECTIVES(CODE, NAME) CODE,
......@@ -20,6 +22,15 @@ const char *const mpi_collective_name[] =
};
#undef DEFMPICOLLECTIVES
struct bb_data
{
mpi_collective_code mpi_code;
std::vector<basic_block> dom;
std::vector<basic_block> post_dom;
std::vector<basic_block> dom_front;
std::vector<basic_block> post_dom_front;
};
class pass_mpi_collective : public opt_pass
{
......@@ -42,11 +53,13 @@ public:
void split_blocks(function *fun);
// gestions des aux
void label_bb(function *fun);
void clean_bb(function *fun);
void alloc_bb_aux(function *fun);
void label_collec(function *fun);
void free_bb_aux(function *fun);
// calculate dominances
void dominance(function *fun);
void label_dom(function *fun);
void free_dom_data();
private:
// MPI function / collectives detections
......
......@@ -10,6 +10,8 @@
#include <gimple-iterator.h>
// basename
#include <filesystem>
// vector
#include <vector>
// our pass
#include "pass_mpi_collective.hpp"
......@@ -54,9 +56,13 @@ unsigned int pass_mpi_collective::execute(function *fun)
printf("\t--------------------------[split]---------------------------\n");
print_tree(fun);
label_bb(fun);
alloc_bb_aux(fun);
label_collec(fun);
label_dom(fun);
cfgviz_dump(fun, "_split");
clean_bb(fun);
free_dom_data();
free_bb_aux(fun);
return 0;
}
......@@ -175,78 +181,99 @@ void pass_mpi_collective::split_blocks(function *fun)
}
}
// gestions des aux
void pass_mpi_collective::alloc_bb_aux(function *fun)
{
basic_block bb;
FOR_ALL_BB_FN(bb, fun)
{
bb->aux = (bb_data *) new bb_data();
}
}
void pass_mpi_collective::label_bb(function *fun)
// gestions des aux
void pass_mpi_collective::label_collec(function *fun)
{
basic_block bb;
gimple_stmt_iterator gsi;
gimple *stmt;
mpi_collective_code mpi_code;
FOR_EACH_BB_FN(bb, fun)
FOR_ALL_BB_FN(bb, fun)
{
((bb_data *) bb->aux)->mpi_code = LAST_AND_UNUSED_MPI_COLLECTIVE_CODE;
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));
}
mpi_code = is_mpi_collec(stmt);
((bb_data *) bb->aux)->mpi_code = mpi_code;
}
}
}
void pass_mpi_collective::clean_bb(function *fun)
void pass_mpi_collective::free_bb_aux(function *fun)
{
basic_block bb;
FOR_ALL_BB_FN(bb, fun)
{
if (bb->aux != NULL)
{
delete (int *) bb->aux;
delete (bb_data *) bb->aux;
bb->aux = NULL;
}
}
}
// calculate dominance
void pass_mpi_collective::dominance(function *fun)
void pass_mpi_collective::label_dom(function *fun)
{
basic_block bb;
auto_vec<basic_block> dominated;
auto_vec<basic_block> post_dominated;
auto_vec<basic_block> dom_gccvec;
auto_vec<basic_block> post_dom_gccvec;
size_t size_dom;
size_t size_post_dom;
calculate_dominance_info(CDI_POST_DOMINATORS);
calculate_dominance_info(CDI_DOMINATORS);
calculate_dominance_info(CDI_POST_DOMINATORS);
FOR_ALL_BB_FN(bb, fun)
{
dominated = get_all_dominated_blocks(CDI_DOMINATORS, bb);
size_dom = dominated.length();
bb_data *data = ((bb_data *) bb->aux);
dom_gccvec = get_all_dominated_blocks(CDI_DOMINATORS, bb);
size_dom = dom_gccvec.length();
for (size_t i = 0; i < size_dom; ++i)
{
if (dominated[i]->index != bb->index)
if (dom_gccvec[i]->index != bb->index)
{
printf("%d domine %d\n",
bb->index, dominated[i]->index);
data->dom.push_back(dom_gccvec[i]);
}
}
post_dominated = get_all_dominated_blocks(CDI_POST_DOMINATORS, bb);
size_post_dom = post_dominated.length();
//for (basic_block bb2 : *dom)
//{
// printf("%d dom %d\n", bb->index, bb2->index);
//}
//((bb_data *) bb->aux)->dom = dominated;
post_dom_gccvec = get_all_dominated_blocks(CDI_POST_DOMINATORS, bb);
size_post_dom = post_dom_gccvec.length();
for (size_t i = 0; i < size_post_dom; ++i)
{
if (post_dominated[i]->index != bb->index)
if (post_dom_gccvec[i]->index != bb->index)
{
printf("%d post domine %d\n",
bb->index, post_dominated[i]->index);
data->post_dom.push_back(post_dom_gccvec[i]);
}
}
//for (basic_block bb2 : *post_dom)
//{
// printf("%d post dom %d\n", bb->index, bb2->index);
//}
//((bb_data *) bb->aux)->post_dom = post_dominated;
}
}
void pass_mpi_collective::free_dom_data()
{
free_dominance_info(CDI_DOMINATORS);
free_dominance_info(CDI_POST_DOMINATORS);
}
......@@ -280,23 +307,42 @@ char *pass_mpi_collective::cfgviz_generate_filename(function *fun,
void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out)
{
basic_block bb;
mpi_collective_code code;
edge_iterator eit;
edge e;
fprintf(out, "Digraph G{\n");
FOR_ALL_BB_FN(bb, fun)
{
code = LAST_AND_UNUSED_MPI_COLLECTIVE_CODE;
if (bb->aux != NULL)
bb_data *data = ((bb_data *) bb->aux);
fprintf(out, "%d [label=\"BB %d", bb->index, bb->index);
if (data->mpi_code != LAST_AND_UNUSED_MPI_COLLECTIVE_CODE)
{
fprintf(out, "|%s", mpi_collective_name[data->mpi_code]);
}
if (! data->dom.empty())
{
fprintf(out, "|dom(");
for (basic_block bb2 : data->dom)
{
fprintf(out, "%d,", bb2->index);
}
fprintf(out, ")");
}
if (! data->post_dom.empty())
{
code = *((mpi_collective_code *) bb->aux);
fprintf(out, "|post_dom(");
for (basic_block bb2 : data->post_dom)
{
fprintf(out, "%d,", bb2->index);
}
fprintf(out, ")");
}
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]));
fprintf(out, "\" shape=ellipse]\n");
FOR_EACH_EDGE(e, eit, bb->succs)
{
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter