+/* 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,
+ unsigned n)
+{
+ unsigned i;
+ for (i = 0; i < n; i++)
+ {
+ if (v[i] == 0)
+ continue;
+ if (v[i] < 0)
+ return false;
+ if (v[i] > 0)
+ return true;
+ }
+ return true;
+}
+
+/* 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 */