tree-data-ref.h 25 KB

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