PandA-2024.02
weak_dominance.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
44 #include "weak_dominance.hpp"
46 
47 #include "Dominance.hpp"
48 #include "Parameter.hpp" // for ParameterConstRef
49 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_NONE
50 #include "edge_info.hpp" // for EdgeInfoRef
51 #include "exceptions.hpp" // for THROW_ASSERT
52 #include "string_manipulation.hpp" // for GET_CLASS
53 #include <boost/tuple/tuple.hpp> // for tie
54 #include <iterator> // for front_insert_iterator
55 #include <list> // for list, _List_iterator
56 
59 {
60  if(boost::num_vertices(*input) == 0)
61  {
62  return;
63  }
64  // creating maps
65  THROW_ASSERT(i2o.size() == o2i.size(), "Different map sizes");
66  if(i2o.size() == 0)
67  {
68  graph::vertex_iterator v, v_end;
69  for(boost::tie(v, v_end) = boost::vertices(*input); v != v_end; v++)
70  {
71  vertex new_vertex = output->AddVertex(NodeInfoRef());
72  i2o[*v] = new_vertex;
73  o2i[new_vertex] = *v;
74  }
75  }
76 
77  std::list<vertex> levels;
78  boost::topological_sort(*input, std::front_inserter(levels));
80  unsigned int counter = 0;
81  for(auto& level : levels)
82  {
83  sorted_nodes[level] = ++counter;
84  }
85 
88  const auto& post_dominators = dm.get_dominator_map();
89 
90  // iterate over outgoing edges of the input graph
91  EdgeIterator ei, ei_end;
92  for(boost::tie(ei, ei_end) = boost::edges(*input); ei != ei_end; ++ei)
93  {
94  vertex A = boost::source(*ei, *input);
95  vertex B = boost::target(*ei, *input);
96  InEdgeIterator pd_ei, pd_ei_end;
97  {
98  vertex current_node = B;
99  while(current_node && current_node != A && current_node != post_dominators.at(A))
100  {
101  if(sorted_nodes[current_node] > sorted_nodes[A])
102  {
103  add_edge(i2o[A], i2o[current_node], output);
104  }
105  else
106  {
107  break;
108  }
109  current_node = post_dominators.at(current_node);
110  }
111  }
112  }
113 }
114 
115 weak_dominance::weak_dominance(const graph* _input, vertex _start, vertex _end, const ParameterConstRef _param,
116  int _selector)
117  : input(_input),
118  start(_start),
119  end(_end),
120  selector(_selector),
121  param(_param),
122  debug_level(_param->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE))
123 {
124 }
125 
127 {
128  if(output->ExistsEdge(source, target))
129  {
130  output->AddSelector(source, target, selector);
131  }
132  else
133  {
134  output->InternalAddEdge(source, target, selector, EdgeInfoRef());
135  }
136 }
Dominator o post-dominator data structure.
Definition: Dominance.hpp:627
File containing functions and utilities to support the printing of debug messagges.
string target
Definition: lenet_tvm.py:16
#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.
Definition: Dominance.hpp:806
void calculate_weak_dominance_info(graphs_collection *output, CustomUnorderedMap< vertex, vertex > &i2o, CustomUnorderedMap< vertex, vertex > &o2i)
Compute weak dominance info.
const int debug_level
the debug level
void add_edge(vertex source, vertex target, graphs_collection *output)
Add a weak dominance edge between two nodes.
boost::graph_traits< graph >::in_edge_iterator InEdgeIterator
in_edge_iterator definition.
Definition: graph.hpp:1310
exceptions managed by PandA
vertex end
the exit vertex
const ParameterConstRef param
The set of input parameters.
volatile int output[DIM_Y][DIM_X]
Definition: los.h:1
#define A
Definition: generate.c:13
Auxiliary methods for manipulating string.
vertex start
the entry vertex
boost::graph_traits< graph >::edge_iterator EdgeIterator
edge_iterator definition.
Definition: graph.hpp:1314
unsigned edges[4545]
Definition: graph.h:25
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
refcount< EdgeInfo > EdgeInfoRef
RefCount type definition of the edge_info class structure.
Definition: edge_info.hpp:67
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
General class used to describe a graph in PandA.
Definition: graph.hpp:771
void calculate_dominance_info(enum dominance::cdi_direction dir)
The main entry point into this module.
Definition: Dominance.hpp:701
#define DEBUG_LEVEL_NONE
no debugging print is performed.
const int selector
the selector used in output graph
boost::graph_traits< graphs_collection >::edge_descriptor AddSelector(const boost::graph_traits< graphs_collection >::edge_descriptor edge, const int selector)
Add a selector to an existing edge.
Definition: graph.hpp:311
refcount< NodeInfo > NodeInfoRef
RefCount type definition of the NodeInfo class structure.
Definition: node_info.hpp:98
Base class description of data information associated with each edge of a graph.
bulk graph.
Definition: graph.hpp:287
weak_dominance(const graph *_input, vertex _start, vertex _end, const ParameterConstRef param, int selector=WD_SELECTOR)
Constructor.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
int level
Definition: main.c:98
this class is used to manage the command-line or XML options.
unsigned counter[N_THREADS]
Definition: data.c:3
boost::graph_traits< graphs_collection >::edge_descriptor InternalAddEdge(boost::graph_traits< graphs_collection >::vertex_descriptor source, boost::graph_traits< graphs_collection >::vertex_descriptor target, const int selector, const EdgeInfoRef info)
Add an edge to this graph FIXME: this should be protected.
Definition: graph.hpp:408
const graph * input
the input graph (not const since node info are copied in the new graph
#define B
Definition: generate.c:14
virtual boost::graph_traits< boost_graphs_collection >::vertex_descriptor AddVertex(const NodeInfoRef info)
Add a vertex to this graph with a property.
Definition: graph.cpp:57
bool ExistsEdge(const boost::graph_traits< graphs_collection >::vertex_descriptor source, const boost::graph_traits< graphs_collection >::vertex_descriptor target) const
Check if an edge exists.
Definition: graph.hpp:435
Class specifying weak dominance calculus.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13