Skip to content

Generalise dominators template #367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/analyses/cfg_dominators.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ void cfg_dominators_templatet<P, T, post_dom>::fixedpoint(P &program)
{
std::list<T> worklist;

if(program.instructions.empty())
if(cfg.nodes_empty(program))
return;

if(post_dom)
entry_node = --program.instructions.end();
entry_node=cfg.get_last_node(program);
else
entry_node = program.instructions.begin();
entry_node=cfg.get_first_node(program);
typename cfgt::nodet &n=cfg[cfg.entry_map[entry_node]];
n.dominators.insert(entry_node);

Expand Down Expand Up @@ -228,17 +228,18 @@ void cfg_dominators_templatet<P, T, post_dom>::output(std::ostream &out) const
it=cfg.entry_map.begin();
it!=cfg.entry_map.end(); ++it)
{
unsigned n=it->first->location_number;
T n=it->first;

if(post_dom)
out << n << " post-dominated by ";
else
out << n << " dominated by ";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you actually output (operator<<) a T object?

for(typename target_sett::const_iterator d_it=it->second.dominators.begin();
d_it!=it->second.dominators.end();)
const auto& doms=cfg[it->second].dominators;
for(typename target_sett::const_iterator d_it=doms.begin();
d_it!=doms.end();)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ranged-for for(const auto & d : cfg[it->second].dominators)

{
out << (*d_it)->location_number;
if (++d_it!=it->second.dominators.end())
out << *d_it;
if(++d_it!=doms.end())
out << ", ";
}
out << "\n";
Expand Down
4 changes: 4 additions & 0 deletions src/goto-programs/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ class cfg_baset:public graph< cfg_base_nodet<T,I> >
compute_edges(goto_functions, goto_program);
}

I get_first_node(P &program) const { return program.instructions.begin(); }
I get_last_node(P &program) const { return --program.instructions.end(); }
bool nodes_empty(P &program) const { return program.instructions.empty(); }

};

/*******************************************************************\
Expand Down