OSDN Git Service

2010-04-27 Martin Jambor <mjambor@suse.cz>
[pf3gnuchains/gcc-fork.git] / gcc / lambda.h
index 9855b6f..c819027 100644 (file)
@@ -1,12 +1,13 @@
 /* Lambda matrix and vector interface.
-   Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+   Free Software Foundation, Inc.
    Contributed by Daniel Berlin <dberlin@dberlin.org>
 
 This file is part of GCC.
 
 GCC is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
-Software Foundation; either version 2, or (at your option) any later
+Software Foundation; either version 3, or (at your option) any later
 version.
 
 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
@@ -15,9 +16,8 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING.  If not, write to the Free
-Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.  */
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
 
 #ifndef LAMBDA_H
 #define LAMBDA_H
@@ -29,15 +29,25 @@ Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
    and scalar multiplication.  In this vector space, an element is a list of
    integers.  */
 typedef int *lambda_vector;
+DEF_VEC_P(lambda_vector);
+DEF_VEC_ALLOC_P(lambda_vector,heap);
+DEF_VEC_ALLOC_P(lambda_vector,gc);
+
+typedef VEC(lambda_vector, heap) *lambda_vector_vec_p;
+DEF_VEC_P (lambda_vector_vec_p);
+DEF_VEC_ALLOC_P (lambda_vector_vec_p, heap);
 
 /* An integer matrix.  A matrix consists of m vectors of length n (IE
    all vectors are the same length).  */
 typedef lambda_vector *lambda_matrix;
 
+DEF_VEC_P (lambda_matrix);
+DEF_VEC_ALLOC_P (lambda_matrix, heap);
+
 /* A transformation matrix, which is a self-contained ROWSIZE x COLSIZE
    matrix.  Rather than use floats, we simply keep a single DENOMINATOR that
    represents the denominator for every element in the matrix.  */
