Go to the documentation of this file.
12 #ifndef CPROVER_ANALYSES_CFG_DOMINATORS_H
13 #define CPROVER_ANALYSES_CFG_DOMINATORS_H
36 template <
class P,
class T,
bool post_dom>
79 return rhs_node.dominators.count(lhs);
97 return !program_point_node.dominators.empty();
121 template <
class P,
class T,
bool post_dom>
126 cfg_dominators.
output(out);
131 template <
class P,
class T,
bool post_dom>
139 template <
class P,
class T,
bool post_dom>
146 template <
class P,
class T,
bool post_dom>
149 std::list<T> worklist;
151 if(cfgt::nodes_empty(program))
155 entry_node = cfgt::get_last_node(program);
157 entry_node = cfgt::get_first_node(program);
158 typename cfgt::nodet &n = cfg.get_node(entry_node);
159 n.dominators.insert(entry_node);
161 for(
typename cfgt::edgest::const_iterator
162 s_it=(post_dom?n.
in:n.
out).begin();
163 s_it!=(post_dom?n.
in:n.
out).end();
165 worklist.push_back(cfg[s_it->first].PC);
167 while(!worklist.empty())
170 T current=worklist.front();
171 worklist.pop_front();
174 typename cfgt::nodet &node = cfg.get_node(current);
175 if(node.dominators.empty())
177 for(
const auto &edge : (post_dom ? node.
out : node.
in))
178 if(!cfg[edge.first].dominators.empty())
180 node.dominators=cfg[edge.first].dominators;
181 node.dominators.insert(current);
187 for(
const auto &edge : (post_dom ? node.
out : node.
in))
189 const target_sett &other=cfg[edge.first].dominators;
193 typename target_sett::const_iterator n_it=node.dominators.begin();
194 typename target_sett::const_iterator o_it=other.begin();
197 while(n_it!=node.dominators.end() && o_it!=other.end())
204 node.dominators.erase(n_it++);
215 while(n_it!=node.dominators.end())
222 node.dominators.erase(n_it++);
229 for(
const auto &edge : (post_dom ? node.
in : node.
out))
231 worklist.push_back(cfg[edge.first].PC);
250 out << target->code.pretty();
254 template <
class P,
class T,
bool post_dom>
257 for(
const auto &node : cfg.entries())
263 out <<
" post-dominated by ";
265 out <<
" dominated by ";
267 for(
const auto &d : cfg[node.second].dominators)
291 out << node->location_number;
294 #endif // CPROVER_ANALYSES_CFG_DOMINATORS_H
bool program_point_reachable(const nodet &program_point_node) const
Returns true if the program point for program_point_node is reachable from the entry point.
base_grapht::node_indext entryt
std::ostream & operator<<(std::ostream &out, const cfg_dominators_templatet< P, T, post_dom > &cfg_dominators)
Print the result of the dominator computation.
procedure_local_cfg_baset< nodet, P, T > cfgt
cfgt::entryt get_node_index(const T &program_point) const
Get the graph node index for program_point.
nodet & get_node(const goto_programt::const_targett &program_point)
Get the CFG graph node relating to program_point.
std::set< T > target_sett
entryt get_node_index(const goto_programt::const_targett &program_point) const
Get the graph node index for program_point.
bool dominates(T lhs, T rhs) const
Returns true if program point lhs dominates rhs.
const cfgt::nodet & get_node(const T &program_point) const
Get the graph node (which gives dominators, predecessors and successors) for program_point.
void initialise(P &program)
Initialises the elements of the fixed point analysis.
bool dominates(T lhs, const nodet &rhs_node) const
Returns true if the program point corresponding to rhs_node is dominated by program point lhs.
void operator()(P &program)
Compute dominators.
bool program_point_reachable(T program_point) const
Returns true if the program point for program_point_node is reachable from the entry point.
void dominators_pretty_print_node(const T &node, std::ostream &out)
Pretty-print a single node in the dominator tree.
cfgt::nodet & get_node(const T &program_point)
Get the graph node (which gives dominators, predecessors and successors) for program_point.
cfg_dominators_templatet< const goto_programt, goto_programt::const_targett, false > cfg_dominatorst
cfg_dominators_templatet< const goto_programt, goto_programt::const_targett, true > cfg_post_dominatorst
Goto Programs with Functions.
A generic container class for the GOTO intermediate representation of one function.
instructionst::const_iterator const_targett
void output(std::ostream &) const
Print the result of the dominator computation.
void fixedpoint(P &program)
Computes the MOP for the dominator analysis.
instructionst::iterator targett