@@ -140,45 +140,23 @@ void sese_region_analysist::compute_sese_regions(
140140 (*successors.begin ())->incoming_edges .size () == 1 )
141141 continue ;
142142
143- const auto &instruction_postdoms = postdominators.get_node (it).dominators ;
144-
145- // Ideally we would start with the immediate postdominator and walk down,
146- // but our current dominator analysis doesn't make it easy to determine an
147- // immediate dominator.
148-
149- // Ideally I would use `optionalt<std::size_t>` here, but it triggers a
150- // GCC-5 bug.
151- std::size_t closest_exit_index = dominators.cfg .size ();
152- for (const auto &possible_exit : instruction_postdoms)
143+ for (const auto &possible_exit : postdominators.dominators (it))
153144 {
154- const auto possible_exit_index = dominators.get_node_index (possible_exit);
155- const auto &possible_exit_node = dominators.cfg [possible_exit_index];
156- const auto possible_exit_dominators =
157- possible_exit_node.dominators .size ();
158-
159145 if (
160- it != possible_exit && dominators.dominates (it, possible_exit_node ) &&
146+ it != possible_exit && dominators.dominates (it, possible_exit ) &&
161147 get_innermost_loop (innermost_loop_ids, it) ==
162148 get_innermost_loop (innermost_loop_ids, possible_exit))
163149 {
164- // If there are several candidate region exit nodes, prefer the one with
165- // the least dominators, i.e. the closest to the region entrance.
166- if (
167- closest_exit_index == dominators.cfg .size () ||
168- dominators.cfg [closest_exit_index].dominators .size () >
169- possible_exit_dominators)
170- {
171- closest_exit_index = possible_exit_index;
172- }
173- }
174- }
150+ // The first candidate that meets out criteria is the best, as
151+ // postdominators are iterated over closest first (i.e. starting with
152+ // the immediate postdominator).
175153
176- if (closest_exit_index < dominators. cfg . size ())
177- {
178- auto emplace_result =
179- sese_regions. emplace (it, dominators. cfg [closest_exit_index]. PC );
180- INVARIANT (
181- emplace_result. second , " should only visit each region entry once " );
154+ auto emplace_result = sese_regions. emplace (it, possible_exit);
155+ INVARIANT (
156+ emplace_result. second , " should only visit each region entry once " );
157+
158+ break ;
159+ }
182160 }
183161 }
184162}
0 commit comments