Skip to content
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

Dominator nodes only store immediate dominator #5137

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions jbmc/src/java_bytecode/java_local_variable_table.cpp
Original file line number Diff line number Diff line change
@@ -464,10 +464,7 @@ static java_bytecode_convert_methodt::method_offsett get_common_dominator(
candidate_dominators;
for(auto v : merge_vars)
{
const auto &dominator_nodeidx=
dominator_analysis.cfg.entry_map.at(v->var.start_pc);
const auto &this_var_doms=
dominator_analysis.cfg[dominator_nodeidx].dominators;
const auto &this_var_doms = dominator_analysis.dominators(v->var.start_pc);
for(const auto this_var_dom : this_var_doms)
if(this_var_dom<=first_pc)
candidate_dominators.push_back(this_var_dom);
408 changes: 330 additions & 78 deletions src/analyses/cfg_dominators.h

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/analyses/dependence_graph.cpp
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ void dep_graph_domaint::control_dependencies(
const cfg_post_dominatorst::cfgt::nodet &m_s=
pd.cfg[edge.first];

if(m_s.dominators.find(to)!=m_s.dominators.end())
if(pd.dominates(to, m_s))
post_dom_one=true;
else
post_dom_all=false;
44 changes: 11 additions & 33 deletions src/analyses/sese_regions.cpp
Original file line number Diff line number Diff line change
@@ -140,45 +140,23 @@ void sese_region_analysist::compute_sese_regions(
(*successors.begin())->incoming_edges.size() == 1)
continue;

const auto &instruction_postdoms = postdominators.get_node(it).dominators;

// Ideally we would start with the immediate postdominator and walk down,
// but our current dominator analysis doesn't make it easy to determine an
// immediate dominator.

// Ideally I would use `optionalt<std::size_t>` here, but it triggers a
// GCC-5 bug.
std::size_t closest_exit_index = dominators.cfg.size();
for(const auto &possible_exit : instruction_postdoms)
for(const auto &possible_exit : postdominators.dominators(it))
{
const auto possible_exit_index = dominators.get_node_index(possible_exit);
const auto &possible_exit_node = dominators.cfg[possible_exit_index];
const auto possible_exit_dominators =
possible_exit_node.dominators.size();

if(
it != possible_exit && dominators.dominates(it, possible_exit_node) &&
it != possible_exit && dominators.dominates(it, possible_exit) &&
get_innermost_loop(innermost_loop_ids, it) ==
get_innermost_loop(innermost_loop_ids, possible_exit))
{
// If there are several candidate region exit nodes, prefer the one with
// the least dominators, i.e. the closest to the region entrance.
if(
closest_exit_index == dominators.cfg.size() ||
dominators.cfg[closest_exit_index].dominators.size() >
possible_exit_dominators)
{
closest_exit_index = possible_exit_index;
}
}
}
// The first candidate that meets out criteria is the best, as
// postdominators are iterated over closest first (i.e. starting with
// the immediate postdominator).

if(closest_exit_index < dominators.cfg.size())
{
auto emplace_result =
sese_regions.emplace(it, dominators.cfg[closest_exit_index].PC);
INVARIANT(
emplace_result.second, "should only visit each region entry once");
auto emplace_result = sese_regions.emplace(it, possible_exit);
INVARIANT(
emplace_result.second, "should only visit each region entry once");

break;
}
}
}
}
2 changes: 1 addition & 1 deletion src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ static void unreachable_instructions(
++it)
{
const cfg_dominatorst::cfgt::nodet &n=dominators.cfg[it->second];
if(n.dominators.empty())
if(!n.dominator)
dest.insert(std::make_pair(it->first->location_number,
it->first));
}
27 changes: 2 additions & 25 deletions src/goto-instrument/full_slicer.cpp
Original file line number Diff line number Diff line change
@@ -153,32 +153,9 @@ void full_slicert::add_jumps(
{
// check whether the nearest post-dominator is different from
// lex_succ
goto_programt::const_targett nearest=lex_succ;
std::size_t post_dom_size=0;
for(cfg_dominatorst::target_sett::const_iterator d_it =
j_PC_node.dominators.begin();
d_it != j_PC_node.dominators.end();
++d_it)
if(j_PC_node.dominator && pd.cfg[*j_PC_node.dominator].PC != lex_succ)
{
const auto &node = cfg.get_node(*d_it);
if(node.node_required)
{
const irep_idt &id2 = node.function_id;
INVARIANT(id==id2,
"goto/jump expected to be within a single function");

const auto &postdom_node = pd.get_node(*d_it);

if(postdom_node.dominators.size() > post_dom_size)
{
nearest=*d_it;
post_dom_size = postdom_node.dominators.size();
}
}
}
if(nearest!=lex_succ)
{
add_to_queue(queue, *it, nearest);
add_to_queue(queue, *it, lex_succ);
jumps.erase(it);
}
}