OSDN Git Service

2010-11-25 Basile Starynkevitch <basile@starynkevitch.net>
[pf3gnuchains/gcc-fork.git] / gcc / graphite-blocking.c
index b5f5acd..3951b60 100644 (file)
@@ -46,7 +46,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "params.h"
 
 #ifdef HAVE_cloog
-#include "cloog/cloog.h"
 #include "ppl_c.h"
 #include "sese.h"
 #include "graphite-ppl.h"
@@ -173,25 +172,25 @@ pbb_strip_mine_time_depth (poly_bb_p pbb, int time_depth, int stride)
   return true;
 }
 
-/* Returns true when strip mining with STRIDE of the loop around PBB
-   at scattering time TIME_DEPTH is profitable.  */
+/* Returns true when strip mining with STRIDE of the loop LST is
+   profitable.  */
 
 static bool
-pbb_strip_mine_profitable_p (poly_bb_p pbb,
-                            graphite_dim_t time_depth,
-                            int stride)
+lst_strip_mine_profitable_p (lst_p lst, int stride)
 {
-  Value niter, strip_stride;
+  mpz_t niter, strip_stride;
   bool res;
 
-  value_init (strip_stride);
-  value_init (niter);
-  value_set_si (strip_stride, stride);
-  pbb_number_of_iterations_at_time (pbb, time_depth, niter);
-  res = value_gt (niter, strip_stride);
-  value_clear (strip_stride);
-  value_clear (niter);
+  gcc_assert (LST_LOOP_P (lst));
+  mpz_init (strip_stride);
+  mpz_init (niter);
 
+  mpz_set_si (strip_stride, stride);
+  lst_niter_for_loop (lst, niter);
+  res = (mpz_cmp (niter, strip_stride) > 0);
+
+  mpz_clear (strip_stride);
+  mpz_clear (niter);
   return res;
 }
 
@@ -213,7 +212,7 @@ lst_do_strip_mine_loop (lst_p lst, int depth)
     {
       bool res = false;
 
-      for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
+      FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
        res |= lst_do_strip_mine_loop (l, depth);
 
       return res;
@@ -234,16 +233,18 @@ lst_do_strip_mine (lst_p lst)
   lst_p l;
   bool res = false;
   int stride = PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE);
+  int depth;
 
   if (!lst
       || !LST_LOOP_P (lst))
     return false;
 
-  for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
+  FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
     res |= lst_do_strip_mine (l);
 
-  if (pbb_strip_mine_profitable_p (LST_PBB (lst_find_first_pbb (lst)),
-                                  lst_depth (lst), stride))
+  depth = lst_depth (lst);
+  if (depth >= 0
+      && lst_strip_mine_profitable_p (lst, stride))
     {
       res |= lst_do_strip_mine_loop (lst, lst_depth (lst));
       lst_add_loop_under_loop (lst);
@@ -252,29 +253,42 @@ lst_do_strip_mine (lst_p lst)
   return res;
 }
 
-
-/* Strip mines all the loops in SCOP.  Nothing profitable in all this:
-   this is just a driver function.  */
+/* Strip mines all the loops in SCOP.  Returns true when some loops
+   have been strip-mined.  */
 
 bool
 scop_do_strip_mine (scop_p scop)
 {
-  bool transform_done = false;
+  return lst_do_strip_mine (SCOP_TRANSFORMED_SCHEDULE (scop));
+}
 
-  store_scattering (scop);
+/* Loop blocks all the loops in SCOP.  Returns true when we manage to
+   block some loops.  */
 
-  transform_done = lst_do_strip_mine (SCOP_TRANSFORMED_SCHEDULE (scop));
+bool
+scop_do_block (scop_p scop)
+{
+  bool strip_mined = false;
+  bool interchanged = false;
 
-  if (!transform_done)
-    return false;
+  store_scattering (scop);
+
+  strip_mined = lst_do_strip_mine (SCOP_TRANSFORMED_SCHEDULE (scop));
+  interchanged = scop_do_interchange (scop);
 
-  if (!graphite_legal_transform (scop))
+  /* If we don't interchange loops, the strip mine alone will not be
+     profitable, and the transform is not a loop blocking: so revert
+     the transform.  */
+  if (!interchanged)
     {
       restore_scattering (scop);
       return false;
     }
+  else if (strip_mined && interchanged
+          && dump_file && (dump_flags & TDF_DETAILS))
+    fprintf (dump_file, "SCoP will be loop blocked.\n");
 
-  return transform_done;
+  return strip_mined || interchanged;
 }
 
 #endif