diff options
author | Tom de Vries <tom@codesourcery.com> | 2015-11-25 11:28:49 +0000 |
---|---|---|
committer | Tom de Vries <vries@gcc.gnu.org> | 2015-11-25 11:28:49 +0000 |
commit | b81b8bcadbaf0c703cc88b81f1ed3a6cae583e20 (patch) | |
tree | eeaa9b933e9f67b2998b67bbf5bfc75188ea7771 /gcc/cfgloop.c | |
parent | e5ef217c3e12ddab9e50843ce322702e8b9d1686 (diff) | |
download | gcc-b81b8bcadbaf0c703cc88b81f1ed3a6cae583e20.zip gcc-b81b8bcadbaf0c703cc88b81f1ed3a6cae583e20.tar.gz gcc-b81b8bcadbaf0c703cc88b81f1ed3a6cae583e20.tar.bz2 |
Improve verification of loop->latch in verify_loop_structure
2015-11-25 Tom de Vries <tom@codesourcery.com>
* cfgloop.c (find_single_latch): New function, factored out of ...
(flow_loops_find): ... here.
(verify_loop_structure): Improve verification of loop->latch.
* cfgloop.h (find_single_latch): Declare.
* omp-low.c (expand_omp_for_generic): Initialize latch of orig_loop.
From-SVN: r230866
Diffstat (limited to 'gcc/cfgloop.c')
-rw-r--r-- | gcc/cfgloop.c | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/gcc/cfgloop.c b/gcc/cfgloop.c index 83a5262..e7cb78a 100644 --- a/gcc/cfgloop.c +++ b/gcc/cfgloop.c @@ -388,6 +388,33 @@ bb_loop_header_p (basic_block header) return false; } +/* Return the latch block for this header block, if it has just a single one. + Otherwise, return NULL. */ + +basic_block +find_single_latch (struct loop* loop) +{ + basic_block header = loop->header; + edge_iterator ei; + edge e; + basic_block latch = NULL; + + FOR_EACH_EDGE (e, ei, header->preds) + { + basic_block cand = e->src; + if (!flow_bb_inside_loop_p (loop, cand)) + continue; + + if (latch != NULL) + /* More than one latch edge. */ + return NULL; + + latch = cand; + } + + return latch; +} + /* Find all the natural loops in the function and save in LOOPS structure and recalculate loop_father information in basic block structures. If LOOPS is non-NULL then the loop structures for already recorded loops @@ -482,29 +509,10 @@ flow_loops_find (struct loops *loops) { struct loop *loop = larray[i]; basic_block header = loop->header; - edge_iterator ei; - edge e; flow_loop_tree_node_add (header->loop_father, loop); loop->num_nodes = flow_loop_nodes_find (loop->header, loop); - - /* Look for the latch for this header block, if it has just a - single one. */ - FOR_EACH_EDGE (e, ei, header->preds) - { - basic_block latch = e->src; - - if (flow_bb_inside_loop_p (loop, latch)) - { - if (loop->latch != NULL) - { - /* More than one latch edge. */ - loop->latch = NULL; - break; - } - loop->latch = latch; - } - } + loop->latch = find_single_latch (loop); } return loops; @@ -1434,6 +1442,28 @@ verify_loop_structure (void) error ("loop %d%'s latch is not dominated by its header", i); err = 1; } + if (find_single_latch (loop) == NULL) + { + error ("loop %d%'s latch is is not the only latch", i); + err = 1; + } + } + else + { + if (loops_state_satisfies_p (LOOPS_MAY_HAVE_MULTIPLE_LATCHES)) + { + if (find_single_latch (loop) != NULL) + { + error ("loop %d%'s latch is missing", i); + err = 1; + } + } + else + { + error ("loop %d%'s latch is missing, and loops may not have" + " multiple latches", i); + err = 1; + } } if (loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES)) { |