During scop detection we can figure out if loop IVs cannot be represeted in the
polyhedral model. We now bail out early instead of waiting until
graphite-sese-to-poly.c

Passes regtest and bootstrap with BOOT_CFLAGS=="-g -O2 -fgraphite-identity 
-floop-nest-optimize"
with ISL-0.15.

gcc/ChangeLog:

2015-10-02  Aditya Kumar  <hiradi...@msn.com>

        * graphite-scop-detection.c (loop_ivs_can_be_represented): New. Return
          true when a loop iv can be represented by a signed int.
        (loop_body_is_valid_scop): Call loop_ivs_can_be_represented.
        * graphite-sese-to-poly.c (remove_gbbs_in_scop):
        (new_gimple_poly_bb): Renamed from new_gimple_bb.
        (free_gimple_poly_bb): Renamed from free_gimple_bb.
        (try_generate_gimple_bb): Hoist loop invariant code.
        (analyze_drs_in_stmts): Same.
        (build_scop_drs): Call renamed functions.
        (new_pbb_from_pbb): Same.
        (scop_ivs_can_be_represented): Delete as functionality now moved to
        graphite-scop-detection.c
        (build_poly_scop): Remove call to scop_ivs_can_be_represented.


---
 gcc/graphite-scop-detection.c | 28 ++++++++++++++++
 gcc/graphite-sese-to-poly.c   | 74 +++++++++----------------------------------
 2 files changed, 43 insertions(+), 59 deletions(-)

diff --git a/gcc/graphite-scop-detection.c b/gcc/graphite-scop-detection.c
index a498ddc..d3f5a41 100644
--- a/gcc/graphite-scop-detection.c
+++ b/gcc/graphite-scop-detection.c
@@ -783,12 +783,40 @@ dot_scop (scop_p scop)
 #endif
 }
 
