Mercurial > hg > CbC > CbC_gcc
comparison gcc/tree-data-ref.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
19 along with GCC; see the file COPYING3. If not see | 19 along with GCC; see the file COPYING3. If not see |
20 <http://www.gnu.org/licenses/>. */ | 20 <http://www.gnu.org/licenses/>. */ |
21 | 21 |
22 /* This pass walks a given loop structure searching for array | 22 /* This pass walks a given loop structure searching for array |
23 references. The information about the array accesses is recorded | 23 references. The information about the array accesses is recorded |
24 in DATA_REFERENCE structures. | 24 in DATA_REFERENCE structures. |
25 | 25 |
26 The basic test for determining the dependences is: | 26 The basic test for determining the dependences is: |
27 given two access functions chrec1 and chrec2 to a same array, and | 27 given two access functions chrec1 and chrec2 to a same array, and |
28 x and y two vectors from the iteration domain, the same element of | 28 x and y two vectors from the iteration domain, the same element of |
29 the array is accessed twice at iterations x and y if and only if: | 29 the array is accessed twice at iterations x and y if and only if: |
30 | chrec1 (x) == chrec2 (y). | 30 | chrec1 (x) == chrec2 (y). |
31 | 31 |
32 The goals of this analysis are: | 32 The goals of this analysis are: |
33 | 33 |
34 - to determine the independence: the relation between two | 34 - to determine the independence: the relation between two |
35 independent accesses is qualified with the chrec_known (this | 35 independent accesses is qualified with the chrec_known (this |
36 information allows a loop parallelization), | 36 information allows a loop parallelization), |
37 | 37 |
38 - when two data references access the same data, to qualify the | 38 - when two data references access the same data, to qualify the |
39 dependence relation with classic dependence representations: | 39 dependence relation with classic dependence representations: |
40 | 40 |
41 - distance vectors | 41 - distance vectors |
42 - direction vectors | 42 - direction vectors |
43 - loop carried level dependence | 43 - loop carried level dependence |
44 - polyhedron dependence | 44 - polyhedron dependence |
45 or with the chains of recurrences based representation, | 45 or with the chains of recurrences based representation, |
46 | 46 |
47 - to define a knowledge base for storing the data dependence | 47 - to define a knowledge base for storing the data dependence |
48 information, | 48 information, |
49 | 49 |
50 - to define an interface to access this data. | 50 - to define an interface to access this data. |
51 | 51 |
52 | 52 |
53 Definitions: | 53 Definitions: |
54 | 54 |
55 - subscript: given two array accesses a subscript is the tuple | 55 - subscript: given two array accesses a subscript is the tuple |
56 composed of the access functions for a given dimension. Example: | 56 composed of the access functions for a given dimension. Example: |
57 Given A[f1][f2][f3] and B[g1][g2][g3], there are three subscripts: | 57 Given A[f1][f2][f3] and B[g1][g2][g3], there are three subscripts: |
58 (f1, g1), (f2, g2), (f3, g3). | 58 (f1, g1), (f2, g2), (f3, g3). |
59 | 59 |
60 - Diophantine equation: an equation whose coefficients and | 60 - Diophantine equation: an equation whose coefficients and |
61 solutions are integer constants, for example the equation | 61 solutions are integer constants, for example the equation |
62 | 3*x + 2*y = 1 | 62 | 3*x + 2*y = 1 |
63 has an integer solution x = 1 and y = -1. | 63 has an integer solution x = 1 and y = -1. |
64 | 64 |
65 References: | 65 References: |
66 | 66 |
67 - "Advanced Compilation for High Performance Computing" by Randy | 67 - "Advanced Compilation for High Performance Computing" by Randy |
68 Allen and Ken Kennedy. | 68 Allen and Ken Kennedy. |
69 http://citeseer.ist.psu.edu/goff91practical.html | 69 http://citeseer.ist.psu.edu/goff91practical.html |
70 | 70 |
71 - "Loop Transformations for Restructuring Compilers - The Foundations" | 71 - "Loop Transformations for Restructuring Compilers - The Foundations" |
72 by Utpal Banerjee. | 72 by Utpal Banerjee. |
73 | 73 |
74 | 74 |
75 */ | 75 */ |
76 | 76 |
77 #include "config.h" | 77 #include "config.h" |
78 #include "system.h" | 78 #include "system.h" |
79 #include "coretypes.h" | 79 #include "coretypes.h" |
125 struct data_reference *, | 125 struct data_reference *, |
126 struct data_reference *, | 126 struct data_reference *, |
127 struct loop *); | 127 struct loop *); |
128 /* Returns true iff A divides B. */ | 128 /* Returns true iff A divides B. */ |
129 | 129 |
130 static inline bool | 130 static inline bool |
131 tree_fold_divides_p (const_tree a, const_tree b) | 131 tree_fold_divides_p (const_tree a, const_tree b) |
132 { | 132 { |
133 gcc_assert (TREE_CODE (a) == INTEGER_CST); | 133 gcc_assert (TREE_CODE (a) == INTEGER_CST); |
134 gcc_assert (TREE_CODE (b) == INTEGER_CST); | 134 gcc_assert (TREE_CODE (b) == INTEGER_CST); |
135 return integer_zerop (int_const_binop (TRUNC_MOD_EXPR, b, a, 0)); | 135 return integer_zerop (int_const_binop (TRUNC_MOD_EXPR, b, a, 0)); |
136 } | 136 } |
137 | 137 |
138 /* Returns true iff A divides B. */ | 138 /* Returns true iff A divides B. */ |
139 | 139 |
140 static inline bool | 140 static inline bool |
141 int_divides_p (int a, int b) | 141 int_divides_p (int a, int b) |
142 { | 142 { |
143 return ((b % a) == 0); | 143 return ((b % a) == 0); |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 | 147 |
148 /* Dump into FILE all the data references from DATAREFS. */ | 148 /* Dump into FILE all the data references from DATAREFS. */ |
149 | 149 |
150 void | 150 void |
151 dump_data_references (FILE *file, VEC (data_reference_p, heap) *datarefs) | 151 dump_data_references (FILE *file, VEC (data_reference_p, heap) *datarefs) |
152 { | 152 { |
153 unsigned int i; | 153 unsigned int i; |
154 struct data_reference *dr; | 154 struct data_reference *dr; |
155 | 155 |
156 for (i = 0; VEC_iterate (data_reference_p, datarefs, i, dr); i++) | 156 for (i = 0; VEC_iterate (data_reference_p, datarefs, i, dr); i++) |
157 dump_data_reference (file, dr); | 157 dump_data_reference (file, dr); |
158 } | 158 } |
159 | 159 |
160 /* Dump to STDERR all the dependence relations from DDRS. */ | 160 /* Dump into STDERR all the data references from DATAREFS. */ |
161 | 161 |
162 void | 162 void |
163 debug_data_references (VEC (data_reference_p, heap) *datarefs) | |
164 { | |
165 dump_data_references (stderr, datarefs); | |
166 } | |
167 | |
168 /* Dump to STDERR all the dependence relations from DDRS. */ | |
169 | |
170 void | |
163 debug_data_dependence_relations (VEC (ddr_p, heap) *ddrs) | 171 debug_data_dependence_relations (VEC (ddr_p, heap) *ddrs) |
164 { | 172 { |
165 dump_data_dependence_relations (stderr, ddrs); | 173 dump_data_dependence_relations (stderr, ddrs); |
166 } | 174 } |
167 | 175 |
168 /* Dump into FILE all the dependence relations from DDRS. */ | 176 /* Dump into FILE all the dependence relations from DDRS. */ |
169 | 177 |
170 void | 178 void |
171 dump_data_dependence_relations (FILE *file, | 179 dump_data_dependence_relations (FILE *file, |
172 VEC (ddr_p, heap) *ddrs) | 180 VEC (ddr_p, heap) *ddrs) |
173 { | 181 { |
174 unsigned int i; | 182 unsigned int i; |
175 struct data_dependence_relation *ddr; | 183 struct data_dependence_relation *ddr; |
176 | 184 |
177 for (i = 0; VEC_iterate (ddr_p, ddrs, i, ddr); i++) | 185 for (i = 0; VEC_iterate (ddr_p, ddrs, i, ddr); i++) |
178 dump_data_dependence_relation (file, ddr); | 186 dump_data_dependence_relation (file, ddr); |
179 } | 187 } |
180 | 188 |
189 /* Print to STDERR the data_reference DR. */ | |
190 | |
191 void | |
192 debug_data_reference (struct data_reference *dr) | |
193 { | |
194 dump_data_reference (stderr, dr); | |
195 } | |
196 | |
181 /* Dump function for a DATA_REFERENCE structure. */ | 197 /* Dump function for a DATA_REFERENCE structure. */ |
182 | 198 |
183 void | 199 void |
184 dump_data_reference (FILE *outf, | 200 dump_data_reference (FILE *outf, |
185 struct data_reference *dr) | 201 struct data_reference *dr) |
186 { | 202 { |
187 unsigned int i; | 203 unsigned int i; |
188 | 204 |
189 fprintf (outf, "(Data Ref: \n stmt: "); | 205 fprintf (outf, "(Data Ref: \n stmt: "); |
190 print_gimple_stmt (outf, DR_STMT (dr), 0, 0); | 206 print_gimple_stmt (outf, DR_STMT (dr), 0, 0); |
191 fprintf (outf, " ref: "); | 207 fprintf (outf, " ref: "); |
192 print_generic_stmt (outf, DR_REF (dr), 0); | 208 print_generic_stmt (outf, DR_REF (dr), 0); |
193 fprintf (outf, " base_object: "); | 209 fprintf (outf, " base_object: "); |
194 print_generic_stmt (outf, DR_BASE_OBJECT (dr), 0); | 210 print_generic_stmt (outf, DR_BASE_OBJECT (dr), 0); |
195 | 211 |
196 for (i = 0; i < DR_NUM_DIMENSIONS (dr); i++) | 212 for (i = 0; i < DR_NUM_DIMENSIONS (dr); i++) |
197 { | 213 { |
198 fprintf (outf, " Access function %d: ", i); | 214 fprintf (outf, " Access function %d: ", i); |
199 print_generic_stmt (outf, DR_ACCESS_FN (dr, i), 0); | 215 print_generic_stmt (outf, DR_ACCESS_FN (dr, i), 0); |
200 } | 216 } |
240 } | 256 } |
241 } | 257 } |
242 | 258 |
243 /* Dump function for a SUBSCRIPT structure. */ | 259 /* Dump function for a SUBSCRIPT structure. */ |
244 | 260 |
245 void | 261 void |
246 dump_subscript (FILE *outf, struct subscript *subscript) | 262 dump_subscript (FILE *outf, struct subscript *subscript) |
247 { | 263 { |
248 conflict_function *cf = SUB_CONFLICTS_IN_A (subscript); | 264 conflict_function *cf = SUB_CONFLICTS_IN_A (subscript); |
249 | 265 |
250 fprintf (outf, "\n (subscript \n"); | 266 fprintf (outf, "\n (subscript \n"); |
254 { | 270 { |
255 tree last_iteration = SUB_LAST_CONFLICT (subscript); | 271 tree last_iteration = SUB_LAST_CONFLICT (subscript); |
256 fprintf (outf, " last_conflict: "); | 272 fprintf (outf, " last_conflict: "); |
257 print_generic_stmt (outf, last_iteration, 0); | 273 print_generic_stmt (outf, last_iteration, 0); |
258 } | 274 } |
259 | 275 |
260 cf = SUB_CONFLICTS_IN_B (subscript); | 276 cf = SUB_CONFLICTS_IN_B (subscript); |
261 fprintf (outf, " iterations_that_access_an_element_twice_in_B: "); | 277 fprintf (outf, " iterations_that_access_an_element_twice_in_B: "); |
262 dump_conflict_function (outf, cf); | 278 dump_conflict_function (outf, cf); |
263 if (CF_NONTRIVIAL_P (cf)) | 279 if (CF_NONTRIVIAL_P (cf)) |
264 { | 280 { |
282 { | 298 { |
283 int eq; | 299 int eq; |
284 | 300 |
285 for (eq = 0; eq < length; eq++) | 301 for (eq = 0; eq < length; eq++) |
286 { | 302 { |
287 enum data_dependence_direction dir = dirv[eq]; | 303 enum data_dependence_direction dir = ((enum data_dependence_direction) |
304 dirv[eq]); | |
288 | 305 |
289 switch (dir) | 306 switch (dir) |
290 { | 307 { |
291 case dir_positive: | 308 case dir_positive: |
292 fprintf (outf, " +"); | 309 fprintf (outf, " +"); |
343 print_lambda_vector (outf, v, length); | 360 print_lambda_vector (outf, v, length); |
344 } | 361 } |
345 | 362 |
346 /* Debug version. */ | 363 /* Debug version. */ |
347 | 364 |
348 void | 365 void |
349 debug_data_dependence_relation (struct data_dependence_relation *ddr) | 366 debug_data_dependence_relation (struct data_dependence_relation *ddr) |
350 { | 367 { |
351 dump_data_dependence_relation (stderr, ddr); | 368 dump_data_dependence_relation (stderr, ddr); |
352 } | 369 } |
353 | 370 |
354 /* Dump function for a DATA_DEPENDENCE_RELATION structure. */ | 371 /* Dump function for a DATA_DEPENDENCE_RELATION structure. */ |
355 | 372 |
356 void | 373 void |
357 dump_data_dependence_relation (FILE *outf, | 374 dump_data_dependence_relation (FILE *outf, |
358 struct data_dependence_relation *ddr) | 375 struct data_dependence_relation *ddr) |
359 { | 376 { |
360 struct data_reference *dra, *drb; | 377 struct data_reference *dra, *drb; |
361 | 378 |
362 fprintf (outf, "(Data Dep: \n"); | 379 fprintf (outf, "(Data Dep: \n"); |
372 dump_data_reference (outf, dra); | 389 dump_data_reference (outf, dra); |
373 dump_data_reference (outf, drb); | 390 dump_data_reference (outf, drb); |
374 | 391 |
375 if (DDR_ARE_DEPENDENT (ddr) == chrec_known) | 392 if (DDR_ARE_DEPENDENT (ddr) == chrec_known) |
376 fprintf (outf, " (no dependence)\n"); | 393 fprintf (outf, " (no dependence)\n"); |
377 | 394 |
378 else if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) | 395 else if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) |
379 { | 396 { |
380 unsigned int i; | 397 unsigned int i; |
381 struct loop *loopi; | 398 struct loop *loopi; |
382 | 399 |
414 } | 431 } |
415 | 432 |
416 /* Dump function for a DATA_DEPENDENCE_DIRECTION structure. */ | 433 /* Dump function for a DATA_DEPENDENCE_DIRECTION structure. */ |
417 | 434 |
418 void | 435 void |
419 dump_data_dependence_direction (FILE *file, | 436 dump_data_dependence_direction (FILE *file, |
420 enum data_dependence_direction dir) | 437 enum data_dependence_direction dir) |
421 { | 438 { |
422 switch (dir) | 439 switch (dir) |
423 { | 440 { |
424 case dir_positive: | 441 case dir_positive: |
425 fprintf (file, "+"); | 442 fprintf (file, "+"); |
426 break; | 443 break; |
427 | 444 |
428 case dir_negative: | 445 case dir_negative: |
429 fprintf (file, "-"); | 446 fprintf (file, "-"); |
430 break; | 447 break; |
431 | 448 |
432 case dir_equal: | 449 case dir_equal: |
433 fprintf (file, "="); | 450 fprintf (file, "="); |
434 break; | 451 break; |
435 | 452 |
436 case dir_positive_or_negative: | 453 case dir_positive_or_negative: |
437 fprintf (file, "+-"); | 454 fprintf (file, "+-"); |
438 break; | 455 break; |
439 | 456 |
440 case dir_positive_or_equal: | 457 case dir_positive_or_equal: |
441 fprintf (file, "+="); | 458 fprintf (file, "+="); |
442 break; | 459 break; |
443 | 460 |
444 case dir_negative_or_equal: | 461 case dir_negative_or_equal: |
445 fprintf (file, "-="); | 462 fprintf (file, "-="); |
446 break; | 463 break; |
447 | 464 |
448 case dir_star: | 465 case dir_star: |
449 fprintf (file, "*"); | 466 fprintf (file, "*"); |
450 break; | 467 break; |
451 | 468 |
452 default: | 469 default: |
453 break; | 470 break; |
454 } | 471 } |
455 } | 472 } |
456 | 473 |
457 /* Dumps the distance and direction vectors in FILE. DDRS contains | 474 /* Dumps the distance and direction vectors in FILE. DDRS contains |
458 the dependence relations, and VECT_SIZE is the size of the | 475 the dependence relations, and VECT_SIZE is the size of the |
459 dependence vectors, or in other words the number of loops in the | 476 dependence vectors, or in other words the number of loops in the |
460 considered nest. */ | 477 considered nest. */ |
461 | 478 |
462 void | 479 void |
463 dump_dist_dir_vectors (FILE *file, VEC (ddr_p, heap) *ddrs) | 480 dump_dist_dir_vectors (FILE *file, VEC (ddr_p, heap) *ddrs) |
464 { | 481 { |
465 unsigned int i, j; | 482 unsigned int i, j; |
466 struct data_dependence_relation *ddr; | 483 struct data_dependence_relation *ddr; |
467 lambda_vector v; | 484 lambda_vector v; |
487 fprintf (file, "\n\n"); | 504 fprintf (file, "\n\n"); |
488 } | 505 } |
489 | 506 |
490 /* Dumps the data dependence relations DDRS in FILE. */ | 507 /* Dumps the data dependence relations DDRS in FILE. */ |
491 | 508 |
492 void | 509 void |
493 dump_ddrs (FILE *file, VEC (ddr_p, heap) *ddrs) | 510 dump_ddrs (FILE *file, VEC (ddr_p, heap) *ddrs) |
494 { | 511 { |
495 unsigned int i; | 512 unsigned int i; |
496 struct data_dependence_relation *ddr; | 513 struct data_dependence_relation *ddr; |
497 | 514 |
665 return addr; | 682 return addr; |
666 | 683 |
667 return build_fold_addr_expr (TREE_OPERAND (addr, 0)); | 684 return build_fold_addr_expr (TREE_OPERAND (addr, 0)); |
668 } | 685 } |
669 | 686 |
670 /* Analyzes the behavior of the memory reference DR in the innermost loop that | 687 /* Analyzes the behavior of the memory reference DR in the innermost loop or |
671 contains it. Returns true if analysis succeed or false otherwise. */ | 688 basic block that contains it. Returns true if analysis succeed or false |
689 otherwise. */ | |
672 | 690 |
673 bool | 691 bool |
674 dr_analyze_innermost (struct data_reference *dr) | 692 dr_analyze_innermost (struct data_reference *dr) |
675 { | 693 { |
676 gimple stmt = DR_STMT (dr); | 694 gimple stmt = DR_STMT (dr); |
680 tree base, poffset; | 698 tree base, poffset; |
681 enum machine_mode pmode; | 699 enum machine_mode pmode; |
682 int punsignedp, pvolatilep; | 700 int punsignedp, pvolatilep; |
683 affine_iv base_iv, offset_iv; | 701 affine_iv base_iv, offset_iv; |
684 tree init, dinit, step; | 702 tree init, dinit, step; |
703 bool in_loop = (loop && loop->num); | |
685 | 704 |
686 if (dump_file && (dump_flags & TDF_DETAILS)) | 705 if (dump_file && (dump_flags & TDF_DETAILS)) |
687 fprintf (dump_file, "analyze_innermost: "); | 706 fprintf (dump_file, "analyze_innermost: "); |
688 | 707 |
689 base = get_inner_reference (ref, &pbitsize, &pbitpos, &poffset, | 708 base = get_inner_reference (ref, &pbitsize, &pbitpos, &poffset, |
696 fprintf (dump_file, "failed: bit offset alignment.\n"); | 715 fprintf (dump_file, "failed: bit offset alignment.\n"); |
697 return false; | 716 return false; |
698 } | 717 } |
699 | 718 |
700 base = build_fold_addr_expr (base); | 719 base = build_fold_addr_expr (base); |
701 if (!simple_iv (loop, loop_containing_stmt (stmt), base, &base_iv, false)) | 720 if (in_loop) |
702 { | 721 { |
703 if (dump_file && (dump_flags & TDF_DETAILS)) | 722 if (!simple_iv (loop, loop_containing_stmt (stmt), base, &base_iv, |
704 fprintf (dump_file, "failed: evolution of base is not affine.\n"); | 723 false)) |
705 return false; | 724 { |
706 } | 725 if (dump_file && (dump_flags & TDF_DETAILS)) |
726 fprintf (dump_file, "failed: evolution of base is not affine.\n"); | |
727 return false; | |
728 } | |
729 } | |
730 else | |
731 { | |
732 base_iv.base = base; | |
733 base_iv.step = ssize_int (0); | |
734 base_iv.no_overflow = true; | |
735 } | |
736 | |
707 if (!poffset) | 737 if (!poffset) |
708 { | 738 { |
709 offset_iv.base = ssize_int (0); | 739 offset_iv.base = ssize_int (0); |
710 offset_iv.step = ssize_int (0); | 740 offset_iv.step = ssize_int (0); |
711 } | 741 } |
712 else if (!simple_iv (loop, loop_containing_stmt (stmt), | 742 else |
713 poffset, &offset_iv, false)) | 743 { |
714 { | 744 if (!in_loop) |
715 if (dump_file && (dump_flags & TDF_DETAILS)) | 745 { |
716 fprintf (dump_file, "failed: evolution of offset is not affine.\n"); | 746 offset_iv.base = poffset; |
717 return false; | 747 offset_iv.step = ssize_int (0); |
748 } | |
749 else if (!simple_iv (loop, loop_containing_stmt (stmt), | |
750 poffset, &offset_iv, false)) | |
751 { | |
752 if (dump_file && (dump_flags & TDF_DETAILS)) | |
753 fprintf (dump_file, "failed: evolution of offset is not" | |
754 " affine.\n"); | |
755 return false; | |
756 } | |
718 } | 757 } |
719 | 758 |
720 init = ssize_int (pbitpos / BITS_PER_UNIT); | 759 init = ssize_int (pbitpos / BITS_PER_UNIT); |
721 split_constant_offset (base_iv.base, &base_iv.base, &dinit); | 760 split_constant_offset (base_iv.base, &base_iv.base, &dinit); |
722 init = size_binop (PLUS_EXPR, init, dinit); | 761 init = size_binop (PLUS_EXPR, init, dinit); |
749 { | 788 { |
750 gimple stmt = DR_STMT (dr); | 789 gimple stmt = DR_STMT (dr); |
751 struct loop *loop = loop_containing_stmt (stmt); | 790 struct loop *loop = loop_containing_stmt (stmt); |
752 VEC (tree, heap) *access_fns = NULL; | 791 VEC (tree, heap) *access_fns = NULL; |
753 tree ref = unshare_expr (DR_REF (dr)), aref = ref, op; | 792 tree ref = unshare_expr (DR_REF (dr)), aref = ref, op; |
754 tree base, off, access_fn; | 793 tree base, off, access_fn = NULL_TREE; |
755 basic_block before_loop = block_before_loop (nest); | 794 basic_block before_loop = NULL; |
795 | |
796 if (nest) | |
797 before_loop = block_before_loop (nest); | |
756 | 798 |
757 while (handled_component_p (aref)) | 799 while (handled_component_p (aref)) |
758 { | 800 { |
759 if (TREE_CODE (aref) == ARRAY_REF) | 801 if (TREE_CODE (aref) == ARRAY_REF) |
760 { | 802 { |
761 op = TREE_OPERAND (aref, 1); | 803 op = TREE_OPERAND (aref, 1); |
762 access_fn = analyze_scalar_evolution (loop, op); | 804 if (nest) |
763 access_fn = instantiate_scev (before_loop, loop, access_fn); | 805 { |
764 VEC_safe_push (tree, heap, access_fns, access_fn); | 806 access_fn = analyze_scalar_evolution (loop, op); |
807 access_fn = instantiate_scev (before_loop, loop, access_fn); | |
808 VEC_safe_push (tree, heap, access_fns, access_fn); | |
809 } | |
765 | 810 |
766 TREE_OPERAND (aref, 1) = build_int_cst (TREE_TYPE (op), 0); | 811 TREE_OPERAND (aref, 1) = build_int_cst (TREE_TYPE (op), 0); |
767 } | 812 } |
768 | 813 |
769 aref = TREE_OPERAND (aref, 0); | 814 aref = TREE_OPERAND (aref, 0); |
770 } | 815 } |
771 | 816 |
772 if (INDIRECT_REF_P (aref)) | 817 if (nest && INDIRECT_REF_P (aref)) |
773 { | 818 { |
774 op = TREE_OPERAND (aref, 0); | 819 op = TREE_OPERAND (aref, 0); |
775 access_fn = analyze_scalar_evolution (loop, op); | 820 access_fn = analyze_scalar_evolution (loop, op); |
776 access_fn = instantiate_scev (before_loop, loop, access_fn); | 821 access_fn = instantiate_scev (before_loop, loop, access_fn); |
777 base = initial_condition (access_fn); | 822 base = initial_condition (access_fn); |
790 /* Extracts the alias analysis information from the memory reference DR. */ | 835 /* Extracts the alias analysis information from the memory reference DR. */ |
791 | 836 |
792 static void | 837 static void |
793 dr_analyze_alias (struct data_reference *dr) | 838 dr_analyze_alias (struct data_reference *dr) |
794 { | 839 { |
795 gimple stmt = DR_STMT (dr); | |
796 tree ref = DR_REF (dr); | 840 tree ref = DR_REF (dr); |
797 tree base = get_base_address (ref), addr, smt = NULL_TREE; | 841 tree base = get_base_address (ref), addr; |
798 ssa_op_iter it; | 842 |
799 tree op; | 843 if (INDIRECT_REF_P (base)) |
800 bitmap vops; | |
801 | |
802 if (DECL_P (base)) | |
803 smt = base; | |
804 else if (INDIRECT_REF_P (base)) | |
805 { | 844 { |
806 addr = TREE_OPERAND (base, 0); | 845 addr = TREE_OPERAND (base, 0); |
807 if (TREE_CODE (addr) == SSA_NAME) | 846 if (TREE_CODE (addr) == SSA_NAME) |
808 { | 847 DR_PTR_INFO (dr) = SSA_NAME_PTR_INFO (addr); |
809 smt = symbol_mem_tag (SSA_NAME_VAR (addr)); | 848 } |
810 DR_PTR_INFO (dr) = SSA_NAME_PTR_INFO (addr); | |
811 } | |
812 } | |
813 | |
814 DR_SYMBOL_TAG (dr) = smt; | |
815 | |
816 vops = BITMAP_ALLOC (NULL); | |
817 FOR_EACH_SSA_TREE_OPERAND (op, stmt, it, SSA_OP_VIRTUAL_USES) | |
818 { | |
819 bitmap_set_bit (vops, DECL_UID (SSA_NAME_VAR (op))); | |
820 } | |
821 | |
822 DR_VOPS (dr) = vops; | |
823 } | 849 } |
824 | 850 |
825 /* Returns true if the address of DR is invariant. */ | 851 /* Returns true if the address of DR is invariant. */ |
826 | 852 |
827 static bool | 853 static bool |
840 /* Frees data reference DR. */ | 866 /* Frees data reference DR. */ |
841 | 867 |
842 void | 868 void |
843 free_data_ref (data_reference_p dr) | 869 free_data_ref (data_reference_p dr) |
844 { | 870 { |
845 BITMAP_FREE (DR_VOPS (dr)); | |
846 VEC_free (tree, heap, DR_ACCESS_FNS (dr)); | 871 VEC_free (tree, heap, DR_ACCESS_FNS (dr)); |
847 free (dr); | 872 free (dr); |
848 } | 873 } |
849 | 874 |
850 /* Analyzes memory reference MEMREF accessed in STMT. The reference | 875 /* Analyzes memory reference MEMREF accessed in STMT. The reference |
885 print_generic_expr (dump_file, DR_STEP (dr), TDF_SLIM); | 910 print_generic_expr (dump_file, DR_STEP (dr), TDF_SLIM); |
886 fprintf (dump_file, "\n\taligned to: "); | 911 fprintf (dump_file, "\n\taligned to: "); |
887 print_generic_expr (dump_file, DR_ALIGNED_TO (dr), TDF_SLIM); | 912 print_generic_expr (dump_file, DR_ALIGNED_TO (dr), TDF_SLIM); |
888 fprintf (dump_file, "\n\tbase_object: "); | 913 fprintf (dump_file, "\n\tbase_object: "); |
889 print_generic_expr (dump_file, DR_BASE_OBJECT (dr), TDF_SLIM); | 914 print_generic_expr (dump_file, DR_BASE_OBJECT (dr), TDF_SLIM); |
890 fprintf (dump_file, "\n\tsymbol tag: "); | |
891 print_generic_expr (dump_file, DR_SYMBOL_TAG (dr), TDF_SLIM); | |
892 fprintf (dump_file, "\n"); | 915 fprintf (dump_file, "\n"); |
893 } | 916 } |
894 | 917 |
895 return dr; | 918 return dr; |
896 } | 919 } |
897 | 920 |
898 /* Returns true if FNA == FNB. */ | 921 /* Returns true if FNA == FNB. */ |
899 | 922 |
900 static bool | 923 static bool |
1005 tree type = signed_type_for_types (TREE_TYPE (VEC_index (tree, fna, i)), | 1028 tree type = signed_type_for_types (TREE_TYPE (VEC_index (tree, fna, i)), |
1006 TREE_TYPE (VEC_index (tree, fnb, i))); | 1029 TREE_TYPE (VEC_index (tree, fnb, i))); |
1007 | 1030 |
1008 VEC_quick_push (tree, ret, | 1031 VEC_quick_push (tree, ret, |
1009 fold_build2 (op, type, | 1032 fold_build2 (op, type, |
1010 VEC_index (tree, fna, i), | 1033 VEC_index (tree, fna, i), |
1011 VEC_index (tree, fnb, i))); | 1034 VEC_index (tree, fnb, i))); |
1012 } | 1035 } |
1013 | 1036 |
1014 for (; VEC_iterate (tree, fna, i, coef); i++) | 1037 for (; VEC_iterate (tree, fna, i, coef); i++) |
1015 VEC_quick_push (tree, ret, | 1038 VEC_quick_push (tree, ret, |
1057 affine_fn fn_a, fn_b, diff; | 1080 affine_fn fn_a, fn_b, diff; |
1058 | 1081 |
1059 if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) | 1082 if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) |
1060 { | 1083 { |
1061 unsigned int i; | 1084 unsigned int i; |
1062 | 1085 |
1063 for (i = 0; i < DDR_NUM_SUBSCRIPTS (ddr); i++) | 1086 for (i = 0; i < DDR_NUM_SUBSCRIPTS (ddr); i++) |
1064 { | 1087 { |
1065 struct subscript *subscript; | 1088 struct subscript *subscript; |
1066 | 1089 |
1067 subscript = DDR_SUBSCRIPT (ddr, i); | 1090 subscript = DDR_SUBSCRIPT (ddr, i); |
1068 cf_a = SUB_CONFLICTS_IN_A (subscript); | 1091 cf_a = SUB_CONFLICTS_IN_A (subscript); |
1069 cf_b = SUB_CONFLICTS_IN_B (subscript); | 1092 cf_b = SUB_CONFLICTS_IN_B (subscript); |
1070 | 1093 |
1071 fn_a = common_affine_function (cf_a); | 1094 fn_a = common_affine_function (cf_a); |
1074 { | 1097 { |
1075 SUB_DISTANCE (subscript) = chrec_dont_know; | 1098 SUB_DISTANCE (subscript) = chrec_dont_know; |
1076 return; | 1099 return; |
1077 } | 1100 } |
1078 diff = affine_fn_minus (fn_a, fn_b); | 1101 diff = affine_fn_minus (fn_a, fn_b); |
1079 | 1102 |
1080 if (affine_function_constant_p (diff)) | 1103 if (affine_function_constant_p (diff)) |
1081 SUB_DISTANCE (subscript) = affine_function_base (diff); | 1104 SUB_DISTANCE (subscript) = affine_function_base (diff); |
1082 else | 1105 else |
1083 SUB_DISTANCE (subscript) = chrec_dont_know; | 1106 SUB_DISTANCE (subscript) = chrec_dont_know; |
1084 | 1107 |
1236 const_tree addr_a = DR_BASE_ADDRESS (a); | 1259 const_tree addr_a = DR_BASE_ADDRESS (a); |
1237 const_tree addr_b = DR_BASE_ADDRESS (b); | 1260 const_tree addr_b = DR_BASE_ADDRESS (b); |
1238 const_tree type_a, type_b; | 1261 const_tree type_a, type_b; |
1239 const_tree decl_a = NULL_TREE, decl_b = NULL_TREE; | 1262 const_tree decl_a = NULL_TREE, decl_b = NULL_TREE; |
1240 | 1263 |
1241 /* If the sets of virtual operands are disjoint, the memory references do not | |
1242 alias. */ | |
1243 if (!bitmap_intersect_p (DR_VOPS (a), DR_VOPS (b))) | |
1244 return false; | |
1245 | |
1246 /* If the accessed objects are disjoint, the memory references do not | 1264 /* If the accessed objects are disjoint, the memory references do not |
1247 alias. */ | 1265 alias. */ |
1248 if (disjoint_objects_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b))) | 1266 if (disjoint_objects_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b))) |
1249 return false; | 1267 return false; |
1250 | 1268 |
1269 /* Query the alias oracle. */ | |
1270 if (!DR_IS_READ (a) && !DR_IS_READ (b)) | |
1271 { | |
1272 if (!refs_output_dependent_p (DR_REF (a), DR_REF (b))) | |
1273 return false; | |
1274 } | |
1275 else if (DR_IS_READ (a) && !DR_IS_READ (b)) | |
1276 { | |
1277 if (!refs_anti_dependent_p (DR_REF (a), DR_REF (b))) | |
1278 return false; | |
1279 } | |
1280 else if (!refs_may_alias_p (DR_REF (a), DR_REF (b))) | |
1281 return false; | |
1282 | |
1251 if (!addr_a || !addr_b) | 1283 if (!addr_a || !addr_b) |
1252 return true; | 1284 return true; |
1253 | 1285 |
1254 /* If the references are based on different static objects, they cannot alias | 1286 /* If the references are based on different static objects, they cannot |
1255 (PTA should be able to disambiguate such accesses, but often it fails to, | 1287 alias (PTA should be able to disambiguate such accesses, but often |
1256 since currently we cannot distinguish between pointer and offset in pointer | 1288 it fails to). */ |
1257 arithmetics). */ | |
1258 if (TREE_CODE (addr_a) == ADDR_EXPR | 1289 if (TREE_CODE (addr_a) == ADDR_EXPR |
1259 && TREE_CODE (addr_b) == ADDR_EXPR) | 1290 && TREE_CODE (addr_b) == ADDR_EXPR) |
1260 return TREE_OPERAND (addr_a, 0) == TREE_OPERAND (addr_b, 0); | 1291 return TREE_OPERAND (addr_a, 0) == TREE_OPERAND (addr_b, 0); |
1261 | 1292 |
1262 /* An instruction writing through a restricted pointer is "independent" of any | 1293 /* An instruction writing through a restricted pointer is "independent" of any |
1263 instruction reading or writing through a different restricted pointer, | 1294 instruction reading or writing through a different restricted pointer, |
1264 in the same block/scope. */ | 1295 in the same block/scope. */ |
1265 | 1296 |
1266 type_a = TREE_TYPE (addr_a); | 1297 type_a = TREE_TYPE (addr_a); |
1267 type_b = TREE_TYPE (addr_b); | 1298 type_b = TREE_TYPE (addr_b); |
1268 gcc_assert (POINTER_TYPE_P (type_a) && POINTER_TYPE_P (type_b)); | 1299 gcc_assert (POINTER_TYPE_P (type_a) && POINTER_TYPE_P (type_b)); |
1270 if (TREE_CODE (addr_a) == SSA_NAME) | 1301 if (TREE_CODE (addr_a) == SSA_NAME) |
1271 decl_a = SSA_NAME_VAR (addr_a); | 1302 decl_a = SSA_NAME_VAR (addr_a); |
1272 if (TREE_CODE (addr_b) == SSA_NAME) | 1303 if (TREE_CODE (addr_b) == SSA_NAME) |
1273 decl_b = SSA_NAME_VAR (addr_b); | 1304 decl_b = SSA_NAME_VAR (addr_b); |
1274 | 1305 |
1275 if (TYPE_RESTRICT (type_a) && TYPE_RESTRICT (type_b) | 1306 if (TYPE_RESTRICT (type_a) && TYPE_RESTRICT (type_b) |
1276 && (!DR_IS_READ (a) || !DR_IS_READ (b)) | 1307 && (!DR_IS_READ (a) || !DR_IS_READ (b)) |
1277 && decl_a && DECL_P (decl_a) | 1308 && decl_a && DECL_P (decl_a) |
1278 && decl_b && DECL_P (decl_b) | 1309 && decl_b && DECL_P (decl_b) |
1279 && decl_a != decl_b | 1310 && decl_a != decl_b |
1280 && TREE_CODE (DECL_CONTEXT (decl_a)) == FUNCTION_DECL | 1311 && TREE_CODE (DECL_CONTEXT (decl_a)) == FUNCTION_DECL |
1289 /* Initialize a data dependence relation between data accesses A and | 1320 /* Initialize a data dependence relation between data accesses A and |
1290 B. NB_LOOPS is the number of loops surrounding the references: the | 1321 B. NB_LOOPS is the number of loops surrounding the references: the |
1291 size of the classic distance/direction vectors. */ | 1322 size of the classic distance/direction vectors. */ |
1292 | 1323 |
1293 static struct data_dependence_relation * | 1324 static struct data_dependence_relation * |
1294 initialize_data_dependence_relation (struct data_reference *a, | 1325 initialize_data_dependence_relation (struct data_reference *a, |
1295 struct data_reference *b, | 1326 struct data_reference *b, |
1296 VEC (loop_p, heap) *loop_nest) | 1327 VEC (loop_p, heap) *loop_nest) |
1297 { | 1328 { |
1298 struct data_dependence_relation *res; | 1329 struct data_dependence_relation *res; |
1299 unsigned int i; | 1330 unsigned int i; |
1300 | 1331 |
1301 res = XNEW (struct data_dependence_relation); | 1332 res = XNEW (struct data_dependence_relation); |
1302 DDR_A (res) = a; | 1333 DDR_A (res) = a; |
1303 DDR_B (res) = b; | 1334 DDR_B (res) = b; |
1304 DDR_LOOP_NEST (res) = NULL; | 1335 DDR_LOOP_NEST (res) = NULL; |
1305 DDR_REVERSED_P (res) = false; | 1336 DDR_REVERSED_P (res) = false; |
1307 DDR_DIR_VECTS (res) = NULL; | 1338 DDR_DIR_VECTS (res) = NULL; |
1308 DDR_DIST_VECTS (res) = NULL; | 1339 DDR_DIST_VECTS (res) = NULL; |
1309 | 1340 |
1310 if (a == NULL || b == NULL) | 1341 if (a == NULL || b == NULL) |
1311 { | 1342 { |
1312 DDR_ARE_DEPENDENT (res) = chrec_dont_know; | 1343 DDR_ARE_DEPENDENT (res) = chrec_dont_know; |
1313 return res; | 1344 return res; |
1314 } | 1345 } |
1315 | 1346 |
1316 /* If the data references do not alias, then they are independent. */ | 1347 /* If the data references do not alias, then they are independent. */ |
1317 if (!dr_may_alias_p (a, b)) | 1348 if (!dr_may_alias_p (a, b)) |
1318 { | 1349 { |
1319 DDR_ARE_DEPENDENT (res) = chrec_known; | 1350 DDR_ARE_DEPENDENT (res) = chrec_known; |
1320 return res; | 1351 return res; |
1321 } | 1352 } |
1322 | 1353 |
1323 /* When the references are exactly the same, don't spend time doing | 1354 /* When the references are exactly the same, don't spend time doing |
1324 the data dependence tests, just initialize the ddr and return. */ | 1355 the data dependence tests, just initialize the ddr and return. */ |
1336 | 1367 |
1337 /* If the references do not access the same object, we do not know | 1368 /* If the references do not access the same object, we do not know |
1338 whether they alias or not. */ | 1369 whether they alias or not. */ |
1339 if (!operand_equal_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b), 0)) | 1370 if (!operand_equal_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b), 0)) |
1340 { | 1371 { |
1341 DDR_ARE_DEPENDENT (res) = chrec_dont_know; | 1372 DDR_ARE_DEPENDENT (res) = chrec_dont_know; |
1342 return res; | 1373 return res; |
1343 } | 1374 } |
1344 | 1375 |
1345 /* If the base of the object is not invariant in the loop nest, we cannot | 1376 /* If the base of the object is not invariant in the loop nest, we cannot |
1346 analyze it. TODO -- in fact, it would suffice to record that there may | 1377 analyze it. TODO -- in fact, it would suffice to record that there may |
1347 be arbitrary dependences in the loops where the base object varies. */ | 1378 be arbitrary dependences in the loops where the base object varies. */ |
1348 if (!object_address_invariant_in_loop_p (VEC_index (loop_p, loop_nest, 0), | 1379 if (loop_nest |
1349 DR_BASE_OBJECT (a))) | 1380 && !object_address_invariant_in_loop_p (VEC_index (loop_p, loop_nest, 0), |
1350 { | 1381 DR_BASE_OBJECT (a))) |
1351 DDR_ARE_DEPENDENT (res) = chrec_dont_know; | 1382 { |
1383 DDR_ARE_DEPENDENT (res) = chrec_dont_know; | |
1352 return res; | 1384 return res; |
1353 } | 1385 } |
1354 | 1386 |
1355 gcc_assert (DR_NUM_DIMENSIONS (a) == DR_NUM_DIMENSIONS (b)); | 1387 gcc_assert (DR_NUM_DIMENSIONS (a) == DR_NUM_DIMENSIONS (b)); |
1356 | 1388 |
1362 DDR_SELF_REFERENCE (res) = false; | 1394 DDR_SELF_REFERENCE (res) = false; |
1363 | 1395 |
1364 for (i = 0; i < DR_NUM_DIMENSIONS (a); i++) | 1396 for (i = 0; i < DR_NUM_DIMENSIONS (a); i++) |
1365 { | 1397 { |
1366 struct subscript *subscript; | 1398 struct subscript *subscript; |
1367 | 1399 |
1368 subscript = XNEW (struct subscript); | 1400 subscript = XNEW (struct subscript); |
1369 SUB_CONFLICTS_IN_A (subscript) = conflict_fn_not_known (); | 1401 SUB_CONFLICTS_IN_A (subscript) = conflict_fn_not_known (); |
1370 SUB_CONFLICTS_IN_B (subscript) = conflict_fn_not_known (); | 1402 SUB_CONFLICTS_IN_B (subscript) = conflict_fn_not_known (); |
1371 SUB_LAST_CONFLICT (subscript) = chrec_dont_know; | 1403 SUB_LAST_CONFLICT (subscript) = chrec_dont_know; |
1372 SUB_DISTANCE (subscript) = chrec_dont_know; | 1404 SUB_DISTANCE (subscript) = chrec_dont_know; |
1410 | 1442 |
1411 /* Set DDR_ARE_DEPENDENT to CHREC and finalize the subscript overlap | 1443 /* Set DDR_ARE_DEPENDENT to CHREC and finalize the subscript overlap |
1412 description. */ | 1444 description. */ |
1413 | 1445 |
1414 static inline void | 1446 static inline void |
1415 finalize_ddr_dependent (struct data_dependence_relation *ddr, | 1447 finalize_ddr_dependent (struct data_dependence_relation *ddr, |
1416 tree chrec) | 1448 tree chrec) |
1417 { | 1449 { |
1418 if (dump_file && (dump_flags & TDF_DETAILS)) | 1450 if (dump_file && (dump_flags & TDF_DETAILS)) |
1419 { | 1451 { |
1420 fprintf (dump_file, "(dependence classified: "); | 1452 fprintf (dump_file, "(dependence classified: "); |
1421 print_generic_expr (dump_file, chrec, 0); | 1453 print_generic_expr (dump_file, chrec, 0); |
1422 fprintf (dump_file, ")\n"); | 1454 fprintf (dump_file, ")\n"); |
1423 } | 1455 } |
1424 | 1456 |
1425 DDR_ARE_DEPENDENT (ddr) = chrec; | 1457 DDR_ARE_DEPENDENT (ddr) = chrec; |
1426 free_subscripts (DDR_SUBSCRIPTS (ddr)); | 1458 free_subscripts (DDR_SUBSCRIPTS (ddr)); |
1427 DDR_SUBSCRIPTS (ddr) = NULL; | 1459 DDR_SUBSCRIPTS (ddr) = NULL; |
1428 } | 1460 } |
1429 | 1461 |
1430 /* The dependence relation DDR cannot be represented by a distance | 1462 /* The dependence relation DDR cannot be represented by a distance |
1462 if ((evolution_function_is_constant_p (chrec_a) | 1494 if ((evolution_function_is_constant_p (chrec_a) |
1463 && evolution_function_is_univariate_p (chrec_b)) | 1495 && evolution_function_is_univariate_p (chrec_b)) |
1464 || (evolution_function_is_constant_p (chrec_b) | 1496 || (evolution_function_is_constant_p (chrec_b) |
1465 && evolution_function_is_univariate_p (chrec_a))) | 1497 && evolution_function_is_univariate_p (chrec_a))) |
1466 return true; | 1498 return true; |
1467 | 1499 |
1468 if (evolution_function_is_univariate_p (chrec_a) | 1500 if (evolution_function_is_univariate_p (chrec_a) |
1469 && evolution_function_is_univariate_p (chrec_b)) | 1501 && evolution_function_is_univariate_p (chrec_b)) |
1470 { | 1502 { |
1471 switch (TREE_CODE (chrec_a)) | 1503 switch (TREE_CODE (chrec_a)) |
1472 { | 1504 { |
1474 switch (TREE_CODE (chrec_b)) | 1506 switch (TREE_CODE (chrec_b)) |
1475 { | 1507 { |
1476 case POLYNOMIAL_CHREC: | 1508 case POLYNOMIAL_CHREC: |
1477 if (CHREC_VARIABLE (chrec_a) != CHREC_VARIABLE (chrec_b)) | 1509 if (CHREC_VARIABLE (chrec_a) != CHREC_VARIABLE (chrec_b)) |
1478 return false; | 1510 return false; |
1479 | 1511 |
1480 default: | 1512 default: |
1481 return true; | 1513 return true; |
1482 } | 1514 } |
1483 | 1515 |
1484 default: | 1516 default: |
1485 return true; | 1517 return true; |
1486 } | 1518 } |
1487 } | 1519 } |
1488 | 1520 |
1489 return false; | 1521 return false; |
1490 } | 1522 } |
1491 | 1523 |
1492 /* Creates a conflict function with N dimensions. The affine functions | 1524 /* Creates a conflict function with N dimensions. The affine functions |
1493 in each dimension follow. */ | 1525 in each dimension follow. */ |
1499 conflict_function *ret = XCNEW (conflict_function); | 1531 conflict_function *ret = XCNEW (conflict_function); |
1500 va_list ap; | 1532 va_list ap; |
1501 | 1533 |
1502 gcc_assert (0 < n && n <= MAX_DIM); | 1534 gcc_assert (0 < n && n <= MAX_DIM); |
1503 va_start(ap, n); | 1535 va_start(ap, n); |
1504 | 1536 |
1505 ret->n = n; | 1537 ret->n = n; |
1506 for (i = 0; i < n; i++) | 1538 for (i = 0; i < n; i++) |
1507 ret->fns[i] = va_arg (ap, affine_fn); | 1539 ret->fns[i] = va_arg (ap, affine_fn); |
1508 va_end(ap); | 1540 va_end(ap); |
1509 | 1541 |
1541 relation between the elements accessed twice by CHREC_A and | 1573 relation between the elements accessed twice by CHREC_A and |
1542 CHREC_B. For k >= 0, the following property is verified: | 1574 CHREC_B. For k >= 0, the following property is verified: |
1543 | 1575 |
1544 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ | 1576 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ |
1545 | 1577 |
1546 static void | 1578 static void |
1547 analyze_ziv_subscript (tree chrec_a, | 1579 analyze_ziv_subscript (tree chrec_a, |
1548 tree chrec_b, | 1580 tree chrec_b, |
1549 conflict_function **overlaps_a, | 1581 conflict_function **overlaps_a, |
1550 conflict_function **overlaps_b, | 1582 conflict_function **overlaps_b, |
1551 tree *last_conflicts) | 1583 tree *last_conflicts) |
1552 { | 1584 { |
1553 tree type, difference; | 1585 tree type, difference; |
1554 dependence_stats.num_ziv++; | 1586 dependence_stats.num_ziv++; |
1555 | 1587 |
1556 if (dump_file && (dump_flags & TDF_DETAILS)) | 1588 if (dump_file && (dump_flags & TDF_DETAILS)) |
1557 fprintf (dump_file, "(analyze_ziv_subscript \n"); | 1589 fprintf (dump_file, "(analyze_ziv_subscript \n"); |
1558 | 1590 |
1559 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); | 1591 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); |
1560 chrec_a = chrec_convert (type, chrec_a, NULL); | 1592 chrec_a = chrec_convert (type, chrec_a, NULL); |
1561 chrec_b = chrec_convert (type, chrec_b, NULL); | 1593 chrec_b = chrec_convert (type, chrec_b, NULL); |
1562 difference = chrec_fold_minus (type, chrec_a, chrec_b); | 1594 difference = chrec_fold_minus (type, chrec_a, chrec_b); |
1563 | 1595 |
1564 switch (TREE_CODE (difference)) | 1596 switch (TREE_CODE (difference)) |
1565 { | 1597 { |
1566 case INTEGER_CST: | 1598 case INTEGER_CST: |
1567 if (integer_zerop (difference)) | 1599 if (integer_zerop (difference)) |
1568 { | 1600 { |
1580 *overlaps_b = conflict_fn_no_dependence (); | 1612 *overlaps_b = conflict_fn_no_dependence (); |
1581 *last_conflicts = integer_zero_node; | 1613 *last_conflicts = integer_zero_node; |
1582 dependence_stats.num_ziv_independent++; | 1614 dependence_stats.num_ziv_independent++; |
1583 } | 1615 } |
1584 break; | 1616 break; |
1585 | 1617 |
1586 default: | 1618 default: |
1587 /* We're not sure whether the indexes overlap. For the moment, | 1619 /* We're not sure whether the indexes overlap. For the moment, |
1588 conservatively answer "don't know". */ | 1620 conservatively answer "don't know". */ |
1589 if (dump_file && (dump_flags & TDF_DETAILS)) | 1621 if (dump_file && (dump_flags & TDF_DETAILS)) |
1590 fprintf (dump_file, "ziv test failed: difference is non-integer.\n"); | 1622 fprintf (dump_file, "ziv test failed: difference is non-integer.\n"); |
1591 | 1623 |
1592 *overlaps_a = conflict_fn_not_known (); | 1624 *overlaps_a = conflict_fn_not_known (); |
1593 *overlaps_b = conflict_fn_not_known (); | 1625 *overlaps_b = conflict_fn_not_known (); |
1594 *last_conflicts = chrec_dont_know; | 1626 *last_conflicts = chrec_dont_know; |
1595 dependence_stats.num_ziv_unimplemented++; | 1627 dependence_stats.num_ziv_unimplemented++; |
1596 break; | 1628 break; |
1597 } | 1629 } |
1598 | 1630 |
1599 if (dump_file && (dump_flags & TDF_DETAILS)) | 1631 if (dump_file && (dump_flags & TDF_DETAILS)) |
1600 fprintf (dump_file, ")\n"); | 1632 fprintf (dump_file, ")\n"); |
1601 } | 1633 } |
1602 | 1634 |
1603 /* Sets NIT to the estimated number of executions of the statements in | 1635 /* Sets NIT to the estimated number of executions of the statements in |
1645 return -1; | 1677 return -1; |
1646 hwi_nit = double_int_to_shwi (nit); | 1678 hwi_nit = double_int_to_shwi (nit); |
1647 | 1679 |
1648 return hwi_nit < 0 ? -1 : hwi_nit; | 1680 return hwi_nit < 0 ? -1 : hwi_nit; |
1649 } | 1681 } |
1650 | 1682 |
1651 /* Similar to estimated_loop_iterations, but returns the estimate as a tree, | 1683 /* Similar to estimated_loop_iterations, but returns the estimate as a tree, |
1652 and only if it fits to the int type. If this is not the case, or the | 1684 and only if it fits to the int type. If this is not the case, or the |
1653 estimate on the number of iterations of LOOP could not be derived, returns | 1685 estimate on the number of iterations of LOOP could not be derived, returns |
1654 chrec_dont_know. */ | 1686 chrec_dont_know. */ |
1655 | 1687 |
1676 CHREC_B. For k >= 0, the following property is verified: | 1708 CHREC_B. For k >= 0, the following property is verified: |
1677 | 1709 |
1678 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ | 1710 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ |
1679 | 1711 |
1680 static void | 1712 static void |
1681 analyze_siv_subscript_cst_affine (tree chrec_a, | 1713 analyze_siv_subscript_cst_affine (tree chrec_a, |
1682 tree chrec_b, | 1714 tree chrec_b, |
1683 conflict_function **overlaps_a, | 1715 conflict_function **overlaps_a, |
1684 conflict_function **overlaps_b, | 1716 conflict_function **overlaps_b, |
1685 tree *last_conflicts) | 1717 tree *last_conflicts) |
1686 { | 1718 { |
1687 bool value0, value1, value2; | 1719 bool value0, value1, value2; |
1688 tree type, difference, tmp; | 1720 tree type, difference, tmp; |
1689 | 1721 |
1690 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); | 1722 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); |
1691 chrec_a = chrec_convert (type, chrec_a, NULL); | 1723 chrec_a = chrec_convert (type, chrec_a, NULL); |
1692 chrec_b = chrec_convert (type, chrec_b, NULL); | 1724 chrec_b = chrec_convert (type, chrec_b, NULL); |
1693 difference = chrec_fold_minus (type, initial_condition (chrec_b), chrec_a); | 1725 difference = chrec_fold_minus (type, initial_condition (chrec_b), chrec_a); |
1694 | 1726 |
1695 if (!chrec_is_positive (initial_condition (difference), &value0)) | 1727 if (!chrec_is_positive (initial_condition (difference), &value0)) |
1696 { | 1728 { |
1697 if (dump_file && (dump_flags & TDF_DETAILS)) | 1729 if (dump_file && (dump_flags & TDF_DETAILS)) |
1698 fprintf (dump_file, "siv test failed: chrec is not positive.\n"); | 1730 fprintf (dump_file, "siv test failed: chrec is not positive.\n"); |
1699 | 1731 |
1700 dependence_stats.num_siv_unimplemented++; | 1732 dependence_stats.num_siv_unimplemented++; |
1701 *overlaps_a = conflict_fn_not_known (); | 1733 *overlaps_a = conflict_fn_not_known (); |
1702 *overlaps_b = conflict_fn_not_known (); | 1734 *overlaps_b = conflict_fn_not_known (); |
1703 *last_conflicts = chrec_dont_know; | 1735 *last_conflicts = chrec_dont_know; |
1711 { | 1743 { |
1712 if (dump_file && (dump_flags & TDF_DETAILS)) | 1744 if (dump_file && (dump_flags & TDF_DETAILS)) |
1713 fprintf (dump_file, "siv test failed: chrec not positive.\n"); | 1745 fprintf (dump_file, "siv test failed: chrec not positive.\n"); |
1714 | 1746 |
1715 *overlaps_a = conflict_fn_not_known (); | 1747 *overlaps_a = conflict_fn_not_known (); |
1716 *overlaps_b = conflict_fn_not_known (); | 1748 *overlaps_b = conflict_fn_not_known (); |
1717 *last_conflicts = chrec_dont_know; | 1749 *last_conflicts = chrec_dont_know; |
1718 dependence_stats.num_siv_unimplemented++; | 1750 dependence_stats.num_siv_unimplemented++; |
1719 return; | 1751 return; |
1720 } | 1752 } |
1721 else | 1753 else |
1722 { | 1754 { |
1723 if (value1 == true) | 1755 if (value1 == true) |
1724 { | 1756 { |
1725 /* Example: | 1757 /* Example: |
1726 chrec_a = 12 | 1758 chrec_a = 12 |
1727 chrec_b = {10, +, 1} | 1759 chrec_b = {10, +, 1} |
1728 */ | 1760 */ |
1729 | 1761 |
1730 if (tree_fold_divides_p (CHREC_RIGHT (chrec_b), difference)) | 1762 if (tree_fold_divides_p (CHREC_RIGHT (chrec_b), difference)) |
1731 { | 1763 { |
1732 HOST_WIDE_INT numiter; | 1764 HOST_WIDE_INT numiter; |
1733 struct loop *loop = get_chrec_loop (chrec_b); | 1765 struct loop *loop = get_chrec_loop (chrec_b); |
1734 | 1766 |
1736 tmp = fold_build2 (EXACT_DIV_EXPR, type, | 1768 tmp = fold_build2 (EXACT_DIV_EXPR, type, |
1737 fold_build1 (ABS_EXPR, type, difference), | 1769 fold_build1 (ABS_EXPR, type, difference), |
1738 CHREC_RIGHT (chrec_b)); | 1770 CHREC_RIGHT (chrec_b)); |
1739 *overlaps_b = conflict_fn (1, affine_fn_cst (tmp)); | 1771 *overlaps_b = conflict_fn (1, affine_fn_cst (tmp)); |
1740 *last_conflicts = integer_one_node; | 1772 *last_conflicts = integer_one_node; |
1741 | 1773 |
1742 | 1774 |
1743 /* Perform weak-zero siv test to see if overlap is | 1775 /* Perform weak-zero siv test to see if overlap is |
1744 outside the loop bounds. */ | 1776 outside the loop bounds. */ |
1745 numiter = estimated_loop_iterations_int (loop, false); | 1777 numiter = estimated_loop_iterations_int (loop, false); |
1746 | 1778 |
1752 *overlaps_a = conflict_fn_no_dependence (); | 1784 *overlaps_a = conflict_fn_no_dependence (); |
1753 *overlaps_b = conflict_fn_no_dependence (); | 1785 *overlaps_b = conflict_fn_no_dependence (); |
1754 *last_conflicts = integer_zero_node; | 1786 *last_conflicts = integer_zero_node; |
1755 dependence_stats.num_siv_independent++; | 1787 dependence_stats.num_siv_independent++; |
1756 return; | 1788 return; |
1757 } | 1789 } |
1758 dependence_stats.num_siv_dependent++; | 1790 dependence_stats.num_siv_dependent++; |
1759 return; | 1791 return; |
1760 } | 1792 } |
1761 | 1793 |
1762 /* When the step does not divide the difference, there are | 1794 /* When the step does not divide the difference, there are |
1763 no overlaps. */ | 1795 no overlaps. */ |
1764 else | 1796 else |
1765 { | 1797 { |
1766 *overlaps_a = conflict_fn_no_dependence (); | 1798 *overlaps_a = conflict_fn_no_dependence (); |
1767 *overlaps_b = conflict_fn_no_dependence (); | 1799 *overlaps_b = conflict_fn_no_dependence (); |
1768 *last_conflicts = integer_zero_node; | 1800 *last_conflicts = integer_zero_node; |
1769 dependence_stats.num_siv_independent++; | 1801 dependence_stats.num_siv_independent++; |
1770 return; | 1802 return; |
1771 } | 1803 } |
1772 } | 1804 } |
1773 | 1805 |
1774 else | 1806 else |
1775 { | 1807 { |
1776 /* Example: | 1808 /* Example: |
1777 chrec_a = 12 | 1809 chrec_a = 12 |
1778 chrec_b = {10, +, -1} | 1810 chrec_b = {10, +, -1} |
1779 | 1811 |
1780 In this case, chrec_a will not overlap with chrec_b. */ | 1812 In this case, chrec_a will not overlap with chrec_b. */ |
1781 *overlaps_a = conflict_fn_no_dependence (); | 1813 *overlaps_a = conflict_fn_no_dependence (); |
1782 *overlaps_b = conflict_fn_no_dependence (); | 1814 *overlaps_b = conflict_fn_no_dependence (); |
1783 *last_conflicts = integer_zero_node; | 1815 *last_conflicts = integer_zero_node; |
1784 dependence_stats.num_siv_independent++; | 1816 dependence_stats.num_siv_independent++; |
1785 return; | 1817 return; |
1786 } | 1818 } |
1787 } | 1819 } |
1788 } | 1820 } |
1789 else | 1821 else |
1790 { | 1822 { |
1791 if (!chrec_is_positive (CHREC_RIGHT (chrec_b), &value2)) | 1823 if (!chrec_is_positive (CHREC_RIGHT (chrec_b), &value2)) |
1792 { | 1824 { |
1793 if (dump_file && (dump_flags & TDF_DETAILS)) | 1825 if (dump_file && (dump_flags & TDF_DETAILS)) |
1794 fprintf (dump_file, "siv test failed: chrec not positive.\n"); | 1826 fprintf (dump_file, "siv test failed: chrec not positive.\n"); |
1795 | 1827 |
1796 *overlaps_a = conflict_fn_not_known (); | 1828 *overlaps_a = conflict_fn_not_known (); |
1797 *overlaps_b = conflict_fn_not_known (); | 1829 *overlaps_b = conflict_fn_not_known (); |
1798 *last_conflicts = chrec_dont_know; | 1830 *last_conflicts = chrec_dont_know; |
1799 dependence_stats.num_siv_unimplemented++; | 1831 dependence_stats.num_siv_unimplemented++; |
1800 return; | 1832 return; |
1801 } | 1833 } |
1802 else | 1834 else |
1803 { | 1835 { |
1804 if (value2 == false) | 1836 if (value2 == false) |
1805 { | 1837 { |
1806 /* Example: | 1838 /* Example: |
1807 chrec_a = 3 | 1839 chrec_a = 3 |
1808 chrec_b = {10, +, -1} | 1840 chrec_b = {10, +, -1} |
1809 */ | 1841 */ |
1810 if (tree_fold_divides_p (CHREC_RIGHT (chrec_b), difference)) | 1842 if (tree_fold_divides_p (CHREC_RIGHT (chrec_b), difference)) |
1811 { | 1843 { |
1830 *overlaps_a = conflict_fn_no_dependence (); | 1862 *overlaps_a = conflict_fn_no_dependence (); |
1831 *overlaps_b = conflict_fn_no_dependence (); | 1863 *overlaps_b = conflict_fn_no_dependence (); |
1832 *last_conflicts = integer_zero_node; | 1864 *last_conflicts = integer_zero_node; |
1833 dependence_stats.num_siv_independent++; | 1865 dependence_stats.num_siv_independent++; |
1834 return; | 1866 return; |
1835 } | 1867 } |
1836 dependence_stats.num_siv_dependent++; | 1868 dependence_stats.num_siv_dependent++; |
1837 return; | 1869 return; |
1838 } | 1870 } |
1839 | 1871 |
1840 /* When the step does not divide the difference, there | 1872 /* When the step does not divide the difference, there |
1841 are no overlaps. */ | 1873 are no overlaps. */ |
1842 else | 1874 else |
1843 { | 1875 { |
1844 *overlaps_a = conflict_fn_no_dependence (); | 1876 *overlaps_a = conflict_fn_no_dependence (); |
1845 *overlaps_b = conflict_fn_no_dependence (); | 1877 *overlaps_b = conflict_fn_no_dependence (); |
1846 *last_conflicts = integer_zero_node; | 1878 *last_conflicts = integer_zero_node; |
1847 dependence_stats.num_siv_independent++; | 1879 dependence_stats.num_siv_independent++; |
1848 return; | 1880 return; |
1849 } | 1881 } |
1850 } | 1882 } |
1851 else | 1883 else |
1852 { | 1884 { |
1853 /* Example: | 1885 /* Example: |
1854 chrec_a = 3 | 1886 chrec_a = 3 |
1855 chrec_b = {4, +, 1} | 1887 chrec_b = {4, +, 1} |
1856 | 1888 |
1857 In this case, chrec_a will not overlap with chrec_b. */ | 1889 In this case, chrec_a will not overlap with chrec_b. */ |
1858 *overlaps_a = conflict_fn_no_dependence (); | 1890 *overlaps_a = conflict_fn_no_dependence (); |
1859 *overlaps_b = conflict_fn_no_dependence (); | 1891 *overlaps_b = conflict_fn_no_dependence (); |
1860 *last_conflicts = integer_zero_node; | 1892 *last_conflicts = integer_zero_node; |
1861 dependence_stats.num_siv_independent++; | 1893 dependence_stats.num_siv_independent++; |
1915 } | 1947 } |
1916 } | 1948 } |
1917 | 1949 |
1918 #define FLOOR_DIV(x,y) ((x) / (y)) | 1950 #define FLOOR_DIV(x,y) ((x) / (y)) |
1919 | 1951 |
1920 /* Solves the special case of the Diophantine equation: | 1952 /* Solves the special case of the Diophantine equation: |
1921 | {0, +, STEP_A}_x (OVERLAPS_A) = {0, +, STEP_B}_y (OVERLAPS_B) | 1953 | {0, +, STEP_A}_x (OVERLAPS_A) = {0, +, STEP_B}_y (OVERLAPS_B) |
1922 | 1954 |
1923 Computes the descriptions OVERLAPS_A and OVERLAPS_B. NITER is the | 1955 Computes the descriptions OVERLAPS_A and OVERLAPS_B. NITER is the |
1924 number of iterations that loops X and Y run. The overlaps will be | 1956 number of iterations that loops X and Y run. The overlaps will be |
1925 constructed as evolutions in dimension DIM. */ | 1957 constructed as evolutions in dimension DIM. */ |
1926 | 1958 |
1927 static void | 1959 static void |
1928 compute_overlap_steps_for_affine_univar (int niter, int step_a, int step_b, | 1960 compute_overlap_steps_for_affine_univar (int niter, int step_a, int step_b, |
1929 affine_fn *overlaps_a, | 1961 affine_fn *overlaps_a, |
1930 affine_fn *overlaps_b, | 1962 affine_fn *overlaps_b, |
1931 tree *last_conflicts, int dim) | 1963 tree *last_conflicts, int dim) |
1932 { | 1964 { |
1933 if (((step_a > 0 && step_b > 0) | 1965 if (((step_a > 0 && step_b > 0) |
1934 || (step_a < 0 && step_b < 0))) | 1966 || (step_a < 0 && step_b < 0))) |
1935 { | 1967 { |
1948 *last_conflicts = build_int_cst (NULL_TREE, last_conflict); | 1980 *last_conflicts = build_int_cst (NULL_TREE, last_conflict); |
1949 } | 1981 } |
1950 else | 1982 else |
1951 *last_conflicts = chrec_dont_know; | 1983 *last_conflicts = chrec_dont_know; |
1952 | 1984 |
1953 *overlaps_a = affine_fn_univar (integer_zero_node, dim, | 1985 *overlaps_a = affine_fn_univar (integer_zero_node, dim, |
1954 build_int_cst (NULL_TREE, | 1986 build_int_cst (NULL_TREE, |
1955 step_overlaps_a)); | 1987 step_overlaps_a)); |
1956 *overlaps_b = affine_fn_univar (integer_zero_node, dim, | 1988 *overlaps_b = affine_fn_univar (integer_zero_node, dim, |
1957 build_int_cst (NULL_TREE, | 1989 build_int_cst (NULL_TREE, |
1958 step_overlaps_b)); | 1990 step_overlaps_b)); |
1959 } | 1991 } |
1960 | 1992 |
1961 else | 1993 else |
1962 { | 1994 { |
1966 } | 1998 } |
1967 } | 1999 } |
1968 | 2000 |
1969 /* Solves the special case of a Diophantine equation where CHREC_A is | 2001 /* Solves the special case of a Diophantine equation where CHREC_A is |
1970 an affine bivariate function, and CHREC_B is an affine univariate | 2002 an affine bivariate function, and CHREC_B is an affine univariate |
1971 function. For example, | 2003 function. For example, |
1972 | 2004 |
1973 | {{0, +, 1}_x, +, 1335}_y = {0, +, 1336}_z | 2005 | {{0, +, 1}_x, +, 1335}_y = {0, +, 1336}_z |
1974 | 2006 |
1975 has the following overlapping functions: | 2007 has the following overlapping functions: |
1976 | 2008 |
1977 | x (t, u, v) = {{0, +, 1336}_t, +, 1}_v | 2009 | x (t, u, v) = {{0, +, 1336}_t, +, 1}_v |
1978 | y (t, u, v) = {{0, +, 1336}_u, +, 1}_v | 2010 | y (t, u, v) = {{0, +, 1336}_u, +, 1}_v |
1979 | z (t, u, v) = {{{0, +, 1}_t, +, 1335}_u, +, 1}_v | 2011 | z (t, u, v) = {{{0, +, 1}_t, +, 1335}_u, +, 1}_v |
1980 | 2012 |
1981 FORNOW: This is a specialized implementation for a case occurring in | 2013 FORNOW: This is a specialized implementation for a case occurring in |
1982 a common benchmark. Implement the general algorithm. */ | 2014 a common benchmark. Implement the general algorithm. */ |
1983 | 2015 |
1984 static void | 2016 static void |
1985 compute_overlap_steps_for_affine_1_2 (tree chrec_a, tree chrec_b, | 2017 compute_overlap_steps_for_affine_1_2 (tree chrec_a, tree chrec_b, |
1986 conflict_function **overlaps_a, | 2018 conflict_function **overlaps_a, |
1987 conflict_function **overlaps_b, | 2019 conflict_function **overlaps_b, |
1988 tree *last_conflicts) | 2020 tree *last_conflicts) |
1989 { | 2021 { |
1990 bool xz_p, yz_p, xyz_p; | 2022 bool xz_p, yz_p, xyz_p; |
1991 int step_x, step_y, step_z; | 2023 int step_x, step_y, step_z; |
1992 HOST_WIDE_INT niter_x, niter_y, niter_z, niter; | 2024 HOST_WIDE_INT niter_x, niter_y, niter_z, niter; |
1998 | 2030 |
1999 step_x = int_cst_value (CHREC_RIGHT (CHREC_LEFT (chrec_a))); | 2031 step_x = int_cst_value (CHREC_RIGHT (CHREC_LEFT (chrec_a))); |
2000 step_y = int_cst_value (CHREC_RIGHT (chrec_a)); | 2032 step_y = int_cst_value (CHREC_RIGHT (chrec_a)); |
2001 step_z = int_cst_value (CHREC_RIGHT (chrec_b)); | 2033 step_z = int_cst_value (CHREC_RIGHT (chrec_b)); |
2002 | 2034 |
2003 niter_x = | 2035 niter_x = |
2004 estimated_loop_iterations_int (get_chrec_loop (CHREC_LEFT (chrec_a)), | 2036 estimated_loop_iterations_int (get_chrec_loop (CHREC_LEFT (chrec_a)), |
2005 false); | 2037 false); |
2006 niter_y = estimated_loop_iterations_int (get_chrec_loop (chrec_a), false); | 2038 niter_y = estimated_loop_iterations_int (get_chrec_loop (chrec_a), false); |
2007 niter_z = estimated_loop_iterations_int (get_chrec_loop (chrec_b), false); | 2039 niter_z = estimated_loop_iterations_int (get_chrec_loop (chrec_b), false); |
2008 | 2040 |
2009 if (niter_x < 0 || niter_y < 0 || niter_z < 0) | 2041 if (niter_x < 0 || niter_y < 0 || niter_z < 0) |
2010 { | 2042 { |
2011 if (dump_file && (dump_flags & TDF_DETAILS)) | 2043 if (dump_file && (dump_flags & TDF_DETAILS)) |
2012 fprintf (dump_file, "overlap steps test failed: no iteration counts.\n"); | 2044 fprintf (dump_file, "overlap steps test failed: no iteration counts.\n"); |
2013 | 2045 |
2014 *overlaps_a = conflict_fn_not_known (); | 2046 *overlaps_a = conflict_fn_not_known (); |
2015 *overlaps_b = conflict_fn_not_known (); | 2047 *overlaps_b = conflict_fn_not_known (); |
2016 *last_conflicts = chrec_dont_know; | 2048 *last_conflicts = chrec_dont_know; |
2017 return; | 2049 return; |
2018 } | 2050 } |
2101 CHREC_B, that are affine functions. This function cannot handle | 2133 CHREC_B, that are affine functions. This function cannot handle |
2102 symbolic evolution functions, ie. when initial conditions are | 2134 symbolic evolution functions, ie. when initial conditions are |
2103 parameters, because it uses lambda matrices of integers. */ | 2135 parameters, because it uses lambda matrices of integers. */ |
2104 | 2136 |
2105 static void | 2137 static void |
2106 analyze_subscript_affine_affine (tree chrec_a, | 2138 analyze_subscript_affine_affine (tree chrec_a, |
2107 tree chrec_b, | 2139 tree chrec_b, |
2108 conflict_function **overlaps_a, | 2140 conflict_function **overlaps_a, |
2109 conflict_function **overlaps_b, | 2141 conflict_function **overlaps_b, |
2110 tree *last_conflicts) | 2142 tree *last_conflicts) |
2111 { | 2143 { |
2112 unsigned nb_vars_a, nb_vars_b, dim; | 2144 unsigned nb_vars_a, nb_vars_b, dim; |
2113 HOST_WIDE_INT init_a, init_b, gamma, gcd_alpha_beta; | 2145 HOST_WIDE_INT init_a, init_b, gamma, gcd_alpha_beta; |
2114 lambda_matrix A, U, S; | 2146 lambda_matrix A, U, S; |
2122 *last_conflicts = chrec_dont_know; | 2154 *last_conflicts = chrec_dont_know; |
2123 return; | 2155 return; |
2124 } | 2156 } |
2125 if (dump_file && (dump_flags & TDF_DETAILS)) | 2157 if (dump_file && (dump_flags & TDF_DETAILS)) |
2126 fprintf (dump_file, "(analyze_subscript_affine_affine \n"); | 2158 fprintf (dump_file, "(analyze_subscript_affine_affine \n"); |
2127 | 2159 |
2128 /* For determining the initial intersection, we have to solve a | 2160 /* For determining the initial intersection, we have to solve a |
2129 Diophantine equation. This is the most time consuming part. | 2161 Diophantine equation. This is the most time consuming part. |
2130 | 2162 |
2131 For answering to the question: "Is there a dependence?" we have | 2163 For answering to the question: "Is there a dependence?" we have |
2132 to prove that there exists a solution to the Diophantine | 2164 to prove that there exists a solution to the Diophantine |
2133 equation, and that the solution is in the iteration domain, | 2165 equation, and that the solution is in the iteration domain, |
2134 i.e. the solution is positive or zero, and that the solution | 2166 i.e. the solution is positive or zero, and that the solution |
2135 happens before the upper bound loop.nb_iterations. Otherwise | 2167 happens before the upper bound loop.nb_iterations. Otherwise |
2147 init_a = int_cst_value (initialize_matrix_A (A, chrec_a, 0, 1)); | 2179 init_a = int_cst_value (initialize_matrix_A (A, chrec_a, 0, 1)); |
2148 init_b = int_cst_value (initialize_matrix_A (A, chrec_b, nb_vars_a, -1)); | 2180 init_b = int_cst_value (initialize_matrix_A (A, chrec_b, nb_vars_a, -1)); |
2149 gamma = init_b - init_a; | 2181 gamma = init_b - init_a; |
2150 | 2182 |
2151 /* Don't do all the hard work of solving the Diophantine equation | 2183 /* Don't do all the hard work of solving the Diophantine equation |
2152 when we already know the solution: for example, | 2184 when we already know the solution: for example, |
2153 | {3, +, 1}_1 | 2185 | {3, +, 1}_1 |
2154 | {3, +, 4}_2 | 2186 | {3, +, 4}_2 |
2155 | gamma = 3 - 3 = 0. | 2187 | gamma = 3 - 3 = 0. |
2156 Then the first overlap occurs during the first iterations: | 2188 Then the first overlap occurs during the first iterations: |
2157 | {3, +, 1}_1 ({0, +, 4}_x) = {3, +, 4}_2 ({0, +, 1}_x) | 2189 | {3, +, 1}_1 ({0, +, 4}_x) = {3, +, 4}_2 ({0, +, 1}_x) |
2158 */ | 2190 */ |
2159 if (gamma == 0) | 2191 if (gamma == 0) |
2160 { | 2192 { |
2161 if (nb_vars_a == 1 && nb_vars_b == 1) | 2193 if (nb_vars_a == 1 && nb_vars_b == 1) |
2170 false); | 2202 false); |
2171 niter = MIN (niter_a, niter_b); | 2203 niter = MIN (niter_a, niter_b); |
2172 step_a = int_cst_value (CHREC_RIGHT (chrec_a)); | 2204 step_a = int_cst_value (CHREC_RIGHT (chrec_a)); |
2173 step_b = int_cst_value (CHREC_RIGHT (chrec_b)); | 2205 step_b = int_cst_value (CHREC_RIGHT (chrec_b)); |
2174 | 2206 |
2175 compute_overlap_steps_for_affine_univar (niter, step_a, step_b, | 2207 compute_overlap_steps_for_affine_univar (niter, step_a, step_b, |
2176 &ova, &ovb, | 2208 &ova, &ovb, |
2177 last_conflicts, 1); | 2209 last_conflicts, 1); |
2178 *overlaps_a = conflict_fn (1, ova); | 2210 *overlaps_a = conflict_fn (1, ova); |
2179 *overlaps_b = conflict_fn (1, ovb); | 2211 *overlaps_b = conflict_fn (1, ovb); |
2180 } | 2212 } |
2181 | 2213 |
2235 /* Both functions should have the same evolution sign. */ | 2267 /* Both functions should have the same evolution sign. */ |
2236 if (((A[0][0] > 0 && -A[1][0] > 0) | 2268 if (((A[0][0] > 0 && -A[1][0] > 0) |
2237 || (A[0][0] < 0 && -A[1][0] < 0))) | 2269 || (A[0][0] < 0 && -A[1][0] < 0))) |
2238 { | 2270 { |
2239 /* The solutions are given by: | 2271 /* The solutions are given by: |
2240 | | 2272 | |
2241 | [GAMMA/GCD_ALPHA_BETA t].[u11 u12] = [x0] | 2273 | [GAMMA/GCD_ALPHA_BETA t].[u11 u12] = [x0] |
2242 | [u21 u22] [y0] | 2274 | [u21 u22] [y0] |
2243 | 2275 |
2244 For a given integer t. Using the following variables, | 2276 For a given integer t. Using the following variables, |
2245 | 2277 |
2246 | i0 = u11 * gamma / gcd_alpha_beta | 2278 | i0 = u11 * gamma / gcd_alpha_beta |
2247 | j0 = u12 * gamma / gcd_alpha_beta | 2279 | j0 = u12 * gamma / gcd_alpha_beta |
2248 | i1 = u21 | 2280 | i1 = u21 |
2249 | j1 = u22 | 2281 | j1 = u22 |
2250 | 2282 |
2251 the solutions are: | 2283 the solutions are: |
2252 | 2284 |
2253 | x0 = i0 + i1 * t, | 2285 | x0 = i0 + i1 * t, |
2254 | y0 = j0 + j1 * t. */ | 2286 | y0 = j0 + j1 * t. */ |
2255 HOST_WIDE_INT i0, j0, i1, j1; | 2287 HOST_WIDE_INT i0, j0, i1, j1; |
2256 | 2288 |
2257 i0 = U[0][0] * gamma / gcd_alpha_beta; | 2289 i0 = U[0][0] * gamma / gcd_alpha_beta; |
2258 j0 = U[0][1] * gamma / gcd_alpha_beta; | 2290 j0 = U[0][1] * gamma / gcd_alpha_beta; |
2260 j1 = U[1][1]; | 2292 j1 = U[1][1]; |
2261 | 2293 |
2262 if ((i1 == 0 && i0 < 0) | 2294 if ((i1 == 0 && i0 < 0) |
2263 || (j1 == 0 && j0 < 0)) | 2295 || (j1 == 0 && j0 < 0)) |
2264 { | 2296 { |
2265 /* There is no solution. | 2297 /* There is no solution. |
2266 FIXME: The case "i0 > nb_iterations, j0 > nb_iterations" | 2298 FIXME: The case "i0 > nb_iterations, j0 > nb_iterations" |
2267 falls in here, but for the moment we don't look at the | 2299 falls in here, but for the moment we don't look at the |
2268 upper bound of the iteration domain. */ | 2300 upper bound of the iteration domain. */ |
2269 *overlaps_a = conflict_fn_no_dependence (); | 2301 *overlaps_a = conflict_fn_no_dependence (); |
2270 *overlaps_b = conflict_fn_no_dependence (); | 2302 *overlaps_b = conflict_fn_no_dependence (); |
2271 *last_conflicts = integer_zero_node; | 2303 *last_conflicts = integer_zero_node; |
2272 goto end_analyze_subs_aa; | 2304 goto end_analyze_subs_aa; |
2353 *overlaps_a = conflict_fn_not_known (); | 2385 *overlaps_a = conflict_fn_not_known (); |
2354 *overlaps_b = conflict_fn_not_known (); | 2386 *overlaps_b = conflict_fn_not_known (); |
2355 *last_conflicts = chrec_dont_know; | 2387 *last_conflicts = chrec_dont_know; |
2356 } | 2388 } |
2357 | 2389 |
2358 end_analyze_subs_aa: | 2390 end_analyze_subs_aa: |
2359 if (dump_file && (dump_flags & TDF_DETAILS)) | 2391 if (dump_file && (dump_flags & TDF_DETAILS)) |
2360 { | 2392 { |
2361 fprintf (dump_file, " (overlaps_a = "); | 2393 fprintf (dump_file, " (overlaps_a = "); |
2362 dump_conflict_function (dump_file, *overlaps_a); | 2394 dump_conflict_function (dump_file, *overlaps_a); |
2363 fprintf (dump_file, ")\n (overlaps_b = "); | 2395 fprintf (dump_file, ")\n (overlaps_b = "); |
2369 | 2401 |
2370 /* Returns true when analyze_subscript_affine_affine can be used for | 2402 /* Returns true when analyze_subscript_affine_affine can be used for |
2371 determining the dependence relation between chrec_a and chrec_b, | 2403 determining the dependence relation between chrec_a and chrec_b, |
2372 that contain symbols. This function modifies chrec_a and chrec_b | 2404 that contain symbols. This function modifies chrec_a and chrec_b |
2373 such that the analysis result is the same, and such that they don't | 2405 such that the analysis result is the same, and such that they don't |
2374 contain symbols, and then can safely be passed to the analyzer. | 2406 contain symbols, and then can safely be passed to the analyzer. |
2375 | 2407 |
2376 Example: The analysis of the following tuples of evolutions produce | 2408 Example: The analysis of the following tuples of evolutions produce |
2377 the same results: {x+1, +, 1}_1 vs. {x+3, +, 1}_1, and {-2, +, 1}_1 | 2409 the same results: {x+1, +, 1}_1 vs. {x+3, +, 1}_1, and {-2, +, 1}_1 |
2378 vs. {0, +, 1}_1 | 2410 vs. {0, +, 1}_1 |
2379 | 2411 |
2380 {x+1, +, 1}_1 ({2, +, 1}_1) = {x+3, +, 1}_1 ({0, +, 1}_1) | 2412 {x+1, +, 1}_1 ({2, +, 1}_1) = {x+3, +, 1}_1 ({0, +, 1}_1) |
2381 {-2, +, 1}_1 ({2, +, 1}_1) = {0, +, 1}_1 ({0, +, 1}_1) | 2413 {-2, +, 1}_1 ({2, +, 1}_1) = {0, +, 1}_1 ({0, +, 1}_1) |
2382 */ | 2414 */ |
2383 | 2415 |
2384 static bool | 2416 static bool |
2400 return false; | 2432 return false; |
2401 | 2433 |
2402 if (dump_file && (dump_flags & TDF_DETAILS)) | 2434 if (dump_file && (dump_flags & TDF_DETAILS)) |
2403 fprintf (dump_file, "can_use_subscript_aff_aff_for_symbolic \n"); | 2435 fprintf (dump_file, "can_use_subscript_aff_aff_for_symbolic \n"); |
2404 | 2436 |
2405 *chrec_a = build_polynomial_chrec (CHREC_VARIABLE (*chrec_a), | 2437 *chrec_a = build_polynomial_chrec (CHREC_VARIABLE (*chrec_a), |
2406 diff, CHREC_RIGHT (*chrec_a)); | 2438 diff, CHREC_RIGHT (*chrec_a)); |
2407 right_b = chrec_convert (type, CHREC_RIGHT (*chrec_b), NULL); | 2439 right_b = chrec_convert (type, CHREC_RIGHT (*chrec_b), NULL); |
2408 *chrec_b = build_polynomial_chrec (CHREC_VARIABLE (*chrec_b), | 2440 *chrec_b = build_polynomial_chrec (CHREC_VARIABLE (*chrec_b), |
2409 build_int_cst (type, 0), | 2441 build_int_cst (type, 0), |
2410 right_b); | 2442 right_b); |
2417 CHREC_B. For k >= 0, the following property is verified: | 2449 CHREC_B. For k >= 0, the following property is verified: |
2418 | 2450 |
2419 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ | 2451 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ |
2420 | 2452 |
2421 static void | 2453 static void |
2422 analyze_siv_subscript (tree chrec_a, | 2454 analyze_siv_subscript (tree chrec_a, |
2423 tree chrec_b, | 2455 tree chrec_b, |
2424 conflict_function **overlaps_a, | 2456 conflict_function **overlaps_a, |
2425 conflict_function **overlaps_b, | 2457 conflict_function **overlaps_b, |
2426 tree *last_conflicts, | 2458 tree *last_conflicts, |
2427 int loop_nest_num) | 2459 int loop_nest_num) |
2428 { | 2460 { |
2429 dependence_stats.num_siv++; | 2461 dependence_stats.num_siv++; |
2430 | 2462 |
2431 if (dump_file && (dump_flags & TDF_DETAILS)) | 2463 if (dump_file && (dump_flags & TDF_DETAILS)) |
2432 fprintf (dump_file, "(analyze_siv_subscript \n"); | 2464 fprintf (dump_file, "(analyze_siv_subscript \n"); |
2433 | 2465 |
2434 if (evolution_function_is_constant_p (chrec_a) | 2466 if (evolution_function_is_constant_p (chrec_a) |
2435 && evolution_function_is_affine_in_loop (chrec_b, loop_nest_num)) | 2467 && evolution_function_is_affine_in_loop (chrec_b, loop_nest_num)) |
2436 analyze_siv_subscript_cst_affine (chrec_a, chrec_b, | 2468 analyze_siv_subscript_cst_affine (chrec_a, chrec_b, |
2437 overlaps_a, overlaps_b, last_conflicts); | 2469 overlaps_a, overlaps_b, last_conflicts); |
2438 | 2470 |
2439 else if (evolution_function_is_affine_in_loop (chrec_a, loop_nest_num) | 2471 else if (evolution_function_is_affine_in_loop (chrec_a, loop_nest_num) |
2440 && evolution_function_is_constant_p (chrec_b)) | 2472 && evolution_function_is_constant_p (chrec_b)) |
2441 analyze_siv_subscript_cst_affine (chrec_b, chrec_a, | 2473 analyze_siv_subscript_cst_affine (chrec_b, chrec_a, |
2442 overlaps_b, overlaps_a, last_conflicts); | 2474 overlaps_b, overlaps_a, last_conflicts); |
2443 | 2475 |
2444 else if (evolution_function_is_affine_in_loop (chrec_a, loop_nest_num) | 2476 else if (evolution_function_is_affine_in_loop (chrec_a, loop_nest_num) |
2445 && evolution_function_is_affine_in_loop (chrec_b, loop_nest_num)) | 2477 && evolution_function_is_affine_in_loop (chrec_b, loop_nest_num)) |
2446 { | 2478 { |
2447 if (!chrec_contains_symbols (chrec_a) | 2479 if (!chrec_contains_symbols (chrec_a) |
2448 && !chrec_contains_symbols (chrec_b)) | 2480 && !chrec_contains_symbols (chrec_b)) |
2449 { | 2481 { |
2450 analyze_subscript_affine_affine (chrec_a, chrec_b, | 2482 analyze_subscript_affine_affine (chrec_a, chrec_b, |
2451 overlaps_a, overlaps_b, | 2483 overlaps_a, overlaps_b, |
2452 last_conflicts); | 2484 last_conflicts); |
2453 | 2485 |
2454 if (CF_NOT_KNOWN_P (*overlaps_a) | 2486 if (CF_NOT_KNOWN_P (*overlaps_a) |
2455 || CF_NOT_KNOWN_P (*overlaps_b)) | 2487 || CF_NOT_KNOWN_P (*overlaps_b)) |
2456 dependence_stats.num_siv_unimplemented++; | 2488 dependence_stats.num_siv_unimplemented++; |
2458 || CF_NO_DEPENDENCE_P (*overlaps_b)) | 2490 || CF_NO_DEPENDENCE_P (*overlaps_b)) |
2459 dependence_stats.num_siv_independent++; | 2491 dependence_stats.num_siv_independent++; |
2460 else | 2492 else |
2461 dependence_stats.num_siv_dependent++; | 2493 dependence_stats.num_siv_dependent++; |
2462 } | 2494 } |
2463 else if (can_use_analyze_subscript_affine_affine (&chrec_a, | 2495 else if (can_use_analyze_subscript_affine_affine (&chrec_a, |
2464 &chrec_b)) | 2496 &chrec_b)) |
2465 { | 2497 { |
2466 analyze_subscript_affine_affine (chrec_a, chrec_b, | 2498 analyze_subscript_affine_affine (chrec_a, chrec_b, |
2467 overlaps_a, overlaps_b, | 2499 overlaps_a, overlaps_b, |
2468 last_conflicts); | 2500 last_conflicts); |
2469 | 2501 |
2470 if (CF_NOT_KNOWN_P (*overlaps_a) | 2502 if (CF_NOT_KNOWN_P (*overlaps_a) |
2471 || CF_NOT_KNOWN_P (*overlaps_b)) | 2503 || CF_NOT_KNOWN_P (*overlaps_b)) |
2472 dependence_stats.num_siv_unimplemented++; | 2504 dependence_stats.num_siv_unimplemented++; |
2488 *overlaps_a = conflict_fn_not_known (); | 2520 *overlaps_a = conflict_fn_not_known (); |
2489 *overlaps_b = conflict_fn_not_known (); | 2521 *overlaps_b = conflict_fn_not_known (); |
2490 *last_conflicts = chrec_dont_know; | 2522 *last_conflicts = chrec_dont_know; |
2491 dependence_stats.num_siv_unimplemented++; | 2523 dependence_stats.num_siv_unimplemented++; |
2492 } | 2524 } |
2493 | 2525 |
2494 if (dump_file && (dump_flags & TDF_DETAILS)) | 2526 if (dump_file && (dump_flags & TDF_DETAILS)) |
2495 fprintf (dump_file, ")\n"); | 2527 fprintf (dump_file, ")\n"); |
2496 } | 2528 } |
2497 | 2529 |
2498 /* Returns false if we can prove that the greatest common divisor of the steps | 2530 /* Returns false if we can prove that the greatest common divisor of the steps |
2527 is verified: | 2559 is verified: |
2528 | 2560 |
2529 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ | 2561 CHREC_A (*OVERLAPS_A (k)) = CHREC_B (*OVERLAPS_B (k)). */ |
2530 | 2562 |
2531 static void | 2563 static void |
2532 analyze_miv_subscript (tree chrec_a, | 2564 analyze_miv_subscript (tree chrec_a, |
2533 tree chrec_b, | 2565 tree chrec_b, |
2534 conflict_function **overlaps_a, | 2566 conflict_function **overlaps_a, |
2535 conflict_function **overlaps_b, | 2567 conflict_function **overlaps_b, |
2536 tree *last_conflicts, | 2568 tree *last_conflicts, |
2537 struct loop *loop_nest) | 2569 struct loop *loop_nest) |
2538 { | 2570 { |
2539 /* FIXME: This is a MIV subscript, not yet handled. | 2571 /* FIXME: This is a MIV subscript, not yet handled. |
2540 Example: (A[{1, +, 1}_1] vs. A[{1, +, 1}_2]) that comes from | 2572 Example: (A[{1, +, 1}_1] vs. A[{1, +, 1}_2]) that comes from |
2541 (A[i] vs. A[j]). | 2573 (A[i] vs. A[j]). |
2542 | 2574 |
2543 In the SIV test we had to solve a Diophantine equation with two | 2575 In the SIV test we had to solve a Diophantine equation with two |
2544 variables. In the MIV case we have to solve a Diophantine | 2576 variables. In the MIV case we have to solve a Diophantine |
2545 equation with 2*n variables (if the subscript uses n IVs). | 2577 equation with 2*n variables (if the subscript uses n IVs). |
2546 */ | 2578 */ |
2547 tree type, difference; | 2579 tree type, difference; |
2552 | 2584 |
2553 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); | 2585 type = signed_type_for_types (TREE_TYPE (chrec_a), TREE_TYPE (chrec_b)); |
2554 chrec_a = chrec_convert (type, chrec_a, NULL); | 2586 chrec_a = chrec_convert (type, chrec_a, NULL); |
2555 chrec_b = chrec_convert (type, chrec_b, NULL); | 2587 chrec_b = chrec_convert (type, chrec_b, NULL); |
2556 difference = chrec_fold_minus (type, chrec_a, chrec_b); | 2588 difference = chrec_fold_minus (type, chrec_a, chrec_b); |
2557 | 2589 |
2558 if (eq_evolutions_p (chrec_a, chrec_b)) | 2590 if (eq_evolutions_p (chrec_a, chrec_b)) |
2559 { | 2591 { |
2560 /* Access functions are the same: all the elements are accessed | 2592 /* Access functions are the same: all the elements are accessed |
2561 in the same order. */ | 2593 in the same order. */ |
2562 *overlaps_a = conflict_fn (1, affine_fn_cst (integer_zero_node)); | 2594 *overlaps_a = conflict_fn (1, affine_fn_cst (integer_zero_node)); |
2563 *overlaps_b = conflict_fn (1, affine_fn_cst (integer_zero_node)); | 2595 *overlaps_b = conflict_fn (1, affine_fn_cst (integer_zero_node)); |
2564 *last_conflicts = estimated_loop_iterations_tree | 2596 *last_conflicts = estimated_loop_iterations_tree |
2565 (get_chrec_loop (chrec_a), true); | 2597 (get_chrec_loop (chrec_a), true); |
2566 dependence_stats.num_miv_dependent++; | 2598 dependence_stats.num_miv_dependent++; |
2567 } | 2599 } |
2568 | 2600 |
2569 else if (evolution_function_is_constant_p (difference) | 2601 else if (evolution_function_is_constant_p (difference) |
2570 /* For the moment, the following is verified: | 2602 /* For the moment, the following is verified: |
2571 evolution_function_is_affine_multivariate_p (chrec_a, | 2603 evolution_function_is_affine_multivariate_p (chrec_a, |
2572 loop_nest->num) */ | 2604 loop_nest->num) */ |
2573 && !gcd_of_steps_may_divide_p (chrec_a, difference)) | 2605 && !gcd_of_steps_may_divide_p (chrec_a, difference)) |
2574 { | 2606 { |
2575 /* testsuite/.../ssa-chrec-33.c | 2607 /* testsuite/.../ssa-chrec-33.c |
2576 {{21, +, 2}_1, +, -2}_2 vs. {{20, +, 2}_1, +, -2}_2 | 2608 {{21, +, 2}_1, +, -2}_2 vs. {{20, +, 2}_1, +, -2}_2 |
2577 | 2609 |
2578 The difference is 1, and all the evolution steps are multiples | 2610 The difference is 1, and all the evolution steps are multiples |
2579 of 2, consequently there are no overlapping elements. */ | 2611 of 2, consequently there are no overlapping elements. */ |
2580 *overlaps_a = conflict_fn_no_dependence (); | 2612 *overlaps_a = conflict_fn_no_dependence (); |
2581 *overlaps_b = conflict_fn_no_dependence (); | 2613 *overlaps_b = conflict_fn_no_dependence (); |
2582 *last_conflicts = integer_zero_node; | 2614 *last_conflicts = integer_zero_node; |
2583 dependence_stats.num_miv_independent++; | 2615 dependence_stats.num_miv_independent++; |
2584 } | 2616 } |
2585 | 2617 |
2586 else if (evolution_function_is_affine_multivariate_p (chrec_a, loop_nest->num) | 2618 else if (evolution_function_is_affine_multivariate_p (chrec_a, loop_nest->num) |
2587 && !chrec_contains_symbols (chrec_a) | 2619 && !chrec_contains_symbols (chrec_a) |
2588 && evolution_function_is_affine_multivariate_p (chrec_b, loop_nest->num) | 2620 && evolution_function_is_affine_multivariate_p (chrec_b, loop_nest->num) |
2589 && !chrec_contains_symbols (chrec_b)) | 2621 && !chrec_contains_symbols (chrec_b)) |
2590 { | 2622 { |
2591 /* testsuite/.../ssa-chrec-35.c | 2623 /* testsuite/.../ssa-chrec-35.c |
2592 {0, +, 1}_2 vs. {0, +, 1}_3 | 2624 {0, +, 1}_2 vs. {0, +, 1}_3 |
2593 the overlapping elements are respectively located at iterations: | 2625 the overlapping elements are respectively located at iterations: |
2594 {0, +, 1}_x and {0, +, 1}_x, | 2626 {0, +, 1}_x and {0, +, 1}_x, |
2595 in other words, we have the equality: | 2627 in other words, we have the equality: |
2596 {0, +, 1}_2 ({0, +, 1}_x) = {0, +, 1}_3 ({0, +, 1}_x) | 2628 {0, +, 1}_2 ({0, +, 1}_x) = {0, +, 1}_3 ({0, +, 1}_x) |
2597 | 2629 |
2598 Other examples: | 2630 Other examples: |
2599 {{0, +, 1}_1, +, 2}_2 ({0, +, 1}_x, {0, +, 1}_y) = | 2631 {{0, +, 1}_1, +, 2}_2 ({0, +, 1}_x, {0, +, 1}_y) = |
2600 {0, +, 1}_1 ({{0, +, 1}_x, +, 2}_y) | 2632 {0, +, 1}_1 ({{0, +, 1}_x, +, 2}_y) |
2601 | 2633 |
2602 {{0, +, 2}_1, +, 3}_2 ({0, +, 1}_y, {0, +, 1}_x) = | 2634 {{0, +, 2}_1, +, 3}_2 ({0, +, 1}_y, {0, +, 1}_x) = |
2603 {{0, +, 3}_1, +, 2}_2 ({0, +, 1}_x, {0, +, 1}_y) | 2635 {{0, +, 3}_1, +, 2}_2 ({0, +, 1}_x, {0, +, 1}_y) |
2604 */ | 2636 */ |
2605 analyze_subscript_affine_affine (chrec_a, chrec_b, | 2637 analyze_subscript_affine_affine (chrec_a, chrec_b, |
2606 overlaps_a, overlaps_b, last_conflicts); | 2638 overlaps_a, overlaps_b, last_conflicts); |
2607 | 2639 |
2608 if (CF_NOT_KNOWN_P (*overlaps_a) | 2640 if (CF_NOT_KNOWN_P (*overlaps_a) |
2609 || CF_NOT_KNOWN_P (*overlaps_b)) | 2641 || CF_NOT_KNOWN_P (*overlaps_b)) |
2610 dependence_stats.num_miv_unimplemented++; | 2642 dependence_stats.num_miv_unimplemented++; |
2612 || CF_NO_DEPENDENCE_P (*overlaps_b)) | 2644 || CF_NO_DEPENDENCE_P (*overlaps_b)) |
2613 dependence_stats.num_miv_independent++; | 2645 dependence_stats.num_miv_independent++; |
2614 else | 2646 else |
2615 dependence_stats.num_miv_dependent++; | 2647 dependence_stats.num_miv_dependent++; |
2616 } | 2648 } |
2617 | 2649 |
2618 else | 2650 else |
2619 { | 2651 { |
2620 /* When the analysis is too difficult, answer "don't know". */ | 2652 /* When the analysis is too difficult, answer "don't know". */ |
2621 if (dump_file && (dump_flags & TDF_DETAILS)) | 2653 if (dump_file && (dump_flags & TDF_DETAILS)) |
2622 fprintf (dump_file, "analyze_miv_subscript test failed: unimplemented.\n"); | 2654 fprintf (dump_file, "analyze_miv_subscript test failed: unimplemented.\n"); |
2624 *overlaps_a = conflict_fn_not_known (); | 2656 *overlaps_a = conflict_fn_not_known (); |
2625 *overlaps_b = conflict_fn_not_known (); | 2657 *overlaps_b = conflict_fn_not_known (); |
2626 *last_conflicts = chrec_dont_know; | 2658 *last_conflicts = chrec_dont_know; |
2627 dependence_stats.num_miv_unimplemented++; | 2659 dependence_stats.num_miv_unimplemented++; |
2628 } | 2660 } |
2629 | 2661 |
2630 if (dump_file && (dump_flags & TDF_DETAILS)) | 2662 if (dump_file && (dump_flags & TDF_DETAILS)) |
2631 fprintf (dump_file, ")\n"); | 2663 fprintf (dump_file, ")\n"); |
2632 } | 2664 } |
2633 | 2665 |
2634 /* Determines the iterations for which CHREC_A is equal to CHREC_B in | 2666 /* Determines the iterations for which CHREC_A is equal to CHREC_B in |
2635 with respect to LOOP_NEST. OVERLAP_ITERATIONS_A and | 2667 with respect to LOOP_NEST. OVERLAP_ITERATIONS_A and |
2636 OVERLAP_ITERATIONS_B are initialized with two functions that | 2668 OVERLAP_ITERATIONS_B are initialized with two functions that |
2637 describe the iterations that contain conflicting elements. | 2669 describe the iterations that contain conflicting elements. |
2638 | 2670 |
2639 Remark: For an integer k >= 0, the following equality is true: | 2671 Remark: For an integer k >= 0, the following equality is true: |
2640 | 2672 |
2641 CHREC_A (OVERLAP_ITERATIONS_A (k)) == CHREC_B (OVERLAP_ITERATIONS_B (k)). | 2673 CHREC_A (OVERLAP_ITERATIONS_A (k)) == CHREC_B (OVERLAP_ITERATIONS_B (k)). |
2642 */ | 2674 */ |
2643 | 2675 |
2644 static void | 2676 static void |
2645 analyze_overlapping_iterations (tree chrec_a, | 2677 analyze_overlapping_iterations (tree chrec_a, |
2646 tree chrec_b, | 2678 tree chrec_b, |
2647 conflict_function **overlap_iterations_a, | 2679 conflict_function **overlap_iterations_a, |
2648 conflict_function **overlap_iterations_b, | 2680 conflict_function **overlap_iterations_b, |
2649 tree *last_conflicts, struct loop *loop_nest) | 2681 tree *last_conflicts, struct loop *loop_nest) |
2650 { | 2682 { |
2651 unsigned int lnn = loop_nest->num; | 2683 unsigned int lnn = loop_nest->num; |
2652 | 2684 |
2653 dependence_stats.num_subscript_tests++; | 2685 dependence_stats.num_subscript_tests++; |
2654 | 2686 |
2655 if (dump_file && (dump_flags & TDF_DETAILS)) | 2687 if (dump_file && (dump_flags & TDF_DETAILS)) |
2656 { | 2688 { |
2657 fprintf (dump_file, "(analyze_overlapping_iterations \n"); | 2689 fprintf (dump_file, "(analyze_overlapping_iterations \n"); |
2658 fprintf (dump_file, " (chrec_a = "); | 2690 fprintf (dump_file, " (chrec_a = "); |
2659 print_generic_expr (dump_file, chrec_a, 0); | 2691 print_generic_expr (dump_file, chrec_a, 0); |
2666 || chrec_b == NULL_TREE | 2698 || chrec_b == NULL_TREE |
2667 || chrec_contains_undetermined (chrec_a) | 2699 || chrec_contains_undetermined (chrec_a) |
2668 || chrec_contains_undetermined (chrec_b)) | 2700 || chrec_contains_undetermined (chrec_b)) |
2669 { | 2701 { |
2670 dependence_stats.num_subscript_undetermined++; | 2702 dependence_stats.num_subscript_undetermined++; |
2671 | 2703 |
2672 *overlap_iterations_a = conflict_fn_not_known (); | 2704 *overlap_iterations_a = conflict_fn_not_known (); |
2673 *overlap_iterations_b = conflict_fn_not_known (); | 2705 *overlap_iterations_b = conflict_fn_not_known (); |
2674 } | 2706 } |
2675 | 2707 |
2676 /* If they are the same chrec, and are affine, they overlap | 2708 /* If they are the same chrec, and are affine, they overlap |
2677 on every iteration. */ | 2709 on every iteration. */ |
2678 else if (eq_evolutions_p (chrec_a, chrec_b) | 2710 else if (eq_evolutions_p (chrec_a, chrec_b) |
2679 && evolution_function_is_affine_multivariate_p (chrec_a, lnn)) | 2711 && evolution_function_is_affine_multivariate_p (chrec_a, lnn)) |
2680 { | 2712 { |
2681 dependence_stats.num_same_subscript_function++; | 2713 dependence_stats.num_same_subscript_function++; |
2684 *last_conflicts = chrec_dont_know; | 2716 *last_conflicts = chrec_dont_know; |
2685 } | 2717 } |
2686 | 2718 |
2687 /* If they aren't the same, and aren't affine, we can't do anything | 2719 /* If they aren't the same, and aren't affine, we can't do anything |
2688 yet. */ | 2720 yet. */ |
2689 else if ((chrec_contains_symbols (chrec_a) | 2721 else if ((chrec_contains_symbols (chrec_a) |
2690 || chrec_contains_symbols (chrec_b)) | 2722 || chrec_contains_symbols (chrec_b)) |
2691 && (!evolution_function_is_affine_multivariate_p (chrec_a, lnn) | 2723 && (!evolution_function_is_affine_multivariate_p (chrec_a, lnn) |
2692 || !evolution_function_is_affine_multivariate_p (chrec_b, lnn))) | 2724 || !evolution_function_is_affine_multivariate_p (chrec_b, lnn))) |
2693 { | 2725 { |
2694 dependence_stats.num_subscript_undetermined++; | 2726 dependence_stats.num_subscript_undetermined++; |
2695 *overlap_iterations_a = conflict_fn_not_known (); | 2727 *overlap_iterations_a = conflict_fn_not_known (); |
2696 *overlap_iterations_b = conflict_fn_not_known (); | 2728 *overlap_iterations_b = conflict_fn_not_known (); |
2697 } | 2729 } |
2698 | 2730 |
2699 else if (ziv_subscript_p (chrec_a, chrec_b)) | 2731 else if (ziv_subscript_p (chrec_a, chrec_b)) |
2700 analyze_ziv_subscript (chrec_a, chrec_b, | 2732 analyze_ziv_subscript (chrec_a, chrec_b, |
2701 overlap_iterations_a, overlap_iterations_b, | 2733 overlap_iterations_a, overlap_iterations_b, |
2702 last_conflicts); | 2734 last_conflicts); |
2703 | 2735 |
2704 else if (siv_subscript_p (chrec_a, chrec_b)) | 2736 else if (siv_subscript_p (chrec_a, chrec_b)) |
2705 analyze_siv_subscript (chrec_a, chrec_b, | 2737 analyze_siv_subscript (chrec_a, chrec_b, |
2706 overlap_iterations_a, overlap_iterations_b, | 2738 overlap_iterations_a, overlap_iterations_b, |
2707 last_conflicts, lnn); | 2739 last_conflicts, lnn); |
2708 | 2740 |
2709 else | 2741 else |
2710 analyze_miv_subscript (chrec_a, chrec_b, | 2742 analyze_miv_subscript (chrec_a, chrec_b, |
2711 overlap_iterations_a, overlap_iterations_b, | 2743 overlap_iterations_a, overlap_iterations_b, |
2712 last_conflicts, loop_nest); | 2744 last_conflicts, loop_nest); |
2713 | 2745 |
2714 if (dump_file && (dump_flags & TDF_DETAILS)) | 2746 if (dump_file && (dump_flags & TDF_DETAILS)) |
2715 { | 2747 { |
2716 fprintf (dump_file, " (overlap_iterations_a = "); | 2748 fprintf (dump_file, " (overlap_iterations_a = "); |
2717 dump_conflict_function (dump_file, *overlap_iterations_a); | 2749 dump_conflict_function (dump_file, *overlap_iterations_a); |
2718 fprintf (dump_file, ")\n (overlap_iterations_b = "); | 2750 fprintf (dump_file, ")\n (overlap_iterations_b = "); |
2808 } | 2840 } |
2809 | 2841 |
2810 access_fn_a = DR_ACCESS_FN (ddr_a, i); | 2842 access_fn_a = DR_ACCESS_FN (ddr_a, i); |
2811 access_fn_b = DR_ACCESS_FN (ddr_b, i); | 2843 access_fn_b = DR_ACCESS_FN (ddr_b, i); |
2812 | 2844 |
2813 if (TREE_CODE (access_fn_a) == POLYNOMIAL_CHREC | 2845 if (TREE_CODE (access_fn_a) == POLYNOMIAL_CHREC |
2814 && TREE_CODE (access_fn_b) == POLYNOMIAL_CHREC) | 2846 && TREE_CODE (access_fn_b) == POLYNOMIAL_CHREC) |
2815 { | 2847 { |
2816 int dist, index; | 2848 int dist, index; |
2817 int index_a = index_in_loop_nest (CHREC_VARIABLE (access_fn_a), | 2849 int index_a = index_in_loop_nest (CHREC_VARIABLE (access_fn_a), |
2818 DDR_LOOP_NEST (ddr)); | 2850 DDR_LOOP_NEST (ddr)); |
2833 if (chrec_contains_undetermined (SUB_DISTANCE (subscript))) | 2865 if (chrec_contains_undetermined (SUB_DISTANCE (subscript))) |
2834 { | 2866 { |
2835 non_affine_dependence_relation (ddr); | 2867 non_affine_dependence_relation (ddr); |
2836 return false; | 2868 return false; |
2837 } | 2869 } |
2838 | 2870 |
2839 dist = int_cst_value (SUB_DISTANCE (subscript)); | 2871 dist = int_cst_value (SUB_DISTANCE (subscript)); |
2840 | 2872 |
2841 /* This is the subscript coupling test. If we have already | 2873 /* This is the subscript coupling test. If we have already |
2842 recorded a distance for this loop (a distance coming from | 2874 recorded a distance for this loop (a distance coming from |
2843 another subscript), it should be the same. For example, | 2875 another subscript), it should be the same. For example, |
3113 | { | 3145 | { |
3114 | t = T[j+1][i-1]; // A | 3146 | t = T[j+1][i-1]; // A |
3115 | T[j][i] = t + 2; // B | 3147 | T[j][i] = t + 2; // B |
3116 | } | 3148 | } |
3117 | 3149 |
3118 the vectors are: | 3150 the vectors are: |
3119 (0, 1, -1) | 3151 (0, 1, -1) |
3120 (1, 1, -1) | 3152 (1, 1, -1) |
3121 (1, -1, 1) | 3153 (1, -1, 1) |
3122 */ | 3154 */ |
3123 if (DDR_NB_LOOPS (ddr) > 1) | 3155 if (DDR_NB_LOOPS (ddr) > 1) |
3235 for (i = 0; VEC_iterate (subscript_p, DDR_SUBSCRIPTS (ddr), i, subscript); | 3267 for (i = 0; VEC_iterate (subscript_p, DDR_SUBSCRIPTS (ddr), i, subscript); |
3236 i++) | 3268 i++) |
3237 { | 3269 { |
3238 conflict_function *overlaps_a, *overlaps_b; | 3270 conflict_function *overlaps_a, *overlaps_b; |
3239 | 3271 |
3240 analyze_overlapping_iterations (DR_ACCESS_FN (dra, i), | 3272 analyze_overlapping_iterations (DR_ACCESS_FN (dra, i), |
3241 DR_ACCESS_FN (drb, i), | 3273 DR_ACCESS_FN (drb, i), |
3242 &overlaps_a, &overlaps_b, | 3274 &overlaps_a, &overlaps_b, |
3243 &last_conflicts, loop_nest); | 3275 &last_conflicts, loop_nest); |
3244 | 3276 |
3245 if (CF_NOT_KNOWN_P (overlaps_a) | 3277 if (CF_NOT_KNOWN_P (overlaps_a) |
3246 || CF_NOT_KNOWN_P (overlaps_b)) | 3278 || CF_NOT_KNOWN_P (overlaps_b)) |
3247 { | 3279 { |
3282 | 3314 |
3283 static void | 3315 static void |
3284 subscript_dependence_tester (struct data_dependence_relation *ddr, | 3316 subscript_dependence_tester (struct data_dependence_relation *ddr, |
3285 struct loop *loop_nest) | 3317 struct loop *loop_nest) |
3286 { | 3318 { |
3287 | 3319 |
3288 if (dump_file && (dump_flags & TDF_DETAILS)) | 3320 if (dump_file && (dump_flags & TDF_DETAILS)) |
3289 fprintf (dump_file, "(subscript_dependence_tester \n"); | 3321 fprintf (dump_file, "(subscript_dependence_tester \n"); |
3290 | 3322 |
3291 if (subscript_dependence_tester_1 (ddr, DDR_A (ddr), DDR_B (ddr), loop_nest)) | 3323 if (subscript_dependence_tester_1 (ddr, DDR_A (ddr), DDR_B (ddr), loop_nest)) |
3292 dependence_stats.num_dependence_dependent++; | 3324 dependence_stats.num_dependence_dependent++; |
3293 | 3325 |
3294 compute_subscript_distance (ddr); | 3326 compute_subscript_distance (ddr); |
3295 if (build_classic_dist_vector (ddr, loop_nest)) | 3327 if (build_classic_dist_vector (ddr, loop_nest)) |
3300 } | 3332 } |
3301 | 3333 |
3302 /* Returns true when all the access functions of A are affine or | 3334 /* Returns true when all the access functions of A are affine or |
3303 constant with respect to LOOP_NEST. */ | 3335 constant with respect to LOOP_NEST. */ |
3304 | 3336 |
3305 static bool | 3337 static bool |
3306 access_functions_are_affine_or_constant_p (const struct data_reference *a, | 3338 access_functions_are_affine_or_constant_p (const struct data_reference *a, |
3307 const struct loop *loop_nest) | 3339 const struct loop *loop_nest) |
3308 { | 3340 { |
3309 unsigned int i; | 3341 unsigned int i; |
3310 VEC(tree,heap) *fns = DR_ACCESS_FNS (a); | 3342 VEC(tree,heap) *fns = DR_ACCESS_FNS (a); |
3312 | 3344 |
3313 for (i = 0; VEC_iterate (tree, fns, i, t); i++) | 3345 for (i = 0; VEC_iterate (tree, fns, i, t); i++) |
3314 if (!evolution_function_is_invariant_p (t, loop_nest->num) | 3346 if (!evolution_function_is_invariant_p (t, loop_nest->num) |
3315 && !evolution_function_is_affine_multivariate_p (t, loop_nest->num)) | 3347 && !evolution_function_is_affine_multivariate_p (t, loop_nest->num)) |
3316 return false; | 3348 return false; |
3317 | 3349 |
3318 return true; | 3350 return true; |
3319 } | |
3320 | |
3321 /* Return true if we can create an affine data-ref for OP in STMT. */ | |
3322 | |
3323 bool | |
3324 stmt_simple_memref_p (struct loop *loop, gimple stmt, tree op) | |
3325 { | |
3326 data_reference_p dr; | |
3327 bool res = true; | |
3328 | |
3329 dr = create_data_ref (loop, op, stmt, true); | |
3330 if (!access_functions_are_affine_or_constant_p (dr, loop)) | |
3331 res = false; | |
3332 | |
3333 free_data_ref (dr); | |
3334 return res; | |
3335 } | 3351 } |
3336 | 3352 |
3337 /* Initializes an equation for an OMEGA problem using the information | 3353 /* Initializes an equation for an OMEGA problem using the information |
3338 contained in the ACCESS_FUN. Returns true when the operation | 3354 contained in the ACCESS_FUN. Returns true when the operation |
3339 succeeded. | 3355 succeeded. |
3345 dependence accesses. OFFSET is set either to 0 for the first n variables, | 3361 dependence accesses. OFFSET is set either to 0 for the first n variables, |
3346 then it is set to n. | 3362 then it is set to n. |
3347 ACCESS_FUN is expected to be an affine chrec. */ | 3363 ACCESS_FUN is expected to be an affine chrec. */ |
3348 | 3364 |
3349 static bool | 3365 static bool |
3350 init_omega_eq_with_af (omega_pb pb, unsigned eq, | 3366 init_omega_eq_with_af (omega_pb pb, unsigned eq, |
3351 unsigned int offset, tree access_fun, | 3367 unsigned int offset, tree access_fun, |
3352 struct data_dependence_relation *ddr) | 3368 struct data_dependence_relation *ddr) |
3353 { | 3369 { |
3354 switch (TREE_CODE (access_fun)) | 3370 switch (TREE_CODE (access_fun)) |
3355 { | 3371 { |
3356 case POLYNOMIAL_CHREC: | 3372 case POLYNOMIAL_CHREC: |
3368 | 3384 |
3369 /* Compute the innermost loop index. */ | 3385 /* Compute the innermost loop index. */ |
3370 DDR_INNER_LOOP (ddr) = MAX (DDR_INNER_LOOP (ddr), var_idx); | 3386 DDR_INNER_LOOP (ddr) = MAX (DDR_INNER_LOOP (ddr), var_idx); |
3371 | 3387 |
3372 if (offset == 0) | 3388 if (offset == 0) |
3373 pb->eqs[eq].coef[var_idx + DDR_NB_LOOPS (ddr) + 1] | 3389 pb->eqs[eq].coef[var_idx + DDR_NB_LOOPS (ddr) + 1] |
3374 += int_cst_value (right); | 3390 += int_cst_value (right); |
3375 | 3391 |
3376 switch (TREE_CODE (left)) | 3392 switch (TREE_CODE (left)) |
3377 { | 3393 { |
3378 case POLYNOMIAL_CHREC: | 3394 case POLYNOMIAL_CHREC: |
3411 enum omega_result res; | 3427 enum omega_result res; |
3412 | 3428 |
3413 /* Set a new problem for each loop in the nest. The basis is the | 3429 /* Set a new problem for each loop in the nest. The basis is the |
3414 problem that we have initialized until now. On top of this we | 3430 problem that we have initialized until now. On top of this we |
3415 add new constraints. */ | 3431 add new constraints. */ |
3416 for (i = 0; i <= DDR_INNER_LOOP (ddr) | 3432 for (i = 0; i <= DDR_INNER_LOOP (ddr) |
3417 && VEC_iterate (loop_p, DDR_LOOP_NEST (ddr), i, loopi); i++) | 3433 && VEC_iterate (loop_p, DDR_LOOP_NEST (ddr), i, loopi); i++) |
3418 { | 3434 { |
3419 int dist = 0; | 3435 int dist = 0; |
3420 omega_pb copy = omega_alloc_problem (2 * DDR_NB_LOOPS (ddr), | 3436 omega_pb copy = omega_alloc_problem (2 * DDR_NB_LOOPS (ddr), |
3421 DDR_NB_LOOPS (ddr)); | 3437 DDR_NB_LOOPS (ddr)); |
3435 copy->geqs[geq].coef[i + 1] = 1; | 3451 copy->geqs[geq].coef[i + 1] = 1; |
3436 | 3452 |
3437 /* Reduce the constraint system, and test that the current | 3453 /* Reduce the constraint system, and test that the current |
3438 problem is feasible. */ | 3454 problem is feasible. */ |
3439 res = omega_simplify_problem (copy); | 3455 res = omega_simplify_problem (copy); |
3440 if (res == omega_false | 3456 if (res == omega_false |
3441 || res == omega_unknown | 3457 || res == omega_unknown |
3442 || copy->num_geqs > (int) DDR_NB_LOOPS (ddr)) | 3458 || copy->num_geqs > (int) DDR_NB_LOOPS (ddr)) |
3443 goto next_problem; | 3459 goto next_problem; |
3444 | 3460 |
3445 for (eq = 0; eq < copy->num_subs; eq++) | 3461 for (eq = 0; eq < copy->num_subs; eq++) |
3464 eq = omega_add_zero_eq (copy, omega_black); | 3480 eq = omega_add_zero_eq (copy, omega_black); |
3465 copy->eqs[eq].coef[i + 1] = 1; | 3481 copy->eqs[eq].coef[i + 1] = 1; |
3466 copy->eqs[eq].coef[0] = -1; | 3482 copy->eqs[eq].coef[0] = -1; |
3467 | 3483 |
3468 res = omega_simplify_problem (copy); | 3484 res = omega_simplify_problem (copy); |
3469 if (res == omega_false | 3485 if (res == omega_false |
3470 || res == omega_unknown | 3486 || res == omega_unknown |
3471 || copy->num_geqs > (int) DDR_NB_LOOPS (ddr)) | 3487 || copy->num_geqs > (int) DDR_NB_LOOPS (ddr)) |
3472 goto next_problem; | 3488 goto next_problem; |
3473 | 3489 |
3474 for (eq = 0; eq < copy->num_subs; eq++) | 3490 for (eq = 0; eq < copy->num_subs; eq++) |
3544 constraints cannot be built: answer "don't know". */ | 3560 constraints cannot be built: answer "don't know". */ |
3545 return false; | 3561 return false; |
3546 | 3562 |
3547 /* GCD test. */ | 3563 /* GCD test. */ |
3548 if (DDR_NB_LOOPS (ddr) != 0 && pb->eqs[eq].coef[0] | 3564 if (DDR_NB_LOOPS (ddr) != 0 && pb->eqs[eq].coef[0] |
3549 && !int_divides_p (lambda_vector_gcd | 3565 && !int_divides_p (lambda_vector_gcd |
3550 ((lambda_vector) &(pb->eqs[eq].coef[1]), | 3566 ((lambda_vector) &(pb->eqs[eq].coef[1]), |
3551 2 * DDR_NB_LOOPS (ddr)), | 3567 2 * DDR_NB_LOOPS (ddr)), |
3552 pb->eqs[eq].coef[0])) | 3568 pb->eqs[eq].coef[0])) |
3553 { | 3569 { |
3554 /* There is no dependence. */ | 3570 /* There is no dependence. */ |
3593 - coef[0] is the constant | 3609 - coef[0] is the constant |
3594 - coef[1..nb_loops] are the protected variables that will not be | 3610 - coef[1..nb_loops] are the protected variables that will not be |
3595 removed by the solver: the "dx" | 3611 removed by the solver: the "dx" |
3596 - coef[nb_loops + 1, 2*nb_loops] are the loop variables: "loop_x". | 3612 - coef[nb_loops + 1, 2*nb_loops] are the loop variables: "loop_x". |
3597 */ | 3613 */ |
3598 for (i = 0; i <= DDR_INNER_LOOP (ddr) | 3614 for (i = 0; i <= DDR_INNER_LOOP (ddr) |
3599 && VEC_iterate (loop_p, DDR_LOOP_NEST (ddr), i, loopi); i++) | 3615 && VEC_iterate (loop_p, DDR_LOOP_NEST (ddr), i, loopi); i++) |
3600 { | 3616 { |
3601 HOST_WIDE_INT nbi = estimated_loop_iterations_int (loopi, false); | 3617 HOST_WIDE_INT nbi = estimated_loop_iterations_int (loopi, false); |
3602 | 3618 |
3603 /* 0 <= loop_x */ | 3619 /* 0 <= loop_x */ |
3645 otherwise, and when independence has been proved (using one of the | 3661 otherwise, and when independence has been proved (using one of the |
3646 trivial dependence test), set MAYBE_DEPENDENT to false, otherwise | 3662 trivial dependence test), set MAYBE_DEPENDENT to false, otherwise |
3647 set MAYBE_DEPENDENT to true. | 3663 set MAYBE_DEPENDENT to true. |
3648 | 3664 |
3649 Example: for setting up the dependence system corresponding to the | 3665 Example: for setting up the dependence system corresponding to the |
3650 conflicting accesses | 3666 conflicting accesses |
3651 | 3667 |
3652 | loop_i | 3668 | loop_i |
3653 | loop_j | 3669 | loop_j |
3654 | A[i, i+1] = ... | 3670 | A[i, i+1] = ... |
3655 | ... A[2*j, 2*(i + j)] | 3671 | ... A[2*j, 2*(i + j)] |
3656 | endloop_j | 3672 | endloop_j |
3657 | endloop_i | 3673 | endloop_i |
3658 | 3674 |
3659 the following constraints come from the iteration domain: | 3675 the following constraints come from the iteration domain: |
3660 | 3676 |
3661 0 <= i <= Ni | 3677 0 <= i <= Ni |
3662 0 <= i + di <= Ni | 3678 0 <= i + di <= Ni |
3663 0 <= j <= Nj | 3679 0 <= j <= Nj |
3854 dump_data_dependence_relation (file, ddr); | 3870 dump_data_dependence_relation (file, ddr); |
3855 fprintf (file, ")\n"); | 3871 fprintf (file, ")\n"); |
3856 } | 3872 } |
3857 } | 3873 } |
3858 | 3874 |
3859 return true; | 3875 return true; |
3860 } | 3876 } |
3861 | 3877 |
3862 /* This computes the affine dependence relation between A and B with | 3878 /* This computes the affine dependence relation between A and B with |
3863 respect to LOOP_NEST. CHREC_KNOWN is used for representing the | 3879 respect to LOOP_NEST. CHREC_KNOWN is used for representing the |
3864 independence between two accesses, while CHREC_DONT_KNOW is used | 3880 independence between two accesses, while CHREC_DONT_KNOW is used |
3865 for representing the unknown relation. | 3881 for representing the unknown relation. |
3866 | 3882 |
3867 Note that it is possible to stop the computation of the dependence | 3883 Note that it is possible to stop the computation of the dependence |
3868 relation the first time we detect a CHREC_KNOWN element for a given | 3884 relation the first time we detect a CHREC_KNOWN element for a given |
3869 subscript. */ | 3885 subscript. */ |
3870 | 3886 |
3871 static void | 3887 static void |
3872 compute_affine_dependence (struct data_dependence_relation *ddr, | 3888 compute_affine_dependence (struct data_dependence_relation *ddr, |
3873 struct loop *loop_nest) | 3889 struct loop *loop_nest) |
3874 { | 3890 { |
3875 struct data_reference *dra = DDR_A (ddr); | 3891 struct data_reference *dra = DDR_A (ddr); |
3876 struct data_reference *drb = DDR_B (ddr); | 3892 struct data_reference *drb = DDR_B (ddr); |
3877 | 3893 |
3878 if (dump_file && (dump_flags & TDF_DETAILS)) | 3894 if (dump_file && (dump_flags & TDF_DETAILS)) |
3879 { | 3895 { |
3880 fprintf (dump_file, "(compute_affine_dependence\n"); | 3896 fprintf (dump_file, "(compute_affine_dependence\n"); |
3881 fprintf (dump_file, " (stmt_a = \n"); | 3897 fprintf (dump_file, " (stmt_a = \n"); |
3882 print_gimple_stmt (dump_file, DR_STMT (dra), 0, 0); | 3898 print_gimple_stmt (dump_file, DR_STMT (dra), 0, 0); |
3935 } | 3951 } |
3936 } | 3952 } |
3937 else | 3953 else |
3938 subscript_dependence_tester (ddr, loop_nest); | 3954 subscript_dependence_tester (ddr, loop_nest); |
3939 } | 3955 } |
3940 | 3956 |
3941 /* As a last case, if the dependence cannot be determined, or if | 3957 /* As a last case, if the dependence cannot be determined, or if |
3942 the dependence is considered too difficult to determine, answer | 3958 the dependence is considered too difficult to determine, answer |
3943 "don't know". */ | 3959 "don't know". */ |
3944 else | 3960 else |
3945 { | 3961 { |
3955 fprintf (dump_file, "affine dependence test not usable: access function not affine or constant.\n"); | 3971 fprintf (dump_file, "affine dependence test not usable: access function not affine or constant.\n"); |
3956 } | 3972 } |
3957 finalize_ddr_dependent (ddr, chrec_dont_know); | 3973 finalize_ddr_dependent (ddr, chrec_dont_know); |
3958 } | 3974 } |
3959 } | 3975 } |
3960 | 3976 |
3961 if (dump_file && (dump_flags & TDF_DETAILS)) | 3977 if (dump_file && (dump_flags & TDF_DETAILS)) |
3962 fprintf (dump_file, ")\n"); | 3978 fprintf (dump_file, ")\n"); |
3963 } | 3979 } |
3964 | 3980 |
3965 /* This computes the dependence relation for the same data | 3981 /* This computes the dependence relation for the same data |
3998 /* Compute in DEPENDENCE_RELATIONS the data dependence graph for all | 4014 /* Compute in DEPENDENCE_RELATIONS the data dependence graph for all |
3999 the data references in DATAREFS, in the LOOP_NEST. When | 4015 the data references in DATAREFS, in the LOOP_NEST. When |
4000 COMPUTE_SELF_AND_RR is FALSE, don't compute read-read and self | 4016 COMPUTE_SELF_AND_RR is FALSE, don't compute read-read and self |
4001 relations. */ | 4017 relations. */ |
4002 | 4018 |
4003 void | 4019 void |
4004 compute_all_dependences (VEC (data_reference_p, heap) *datarefs, | 4020 compute_all_dependences (VEC (data_reference_p, heap) *datarefs, |
4005 VEC (ddr_p, heap) **dependence_relations, | 4021 VEC (ddr_p, heap) **dependence_relations, |
4006 VEC (loop_p, heap) *loop_nest, | 4022 VEC (loop_p, heap) *loop_nest, |
4007 bool compute_self_and_rr) | 4023 bool compute_self_and_rr) |
4008 { | 4024 { |
4014 for (j = i + 1; VEC_iterate (data_reference_p, datarefs, j, b); j++) | 4030 for (j = i + 1; VEC_iterate (data_reference_p, datarefs, j, b); j++) |
4015 if (!DR_IS_READ (a) || !DR_IS_READ (b) || compute_self_and_rr) | 4031 if (!DR_IS_READ (a) || !DR_IS_READ (b) || compute_self_and_rr) |
4016 { | 4032 { |
4017 ddr = initialize_data_dependence_relation (a, b, loop_nest); | 4033 ddr = initialize_data_dependence_relation (a, b, loop_nest); |
4018 VEC_safe_push (ddr_p, heap, *dependence_relations, ddr); | 4034 VEC_safe_push (ddr_p, heap, *dependence_relations, ddr); |
4019 compute_affine_dependence (ddr, VEC_index (loop_p, loop_nest, 0)); | 4035 if (loop_nest) |
4036 compute_affine_dependence (ddr, VEC_index (loop_p, loop_nest, 0)); | |
4020 } | 4037 } |
4021 | 4038 |
4022 if (compute_self_and_rr) | 4039 if (compute_self_and_rr) |
4023 for (i = 0; VEC_iterate (data_reference_p, datarefs, i, a); i++) | 4040 for (i = 0; VEC_iterate (data_reference_p, datarefs, i, a); i++) |
4024 { | 4041 { |
4048 && !(gimple_call_flags (stmt) & (ECF_CONST | ECF_PURE))) | 4065 && !(gimple_call_flags (stmt) & (ECF_CONST | ECF_PURE))) |
4049 || (stmt_code == GIMPLE_ASM | 4066 || (stmt_code == GIMPLE_ASM |
4050 && gimple_asm_volatile_p (stmt))) | 4067 && gimple_asm_volatile_p (stmt))) |
4051 clobbers_memory = true; | 4068 clobbers_memory = true; |
4052 | 4069 |
4053 if (ZERO_SSA_OPERANDS (stmt, SSA_OP_ALL_VIRTUALS)) | 4070 if (!gimple_vuse (stmt)) |
4054 return clobbers_memory; | 4071 return clobbers_memory; |
4055 | 4072 |
4056 if (stmt_code == GIMPLE_ASSIGN) | 4073 if (stmt_code == GIMPLE_ASSIGN) |
4057 { | 4074 { |
4058 tree base; | 4075 tree base; |
4059 op0 = gimple_assign_lhs_ptr (stmt); | 4076 op0 = gimple_assign_lhs_ptr (stmt); |
4060 op1 = gimple_assign_rhs1_ptr (stmt); | 4077 op1 = gimple_assign_rhs1_ptr (stmt); |
4061 | 4078 |
4062 if (DECL_P (*op1) | 4079 if (DECL_P (*op1) |
4063 || (REFERENCE_CLASS_P (*op1) | 4080 || (REFERENCE_CLASS_P (*op1) |
4064 && (base = get_base_address (*op1)) | 4081 && (base = get_base_address (*op1)) |
4065 && TREE_CODE (base) != SSA_NAME)) | 4082 && TREE_CODE (base) != SSA_NAME)) |
4066 { | 4083 { |
4120 | 4137 |
4121 for (i = 0; VEC_iterate (data_ref_loc, references, i, ref); i++) | 4138 for (i = 0; VEC_iterate (data_ref_loc, references, i, ref); i++) |
4122 { | 4139 { |
4123 dr = create_data_ref (nest, *ref->pos, stmt, ref->is_read); | 4140 dr = create_data_ref (nest, *ref->pos, stmt, ref->is_read); |
4124 gcc_assert (dr != NULL); | 4141 gcc_assert (dr != NULL); |
4125 | 4142 |
4126 /* FIXME -- data dependence analysis does not work correctly for objects with | 4143 /* FIXME -- data dependence analysis does not work correctly for objects |
4127 invariant addresses. Let us fail here until the problem is fixed. */ | 4144 with invariant addresses in loop nests. Let us fail here until the |
4128 if (dr_address_invariant_p (dr)) | 4145 problem is fixed. */ |
4146 if (dr_address_invariant_p (dr) && nest) | |
4129 { | 4147 { |
4130 free_data_ref (dr); | 4148 free_data_ref (dr); |
4131 if (dump_file && (dump_flags & TDF_DETAILS)) | 4149 if (dump_file && (dump_flags & TDF_DETAILS)) |
4132 fprintf (dump_file, "\tFAILED as dr address is invariant\n"); | 4150 fprintf (dump_file, "\tFAILED as dr address is invariant\n"); |
4133 ret = false; | 4151 ret = false; |
4138 } | 4156 } |
4139 VEC_free (data_ref_loc, heap, references); | 4157 VEC_free (data_ref_loc, heap, references); |
4140 return ret; | 4158 return ret; |
4141 } | 4159 } |
4142 | 4160 |
4161 /* Stores the data references in STMT to DATAREFS. If there is an unanalyzable | |
4162 reference, returns false, otherwise returns true. NEST is the outermost | |
4163 loop of the loop nest in which the references should be analyzed. */ | |
4164 | |
4165 bool | |
4166 graphite_find_data_references_in_stmt (struct loop *nest, gimple stmt, | |
4167 VEC (data_reference_p, heap) **datarefs) | |
4168 { | |
4169 unsigned i; | |
4170 VEC (data_ref_loc, heap) *references; | |
4171 data_ref_loc *ref; | |
4172 bool ret = true; | |
4173 data_reference_p dr; | |
4174 | |
4175 if (get_references_in_stmt (stmt, &references)) | |
4176 { | |
4177 VEC_free (data_ref_loc, heap, references); | |
4178 return false; | |
4179 } | |
4180 | |
4181 for (i = 0; VEC_iterate (data_ref_loc, references, i, ref); i++) | |
4182 { | |
4183 dr = create_data_ref (nest, *ref->pos, stmt, ref->is_read); | |
4184 gcc_assert (dr != NULL); | |
4185 VEC_safe_push (data_reference_p, heap, *datarefs, dr); | |
4186 } | |
4187 | |
4188 VEC_free (data_ref_loc, heap, references); | |
4189 return ret; | |
4190 } | |
4191 | |
4192 /* Search the data references in LOOP, and record the information into | |
4193 DATAREFS. Returns chrec_dont_know when failing to analyze a | |
4194 difficult case, returns NULL_TREE otherwise. */ | |
4195 | |
4196 static tree | |
4197 find_data_references_in_bb (struct loop *loop, basic_block bb, | |
4198 VEC (data_reference_p, heap) **datarefs) | |
4199 { | |
4200 gimple_stmt_iterator bsi; | |
4201 | |
4202 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) | |
4203 { | |
4204 gimple stmt = gsi_stmt (bsi); | |
4205 | |
4206 if (!find_data_references_in_stmt (loop, stmt, datarefs)) | |
4207 { | |
4208 struct data_reference *res; | |
4209 res = XCNEW (struct data_reference); | |
4210 VEC_safe_push (data_reference_p, heap, *datarefs, res); | |
4211 | |
4212 return chrec_dont_know; | |
4213 } | |
4214 } | |
4215 | |
4216 return NULL_TREE; | |
4217 } | |
4218 | |
4143 /* Search the data references in LOOP, and record the information into | 4219 /* Search the data references in LOOP, and record the information into |
4144 DATAREFS. Returns chrec_dont_know when failing to analyze a | 4220 DATAREFS. Returns chrec_dont_know when failing to analyze a |
4145 difficult case, returns NULL_TREE otherwise. | 4221 difficult case, returns NULL_TREE otherwise. |
4146 | 4222 |
4147 TODO: This function should be made smarter so that it can handle address | 4223 TODO: This function should be made smarter so that it can handle address |
4148 arithmetic as if they were array accesses, etc. */ | 4224 arithmetic as if they were array accesses, etc. */ |
4149 | 4225 |
4150 tree | 4226 tree |
4151 find_data_references_in_loop (struct loop *loop, | 4227 find_data_references_in_loop (struct loop *loop, |
4152 VEC (data_reference_p, heap) **datarefs) | 4228 VEC (data_reference_p, heap) **datarefs) |
4153 { | 4229 { |
4154 basic_block bb, *bbs; | 4230 basic_block bb, *bbs; |
4155 unsigned int i; | 4231 unsigned int i; |
4156 gimple_stmt_iterator bsi; | |
4157 | 4232 |
4158 bbs = get_loop_body_in_dom_order (loop); | 4233 bbs = get_loop_body_in_dom_order (loop); |
4159 | 4234 |
4160 for (i = 0; i < loop->num_nodes; i++) | 4235 for (i = 0; i < loop->num_nodes; i++) |
4161 { | 4236 { |
4162 bb = bbs[i]; | 4237 bb = bbs[i]; |
4163 | 4238 |
4164 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) | 4239 if (find_data_references_in_bb (loop, bb, datarefs) == chrec_dont_know) |
4165 { | 4240 { |
4166 gimple stmt = gsi_stmt (bsi); | 4241 free (bbs); |
4167 | 4242 return chrec_dont_know; |
4168 if (!find_data_references_in_stmt (loop, stmt, datarefs)) | 4243 } |
4169 { | |
4170 struct data_reference *res; | |
4171 res = XCNEW (struct data_reference); | |
4172 VEC_safe_push (data_reference_p, heap, *datarefs, res); | |
4173 | |
4174 free (bbs); | |
4175 return chrec_dont_know; | |
4176 } | |
4177 } | |
4178 } | 4244 } |
4179 free (bbs); | 4245 free (bbs); |
4180 | 4246 |
4181 return NULL_TREE; | 4247 return NULL_TREE; |
4182 } | 4248 } |
4223 return true; | 4289 return true; |
4224 } | 4290 } |
4225 | 4291 |
4226 /* Returns true when the data dependences have been computed, false otherwise. | 4292 /* Returns true when the data dependences have been computed, false otherwise. |
4227 Given a loop nest LOOP, the following vectors are returned: | 4293 Given a loop nest LOOP, the following vectors are returned: |
4228 DATAREFS is initialized to all the array elements contained in this loop, | 4294 DATAREFS is initialized to all the array elements contained in this loop, |
4229 DEPENDENCE_RELATIONS contains the relations between the data references. | 4295 DEPENDENCE_RELATIONS contains the relations between the data references. |
4230 Compute read-read and self relations if | 4296 Compute read-read and self relations if |
4231 COMPUTE_SELF_AND_READ_READ_DEPENDENCES is TRUE. */ | 4297 COMPUTE_SELF_AND_READ_READ_DEPENDENCES is TRUE. */ |
4232 | 4298 |
4233 bool | 4299 bool |
4234 compute_data_dependences_for_loop (struct loop *loop, | 4300 compute_data_dependences_for_loop (struct loop *loop, |
4235 bool compute_self_and_read_read_dependences, | 4301 bool compute_self_and_read_read_dependences, |
4236 VEC (data_reference_p, heap) **datarefs, | 4302 VEC (data_reference_p, heap) **datarefs, |
4237 VEC (ddr_p, heap) **dependence_relations) | 4303 VEC (ddr_p, heap) **dependence_relations) |
4238 { | 4304 { |
4239 bool res = true; | 4305 bool res = true; |
4240 VEC (loop_p, heap) *vloops = VEC_alloc (loop_p, heap, 3); | 4306 VEC (loop_p, heap) *vloops = VEC_alloc (loop_p, heap, 3); |
4241 | 4307 |
4242 memset (&dependence_stats, 0, sizeof (dependence_stats)); | 4308 memset (&dependence_stats, 0, sizeof (dependence_stats)); |
4243 | 4309 |
4244 /* If the loop nest is not well formed, or one of the data references | 4310 /* If the loop nest is not well formed, or one of the data references |
4245 is not computable, give up without spending time to compute other | 4311 is not computable, give up without spending time to compute other |
4246 dependences. */ | 4312 dependences. */ |
4247 if (!loop | 4313 if (!loop |
4248 || !find_loop_nest (loop, &vloops) | 4314 || !find_loop_nest (loop, &vloops) |
4249 || find_data_references_in_loop (loop, datarefs) == chrec_dont_know) | 4315 || find_data_references_in_loop (loop, datarefs) == chrec_dont_know) |
4262 | 4328 |
4263 if (dump_file && (dump_flags & TDF_STATS)) | 4329 if (dump_file && (dump_flags & TDF_STATS)) |
4264 { | 4330 { |
4265 fprintf (dump_file, "Dependence tester statistics:\n"); | 4331 fprintf (dump_file, "Dependence tester statistics:\n"); |
4266 | 4332 |
4267 fprintf (dump_file, "Number of dependence tests: %d\n", | 4333 fprintf (dump_file, "Number of dependence tests: %d\n", |
4268 dependence_stats.num_dependence_tests); | 4334 dependence_stats.num_dependence_tests); |
4269 fprintf (dump_file, "Number of dependence tests classified dependent: %d\n", | 4335 fprintf (dump_file, "Number of dependence tests classified dependent: %d\n", |
4270 dependence_stats.num_dependence_dependent); | 4336 dependence_stats.num_dependence_dependent); |
4271 fprintf (dump_file, "Number of dependence tests classified independent: %d\n", | 4337 fprintf (dump_file, "Number of dependence tests classified independent: %d\n", |
4272 dependence_stats.num_dependence_independent); | 4338 dependence_stats.num_dependence_independent); |
4273 fprintf (dump_file, "Number of undetermined dependence tests: %d\n", | 4339 fprintf (dump_file, "Number of undetermined dependence tests: %d\n", |
4274 dependence_stats.num_dependence_undetermined); | 4340 dependence_stats.num_dependence_undetermined); |
4275 | 4341 |
4276 fprintf (dump_file, "Number of subscript tests: %d\n", | 4342 fprintf (dump_file, "Number of subscript tests: %d\n", |
4277 dependence_stats.num_subscript_tests); | 4343 dependence_stats.num_subscript_tests); |
4278 fprintf (dump_file, "Number of undetermined subscript tests: %d\n", | 4344 fprintf (dump_file, "Number of undetermined subscript tests: %d\n", |
4279 dependence_stats.num_subscript_undetermined); | 4345 dependence_stats.num_subscript_undetermined); |
4280 fprintf (dump_file, "Number of same subscript function: %d\n", | 4346 fprintf (dump_file, "Number of same subscript function: %d\n", |
4281 dependence_stats.num_same_subscript_function); | 4347 dependence_stats.num_same_subscript_function); |
4282 | 4348 |
4283 fprintf (dump_file, "Number of ziv tests: %d\n", | 4349 fprintf (dump_file, "Number of ziv tests: %d\n", |
4284 dependence_stats.num_ziv); | 4350 dependence_stats.num_ziv); |
4285 fprintf (dump_file, "Number of ziv tests returning dependent: %d\n", | 4351 fprintf (dump_file, "Number of ziv tests returning dependent: %d\n", |
4286 dependence_stats.num_ziv_dependent); | 4352 dependence_stats.num_ziv_dependent); |
4287 fprintf (dump_file, "Number of ziv tests returning independent: %d\n", | 4353 fprintf (dump_file, "Number of ziv tests returning independent: %d\n", |
4288 dependence_stats.num_ziv_independent); | 4354 dependence_stats.num_ziv_independent); |
4289 fprintf (dump_file, "Number of ziv tests unimplemented: %d\n", | 4355 fprintf (dump_file, "Number of ziv tests unimplemented: %d\n", |
4290 dependence_stats.num_ziv_unimplemented); | 4356 dependence_stats.num_ziv_unimplemented); |
4291 | 4357 |
4292 fprintf (dump_file, "Number of siv tests: %d\n", | 4358 fprintf (dump_file, "Number of siv tests: %d\n", |
4293 dependence_stats.num_siv); | 4359 dependence_stats.num_siv); |
4294 fprintf (dump_file, "Number of siv tests returning dependent: %d\n", | 4360 fprintf (dump_file, "Number of siv tests returning dependent: %d\n", |
4295 dependence_stats.num_siv_dependent); | 4361 dependence_stats.num_siv_dependent); |
4296 fprintf (dump_file, "Number of siv tests returning independent: %d\n", | 4362 fprintf (dump_file, "Number of siv tests returning independent: %d\n", |
4297 dependence_stats.num_siv_independent); | 4363 dependence_stats.num_siv_independent); |
4298 fprintf (dump_file, "Number of siv tests unimplemented: %d\n", | 4364 fprintf (dump_file, "Number of siv tests unimplemented: %d\n", |
4299 dependence_stats.num_siv_unimplemented); | 4365 dependence_stats.num_siv_unimplemented); |
4300 | 4366 |
4301 fprintf (dump_file, "Number of miv tests: %d\n", | 4367 fprintf (dump_file, "Number of miv tests: %d\n", |
4302 dependence_stats.num_miv); | 4368 dependence_stats.num_miv); |
4303 fprintf (dump_file, "Number of miv tests returning dependent: %d\n", | 4369 fprintf (dump_file, "Number of miv tests returning dependent: %d\n", |
4304 dependence_stats.num_miv_dependent); | 4370 dependence_stats.num_miv_dependent); |
4305 fprintf (dump_file, "Number of miv tests returning independent: %d\n", | 4371 fprintf (dump_file, "Number of miv tests returning independent: %d\n", |
4306 dependence_stats.num_miv_independent); | 4372 dependence_stats.num_miv_independent); |
4309 } | 4375 } |
4310 | 4376 |
4311 return res; | 4377 return res; |
4312 } | 4378 } |
4313 | 4379 |
4380 /* Returns true when the data dependences for the basic block BB have been | |
4381 computed, false otherwise. | |
4382 DATAREFS is initialized to all the array elements contained in this basic | |
4383 block, DEPENDENCE_RELATIONS contains the relations between the data | |
4384 references. Compute read-read and self relations if | |
4385 COMPUTE_SELF_AND_READ_READ_DEPENDENCES is TRUE. */ | |
4386 bool | |
4387 compute_data_dependences_for_bb (basic_block bb, | |
4388 bool compute_self_and_read_read_dependences, | |
4389 VEC (data_reference_p, heap) **datarefs, | |
4390 VEC (ddr_p, heap) **dependence_relations) | |
4391 { | |
4392 if (find_data_references_in_bb (NULL, bb, datarefs) == chrec_dont_know) | |
4393 return false; | |
4394 | |
4395 compute_all_dependences (*datarefs, dependence_relations, NULL, | |
4396 compute_self_and_read_read_dependences); | |
4397 return true; | |
4398 } | |
4399 | |
4314 /* Entry point (for testing only). Analyze all the data references | 4400 /* Entry point (for testing only). Analyze all the data references |
4315 and the dependence relations in LOOP. | 4401 and the dependence relations in LOOP. |
4316 | 4402 |
4317 The data references are computed first. | 4403 The data references are computed first. |
4318 | 4404 |
4319 A relation on these nodes is represented by a complete graph. Some | 4405 A relation on these nodes is represented by a complete graph. Some |
4320 of the relations could be of no interest, thus the relations can be | 4406 of the relations could be of no interest, thus the relations can be |
4321 computed on demand. | 4407 computed on demand. |
4322 | 4408 |
4323 In the following function we compute all the relations. This is | 4409 In the following function we compute all the relations. This is |
4324 just a first implementation that is here for: | 4410 just a first implementation that is here for: |
4325 - for showing how to ask for the dependence relations, | 4411 - for showing how to ask for the dependence relations, |
4326 - for the debugging the whole dependence graph, | 4412 - for the debugging the whole dependence graph, |
4327 - for the dejagnu testcases and maintenance. | 4413 - for the dejagnu testcases and maintenance. |
4328 | 4414 |
4329 It is possible to ask only for a part of the graph, avoiding to | 4415 It is possible to ask only for a part of the graph, avoiding to |
4330 compute the whole dependence graph. The computed dependences are | 4416 compute the whole dependence graph. The computed dependences are |
4331 stored in a knowledge base (KB) such that later queries don't | 4417 stored in a knowledge base (KB) such that later queries don't |
4332 recompute the same information. The implementation of this KB is | 4418 recompute the same information. The implementation of this KB is |
4333 transparent to the optimizer, and thus the KB can be changed with a | 4419 transparent to the optimizer, and thus the KB can be changed with a |
4334 more efficient implementation, or the KB could be disabled. */ | 4420 more efficient implementation, or the KB could be disabled. */ |
4335 static void | 4421 static void |
4336 analyze_all_data_dependences (struct loop *loop) | 4422 analyze_all_data_dependences (struct loop *loop) |
4337 { | 4423 { |
4338 unsigned int i; | 4424 unsigned int i; |
4339 int nb_data_refs = 10; | 4425 int nb_data_refs = 10; |
4340 VEC (data_reference_p, heap) *datarefs = | 4426 VEC (data_reference_p, heap) *datarefs = |
4341 VEC_alloc (data_reference_p, heap, nb_data_refs); | 4427 VEC_alloc (data_reference_p, heap, nb_data_refs); |
4342 VEC (ddr_p, heap) *dependence_relations = | 4428 VEC (ddr_p, heap) *dependence_relations = |
4343 VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs); | 4429 VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs); |
4344 | 4430 |
4345 /* Compute DDs on the whole function. */ | 4431 /* Compute DDs on the whole function. */ |
4346 compute_data_dependences_for_loop (loop, false, &datarefs, | 4432 compute_data_dependences_for_loop (loop, false, &datarefs, |
4347 &dependence_relations); | 4433 &dependence_relations); |
4356 | 4442 |
4357 if (dump_flags & TDF_STATS) | 4443 if (dump_flags & TDF_STATS) |
4358 { | 4444 { |
4359 unsigned nb_top_relations = 0; | 4445 unsigned nb_top_relations = 0; |
4360 unsigned nb_bot_relations = 0; | 4446 unsigned nb_bot_relations = 0; |
4361 unsigned nb_basename_differ = 0; | |
4362 unsigned nb_chrec_relations = 0; | 4447 unsigned nb_chrec_relations = 0; |
4363 struct data_dependence_relation *ddr; | 4448 struct data_dependence_relation *ddr; |
4364 | 4449 |
4365 for (i = 0; VEC_iterate (ddr_p, dependence_relations, i, ddr); i++) | 4450 for (i = 0; VEC_iterate (ddr_p, dependence_relations, i, ddr); i++) |
4366 { | 4451 { |
4367 if (chrec_contains_undetermined (DDR_ARE_DEPENDENT (ddr))) | 4452 if (chrec_contains_undetermined (DDR_ARE_DEPENDENT (ddr))) |
4368 nb_top_relations++; | 4453 nb_top_relations++; |
4369 | 4454 |
4370 else if (DDR_ARE_DEPENDENT (ddr) == chrec_known) | 4455 else if (DDR_ARE_DEPENDENT (ddr) == chrec_known) |
4371 { | 4456 nb_bot_relations++; |
4372 struct data_reference *a = DDR_A (ddr); | 4457 |
4373 struct data_reference *b = DDR_B (ddr); | 4458 else |
4374 | |
4375 if (!bitmap_intersect_p (DR_VOPS (a), DR_VOPS (b))) | |
4376 nb_basename_differ++; | |
4377 else | |
4378 nb_bot_relations++; | |
4379 } | |
4380 | |
4381 else | |
4382 nb_chrec_relations++; | 4459 nb_chrec_relations++; |
4383 } | 4460 } |
4384 | 4461 |
4385 gather_stats_on_scev_database (); | 4462 gather_stats_on_scev_database (); |
4386 } | 4463 } |
4387 } | 4464 } |
4388 | 4465 |
4389 free_dependence_relations (dependence_relations); | 4466 free_dependence_relations (dependence_relations); |
4422 } | 4499 } |
4423 | 4500 |
4424 /* Free the memory used by the data dependence relations from | 4501 /* Free the memory used by the data dependence relations from |
4425 DEPENDENCE_RELATIONS. */ | 4502 DEPENDENCE_RELATIONS. */ |
4426 | 4503 |
4427 void | 4504 void |
4428 free_dependence_relations (VEC (ddr_p, heap) *dependence_relations) | 4505 free_dependence_relations (VEC (ddr_p, heap) *dependence_relations) |
4429 { | 4506 { |
4430 unsigned int i; | 4507 unsigned int i; |
4431 struct data_dependence_relation *ddr; | 4508 struct data_dependence_relation *ddr; |
4432 VEC (loop_p, heap) *loop_nest = NULL; | 4509 VEC (loop_p, heap) *loop_nest = NULL; |
4469 dump_rdg_vertex (FILE *file, struct graph *rdg, int i) | 4546 dump_rdg_vertex (FILE *file, struct graph *rdg, int i) |
4470 { | 4547 { |
4471 struct vertex *v = &(rdg->vertices[i]); | 4548 struct vertex *v = &(rdg->vertices[i]); |
4472 struct graph_edge *e; | 4549 struct graph_edge *e; |
4473 | 4550 |
4474 fprintf (file, "(vertex %d: (%s%s) (in:", i, | 4551 fprintf (file, "(vertex %d: (%s%s) (in:", i, |
4475 RDG_MEM_WRITE_STMT (rdg, i) ? "w" : "", | 4552 RDG_MEM_WRITE_STMT (rdg, i) ? "w" : "", |
4476 RDG_MEM_READS_STMT (rdg, i) ? "r" : ""); | 4553 RDG_MEM_READS_STMT (rdg, i) ? "r" : ""); |
4477 | 4554 |
4478 if (v->pred) | 4555 if (v->pred) |
4479 for (e = v->pred; e; e = e->pred_next) | 4556 for (e = v->pred; e; e = e->pred_next) |
4551 debug_rdg (struct graph *rdg) | 4628 debug_rdg (struct graph *rdg) |
4552 { | 4629 { |
4553 dump_rdg (stderr, rdg); | 4630 dump_rdg (stderr, rdg); |
4554 } | 4631 } |
4555 | 4632 |
4556 static void | |
4557 dot_rdg_1 (FILE *file, struct graph *rdg) | |
4558 { | |
4559 int i; | |
4560 | |
4561 fprintf (file, "digraph RDG {\n"); | |
4562 | |
4563 for (i = 0; i < rdg->n_vertices; i++) | |
4564 { | |
4565 struct vertex *v = &(rdg->vertices[i]); | |
4566 struct graph_edge *e; | |
4567 | |
4568 /* Highlight reads from memory. */ | |
4569 if (RDG_MEM_READS_STMT (rdg, i)) | |
4570 fprintf (file, "%d [style=filled, fillcolor=green]\n", i); | |
4571 | |
4572 /* Highlight stores to memory. */ | |
4573 if (RDG_MEM_WRITE_STMT (rdg, i)) | |
4574 fprintf (file, "%d [style=filled, fillcolor=red]\n", i); | |
4575 | |
4576 if (v->succ) | |
4577 for (e = v->succ; e; e = e->succ_next) | |
4578 switch (RDGE_TYPE (e)) | |
4579 { | |
4580 case input_dd: | |
4581 fprintf (file, "%d -> %d [label=input] \n", i, e->dest); | |
4582 break; | |
4583 | |
4584 case output_dd: | |
4585 fprintf (file, "%d -> %d [label=output] \n", i, e->dest); | |
4586 break; | |
4587 | |
4588 case flow_dd: | |
4589 /* These are the most common dependences: don't print these. */ | |
4590 fprintf (file, "%d -> %d \n", i, e->dest); | |
4591 break; | |
4592 | |
4593 case anti_dd: | |
4594 fprintf (file, "%d -> %d [label=anti] \n", i, e->dest); | |
4595 break; | |
4596 | |
4597 default: | |
4598 gcc_unreachable (); | |
4599 } | |
4600 } | |
4601 | |
4602 fprintf (file, "}\n\n"); | |
4603 } | |
4604 | |
4605 /* Display SCOP using dotty. */ | |
4606 | |
4607 void | |
4608 dot_rdg (struct graph *rdg) | |
4609 { | |
4610 FILE *file = fopen ("/tmp/rdg.dot", "w"); | |
4611 gcc_assert (file != NULL); | |
4612 | |
4613 dot_rdg_1 (file, rdg); | |
4614 fclose (file); | |
4615 | |
4616 system ("dotty /tmp/rdg.dot"); | |
4617 } | |
4618 | |
4619 | |
4620 /* This structure is used for recording the mapping statement index in | 4633 /* This structure is used for recording the mapping statement index in |
4621 the RDG. */ | 4634 the RDG. */ |
4622 | 4635 |
4623 struct rdg_vertex_info GTY(()) | 4636 struct GTY(()) rdg_vertex_info |
4624 { | 4637 { |
4625 gimple stmt; | 4638 gimple stmt; |
4626 int index; | 4639 int index; |
4627 }; | 4640 }; |
4628 | 4641 |
4694 static void | 4707 static void |
4695 create_rdg_edges_for_scalar (struct graph *rdg, tree def, int idef) | 4708 create_rdg_edges_for_scalar (struct graph *rdg, tree def, int idef) |
4696 { | 4709 { |
4697 use_operand_p imm_use_p; | 4710 use_operand_p imm_use_p; |
4698 imm_use_iterator iterator; | 4711 imm_use_iterator iterator; |
4699 | 4712 |
4700 FOR_EACH_IMM_USE_FAST (imm_use_p, iterator, def) | 4713 FOR_EACH_IMM_USE_FAST (imm_use_p, iterator, def) |
4701 { | 4714 { |
4702 struct graph_edge *e; | 4715 struct graph_edge *e; |
4703 int use = rdg_vertex_for_stmt (rdg, USE_STMT (imm_use_p)); | 4716 int use = rdg_vertex_for_stmt (rdg, USE_STMT (imm_use_p)); |
4704 | 4717 |
4817 unsigned int i; | 4830 unsigned int i; |
4818 | 4831 |
4819 for (i = 0; VEC_iterate (ddr_p, dependence_relations, i, ddr); i++) | 4832 for (i = 0; VEC_iterate (ddr_p, dependence_relations, i, ddr); i++) |
4820 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) | 4833 if (DDR_ARE_DEPENDENT (ddr) == chrec_dont_know) |
4821 return false; | 4834 return false; |
4822 | 4835 |
4823 return true; | 4836 return true; |
4824 } | 4837 } |
4825 | 4838 |
4826 /* Computes a hash function for element ELT. */ | 4839 /* Computes a hash function for element ELT. */ |
4827 | 4840 |
4879 int nb_data_refs = 10; | 4892 int nb_data_refs = 10; |
4880 struct graph *rdg = NULL; | 4893 struct graph *rdg = NULL; |
4881 VEC (ddr_p, heap) *dependence_relations; | 4894 VEC (ddr_p, heap) *dependence_relations; |
4882 VEC (data_reference_p, heap) *datarefs; | 4895 VEC (data_reference_p, heap) *datarefs; |
4883 VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, nb_data_refs); | 4896 VEC (gimple, heap) *stmts = VEC_alloc (gimple, heap, nb_data_refs); |
4884 | 4897 |
4885 dependence_relations = VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs) ; | 4898 dependence_relations = VEC_alloc (ddr_p, heap, nb_data_refs * nb_data_refs) ; |
4886 datarefs = VEC_alloc (data_reference_p, heap, nb_data_refs); | 4899 datarefs = VEC_alloc (data_reference_p, heap, nb_data_refs); |
4887 compute_data_dependences_for_loop (loop, | 4900 compute_data_dependences_for_loop (loop, |
4888 false, | 4901 false, |
4889 &datarefs, | 4902 &datarefs, |
4890 &dependence_relations); | 4903 &dependence_relations); |
4891 | 4904 |
4892 if (!known_dependences_p (dependence_relations)) | 4905 if (!known_dependences_p (dependence_relations)) |
4937 { | 4950 { |
4938 basic_block bb = bbs[i]; | 4951 basic_block bb = bbs[i]; |
4939 gimple_stmt_iterator bsi; | 4952 gimple_stmt_iterator bsi; |
4940 | 4953 |
4941 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) | 4954 for (bsi = gsi_start_bb (bb); !gsi_end_p (bsi); gsi_next (&bsi)) |
4942 if (!ZERO_SSA_OPERANDS (gsi_stmt (bsi), SSA_OP_VDEF)) | 4955 if (gimple_vdef (gsi_stmt (bsi))) |
4943 VEC_safe_push (gimple, heap, *stmts, gsi_stmt (bsi)); | 4956 VEC_safe_push (gimple, heap, *stmts, gsi_stmt (bsi)); |
4944 } | 4957 } |
4945 | 4958 |
4946 free (bbs); | 4959 free (bbs); |
4947 } | 4960 } |
5105 } | 5118 } |
5106 | 5119 |
5107 /* Returns the index of PARAMETER in the parameters vector of the | 5120 /* Returns the index of PARAMETER in the parameters vector of the |
5108 ACCESS_MATRIX. If PARAMETER does not exist return -1. */ | 5121 ACCESS_MATRIX. If PARAMETER does not exist return -1. */ |
5109 | 5122 |
5110 int | 5123 int |
5111 access_matrix_get_index_for_parameter (tree parameter, | 5124 access_matrix_get_index_for_parameter (tree parameter, |
5112 struct access_matrix *access_matrix) | 5125 struct access_matrix *access_matrix) |
5113 { | 5126 { |
5114 int i; | 5127 int i; |
5115 VEC (tree,heap) *lambda_parameters = AM_PARAMETERS (access_matrix); | 5128 VEC (tree,heap) *lambda_parameters = AM_PARAMETERS (access_matrix); |
5116 tree lambda_parameter; | 5129 tree lambda_parameter; |