OSDN Git Service

Add a stride parameter to scop_do_strip_mine.
[pf3gnuchains/gcc-fork.git] / gcc / graphite-poly.h
index 4912801..4a2f25c 100644 (file)
@@ -1,5 +1,5 @@
 /* Graphite 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
    Tobias Grosser <grosser@fim.uni-passau.de>.
 
@@ -132,7 +132,54 @@ struct poly_dr
      dimensions.
 
      | i   j   k   a   1
-     | 0   0   0  -1   15  = 0 */
+     | 0   0   0  -1   15  = 0
+
+     The difference between the graphite internal format for access data and
+     the OpenSop format is in the order of columns.
+     Instead of having:
+
+     | i   j   k   a  s0  s1   1
+     | 0   0   0   1   0   0  -5     =  0
+     |-1   0   0   0   1   0   0     =  0
+     | 0  -1  -1   0   0   1   0     =  0
+     | 0   0   0   0   1   0   0     >= 0  # The last four lines describe the
+     | 0   0   0   0   0   1   0     >= 0  # array size.
+     | 0   0   0   0  -1   0 1335    >= 0
+     | 0   0   0   0   0  -1 123     >= 0
+
+     In OpenScop we have:
+
+     | a  s0  s1   i   j   k   1
+     | 1   0   0   0   0   0  -5     =  0
+     | 0   1   0  -1   0   0   0     =  0
+     | 0   0   1   0  -1  -1   0     =  0
+     | 0   1   0   0   0   0   0     >= 0  # The last four lines describe the
+     | 0   0   1   0   0   0   0     >= 0  # array size.
+     | 0  -1   0   0   0   0 1335    >= 0
+     | 0   0  -1   0   0   0 123     >= 0
+
+     The OpenScop access function is printed as follows:
+
+     | 1  # The number of disjunct components in a union of access functions.
+     | R C O I L P  # Described bellow.
+     | a  s0  s1   i   j   k   1
+     | 1   0   0   0   0   0  -5     =  0
+     | 0   1   0  -1   0   0   0     =  0
+     | 0   0   1   0  -1  -1   0     =  0
+     | 0   1   0   0   0   0   0     >= 0  # The last four lines describe the
+     | 0   0   1   0   0   0   0     >= 0  # array size.
+     | 0  -1   0   0   0   0 1335    >= 0
+     | 0   0  -1   0   0   0 123     >= 0
+
+     Where:
+     - R: Number of rows.
+     - C: Number of columns.
+     - O: Number of output dimensions = alias set + number of subscripts.
+     - I: Number of input dimensions (iterators).
+     - L: Number of local (existentially quantified) dimensions.
+     - P: Number of parameters.
+
+     In the example, the vector "R C O I L P" is "7 7 3 2 0 1".  */
   ppl_Pointset_Powerset_C_Polyhedron_t accesses;
 
   /* Data reference's base object set number, we must assure 2 pdrs are in the
@@ -155,8 +202,8 @@ struct poly_dr
 void new_poly_dr (poly_bb_p, int, ppl_Pointset_Powerset_C_Polyhedron_t,
                  enum poly_dr_type, void *, graphite_dim_t);
 void free_poly_dr (poly_dr_p);
-void debug_pdr (poly_dr_p);
-void print_pdr (FILE *, poly_dr_p);
+void debug_pdr (poly_dr_p, int);
+void print_pdr (FILE *, poly_dr_p, int);
 static inline scop_p pdr_scop (poly_dr_p pdr);
 
 /* The dimension of the PDR_ACCESSES polyhedron of PDR.  */
