1 /* Loop transformation code generation
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
4 Contributed by Daniel Berlin <dberlin@dberlin.org>
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
24 #include "coretypes.h"
25 #include "tree-flow.h"
27 #include "tree-chrec.h"
28 #include "tree-data-ref.h"
29 #include "tree-scalar-evolution.h"
31 #include "tree-pass.h"
33 /* This loop nest code generation is based on non-singular matrix
36 A little terminology and a general sketch of the algorithm. See "A singular
37 loop transformation framework based on non-singular matrices" by Wei Li and
38 Keshav Pingali for formal proofs that the various statements below are
41 A loop iteration space represents the points traversed by the loop. A point in the
42 iteration space can be represented by a vector of size <loop depth>. You can
43 therefore represent the iteration space as an integral combinations of a set
46 A loop iteration space is dense if every integer point between the loop
47 bounds is a point in the iteration space. Every loop with a step of 1
48 therefore has a dense iteration space.
50 for i = 1 to 3, step 1 is a dense iteration space.
52 A loop iteration space is sparse if it is not dense. That is, the iteration
53 space skips integer points that are within the loop bounds.
55 for i = 1 to 3, step 2 is a sparse iteration space, because the integer point
58 Dense source spaces are easy to transform, because they don't skip any
59 points to begin with. Thus we can compute the exact bounds of the target
60 space using min/max and floor/ceil.
62 For a dense source space, we take the transformation matrix, decompose it
63 into a lower triangular part (H) and a unimodular part (U).
64 We then compute the auxiliary space from the unimodular part (source loop
65 nest . U = auxiliary space) , which has two important properties:
66 1. It traverses the iterations in the same lexicographic order as the source
68 2. It is a dense space when the source is a dense space (even if the target
69 space is going to be sparse).
71 Given the auxiliary space, we use the lower triangular part to compute the
72 bounds in the target space by simple matrix multiplication.
73 The gaps in the target space (IE the new loop step sizes) will be the
74 diagonals of the H matrix.
76 Sparse source spaces require another step, because you can't directly compute
77 the exact bounds of the auxiliary and target space from the sparse space.
78 Rather than try to come up with a separate algorithm to handle sparse source
79 spaces directly, we just find a legal transformation matrix that gives you
80 the sparse source space, from a dense space, and then transform the dense
83 For a regular sparse space, you can represent the source space as an integer
84 lattice, and the base space of that lattice will always be dense. Thus, we
85 effectively use the lattice to figure out the transformation from the lattice
86 base space, to the sparse iteration space (IE what transform was applied to
87 the dense space to make it sparse). We then compose this transform with the
88 transformation matrix specified by the user (since our matrix transformations
89 are closed under composition, this is okay). We can then use the base space
90 (which is dense) plus the composed transformation matrix, to compute the rest
91 of the transform using the dense space algorithm above.
93 In other words, our sparse source space (B) is decomposed into a dense base
94 space (A), and a matrix (L) that transforms A into B, such that A.L = B.
95 We then compute the composition of L and the user transformation matrix (T),
96 so that T is now a transform from A to the result, instead of from B to the
98 IE A.(LT) = result instead of B.T = result
99 Since A is now a dense source space, we can use the dense source space
100 algorithm above to compute the result of applying transform (LT) to A.
102 Fourier-Motzkin elimination is used to compute the bounds of the base space
105 static bool perfect_nestify (struct loop
*, VEC(tree
,heap
) *,
106 VEC(tree
,heap
) *, VEC(int,heap
) *,
108 /* Lattice stuff that is internal to the code generation algorithm. */
110 typedef struct lambda_lattice_s
112 /* Lattice base matrix. */
114 /* Lattice dimension. */
116 /* Origin vector for the coefficients. */
117 lambda_vector origin
;
118 /* Origin matrix for the invariants. */
119 lambda_matrix origin_invariants
;
120 /* Number of invariants. */
124 #define LATTICE_BASE(T) ((T)->base)
125 #define LATTICE_DIMENSION(T) ((T)->dimension)
126 #define LATTICE_ORIGIN(T) ((T)->origin)
127 #define LATTICE_ORIGIN_INVARIANTS(T) ((T)->origin_invariants)
128 #define LATTICE_INVARIANTS(T) ((T)->invariants)
130 static bool lle_equal (lambda_linear_expression
, lambda_linear_expression
,
132 static lambda_lattice
lambda_lattice_new (int, int, struct obstack
*);
133 static lambda_lattice
lambda_lattice_compute_base (lambda_loopnest
,
136 static bool can_convert_to_perfect_nest (struct loop
*);
138 /* Create a new lambda loop in LAMBDA_OBSTACK. */
141 lambda_loop_new (struct obstack
* lambda_obstack
)
143 lambda_loop result
= (lambda_loop
)
144 obstack_alloc (lambda_obstack
, sizeof (struct lambda_loop_s
));
145 memset (result
, 0, sizeof (struct lambda_loop_s
));
149 /* Create a new lambda body vector. */
152 lambda_body_vector_new (int size
, struct obstack
* lambda_obstack
)
154 lambda_body_vector ret
;
156 ret
= (lambda_body_vector
) obstack_alloc (lambda_obstack
,
158 LBV_COEFFICIENTS (ret
) = lambda_vector_new (size
);
159 LBV_SIZE (ret
) = size
;
160 LBV_DENOMINATOR (ret
) = 1;
164 /* Compute the new coefficients for the vector based on the
165 *inverse* of the transformation matrix. */
168 lambda_body_vector_compute_new (lambda_trans_matrix transform
,
169 lambda_body_vector vect
,
170 struct obstack
* lambda_obstack
)
172 lambda_body_vector temp
;
175 /* Make sure the matrix is square. */
176 gcc_assert (LTM_ROWSIZE (transform
) == LTM_COLSIZE (transform
));
178 depth
= LTM_ROWSIZE (transform
);
180 temp
= lambda_body_vector_new (depth
, lambda_obstack
);
181 LBV_DENOMINATOR (temp
) =
182 LBV_DENOMINATOR (vect
) * LTM_DENOMINATOR (transform
);
183 lambda_vector_matrix_mult (LBV_COEFFICIENTS (vect
), depth
,
184 LTM_MATRIX (transform
), depth
,
185 LBV_COEFFICIENTS (temp
));
186 LBV_SIZE (temp
) = LBV_SIZE (vect
);
190 /* Print out a lambda body vector. */
193 print_lambda_body_vector (FILE * outfile
, lambda_body_vector body
)
195 print_lambda_vector (outfile
, LBV_COEFFICIENTS (body
), LBV_SIZE (body
));
198 /* Return TRUE if two linear expressions are equal. */
201 lle_equal (lambda_linear_expression lle1
, lambda_linear_expression lle2
,
202 int depth
, int invariants
)
206 if (lle1
== NULL
|| lle2
== NULL
)
208 if (LLE_CONSTANT (lle1
) != LLE_CONSTANT (lle2
))
210 if (LLE_DENOMINATOR (lle1
) != LLE_DENOMINATOR (lle2
))
212 for (i
= 0; i
< depth
; i
++)
213 if (LLE_COEFFICIENTS (lle1
)[i
] != LLE_COEFFICIENTS (lle2
)[i
])
215 for (i
= 0; i
< invariants
; i
++)
216 if (LLE_INVARIANT_COEFFICIENTS (lle1
)[i
] !=
217 LLE_INVARIANT_COEFFICIENTS (lle2
)[i
])
222 /* Create a new linear expression with dimension DIM, and total number
223 of invariants INVARIANTS. */
225 lambda_linear_expression
226 lambda_linear_expression_new (int dim
, int invariants
,
227 struct obstack
* lambda_obstack
)
229 lambda_linear_expression ret
;
231 ret
= (lambda_linear_expression
)obstack_alloc (lambda_obstack
,
233 LLE_COEFFICIENTS (ret
) = lambda_vector_new (dim
);
234 LLE_CONSTANT (ret
) = 0;
235 LLE_INVARIANT_COEFFICIENTS (ret
) = lambda_vector_new (invariants
);
236 LLE_DENOMINATOR (ret
) = 1;
237 LLE_NEXT (ret
) = NULL
;
242 /* Print out a linear expression EXPR, with SIZE coefficients, to OUTFILE.
243 The starting letter used for variable names is START. */
246 print_linear_expression (FILE * outfile
, lambda_vector expr
, int size
,
251 for (i
= 0; i
< size
; i
++)
258 fprintf (outfile
, "-");
261 else if (expr
[i
] > 0)
262 fprintf (outfile
, " + ");
264 fprintf (outfile
, " - ");
265 if (abs (expr
[i
]) == 1)
266 fprintf (outfile
, "%c", start
+ i
);
268 fprintf (outfile
, "%d%c", abs (expr
[i
]), start
+ i
);
273 /* Print out a lambda linear expression structure, EXPR, to OUTFILE. The
274 depth/number of coefficients is given by DEPTH, the number of invariants is
275 given by INVARIANTS, and the character to start variable names with is given
279 print_lambda_linear_expression (FILE * outfile
,
280 lambda_linear_expression expr
,
281 int depth
, int invariants
, char start
)
283 fprintf (outfile
, "\tLinear expression: ");
284 print_linear_expression (outfile
, LLE_COEFFICIENTS (expr
), depth
, start
);
285 fprintf (outfile
, " constant: %d ", LLE_CONSTANT (expr
));
286 fprintf (outfile
, " invariants: ");
287 print_linear_expression (outfile
, LLE_INVARIANT_COEFFICIENTS (expr
),
289 fprintf (outfile
, " denominator: %d\n", LLE_DENOMINATOR (expr
));
292 /* Print a lambda loop structure LOOP to OUTFILE. The depth/number of
293 coefficients is given by DEPTH, the number of invariants is
294 given by INVARIANTS, and the character to start variable names with is given
298 print_lambda_loop (FILE * outfile
, lambda_loop loop
, int depth
,
299 int invariants
, char start
)
302 lambda_linear_expression expr
;
306 expr
= LL_LINEAR_OFFSET (loop
);
307 step
= LL_STEP (loop
);
308 fprintf (outfile
, " step size = %d \n", step
);
312 fprintf (outfile
, " linear offset: \n");
313 print_lambda_linear_expression (outfile
, expr
, depth
, invariants
,
317 fprintf (outfile
, " lower bound: \n");
318 for (expr
= LL_LOWER_BOUND (loop
); expr
!= NULL
; expr
= LLE_NEXT (expr
))
319 print_lambda_linear_expression (outfile
, expr
, depth
, invariants
, start
);
320 fprintf (outfile
, " upper bound: \n");
321 for (expr
= LL_UPPER_BOUND (loop
); expr
!= NULL
; expr
= LLE_NEXT (expr
))
322 print_lambda_linear_expression (outfile
, expr
, depth
, invariants
, start
);
325 /* Create a new loop nest structure with DEPTH loops, and INVARIANTS as the
326 number of invariants. */
329 lambda_loopnest_new (int depth
, int invariants
,
330 struct obstack
* lambda_obstack
)
333 ret
= (lambda_loopnest
)obstack_alloc (lambda_obstack
, sizeof (*ret
));
335 LN_LOOPS (ret
) = (lambda_loop
*)
336 obstack_alloc (lambda_obstack
, depth
* sizeof(LN_LOOPS(ret
)));
337 LN_DEPTH (ret
) = depth
;
338 LN_INVARIANTS (ret
) = invariants
;
343 /* Print a lambda loopnest structure, NEST, to OUTFILE. The starting
344 character to use for loop names is given by START. */
347 print_lambda_loopnest (FILE * outfile
, lambda_loopnest nest
, char start
)
350 for (i
= 0; i
< LN_DEPTH (nest
); i
++)
352 fprintf (outfile
, "Loop %c\n", start
+ i
);
353 print_lambda_loop (outfile
, LN_LOOPS (nest
)[i
], LN_DEPTH (nest
),
354 LN_INVARIANTS (nest
), 'i');
355 fprintf (outfile
, "\n");
359 /* Allocate a new lattice structure of DEPTH x DEPTH, with INVARIANTS number
362 static lambda_lattice
363 lambda_lattice_new (int depth
, int invariants
, struct obstack
* lambda_obstack
)
366 = (lambda_lattice
)obstack_alloc (lambda_obstack
, sizeof (*ret
));
367 LATTICE_BASE (ret
) = lambda_matrix_new (depth
, depth
, lambda_obstack
);
368 LATTICE_ORIGIN (ret
) = lambda_vector_new (depth
);
369 LATTICE_ORIGIN_INVARIANTS (ret
) = lambda_matrix_new (depth
, invariants
,
371 LATTICE_DIMENSION (ret
) = depth
;
372 LATTICE_INVARIANTS (ret
) = invariants
;
376 /* Compute the lattice base for NEST. The lattice base is essentially a
377 non-singular transform from a dense base space to a sparse iteration space.
378 We use it so that we don't have to specially handle the case of a sparse
379 iteration space in other parts of the algorithm. As a result, this routine
380 only does something interesting (IE produce a matrix that isn't the
381 identity matrix) if NEST is a sparse space. */
383 static lambda_lattice
384 lambda_lattice_compute_base (lambda_loopnest nest
,
385 struct obstack
* lambda_obstack
)
388 int depth
, invariants
;
393 lambda_linear_expression expression
;
395 depth
= LN_DEPTH (nest
);
396 invariants
= LN_INVARIANTS (nest
);
398 ret
= lambda_lattice_new (depth
, invariants
, lambda_obstack
);
399 base
= LATTICE_BASE (ret
);
400 for (i
= 0; i
< depth
; i
++)
402 loop
= LN_LOOPS (nest
)[i
];
404 step
= LL_STEP (loop
);
405 /* If we have a step of 1, then the base is one, and the
406 origin and invariant coefficients are 0. */
409 for (j
= 0; j
< depth
; j
++)
412 LATTICE_ORIGIN (ret
)[i
] = 0;
413 for (j
= 0; j
< invariants
; j
++)
414 LATTICE_ORIGIN_INVARIANTS (ret
)[i
][j
] = 0;
418 /* Otherwise, we need the lower bound expression (which must
419 be an affine function) to determine the base. */
420 expression
= LL_LOWER_BOUND (loop
);
421 gcc_assert (expression
&& !LLE_NEXT (expression
)
422 && LLE_DENOMINATOR (expression
) == 1);
424 /* The lower triangular portion of the base is going to be the
425 coefficient times the step */
426 for (j
= 0; j
< i
; j
++)
427 base
[i
][j
] = LLE_COEFFICIENTS (expression
)[j
]
428 * LL_STEP (LN_LOOPS (nest
)[j
]);
430 for (j
= i
+ 1; j
< depth
; j
++)
433 /* Origin for this loop is the constant of the lower bound
435 LATTICE_ORIGIN (ret
)[i
] = LLE_CONSTANT (expression
);
437 /* Coefficient for the invariants are equal to the invariant
438 coefficients in the expression. */
439 for (j
= 0; j
< invariants
; j
++)
440 LATTICE_ORIGIN_INVARIANTS (ret
)[i
][j
] =
441 LLE_INVARIANT_COEFFICIENTS (expression
)[j
];
447 /* Compute the least common multiple of two numbers A and B . */
450 least_common_multiple (int a
, int b
)
452 return (abs (a
) * abs (b
) / gcd (a
, b
));
455 /* Perform Fourier-Motzkin elimination to calculate the bounds of the
457 Fourier-Motzkin is a way of reducing systems of linear inequalities so that
458 it is easy to calculate the answer and bounds.
459 A sketch of how it works:
460 Given a system of linear inequalities, ai * xj >= bk, you can always
461 rewrite the constraints so they are all of the form
462 a <= x, or x <= b, or x >= constant for some x in x1 ... xj (and some b
463 in b1 ... bk, and some a in a1...ai)
464 You can then eliminate this x from the non-constant inequalities by
465 rewriting these as a <= b, x >= constant, and delete the x variable.
466 You can then repeat this for any remaining x variables, and then we have
467 an easy to use variable <= constant (or no variables at all) form that we
468 can construct our bounds from.
470 In our case, each time we eliminate, we construct part of the bound from
471 the ith variable, then delete the ith variable.
473 Remember the constant are in our vector a, our coefficient matrix is A,
474 and our invariant coefficient matrix is B.
476 SIZE is the size of the matrices being passed.
477 DEPTH is the loop nest depth.
478 INVARIANTS is the number of loop invariants.
479 A, B, and a are the coefficient matrix, invariant coefficient, and a
480 vector of constants, respectively. */
482 static lambda_loopnest
483 compute_nest_using_fourier_motzkin (int size
,
489 struct obstack
* lambda_obstack
)
492 int multiple
, f1
, f2
;
494 lambda_linear_expression expression
;
496 lambda_loopnest auxillary_nest
;
497 lambda_matrix swapmatrix
, A1
, B1
;
498 lambda_vector swapvector
, a1
;
501 A1
= lambda_matrix_new (128, depth
, lambda_obstack
);
502 B1
= lambda_matrix_new (128, invariants
, lambda_obstack
);
503 a1
= lambda_vector_new (128);
505 auxillary_nest
= lambda_loopnest_new (depth
, invariants
, lambda_obstack
);
507 for (i
= depth
- 1; i
>= 0; i
--)
509 loop
= lambda_loop_new (lambda_obstack
);
510 LN_LOOPS (auxillary_nest
)[i
] = loop
;
513 for (j
= 0; j
< size
; j
++)
517 /* Any linear expression in the matrix with a coefficient less
518 than 0 becomes part of the new lower bound. */
519 expression
= lambda_linear_expression_new (depth
, invariants
,
522 for (k
= 0; k
< i
; k
++)
523 LLE_COEFFICIENTS (expression
)[k
] = A
[j
][k
];
525 for (k
= 0; k
< invariants
; k
++)
526 LLE_INVARIANT_COEFFICIENTS (expression
)[k
] = -1 * B
[j
][k
];
528 LLE_DENOMINATOR (expression
) = -1 * A
[j
][i
];
529 LLE_CONSTANT (expression
) = -1 * a
[j
];
531 /* Ignore if identical to the existing lower bound. */
532 if (!lle_equal (LL_LOWER_BOUND (loop
),
533 expression
, depth
, invariants
))
535 LLE_NEXT (expression
) = LL_LOWER_BOUND (loop
);
536 LL_LOWER_BOUND (loop
) = expression
;
540 else if (A
[j
][i
] > 0)
542 /* Any linear expression with a coefficient greater than 0
543 becomes part of the new upper bound. */
544 expression
= lambda_linear_expression_new (depth
, invariants
,
546 for (k
= 0; k
< i
; k
++)
547 LLE_COEFFICIENTS (expression
)[k
] = -1 * A
[j
][k
];
549 for (k
= 0; k
< invariants
; k
++)
550 LLE_INVARIANT_COEFFICIENTS (expression
)[k
] = B
[j
][k
];
552 LLE_DENOMINATOR (expression
) = A
[j
][i
];
553 LLE_CONSTANT (expression
) = a
[j
];
555 /* Ignore if identical to the existing upper bound. */
556 if (!lle_equal (LL_UPPER_BOUND (loop
),
557 expression
, depth
, invariants
))
559 LLE_NEXT (expression
) = LL_UPPER_BOUND (loop
);
560 LL_UPPER_BOUND (loop
) = expression
;
566 /* This portion creates a new system of linear inequalities by deleting
567 the i'th variable, reducing the system by one variable. */
569 for (j
= 0; j
< size
; j
++)
571 /* If the coefficient for the i'th variable is 0, then we can just
572 eliminate the variable straightaway. Otherwise, we have to
573 multiply through by the coefficients we are eliminating. */
576 lambda_vector_copy (A
[j
], A1
[newsize
], depth
);
577 lambda_vector_copy (B
[j
], B1
[newsize
], invariants
);
581 else if (A
[j
][i
] > 0)
583 for (k
= 0; k
< size
; k
++)
587 multiple
= least_common_multiple (A
[j
][i
], A
[k
][i
]);
588 f1
= multiple
/ A
[j
][i
];
589 f2
= -1 * multiple
/ A
[k
][i
];
591 lambda_vector_add_mc (A
[j
], f1
, A
[k
], f2
,
593 lambda_vector_add_mc (B
[j
], f1
, B
[k
], f2
,
594 B1
[newsize
], invariants
);
595 a1
[newsize
] = f1
* a
[j
] + f2
* a
[k
];
617 return auxillary_nest
;
620 /* Compute the loop bounds for the auxiliary space NEST.
621 Input system used is Ax <= b. TRANS is the unimodular transformation.
622 Given the original nest, this function will
623 1. Convert the nest into matrix form, which consists of a matrix for the
624 coefficients, a matrix for the
625 invariant coefficients, and a vector for the constants.
626 2. Use the matrix form to calculate the lattice base for the nest (which is
628 3. Compose the dense space transform with the user specified transform, to
629 get a transform we can easily calculate transformed bounds for.
630 4. Multiply the composed transformation matrix times the matrix form of the
632 5. Transform the newly created matrix (from step 4) back into a loop nest
633 using Fourier-Motzkin elimination to figure out the bounds. */
635 static lambda_loopnest
636 lambda_compute_auxillary_space (lambda_loopnest nest
,
637 lambda_trans_matrix trans
,
638 struct obstack
* lambda_obstack
)
640 lambda_matrix A
, B
, A1
, B1
;
642 lambda_matrix invertedtrans
;
643 int depth
, invariants
, size
;
646 lambda_linear_expression expression
;
647 lambda_lattice lattice
;
649 depth
= LN_DEPTH (nest
);
650 invariants
= LN_INVARIANTS (nest
);
652 /* Unfortunately, we can't know the number of constraints we'll have
653 ahead of time, but this should be enough even in ridiculous loop nest
654 cases. We must not go over this limit. */
655 A
= lambda_matrix_new (128, depth
, lambda_obstack
);
656 B
= lambda_matrix_new (128, invariants
, lambda_obstack
);
657 a
= lambda_vector_new (128);
659 A1
= lambda_matrix_new (128, depth
, lambda_obstack
);
660 B1
= lambda_matrix_new (128, invariants
, lambda_obstack
);
661 a1
= lambda_vector_new (128);
663 /* Store the bounds in the equation matrix A, constant vector a, and
664 invariant matrix B, so that we have Ax <= a + B.
665 This requires a little equation rearranging so that everything is on the
666 correct side of the inequality. */
668 for (i
= 0; i
< depth
; i
++)
670 loop
= LN_LOOPS (nest
)[i
];
672 /* First we do the lower bound. */
673 if (LL_STEP (loop
) > 0)
674 expression
= LL_LOWER_BOUND (loop
);
676 expression
= LL_UPPER_BOUND (loop
);
678 for (; expression
!= NULL
; expression
= LLE_NEXT (expression
))
680 /* Fill in the coefficient. */
681 for (j
= 0; j
< i
; j
++)
682 A
[size
][j
] = LLE_COEFFICIENTS (expression
)[j
];
684 /* And the invariant coefficient. */
685 for (j
= 0; j
< invariants
; j
++)
686 B
[size
][j
] = LLE_INVARIANT_COEFFICIENTS (expression
)[j
];
688 /* And the constant. */
689 a
[size
] = LLE_CONSTANT (expression
);
691 /* Convert (2x+3y+2+b)/4 <= z to 2x+3y-4z <= -2-b. IE put all
692 constants and single variables on */
693 A
[size
][i
] = -1 * LLE_DENOMINATOR (expression
);
695 for (j
= 0; j
< invariants
; j
++)
699 /* Need to increase matrix sizes above. */
700 gcc_assert (size
<= 127);
704 /* Then do the exact same thing for the upper bounds. */
705 if (LL_STEP (loop
) > 0)
706 expression
= LL_UPPER_BOUND (loop
);
708 expression
= LL_LOWER_BOUND (loop
);
710 for (; expression
!= NULL
; expression
= LLE_NEXT (expression
))
712 /* Fill in the coefficient. */
713 for (j
= 0; j
< i
; j
++)
714 A
[size
][j
] = LLE_COEFFICIENTS (expression
)[j
];
716 /* And the invariant coefficient. */
717 for (j
= 0; j
< invariants
; j
++)
718 B
[size
][j
] = LLE_INVARIANT_COEFFICIENTS (expression
)[j
];
720 /* And the constant. */
721 a
[size
] = LLE_CONSTANT (expression
);
723 /* Convert z <= (2x+3y+2+b)/4 to -2x-3y+4z <= 2+b. */
724 for (j
= 0; j
< i
; j
++)
726 A
[size
][i
] = LLE_DENOMINATOR (expression
);
728 /* Need to increase matrix sizes above. */
729 gcc_assert (size
<= 127);
734 /* Compute the lattice base x = base * y + origin, where y is the
736 lattice
= lambda_lattice_compute_base (nest
, lambda_obstack
);
738 /* Ax <= a + B then becomes ALy <= a+B - A*origin. L is the lattice base */
741 lambda_matrix_mult (A
, LATTICE_BASE (lattice
), A1
, size
, depth
, depth
);
743 /* a1 = a - A * origin constant. */
744 lambda_matrix_vector_mult (A
, size
, depth
, LATTICE_ORIGIN (lattice
), a1
);
745 lambda_vector_add_mc (a
, 1, a1
, -1, a1
, size
);
747 /* B1 = B - A * origin invariant. */
748 lambda_matrix_mult (A
, LATTICE_ORIGIN_INVARIANTS (lattice
), B1
, size
, depth
,
750 lambda_matrix_add_mc (B
, 1, B1
, -1, B1
, size
, invariants
);
752 /* Now compute the auxiliary space bounds by first inverting U, multiplying
753 it by A1, then performing Fourier-Motzkin. */
755 invertedtrans
= lambda_matrix_new (depth
, depth
, lambda_obstack
);
757 /* Compute the inverse of U. */
758 lambda_matrix_inverse (LTM_MATRIX (trans
),
759 invertedtrans
, depth
, lambda_obstack
);
762 lambda_matrix_mult (A1
, invertedtrans
, A
, size
, depth
, depth
);
764 return compute_nest_using_fourier_motzkin (size
, depth
, invariants
,
765 A
, B1
, a1
, lambda_obstack
);
768 /* Compute the loop bounds for the target space, using the bounds of
769 the auxiliary nest AUXILLARY_NEST, and the triangular matrix H.
770 The target space loop bounds are computed by multiplying the triangular
771 matrix H by the auxiliary nest, to get the new loop bounds. The sign of
772 the loop steps (positive or negative) is then used to swap the bounds if
773 the loop counts downwards.
774 Return the target loopnest. */
776 static lambda_loopnest
777 lambda_compute_target_space (lambda_loopnest auxillary_nest
,
778 lambda_trans_matrix H
, lambda_vector stepsigns
,
779 struct obstack
* lambda_obstack
)
781 lambda_matrix inverse
, H1
;
782 int determinant
, i
, j
;
786 lambda_loopnest target_nest
;
787 int depth
, invariants
;
788 lambda_matrix target
;
790 lambda_loop auxillary_loop
, target_loop
;
791 lambda_linear_expression expression
, auxillary_expr
, target_expr
, tmp_expr
;
793 depth
= LN_DEPTH (auxillary_nest
);
794 invariants
= LN_INVARIANTS (auxillary_nest
);
796 inverse
= lambda_matrix_new (depth
, depth
, lambda_obstack
);
797 determinant
= lambda_matrix_inverse (LTM_MATRIX (H
), inverse
, depth
,
800 /* H1 is H excluding its diagonal. */
801 H1
= lambda_matrix_new (depth
, depth
, lambda_obstack
);
802 lambda_matrix_copy (LTM_MATRIX (H
), H1
, depth
, depth
);
804 for (i
= 0; i
< depth
; i
++)
807 /* Computes the linear offsets of the loop bounds. */
808 target
= lambda_matrix_new (depth
, depth
, lambda_obstack
);
809 lambda_matrix_mult (H1
, inverse
, target
, depth
, depth
, depth
);
811 target_nest
= lambda_loopnest_new (depth
, invariants
, lambda_obstack
);
813 for (i
= 0; i
< depth
; i
++)
816 /* Get a new loop structure. */
817 target_loop
= lambda_loop_new (lambda_obstack
);
818 LN_LOOPS (target_nest
)[i
] = target_loop
;
820 /* Computes the gcd of the coefficients of the linear part. */
821 gcd1
= lambda_vector_gcd (target
[i
], i
);
823 /* Include the denominator in the GCD. */
824 gcd1
= gcd (gcd1
, determinant
);
826 /* Now divide through by the gcd. */
827 for (j
= 0; j
< i
; j
++)
828 target
[i
][j
] = target
[i
][j
] / gcd1
;
830 expression
= lambda_linear_expression_new (depth
, invariants
,
832 lambda_vector_copy (target
[i
], LLE_COEFFICIENTS (expression
), depth
);
833 LLE_DENOMINATOR (expression
) = determinant
/ gcd1
;
834 LLE_CONSTANT (expression
) = 0;
835 lambda_vector_clear (LLE_INVARIANT_COEFFICIENTS (expression
),
837 LL_LINEAR_OFFSET (target_loop
) = expression
;
840 /* For each loop, compute the new bounds from H. */
841 for (i
= 0; i
< depth
; i
++)
843 auxillary_loop
= LN_LOOPS (auxillary_nest
)[i
];
844 target_loop
= LN_LOOPS (target_nest
)[i
];
845 LL_STEP (target_loop
) = LTM_MATRIX (H
)[i
][i
];
846 factor
= LTM_MATRIX (H
)[i
][i
];
848 /* First we do the lower bound. */
849 auxillary_expr
= LL_LOWER_BOUND (auxillary_loop
);
851 for (; auxillary_expr
!= NULL
;
852 auxillary_expr
= LLE_NEXT (auxillary_expr
))
854 target_expr
= lambda_linear_expression_new (depth
, invariants
,
856 lambda_vector_matrix_mult (LLE_COEFFICIENTS (auxillary_expr
),
857 depth
, inverse
, depth
,
858 LLE_COEFFICIENTS (target_expr
));
859 lambda_vector_mult_const (LLE_COEFFICIENTS (target_expr
),
860 LLE_COEFFICIENTS (target_expr
), depth
,
863 LLE_CONSTANT (target_expr
) = LLE_CONSTANT (auxillary_expr
) * factor
;
864 lambda_vector_copy (LLE_INVARIANT_COEFFICIENTS (auxillary_expr
),
865 LLE_INVARIANT_COEFFICIENTS (target_expr
),
867 lambda_vector_mult_const (LLE_INVARIANT_COEFFICIENTS (target_expr
),
868 LLE_INVARIANT_COEFFICIENTS (target_expr
),
870 LLE_DENOMINATOR (target_expr
) = LLE_DENOMINATOR (auxillary_expr
);
872 if (!lambda_vector_zerop (LLE_COEFFICIENTS (target_expr
), depth
))
874 LLE_CONSTANT (target_expr
) = LLE_CONSTANT (target_expr
)
876 lambda_vector_mult_const (LLE_INVARIANT_COEFFICIENTS
878 LLE_INVARIANT_COEFFICIENTS
879 (target_expr
), invariants
,
881 LLE_DENOMINATOR (target_expr
) =
882 LLE_DENOMINATOR (target_expr
) * determinant
;
884 /* Find the gcd and divide by it here, rather than doing it
885 at the tree level. */
886 gcd1
= lambda_vector_gcd (LLE_COEFFICIENTS (target_expr
), depth
);
887 gcd2
= lambda_vector_gcd (LLE_INVARIANT_COEFFICIENTS (target_expr
),
889 gcd1
= gcd (gcd1
, gcd2
);
890 gcd1
= gcd (gcd1
, LLE_CONSTANT (target_expr
));
891 gcd1
= gcd (gcd1
, LLE_DENOMINATOR (target_expr
));
892 for (j
= 0; j
< depth
; j
++)
893 LLE_COEFFICIENTS (target_expr
)[j
] /= gcd1
;
894 for (j
= 0; j
< invariants
; j
++)
895 LLE_INVARIANT_COEFFICIENTS (target_expr
)[j
] /= gcd1
;
896 LLE_CONSTANT (target_expr
) /= gcd1
;
897 LLE_DENOMINATOR (target_expr
) /= gcd1
;
898 /* Ignore if identical to existing bound. */
899 if (!lle_equal (LL_LOWER_BOUND (target_loop
), target_expr
, depth
,
902 LLE_NEXT (target_expr
) = LL_LOWER_BOUND (target_loop
);
903 LL_LOWER_BOUND (target_loop
) = target_expr
;
906 /* Now do the upper bound. */
907 auxillary_expr
= LL_UPPER_BOUND (auxillary_loop
);
909 for (; auxillary_expr
!= NULL
;
910 auxillary_expr
= LLE_NEXT (auxillary_expr
))
912 target_expr
= lambda_linear_expression_new (depth
, invariants
,
914 lambda_vector_matrix_mult (LLE_COEFFICIENTS (auxillary_expr
),
915 depth
, inverse
, depth
,
916 LLE_COEFFICIENTS (target_expr
));
917 lambda_vector_mult_const (LLE_COEFFICIENTS (target_expr
),
918 LLE_COEFFICIENTS (target_expr
), depth
,
920 LLE_CONSTANT (target_expr
) = LLE_CONSTANT (auxillary_expr
) * factor
;
921 lambda_vector_copy (LLE_INVARIANT_COEFFICIENTS (auxillary_expr
),
922 LLE_INVARIANT_COEFFICIENTS (target_expr
),
924 lambda_vector_mult_const (LLE_INVARIANT_COEFFICIENTS (target_expr
),
925 LLE_INVARIANT_COEFFICIENTS (target_expr
),
927 LLE_DENOMINATOR (target_expr
) = LLE_DENOMINATOR (auxillary_expr
);
929 if (!lambda_vector_zerop (LLE_COEFFICIENTS (target_expr
), depth
))
931 LLE_CONSTANT (target_expr
) = LLE_CONSTANT (target_expr
)
933 lambda_vector_mult_const (LLE_INVARIANT_COEFFICIENTS
935 LLE_INVARIANT_COEFFICIENTS
936 (target_expr
), invariants
,
938 LLE_DENOMINATOR (target_expr
) =
939 LLE_DENOMINATOR (target_expr
) * determinant
;
941 /* Find the gcd and divide by it here, instead of at the
943 gcd1
= lambda_vector_gcd (LLE_COEFFICIENTS (target_expr
), depth
);
944 gcd2
= lambda_vector_gcd (LLE_INVARIANT_COEFFICIENTS (target_expr
),
946 gcd1
= gcd (gcd1
, gcd2
);
947 gcd1
= gcd (gcd1
, LLE_CONSTANT (target_expr
));
948 gcd1
= gcd (gcd1
, LLE_DENOMINATOR (target_expr
));
949 for (j
= 0; j
< depth
; j
++)
950 LLE_COEFFICIENTS (target_expr
)[j
] /= gcd1
;
951 for (j
= 0; j
< invariants
; j
++)
952 LLE_INVARIANT_COEFFICIENTS (target_expr
)[j
] /= gcd1
;
953 LLE_CONSTANT (target_expr
) /= gcd1
;
954 LLE_DENOMINATOR (target_expr
) /= gcd1
;
955 /* Ignore if equal to existing bound. */
956 if (!lle_equal (LL_UPPER_BOUND (target_loop
), target_expr
, depth
,
959 LLE_NEXT (target_expr
) = LL_UPPER_BOUND (target_loop
);
960 LL_UPPER_BOUND (target_loop
) = target_expr
;
964 for (i
= 0; i
< depth
; i
++)
966 target_loop
= LN_LOOPS (target_nest
)[i
];
967 /* If necessary, exchange the upper and lower bounds and negate
969 if (stepsigns
[i
] < 0)
971 LL_STEP (target_loop
) *= -1;
972 tmp_expr
= LL_LOWER_BOUND (target_loop
);
973 LL_LOWER_BOUND (target_loop
) = LL_UPPER_BOUND (target_loop
);
974 LL_UPPER_BOUND (target_loop
) = tmp_expr
;
980 /* Compute the step signs of TRANS, using TRANS and stepsigns. Return the new
984 lambda_compute_step_signs (lambda_trans_matrix trans
,
985 lambda_vector stepsigns
,
986 struct obstack
* lambda_obstack
)
988 lambda_matrix matrix
, H
;
990 lambda_vector newsteps
;
991 int i
, j
, factor
, minimum_column
;
994 matrix
= LTM_MATRIX (trans
);
995 size
= LTM_ROWSIZE (trans
);
996 H
= lambda_matrix_new (size
, size
, lambda_obstack
);
998 newsteps
= lambda_vector_new (size
);
999 lambda_vector_copy (stepsigns
, newsteps
, size
);
1001 lambda_matrix_copy (matrix
, H
, size
, size
);
1003 for (j
= 0; j
< size
; j
++)
1007 for (i
= j
; i
< size
; i
++)
1009 lambda_matrix_col_negate (H
, size
, i
);
1010 while (lambda_vector_first_nz (row
, size
, j
+ 1) < size
)
1012 minimum_column
= lambda_vector_min_nz (row
, size
, j
);
1013 lambda_matrix_col_exchange (H
, size
, j
, minimum_column
);
1016 newsteps
[j
] = newsteps
[minimum_column
];
1017 newsteps
[minimum_column
] = temp
;
1019 for (i
= j
+ 1; i
< size
; i
++)
1021 factor
= row
[i
] / row
[j
];
1022 lambda_matrix_col_add (H
, size
, j
, i
, -1 * factor
);
1029 /* Transform NEST according to TRANS, and return the new loopnest.
1031 1. Computing a lattice base for the transformation
1032 2. Composing the dense base with the specified transformation (TRANS)
1033 3. Decomposing the combined transformation into a lower triangular portion,
1034 and a unimodular portion.
1035 4. Computing the auxiliary nest using the unimodular portion.
1036 5. Computing the target nest using the auxiliary nest and the lower
1037 triangular portion. */
1040 lambda_loopnest_transform (lambda_loopnest nest
, lambda_trans_matrix trans
,
1041 struct obstack
* lambda_obstack
)
1043 lambda_loopnest auxillary_nest
, target_nest
;
1045 int depth
, invariants
;
1047 lambda_lattice lattice
;
1048 lambda_trans_matrix trans1
, H
, U
;
1050 lambda_linear_expression expression
;
1051 lambda_vector origin
;
1052 lambda_matrix origin_invariants
;
1053 lambda_vector stepsigns
;
1056 depth
= LN_DEPTH (nest
);
1057 invariants
= LN_INVARIANTS (nest
);
1059 /* Keep track of the signs of the loop steps. */
1060 stepsigns
= lambda_vector_new (depth
);
1061 for (i
= 0; i
< depth
; i
++)
1063 if (LL_STEP (LN_LOOPS (nest
)[i
]) > 0)
1069 /* Compute the lattice base. */
1070 lattice
= lambda_lattice_compute_base (nest
, lambda_obstack
);
1071 trans1
= lambda_trans_matrix_new (depth
, depth
, lambda_obstack
);
1073 /* Multiply the transformation matrix by the lattice base. */
1075 lambda_matrix_mult (LTM_MATRIX (trans
), LATTICE_BASE (lattice
),
1076 LTM_MATRIX (trans1
), depth
, depth
, depth
);
1078 /* Compute the Hermite normal form for the new transformation matrix. */
1079 H
= lambda_trans_matrix_new (depth
, depth
, lambda_obstack
);
1080 U
= lambda_trans_matrix_new (depth
, depth
, lambda_obstack
);
1081 lambda_matrix_hermite (LTM_MATRIX (trans1
), depth
, LTM_MATRIX (H
),
1084 /* Compute the auxiliary loop nest's space from the unimodular
1086 auxillary_nest
= lambda_compute_auxillary_space (nest
, U
,
1089 /* Compute the loop step signs from the old step signs and the
1090 transformation matrix. */
1091 stepsigns
= lambda_compute_step_signs (trans1
, stepsigns
,
1094 /* Compute the target loop nest space from the auxiliary nest and
1095 the lower triangular matrix H. */
1096 target_nest
= lambda_compute_target_space (auxillary_nest
, H
, stepsigns
,
1098 origin
= lambda_vector_new (depth
);
1099 origin_invariants
= lambda_matrix_new (depth
, invariants
, lambda_obstack
);
1100 lambda_matrix_vector_mult (LTM_MATRIX (trans
), depth
, depth
,
1101 LATTICE_ORIGIN (lattice
), origin
);
1102 lambda_matrix_mult (LTM_MATRIX (trans
), LATTICE_ORIGIN_INVARIANTS (lattice
),
1103 origin_invariants
, depth
, depth
, invariants
);
1105 for (i
= 0; i
< depth
; i
++)
1107 loop
= LN_LOOPS (target_nest
)[i
];
1108 expression
= LL_LINEAR_OFFSET (loop
);
1109 if (lambda_vector_zerop (LLE_COEFFICIENTS (expression
), depth
))
1112 f
= LLE_DENOMINATOR (expression
);
1114 LLE_CONSTANT (expression
) += f
* origin
[i
];
1116 for (j
= 0; j
< invariants
; j
++)
1117 LLE_INVARIANT_COEFFICIENTS (expression
)[j
] +=
1118 f
* origin_invariants
[i
][j
];
1125 /* Convert a gcc tree expression EXPR to a lambda linear expression, and
1126 return the new expression. DEPTH is the depth of the loopnest.
1127 OUTERINDUCTIONVARS is an array of the induction variables for outer loops
1128 in this nest. INVARIANTS is the array of invariants for the loop. EXTRA
1129 is the amount we have to add/subtract from the expression because of the
1130 type of comparison it is used in. */
1132 static lambda_linear_expression
1133 gcc_tree_to_linear_expression (int depth
, tree expr
,
1134 VEC(tree
,heap
) *outerinductionvars
,
1135 VEC(tree
,heap
) *invariants
, int extra
,
1136 struct obstack
* lambda_obstack
)
1138 lambda_linear_expression lle
= NULL
;
1139 switch (TREE_CODE (expr
))
1143 lle
= lambda_linear_expression_new (depth
, 2 * depth
, lambda_obstack
);
1144 LLE_CONSTANT (lle
) = TREE_INT_CST_LOW (expr
);
1146 LLE_CONSTANT (lle
) += extra
;
1148 LLE_DENOMINATOR (lle
) = 1;
1155 FOR_EACH_VEC_ELT (tree
, outerinductionvars
, i
, iv
)
1158 if (SSA_NAME_VAR (iv
) == SSA_NAME_VAR (expr
))
1160 lle
= lambda_linear_expression_new (depth
, 2 * depth
,
1162 LLE_COEFFICIENTS (lle
)[i
] = 1;
1164 LLE_CONSTANT (lle
) = extra
;
1166 LLE_DENOMINATOR (lle
) = 1;
1169 FOR_EACH_VEC_ELT (tree
, invariants
, i
, invar
)
1172 if (SSA_NAME_VAR (invar
) == SSA_NAME_VAR (expr
))
1174 lle
= lambda_linear_expression_new (depth
, 2 * depth
,
1176 LLE_INVARIANT_COEFFICIENTS (lle
)[i
] = 1;
1178 LLE_CONSTANT (lle
) = extra
;
1179 LLE_DENOMINATOR (lle
) = 1;
1191 /* Return the depth of the loopnest NEST */
1194 depth_of_nest (struct loop
*nest
)
1206 /* Return true if OP is invariant in LOOP and all outer loops. */
1209 invariant_in_loop_and_outer_loops (struct loop
*loop
, tree op
)
1211 if (is_gimple_min_invariant (op
))
1213 if (loop_depth (loop
) == 0)
1215 if (!expr_invariant_in_loop_p (loop
, op
))
1217 if (!invariant_in_loop_and_outer_loops (loop_outer (loop
), op
))
1222 /* Generate a lambda loop from a gcc loop LOOP. Return the new lambda loop,
1223 or NULL if it could not be converted.
1224 DEPTH is the depth of the loop.
1225 INVARIANTS is a pointer to the array of loop invariants.
1226 The induction variable for this loop should be stored in the parameter
1228 OUTERINDUCTIONVARS is an array of induction variables for outer loops. */
1231 gcc_loop_to_lambda_loop (struct loop
*loop
, int depth
,
1232 VEC(tree
,heap
) ** invariants
,
1233 tree
* ourinductionvar
,
1234 VEC(tree
,heap
) * outerinductionvars
,
1235 VEC(tree
,heap
) ** lboundvars
,
1236 VEC(tree
,heap
) ** uboundvars
,
1237 VEC(int,heap
) ** steps
,
1238 struct obstack
* lambda_obstack
)
1242 tree access_fn
, inductionvar
;
1244 lambda_loop lloop
= NULL
;
1245 lambda_linear_expression lbound
, ubound
;
1246 tree test_lhs
, test_rhs
;
1249 tree lboundvar
, uboundvar
, uboundresult
;
1251 /* Find out induction var and exit condition. */
1252 inductionvar
= find_induction_var_from_exit_cond (loop
);
1253 exit_cond
= get_loop_exit_condition (loop
);
1255 if (inductionvar
== NULL
|| exit_cond
== NULL
)
1257 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1259 "Unable to convert loop: Cannot determine exit condition or induction variable for loop.\n");
1263 if (SSA_NAME_DEF_STMT (inductionvar
) == NULL
)
1266 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1268 "Unable to convert loop: Cannot find PHI node for induction variable\n");
1273 phi
= SSA_NAME_DEF_STMT (inductionvar
);
1274 if (gimple_code (phi
) != GIMPLE_PHI
)
1276 tree op
= SINGLE_SSA_TREE_OPERAND (phi
, SSA_OP_USE
);
1280 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1282 "Unable to convert loop: Cannot find PHI node for induction variable\n");
1287 phi
= SSA_NAME_DEF_STMT (op
);
1288 if (gimple_code (phi
) != GIMPLE_PHI
)
1290 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1292 "Unable to convert loop: Cannot find PHI node for induction variable\n");
1297 /* The induction variable name/version we want to put in the array is the
1298 result of the induction variable phi node. */
1299 *ourinductionvar
= PHI_RESULT (phi
);
1300 access_fn
= instantiate_parameters
1301 (loop
, analyze_scalar_evolution (loop
, PHI_RESULT (phi
)));
1302 if (access_fn
== chrec_dont_know
)
1304 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1306 "Unable to convert loop: Access function for induction variable phi is unknown\n");
1311 step
= evolution_part_in_loop_num (access_fn
, loop
->num
);
1312 if (!step
|| step
== chrec_dont_know
)
1314 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1316 "Unable to convert loop: Cannot determine step of loop.\n");
1320 if (TREE_CODE (step
) != INTEGER_CST
)
1323 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1325 "Unable to convert loop: Step of loop is not integer.\n");
1329 stepint
= TREE_INT_CST_LOW (step
);
1331 /* Only want phis for induction vars, which will have two
1333 if (gimple_phi_num_args (phi
) != 2)
1335 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1337 "Unable to convert loop: PHI node for induction variable has >2 arguments\n");
1341 /* Another induction variable check. One argument's source should be
1342 in the loop, one outside the loop. */
1343 if (flow_bb_inside_loop_p (loop
, gimple_phi_arg_edge (phi
, 0)->src
)
1344 && flow_bb_inside_loop_p (loop
, gimple_phi_arg_edge (phi
, 1)->src
))
1347 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1349 "Unable to convert loop: PHI edges both inside loop, or both outside loop.\n");
1354 if (flow_bb_inside_loop_p (loop
, gimple_phi_arg_edge (phi
, 0)->src
))
1356 lboundvar
= PHI_ARG_DEF (phi
, 1);
1357 lbound
= gcc_tree_to_linear_expression (depth
, lboundvar
,
1358 outerinductionvars
, *invariants
,
1363 lboundvar
= PHI_ARG_DEF (phi
, 0);
1364 lbound
= gcc_tree_to_linear_expression (depth
, lboundvar
,
1365 outerinductionvars
, *invariants
,
1372 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1374 "Unable to convert loop: Cannot convert lower bound to linear expression\n");
1378 /* One part of the test may be a loop invariant tree. */
1379 VEC_reserve (tree
, heap
, *invariants
, 1);
1380 test_lhs
= gimple_cond_lhs (exit_cond
);
1381 test_rhs
= gimple_cond_rhs (exit_cond
);
1383 if (TREE_CODE (test_rhs
) == SSA_NAME
1384 && invariant_in_loop_and_outer_loops (loop
, test_rhs
))
1385 VEC_quick_push (tree
, *invariants
, test_rhs
);
1386 else if (TREE_CODE (test_lhs
) == SSA_NAME
1387 && invariant_in_loop_and_outer_loops (loop
, test_lhs
))
1388 VEC_quick_push (tree
, *invariants
, test_lhs
);
1390 /* The non-induction variable part of the test is the upper bound variable.
1392 if (test_lhs
== inductionvar
)
1393 uboundvar
= test_rhs
;
1395 uboundvar
= test_lhs
;
1397 /* We only size the vectors assuming we have, at max, 2 times as many
1398 invariants as we do loops (one for each bound).
1399 This is just an arbitrary number, but it has to be matched against the
1401 gcc_assert (VEC_length (tree
, *invariants
) <= (unsigned int) (2 * depth
));
1404 /* We might have some leftover. */
1405 if (gimple_cond_code (exit_cond
) == LT_EXPR
)
1406 extra
= -1 * stepint
;
1407 else if (gimple_cond_code (exit_cond
) == NE_EXPR
)
1408 extra
= -1 * stepint
;
1409 else if (gimple_cond_code (exit_cond
) == GT_EXPR
)
1410 extra
= -1 * stepint
;
1411 else if (gimple_cond_code (exit_cond
) == EQ_EXPR
)
1412 extra
= 1 * stepint
;
1414 ubound
= gcc_tree_to_linear_expression (depth
, uboundvar
,
1416 *invariants
, extra
, lambda_obstack
);
1417 uboundresult
= build2 (PLUS_EXPR
, TREE_TYPE (uboundvar
), uboundvar
,
1418 build_int_cst (TREE_TYPE (uboundvar
), extra
));
1419 VEC_safe_push (tree
, heap
, *uboundvars
, uboundresult
);
1420 VEC_safe_push (tree
, heap
, *lboundvars
, lboundvar
);
1421 VEC_safe_push (int, heap
, *steps
, stepint
);
1424 if (dump_file
&& (dump_flags
& TDF_DETAILS
))
1426 "Unable to convert loop: Cannot convert upper bound to linear expression\n");
1430 lloop
= lambda_loop_new (lambda_obstack
);
1431 LL_STEP (lloop
) = stepint
;
1432 LL_LOWER_BOUND (lloop
) = lbound
;
1433 LL_UPPER_BOUND (lloop
) = ubound
;
1437 /* Given a LOOP, find the induction variable it is testing against in the exit
1438 condition. Return the induction variable if found, NULL otherwise. */
1441 find_induction_var_from_exit_cond (struct loop
*loop
)
1443 gimple expr
= get_loop_exit_condition (loop
);
1445 tree test_lhs
, test_rhs
;
1448 if (gimple_code (expr
) != GIMPLE_COND
)
1450 test_lhs
= gimple_cond_lhs (expr
);
1451 test_rhs
= gimple_cond_rhs (expr
);
1453 /* Find the side that is invariant in this loop. The ivar must be the other
1456 if (expr_invariant_in_loop_p (loop
, test_lhs
))
1458 else if (expr_invariant_in_loop_p (loop
, test_rhs
))
1463 if (TREE_CODE (ivarop
) != SSA_NAME
)
1468 DEF_VEC_P(lambda_loop
);
1469 DEF_VEC_ALLOC_P(lambda_loop
,heap
);
1471 /* Generate a lambda loopnest from a gcc loopnest LOOP_NEST.
1472 Return the new loop nest.
1473 INDUCTIONVARS is a pointer to an array of induction variables for the
1474 loopnest that will be filled in during this process.
1475 INVARIANTS is a pointer to an array of invariants that will be filled in
1476 during this process. */
1479 gcc_loopnest_to_lambda_loopnest (struct loop
*loop_nest
,
1480 VEC(tree
,heap
) **inductionvars
,
1481 VEC(tree
,heap
) **invariants
,
1482 struct obstack
* lambda_obstack
)
1484 lambda_loopnest ret
= NULL
;
1485 struct loop
*temp
= loop_nest
;
1486 int depth
= depth_of_nest (loop_nest
);
1488 VEC(lambda_loop
,heap
) *loops
= NULL
;
1489 VEC(tree
,heap
) *uboundvars
= NULL
;
1490 VEC(tree
,heap
) *lboundvars
= NULL
;
1491 VEC(int,heap
) *steps
= NULL
;
1492 lambda_loop newloop
;
1493 tree inductionvar
= NULL
;
1494 bool perfect_nest
= perfect_nest_p (loop_nest
);
1496 if (!perfect_nest
&& !can_convert_to_perfect_nest (loop_nest
))
1501 newloop
= gcc_loop_to_lambda_loop (temp
, depth
, invariants
,
1502 &inductionvar
, *inductionvars
,
1503 &lboundvars
, &uboundvars
,
1504 &steps
, lambda_obstack
);
1508 VEC_safe_push (tree
, heap
, *inductionvars
, inductionvar
);
1509 VEC_safe_push (lambda_loop
, heap
, loops
, newloop
);
1515 if (!perfect_nestify (loop_nest
, lboundvars
, uboundvars
, steps
,
1520 "Not a perfect loop nest and couldn't convert to one.\n");
1525 "Successfully converted loop nest to perfect loop nest.\n");
1528 ret
= lambda_loopnest_new (depth
, 2 * depth
, lambda_obstack
);
1530 FOR_EACH_VEC_ELT (lambda_loop
, loops
, i
, newloop
)
1531 LN_LOOPS (ret
)[i
] = newloop
;
1534 VEC_free (lambda_loop
, heap
, loops
);
1535 VEC_free (tree
, heap
, uboundvars
);
1536 VEC_free (tree
, heap
, lboundvars
);
1537 VEC_free (int, heap
, steps
);
1542 /* Convert a lambda body vector LBV to a gcc tree, and return the new tree.
1543 STMTS_TO_INSERT is a pointer to a tree where the statements we need to be
1544 inserted for us are stored. INDUCTION_VARS is the array of induction
1545 variables for the loop this LBV is from. TYPE is the tree type to use for
1546 the variables and trees involved. */
1549 lbv_to_gcc_expression (lambda_body_vector lbv
,
1550 tree type
, VEC(tree
,heap
) *induction_vars
,
1551 gimple_seq
*stmts_to_insert
)
1555 tree expr
= build_linear_expr (type
, LBV_COEFFICIENTS (lbv
), induction_vars
);
1557 k
= LBV_DENOMINATOR (lbv
);
1558 gcc_assert (k
!= 0);
1560 expr
= fold_build2 (CEIL_DIV_EXPR
, type
, expr
, build_int_cst (type
, k
));
1562 resvar
= create_tmp_var (type
, "lbvtmp");
1563 add_referenced_var (resvar
);
1564 return force_gimple_operand (fold (expr
), stmts_to_insert
, true, resvar
);
1567 /* Convert a linear expression from coefficient and constant form to a
1569 Return the tree that represents the final value of the expression.
1570 LLE is the linear expression to convert.
1571 OFFSET is the linear offset to apply to the expression.
1572 TYPE is the tree type to use for the variables and math.
1573 INDUCTION_VARS is a vector of induction variables for the loops.
1574 INVARIANTS is a vector of the loop nest invariants.
1575 WRAP specifies what tree code to wrap the results in, if there is more than
1576 one (it is either MAX_EXPR, or MIN_EXPR).
1577 STMTS_TO_INSERT Is a pointer to the statement list we fill in with
1578 statements that need to be inserted for the linear expression. */
1581 lle_to_gcc_expression (lambda_linear_expression lle
,
1582 lambda_linear_expression offset
,
1584 VEC(tree
,heap
) *induction_vars
,
1585 VEC(tree
,heap
) *invariants
,
1586 enum tree_code wrap
, gimple_seq
*stmts_to_insert
)
1590 tree expr
= NULL_TREE
;
1591 VEC(tree
,heap
) *results
= NULL
;
1593 gcc_assert (wrap
== MAX_EXPR
|| wrap
== MIN_EXPR
);
1595 /* Build up the linear expressions. */
1596 for (; lle
!= NULL
; lle
= LLE_NEXT (lle
))
1598 expr
= build_linear_expr (type
, LLE_COEFFICIENTS (lle
), induction_vars
);
1599 expr
= fold_build2 (PLUS_EXPR
, type
, expr
,
1600 build_linear_expr (type
,
1601 LLE_INVARIANT_COEFFICIENTS (lle
),
1604 k
= LLE_CONSTANT (lle
);
1606 expr
= fold_build2 (PLUS_EXPR
, type
, expr
, build_int_cst (type
, k
));
1608 k
= LLE_CONSTANT (offset
);
1610 expr
= fold_build2 (PLUS_EXPR
, type
, expr
, build_int_cst (type
, k
));
1612 k
= LLE_DENOMINATOR (lle
);
1614 expr
= fold_build2 (wrap
== MAX_EXPR
? CEIL_DIV_EXPR
: FLOOR_DIV_EXPR
,
1615 type
, expr
, build_int_cst (type
, k
));
1618 VEC_safe_push (tree
, heap
, results
, expr
);
1623 /* We may need to wrap the results in a MAX_EXPR or MIN_EXPR. */
1624 if (VEC_length (tree
, results
) > 1)
1629 expr
= VEC_index (tree
, results
, 0);
1630 for (i
= 1; VEC_iterate (tree
, results
, i
, op
); i
++)
1631 expr
= fold_build2 (wrap
, type
, expr
, op
);
1634 VEC_free (tree
, heap
, results
);
1636 resvar
= create_tmp_var (type
, "lletmp");
1637 add_referenced_var (resvar
);
1638 return force_gimple_operand (fold (expr
), stmts_to_insert
, true, resvar
);
1641 /* Remove the induction variable defined at IV_STMT. */
1644 remove_iv (gimple iv_stmt
)
1646 gimple_stmt_iterator si
= gsi_for_stmt (iv_stmt
);
1648 if (gimple_code (iv_stmt
) == GIMPLE_PHI
)
1652 for (i
= 0; i
< gimple_phi_num_args (iv_stmt
); i
++)
1655 imm_use_iterator imm_iter
;
1656 tree arg
= gimple_phi_arg_def (iv_stmt
, i
);
1659 if (TREE_CODE (arg
) != SSA_NAME
)
1662 FOR_EACH_IMM_USE_STMT (stmt
, imm_iter
, arg
)
1663 if (stmt
!= iv_stmt
&& !is_gimple_debug (stmt
))
1667 remove_iv (SSA_NAME_DEF_STMT (arg
));
1670 remove_phi_node (&si
, true);
1674 gsi_remove (&si
, true);
1675 release_defs (iv_stmt
);
1679 /* Transform a lambda loopnest NEW_LOOPNEST, which had TRANSFORM applied to
1680 it, back into gcc code. This changes the
1681 loops, their induction variables, and their bodies, so that they
1682 match the transformed loopnest.
1683 OLD_LOOPNEST is the loopnest before we've replaced it with the new
1685 OLD_IVS is a vector of induction variables from the old loopnest.
1686 INVARIANTS is a vector of loop invariants from the old loopnest.
1687 NEW_LOOPNEST is the new lambda loopnest to replace OLD_LOOPNEST with.
1688 TRANSFORM is the matrix transform that was applied to OLD_LOOPNEST to get
1692 lambda_loopnest_to_gcc_loopnest (struct loop
*old_loopnest
,
1693 VEC(tree
,heap
) *old_ivs
,
1694 VEC(tree
,heap
) *invariants
,
1695 VEC(gimple
,heap
) **remove_ivs
,
1696 lambda_loopnest new_loopnest
,
1697 lambda_trans_matrix transform
,
1698 struct obstack
* lambda_obstack
)
1704 VEC(tree
,heap
) *new_ivs
= NULL
;
1706 gimple_stmt_iterator bsi
;
1708 transform
= lambda_trans_matrix_inverse (transform
, lambda_obstack
);
1712 fprintf (dump_file
, "Inverse of transformation matrix:\n");
1713 print_lambda_trans_matrix (dump_file
, transform
);
1715 depth
= depth_of_nest (old_loopnest
);
1716 temp
= old_loopnest
;
1720 lambda_loop newloop
;
1723 tree ivvar
, ivvarinced
;
1726 enum tree_code testtype
;
1727 tree newupperbound
, newlowerbound
;
1728 lambda_linear_expression offset
;
1733 oldiv
= VEC_index (tree
, old_ivs
, i
);
1734 type
= TREE_TYPE (oldiv
);
1736 /* First, build the new induction variable temporary */
1738 ivvar
= create_tmp_var (type
, "lnivtmp");
1739 add_referenced_var (ivvar
);
1741 VEC_safe_push (tree
, heap
, new_ivs
, ivvar
);
1743 newloop
= LN_LOOPS (new_loopnest
)[i
];
1745 /* Linear offset is a bit tricky to handle. Punt on the unhandled
1747 offset
= LL_LINEAR_OFFSET (newloop
);
1749 gcc_assert (LLE_DENOMINATOR (offset
) == 1 &&
1750 lambda_vector_zerop (LLE_COEFFICIENTS (offset
), depth
));
1752 /* Now build the new lower bounds, and insert the statements
1753 necessary to generate it on the loop preheader. */
1755 newlowerbound
= lle_to_gcc_expression (LL_LOWER_BOUND (newloop
),
1756 LL_LINEAR_OFFSET (newloop
),
1759 invariants
, MAX_EXPR
, &stmts
);
1763 gsi_insert_seq_on_edge (loop_preheader_edge (temp
), stmts
);
1764 gsi_commit_edge_inserts ();
1766 /* Build the new upper bound and insert its statements in the
1767 basic block of the exit condition */
1769 newupperbound
= lle_to_gcc_expression (LL_UPPER_BOUND (newloop
),
1770 LL_LINEAR_OFFSET (newloop
),
1773 invariants
, MIN_EXPR
, &stmts
);
1774 exit
= single_exit (temp
);
1775 exitcond
= get_loop_exit_condition (temp
);
1776 bb
= gimple_bb (exitcond
);
1777 bsi
= gsi_after_labels (bb
);
1779 gsi_insert_seq_before (&bsi
, stmts
, GSI_NEW_STMT
);
1781 /* Create the new iv. */
1783 standard_iv_increment_position (temp
, &bsi
, &insert_after
);
1784 create_iv (newlowerbound
,
1785 build_int_cst (type
, LL_STEP (newloop
)),
1786 ivvar
, temp
, &bsi
, insert_after
, &ivvar
,
1789 /* Unfortunately, the incremented ivvar that create_iv inserted may not
1790 dominate the block containing the exit condition.
1791 So we simply create our own incremented iv to use in the new exit
1792 test, and let redundancy elimination sort it out. */
1793 inc_stmt
= gimple_build_assign_with_ops (PLUS_EXPR
, SSA_NAME_VAR (ivvar
),
1795 build_int_cst (type
, LL_STEP (newloop
)));
1797 ivvarinced
= make_ssa_name (SSA_NAME_VAR (ivvar
), inc_stmt
);
1798 gimple_assign_set_lhs (inc_stmt
, ivvarinced
);
1799 bsi
= gsi_for_stmt (exitcond
);
1800 gsi_insert_before (&bsi
, inc_stmt
, GSI_SAME_STMT
);
1802 /* Replace the exit condition with the new upper bound
1805 testtype
= LL_STEP (newloop
) >= 0 ? LE_EXPR
: GE_EXPR
;
1807 /* We want to build a conditional where true means exit the loop, and
1808 false means continue the loop.
1809 So swap the testtype if this isn't the way things are.*/
1811 if (exit
->flags
& EDGE_FALSE_VALUE
)
1812 testtype
= swap_tree_comparison (testtype
);
1814 gimple_cond_set_condition (exitcond
, testtype
, newupperbound
, ivvarinced
);
1815 update_stmt (exitcond
);
1816 VEC_replace (tree
, new_ivs
, i
, ivvar
);
1822 /* Rewrite uses of the old ivs so that they are now specified in terms of
1825 FOR_EACH_VEC_ELT (tree
, old_ivs
, i
, oldiv
)
1827 imm_use_iterator imm_iter
;
1828 use_operand_p use_p
;
1830 gimple oldiv_stmt
= SSA_NAME_DEF_STMT (oldiv
);
1833 if (gimple_code (oldiv_stmt
) == GIMPLE_PHI
)
1834 oldiv_def
= PHI_RESULT (oldiv_stmt
);
1836 oldiv_def
= SINGLE_SSA_TREE_OPERAND (oldiv_stmt
, SSA_OP_DEF
);
1837 gcc_assert (oldiv_def
!= NULL_TREE
);
1839 FOR_EACH_IMM_USE_STMT (stmt
, imm_iter
, oldiv_def
)
1843 lambda_body_vector lbv
, newlbv
;
1845 if (is_gimple_debug (stmt
))
1848 /* Compute the new expression for the induction
1850 depth
= VEC_length (tree
, new_ivs
);
1851 lbv
= lambda_body_vector_new (depth
, lambda_obstack
);
1852 LBV_COEFFICIENTS (lbv
)[i
] = 1;
1854 newlbv
= lambda_body_vector_compute_new (transform
, lbv
,
1858 newiv
= lbv_to_gcc_expression (newlbv
, TREE_TYPE (oldiv
),
1861 if (stmts
&& gimple_code (stmt
) != GIMPLE_PHI
)
1863 bsi
= gsi_for_stmt (stmt
);
1864 gsi_insert_seq_before (&bsi
, stmts
, GSI_SAME_STMT
);
1867 FOR_EACH_IMM_USE_ON_STMT (use_p
, imm_iter
)
1868 propagate_value (use_p
, newiv
);
1870 if (stmts
&& gimple_code (stmt
) == GIMPLE_PHI
)
1871 for (j
= 0; j
< gimple_phi_num_args (stmt
); j
++)
1872 if (gimple_phi_arg_def (stmt
, j
) == newiv
)
1873 gsi_insert_seq_on_edge (gimple_phi_arg_edge (stmt
, j
), stmts
);
1878 /* Remove the now unused induction variable. */
1879 VEC_safe_push (gimple
, heap
, *remove_ivs
, oldiv_stmt
);
1881 VEC_free (tree
, heap
, new_ivs
);
1884 /* Return TRUE if this is not interesting statement from the perspective of
1885 determining if we have a perfect loop nest. */
1888 not_interesting_stmt (gimple stmt
)
1890 /* Note that COND_EXPR's aren't interesting because if they were exiting the
1891 loop, we would have already failed the number of exits tests. */
1892 if (gimple_code (stmt
) == GIMPLE_LABEL
1893 || gimple_code (stmt
) == GIMPLE_GOTO
1894 || gimple_code (stmt
) == GIMPLE_COND
1895 || is_gimple_debug (stmt
))
1900 /* Return TRUE if PHI uses DEF for it's in-the-loop edge for LOOP. */
1903 phi_loop_edge_uses_def (struct loop
*loop
, gimple phi
, tree def
)
1906 for (i
= 0; i
< gimple_phi_num_args (phi
); i
++)
1907 if (flow_bb_inside_loop_p (loop
, gimple_phi_arg_edge (phi
, i
)->src
))
1908 if (PHI_ARG_DEF (phi
, i
) == def
)
1913 /* Return TRUE if STMT is a use of PHI_RESULT. */
1916 stmt_uses_phi_result (gimple stmt
, tree phi_result
)
1918 tree use
= SINGLE_SSA_TREE_OPERAND (stmt
, SSA_OP_USE
);
1920 /* This is conservatively true, because we only want SIMPLE bumpers
1921 of the form x +- constant for our pass. */
1922 return (use
== phi_result
);
1925 /* STMT is a bumper stmt for LOOP if the version it defines is used in the
1926 in-loop-edge in a phi node, and the operand it uses is the result of that
1929 i_3 = PHI (0, i_29); */
1932 stmt_is_bumper_for_loop (struct loop
*loop
, gimple stmt
)
1936 imm_use_iterator iter
;
1937 use_operand_p use_p
;
1939 def
= SINGLE_SSA_TREE_OPERAND (stmt
, SSA_OP_DEF
);
1943 FOR_EACH_IMM_USE_FAST (use_p
, iter
, def
)
1945 use
= USE_STMT (use_p
);
1946 if (gimple_code (use
) == GIMPLE_PHI
)
1948 if (phi_loop_edge_uses_def (loop
, use
, def
))
1949 if (stmt_uses_phi_result (stmt
, PHI_RESULT (use
)))
1957 /* Return true if LOOP is a perfect loop nest.
1958 Perfect loop nests are those loop nests where all code occurs in the
1959 innermost loop body.
1960 If S is a program statement, then
1969 is not a perfect loop nest because of S1.
1977 is a perfect loop nest.
1979 Since we don't have high level loops anymore, we basically have to walk our
1980 statements and ignore those that are there because the loop needs them (IE
1981 the induction variable increment, and jump back to the top of the loop). */
1984 perfect_nest_p (struct loop
*loop
)
1990 /* Loops at depth 0 are perfect nests. */
1994 bbs
= get_loop_body (loop
);
1995 exit_cond
= get_loop_exit_condition (loop
);
1997 for (i
= 0; i
< loop
->num_nodes
; i
++)
1999 if (bbs
[i
]->loop_father
== loop
)
2001 gimple_stmt_iterator bsi
;
2003 for (bsi
= gsi_start_bb (bbs
[i
]); !gsi_end_p (bsi
); gsi_next (&bsi
))
2005 gimple stmt
= gsi_stmt (bsi
);
2007 if (gimple_code (stmt
) == GIMPLE_COND
2008 && exit_cond
!= stmt
)
2009 goto non_perfectly_nested
;
2011 if (stmt
== exit_cond
2012 || not_interesting_stmt (stmt
)
2013 || stmt_is_bumper_for_loop (loop
, stmt
))
2016 non_perfectly_nested
:
2025 return perfect_nest_p (loop
->inner
);
2028 /* Replace the USES of X in STMT, or uses with the same step as X with Y.
2029 YINIT is the initial value of Y, REPLACEMENTS is a hash table to
2030 avoid creating duplicate temporaries and FIRSTBSI is statement
2031 iterator where new temporaries should be inserted at the beginning
2032 of body basic block. */
2035 replace_uses_equiv_to_x_with_y (struct loop
*loop
, gimple stmt
, tree x
,
2036 int xstep
, tree y
, tree yinit
,
2037 htab_t replacements
,
2038 gimple_stmt_iterator
*firstbsi
)
2041 use_operand_p use_p
;
2043 FOR_EACH_SSA_USE_OPERAND (use_p
, stmt
, iter
, SSA_OP_USE
)
2045 tree use
= USE_FROM_PTR (use_p
);
2046 tree step
= NULL_TREE
;
2047 tree scev
, init
, val
, var
;
2049 struct tree_map
*h
, in
;
2052 /* Replace uses of X with Y right away. */
2059 scev
= instantiate_parameters (loop
,
2060 analyze_scalar_evolution (loop
, use
));
2062 if (scev
== NULL
|| scev
== chrec_dont_know
)
2065 step
= evolution_part_in_loop_num (scev
, loop
->num
);
2067 || step
== chrec_dont_know
2068 || TREE_CODE (step
) != INTEGER_CST
2069 || int_cst_value (step
) != xstep
)
2072 /* Use REPLACEMENTS hash table to cache already created
2074 in
.hash
= htab_hash_pointer (use
);
2076 h
= (struct tree_map
*) htab_find_with_hash (replacements
, &in
, in
.hash
);
2079 SET_USE (use_p
, h
->to
);
2083 /* USE which has the same step as X should be replaced
2084 with a temporary set to Y + YINIT - INIT. */
2085 init
= initial_condition_in_loop_num (scev
, loop
->num
);
2086 gcc_assert (init
!= NULL
&& init
!= chrec_dont_know
);
2087 if (TREE_TYPE (use
) == TREE_TYPE (y
))
2089 val
= fold_build2 (MINUS_EXPR
, TREE_TYPE (y
), init
, yinit
);
2090 val
= fold_build2 (PLUS_EXPR
, TREE_TYPE (y
), y
, val
);
2093 /* If X has the same type as USE, the same step
2094 and same initial value, it can be replaced by Y. */
2101 val
= fold_build2 (MINUS_EXPR
, TREE_TYPE (y
), y
, yinit
);
2102 val
= fold_convert (TREE_TYPE (use
), val
);
2103 val
= fold_build2 (PLUS_EXPR
, TREE_TYPE (use
), val
, init
);
2106 /* Create a temporary variable and insert it at the beginning
2107 of the loop body basic block, right after the PHI node
2109 var
= create_tmp_var (TREE_TYPE (use
), "perfecttmp");
2110 add_referenced_var (var
);
2111 val
= force_gimple_operand_gsi (firstbsi
, val
, false, NULL
,
2112 true, GSI_SAME_STMT
);
2113 setstmt
= gimple_build_assign (var
, val
);
2114 var
= make_ssa_name (var
, setstmt
);
2115 gimple_assign_set_lhs (setstmt
, var
);
2116 gsi_insert_before (firstbsi
, setstmt
, GSI_SAME_STMT
);
2117 update_stmt (setstmt
);
2118 SET_USE (use_p
, var
);
2119 h
= ggc_alloc_tree_map ();
2123 loc
= htab_find_slot_with_hash (replacements
, h
, in
.hash
, INSERT
);
2124 gcc_assert ((*(struct tree_map
**)loc
) == NULL
);
2125 *(struct tree_map
**) loc
= h
;
2129 /* Return true if STMT is an exit PHI for LOOP */
2132 exit_phi_for_loop_p (struct loop
*loop
, gimple stmt
)
2134 if (gimple_code (stmt
) != GIMPLE_PHI
2135 || gimple_phi_num_args (stmt
) != 1
2136 || gimple_bb (stmt
) != single_exit (loop
)->dest
)
2142 /* Return true if STMT can be put back into the loop INNER, by
2143 copying it to the beginning of that loop and changing the uses. */
2146 can_put_in_inner_loop (struct loop
*inner
, gimple stmt
)
2148 imm_use_iterator imm_iter
;
2149 use_operand_p use_p
;
2151 gcc_assert (is_gimple_assign (stmt
));
2152 if (gimple_vuse (stmt
)
2153 || !stmt_invariant_in_loop_p (inner
, stmt
))
2156 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, gimple_assign_lhs (stmt
))
2158 if (!exit_phi_for_loop_p (inner
, USE_STMT (use_p
)))
2160 basic_block immbb
= gimple_bb (USE_STMT (use_p
));
2162 if (!flow_bb_inside_loop_p (inner
, immbb
))
2169 /* Return true if STMT can be put *after* the inner loop of LOOP. */
2172 can_put_after_inner_loop (struct loop
*loop
, gimple stmt
)
2174 imm_use_iterator imm_iter
;
2175 use_operand_p use_p
;
2177 if (gimple_vuse (stmt
))
2180 FOR_EACH_IMM_USE_FAST (use_p
, imm_iter
, gimple_assign_lhs (stmt
))
2182 if (!exit_phi_for_loop_p (loop
, USE_STMT (use_p
)))
2184 basic_block immbb
= gimple_bb (USE_STMT (use_p
));
2186 if (!dominated_by_p (CDI_DOMINATORS
,
2188 loop
->inner
->header
)
2189 && !can_put_in_inner_loop (loop
->inner
, stmt
))
2196 /* Return true when the induction variable IV is simple enough to be
2200 can_duplicate_iv (tree iv
, struct loop
*loop
)
2202 tree scev
= instantiate_parameters
2203 (loop
, analyze_scalar_evolution (loop
, iv
));
2205 if (!automatically_generated_chrec_p (scev
))
2207 tree step
= evolution_part_in_loop_num (scev
, loop
->num
);
2209 if (step
&& step
!= chrec_dont_know
&& TREE_CODE (step
) == INTEGER_CST
)
2216 /* If this is a scalar operation that can be put back into the inner
2217 loop, or after the inner loop, through copying, then do so. This
2218 works on the theory that any amount of scalar code we have to
2219 reduplicate into or after the loops is less expensive that the win
2220 we get from rearranging the memory walk the loop is doing so that
2221 it has better cache behavior. */
2224 cannot_convert_modify_to_perfect_nest (gimple stmt
, struct loop
*loop
)
2226 use_operand_p use_a
, use_b
;
2227 imm_use_iterator imm_iter
;
2228 ssa_op_iter op_iter
, op_iter1
;
2229 tree op0
= gimple_assign_lhs (stmt
);
2231 /* The statement should not define a variable used in the inner
2233 if (TREE_CODE (op0
) == SSA_NAME
2234 && !can_duplicate_iv (op0
, loop
))
2235 FOR_EACH_IMM_USE_FAST (use_a
, imm_iter
, op0
)
2236 if (gimple_bb (USE_STMT (use_a
))->loop_father
== loop
->inner
)
2239 FOR_EACH_SSA_USE_OPERAND (use_a
, stmt
, op_iter
, SSA_OP_USE
)
2242 tree op
= USE_FROM_PTR (use_a
);
2244 /* The variables should not be used in both loops. */
2245 if (!can_duplicate_iv (op
, loop
))
2246 FOR_EACH_IMM_USE_FAST (use_b
, imm_iter
, op
)
2247 if (gimple_bb (USE_STMT (use_b
))->loop_father
== loop
->inner
)
2250 /* The statement should not use the value of a scalar that was
2251 modified in the loop. */
2252 node
= SSA_NAME_DEF_STMT (op
);
2253 if (gimple_code (node
) == GIMPLE_PHI
)
2254 FOR_EACH_PHI_ARG (use_b
, node
, op_iter1
, SSA_OP_USE
)
2256 tree arg
= USE_FROM_PTR (use_b
);
2258 if (TREE_CODE (arg
) == SSA_NAME
)
2260 gimple arg_stmt
= SSA_NAME_DEF_STMT (arg
);
2262 if (gimple_bb (arg_stmt
)
2263 && (gimple_bb (arg_stmt
)->loop_father
== loop
->inner
))
2271 /* Return true when BB contains statements that can harm the transform
2272 to a perfect loop nest. */
2275 cannot_convert_bb_to_perfect_nest (basic_block bb
, struct loop
*loop
)
2277 gimple_stmt_iterator bsi
;
2278 gimple exit_condition
= get_loop_exit_condition (loop
);
2280 for (bsi
= gsi_start_bb (bb
); !gsi_end_p (bsi
); gsi_next (&bsi
))
2282 gimple stmt
= gsi_stmt (bsi
);
2284 if (stmt
== exit_condition
2285 || not_interesting_stmt (stmt
)
2286 || stmt_is_bumper_for_loop (loop
, stmt
))
2289 if (is_gimple_assign (stmt
))
2291 if (cannot_convert_modify_to_perfect_nest (stmt
, loop
))
2294 if (can_duplicate_iv (gimple_assign_lhs (stmt
), loop
))
2297 if (can_put_in_inner_loop (loop
->inner
, stmt
)
2298 || can_put_after_inner_loop (loop
, stmt
))
2302 /* If the bb of a statement we care about isn't dominated by the
2303 header of the inner loop, then we can't handle this case
2304 right now. This test ensures that the statement comes
2305 completely *after* the inner loop. */
2306 if (!dominated_by_p (CDI_DOMINATORS
,
2308 loop
->inner
->header
))
2316 /* Return TRUE if LOOP is an imperfect nest that we can convert to a
2317 perfect one. At the moment, we only handle imperfect nests of
2318 depth 2, where all of the statements occur after the inner loop. */
2321 can_convert_to_perfect_nest (struct loop
*loop
)
2325 gimple_stmt_iterator si
;
2327 /* Can't handle triply nested+ loops yet. */
2328 if (!loop
->inner
|| loop
->inner
->inner
)
2331 bbs
= get_loop_body (loop
);
2332 for (i
= 0; i
< loop
->num_nodes
; i
++)
2333 if (bbs
[i
]->loop_father
== loop
2334 && cannot_convert_bb_to_perfect_nest (bbs
[i
], loop
))
2337 /* We also need to make sure the loop exit only has simple copy phis in it,
2338 otherwise we don't know how to transform it into a perfect nest. */
2339 for (si
= gsi_start_phis (single_exit (loop
)->dest
);
2342 if (gimple_phi_num_args (gsi_stmt (si
)) != 1)
2354 DEF_VEC_I(source_location
);
2355 DEF_VEC_ALLOC_I(source_location
,heap
);
2357 /* Transform the loop nest into a perfect nest, if possible.
2358 LOOP is the loop nest to transform into a perfect nest
2359 LBOUNDS are the lower bounds for the loops to transform
2360 UBOUNDS are the upper bounds for the loops to transform
2361 STEPS is the STEPS for the loops to transform.
2362 LOOPIVS is the induction variables for the loops to transform.
2364 Basically, for the case of
2366 FOR (i = 0; i < 50; i++)
2368 FOR (j =0; j < 50; j++)
2375 This function will transform it into a perfect loop nest by splitting the
2376 outer loop into two loops, like so:
2378 FOR (i = 0; i < 50; i++)
2380 FOR (j = 0; j < 50; j++)
2386 FOR (i = 0; i < 50; i ++)
2391 Return FALSE if we can't make this loop into a perfect nest. */
2394 perfect_nestify (struct loop
*loop
,
2395 VEC(tree
,heap
) *lbounds
,
2396 VEC(tree
,heap
) *ubounds
,
2397 VEC(int,heap
) *steps
,
2398 VEC(tree
,heap
) *loopivs
)
2401 gimple exit_condition
;
2403 basic_block preheaderbb
, headerbb
, bodybb
, latchbb
, olddest
;
2405 gimple_stmt_iterator bsi
, firstbsi
;
2408 struct loop
*newloop
;
2412 tree oldivvar
, ivvar
, ivvarinced
;
2413 VEC(tree
,heap
) *phis
= NULL
;
2414 VEC(source_location
,heap
) *locations
= NULL
;
2415 htab_t replacements
= NULL
;
2417 /* Create the new loop. */
2418 olddest
= single_exit (loop
)->dest
;
2419 preheaderbb
= split_edge (single_exit (loop
));
2420 headerbb
= create_empty_bb (EXIT_BLOCK_PTR
->prev_bb
);
2422 /* Push the exit phi nodes that we are moving. */
2423 for (bsi
= gsi_start_phis (olddest
); !gsi_end_p (bsi
); gsi_next (&bsi
))
2425 phi
= gsi_stmt (bsi
);
2426 VEC_reserve (tree
, heap
, phis
, 2);
2427 VEC_reserve (source_location
, heap
, locations
, 1);
2428 VEC_quick_push (tree
, phis
, PHI_RESULT (phi
));
2429 VEC_quick_push (tree
, phis
, PHI_ARG_DEF (phi
, 0));
2430 VEC_quick_push (source_location
, locations
,
2431 gimple_phi_arg_location (phi
, 0));
2433 e
= redirect_edge_and_branch (single_succ_edge (preheaderbb
), headerbb
);
2435 /* Remove the exit phis from the old basic block. */
2436 for (bsi
= gsi_start_phis (olddest
); !gsi_end_p (bsi
); )
2437 remove_phi_node (&bsi
, false);
2439 /* and add them back to the new basic block. */
2440 while (VEC_length (tree
, phis
) != 0)
2444 source_location locus
;
2445 def
= VEC_pop (tree
, phis
);
2446 phiname
= VEC_pop (tree
, phis
);
2447 locus
= VEC_pop (source_location
, locations
);
2448 phi
= create_phi_node (phiname
, preheaderbb
);
2449 add_phi_arg (phi
, def
, single_pred_edge (preheaderbb
), locus
);
2451 flush_pending_stmts (e
);
2452 VEC_free (tree
, heap
, phis
);
2454 bodybb
= create_empty_bb (EXIT_BLOCK_PTR
->prev_bb
);
2455 latchbb
= create_empty_bb (EXIT_BLOCK_PTR
->prev_bb
);
2456 make_edge (headerbb
, bodybb
, EDGE_FALLTHRU
);
2457 cond_stmt
= gimple_build_cond (NE_EXPR
, integer_one_node
, integer_zero_node
,
2458 NULL_TREE
, NULL_TREE
);
2459 bsi
= gsi_start_bb (bodybb
);
2460 gsi_insert_after (&bsi
, cond_stmt
, GSI_NEW_STMT
);
2461 e
= make_edge (bodybb
, olddest
, EDGE_FALSE_VALUE
);
2462 make_edge (bodybb
, latchbb
, EDGE_TRUE_VALUE
);
2463 make_edge (latchbb
, headerbb
, EDGE_FALLTHRU
);
2465 /* Update the loop structures. */
2466 newloop
= duplicate_loop (loop
, olddest
->loop_father
);
2467 newloop
->header
= headerbb
;
2468 newloop
->latch
= latchbb
;
2469 add_bb_to_loop (latchbb
, newloop
);
2470 add_bb_to_loop (bodybb
, newloop
);
2471 add_bb_to_loop (headerbb
, newloop
);
2472 set_immediate_dominator (CDI_DOMINATORS
, bodybb
, headerbb
);
2473 set_immediate_dominator (CDI_DOMINATORS
, headerbb
, preheaderbb
);
2474 set_immediate_dominator (CDI_DOMINATORS
, preheaderbb
,
2475 single_exit (loop
)->src
);
2476 set_immediate_dominator (CDI_DOMINATORS
, latchbb
, bodybb
);
2477 set_immediate_dominator (CDI_DOMINATORS
, olddest
,
2478 recompute_dominator (CDI_DOMINATORS
, olddest
));
2479 /* Create the new iv. */
2480 oldivvar
= VEC_index (tree
, loopivs
, 0);
2481 ivvar
= create_tmp_var (TREE_TYPE (oldivvar
), "perfectiv");
2482 add_referenced_var (ivvar
);
2483 standard_iv_increment_position (newloop
, &bsi
, &insert_after
);
2484 create_iv (VEC_index (tree
, lbounds
, 0),
2485 build_int_cst (TREE_TYPE (oldivvar
), VEC_index (int, steps
, 0)),
2486 ivvar
, newloop
, &bsi
, insert_after
, &ivvar
, &ivvarinced
);
2488 /* Create the new upper bound. This may be not just a variable, so we copy
2489 it to one just in case. */
2491 exit_condition
= get_loop_exit_condition (newloop
);
2492 uboundvar
= create_tmp_var (TREE_TYPE (VEC_index (tree
, ubounds
, 0)),
2494 add_referenced_var (uboundvar
);
2495 stmt
= gimple_build_assign (uboundvar
, VEC_index (tree
, ubounds
, 0));
2496 uboundvar
= make_ssa_name (uboundvar
, stmt
);
2497 gimple_assign_set_lhs (stmt
, uboundvar
);
2500 gsi_insert_after (&bsi
, stmt
, GSI_SAME_STMT
);
2502 gsi_insert_before (&bsi
, stmt
, GSI_SAME_STMT
);
2504 gimple_cond_set_condition (exit_condition
, GE_EXPR
, uboundvar
, ivvarinced
);
2505 update_stmt (exit_condition
);
2506 replacements
= htab_create_ggc (20, tree_map_hash
,
2508 bbs
= get_loop_body_in_dom_order (loop
);
2509 /* Now move the statements, and replace the induction variable in the moved
2510 statements with the correct loop induction variable. */
2511 oldivvar
= VEC_index (tree
, loopivs
, 0);
2512 firstbsi
= gsi_start_bb (bodybb
);
2513 for (i
= loop
->num_nodes
- 1; i
>= 0 ; i
--)
2515 gimple_stmt_iterator tobsi
= gsi_last_bb (bodybb
);
2516 if (bbs
[i
]->loop_father
== loop
)
2518 /* If this is true, we are *before* the inner loop.
2519 If this isn't true, we are *after* it.
2521 The only time can_convert_to_perfect_nest returns true when we
2522 have statements before the inner loop is if they can be moved
2523 into the inner loop.
2525 The only time can_convert_to_perfect_nest returns true when we
2526 have statements after the inner loop is if they can be moved into
2527 the new split loop. */
2529 if (dominated_by_p (CDI_DOMINATORS
, loop
->inner
->header
, bbs
[i
]))
2531 gimple_stmt_iterator header_bsi
2532 = gsi_after_labels (loop
->inner
->header
);
2534 for (bsi
= gsi_start_bb (bbs
[i
]); !gsi_end_p (bsi
);)
2536 gimple stmt
= gsi_stmt (bsi
);
2538 if (stmt
== exit_condition
2539 || not_interesting_stmt (stmt
)
2540 || stmt_is_bumper_for_loop (loop
, stmt
))
2546 gsi_move_before (&bsi
, &header_bsi
);
2551 /* Note that the bsi only needs to be explicitly incremented
2552 when we don't move something, since it is automatically
2553 incremented when we do. */
2554 for (bsi
= gsi_start_bb (bbs
[i
]); !gsi_end_p (bsi
);)
2556 gimple stmt
= gsi_stmt (bsi
);
2558 if (stmt
== exit_condition
2559 || not_interesting_stmt (stmt
)
2560 || stmt_is_bumper_for_loop (loop
, stmt
))
2566 replace_uses_equiv_to_x_with_y
2567 (loop
, stmt
, oldivvar
, VEC_index (int, steps
, 0), ivvar
,
2568 VEC_index (tree
, lbounds
, 0), replacements
, &firstbsi
);
2570 gsi_move_before (&bsi
, &tobsi
);
2572 /* If the statement has any virtual operands, they may
2573 need to be rewired because the original loop may
2574 still reference them. */
2575 if (gimple_vuse (stmt
))
2576 mark_sym_for_renaming (gimple_vop (cfun
));
2584 htab_delete (replacements
);
2585 return perfect_nest_p (loop
);
2588 /* Return true if TRANS is a legal transformation matrix that respects
2589 the dependence vectors in DISTS and DIRS. The conservative answer
2592 "Wolfe proves that a unimodular transformation represented by the
2593 matrix T is legal when applied to a loop nest with a set of
2594 lexicographically non-negative distance vectors RDG if and only if
2595 for each vector d in RDG, (T.d >= 0) is lexicographically positive.
2596 i.e.: if and only if it transforms the lexicographically positive
2597 distance vectors to lexicographically positive vectors. Note that
2598 a unimodular matrix must transform the zero vector (and only it) to
2599 the zero vector." S.Muchnick. */
2602 lambda_transform_legal_p (lambda_trans_matrix trans
,
2604 VEC (ddr_p
, heap
) *dependence_relations
)
2607 lambda_vector distres
;
2608 struct data_dependence_relation
*ddr
;
2610 gcc_assert (LTM_COLSIZE (trans
) == nb_loops
2611 && LTM_ROWSIZE (trans
) == nb_loops
);
2613 /* When there are no dependences, the transformation is correct. */
2614 if (VEC_length (ddr_p
, dependence_relations
) == 0)
2617 ddr
= VEC_index (ddr_p
, dependence_relations
, 0);
2621 /* When there is an unknown relation in the dependence_relations, we
2622 know that it is no worth looking at this loop nest: give up. */
2623 if (DDR_ARE_DEPENDENT (ddr
) == chrec_dont_know
)
2626 distres
= lambda_vector_new (nb_loops
);
2628 /* For each distance vector in the dependence graph. */
2629 FOR_EACH_VEC_ELT (ddr_p
, dependence_relations
, i
, ddr
)
2631 /* Don't care about relations for which we know that there is no
2632 dependence, nor about read-read (aka. output-dependences):
2633 these data accesses can happen in any order. */
2634 if (DDR_ARE_DEPENDENT (ddr
) == chrec_known
2635 || (DR_IS_READ (DDR_A (ddr
)) && DR_IS_READ (DDR_B (ddr
))))
2638 /* Conservatively answer: "this transformation is not valid". */
2639 if (DDR_ARE_DEPENDENT (ddr
) == chrec_dont_know
)
2642 /* If the dependence could not be captured by a distance vector,
2643 conservatively answer that the transform is not valid. */
2644 if (DDR_NUM_DIST_VECTS (ddr
) == 0)
2647 /* Compute trans.dist_vect */
2648 for (j
= 0; j
< DDR_NUM_DIST_VECTS (ddr
); j
++)
2650 lambda_matrix_vector_mult (LTM_MATRIX (trans
), nb_loops
, nb_loops
,
2651 DDR_DIST_VECT (ddr
, j
), distres
);
2653 if (!lambda_vector_lexico_pos (distres
, nb_loops
))
2661 /* Collects parameters from affine function ACCESS_FUNCTION, and push
2662 them in PARAMETERS. */
2665 lambda_collect_parameters_from_af (tree access_function
,
2666 struct pointer_set_t
*param_set
,
2667 VEC (tree
, heap
) **parameters
)
2669 if (access_function
== NULL
)
2672 if (TREE_CODE (access_function
) == SSA_NAME
2673 && pointer_set_contains (param_set
, access_function
) == 0)
2675 pointer_set_insert (param_set
, access_function
);
2676 VEC_safe_push (tree
, heap
, *parameters
, access_function
);
2680 int i
, num_operands
= tree_operand_length (access_function
);
2682 for (i
= 0; i
< num_operands
; i
++)
2683 lambda_collect_parameters_from_af (TREE_OPERAND (access_function
, i
),
2684 param_set
, parameters
);
2688 /* Collects parameters from DATAREFS, and push them in PARAMETERS. */
2691 lambda_collect_parameters (VEC (data_reference_p
, heap
) *datarefs
,
2692 VEC (tree
, heap
) **parameters
)
2695 struct pointer_set_t
*parameter_set
= pointer_set_create ();
2696 data_reference_p data_reference
;
2698 FOR_EACH_VEC_ELT (data_reference_p
, datarefs
, i
, data_reference
)
2699 for (j
= 0; j
< DR_NUM_DIMENSIONS (data_reference
); j
++)
2700 lambda_collect_parameters_from_af (DR_ACCESS_FN (data_reference
, j
),
2701 parameter_set
, parameters
);
2702 pointer_set_destroy (parameter_set
);
2705 /* Translates BASE_EXPR to vector CY. AM is needed for inferring
2706 indexing positions in the data access vector. CST is the analyzed
2707 integer constant. */
2710 av_for_af_base (tree base_expr
, lambda_vector cy
, struct access_matrix
*am
,
2715 switch (TREE_CODE (base_expr
))
2718 /* Constant part. */
2719 cy
[AM_CONST_COLUMN_INDEX (am
)] += int_cst_value (base_expr
) * cst
;
2725 access_matrix_get_index_for_parameter (base_expr
, am
);
2727 if (param_index
>= 0)
2729 cy
[param_index
] = cst
+ cy
[param_index
];
2737 return av_for_af_base (TREE_OPERAND (base_expr
, 0), cy
, am
, cst
)
2738 && av_for_af_base (TREE_OPERAND (base_expr
, 1), cy
, am
, cst
);
2741 return av_for_af_base (TREE_OPERAND (base_expr
, 0), cy
, am
, cst
)
2742 && av_for_af_base (TREE_OPERAND (base_expr
, 1), cy
, am
, -1 * cst
);
2745 if (TREE_CODE (TREE_OPERAND (base_expr
, 0)) == INTEGER_CST
)
2746 result
= av_for_af_base (TREE_OPERAND (base_expr
, 1),
2748 int_cst_value (TREE_OPERAND (base_expr
, 0)));
2749 else if (TREE_CODE (TREE_OPERAND (base_expr
, 1)) == INTEGER_CST
)
2750 result
= av_for_af_base (TREE_OPERAND (base_expr
, 0),
2752 int_cst_value (TREE_OPERAND (base_expr
, 1)));
2759 return av_for_af_base (TREE_OPERAND (base_expr
, 0), cy
, am
, -1 * cst
);
2768 /* Translates ACCESS_FUN to vector CY. AM is needed for inferring
2769 indexing positions in the data access vector. */
2772 av_for_af (tree access_fun
, lambda_vector cy
, struct access_matrix
*am
)
2774 switch (TREE_CODE (access_fun
))
2776 case POLYNOMIAL_CHREC
:
2778 tree left
= CHREC_LEFT (access_fun
);
2779 tree right
= CHREC_RIGHT (access_fun
);
2782 if (TREE_CODE (right
) != INTEGER_CST
)
2785 var
= am_vector_index_for_loop (am
, CHREC_VARIABLE (access_fun
));
2786 cy
[var
] = int_cst_value (right
);
2788 if (TREE_CODE (left
) == POLYNOMIAL_CHREC
)
2789 return av_for_af (left
, cy
, am
);
2791 return av_for_af_base (left
, cy
, am
, 1);
2795 /* Constant part. */
2796 return av_for_af_base (access_fun
, cy
, am
, 1);
2803 /* Initializes the access matrix for DATA_REFERENCE. */
2806 build_access_matrix (data_reference_p data_reference
,
2807 VEC (tree
, heap
) *parameters
,
2808 VEC (loop_p
, heap
) *nest
,
2809 struct obstack
* lambda_obstack
)
2811 struct access_matrix
*am
= (struct access_matrix
*)
2812 obstack_alloc(lambda_obstack
, sizeof (struct access_matrix
));
2813 unsigned i
, ndim
= DR_NUM_DIMENSIONS (data_reference
);
2814 unsigned nivs
= VEC_length (loop_p
, nest
);
2815 unsigned lambda_nb_columns
;
2817 AM_LOOP_NEST (am
) = nest
;
2818 AM_NB_INDUCTION_VARS (am
) = nivs
;
2819 AM_PARAMETERS (am
) = parameters
;
2821 lambda_nb_columns
= AM_NB_COLUMNS (am
);
2822 AM_MATRIX (am
) = VEC_alloc (lambda_vector
, gc
, ndim
);
2824 for (i
= 0; i
< ndim
; i
++)
2826 lambda_vector access_vector
= lambda_vector_new (lambda_nb_columns
);
2827 tree access_function
= DR_ACCESS_FN (data_reference
, i
);
2829 if (!av_for_af (access_function
, access_vector
, am
))
2832 VEC_quick_push (lambda_vector
, AM_MATRIX (am
), access_vector
);
2835 DR_ACCESS_MATRIX (data_reference
) = am
;
2839 /* Returns false when one of the access matrices cannot be built. */
2842 lambda_compute_access_matrices (VEC (data_reference_p
, heap
) *datarefs
,
2843 VEC (tree
, heap
) *parameters
,
2844 VEC (loop_p
, heap
) *nest
,
2845 struct obstack
* lambda_obstack
)
2847 data_reference_p dataref
;
2850 FOR_EACH_VEC_ELT (data_reference_p
, datarefs
, ix
, dataref
)
2851 if (!build_access_matrix (dataref
, parameters
, nest
, lambda_obstack
))