OSDN Git Service

compiler: Sort array constructors by index.
[pf3gnuchains/gcc-fork.git] / gcc / graphite-blocking.c
index 80a991c..967de9d 100644 (file)
@@ -1,7 +1,7 @@
 /* Heuristics and transform for loop blocking and strip mining on
    polyhedral representation.
 
-   Copyright (C) 2009 Free Software Foundation, Inc.
+   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
    Contributed by Sebastian Pop <sebastian.pop@amd.com> and
    Pranav Garg  <pranav.garg2107@gmail.com>.
 
@@ -23,34 +23,16 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
-#include "ggc.h"
-#include "tree.h"
-#include "rtl.h"
-#include "output.h"
-#include "basic-block.h"
-#include "diagnostic.h"
 #include "tree-flow.h"
-#include "toplev.h"
 #include "tree-dump.h"
-#include "timevar.h"
 #include "cfgloop.h"
 #include "tree-chrec.h"
 #include "tree-data-ref.h"
-#include "tree-scalar-evolution.h"
-#include "tree-pass.h"
-#include "domwalk.h"
-#include "value-prof.h"
-#include "pointer-set.h"
-#include "gimple.h"
-#include "params.h"
+#include "sese.h"
 
 #ifdef HAVE_cloog
-#include "cloog/cloog.h"
 #include "ppl_c.h"
-#include "sese.h"
 #include "graphite-ppl.h"
-#include "graphite.h"
 #include "graphite-poly.h"
 
 
@@ -107,7 +89,7 @@ along with GCC; see the file COPYING3.  If not see
    # }
 */
 
-static bool
+static void
 pbb_strip_mine_time_depth (poly_bb_p pbb, int time_depth, int stride)
 {
   ppl_dimension_type iter, dim, strip;
@@ -169,78 +151,133 @@ pbb_strip_mine_time_depth (poly_bb_p pbb, int time_depth, int stride)
     ppl_Polyhedron_add_constraint (res, new_cstr);
     ppl_delete_Constraint (new_cstr);
   }
-
-  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;
 }
 
-/* Strip mines all the loops around PBB.  Nothing profitable in all this:
-   this is just a driver function.  */
+/* Strip-mines all the loops of LST with STRIDE.  Return the number of
+   loops strip-mined.  */
 
-static bool
-pbb_do_strip_mine (poly_bb_p pbb)
+static int
+lst_do_strip_mine_loop (lst_p lst, int depth, int stride)
 {
-  graphite_dim_t s_dim;
-  int stride = 64;
-  bool transform_done = false;
-
-  for (s_dim = 0; s_dim < pbb_nb_dynamic_scattering_transform (pbb); s_dim++)
-    if (pbb_strip_mine_profitable_p (pbb, psct_dynamic_dim (pbb, s_dim),
-                                     stride))
-      {
-       ppl_dimension_type d = psct_dynamic_dim (pbb, s_dim);
-       transform_done |= pbb_strip_mine_time_depth (pbb, d, stride);
-       s_dim++;
-      }
-
-  return transform_done;
+  int i;
+  lst_p l;
+  poly_bb_p pbb;
+
+  if (!lst)
+    return 0;
+
+  if (LST_LOOP_P (lst))
+    {
+      int res = 0;
+
+      FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
+       res += lst_do_strip_mine_loop (l, depth, stride);
+
+      return res;
+    }
+
+  pbb = LST_PBB (lst);
+  pbb_strip_mine_time_depth (pbb, psct_dynamic_dim (pbb, depth), stride);
+  return 1;
 }
 
-/* Strip mines all the loops in SCOP.  Nothing profitable in all this:
-   this is just a driver function.  */
+/* Strip-mines all the loops of LST with STRIDE.  When STRIDE is zero,
+   read the stride from the PARAM_LOOP_BLOCK_TILE_SIZE.  Return the
+   number of strip-mined loops.
 
-bool
-scop_do_strip_mine (scop_p scop)
+   Strip mining transforms a loop
+
+   | for (i = 0; i < N; i++)
+   |   S (i);
+
+   into the following loop nest:
+
+   | for (k = 0; k < N; k += STRIDE)
+   |   for (j = 0; j < STRIDE; j++)
+   |     S (i = k + j);
+*/
+
+static int
+lst_do_strip_mine (lst_p lst, int stride)
 {
-  poly_bb_p pbb;
   int i;
-  bool transform_done = false;
-
-  store_scattering (scop);
+  lst_p l;
+  int res = 0;
+  int depth;
 
-  for (i = 0; VEC_iterate (poly_bb_p, SCOP_BBS (scop), i, pbb); i++)
-    transform_done |= pbb_do_strip_mine (pbb);
+  if (!stride)
+    stride = PARAM_VALUE (PARAM_LOOP_BLOCK_TILE_SIZE);
 
-  if (!transform_done)
+  if (!lst
+      || !LST_LOOP_P (lst))
     return false;
 
-  if (!graphite_legal_transform (scop))
+  FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
+    res += lst_do_strip_mine (l, 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), stride);
+      lst_add_loop_under_loop (lst);
+    }
+
+  return res;
+}
+
+/* Strip mines all the loops in SCOP.  Returns the number of
+   strip-mined loops.  */
+
+int
+scop_do_strip_mine (scop_p scop, int stride)
+{
+  return lst_do_strip_mine (SCOP_TRANSFORMED_SCHEDULE (scop), stride);
+}
+
+/* Loop blocks all the loops in SCOP.  Returns true when we manage to
+   block some loops.  */
+
+bool
+scop_do_block (scop_p scop)
+{
+  store_scattering (scop);
+
+  /* If we don't strip mine at least two loops, or not interchange
+     loops, the strip mine alone will not be profitable, and the
+     transform is not a loop blocking: so revert the transform.  */
+  if (lst_do_strip_mine (SCOP_TRANSFORMED_SCHEDULE (scop), 0) < 2
+      || scop_do_interchange (scop) == 0)
     {
       restore_scattering (scop);
       return false;
     }
 
+  if (dump_file && (dump_flags & TDF_DETAILS))
+    fprintf (dump_file, "SCoP will be loop blocked.\n");
+
   return true;
 }