@@ -263,7 +310,9 @@ typedef struct poly_scattering *poly_scattering_p;
 
 struct poly_scattering
 {
-  /* The scattering function containing the transformations.  */
+  /* The scattering function containing the transformations: the
+     layout of this polyhedron is: T|I|G with T the transform
+     scattering, I the iteration domain, G the context parameters.  */
   ppl_Polyhedron_t scattering;
 
   /* The number of local variables.  */
@@ -277,11 +326,15 @@ struct poly_scattering
 
 struct poly_bb
 {
+  /* Pointer to a basic block or a statement in the compiler.  */
   void *black_box;
 
+  /* Pointer to the SCOP containing this PBB.  */
   scop_p scop;
 
-  /* The iteration domain of this bb.
+  /* The iteration domain of this bb.  The layout of this polyhedron
+     is I|G with I the iteration domain, G the context parameters.
+
      Example:
 
      for (i = a - 7*b + 8; i <= 3*a + 13*b + 20; i++)
@@ -340,27 +393,29 @@ extern void new_poly_bb (scop_p, void *, bool);
 extern void free_poly_bb (poly_bb_p);
 extern void debug_loop_vec (poly_bb_p);
 extern void schedule_to_scattering (poly_bb_p, int);
-extern void print_pbb_domain (FILE *, poly_bb_p);
-extern void print_pbb (FILE *, poly_bb_p);
-extern void print_scop_context (FILE *, scop_p);
-extern void print_scop (FILE *, scop_p);
-extern void debug_pbb_domain (poly_bb_p);
-extern void debug_pbb (poly_bb_p);
-extern void print_pdrs (FILE *, poly_bb_p);
-extern void debug_pdrs (poly_bb_p);
-extern void debug_scop_context (scop_p);
-extern void debug_scop (scop_p);
-extern void print_scop_params (FILE *, scop_p);
-extern void debug_scop_params (scop_p);
-extern void print_iteration_domain (FILE *, poly_bb_p);
-extern void print_iteration_domains (FILE *, scop_p);
-extern void debug_iteration_domain (poly_bb_p);
-extern void debug_iteration_domains (scop_p);
+extern void print_pbb_domain (FILE *, poly_bb_p, int);
+extern void print_pbb (FILE *, poly_bb_p, int);
+extern void print_scop_context (FILE *, scop_p, int);
+extern void print_scop (FILE *, scop_p, int);
+extern void print_cloog (FILE *, scop_p, int);
+extern void debug_pbb_domain (poly_bb_p, int);
+extern void debug_pbb (poly_bb_p, int);
+extern void print_pdrs (FILE *, poly_bb_p, int);
+extern void debug_pdrs (poly_bb_p, int);
+extern void debug_scop_context (scop_p, int);
+extern void debug_scop (scop_p, int);
+extern void debug_cloog (scop_p, int);
+extern void print_scop_params (FILE *, scop_p, int);
+extern void debug_scop_params (scop_p, int);
+extern void print_iteration_domain (FILE *, poly_bb_p, int);
+extern void print_iteration_domains (FILE *, scop_p, int);
+extern void debug_iteration_domain (poly_bb_p, int);
+extern void debug_iteration_domains (scop_p, int);
 extern bool scop_do_interchange (scop_p);
-extern bool scop_do_strip_mine (scop_p);
+extern bool scop_do_strip_mine (scop_p, int);
 extern bool scop_do_block (scop_p);
-extern void pbb_number_of_iterations (poly_bb_p, graphite_dim_t, Value);
-extern void pbb_number_of_iterations_at_time (poly_bb_p, graphite_dim_t, Value);
+extern bool flatten_all_loops (scop_p);
+extern void pbb_number_of_iterations_at_time (poly_bb_p, graphite_dim_t, mpz_t);
 extern void pbb_remove_duplicate_pdrs (poly_bb_p);
 
 /* Return the number of write data references in PBB.  */
@@ -379,12 +434,20 @@ number_of_write_pdrs (poly_bb_p pbb)
   return res;
 }
 
+/* The basic block of the PBB.  */
+
+static inline basic_block
+pbb_bb (poly_bb_p pbb)
+{
+  return GBB_BB (PBB_BLACK_BOX (pbb));
+}
+
 /* The index of the PBB.  */
 
 static inline int
 pbb_index (poly_bb_p pbb)
 {
-  return GBB_BB (PBB_BLACK_BOX (pbb))->index;
+  return pbb_bb (pbb)->index;
 }
 
 /* The loop of the PBB.  */
@@ -632,6 +695,9 @@ struct lst {
   /* A pointer to the loop that contains this node.  */
   lst_p loop_father;
 
+  /* The sum of all the memory strides for an LST loop.  */
+  mpz_t memory_strides;
+
   /* Loop nodes contain a sequence SEQ of LST nodes, statements
      contain a pointer to their polyhedral representation PBB.  */
   union {
@@ -644,6 +710,7 @@ struct lst {
 #define LST_LOOP_FATHER(LST) ((LST)->loop_father)
 #define LST_PBB(LST) ((LST)->node.pbb)
 #define LST_SEQ(LST) ((LST)->node.seq)
+#define LST_LOOP_MEMORY_STRIDES(LST) ((LST)->memory_strides)
 
 void scop_to_lst (scop_p);
 void print_lst (FILE *, lst_p, int);
@@ -662,6 +729,8 @@ new_lst_loop (VEC (lst_p, heap) *seq)
   LST_LOOP_P (lst) = true;
   LST_SEQ (lst) = seq;
   LST_LOOP_FATHER (lst) = NULL;
+  mpz_init (LST_LOOP_MEMORY_STRIDES (lst));
+  mpz_set_si (LST_LOOP_MEMORY_STRIDES (lst), -1);
 
   for (i = 0; VEC_iterate (lst_p, seq, i, l); i++)
     LST_LOOP_FATHER (l) = lst;
@@ -698,6 +767,7 @@ free_lst (lst_p lst)
       for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
        free_lst (l);
 
+      mpz_clear (LST_LOOP_MEMORY_STRIDES (lst));
       VEC_free (lst_p, heap, LST_SEQ (lst));
     }
 
@@ -773,7 +843,7 @@ lst_dewey_number (lst_p lst)
   if (!LST_LOOP_FATHER (lst))
     return 0;
 
-  for (i = 0; VEC_iterate (lst_p, LST_SEQ (LST_LOOP_FATHER (lst)), i, l); i++)
+  FOR_EACH_VEC_ELT (lst_p, LST_SEQ (LST_LOOP_FATHER (lst)), i, l)
     if (l == lst)
       return i;
 
@@ -875,7 +945,7 @@ find_lst_loop (lst_p stmt, int loop_depth)
   return loop;
 }
 
-/* Return the first lst representing a PBB statement in LST.  */
+/* Return the first LST representing a PBB statement in LST.  */
 
 static inline lst_p
 lst_find_first_pbb (lst_p lst)
@@ -899,7 +969,7 @@ lst_find_first_pbb (lst_p lst)
   return NULL;
 }
 
-/* Returns true when LST is a loop that does not contains
+/* Returns true when LST is a loop that does not contain
    statements.  */
 
 static inline bool
@@ -908,7 +978,7 @@ lst_empty_p (lst_p lst)
   return !lst_find_first_pbb (lst);
 }
 
