]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-data-ref.h
PR testsuite/92016 - Excess errors in Wstringop-overflow-17.c
[thirdparty/gcc.git] / gcc / tree-data-ref.h
CommitLineData
48e1416a 1/* Data references and dependences detectors.
fbd26352 2 Copyright (C) 2003-2019 Free Software Foundation, Inc.
6b421feb 3 Contributed by Sebastian Pop <pop@cri.ensmp.fr>
2146e26d 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
8c4c00c1 9Software Foundation; either version 3, or (at your option) any later
2146e26d 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
8c4c00c1 18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
2146e26d 20
21#ifndef GCC_TREE_DATA_REF_H
22#define GCC_TREE_DATA_REF_H
23
74c8f69a 24#include "graphds.h"
801c5610 25#include "tree-chrec.h"
ed9370cc 26#include "opt-problem.h"
6b6f234c 27
6b8dbb53 28/*
80bb306a 29 innermost_loop_behavior describes the evolution of the address of the memory
30 reference in the innermost enclosing loop. The address is expressed as
31 BASE + STEP * # of iteration, and base is further decomposed as the base
32 pointer (BASE_ADDRESS), loop invariant offset (OFFSET) and
48e1416a 33 constant offset (INIT). Examples, in loop nest
34
80bb306a 35 for (i = 0; i < 100; i++)
36 for (j = 3; j < 100; j++)
6b8dbb53 37
516849c7 38 Example 1 Example 2
80bb306a 39 data-ref a[j].b[i][j] *(p + x + 16B + 4B * j)
48e1416a 40
801c5610 41
80bb306a 42 innermost_loop_behavior
43 base_address &a p
44 offset i * D_i x
45 init 3 * D_j + offsetof (b) 28
516849c7 46 step D_j 4
516849c7 47
6b8dbb53 48 */
80bb306a 49struct innermost_loop_behavior
516849c7 50{
51 tree base_address;
52 tree offset;
53 tree init;
54 tree step;
80bb306a 55
a5456a6d 56 /* BASE_ADDRESS is known to be misaligned by BASE_MISALIGNMENT bytes
57 from an alignment boundary of BASE_ALIGNMENT bytes. For example,
58 if we had:
59
60 struct S __attribute__((aligned(16))) { ... };
61
62 char *ptr;
63 ... *(struct S *) (ptr - 4) ...;
64
65 the information would be:
66
67 base_address: ptr
68 base_aligment: 16
69 base_misalignment: 4
70 init: -4
71
72 where init cancels the base misalignment. If instead we had a
73 reference to a particular field:
74
75 struct S __attribute__((aligned(16))) { ... int f; ... };
76
77 char *ptr;
78 ... ((struct S *) (ptr - 4))->f ...;
79
80 the information would be:
81
82 base_address: ptr
83 base_aligment: 16
84 base_misalignment: 4
85 init: -4 + offsetof (S, f)
86
87 where base_address + init might also be misaligned, and by a different
88 amount from base_address. */
89 unsigned int base_alignment;
90 unsigned int base_misalignment;
91
a7e05ef2 92 /* The largest power of two that divides OFFSET, capped to a suitably
93 high value if the offset is zero. This is a byte rather than a bit
94 quantity. */
95 unsigned int offset_alignment;
668dd7dc 96
97 /* Likewise for STEP. */
98 unsigned int step_alignment;
516849c7 99};
100
80bb306a 101/* Describes the evolutions of indices of the memory reference. The indices
95539e1d 102 are indices of the ARRAY_REFs, indexes in artificial dimensions
103 added for member selection of records and the operands of MEM_REFs.
104 BASE_OBJECT is the part of the reference that is loop-invariant
105 (note that this reference does not have to cover the whole object
106 being accessed, in which case UNCONSTRAINED_BASE is set; hence it is
107 not recommended to use BASE_OBJECT in any code generation).
108 For the examples above,
109
110 base_object: a *(p + x + 4B * j_0)
80bb306a 111 indices: {j_0, +, 1}_2 {16, +, 4}_2
95539e1d 112 4
80bb306a 113 {i_0, +, 1}_1
114 {j_0, +, 1}_2
115*/
116
117struct indices
516849c7 118{
119 /* The object. */
120 tree base_object;
48e1416a 121
80bb306a 122 /* A list of chrecs. Access functions of the indices. */
f1f41a6c 123 vec<tree> access_fns;
f146c442 124
125 /* Whether BASE_OBJECT is an access representing the whole object
126 or whether the access could not be constrained. */
127 bool unconstrained_base;
516849c7 128};
129
80bb306a 130struct dr_alias
131{
132 /* The alias information that should be used for new pointers to this
95539e1d 133 location. */
80bb306a 134 struct ptr_info_def *ptr_info;
516849c7 135};
136
e01f9f1f 137/* An integer vector. A vector formally consists of an element of a vector
138 space. A vector space is a set that is closed under vector addition
139 and scalar multiplication. In this vector space, an element is a list of
140 integers. */
7652827d 141typedef HOST_WIDE_INT lambda_int;
142typedef lambda_int *lambda_vector;
e01f9f1f 143
144/* An integer matrix. A matrix consists of m vectors of length n (IE
145 all vectors are the same length). */
146typedef lambda_vector *lambda_matrix;
147
b79b3386 148
b79b3386 149
6b6f234c 150struct data_reference
2146e26d 151{
2146e26d 152 /* A pointer to the statement that contains this DR. */
42acab1c 153 gimple *stmt;
48e1416a 154
80bb306a 155 /* A pointer to the memory reference. */
2146e26d 156 tree ref;
157
2146e26d 158 /* Auxiliary info specific to a pass. */
5c205353 159 void *aux;
2146e26d 160
161 /* True when the data reference is in RHS of a stmt. */
162 bool is_read;
163
4f372c2c 164 /* True when the data reference is conditional within STMT,
165 i.e. if it might not occur even when the statement is executed
166 and runs to completion. */
167 bool is_conditional_in_stmt;
168
80bb306a 169 /* Behavior of the memory reference in the innermost loop. */
170 struct innermost_loop_behavior innermost;
516849c7 171
255b6be7 172 /* Subscripts of this data reference. */
80bb306a 173 struct indices indices;
516849c7 174
80bb306a 175 /* Alias information for the data reference. */
176 struct dr_alias alias;
b79b3386 177};
41c7a324 178
516849c7 179#define DR_STMT(DR) (DR)->stmt
180#define DR_REF(DR) (DR)->ref
80bb306a 181#define DR_BASE_OBJECT(DR) (DR)->indices.base_object
f146c442 182#define DR_UNCONSTRAINED_BASE(DR) (DR)->indices.unconstrained_base
80bb306a 183#define DR_ACCESS_FNS(DR) (DR)->indices.access_fns
f1f41a6c 184#define DR_ACCESS_FN(DR, I) DR_ACCESS_FNS (DR)[I]
185#define DR_NUM_DIMENSIONS(DR) DR_ACCESS_FNS (DR).length ()
516849c7 186#define DR_IS_READ(DR) (DR)->is_read
9ff25603 187#define DR_IS_WRITE(DR) (!DR_IS_READ (DR))
4f372c2c 188#define DR_IS_CONDITIONAL_IN_STMT(DR) (DR)->is_conditional_in_stmt
80bb306a 189#define DR_BASE_ADDRESS(DR) (DR)->innermost.base_address
190#define DR_OFFSET(DR) (DR)->innermost.offset
191#define DR_INIT(DR) (DR)->innermost.init
192#define DR_STEP(DR) (DR)->innermost.step
80bb306a 193#define DR_PTR_INFO(DR) (DR)->alias.ptr_info
a5456a6d 194#define DR_BASE_ALIGNMENT(DR) (DR)->innermost.base_alignment
195#define DR_BASE_MISALIGNMENT(DR) (DR)->innermost.base_misalignment
a7e05ef2 196#define DR_OFFSET_ALIGNMENT(DR) (DR)->innermost.offset_alignment
668dd7dc 197#define DR_STEP_ALIGNMENT(DR) (DR)->innermost.step_alignment
bd6f374c 198#define DR_INNERMOST(DR) (DR)->innermost
b79b3386 199
200typedef struct data_reference *data_reference_p;
2146e26d 201
cea441fd 202/* This struct is used to store the information of a data reference,
203 including the data ref itself and the segment length for aliasing
204 checks. This is used to merge alias checks. */
205
251317e4 206class dr_with_seg_len
cea441fd 207{
251317e4 208public:
e85b4a5e 209 dr_with_seg_len (data_reference_p d, tree len, unsigned HOST_WIDE_INT size,
210 unsigned int a)
211 : dr (d), seg_len (len), access_size (size), align (a) {}
cea441fd 212
213 data_reference_p dr;
e85b4a5e 214 /* The offset of the last access that needs to be checked minus
215 the offset of the first. */
cea441fd 216 tree seg_len;
e85b4a5e 217 /* A value that, when added to abs (SEG_LEN), gives the total number of
218 bytes in the segment. */
219 poly_uint64 access_size;
220 /* The minimum common alignment of DR's start address, SEG_LEN and
221 ACCESS_SIZE. */
222 unsigned int align;
cea441fd 223};
224
225/* This struct contains two dr_with_seg_len objects with aliasing data
226 refs. Two comparisons are generated from them. */
227
251317e4 228class dr_with_seg_len_pair_t
cea441fd 229{
251317e4 230public:
cea441fd 231 dr_with_seg_len_pair_t (const dr_with_seg_len& d1,
232 const dr_with_seg_len& d2)
233 : first (d1), second (d2) {}
234
235 dr_with_seg_len first;
236 dr_with_seg_len second;
237};
238
2146e26d 239enum data_dependence_direction {
48e1416a 240 dir_positive,
241 dir_negative,
242 dir_equal,
2146e26d 243 dir_positive_or_negative,
244 dir_positive_or_equal,
245 dir_negative_or_equal,
246 dir_star,
247 dir_independent
248};
249
87da4f2e 250/* The description of the grid of iterations that overlap. At most
251 two loops are considered at the same time just now, hence at most
252 two functions are needed. For each of the functions, we store
253 the vector of coefficients, f[0] + x * f[1] + y * f[2] + ...,
254 where x, y, ... are variables. */
255
256#define MAX_DIM 2
257
258/* Special values of N. */
259#define NO_DEPENDENCE 0
260#define NOT_KNOWN (MAX_DIM + 1)
261#define CF_NONTRIVIAL_P(CF) ((CF)->n != NO_DEPENDENCE && (CF)->n != NOT_KNOWN)
262#define CF_NOT_KNOWN_P(CF) ((CF)->n == NOT_KNOWN)
263#define CF_NO_DEPENDENCE_P(CF) ((CF)->n == NO_DEPENDENCE)
264
f1f41a6c 265typedef vec<tree> affine_fn;
87da4f2e 266
b3e7c666 267struct conflict_function
87da4f2e 268{
269 unsigned n;
270 affine_fn fns[MAX_DIM];
b3e7c666 271};
87da4f2e 272
2146e26d 273/* What is a subscript? Given two array accesses a subscript is the
274 tuple composed of the access functions for a given dimension.
275 Example: Given A[f1][f2][f3] and B[g1][g2][g3], there are three
276 subscripts: (f1, g1), (f2, g2), (f3, g3). These three subscripts
277 are stored in the data_dependence_relation structure under the form
278 of an array of subscripts. */
279
6b6f234c 280struct subscript
2146e26d 281{
403965f7 282 /* The access functions of the two references. */
283 tree access_fn[2];
284
2146e26d 285 /* A description of the iterations for which the elements are
286 accessed twice. */
87da4f2e 287 conflict_function *conflicting_iterations_in_a;
288 conflict_function *conflicting_iterations_in_b;
48e1416a 289
bc3c8ad4 290 /* This field stores the information about the iteration domain
2146e26d 291 validity of the dependence relation. */
bc3c8ad4 292 tree last_conflict;
48e1416a 293
2146e26d 294 /* Distance from the iteration that access a conflicting element in
295 A to the iteration that access this same conflicting element in
5c9dae64 296 B. The distance is a tree scalar expression, i.e. a constant or a
2146e26d 297 symbolic expression, but certainly not a chrec function. */
298 tree distance;
2146e26d 299};
300
41c7a324 301typedef struct subscript *subscript_p;
41c7a324 302
403965f7 303#define SUB_ACCESS_FN(SUB, I) (SUB)->access_fn[I]
643e9393 304#define SUB_CONFLICTS_IN_A(SUB) (SUB)->conflicting_iterations_in_a
305#define SUB_CONFLICTS_IN_B(SUB) (SUB)->conflicting_iterations_in_b
306#define SUB_LAST_CONFLICT(SUB) (SUB)->last_conflict
307#define SUB_DISTANCE(SUB) (SUB)->distance
2146e26d 308
309/* A data_dependence_relation represents a relation between two
310 data_references A and B. */
311
6b6f234c 312struct data_dependence_relation
2146e26d 313{
48e1416a 314
2146e26d 315 struct data_reference *a;
316 struct data_reference *b;
317
318 /* A "yes/no/maybe" field for the dependence relation:
48e1416a 319
2146e26d 320 - when "ARE_DEPENDENT == NULL_TREE", there exist a dependence
321 relation between A and B, and the description of this relation
322 is given in the SUBSCRIPTS array,
48e1416a 323
2146e26d 324 - when "ARE_DEPENDENT == chrec_known", there is no dependence and
325 SUBSCRIPTS is empty,
48e1416a 326
2146e26d 327 - when "ARE_DEPENDENT == chrec_dont_know", there may be a dependence,
328 but the analyzer cannot be more specific. */
329 tree are_dependent;
48e1416a 330
f68a7726 331 /* If nonnull, COULD_BE_INDEPENDENT_P is true and the accesses are
332 independent when the runtime addresses of OBJECT_A and OBJECT_B
333 are different. The addresses of both objects are invariant in the
334 loop nest. */
335 tree object_a;
336 tree object_b;
337
2146e26d 338 /* For each subscript in the dependence test, there is an element in
339 this array. This is the attribute that labels the edge A->B of
340 the data_dependence_relation. */
f1f41a6c 341 vec<subscript_p> subscripts;
6b6f234c 342
b44d1046 343 /* The analyzed loop nest. */
f1f41a6c 344 vec<loop_p> loop_nest;
bc3c8ad4 345
6b6f234c 346 /* The classic direction vector. */
f1f41a6c 347 vec<lambda_vector> dir_vects;
6b6f234c 348
349 /* The classic distance vector. */
f1f41a6c 350 vec<lambda_vector> dist_vects;
0ecb94cf 351
352 /* Is the dependence reversed with respect to the lexicographic order? */
353 bool reversed_p;
0ac758f7 354
355 /* When the dependence relation is affine, it can be represented by
356 a distance vector. */
357 bool affine_p;
358
359 /* Set to true when the dependence relation is on the same data
360 access. */
361 bool self_reference_p;
403965f7 362
363 /* True if the dependence described is conservatively correct rather
364 than exact, and if it is still possible for the accesses to be
365 conditionally independent. For example, the a and b references in:
366
367 struct s *a, *b;
368 for (int i = 0; i < n; ++i)
369 a->f[i] += b->f[i];
370
371 conservatively have a distance vector of (0), for the case in which
372 a == b, but the accesses are independent if a != b. Similarly,
373 the a and b references in:
374
375 struct s *a, *b;
376 for (int i = 0; i < n; ++i)
377 a[0].f[i] += b[i].f[i];
378
379 conservatively have a distance vector of (0), but they are indepenent
380 when a != b + i. In contrast, the references in:
381
382 struct s *a;
383 for (int i = 0; i < n; ++i)
384 a->f[i] += a->f[i];
385
386 have the same distance vector of (0), but the accesses can never be
387 independent. */
388 bool could_be_independent_p;
2146e26d 389};
390
6b421feb 391typedef struct data_dependence_relation *ddr_p;
6b421feb 392
643e9393 393#define DDR_A(DDR) (DDR)->a
394#define DDR_B(DDR) (DDR)->b
395#define DDR_AFFINE_P(DDR) (DDR)->affine_p
396#define DDR_ARE_DEPENDENT(DDR) (DDR)->are_dependent
f68a7726 397#define DDR_OBJECT_A(DDR) (DDR)->object_a
398#define DDR_OBJECT_B(DDR) (DDR)->object_b
643e9393 399#define DDR_SUBSCRIPTS(DDR) (DDR)->subscripts
f1f41a6c 400#define DDR_SUBSCRIPT(DDR, I) DDR_SUBSCRIPTS (DDR)[I]
401#define DDR_NUM_SUBSCRIPTS(DDR) DDR_SUBSCRIPTS (DDR).length ()
b44d1046 402
643e9393 403#define DDR_LOOP_NEST(DDR) (DDR)->loop_nest
b44d1046 404/* The size of the direction/distance vectors: the number of loops in
405 the loop nest. */
f1f41a6c 406#define DDR_NB_LOOPS(DDR) (DDR_LOOP_NEST (DDR).length ())
643e9393 407#define DDR_SELF_REFERENCE(DDR) (DDR)->self_reference_p
1532ec98 408
409#define DDR_DIST_VECTS(DDR) ((DDR)->dist_vects)
410#define DDR_DIR_VECTS(DDR) ((DDR)->dir_vects)
411#define DDR_NUM_DIST_VECTS(DDR) \
f1f41a6c 412 (DDR_DIST_VECTS (DDR).length ())
1532ec98 413#define DDR_NUM_DIR_VECTS(DDR) \
f1f41a6c 414 (DDR_DIR_VECTS (DDR).length ())
1532ec98 415#define DDR_DIR_VECT(DDR, I) \
f1f41a6c 416 DDR_DIR_VECTS (DDR)[I]
1532ec98 417#define DDR_DIST_VECT(DDR, I) \
f1f41a6c 418 DDR_DIST_VECTS (DDR)[I]
643e9393 419#define DDR_REVERSED_P(DDR) (DDR)->reversed_p
403965f7 420#define DDR_COULD_BE_INDEPENDENT_P(DDR) (DDR)->could_be_independent_p
2146e26d 421
422\f
ed9370cc 423opt_result dr_analyze_innermost (innermost_loop_behavior *, tree,
2e966e2a 424 class loop *, const gimple *);
425extern bool compute_data_dependences_for_loop (class loop *, bool,
f1f41a6c 426 vec<loop_p> *,
427 vec<data_reference_p> *,
428 vec<ddr_p> *);
f1f41a6c 429extern void debug_ddrs (vec<ddr_p> );
2146e26d 430extern void dump_data_reference (FILE *, struct data_reference *);
c7d89805 431extern void debug (data_reference &ref);
432extern void debug (data_reference *ptr);
5df4cc8d 433extern void debug_data_reference (struct data_reference *);
f1f41a6c 434extern void debug_data_references (vec<data_reference_p> );
c7d89805 435extern void debug (vec<data_reference_p> &ref);
436extern void debug (vec<data_reference_p> *ptr);
b44d1046 437extern void debug_data_dependence_relation (struct data_dependence_relation *);
f1f41a6c 438extern void dump_data_dependence_relations (FILE *, vec<ddr_p> );
c7d89805 439extern void debug (vec<ddr_p> &ref);
440extern void debug (vec<ddr_p> *ptr);
f1f41a6c 441extern void debug_data_dependence_relations (vec<ddr_p> );
6b6f234c 442extern void free_dependence_relation (struct data_dependence_relation *);
f1f41a6c 443extern void free_dependence_relations (vec<ddr_p> );
801c5610 444extern void free_data_ref (data_reference_p);
f1f41a6c 445extern void free_data_refs (vec<data_reference_p> );
2e966e2a 446extern opt_result find_data_references_in_stmt (class loop *, gimple *,
ed9370cc 447 vec<data_reference_p> *);
453841f9 448extern bool graphite_find_data_references_in_stmt (edge, loop_p, gimple *,
f1f41a6c 449 vec<data_reference_p> *);
2e966e2a 450tree find_data_references_in_loop (class loop *, vec<data_reference_p> *);
fa4dba85 451bool loop_nest_has_data_refs (loop_p loop);
453841f9 452struct data_reference *create_data_ref (edge, loop_p, tree, gimple *, bool,
4f372c2c 453 bool);
2e966e2a 454extern bool find_loop_nest (class loop *, vec<loop_p> *);
16dfb112 455extern struct data_dependence_relation *initialize_data_dependence_relation
f1f41a6c 456 (struct data_reference *, struct data_reference *, vec<loop_p>);
7b6f8db4 457extern void compute_affine_dependence (struct data_dependence_relation *,
458 loop_p);
16dfb112 459extern void compute_self_dependence (struct data_dependence_relation *);
f1f41a6c 460extern bool compute_all_dependences (vec<data_reference_p> ,
461 vec<ddr_p> *,
462 vec<loop_p>, bool);
2e966e2a 463extern tree find_data_references_in_bb (class loop *, basic_block,
f1f41a6c 464 vec<data_reference_p> *);
5528b2de 465extern unsigned int dr_alignment (innermost_loop_behavior *);
469f7bc0 466extern tree get_base_for_alignment (tree, unsigned int *);
5528b2de 467
468/* Return the alignment in bytes that DR is guaranteed to have at all
469 times. */
470
471inline unsigned int
472dr_alignment (data_reference *dr)
473{
474 return dr_alignment (&DR_INNERMOST (dr));
475}
255b6be7 476
255b6be7 477extern bool dr_may_alias_p (const struct data_reference *,
2e966e2a 478 const struct data_reference *, class loop *);
ec611e12 479extern bool dr_equal_offsets_p (struct data_reference *,
480 struct data_reference *);
e1cc68bd 481
2e966e2a 482extern opt_result runtime_alias_check_p (ddr_p, class loop *, bool);
38f2f513 483extern int data_ref_compare_tree (tree, tree);
cea441fd 484extern void prune_runtime_alias_test_list (vec<dr_with_seg_len_pair_t> *,
886901f4 485 poly_uint64);
2e966e2a 486extern void create_runtime_alias_checks (class loop *,
49ce332c 487 vec<dr_with_seg_len_pair_t> *, tree*);
e85b4a5e 488extern tree dr_direction_indicator (struct data_reference *);
489extern tree dr_zero_step_indicator (struct data_reference *);
490extern bool dr_known_forward_stride_p (struct data_reference *);
491
e1cc68bd 492/* Return true when the base objects of data references A and B are
493 the same memory object. */
494
495static inline bool
496same_data_refs_base_objects (data_reference_p a, data_reference_p b)
497{
498 return DR_NUM_DIMENSIONS (a) == DR_NUM_DIMENSIONS (b)
499 && operand_equal_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b), 0);
500}
501
502/* Return true when the data references A and B are accessing the same
503 memory object with the same access functions. */
504
505static inline bool
506same_data_refs (data_reference_p a, data_reference_p b)
507{
508 unsigned int i;
509
510 /* The references are exactly the same. */
511 if (operand_equal_p (DR_REF (a), DR_REF (b), 0))
512 return true;
513
514 if (!same_data_refs_base_objects (a, b))
515 return false;
516
517 for (i = 0; i < DR_NUM_DIMENSIONS (a); i++)
518 if (!eq_evolutions_p (DR_ACCESS_FN (a, i), DR_ACCESS_FN (b, i)))
519 return false;
520
521 return true;
522}
523
15c8650d 524/* Returns true when all the dependences are computable. */
525
526inline bool
527known_dependences_p (vec<ddr_p> dependence_relations)
528{
529 ddr_p ddr;
530 unsigned int i;
531
532 FOR_EACH_VEC_ELT (dependence_relations, i, ddr)
533 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know)
534 return false;
535
536 return true;
537}
538
e01f9f1f 539/* Returns the dependence level for a vector DIST of size LENGTH.
540 LEVEL = 0 means a lexicographic dependence, i.e. a dependence due
541 to the sequence of statements, not carried by any loop. */
542
543static inline unsigned
544dependence_level (lambda_vector dist_vect, int length)
545{
546 int i;
547
548 for (i = 0; i < length; i++)
549 if (dist_vect[i] != 0)
550 return i + 1;
551
552 return 0;
553}
554
801c5610 555/* Return the dependence level for the DDR relation. */
556
557static inline unsigned
558ddr_dependence_level (ddr_p ddr)
559{
560 unsigned vector;
561 unsigned level = 0;
562
f1f41a6c 563 if (DDR_DIST_VECTS (ddr).exists ())
801c5610 564 level = dependence_level (DDR_DIST_VECT (ddr, 0), DDR_NB_LOOPS (ddr));
565
566 for (vector = 1; vector < DDR_NUM_DIST_VECTS (ddr); vector++)
567 level = MIN (level, dependence_level (DDR_DIST_VECT (ddr, vector),
568 DDR_NB_LOOPS (ddr)));
569 return level;
570}
571
b44d1046 572/* Return the index of the variable VAR in the LOOP_NEST array. */
573
574static inline int
f1f41a6c 575index_in_loop_nest (int var, vec<loop_p> loop_nest)
b44d1046 576{
2e966e2a 577 class loop *loopi;
b44d1046 578 int var_index;
579
2199e93e 580 for (var_index = 0; loop_nest.iterate (var_index, &loopi); var_index++)
b44d1046 581 if (loopi->num == var)
2199e93e 582 return var_index;
b44d1046 583
2199e93e 584 gcc_unreachable ();
b44d1046 585}
586
6198d968 587/* Returns true when the data reference DR the form "A[i] = ..."
588 with a stride equal to its unit type size. */
1c4f9959 589
590static inline bool
f689d33d 591adjacent_dr_p (struct data_reference *dr)
1c4f9959 592{
6198d968 593 /* If this is a bitfield store bail out. */
594 if (TREE_CODE (DR_REF (dr)) == COMPONENT_REF
595 && DECL_BIT_FIELD (TREE_OPERAND (DR_REF (dr), 1)))
596 return false;
597
598 if (!DR_STEP (dr)
599 || TREE_CODE (DR_STEP (dr)) != INTEGER_CST)
600 return false;
601
602 return tree_int_cst_equal (fold_unary (ABS_EXPR, TREE_TYPE (DR_STEP (dr)),
603 DR_STEP (dr)),
604 TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr))));
1c4f9959 605}
606
b0eb8c66 607void split_constant_offset (tree , tree *, tree *);
608
e01f9f1f 609/* Compute the greatest common divisor of a VECTOR of SIZE numbers. */
610
7652827d 611static inline lambda_int
e01f9f1f 612lambda_vector_gcd (lambda_vector vector, int size)
613{
614 int i;
7652827d 615 lambda_int gcd1 = 0;
e01f9f1f 616
617 if (size > 0)
618 {
619 gcd1 = vector[0];
620 for (i = 1; i < size; i++)
621 gcd1 = gcd (gcd1, vector[i]);
622 }
623 return gcd1;
624}
625
626/* Allocate a new vector of given SIZE. */
627
628static inline lambda_vector
629lambda_vector_new (int size)
630{
eb352584 631 /* ??? We shouldn't abuse the GC allocator here. */
7652827d 632 return ggc_cleared_vec_alloc<lambda_int> (size);
e01f9f1f 633}
634
635/* Clear out vector VEC1 of length SIZE. */
636
637static inline void
638lambda_vector_clear (lambda_vector vec1, int size)
639{
640 memset (vec1, 0, size * sizeof (*vec1));
641}
642
643/* Returns true when the vector V is lexicographically positive, in
644 other words, when the first nonzero element is positive. */
645
646static inline bool
647lambda_vector_lexico_pos (lambda_vector v,
648 unsigned n)
649{
650 unsigned i;
651 for (i = 0; i < n; i++)
652 {
653 if (v[i] == 0)
654 continue;
655 if (v[i] < 0)
656 return false;
657 if (v[i] > 0)
658 return true;
659 }
660 return true;
661}
662
663/* Return true if vector VEC1 of length SIZE is the zero vector. */
664
665static inline bool
666lambda_vector_zerop (lambda_vector vec1, int size)
667{
668 int i;
669 for (i = 0; i < size; i++)
670 if (vec1[i] != 0)
671 return false;
672 return true;
673}
674
675/* Allocate a matrix of M rows x N cols. */
676
677static inline lambda_matrix
678lambda_matrix_new (int m, int n, struct obstack *lambda_obstack)
679{
680 lambda_matrix mat;
681 int i;
682
eb352584 683 mat = XOBNEWVEC (lambda_obstack, lambda_vector, m);
e01f9f1f 684
685 for (i = 0; i < m; i++)
7652827d 686 mat[i] = XOBNEWVEC (lambda_obstack, lambda_int, n);
e01f9f1f 687
688 return mat;
689}
690
2146e26d 691#endif /* GCC_TREE_DATA_REF_H */