]> gcc.gnu.org Git - gcc.git/blame - gcc/lambda.h
backport: configure: Regenerate.
[gcc.git] / gcc / lambda.h
CommitLineData
98975653 1/* Lambda matrix and vector interface.
9dcd6f09 2 Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
56cf8686
SP
3 Contributed by Daniel Berlin <dberlin@dberlin.org>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
56cf8686
SP
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
98975653 20
56cf8686
SP
21#ifndef LAMBDA_H
22#define LAMBDA_H
23
36d59cf7
DB
24#include "vec.h"
25
98975653
DB
26/* An integer vector. A vector formally consists of an element of a vector
27 space. A vector space is a set that is closed under vector addition
28 and scalar multiplication. In this vector space, an element is a list of
29 integers. */
56cf8686 30typedef int *lambda_vector;
304afda6
SP
31DEF_VEC_P(lambda_vector);
32DEF_VEC_ALLOC_P(lambda_vector,heap);
33
9f275479
JS
34typedef VEC(lambda_vector, heap) *lambda_vector_vec_p;
35DEF_VEC_P (lambda_vector_vec_p);
36DEF_VEC_ALLOC_P (lambda_vector_vec_p, heap);
37
98975653
DB
38/* An integer matrix. A matrix consists of m vectors of length n (IE
39 all vectors are the same length). */
40typedef lambda_vector *lambda_matrix;
41
f8bf9252
SP
42DEF_VEC_P (lambda_matrix);
43DEF_VEC_ALLOC_P (lambda_matrix, heap);
44
c4bda9f0
DB
45/* A transformation matrix, which is a self-contained ROWSIZE x COLSIZE
46 matrix. Rather than use floats, we simply keep a single DENOMINATOR that
47 represents the denominator for every element in the matrix. */
45222d4a 48typedef struct lambda_trans_matrix_s
36d59cf7
DB
49{
50 lambda_matrix matrix;
51 int rowsize;
52 int colsize;
53 int denominator;
54} *lambda_trans_matrix;
55#define LTM_MATRIX(T) ((T)->matrix)
56#define LTM_ROWSIZE(T) ((T)->rowsize)
57#define LTM_COLSIZE(T) ((T)->colsize)
58#define LTM_DENOMINATOR(T) ((T)->denominator)
59
c4bda9f0
DB
60/* A vector representing a statement in the body of a loop.
61 The COEFFICIENTS vector contains a coefficient for each induction variable
62 in the loop nest containing the statement.
63 The DENOMINATOR represents the denominator for each coefficient in the
64 COEFFICIENT vector.
65
66 This structure is used during code generation in order to rewrite the old
67 induction variable uses in a statement in terms of the newly created
68 induction variables. */
45222d4a 69typedef struct lambda_body_vector_s
36d59cf7
DB
70{
71 lambda_vector coefficients;
72 int size;
73 int denominator;
74} *lambda_body_vector;
75#define LBV_COEFFICIENTS(T) ((T)->coefficients)
76#define LBV_SIZE(T) ((T)->size)
77#define LBV_DENOMINATOR(T) ((T)->denominator)
78
c4bda9f0
DB
79/* Piecewise linear expression.
80 This structure represents a linear expression with terms for the invariants
81 and induction variables of a loop.
82 COEFFICIENTS is a vector of coefficients for the induction variables, one
83 per loop in the loop nest.
84 CONSTANT is the constant portion of the linear expression
85 INVARIANT_COEFFICIENTS is a vector of coefficients for the loop invariants,
86 one per invariant.
87 DENOMINATOR is the denominator for all of the coefficients and constants in
88 the expression.
89 The linear expressions can be linked together using the NEXT field, in
90 order to represent MAX or MIN of a group of linear expressions. */
36d59cf7
DB
91typedef struct lambda_linear_expression_s
92{
93 lambda_vector coefficients;
94 int constant;
95 lambda_vector invariant_coefficients;
96 int denominator;
97 struct lambda_linear_expression_s *next;
98} *lambda_linear_expression;
99
100#define LLE_COEFFICIENTS(T) ((T)->coefficients)
101#define LLE_CONSTANT(T) ((T)->constant)
102#define LLE_INVARIANT_COEFFICIENTS(T) ((T)->invariant_coefficients)
103#define LLE_DENOMINATOR(T) ((T)->denominator)
104#define LLE_NEXT(T) ((T)->next)
105
b9dd78fa
LB
106struct obstack;
107
108lambda_linear_expression lambda_linear_expression_new (int, int,
109 struct obstack *);
36d59cf7
DB
110void print_lambda_linear_expression (FILE *, lambda_linear_expression, int,
111 int, char);
112
c4bda9f0
DB
113/* Loop structure. Our loop structure consists of a constant representing the
114 STEP of the loop, a set of linear expressions representing the LOWER_BOUND
115 of the loop, a set of linear expressions representing the UPPER_BOUND of
116 the loop, and a set of linear expressions representing the LINEAR_OFFSET of
117 the loop. The linear offset is a set of linear expressions that are
118 applied to *both* the lower bound, and the upper bound. */
36d59cf7
DB
119typedef struct lambda_loop_s
120{
121 lambda_linear_expression lower_bound;
122 lambda_linear_expression upper_bound;
123 lambda_linear_expression linear_offset;
124 int step;
125} *lambda_loop;
126
127#define LL_LOWER_BOUND(T) ((T)->lower_bound)
128#define LL_UPPER_BOUND(T) ((T)->upper_bound)
129#define LL_LINEAR_OFFSET(T) ((T)->linear_offset)
130#define LL_STEP(T) ((T)->step)
131
c4bda9f0
DB
132/* Loop nest structure.
133 The loop nest structure consists of a set of loop structures (defined
134 above) in LOOPS, along with an integer representing the DEPTH of the loop,
135 and an integer representing the number of INVARIANTS in the loop. Both of
136 these integers are used to size the associated coefficient vectors in the
137 linear expression structures. */
45222d4a 138typedef struct lambda_loopnest_s
36d59cf7
DB
139{
140 lambda_loop *loops;
141 int depth;
142 int invariants;
143} *lambda_loopnest;
144
145#define LN_LOOPS(T) ((T)->loops)
146#define LN_DEPTH(T) ((T)->depth)
147#define LN_INVARIANTS(T) ((T)->invariants)
148
b9dd78fa
LB
149lambda_loopnest lambda_loopnest_new (int, int, struct obstack *);
150lambda_loopnest lambda_loopnest_transform (lambda_loopnest,
151 lambda_trans_matrix,
152 struct obstack *);
f67d92e9 153struct loop;
f67d92e9 154bool perfect_nest_p (struct loop *);
36d59cf7
DB
155void print_lambda_loopnest (FILE *, lambda_loopnest, char);
156
157#define lambda_loop_new() (lambda_loop) ggc_alloc_cleared (sizeof (struct lambda_loop_s))
158
159void print_lambda_loop (FILE *, lambda_loop, int, int, char);
160
98975653
DB
161lambda_matrix lambda_matrix_new (int, int);
162
163void lambda_matrix_id (lambda_matrix, int);
f67d92e9 164bool lambda_matrix_id_p (lambda_matrix, int);
98975653
DB
165void lambda_matrix_copy (lambda_matrix, lambda_matrix, int, int);
166void lambda_matrix_negate (lambda_matrix, lambda_matrix, int, int);
167void lambda_matrix_transpose (lambda_matrix, lambda_matrix, int, int);
168void lambda_matrix_add (lambda_matrix, lambda_matrix, lambda_matrix, int,
169 int);
170void lambda_matrix_add_mc (lambda_matrix, int, lambda_matrix, int,
171 lambda_matrix, int, int);
172void lambda_matrix_mult (lambda_matrix, lambda_matrix, lambda_matrix,
173 int, int, int);
174void lambda_matrix_delete_rows (lambda_matrix, int, int, int);
175void lambda_matrix_row_exchange (lambda_matrix, int, int);
176void lambda_matrix_row_add (lambda_matrix, int, int, int, int);
177void lambda_matrix_row_negate (lambda_matrix mat, int, int);
178void lambda_matrix_row_mc (lambda_matrix, int, int, int);
179void lambda_matrix_col_exchange (lambda_matrix, int, int, int);
180void lambda_matrix_col_add (lambda_matrix, int, int, int, int);
181void lambda_matrix_col_negate (lambda_matrix, int, int);
182void lambda_matrix_col_mc (lambda_matrix, int, int, int);
183int lambda_matrix_inverse (lambda_matrix, lambda_matrix, int);
184void lambda_matrix_hermite (lambda_matrix, int, lambda_matrix, lambda_matrix);
185void lambda_matrix_left_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
186void lambda_matrix_right_hermite (lambda_matrix, int, int, lambda_matrix, lambda_matrix);
187int lambda_matrix_first_nz_vec (lambda_matrix, int, int, int);
188void lambda_matrix_project_to_null (lambda_matrix, int, int, int,
189 lambda_vector);
190void print_lambda_matrix (FILE *, lambda_matrix, int, int);
191
36d59cf7
DB
192lambda_trans_matrix lambda_trans_matrix_new (int, int);
193bool lambda_trans_matrix_nonsingular_p (lambda_trans_matrix);
194bool lambda_trans_matrix_fullrank_p (lambda_trans_matrix);
195int lambda_trans_matrix_rank (lambda_trans_matrix);
196lambda_trans_matrix lambda_trans_matrix_basis (lambda_trans_matrix);
197lambda_trans_matrix lambda_trans_matrix_padding (lambda_trans_matrix);
198lambda_trans_matrix lambda_trans_matrix_inverse (lambda_trans_matrix);
199void print_lambda_trans_matrix (FILE *, lambda_trans_matrix);
98975653
DB
200void lambda_matrix_vector_mult (lambda_matrix, int, int, lambda_vector,
201 lambda_vector);
f67d92e9 202bool lambda_trans_matrix_id_p (lambda_trans_matrix);
98975653 203
b9dd78fa
LB
204lambda_body_vector lambda_body_vector_new (int, struct obstack *);
205lambda_body_vector lambda_body_vector_compute_new (lambda_trans_matrix,
206 lambda_body_vector,
207 struct obstack *);
36d59cf7 208void print_lambda_body_vector (FILE *, lambda_body_vector);
d73be268 209lambda_loopnest gcc_loopnest_to_lambda_loopnest (struct loop *,
e6ef8d81 210 VEC(tree,heap) **,
b9dd78fa
LB
211 VEC(tree,heap) **,
212 struct obstack *);
e6ef8d81
NS
213void lambda_loopnest_to_gcc_loopnest (struct loop *,
214 VEC(tree,heap) *, VEC(tree,heap) *,
726a989a 215 VEC(gimple,heap) **,
b9dd78fa
LB
216 lambda_loopnest, lambda_trans_matrix,
217 struct obstack *);
726a989a 218void remove_iv (gimple);
f8bf9252 219tree find_induction_var_from_exit_cond (struct loop *);
36d59cf7 220
98975653
DB
221static inline void lambda_vector_negate (lambda_vector, lambda_vector, int);
222static inline void lambda_vector_mult_const (lambda_vector, lambda_vector, int, int);
223static inline void lambda_vector_add (lambda_vector, lambda_vector,
224 lambda_vector, int);
225static inline void lambda_vector_add_mc (lambda_vector, int, lambda_vector, int,
226 lambda_vector, int);
227static inline void lambda_vector_copy (lambda_vector, lambda_vector, int);
228static inline bool lambda_vector_zerop (lambda_vector, int);
229static inline void lambda_vector_clear (lambda_vector, int);
230static inline bool lambda_vector_equal (lambda_vector, lambda_vector, int);
231static inline int lambda_vector_min_nz (lambda_vector, int, int);
232static inline int lambda_vector_first_nz (lambda_vector, int, int);
233static inline void print_lambda_vector (FILE *, lambda_vector, int);
56cf8686
SP
234
235/* Allocate a new vector of given SIZE. */
236
237static inline lambda_vector
238lambda_vector_new (int size)
239{
cceb1885 240 return GGC_CNEWVEC (int, size);
56cf8686
SP
241}
242
98975653
DB
243
244
245/* Multiply vector VEC1 of length SIZE by a constant CONST1,
246 and store the result in VEC2. */
247
248static inline void
249lambda_vector_mult_const (lambda_vector vec1, lambda_vector vec2,
250 int size, int const1)
251{
252 int i;
253
254 if (const1 == 0)
255 lambda_vector_clear (vec2, size);
256 else
257 for (i = 0; i < size; i++)
258 vec2[i] = const1 * vec1[i];
259}
260
261/* Negate vector VEC1 with length SIZE and store it in VEC2. */
262
263static inline void
264lambda_vector_negate (lambda_vector vec1, lambda_vector vec2,
265 int size)
266{
267 lambda_vector_mult_const (vec1, vec2, size, -1);
268}
269
270/* VEC3 = VEC1+VEC2, where all three the vectors are of length SIZE. */
271
272static inline void
273lambda_vector_add (lambda_vector vec1, lambda_vector vec2,
274 lambda_vector vec3, int size)
275{
276 int i;
277 for (i = 0; i < size; i++)
278 vec3[i] = vec1[i] + vec2[i];
279}
280
281/* VEC3 = CONSTANT1*VEC1 + CONSTANT2*VEC2. All vectors have length SIZE. */
282
283static inline void
284lambda_vector_add_mc (lambda_vector vec1, int const1,
285 lambda_vector vec2, int const2,
286 lambda_vector vec3, int size)
287{
288 int i;
289 for (i = 0; i < size; i++)
290 vec3[i] = const1 * vec1[i] + const2 * vec2[i];
291}
292
293/* Copy the elements of vector VEC1 with length SIZE to VEC2. */
294
295static inline void
296lambda_vector_copy (lambda_vector vec1, lambda_vector vec2,
297 int size)
298{
299 memcpy (vec2, vec1, size * sizeof (*vec1));
300}
301
302/* Return true if vector VEC1 of length SIZE is the zero vector. */
303
304static inline bool
305lambda_vector_zerop (lambda_vector vec1, int size)
306{
307 int i;
308 for (i = 0; i < size; i++)
309 if (vec1[i] != 0)
310 return false;
311 return true;
312}
313
56cf8686
SP
314/* Clear out vector VEC1 of length SIZE. */
315
316static inline void
317lambda_vector_clear (lambda_vector vec1, int size)
318{
98975653 319 memset (vec1, 0, size * sizeof (*vec1));
56cf8686
SP
320}
321
98975653
DB
322/* Return true if two vectors are equal. */
323
324static inline bool
325lambda_vector_equal (lambda_vector vec1, lambda_vector vec2, int size)
326{
327 int i;
328 for (i = 0; i < size; i++)
329 if (vec1[i] != vec2[i])
330 return false;
331 return true;
332}
333
8e3c61c5 334/* Return the minimum nonzero element in vector VEC1 between START and N.
98975653
DB
335 We must have START <= N. */
336
337static inline int
338lambda_vector_min_nz (lambda_vector vec1, int n, int start)
339{
340 int j;
341 int min = -1;
0e61db61
NS
342
343 gcc_assert (start <= n);
98975653
DB
344 for (j = start; j < n; j++)
345 {
346 if (vec1[j])
347 if (min < 0 || vec1[j] < vec1[min])
348 min = j;
349 }
0e61db61 350 gcc_assert (min >= 0);
98975653
DB
351
352 return min;
353}
354
355/* Return the first nonzero element of vector VEC1 between START and N.
356 We must have START <= N. Returns N if VEC1 is the zero vector. */
357
358static inline int
359lambda_vector_first_nz (lambda_vector vec1, int n, int start)
360{
361 int j = start;
362 while (j < n && vec1[j] == 0)
363 j++;
364 return j;
365}
366
367
368/* Multiply a vector by a matrix. */
369
370static inline void
371lambda_vector_matrix_mult (lambda_vector vect, int m, lambda_matrix mat,
372 int n, lambda_vector dest)
373{
374 int i, j;
375 lambda_vector_clear (dest, n);
376 for (i = 0; i < n; i++)
377 for (j = 0; j < m; j++)
378 dest[i] += mat[j][i] * vect[j];
379}
380
f8bf9252
SP
381/* Compare two vectors returning an integer less than, equal to, or
382 greater than zero if the first argument is considered to be respectively
383 less than, equal to, or greater than the second.
384 We use the lexicographic order. */
385
386static inline int
387lambda_vector_compare (lambda_vector vec1, int length1, lambda_vector vec2,
388 int length2)
389{
390 int min_length;
391 int i;
392
393 if (length1 < length2)
394 min_length = length1;
395 else
396 min_length = length2;
397
398 for (i = 0; i < min_length; i++)
399 if (vec1[i] < vec2[i])
400 return -1;
401 else if (vec1[i] > vec2[i])
402 return 1;
403 else
404 continue;
405
406 return length1 - length2;
407}
98975653 408
56cf8686
SP
409/* Print out a vector VEC of length N to OUTFILE. */
410
411static inline void
412print_lambda_vector (FILE * outfile, lambda_vector vector, int n)
413{
414 int i;
415
416 for (i = 0; i < n; i++)
417 fprintf (outfile, "%3d ", vector[i]);
418 fprintf (outfile, "\n");
419}
37b8a73b 420
0ff4040e
SP
421/* Compute the greatest common divisor of two numbers using
422 Euclid's algorithm. */
423
424static inline int
425gcd (int a, int b)
426{
427 int x, y, z;
428
429 x = abs (a);
430 y = abs (b);
431
432 while (x > 0)
433 {
434 z = y % x;
435 y = x;
436 x = z;
437 }
438
439 return y;
440}
441
442/* Compute the greatest common divisor of a VECTOR of SIZE numbers. */
443
444static inline int
445lambda_vector_gcd (lambda_vector vector, int size)
446{
447 int i;
448 int gcd1 = 0;
449
450 if (size > 0)
451 {
452 gcd1 = vector[0];
453 for (i = 1; i < size; i++)
454 gcd1 = gcd (gcd1, vector[i]);
455 }
456 return gcd1;
457}
458
37b8a73b
SP
459/* Returns true when the vector V is lexicographically positive, in
460 other words, when the first nonzero element is positive. */
461
462static inline bool
463lambda_vector_lexico_pos (lambda_vector v,
464 unsigned n)
465{
466 unsigned i;
467 for (i = 0; i < n; i++)
468 {
469 if (v[i] == 0)
470 continue;
471 if (v[i] < 0)
472 return false;
473 if (v[i] > 0)
474 return true;
475 }
476 return true;
477}
478
69f2880c
JS
479/* Given a vector of induction variables IVS, and a vector of
480 coefficients COEFS, build a tree that is a linear combination of
481 the induction variables. */
482
483static inline tree
484build_linear_expr (tree type, lambda_vector coefs, VEC (tree, heap) *ivs)
485{
486 unsigned i;
487 tree iv;
488 tree expr = fold_convert (type, integer_zero_node);
489
490 for (i = 0; VEC_iterate (tree, ivs, i, iv); i++)
491 {
492 int k = coefs[i];
493
494 if (k == 1)
495 expr = fold_build2 (PLUS_EXPR, type, expr, iv);
496
497 else if (k != 0)
498 expr = fold_build2 (PLUS_EXPR, type, expr,
499 fold_build2 (MULT_EXPR, type, iv,
500 build_int_cst (type, k)));
501 }
502
503 return expr;
504}
505
dea61d92
SP
506/* Returns the dependence level for a vector DIST of size LENGTH.
507 LEVEL = 0 means a lexicographic dependence, i.e. a dependence due
508 to the sequence of statements, not carried by any loop. */
509
510
511static inline unsigned
512dependence_level (lambda_vector dist_vect, int length)
513{
514 int i;
515
516 for (i = 0; i < length; i++)
517 if (dist_vect[i] != 0)
518 return i + 1;
519
520 return 0;
521}
522
56cf8686 523#endif /* LAMBDA_H */
This page took 1.380475 seconds and 5 git commands to generate.