-/* Return the last lst representing a PBB statement in LST.  */
+/* Return the last LST representing a PBB statement in LST.  */
 
 static inline lst_p
 lst_find_last_pbb (lst_p lst)
@@ -992,6 +1062,39 @@ lst_remove_from_sequence (lst_p lst)
   LST_LOOP_FATHER (lst) = NULL;
 }
 
+/* Removes the loop LST and inline its body in the father loop.  */
+
+static inline void
+lst_remove_loop_and_inline_stmts_in_loop_father (lst_p lst)
+{
+  lst_p l, father = LST_LOOP_FATHER (lst);
+  int i, dewey = lst_dewey_number (lst);
+
+  gcc_assert (lst && father && dewey >= 0);
+
+  VEC_ordered_remove (lst_p, LST_SEQ (father), dewey);
+  LST_LOOP_FATHER (lst) = NULL;
+
+  FOR_EACH_VEC_ELT (lst_p, LST_SEQ (lst), i, l)
+    {
+      VEC_safe_insert (lst_p, heap, LST_SEQ (father), dewey + i, l);
+      LST_LOOP_FATHER (l) = father;
+    }
+}
+
+/* Sets NITER to the upper bound approximation of the number of
+   iterations of loop LST.  */
+
+static inline void
+lst_niter_for_loop (lst_p lst, mpz_t niter)
+{
+  int depth = lst_depth (lst);
+  poly_bb_p pbb = LST_PBB (lst_find_first_pbb (lst));
+
+  gcc_assert (LST_LOOP_P (lst));
+  pbb_number_of_iterations_at_time (pbb, psct_dynamic_dim (pbb, depth), niter);
+}
+
 /* Updates the scattering of PBB to be at the DEWEY number in the loop
    at depth LEVEL.  */
 
@@ -1037,24 +1140,6 @@ lst_update_scattering_under (lst_p lst, int level, int dewey)
     pbb_update_scattering (LST_PBB (lst), level, dewey);
 }
 
-/* Updates the scattering of all the PBBs under LST and in sequence
-   with LST.  */
-
-static inline void
-lst_update_scattering_seq (lst_p lst)
-{
-  int i;
-  lst_p l;
-  lst_p father = LST_LOOP_FATHER (lst);
-  int dewey = lst_dewey_number (lst);
-  int level = lst_depth (lst);
-
-  gcc_assert (lst && father && dewey >= 0 && level >= 0);
-
-  for (i = dewey; VEC_iterate (lst_p, LST_SEQ (father), i, l); i++)
-    lst_update_scattering_under (l, level, i);
-}
-
 /* Updates the all the scattering levels of all the PBBs under
    LST.  */
 
@@ -1064,14 +1149,24 @@ lst_update_scattering (lst_p lst)
   int i;
   lst_p l;
 
-  if (!lst || !LST_LOOP_P (lst))
+  if (!lst)
     return;
 
   if (LST_LOOP_FATHER (lst))