+/* Can all ivs be represented by a signed integer?
+   As ISL might generate negative values in its expressions, signed loop ivs
+   are required in the backend.  */
+
+static bool
+loop_ivs_can_be_represented (loop_p loop)
+{
+  for (gphi_iterator psi = gsi_start_phis (loop->header);
+       !gsi_end_p (psi); gsi_next (&psi))
+    {
+      gphi *phi = psi.phi ();
+      tree res = PHI_RESULT (phi);
+      tree type = TREE_TYPE (res);
+
+      if (TYPE_UNSIGNED (type)
+         && TYPE_PRECISION (type) >= TYPE_PRECISION 
(long_long_integer_type_node))
+        return false;
+    }
+  return true;
+}
+
 /* Return true when the body of LOOP has statements that can be represented as 
a
    valid scop.  */
 
 static bool
 loop_body_is_valid_scop (loop_p loop, sese_l scop)
 {
+  if (!loop_ivs_can_be_represented (loop))
+    {
+      DEBUG_PRINT (dp << "[scop-detection-fail] loop_"
+                     << loop->num << "IV cannot be represented.\n");
+      return false;
+    }
+
   if (!loop_nest_has_data_refs (loop))
     {
       DEBUG_PRINT (dp << "[scop-detection-fail] loop_"
diff --git a/gcc/graphite-sese-to-poly.c b/gcc/graphite-sese-to-poly.c
index 26f75e9..a219919 100644
--- a/gcc/graphite-sese-to-poly.c
+++ b/gcc/graphite-sese-to-poly.c
@@ -199,7 +199,7 @@ reduction_phi_p (sese region, gphi_iterator *psi)
 /* Store the GRAPHITE representation of BB.  */
 
 static gimple_bb_p
-new_gimple_bb (basic_block bb, vec<data_reference_p> drs)
+new_gimple_poly_bb (basic_block bb, vec<data_reference_p> drs)
 {
   struct gimple_bb *gbb;
 
@@ -233,7 +233,7 @@ free_data_refs_aux (vec<data_reference_p> datarefs)
 /* Frees GBB.  */
 
 static void
-free_gimple_bb (struct gimple_bb *gbb)
+free_gimple_poly_bb (struct gimple_bb *gbb)
 {
   free_data_refs_aux (GBB_DATA_REFS (gbb));
   free_data_refs (GBB_DATA_REFS (gbb));
@@ -253,7 +253,7 @@ remove_gbbs_in_scop (scop_p scop)
   poly_bb_p pbb;
 
   FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb)
-    free_gimple_bb (PBB_BLACK_BOX (pbb));
+    free_gimple_poly_bb (PBB_BLACK_BOX (pbb));
 }
 
 /* Deletes all scops in SCOPS.  */
@@ -310,24 +310,21 @@ try_generate_gimple_bb (scop_p scop, basic_block bb)
   drs.create (5);
   sese region = SCOP_REGION (scop);
   loop_p nest = outermost_loop_in_sese_1 (region, bb);
-  gimple_stmt_iterator gsi;
+  loop_p loop = bb->loop_father;
+  if (!loop_in_sese_p (loop, region))
+    loop = nest;
 
+  gimple_stmt_iterator gsi;
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
       gimple *stmt = gsi_stmt (gsi);
-      loop_p loop;
-
       if (is_gimple_debug (stmt))
        continue;
 
-      loop = loop_containing_stmt (stmt);
-      if (!loop_in_sese_p (loop, region))
-       loop = nest;
-
       graphite_find_data_references_in_stmt (nest, loop, stmt, &drs);
     }
 
-  return new_gimple_bb (bb, drs);
+  return new_gimple_poly_bb (bb, drs);
 }
 
 /* Returns true if all predecessors of BB, that are not dominated by BB, are
@@ -1887,7 +1884,7 @@ build_scop_drs (scop_p scop)
   for (i = 0; SCOP_BBS (scop).iterate (i, &pbb); i++)
     if (GBB_DATA_REFS (PBB_BLACK_BOX (pbb)).is_empty ())
       {
-       free_gimple_bb (PBB_BLACK_BOX (pbb));
+       free_gimple_poly_bb (PBB_BLACK_BOX (pbb));
        free_poly_bb (pbb);
        SCOP_BBS (scop).ordered_remove (i);
        i--;
@@ -1935,19 +1932,18 @@ analyze_drs_in_stmts (scop_p scop, basic_block bb, 
vec<gimple *> stmts)
     return;
 
   nest = outermost_loop_in_sese_1 (region, bb);
+
+  loop_p loop = bb->loop_father;
+  if (!loop_in_sese_p (loop, region))
+    loop = nest;
+
   gbb = gbb_from_bb (bb);
 
   FOR_EACH_VEC_ELT (stmts, i, stmt)
     {
-      loop_p loop;
-
       if (is_gimple_debug (stmt))
        continue;
 
-      loop = loop_containing_stmt (stmt);
-      if (!loop_in_sese_p (loop, region))
-       loop = nest;
-
       graphite_find_data_references_in_stmt (nest, loop, stmt,
                                             &GBB_DATA_REFS (gbb));
     }
@@ -2009,7 +2005,7 @@ new_pbb_from_pbb (scop_p scop, poly_bb_p pbb, basic_block 
bb)
   vec<data_reference_p> drs;
   drs.create (3);
   gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
-  gimple_bb_p gbb1 = new_gimple_bb (bb, drs);
+  gimple_bb_p gbb1 = new_gimple_poly_bb (bb, drs);
   poly_bb_p pbb1 = new_poly_bb (scop, gbb1);
   int index, n = SCOP_BBS (scop).length ();
 
@@ -2499,43 +2495,6 @@ nb_pbbs_in_loops (scop_p scop)
   return res;
 }
 
-/* Can all ivs be represented by a signed integer?
-   As ISL might generate negative values in its expressions, signed loop ivs
-   are required in the backend. */
-
-static bool
-scop_ivs_can_be_represented (scop_p scop)
-{
-  loop_p loop;
-  gphi_iterator psi;
-  bool result = true;
-
-  FOR_EACH_LOOP (loop, 0)
-    {
-      if (!loop_in_sese_p (loop, SCOP_REGION (scop)))
-       continue;
-
-      for (psi = gsi_start_phis (loop->header);
-          !gsi_end_p (psi); gsi_next (&psi))
-       {
-         gphi *phi = psi.phi ();
-         tree res = PHI_RESULT (phi);
-         tree type = TREE_TYPE (res);
-
-         if (TYPE_UNSIGNED (type)
-             && TYPE_PRECISION (type) >= TYPE_PRECISION 
(long_long_integer_type_node))
-           {
-             result = false;
-             break;
-           }
-       }
-      if (!result)
-       break;
-    }
-
-  return result;
-}
-
 /* Builds the polyhedral representation for a SESE region.  */
 
 void
@@ -2551,9 +2510,6 @@ build_poly_scop (scop_p scop)
   if (nb_pbbs_in_loops (scop) == 0)
     return;
 
-  if (!scop_ivs_can_be_represented (scop))
-    return;
-
   build_sese_loop_nests (region);
   /* Record all conditions in REGION.  */
   sese_dom_walker (CDI_DOMINATORS, region).walk (cfun->cfg->x_entry_block_ptr);
-- 
2.1.0.243.g30d45f7

Reply via email to