77 #include <boost/graph/adjacency_list.hpp> 78 #include <boost/graph/graph_utility.hpp> 79 #include <boost/graph/reverse_graph.hpp> 80 #include <boost/version.hpp> 83 using TBB =
unsigned long;
90 template <
typename GraphObj>
97 using Vertex =
typename boost::graph_traits<const GraphObj>::vertex_descriptor;
99 using in_edge_iterator =
typename boost::graph_traits<const GraphObj>::in_edge_iterator;
103 using edge =
typename boost::graph_traits<const GraphObj>::edge_descriptor;
105 using Vertex_iterator =
typename boost::graph_traits<const GraphObj>::vertex_iterator;
198 "-->Computing dfs tree starting from v_" + std::to_string(index_map[bb]));
202 TBB child_i, my_i = 0;
203 typename boost::graph_traits<GraphObj>::out_edge_iterator ei, ei_end;
205 for(boost::tie(ei, ei_end) = boost::out_edges(bb, g); ei != ei_end; ei++)
210 if(dfs_order[index_map[bn]])
218 my_i = dfs_order[index_map[bb]];
226 child_i = dfs_order[index_map[bn]] = dfsnum++;
227 dfs_to_bb[child_i] = bn;
228 dfs_parent[child_i] = my_i;
233 "<--Computed dfs tree starting from v_" + std::to_string(index_map[bb]));
247 TBB parent = set_chain[v];
248 if(set_chain[parent])
251 if(key[path_min[parent]] < key[path_min[v]])
253 path_min[v] = path_min[parent];
255 set_chain[v] = set_chain[parent];
269 TBB rep = set_chain[v];
283 if(key[path_min[rep]] >= key[path_min[v]])
289 return path_min[rep];
303 while(key[path_min[w]] < key[path_min[set_child[s]]])
305 if(set_size[s] + set_size[set_child[set_child[s]]] >= 2 * set_size[set_child[s]])
307 set_chain[set_child[s]] = s;
308 set_child[s] = set_child[set_child[s]];
312 set_size[set_child[s]] = set_size[s];
313 s = set_chain[s] = set_child[s];
316 path_min[s] = path_min[w];
317 set_size[v] += set_size[w];
318 if(set_size[v] < 2 * set_size[w])
341 : dfs_parent(
boost::num_vertices(_g) + 1, 0),
342 key(
boost::num_vertices(_g) + 1, 0),
343 path_min(
boost::num_vertices(_g) + 1, 0),
344 bucket(
boost::num_vertices(_g) + 1, 0),
345 next_bucket(
boost::num_vertices(_g) + 1, 0),
346 set_chain(
boost::num_vertices(_g) + 1, 0),
347 set_size(
boost::num_vertices(_g) + 1, 1),
348 set_child(
boost::num_vertices(_g) + 1, 0),
351 last_basic_block(
boost::num_vertices(_g)),
355 dom(
boost::num_vertices(_g) + 1, 0),
356 dfs_order(
boost::num_vertices(_g) + 1, 0),
357 dfs_to_bb(
boost::num_vertices(_g) + 1,
boost::graph_traits<GraphObj>::null_vertex()),
360 size_t index_counter = 0;
362 for(boost::tie(v, v_end) = boost::vertices(g); v != v_end; v++, index_counter++)
364 index_map[*v] = index_counter;
366 for(
unsigned int i = 0; i < boost::num_vertices(_g) + 1; i++)
385 dfs_to_bb[
dfsnum] = begin;
401 bool saw_unconnected =
false;
404 for(boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; vi++)
412 if(boost::in_degree(b, g) > 0)
414 if(dfs_order[index_map[b]] == 0)
416 saw_unconnected =
true;
420 fake_exit_edge.insert(index_map[b]);
421 dfs_order[index_map[b]] =
dfsnum;
430 for(boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; vi++)
438 if(dfs_order[index_map[b]])
442 fake_exit_edge.insert(index_map[b]);
443 dfs_order[index_map[b]] =
dfsnum;
457 for(boost::tie(i, i_end) = boost::vertices(g); i != i_end; i++)
463 THROW_ASSERT(nodes == counter,
"there is _no_ path from ENTRY to EXIT at all. Number of vertices in the graph: " +
464 std::to_string(num_vertices(g)) +
" Number of reachable from entry vertices " +
465 std::to_string(nodes));
471 "---" + std::to_string(
index) +
" v_" + std::to_string(index_map[dfs_to_bb[
index]]));
486 typename boost::graph_traits<GraphObj>::in_edge_iterator ei, einext, ei_end, einext_end;
493 "-->Analyzing node in position " + std::to_string(v) +
" v_" +
494 std::to_string(index_map[dfs_to_bb[v]]));
497 bool do_fake_exit_edge =
false;
500 TBB par = dfs_parent[v];
503 boost::tie(ei, ei_end) = boost::in_edges(bb, g);
508 if(fake_exit_edge.find(index_map[bb]) != fake_exit_edge.end())
511 do_fake_exit_edge =
true;
519 while(do_fake_exit_edge || ei != ei_end)
523 if(do_fake_exit_edge)
526 do_fake_exit_edge =
false;
531 b = boost::source(e, g);
541 k1 = dfs_order[index_map[b]];
545 "---Predecessor is " + std::to_string(k1) +
" v_" + std::to_string(index_map[b]));
567 next_bucket[v] = bucket[
k];
571 for(w = bucket[par]; w; w = next_bucket[w])
592 for(v = 1; v <=
nodes; v++)
596 dom[v] = dom[dom[v]];
610 for(boost::tie(vi, vi_end) = boost::vertices(g); vi != vi_end; vi++)
612 TBB d = dom[dfs_order[index_map[*vi]]];
613 if(dfs_to_bb[d] != boost::graph_traits<GraphObj>::null_vertex())
616 "---dom is " + std::to_string(index_map[dfs_to_bb[d]]));
617 dom_map[*vi] = dfs_to_bb[d];
626 template <
typename GraphObj>
652 friend class loop_regions_computation;
653 friend class add_loop_nop;
657 using Vertex =
typename boost::graph_traits<const GraphObj>::vertex_descriptor;
660 using Vertex_iterator =
typename boost::graph_traits<const GraphObj>::vertex_iterator;
703 if(dom_computed == DOM_OK)
707 if(dom_computed == DOM_NONE)
709 bool reverse = (dir == CDI_POST_DOMINATORS) ?
true :
false;
712 boost::reverse_graph<GraphObj, GraphObj> Rcfg(g);
729 dom_computed = DOM_NO_FAST_QUERY;
743 dom_computed(DOM_NONE),
750 THROW_ASSERT(_en_block != _ex_block,
"incorrect entry and exit basic blocks");
759 return dom.find(v)->second;
771 auto dom_it_end = dom.end();
772 for(
auto dom_it = dom.begin(); dom_it != dom_it_end; ++dom_it)
774 dominated[dom_it->second].insert(dom_it->first);
775 dominated[dom_it->first].insert(dom_it->first);
779 bool changed =
false;
784 for(
auto dom_it = dom.begin(); dom_it != dom_it_end; ++dom_it)
787 mSetIter mSetBeg, mSetEnd;
788 for(mSetBeg = dominated.begin(), mSetEnd = dominated.end(); mSetBeg != mSetEnd; ++mSetBeg)
790 if((mSetBeg->second).find(dom_it->second) != (mSetBeg->second).end() &&
791 (mSetBeg->second).find(dom_it->first) == (mSetBeg->second).end())
793 dominated[mSetBeg->first].insert(dom_it->first);
typename boost::graph_traits< const GraphObj >::in_edge_iterator in_edge_iterator
edge_iterator definition.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
Vertex get_immediate_dominator(Vertex v) const
Return the immediate dominator of a Vertex.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
TBB eval(TBB v)
Compress the path from V to the set root of V if needed (when the root has changed since the last cal...
Dominator o post-dominator data structure.
File containing functions and utilities to support the printing of debug messagges.
std::vector< Vertex > dfs_to_bb
If x is the DFS-index of a node which corresponds with a basic block, dfs_to_bb[x] is that basic bloc...
This algorithm is to find coloring of a graph Algorithm: Let G = (V,E) be a graph with vertices v_1...
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const CustomUnorderedMapStable< Vertex, Vertex > & get_dominator_map() const
Return the dominators tree as a map between Vertex and its immediate dominator.
typename boost::graph_traits< const GraphObj >::vertex_iterator Vertex_iterator
Vertex iterator definition.
unsigned int nodes
The number of nodes in the DFS tree (==dfsnum-1).
const CustomUnorderedMapStable< Vertex, CustomOrderedSet< Vertex > > getAllDominated() const
Returns a map containing, for each Vertex, a set formed by all the vertices dominated by it (all the ...
exceptions managed by PandA
std::map< Vertex, size_t > index_map
index map putting into relation vertices and arbitrary indexes.
dom_info(const GraphObj &_g, const Vertex &_en_block, const Vertex &_ex_block, const ParameterConstRef param)
Constructor.
void calc_dfs_tree_rec(Vertex bb)
The recursive variant of creating a DFS tree.
void calc_idoms(bool reverse)
This calculates the immediate dominators (or post-dominators if REVERSE is true). ...
std::vector< unsigned int > set_size
set_size[x] is the number of elements in the set named by x.
std::vector< TBB > path_min
The value in path_min[x] is the node y on the path from x to the root of the tree x is in with the sm...
const GraphObj & g
Flow graph reference.
void link_roots(TBB v, TBB w)
This essentially merges the two sets of V and W, giving a single set with the new root V...
std::vector< TBB > set_child
set_child[x] is used for balancing the tree representing a set.
dom_state
type of information stored in dom_info data structure
redefinition of map to manage ordered/unordered structures
typename boost::graph_traits< const GraphObj >::edge_descriptor edge
edge definition.
const Vertex en_block
Start block (ENTRY_BLOCK_PTR for forward problem, EXIT_BLOCK for backward problem).
Auxiliary methods for manipulating string.
std::vector< TBB > dom
After the algorithm is done, dom[x] contains the immediate dominator of x.
cdi_direction
type of computation.
CustomUnorderedMapStable< Vertex, Vertex > dom
After the algorithm is done, dom[x] contains the immediate dominator of x.
unsigned long TBB
Parameter include.
static const uint32_t k[]
redefinition of set to manage ordered/unordered structures
typename boost::graph_traits< const GraphObj >::vertex_descriptor Vertex
The algorithm uses two different indices for each Vertex: a generic index given by boost and the inde...
const GraphObj & g
Flow graph reference.
void calculate_dominance_info(enum dominance::cdi_direction dir)
The main entry point into this module.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
int debug_level
Debug level.
Store the intermediate information used to compute dominator or post dominator information.
const ParameterConstRef param
The set of input parameters.
void calc_dfs_tree(bool reverse)
The main entry for calculating the DFS tree or forest.
std::vector< TBB > dfs_parent
The parent of a node in the DFS tree.
unsigned int dfsnum
This is the next free DFS number when creating the DFS tree.
int debug_level
debug_level
CustomOrderedSet< TBB > fake_exit_edge
Blocks with bits set here have a fake edge to EXIT.
const Vertex & en_block
Start block (ENTRY_BLOCK_PTR for forward problem, EXIT_BLOCK for backward problem).
std::vector< TBB > set_chain
set_chain[x] is the next node on the path from x to the representant of the set containing x...
const Vertex ex_block
Ending block.
std::vector< TBB > bucket
bucket[x] points to the first node of the set of nodes having x as key.
void fill_dom_map(CustomUnorderedMapStable< Vertex, Vertex > &dom_map)
fill the dominator map after its computation
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
std::vector< TBB > next_bucket
And next_bucket[x] points to the next node.
dominance(const GraphObj &_g, const Vertex _en_block, const Vertex _ex_block, const ParameterConstRef _param)
Constructor for the dominance class.
this class is used to manage the command-line or XML options.
const Vertex & ex_block
Ending block.
typename boost::graph_traits< const BBGraph >::vertex_iterator Vertex_iterator
Vertex_iterator definition.
The data is OK, but the fast query data are not usable.
unsigned counter[N_THREADS]
std::vector< TBB > dfs_order
If b is the number of a basic block (index_map[bb_Vertex]), dfs_order[b] is the number of that node i...
absl::node_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapStable
const unsigned long int last_basic_block
index of the last basic block
std::vector< TBB > key
For a node x key[x] is roughly the node nearest to the root from which exists a way to x only over no...
typename boost::graph_traits< const GraphObj >::out_edge_iterator out_edge_iterator
edge_iterator definition.
void compress(TBB v)
Compress the path from V to the root of its set and update path_min at the same time.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...