-    lst_update_scattering_seq (lst);
+    {
+      lst_p father = LST_LOOP_FATHER (lst);
+      int dewey = lst_dewey_number (lst);
+      int level = lst_depth (lst);
 
-  for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
-    lst_update_scattering (l);
+      gcc_assert (lst && father && dewey >= 0 && level >= 0);
+
+      for (i = dewey; VEC_iterate (lst_p, LST_SEQ (father), i, l); i++)
+       lst_update_scattering_under (l, level, i);
+    }
+
+  if (LST_LOOP_P (lst))
+    for (i = 0; VEC_iterate (lst_p, LST_SEQ (lst), i, l); i++)
+      lst_update_scattering (l);
 }
 
 /* Inserts LST1 before LST2 if BEFORE is true; inserts LST1 after LST2
@@ -1296,6 +1391,10 @@ struct scop
   /* A hashtable of the data dependence relations for the original
      scattering.  */
   htab_t original_pddrs;
+
+  /* True when the scop has been converted to its polyhedral
+     representation.  */
+  bool poly_scop_p;
 };
 
 #define SCOP_BBS(S) (S->bbs)
@@ -1305,20 +1404,22 @@ struct scop
 #define SCOP_ORIGINAL_SCHEDULE(S) (S->original_schedule)
 #define SCOP_TRANSFORMED_SCHEDULE(S) (S->transformed_schedule)
 #define SCOP_SAVED_SCHEDULE(S) (S->saved_schedule)
+#define POLY_SCOP_P(S) (S->poly_scop_p)
 
 extern scop_p new_scop (void *);
 extern void free_scop (scop_p);
 extern void free_scops (VEC (scop_p, heap) *);
 extern void print_generated_program (FILE *, scop_p);
 extern void debug_generated_program (scop_p);
-extern void print_scattering_function (FILE *, poly_bb_p);
-extern void print_scattering_functions (FILE *, scop_p);
-extern void debug_scattering_function (poly_bb_p);
-extern void debug_scattering_functions (scop_p);
+extern void print_scattering_function (FILE *, poly_bb_p, int);
+extern void print_scattering_functions (FILE *, scop_p, int);
+extern void debug_scattering_function (poly_bb_p, int);
+extern void debug_scattering_functions (scop_p, int);
 extern int scop_max_loop_depth (scop_p);
 extern int unify_scattering_dimensions (scop_p);
 extern bool apply_poly_transforms (scop_p);
 extern bool graphite_legal_transform (scop_p);
+extern void cloog_checksum (scop_p);
 
 /* Set the region of SCOP to REGION.  */
 
@@ -1453,4 +1554,49 @@ restore_scattering (scop_p scop)
   restore_lst_schedule (scop);
 }
 
+/* For a given PBB, add to RES the scop context, the iteration domain,
+   the original scattering when ORIGINAL_P is true, otherwise add the
+   transformed scattering.  */
+
+static inline void
+combine_context_id_scat (ppl_Pointset_Powerset_C_Polyhedron_t *res,
+                        poly_bb_p pbb, bool original_p)
+{
+  ppl_Pointset_Powerset_C_Polyhedron_t context;
+  ppl_Pointset_Powerset_C_Polyhedron_t id;
+
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron
+    (res, original_p ?
+     PBB_ORIGINAL_SCATTERING (pbb) : PBB_TRANSFORMED_SCATTERING (pbb));
+
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
+    (&context, SCOP_CONTEXT (PBB_SCOP (pbb)));
+
+  ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
+    (&id, PBB_DOMAIN (pbb));
+
+  /* Extend the context and the iteration domain to the dimension of
+     the scattering: T|I|G.  */
+  {
+    ppl_dimension_type gdim, tdim, idim;
+
+    ppl_Pointset_Powerset_C_Polyhedron_space_dimension (*res, &tdim);
+    ppl_Pointset_Powerset_C_Polyhedron_space_dimension (context, &gdim);
+    ppl_Pointset_Powerset_C_Polyhedron_space_dimension (id, &idim);
+
+    if (tdim > gdim)
+      ppl_insert_dimensions_pointset (context, 0, tdim - gdim);
+
+    if (tdim > idim)
+      ppl_insert_dimensions_pointset (id, 0, tdim - idim);
+  }
+
+  /* Add the context and the iteration domain to the result.  */
+  ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (*res, context);
+  ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (*res, id);
+
+  ppl_delete_Pointset_Powerset_C_Polyhedron (context);
+  ppl_delete_Pointset_Powerset_C_Polyhedron (id);
+}
+
 #endif