-typedef struct
+typedef struct lambda_trans_matrix_s
 {
   lambda_matrix matrix;
   int rowsize;
@@ -58,7 +68,7 @@ typedef struct
    This structure is used during code generation in order to rewrite the old
    induction variable uses in a statement in terms of the newly created
    induction variables.  */
-typedef struct
+typedef struct lambda_body_vector_s
 {
   lambda_vector coefficients;
   int size;
@@ -68,16 +78,16 @@ typedef struct
 #define LBV_SIZE(T) ((T)->size)
 #define LBV_DENOMINATOR(T) ((T)->denominator)
 
-/* Piecewise linear expression.  
+/* Piecewise linear expression.
    This structure represents a linear expression with terms for the invariants
-   and induction variables of a loop. 
+   and induction variables of a loop.
    COEFFICIENTS is a vector of coefficients for the induction variables, one
    per loop in the loop nest.
    CONSTANT is the constant portion of the linear expression
    INVARIANT_COEFFICIENTS is a vector of coefficients for the loop invariants,
    one per invariant.
    DENOMINATOR is the denominator for all of the coefficients and constants in
-   the expression.  
+   the expression.
    The linear expressions can be linked together using the NEXT field, in
    order to represent MAX or MIN of a group of linear expressions.  */
 typedef struct lambda_linear_expression_s
@@ -95,7 +105,10 @@ typedef struct lambda_linear_expression_s
 #define LLE_DENOMINATOR(T) ((T)->denominator)
 #define LLE_NEXT(T) ((T)->next)
 
-lambda_linear_expression lambda_linear_expression_new (int, int);
+struct obstack;
+
+lambda_linear_expression lambda_linear_expression_new (int, int,
+                                                       struct obstack *);
 void print_lambda_linear_expression (FILE *, lambda_linear_expression, int,
                                     int, char);
 
@@ -118,13 +131,13 @@ typedef struct lambda_loop_s
 #define LL_LINEAR_OFFSET(T) ((T)->linear_offset)
 #define LL_STEP(T)   ((T)->step)
 
-/* Loop nest structure.  
+/* Loop nest structure.
    The loop nest structure consists of a set of loop structures (defined
    above) in LOOPS, along with an integer representing the DEPTH of the loop,
    and an integer representing the number of INVARIANTS in the loop.  Both of
    these integers are used to size the associated coefficient vectors in the
    linear expression structures.  */
-typedef struct
+typedef struct lambda_loopnest_s
 {
   lambda_loop *loops;
   int depth;
@@ -135,19 +148,17 @@ typedef struct
 #define LN_DEPTH(T) ((T)->depth)
 #define LN_INVARIANTS(T) ((T)->invariants)
 
-lambda_loopnest lambda_loopnest_new (int, int);
-lambda_loopnest lambda_loopnest_transform (lambda_loopnest, lambda_trans_matrix);
+lambda_loopnest lambda_loopnest_new (int, int, struct obstack *);
+lambda_loopnest lambda_loopnest_transform (lambda_loopnest,
+                                           lambda_trans_matrix,
+                                           struct obstack *);
 struct loop;
-struct loops;
 bool perfect_nest_p (struct loop *);
-bool lambda_transform_legal_p (lambda_trans_matrix, int, varray_type);
 void print_lambda_loopnest (FILE *, lambda_loopnest, char);
 
-#define lambda_loop_new() (lambda_loop) ggc_alloc_cleared (sizeof (struct lambda_loop_s))
-
 void print_lambda_loop (FILE *, lambda_loop, int, int, char);
 
-lambda_matrix lambda_matrix_new (int, int);
+lambda_matrix lambda_matrix_new (int, int, struct obstack *);
 
 void lambda_matrix_id (lambda_matrix, int);
 bool lambda_matrix_id_p (lambda_matrix, int);
@@ -169,40 +180,44 @@ void lambda_matrix_col_exchange (lambda_matrix, int, int, int);
 void lambda_matrix_col_add (lambda_matrix, int, int, int, int);
 void lambda_matrix_col_negate (lambda_matrix, int, int);
 void lambda_matrix_col_mc (lambda_matrix, int, int, int);
-int lambda_matrix_inverse (lambda_matrix, lambda_matrix, int);
+int lambda_matrix_inverse (lambda_matrix, lambda_matrix, int, struct obstack *);
 void lambda_matrix_hermite (lambda_matrix, int, lambda_matrix, lambda_matrix);
 void lambda_matrix_left_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
 void lambda_matrix_right_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
 int lambda_matrix_first_nz_vec (lambda_matrix, int, int, int);
-void lambda_matrix_project_to_null (lambda_matrix, int, int, int, 
+void lambda_matrix_project_to_null (lambda_matrix, int, int, int,
                                    lambda_vector);
 void print_lambda_matrix (FILE *, lambda_matrix, int, int);
 
-lambda_trans_matrix lambda_trans_matrix_new (int, int);
+lambda_trans_matrix lambda_trans_matrix_new (int, int, struct obstack *);
 bool lambda_trans_matrix_nonsingular_p (lambda_trans_matrix);
 bool lambda_trans_matrix_fullrank_p (lambda_trans_matrix);
 int lambda_trans_matrix_rank (lambda_trans_matrix);
 lambda_trans_matrix lambda_trans_matrix_basis (lambda_trans_matrix);
 lambda_trans_matrix lambda_trans_matrix_padding (lambda_trans_matrix);
-lambda_trans_matrix lambda_trans_matrix_inverse (lambda_trans_matrix);
+lambda_trans_matrix lambda_trans_matrix_inverse (lambda_trans_matrix,
+                                                struct obstack *);
 void print_lambda_trans_matrix (FILE *, lambda_trans_matrix);
-void lambda_matrix_vector_mult (lambda_matrix, int, int, lambda_vector, 
+void lambda_matrix_vector_mult (lambda_matrix, int, int, lambda_vector,
                                lambda_vector);
 bool lambda_trans_matrix_id_p (lambda_trans_matrix);
 
-lambda_body_vector lambda_body_vector_new (int);
-lambda_body_vector lambda_body_vector_compute_new (lambda_trans_matrix, 
-                                                  lambda_body_vector);
+lambda_body_vector lambda_body_vector_new (int, struct obstack *);
+lambda_body_vector lambda_body_vector_compute_new (lambda_trans_matrix,
+                                                   lambda_body_vector,
+                                                   struct obstack *);
 void print_lambda_body_vector (FILE *, lambda_body_vector);
-lambda_loopnest gcc_loopnest_to_lambda_loopnest (struct loops *,
-                                                struct loop *,
+lambda_loopnest gcc_loopnest_to_lambda_loopnest (struct loop *,
                                                 VEC(tree,heap) **,
-                                                VEC(tree,heap) **,
-                                                bool);
+                                                 VEC(tree,heap) **,
+                                                 struct obstack *);
 void lambda_loopnest_to_gcc_loopnest (struct loop *,
                                      VEC(tree,heap) *, VEC(tree,heap) *,
-                                     lambda_loopnest, lambda_trans_matrix);
-
+                                     VEC(gimple,heap) **,
+                                      lambda_loopnest, lambda_trans_matrix,
+                                      struct obstack *);
+void remove_iv (gimple);
+tree find_induction_var_from_exit_cond (struct loop *);
 
 static inline void lambda_vector_negate (lambda_vector, lambda_vector, int);
 static inline void lambda_vector_mult_const (lambda_vector, lambda_vector, int, int);
@@ -223,7 +238,7 @@ static inline void print_lambda_vector (FILE *, lambda_vector, int);
 static inline lambda_vector
 lambda_vector_new (int size)
 {
-  return ggc_alloc_cleared (size * sizeof(int));
+  return GGC_CNEWVEC (int, size);
 }
 
 
@@ -246,7 +261,7 @@ lambda_vector_mult_const (lambda_vector vec1, lambda_vector vec2,
 
 /* Negate vector VEC1 with length SIZE and store it in VEC2.  */
 
-static inline void 
+static inline void
 lambda_vector_negate (lambda_vector vec1, lambda_vector vec2,
                      int size)
 {
@@ -287,7 +302,7 @@ lambda_vector_copy (lambda_vector vec1, lambda_vector vec2,
 
 /* Return true if vector VEC1 of length SIZE is the zero vector.  */
 
-static inline bool 
+static inline bool
 lambda_vector_zerop (lambda_vector vec1, int size)
 {
   int i;
@@ -306,7 +321,7 @@ lambda_vector_clear (lambda_vector vec1, int size)
 }
 
 /* Return true if two vectors are equal.  */
+
 static inline bool
 lambda_vector_equal (lambda_vector vec1, lambda_vector vec2, int size)
 {
@@ -354,7 +369,7 @@ lambda_vector_first_nz (lambda_vector vec1, int n, int start)
 /* Multiply a vector by a matrix.  */
 
 static inline void
-lambda_vector_matrix_mult (lambda_vector vect, int m, lambda_matrix mat, 
+lambda_vector_matrix_mult (lambda_vector vect, int m, lambda_matrix mat,
                           int n, lambda_vector dest)
 {
   int i, j;
@@ -364,6 +379,33 @@ lambda_vector_matrix_mult (lambda_vector vect, int m, lambda_matrix mat,
       dest[i] += mat[j][i] * vect[j];
 }
 
+/* Compare two vectors returning an integer less than, equal to, or
+   greater than zero if the first argument is considered to be respectively
+   less than, equal to, or greater than the second.
+   We use the lexicographic order.  */
+
+static inline int
+lambda_vector_compare (lambda_vector vec1, int length1, lambda_vector vec2,
+                       int length2)
+{
+  int min_length;
+  int i;
+
+  if (length1 < length2)
+    min_length = length1;
+  else
+    min_length = length2;
+
+  for (i = 0; i < min_length; i++)
+    if (vec1[i] < vec2[i])
+      return -1;
+    else if (vec1[i] > vec2[i])
+      return 1;
+    else
+      continue;
+
+  return length1 - length2;
+}
 
 /* Print out a vector VEC of length N to OUTFILE.  */
 
@@ -377,11 +419,49 @@ print_lambda_vector (FILE * outfile, lambda_vector vector, int n)
   fprintf (outfile, "\n");
 }
 
+/* Compute the greatest common divisor of two numbers using
+   Euclid's algorithm.  */
+
+static inline int
+gcd (int a, int b)
+{
+  int x, y, z;
+
+  x = abs (a);
+  y = abs (b);
+
+  while (x > 0)
+    {
+      z = y % x;
+      y = x;
+      x = z;
+    }
+
+  return y;
+}
+
+/* Compute the greatest common divisor of a VECTOR of SIZE numbers.  */
+
+static inline int
+lambda_vector_gcd (lambda_vector vector, int size)
+{
+  int i;
+  int gcd1 = 0;
+
+  if (size > 0)
+    {
+      gcd1 = vector[0];
+      for (i = 1; i < size; i++)
+       gcd1 = gcd (gcd1, vector[i]);
+    }
+  return gcd1;
+}
+
 /* Returns true when the vector V is lexicographically positive, in
    other words, when the first nonzero element is positive.  */
 
 static inline bool
-lambda_vector_lexico_pos (lambda_vector v, 
+lambda_vector_lexico_pos (lambda_vector v,
                          unsigned n)
 {
   unsigned i;
@@ -397,5 +477,48 @@ lambda_vector_lexico_pos (lambda_vector v,
   return true;
 }
 
-#endif /* LAMBDA_H  */
+/* Given a vector of induction variables IVS, and a vector of
+   coefficients COEFS, build a tree that is a linear combination of
+   the induction variables.  */
+
+static inline tree
+build_linear_expr (tree type, lambda_vector coefs, VEC (tree, heap) *ivs)
+{
+  unsigned i;
+  tree iv;
+  tree expr = fold_convert (type, integer_zero_node);
+
+  for (i = 0; VEC_iterate (tree, ivs, i, iv); i++)
+    {
+      int k = coefs[i];
 
+      if (k == 1)
+       expr = fold_build2 (PLUS_EXPR, type, expr, iv);
+
+      else if (k != 0)
+       expr = fold_build2 (PLUS_EXPR, type, expr,
+                           fold_build2 (MULT_EXPR, type, iv,
+                                        build_int_cst (type, k)));
+    }
+
+  return expr;
+}
+
+/* Returns the dependence level for a vector DIST of size LENGTH.
+   LEVEL = 0 means a lexicographic dependence, i.e. a dependence due
+   to the sequence of statements, not carried by any loop.  */
+
+
+static inline unsigned
+dependence_level (lambda_vector dist_vect, int length)
+{
+  int i;
+
+  for (i = 0; i < length; i++)
+    if (dist_vect[i] != 0)
+      return i + 1;
+
+  return 0;
+}
+
+#endif /* LAMBDA_H  */