]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/tree-data-ref.h
Update copyright years.
[thirdparty/gcc.git] / gcc / tree-data-ref.h
CommitLineData
b8698a0f 1/* Data references and dependences detectors.
99dee823 2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
0ff4040e 3 Contributed by Sebastian Pop <pop@cri.ensmp.fr>
56cf8686
SP
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
56cf8686
SP
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
56cf8686
SP
20
21#ifndef GCC_TREE_DATA_REF_H
22#define GCC_TREE_DATA_REF_H
23
3a796c6f 24#include "graphds.h"
dea61d92 25#include "tree-chrec.h"
f4ebbd24 26#include "opt-problem.h"
36d59cf7 27
98b44b0e 28/*
3cb960c7
ZD
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
b8698a0f
L
33 constant offset (INIT). Examples, in loop nest
34
3cb960c7
ZD
35 for (i = 0; i < 100; i++)
36 for (j = 3; j < 100; j++)
98b44b0e 37
86a07404 38 Example 1 Example 2
3cb960c7 39 data-ref a[j].b[i][j] *(p + x + 16B + 4B * j)
b8698a0f 40
dea61d92 41
3cb960c7
ZD
42 innermost_loop_behavior
43 base_address &a p
44 offset i * D_i x
45 init 3 * D_j + offsetof (b) 28
86a07404 46 step D_j 4
86a07404 47
98b44b0e 48 */
3cb960c7 49struct innermost_loop_behavior
86a07404
IR
50{
51 tree base_address;
52 tree offset;
53 tree init;
54 tree step;
3cb960c7 55
bb642979
RS
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
e054a185
RS
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;
832b4117
RS
96
97 /* Likewise for STEP. */
98 unsigned int step_alignment;
86a07404
IR
99};
100
3cb960c7 101/* Describes the evolutions of indices of the memory reference. The indices
c4ddde1b
RG
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)
3cb960c7 111 indices: {j_0, +, 1}_2 {16, +, 4}_2
c4ddde1b 112 4
3cb960c7
ZD
113 {i_0, +, 1}_1
114 {j_0, +, 1}_2
115*/
116
117struct indices
86a07404
IR
118{
119 /* The object. */
120 tree base_object;
b8698a0f 121
3cb960c7 122 /* A list of chrecs. Access functions of the indices. */
9771b263 123 vec<tree> access_fns;
f3ae4add
RB
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;
86a07404
IR
128};
129
3cb960c7
ZD
130struct dr_alias
131{
132 /* The alias information that should be used for new pointers to this
c4ddde1b 133 location. */
3cb960c7 134 struct ptr_info_def *ptr_info;
86a07404
IR
135};
136
b305e3da
SP
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. */
1c8badf6
RB
141typedef HOST_WIDE_INT lambda_int;
142typedef lambda_int *lambda_vector;
b305e3da
SP
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
9f275479 148
9f275479 149
36d59cf7 150struct data_reference
56cf8686 151{
56cf8686 152 /* A pointer to the statement that contains this DR. */
355fe088 153 gimple *stmt;
b8698a0f 154
3cb960c7 155 /* A pointer to the memory reference. */
56cf8686
SP
156 tree ref;
157
56cf8686 158 /* Auxiliary info specific to a pass. */
5417e022 159 void *aux;
56cf8686
SP
160
161 /* True when the data reference is in RHS of a stmt. */
162 bool is_read;
163
62c8a2cf
RS
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
3cb960c7
ZD
169 /* Behavior of the memory reference in the innermost loop. */
170 struct innermost_loop_behavior innermost;
86a07404 171
f8bf9252 172 /* Subscripts of this data reference. */
3cb960c7 173 struct indices indices;
86a07404 174
3cb960c7
ZD
175 /* Alias information for the data reference. */
176 struct dr_alias alias;
9f275479 177};
ebf78a47 178
86a07404
IR
179#define DR_STMT(DR) (DR)->stmt
180#define DR_REF(DR) (DR)->ref
3cb960c7 181#define DR_BASE_OBJECT(DR) (DR)->indices.base_object
f3ae4add 182#define DR_UNCONSTRAINED_BASE(DR) (DR)->indices.unconstrained_base
3cb960c7 183#define DR_ACCESS_FNS(DR) (DR)->indices.access_fns
9771b263
DN
184#define DR_ACCESS_FN(DR, I) DR_ACCESS_FNS (DR)[I]
185#define DR_NUM_DIMENSIONS(DR) DR_ACCESS_FNS (DR).length ()
86a07404 186#define DR_IS_READ(DR) (DR)->is_read
b0af49c4 187#define DR_IS_WRITE(DR) (!DR_IS_READ (DR))
62c8a2cf 188#define DR_IS_CONDITIONAL_IN_STMT(DR) (DR)->is_conditional_in_stmt
3cb960c7
ZD
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
3cb960c7 193#define DR_PTR_INFO(DR) (DR)->alias.ptr_info
bb642979
RS
194#define DR_BASE_ALIGNMENT(DR) (DR)->innermost.base_alignment
195#define DR_BASE_MISALIGNMENT(DR) (DR)->innermost.base_misalignment
e054a185 196#define DR_OFFSET_ALIGNMENT(DR) (DR)->innermost.offset_alignment
832b4117 197#define DR_STEP_ALIGNMENT(DR) (DR)->innermost.step_alignment
fad08d12 198#define DR_INNERMOST(DR) (DR)->innermost
9f275479
JS
199
200typedef struct data_reference *data_reference_p;
56cf8686 201
8d44cf72
BC
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
6c1dae73 206class dr_with_seg_len
8d44cf72 207{
6c1dae73 208public:
a57776a1
RS
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) {}
8d44cf72
BC
212
213 data_reference_p dr;
a57776a1
RS
214 /* The offset of the last access that needs to be checked minus
215 the offset of the first. */
8d44cf72 216 tree seg_len;
a57776a1
RS
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;
8d44cf72
BC
223};
224
e9acf80c
RS
225/* Flags that describe a potential alias between two dr_with_seg_lens.
226 In general, each pair of dr_with_seg_lens represents a composite of
227 multiple access pairs P, so testing flags like DR_IS_READ on the DRs
228 does not give meaningful information.
229
230 DR_ALIAS_RAW:
231 There is a pair in P for which the second reference is a read
232 and the first is a write.
233
234 DR_ALIAS_WAR:
235 There is a pair in P for which the second reference is a write
236 and the first is a read.
237
238 DR_ALIAS_WAW:
239 There is a pair in P for which both references are writes.
240
241 DR_ALIAS_ARBITRARY:
242 Either
243 (a) it isn't possible to classify one pair in P as RAW, WAW or WAR; or
244 (b) there is a pair in P that breaks the ordering assumption below.
245
246 This flag overrides the RAW, WAR and WAW flags above.
247
248 DR_ALIAS_UNSWAPPED:
249 DR_ALIAS_SWAPPED:
250 Temporary flags that indicate whether there is a pair P whose
251 DRs have or haven't been swapped around.
252
52c29905
RS
253 DR_ALIAS_MIXED_STEPS:
254 The DR_STEP for one of the data references in the pair does not
255 accurately describe that reference for all members of P. (Note
256 that the flag does not say anything about whether the DR_STEPs
257 of the two references in the pair are the same.)
258
e9acf80c
RS
259 The ordering assumption mentioned above is that for every pair
260 (DR_A, DR_B) in P:
261
262 (1) The original code accesses n elements for DR_A and n elements for DR_B,
263 interleaved as follows:
264
265 one access of size DR_A.access_size at DR_A.dr
266 one access of size DR_B.access_size at DR_B.dr
267 one access of size DR_A.access_size at DR_A.dr + STEP_A
268 one access of size DR_B.access_size at DR_B.dr + STEP_B
269 one access of size DR_A.access_size at DR_A.dr + STEP_A * 2
270 one access of size DR_B.access_size at DR_B.dr + STEP_B * 2
271 ...
272
273 (2) The new code accesses the same data in exactly two chunks:
274
275 one group of accesses spanning |DR_A.seg_len| + DR_A.access_size
276 one group of accesses spanning |DR_B.seg_len| + DR_B.access_size
277
278 A pair might break this assumption if the DR_A and DR_B accesses
279 in the original or the new code are mingled in some way. For example,
280 if DR_A.access_size represents the effect of two individual writes
281 to nearby locations, the pair breaks the assumption if those writes
282 occur either side of the access for DR_B.
283
284 Note that DR_ALIAS_ARBITRARY describes whether the ordering assumption
285 fails to hold for any individual pair in P. If the assumption *does*
286 hold for every pair in P, it doesn't matter whether it holds for the
287 composite pair or not. In other words, P should represent the complete
288 set of pairs that the composite pair is testing, so only the ordering
289 of two accesses in the same member of P matters. */
290const unsigned int DR_ALIAS_RAW = 1U << 0;
291const unsigned int DR_ALIAS_WAR = 1U << 1;
292const unsigned int DR_ALIAS_WAW = 1U << 2;
293const unsigned int DR_ALIAS_ARBITRARY = 1U << 3;
294const unsigned int DR_ALIAS_SWAPPED = 1U << 4;
295const unsigned int DR_ALIAS_UNSWAPPED = 1U << 5;
52c29905 296const unsigned int DR_ALIAS_MIXED_STEPS = 1U << 6;
e9acf80c 297
8d44cf72
BC
298/* This struct contains two dr_with_seg_len objects with aliasing data
299 refs. Two comparisons are generated from them. */
300
6c1dae73 301class dr_with_seg_len_pair_t
8d44cf72 302{
6c1dae73 303public:
e9acf80c
RS
304 /* WELL_ORDERED indicates that the ordering assumption described above
305 DR_ALIAS_ARBITRARY holds. REORDERED indicates that it doesn't. */
306 enum sequencing { WELL_ORDERED, REORDERED };
307
308 dr_with_seg_len_pair_t (const dr_with_seg_len &,
309 const dr_with_seg_len &, sequencing);
8d44cf72
BC
310
311 dr_with_seg_len first;
312 dr_with_seg_len second;
e9acf80c 313 unsigned int flags;
8d44cf72
BC
314};
315
e9acf80c
RS
316inline dr_with_seg_len_pair_t::
317dr_with_seg_len_pair_t (const dr_with_seg_len &d1, const dr_with_seg_len &d2,
318 sequencing seq)
319 : first (d1), second (d2), flags (0)
320{
321 if (DR_IS_READ (d1.dr) && DR_IS_WRITE (d2.dr))
322 flags |= DR_ALIAS_WAR;
323 else if (DR_IS_WRITE (d1.dr) && DR_IS_READ (d2.dr))
324 flags |= DR_ALIAS_RAW;
325 else if (DR_IS_WRITE (d1.dr) && DR_IS_WRITE (d2.dr))
326 flags |= DR_ALIAS_WAW;
327 else
328 gcc_unreachable ();
329 if (seq == REORDERED)
330 flags |= DR_ALIAS_ARBITRARY;
331}
332
56cf8686 333enum data_dependence_direction {
b8698a0f
L
334 dir_positive,
335 dir_negative,
336 dir_equal,
56cf8686
SP
337 dir_positive_or_negative,
338 dir_positive_or_equal,
339 dir_negative_or_equal,
340 dir_star,
341 dir_independent
342};
343
d93817c4
ZD
344/* The description of the grid of iterations that overlap. At most
345 two loops are considered at the same time just now, hence at most
346 two functions are needed. For each of the functions, we store
347 the vector of coefficients, f[0] + x * f[1] + y * f[2] + ...,
348 where x, y, ... are variables. */
349
350#define MAX_DIM 2
351
352/* Special values of N. */
353#define NO_DEPENDENCE 0
354#define NOT_KNOWN (MAX_DIM + 1)
355#define CF_NONTRIVIAL_P(CF) ((CF)->n != NO_DEPENDENCE && (CF)->n != NOT_KNOWN)
356#define CF_NOT_KNOWN_P(CF) ((CF)->n == NOT_KNOWN)
357#define CF_NO_DEPENDENCE_P(CF) ((CF)->n == NO_DEPENDENCE)
358
9771b263 359typedef vec<tree> affine_fn;
d93817c4 360
84562394 361struct conflict_function
d93817c4
ZD
362{
363 unsigned n;
364 affine_fn fns[MAX_DIM];
84562394 365};
d93817c4 366
56cf8686
SP
367/* What is a subscript? Given two array accesses a subscript is the
368 tuple composed of the access functions for a given dimension.
369 Example: Given A[f1][f2][f3] and B[g1][g2][g3], there are three
370 subscripts: (f1, g1), (f2, g2), (f3, g3). These three subscripts
371 are stored in the data_dependence_relation structure under the form
372 of an array of subscripts. */
373
36d59cf7 374struct subscript
56cf8686 375{
dfbddbeb
RS
376 /* The access functions of the two references. */
377 tree access_fn[2];
378
56cf8686
SP
379 /* A description of the iterations for which the elements are
380 accessed twice. */
d93817c4
ZD
381 conflict_function *conflicting_iterations_in_a;
382 conflict_function *conflicting_iterations_in_b;
b8698a0f 383
86df10e3 384 /* This field stores the information about the iteration domain
56cf8686 385 validity of the dependence relation. */
86df10e3 386 tree last_conflict;
b8698a0f 387
56cf8686
SP
388 /* Distance from the iteration that access a conflicting element in
389 A to the iteration that access this same conflicting element in
89dbed81 390 B. The distance is a tree scalar expression, i.e. a constant or a
56cf8686
SP
391 symbolic expression, but certainly not a chrec function. */
392 tree distance;
56cf8686
SP
393};
394
ebf78a47 395typedef struct subscript *subscript_p;
ebf78a47 396
dfbddbeb 397#define SUB_ACCESS_FN(SUB, I) (SUB)->access_fn[I]
45d93414
RS
398#define SUB_CONFLICTS_IN_A(SUB) (SUB)->conflicting_iterations_in_a
399#define SUB_CONFLICTS_IN_B(SUB) (SUB)->conflicting_iterations_in_b
400#define SUB_LAST_CONFLICT(SUB) (SUB)->last_conflict
401#define SUB_DISTANCE(SUB) (SUB)->distance
56cf8686
SP
402
403/* A data_dependence_relation represents a relation between two
404 data_references A and B. */
405
36d59cf7 406struct data_dependence_relation
56cf8686 407{
b8698a0f 408
56cf8686
SP
409 struct data_reference *a;
410 struct data_reference *b;
411
412 /* A "yes/no/maybe" field for the dependence relation:
b8698a0f 413
56cf8686
SP
414 - when "ARE_DEPENDENT == NULL_TREE", there exist a dependence
415 relation between A and B, and the description of this relation
416 is given in the SUBSCRIPTS array,
b8698a0f 417
56cf8686
SP
418 - when "ARE_DEPENDENT == chrec_known", there is no dependence and
419 SUBSCRIPTS is empty,
b8698a0f 420
56cf8686
SP
421 - when "ARE_DEPENDENT == chrec_dont_know", there may be a dependence,
422 but the analyzer cannot be more specific. */
423 tree are_dependent;
b8698a0f 424
9adee305
RS
425 /* If nonnull, COULD_BE_INDEPENDENT_P is true and the accesses are
426 independent when the runtime addresses of OBJECT_A and OBJECT_B
427 are different. The addresses of both objects are invariant in the
428 loop nest. */
429 tree object_a;
430 tree object_b;
431
56cf8686
SP
432 /* For each subscript in the dependence test, there is an element in
433 this array. This is the attribute that labels the edge A->B of
434 the data_dependence_relation. */
9771b263 435 vec<subscript_p> subscripts;
36d59cf7 436
ba42e045 437 /* The analyzed loop nest. */
9771b263 438 vec<loop_p> loop_nest;
86df10e3 439
36d59cf7 440 /* The classic direction vector. */
9771b263 441 vec<lambda_vector> dir_vects;
36d59cf7
DB
442
443 /* The classic distance vector. */
9771b263 444 vec<lambda_vector> dist_vects;
71d5b5e1
SP
445
446 /* Is the dependence reversed with respect to the lexicographic order? */
447 bool reversed_p;
8f5929e1
JJ
448
449 /* When the dependence relation is affine, it can be represented by
450 a distance vector. */
451 bool affine_p;
452
453 /* Set to true when the dependence relation is on the same data
454 access. */
455 bool self_reference_p;
dfbddbeb
RS
456
457 /* True if the dependence described is conservatively correct rather
458 than exact, and if it is still possible for the accesses to be
459 conditionally independent. For example, the a and b references in:
460
461 struct s *a, *b;
462 for (int i = 0; i < n; ++i)
463 a->f[i] += b->f[i];
464
465 conservatively have a distance vector of (0), for the case in which
466 a == b, but the accesses are independent if a != b. Similarly,
467 the a and b references in:
468
469 struct s *a, *b;
470 for (int i = 0; i < n; ++i)
471 a[0].f[i] += b[i].f[i];
472
473 conservatively have a distance vector of (0), but they are indepenent
474 when a != b + i. In contrast, the references in:
475
476 struct s *a;
477 for (int i = 0; i < n; ++i)
478 a->f[i] += a->f[i];
479
480 have the same distance vector of (0), but the accesses can never be
481 independent. */
482 bool could_be_independent_p;
56cf8686
SP
483};
484
0ff4040e 485typedef struct data_dependence_relation *ddr_p;
0ff4040e 486
45d93414
RS
487#define DDR_A(DDR) (DDR)->a
488#define DDR_B(DDR) (DDR)->b
489#define DDR_AFFINE_P(DDR) (DDR)->affine_p
490#define DDR_ARE_DEPENDENT(DDR) (DDR)->are_dependent
9adee305
RS
491#define DDR_OBJECT_A(DDR) (DDR)->object_a
492#define DDR_OBJECT_B(DDR) (DDR)->object_b
45d93414 493#define DDR_SUBSCRIPTS(DDR) (DDR)->subscripts
9771b263
DN
494#define DDR_SUBSCRIPT(DDR, I) DDR_SUBSCRIPTS (DDR)[I]
495#define DDR_NUM_SUBSCRIPTS(DDR) DDR_SUBSCRIPTS (DDR).length ()
ba42e045 496
45d93414 497#define DDR_LOOP_NEST(DDR) (DDR)->loop_nest
ba42e045
SP
498/* The size of the direction/distance vectors: the number of loops in
499 the loop nest. */
9771b263 500#define DDR_NB_LOOPS(DDR) (DDR_LOOP_NEST (DDR).length ())
45d93414 501#define DDR_SELF_REFERENCE(DDR) (DDR)->self_reference_p
304afda6
SP
502
503#define DDR_DIST_VECTS(DDR) ((DDR)->dist_vects)
504#define DDR_DIR_VECTS(DDR) ((DDR)->dir_vects)
505#define DDR_NUM_DIST_VECTS(DDR) \
9771b263 506 (DDR_DIST_VECTS (DDR).length ())
304afda6 507#define DDR_NUM_DIR_VECTS(DDR) \
9771b263 508 (DDR_DIR_VECTS (DDR).length ())
304afda6 509#define DDR_DIR_VECT(DDR, I) \
9771b263 510 DDR_DIR_VECTS (DDR)[I]
304afda6 511#define DDR_DIST_VECT(DDR, I) \
9771b263 512 DDR_DIST_VECTS (DDR)[I]
45d93414 513#define DDR_REVERSED_P(DDR) (DDR)->reversed_p
dfbddbeb 514#define DDR_COULD_BE_INDEPENDENT_P(DDR) (DDR)->could_be_independent_p
56cf8686
SP
515
516\f
f4ebbd24 517opt_result dr_analyze_innermost (innermost_loop_behavior *, tree,
99b1c316
MS
518 class loop *, const gimple *);
519extern bool compute_data_dependences_for_loop (class loop *, bool,
9771b263
DN
520 vec<loop_p> *,
521 vec<data_reference_p> *,
522 vec<ddr_p> *);
9771b263 523extern void debug_ddrs (vec<ddr_p> );
56cf8686 524extern void dump_data_reference (FILE *, struct data_reference *);
7b3b6ae4
LC
525extern void debug (data_reference &ref);
526extern void debug (data_reference *ptr);
a37d995a 527extern void debug_data_reference (struct data_reference *);
9771b263 528extern void debug_data_references (vec<data_reference_p> );
7b3b6ae4
LC
529extern void debug (vec<data_reference_p> &ref);
530extern void debug (vec<data_reference_p> *ptr);
ba42e045 531extern void debug_data_dependence_relation (struct data_dependence_relation *);
9771b263 532extern void dump_data_dependence_relations (FILE *, vec<ddr_p> );
7b3b6ae4
LC
533extern void debug (vec<ddr_p> &ref);
534extern void debug (vec<ddr_p> *ptr);
9771b263 535extern void debug_data_dependence_relations (vec<ddr_p> );
36d59cf7 536extern void free_dependence_relation (struct data_dependence_relation *);
9771b263 537extern void free_dependence_relations (vec<ddr_p> );
dea61d92 538extern void free_data_ref (data_reference_p);
9771b263 539extern void free_data_refs (vec<data_reference_p> );
99b1c316 540extern opt_result find_data_references_in_stmt (class loop *, gimple *,
f4ebbd24 541 vec<data_reference_p> *);
a68f286c 542extern bool graphite_find_data_references_in_stmt (edge, loop_p, gimple *,
9771b263 543 vec<data_reference_p> *);
99b1c316 544tree find_data_references_in_loop (class loop *, vec<data_reference_p> *);
74032f47 545bool loop_nest_has_data_refs (loop_p loop);
a68f286c 546struct data_reference *create_data_ref (edge, loop_p, tree, gimple *, bool,
62c8a2cf 547 bool);
99b1c316 548extern bool find_loop_nest (class loop *, vec<loop_p> *);
aec7ae7d 549extern struct data_dependence_relation *initialize_data_dependence_relation
9771b263 550 (struct data_reference *, struct data_reference *, vec<loop_p>);
f20132e7
RG
551extern void compute_affine_dependence (struct data_dependence_relation *,
552 loop_p);
aec7ae7d 553extern void compute_self_dependence (struct data_dependence_relation *);
9771b263
DN
554extern bool compute_all_dependences (vec<data_reference_p> ,
555 vec<ddr_p> *,
556 vec<loop_p>, bool);
99b1c316 557extern tree find_data_references_in_bb (class loop *, basic_block,
9771b263 558 vec<data_reference_p> *);
25f68d90 559extern unsigned int dr_alignment (innermost_loop_behavior *);
a199d5e7 560extern tree get_base_for_alignment (tree, unsigned int *);
25f68d90
RS
561
562/* Return the alignment in bytes that DR is guaranteed to have at all
563 times. */
564
565inline unsigned int
566dr_alignment (data_reference *dr)
567{
568 return dr_alignment (&DR_INNERMOST (dr));
569}
f8bf9252 570
f8bf9252 571extern bool dr_may_alias_p (const struct data_reference *,
99b1c316 572 const struct data_reference *, class loop *);
bfe068c3
IR
573extern bool dr_equal_offsets_p (struct data_reference *,
574 struct data_reference *);
e1fd038a 575
99b1c316 576extern opt_result runtime_alias_check_p (ddr_p, class loop *, bool);
2c8f03ad 577extern int data_ref_compare_tree (tree, tree);
8d44cf72 578extern void prune_runtime_alias_test_list (vec<dr_with_seg_len_pair_t> *,
079b4a9c 579 poly_uint64);
99b1c316 580extern void create_runtime_alias_checks (class loop *,
9cbd2d97 581 vec<dr_with_seg_len_pair_t> *, tree*);
a57776a1
RS
582extern tree dr_direction_indicator (struct data_reference *);
583extern tree dr_zero_step_indicator (struct data_reference *);
584extern bool dr_known_forward_stride_p (struct data_reference *);
585
e1fd038a
SP
586/* Return true when the base objects of data references A and B are
587 the same memory object. */
588
589static inline bool
590same_data_refs_base_objects (data_reference_p a, data_reference_p b)
591{
592 return DR_NUM_DIMENSIONS (a) == DR_NUM_DIMENSIONS (b)
593 && operand_equal_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b), 0);
594}
595
596/* Return true when the data references A and B are accessing the same
597 memory object with the same access functions. */
598
599static inline bool
600same_data_refs (data_reference_p a, data_reference_p b)
601{
602 unsigned int i;
603
604 /* The references are exactly the same. */
605 if (operand_equal_p (DR_REF (a), DR_REF (b), 0))
606 return true;
607
608 if (!same_data_refs_base_objects (a, b))
609 return false;
610
611 for (i = 0; i < DR_NUM_DIMENSIONS (a); i++)
612 if (!eq_evolutions_p (DR_ACCESS_FN (a, i), DR_ACCESS_FN (b, i)))
613 return false;
614
615 return true;
616}
617
2fd5894f
RB
618/* Returns true when all the dependences are computable. */
619
620inline bool
621known_dependences_p (vec<ddr_p> dependence_relations)
622{
623 ddr_p ddr;
624 unsigned int i;
625
626 FOR_EACH_VEC_ELT (dependence_relations, i, ddr)
627 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know)
628 return false;
629
630 return true;
631}
632
b305e3da
SP
633/* Returns the dependence level for a vector DIST of size LENGTH.
634 LEVEL = 0 means a lexicographic dependence, i.e. a dependence due
635 to the sequence of statements, not carried by any loop. */
636
637static inline unsigned
638dependence_level (lambda_vector dist_vect, int length)
639{
640 int i;
641
642 for (i = 0; i < length; i++)
643 if (dist_vect[i] != 0)
644 return i + 1;
645
646 return 0;
647}
648
dea61d92
SP
649/* Return the dependence level for the DDR relation. */
650
651static inline unsigned
652ddr_dependence_level (ddr_p ddr)
653{
654 unsigned vector;
655 unsigned level = 0;
656
9771b263 657 if (DDR_DIST_VECTS (ddr).exists ())
dea61d92
SP
658 level = dependence_level (DDR_DIST_VECT (ddr, 0), DDR_NB_LOOPS (ddr));
659
660 for (vector = 1; vector < DDR_NUM_DIST_VECTS (ddr); vector++)
661 level = MIN (level, dependence_level (DDR_DIST_VECT (ddr, vector),
662 DDR_NB_LOOPS (ddr)));
663 return level;
664}
665
ba42e045
SP
666/* Return the index of the variable VAR in the LOOP_NEST array. */
667
668static inline int
9771b263 669index_in_loop_nest (int var, vec<loop_p> loop_nest)
ba42e045 670{
99b1c316 671 class loop *loopi;
ba42e045
SP
672 int var_index;
673
d6366157 674 for (var_index = 0; loop_nest.iterate (var_index, &loopi); var_index++)
ba42e045 675 if (loopi->num == var)
d6366157 676 return var_index;
ba42e045 677
d6366157 678 gcc_unreachable ();
ba42e045
SP
679}
680
be6b029b
RG
681/* Returns true when the data reference DR the form "A[i] = ..."
682 with a stride equal to its unit type size. */
5e37ea0e
SP
683
684static inline bool
d0582dc1 685adjacent_dr_p (struct data_reference *dr)
5e37ea0e 686{
be6b029b
RG
687 /* If this is a bitfield store bail out. */
688 if (TREE_CODE (DR_REF (dr)) == COMPONENT_REF
689 && DECL_BIT_FIELD (TREE_OPERAND (DR_REF (dr), 1)))
690 return false;
691
692 if (!DR_STEP (dr)
693 || TREE_CODE (DR_STEP (dr)) != INTEGER_CST)
694 return false;
695
696 return tree_int_cst_equal (fold_unary (ABS_EXPR, TREE_TYPE (DR_STEP (dr)),
697 DR_STEP (dr)),
698 TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr))));
5e37ea0e
SP
699}
700
468c2ac0
DN
701void split_constant_offset (tree , tree *, tree *);
702
b305e3da
SP
703/* Compute the greatest common divisor of a VECTOR of SIZE numbers. */
704
1c8badf6 705static inline lambda_int
b305e3da
SP
706lambda_vector_gcd (lambda_vector vector, int size)
707{
708 int i;
1c8badf6 709 lambda_int gcd1 = 0;
b305e3da
SP
710
711 if (size > 0)
712 {
713 gcd1 = vector[0];
714 for (i = 1; i < size; i++)
715 gcd1 = gcd (gcd1, vector[i]);
716 }
717 return gcd1;
718}
719
720/* Allocate a new vector of given SIZE. */
721
722static inline lambda_vector
723lambda_vector_new (int size)
724{
6f4f1a50 725 /* ??? We shouldn't abuse the GC allocator here. */
1c8badf6 726 return ggc_cleared_vec_alloc<lambda_int> (size);
b305e3da
SP
727}
728
729/* Clear out vector VEC1 of length SIZE. */
730
731static inline void
732lambda_vector_clear (lambda_vector vec1, int size)
733{
734 memset (vec1, 0, size * sizeof (*vec1));
735}
736
737/* Returns true when the vector V is lexicographically positive, in
738 other words, when the first nonzero element is positive. */
739
740static inline bool
741lambda_vector_lexico_pos (lambda_vector v,
742 unsigned n)
743{
744 unsigned i;
745 for (i = 0; i < n; i++)
746 {
747 if (v[i] == 0)
748 continue;
749 if (v[i] < 0)
750 return false;
751 if (v[i] > 0)
752 return true;
753 }
754 return true;
755}
756
757/* Return true if vector VEC1 of length SIZE is the zero vector. */
758
759static inline bool
760lambda_vector_zerop (lambda_vector vec1, int size)
761{
762 int i;
763 for (i = 0; i < size; i++)
764 if (vec1[i] != 0)
765 return false;
766 return true;
767}
768
769/* Allocate a matrix of M rows x N cols. */
770
771static inline lambda_matrix
772lambda_matrix_new (int m, int n, struct obstack *lambda_obstack)
773{
774 lambda_matrix mat;
775 int i;
776
6f4f1a50 777 mat = XOBNEWVEC (lambda_obstack, lambda_vector, m);
b305e3da
SP
778
779 for (i = 0; i < m; i++)
1c8badf6 780 mat[i] = XOBNEWVEC (lambda_obstack, lambda_int, n);
b305e3da
SP
781
782 return mat;
783}
784
56cf8686 785#endif /* GCC_TREE_DATA_REF_H */