+/* Return the number of nested loops in LOOP_NEST, or 0 if the loops
+ are not perfectly nested. */
+
+unsigned int
+perfect_loop_nest_depth (struct loop *loop_nest)
+{
+ struct loop *temp;
+ unsigned int depth = 1;
+
+ /* If it's not a loop nest, we don't want it. We also don't handle
+ sibling loops properly, which are loops of the following form:
+
+ | for (i = 0; i < 50; i++)
+ | {
+ | for (j = 0; j < 50; j++)
+ | {
+ | ...
+ | }
+ | for (j = 0; j < 50; j++)
+ | {
+ | ...
+ | }
+ | }
+ */
+
+ if (!loop_nest->inner || !single_exit (loop_nest))
+ return 0;
+
+ for (temp = loop_nest->inner; temp; temp = temp->inner)
+ {
+ /* If we have a sibling loop or multiple exit edges, jump ship. */
+ if (temp->next || !single_exit (temp))
+ return 0;
+
+ depth++;
+ }
+
+ return depth;
+}
+
+/* Perform a set of linear transforms on loops. */