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

add dominance frontier compute

parent 8404639a
Branches
Étiquettes
Aucune requête de fusion associée trouvée
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
#include <gcc-plugin.h> #include <gcc-plugin.h>
// declare opt_pass // declare opt_pass
#include <tree-pass.h> #include <tree-pass.h>
// vector // set
#include <vector> #include <set>
/* Enum to represent the collective operations */ /* Enum to represent the collective operations */
#define DEFMPICOLLECTIVES(CODE, NAME) CODE, #define DEFMPICOLLECTIVES(CODE, NAME) CODE,
...@@ -25,10 +25,10 @@ const char *const mpi_collective_name[] = ...@@ -25,10 +25,10 @@ const char *const mpi_collective_name[] =
struct bb_data struct bb_data
{ {
mpi_collective_code mpi_code; mpi_collective_code mpi_code;
std::vector<basic_block> dom; std::set<basic_block> dom;
std::vector<basic_block> post_dom; std::set<basic_block> post_dom;
std::vector<basic_block> dom_front; std::set<basic_block> dom_front;
std::vector<basic_block> post_dom_front; std::set<basic_block> post_dom_front;
}; };
class pass_mpi_collective : public opt_pass class pass_mpi_collective : public opt_pass
...@@ -59,6 +59,8 @@ public: ...@@ -59,6 +59,8 @@ public:
// calculate dominances // calculate dominances
void label_dom(function *fun); void label_dom(function *fun);
void compute_dominance_frontiers(function *fun);
void compute_post_dominance_frontiers(function *fun);
void free_dom_data(); void free_dom_data();
private: private:
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include <gimple-iterator.h> #include <gimple-iterator.h>
// basename // basename
#include <filesystem> #include <filesystem>
// vector // set
#include <vector> #include <set>
// our pass // our pass
#include "pass_mpi_collective.hpp" #include "pass_mpi_collective.hpp"
...@@ -59,6 +59,8 @@ unsigned int pass_mpi_collective::execute(function *fun) ...@@ -59,6 +59,8 @@ unsigned int pass_mpi_collective::execute(function *fun)
alloc_bb_aux(fun); alloc_bb_aux(fun);
label_collec(fun); label_collec(fun);
label_dom(fun); label_dom(fun);
compute_dominance_frontiers(fun);
compute_post_dominance_frontiers(fun);
cfgviz_dump(fun, "_split"); cfgviz_dump(fun, "_split");
free_dom_data(); free_dom_data();
...@@ -245,7 +247,7 @@ void pass_mpi_collective::label_dom(function *fun) ...@@ -245,7 +247,7 @@ void pass_mpi_collective::label_dom(function *fun)
{ {
if (dom_gccvec[i]->index != bb->index) if (dom_gccvec[i]->index != bb->index)
{ {
data->dom.push_back(dom_gccvec[i]); data->dom.insert(dom_gccvec[i]);
} }
} }
...@@ -261,7 +263,7 @@ void pass_mpi_collective::label_dom(function *fun) ...@@ -261,7 +263,7 @@ void pass_mpi_collective::label_dom(function *fun)
{ {
if (post_dom_gccvec[i]->index != bb->index) if (post_dom_gccvec[i]->index != bb->index)
{ {
data->post_dom.push_back(post_dom_gccvec[i]); data->post_dom.insert(post_dom_gccvec[i]);
} }
} }
//for (basic_block bb2 : *post_dom) //for (basic_block bb2 : *post_dom)
...@@ -272,6 +274,72 @@ void pass_mpi_collective::label_dom(function *fun) ...@@ -272,6 +274,72 @@ void pass_mpi_collective::label_dom(function *fun)
} }
} }
void pass_mpi_collective::compute_dominance_frontiers(function *fun)
{
edge p;
edge_iterator ei;
basic_block b;
FOR_EACH_BB_FN(b, fun)
{
if (EDGE_COUNT(b->preds) >= 2)
{
basic_block domsb = get_immediate_dominator(CDI_DOMINATORS, b);
FOR_EACH_EDGE(p, ei, b->preds)
{
basic_block runner = p->src;
if (runner == ENTRY_BLOCK_PTR_FOR_FN(fun))
{
continue;
}
while (runner != domsb)
{
bb_data *data = (bb_data *) runner->aux;
if (data->dom_front.count(b) > 0)
{
break;
}
data->dom_front.insert(b);
runner = get_immediate_dominator(CDI_DOMINATORS, runner);
}
}
}
}
}
void pass_mpi_collective::compute_post_dominance_frontiers(function *fun)
{
edge p;
edge_iterator ei;
basic_block b;
FOR_EACH_BB_FN(b, fun)
{
if (EDGE_COUNT(b->succs) >= 2)
{
basic_block domsb = get_immediate_dominator(CDI_POST_DOMINATORS, b);
FOR_EACH_EDGE(p, ei, b->succs)
{
basic_block runner = p->dest;
if (runner == EXIT_BLOCK_PTR_FOR_FN(fun))
{
continue;
}
while (runner != domsb)
{
bb_data *data = (bb_data *) runner->aux;
if (data->post_dom_front.count(b) > 0)
{
break;
}
data->post_dom_front.insert(b);
runner = get_immediate_dominator(CDI_POST_DOMINATORS, runner);
}
}
}
}
}
void pass_mpi_collective::free_dom_data() void pass_mpi_collective::free_dom_data()
{ {
free_dominance_info(CDI_DOMINATORS); free_dominance_info(CDI_DOMINATORS);
...@@ -342,6 +410,26 @@ void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out) ...@@ -342,6 +410,26 @@ void pass_mpi_collective::cfgviz_internal_dump(function *fun, FILE *out)
fprintf(out, ")"); fprintf(out, ")");
} }
if (! data->dom_front.empty())
{
fprintf(out, "|dom_front(");
for (basic_block bb2 : data->dom_front)
{
fprintf(out, "%d,", bb2->index);
}
fprintf(out, ")");
}
if (! data->post_dom_front.empty())
{
fprintf(out, "|post_dom_front(");
for (basic_block bb2 : data->post_dom_front)
{
fprintf(out, "%d,", bb2->index);
}
fprintf(out, ")");
}
fprintf(out, "\" shape=ellipse]\n"); fprintf(out, "\" shape=ellipse]\n");
FOR_EACH_EDGE(e, eit, bb->succs) 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.
Veuillez vous inscrire ou vous pour commenter