Mercurial > hg > CbC > CbC_gcc
comparison gcc/graphite-clast-to-gimple.c @ 63:b7f97abdc517 gcc-4.6-20100522
update gcc from gcc-4.5.0 to gcc-4.6
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 24 May 2010 12:47:05 +0900 |
parents | 77e2b8dfacca |
children | f6334be47118 |
comparison
equal
deleted
inserted
replaced
56:3c8a44c06a95 | 63:b7f97abdc517 |
---|---|
1 /* Translation of CLAST (CLooG AST) to Gimple. | 1 /* Translation of CLAST (CLooG AST) to Gimple. |
2 Copyright (C) 2009 Free Software Foundation, Inc. | 2 Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
3 Contributed by Sebastian Pop <sebastian.pop@amd.com>. | 3 Contributed by Sebastian Pop <sebastian.pop@amd.com>. |
4 | 4 |
5 This file is part of GCC. | 5 This file is part of GCC. |
6 | 6 |
7 GCC is free software; you can redistribute it and/or modify | 7 GCC is free software; you can redistribute it and/or modify |
38 #include "tree-pass.h" | 38 #include "tree-pass.h" |
39 #include "domwalk.h" | 39 #include "domwalk.h" |
40 #include "value-prof.h" | 40 #include "value-prof.h" |
41 #include "pointer-set.h" | 41 #include "pointer-set.h" |
42 #include "gimple.h" | 42 #include "gimple.h" |
43 #include "langhooks.h" | |
43 #include "sese.h" | 44 #include "sese.h" |
44 | 45 |
45 #ifdef HAVE_cloog | 46 #ifdef HAVE_cloog |
46 #include "cloog/cloog.h" | 47 #include "cloog/cloog.h" |
47 #include "ppl_c.h" | 48 #include "ppl_c.h" |
50 #include "graphite-poly.h" | 51 #include "graphite-poly.h" |
51 #include "graphite-scop-detection.h" | 52 #include "graphite-scop-detection.h" |
52 #include "graphite-clast-to-gimple.h" | 53 #include "graphite-clast-to-gimple.h" |
53 #include "graphite-dependences.h" | 54 #include "graphite-dependences.h" |
54 | 55 |
56 /* This flag is set when an error occurred during the translation of | |
57 CLAST to Gimple. */ | |
58 static bool gloog_error; | |
59 | |
55 /* Verifies properties that GRAPHITE should maintain during translation. */ | 60 /* Verifies properties that GRAPHITE should maintain during translation. */ |
56 | 61 |
57 static inline void | 62 static inline void |
58 graphite_verify (void) | 63 graphite_verify (void) |
59 { | 64 { |
60 #ifdef ENABLE_CHECKING | 65 #ifdef ENABLE_CHECKING |
61 verify_loop_structure (); | 66 verify_loop_structure (); |
62 verify_dominators (CDI_DOMINATORS); | 67 verify_dominators (CDI_DOMINATORS); |
63 verify_dominators (CDI_POST_DOMINATORS); | 68 verify_dominators (CDI_POST_DOMINATORS); |
64 verify_ssa (false); | 69 verify_loop_closed_ssa (true); |
65 verify_loop_closed_ssa (); | |
66 #endif | 70 #endif |
67 } | 71 } |
68 | 72 |
69 /* Stores the INDEX in a vector for a given clast NAME. */ | 73 /* Stores the INDEX in a vector for a given clast NAME. */ |
70 | 74 |
115 | 119 |
116 tmp.name = name; | 120 tmp.name = name; |
117 slot = htab_find_slot (index_table, &tmp, INSERT); | 121 slot = htab_find_slot (index_table, &tmp, INSERT); |
118 | 122 |
119 if (slot) | 123 if (slot) |
120 *slot = new_clast_name_index (name, index); | 124 { |
125 if (*slot) | |
126 free (*slot); | |
127 | |
128 *slot = new_clast_name_index (name, index); | |
129 } | |
121 } | 130 } |
122 | 131 |
123 /* Print to stderr the element ELT. */ | 132 /* Print to stderr the element ELT. */ |
124 | 133 |
125 static inline void | 134 static inline void |
213 gcc_assert (index >= 0); | 222 gcc_assert (index >= 0); |
214 | 223 |
215 return newivs_to_depth_to_newiv (newivs, index); | 224 return newivs_to_depth_to_newiv (newivs, index); |
216 } | 225 } |
217 | 226 |
218 /* Returns the maximal precision type for expressions E1 and E2. */ | 227 /* Returns the signed maximal precision type for expressions TYPE1 and TYPE2. */ |
219 | 228 |
220 static inline tree | 229 static tree |
221 max_precision_type (tree e1, tree e2) | 230 max_signed_precision_type (tree type1, tree type2) |
222 { | 231 { |
223 tree type1 = TREE_TYPE (e1); | 232 int p1 = TYPE_PRECISION (type1); |
224 tree type2 = TREE_TYPE (e2); | 233 int p2 = TYPE_PRECISION (type2); |
234 int precision; | |
235 tree type; | |
236 | |
237 if (p1 > p2) | |
238 precision = TYPE_UNSIGNED (type1) ? p1 * 2 : p1; | |
239 else | |
240 precision = TYPE_UNSIGNED (type2) ? p2 * 2 : p2; | |
241 | |
242 type = lang_hooks.types.type_for_size (precision, false); | |
243 | |
244 if (!type) | |
245 { | |
246 gloog_error = true; | |
247 return integer_type_node; | |
248 } | |
249 return type; | |
250 } | |
251 | |
252 /* Returns the maximal precision type for expressions TYPE1 and TYPE2. */ | |
253 | |
254 static tree | |
255 max_precision_type (tree type1, tree type2) | |
256 { | |
257 if (POINTER_TYPE_P (type1)) | |
258 return type1; | |
259 | |
260 if (POINTER_TYPE_P (type2)) | |
261 return type2; | |
262 | |
263 if (!TYPE_UNSIGNED (type1) | |
264 || !TYPE_UNSIGNED (type2)) | |
265 return max_signed_precision_type (type1, type2); | |
266 | |
225 return TYPE_PRECISION (type1) > TYPE_PRECISION (type2) ? type1 : type2; | 267 return TYPE_PRECISION (type1) > TYPE_PRECISION (type2) ? type1 : type2; |
226 } | 268 } |
227 | 269 |
228 static tree | 270 static tree |
229 clast_to_gcc_expression (tree, struct clast_expr *, sese, VEC (tree, heap) *, | 271 clast_to_gcc_expression (tree, struct clast_expr *, sese, VEC (tree, heap) *, |
267 { | 309 { |
268 struct clast_term *t = (struct clast_term *) e; | 310 struct clast_term *t = (struct clast_term *) e; |
269 | 311 |
270 if (t->var) | 312 if (t->var) |
271 { | 313 { |
272 if (value_one_p (t->val)) | 314 if (mpz_cmp_si (t->val, 1) == 0) |
273 { | 315 { |
274 tree name = clast_name_to_gcc (t->var, region, newivs, | 316 tree name = clast_name_to_gcc (t->var, region, newivs, |
275 newivs_index, params_index); | 317 newivs_index, params_index); |
276 return fold_convert (type, name); | 318 |
319 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type)) | |
320 name = fold_convert (sizetype, name); | |
321 | |
322 name = fold_convert (type, name); | |
323 return name; | |
277 } | 324 } |
278 | 325 |
279 else if (value_mone_p (t->val)) | 326 else if (mpz_cmp_si (t->val, -1) == 0) |
280 { | 327 { |
281 tree name = clast_name_to_gcc (t->var, region, newivs, | 328 tree name = clast_name_to_gcc (t->var, region, newivs, |
282 newivs_index, params_index); | 329 newivs_index, params_index); |
330 | |
331 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type)) | |
332 name = fold_convert (sizetype, name); | |
333 | |
283 name = fold_convert (type, name); | 334 name = fold_convert (type, name); |
335 | |
284 return fold_build1 (NEGATE_EXPR, type, name); | 336 return fold_build1 (NEGATE_EXPR, type, name); |
285 } | 337 } |
286 else | 338 else |
287 { | 339 { |
288 tree name = clast_name_to_gcc (t->var, region, newivs, | 340 tree name = clast_name_to_gcc (t->var, region, newivs, |
289 newivs_index, params_index); | 341 newivs_index, params_index); |
290 tree cst = gmp_cst_to_tree (type, t->val); | 342 tree cst = gmp_cst_to_tree (type, t->val); |
343 | |
344 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type)) | |
345 name = fold_convert (sizetype, name); | |
346 | |
291 name = fold_convert (type, name); | 347 name = fold_convert (type, name); |
292 return fold_build2 (MULT_EXPR, type, cst, name); | 348 |
349 if (!POINTER_TYPE_P (type)) | |
350 return fold_build2 (MULT_EXPR, type, cst, name); | |
351 | |
352 gloog_error = true; | |
353 return cst; | |
293 } | 354 } |
294 } | 355 } |
295 else | 356 else |
296 return gmp_cst_to_tree (type, t->val); | 357 return gmp_cst_to_tree (type, t->val); |
297 } | 358 } |
355 } | 416 } |
356 | 417 |
357 return NULL_TREE; | 418 return NULL_TREE; |
358 } | 419 } |
359 | 420 |
360 /* Returns the type for the expression E. */ | 421 /* Return the precision needed to represent the value VAL. */ |
422 | |
423 static int | |
424 precision_for_value (mpz_t val) | |
425 { | |
426 mpz_t x, y, two; | |
427 int precision; | |
428 | |
429 value_init (x); | |
430 value_init (y); | |
431 value_init (two); | |
432 value_set_si (x, 2); | |
433 value_assign (y, val); | |
434 value_set_si (two, 2); | |
435 precision = 1; | |
436 | |
437 if (value_neg_p (y)) | |
438 value_oppose (y, y); | |
439 | |
440 while (value_gt (y, x)) | |
441 { | |
442 value_multiply (x, x, two); | |
443 precision++; | |
444 } | |
445 | |
446 value_clear (x); | |
447 value_clear (y); | |
448 value_clear (two); | |
449 | |
450 return precision; | |
451 } | |
452 | |
453 /* Return the precision needed to represent the values between LOW and | |
454 UP. */ | |
455 | |
456 static int | |
457 precision_for_interval (mpz_t low, mpz_t up) | |
458 { | |
459 mpz_t diff; | |
460 int precision; | |
461 | |
462 gcc_assert (value_le (low, up)); | |
463 | |
464 value_init (diff); | |
465 value_subtract (diff, up, low); | |
466 precision = precision_for_value (diff); | |
467 value_clear (diff); | |
468 | |
469 return precision; | |
470 } | |
471 | |
472 /* Return a type that could represent the integer value VAL, or | |
473 otherwise return NULL_TREE. */ | |
474 | |
475 static tree | |
476 gcc_type_for_interval (mpz_t low, mpz_t up, tree old_type) | |
477 { | |
478 bool unsigned_p = true; | |
479 int precision, prec_up, prec_int; | |
480 tree type; | |
481 | |
482 gcc_assert (value_le (low, up)); | |
483 | |
484 /* Preserve the signedness of the old IV. */ | |
485 if ((old_type && !TYPE_UNSIGNED (old_type)) | |
486 || value_neg_p (low)) | |
487 unsigned_p = false; | |
488 | |
489 prec_up = precision_for_value (up); | |
490 prec_int = precision_for_interval (low, up); | |
491 precision = prec_up > prec_int ? prec_up : prec_int; | |
492 | |
493 type = lang_hooks.types.type_for_size (precision, unsigned_p); | |
494 if (!type) | |
495 { | |
496 gloog_error = true; | |
497 return integer_type_node; | |
498 } | |
499 | |
500 return type; | |
501 } | |
502 | |
503 /* Return a type that could represent the integer value VAL, or | |
504 otherwise return NULL_TREE. */ | |
505 | |
506 static tree | |
507 gcc_type_for_value (mpz_t val) | |
508 { | |
509 return gcc_type_for_interval (val, val, NULL_TREE); | |
510 } | |
511 | |
512 /* Return the type for the clast_term T used in STMT. */ | |
513 | |
514 static tree | |
515 gcc_type_for_clast_term (struct clast_term *t, | |
516 sese region, VEC (tree, heap) *newivs, | |
517 htab_t newivs_index, htab_t params_index) | |
518 { | |
519 gcc_assert (t->expr.type == expr_term); | |
520 | |
521 if (!t->var) | |
522 return gcc_type_for_value (t->val); | |
523 | |
524 return TREE_TYPE (clast_name_to_gcc (t->var, region, newivs, | |
525 newivs_index, params_index)); | |
526 } | |
527 | |
528 static tree | |
529 gcc_type_for_clast_expr (struct clast_expr *, sese, | |
530 VEC (tree, heap) *, htab_t, htab_t); | |
531 | |
532 /* Return the type for the clast_reduction R used in STMT. */ | |
533 | |
534 static tree | |
535 gcc_type_for_clast_red (struct clast_reduction *r, sese region, | |
536 VEC (tree, heap) *newivs, | |
537 htab_t newivs_index, htab_t params_index) | |
538 { | |
539 int i; | |
540 tree type = NULL_TREE; | |
541 | |
542 if (r->n == 1) | |
543 return gcc_type_for_clast_expr (r->elts[0], region, newivs, | |
544 newivs_index, params_index); | |
545 | |
546 switch (r->type) | |
547 { | |
548 case clast_red_sum: | |
549 case clast_red_min: | |
550 case clast_red_max: | |
551 type = gcc_type_for_clast_expr (r->elts[0], region, newivs, | |
552 newivs_index, params_index); | |
553 for (i = 1; i < r->n; i++) | |
554 type = max_precision_type (type, gcc_type_for_clast_expr | |
555 (r->elts[i], region, newivs, | |
556 newivs_index, params_index)); | |
557 | |
558 return type; | |
559 | |
560 default: | |
561 break; | |
562 } | |
563 | |
564 gcc_unreachable (); | |
565 return NULL_TREE; | |
566 } | |
567 | |
568 /* Return the type for the clast_binary B used in STMT. */ | |
569 | |
570 static tree | |
571 gcc_type_for_clast_bin (struct clast_binary *b, | |
572 sese region, VEC (tree, heap) *newivs, | |
573 htab_t newivs_index, htab_t params_index) | |
574 { | |
575 tree l = gcc_type_for_clast_expr ((struct clast_expr *) b->LHS, region, | |
576 newivs, newivs_index, params_index); | |
577 tree r = gcc_type_for_value (b->RHS); | |
578 return max_signed_precision_type (l, r); | |
579 } | |
580 | |
581 /* Returns the type for the CLAST expression E when used in statement | |
582 STMT. */ | |
361 | 583 |
362 static tree | 584 static tree |
363 gcc_type_for_clast_expr (struct clast_expr *e, | 585 gcc_type_for_clast_expr (struct clast_expr *e, |
364 sese region, VEC (tree, heap) *newivs, | 586 sese region, VEC (tree, heap) *newivs, |
365 htab_t newivs_index, htab_t params_index) | 587 htab_t newivs_index, htab_t params_index) |
366 { | 588 { |
367 switch (e->type) | 589 switch (e->type) |
368 { | 590 { |
369 case expr_term: | 591 case expr_term: |
370 { | 592 return gcc_type_for_clast_term ((struct clast_term *) e, region, |
371 struct clast_term *t = (struct clast_term *) e; | 593 newivs, newivs_index, params_index); |
372 | |
373 if (t->var) | |
374 return TREE_TYPE (clast_name_to_gcc (t->var, region, newivs, | |
375 newivs_index, params_index)); | |
376 else | |
377 return NULL_TREE; | |
378 } | |
379 | 594 |
380 case expr_red: | 595 case expr_red: |
381 { | 596 return gcc_type_for_clast_red ((struct clast_reduction *) e, region, |
382 struct clast_reduction *r = (struct clast_reduction *) e; | 597 newivs, newivs_index, params_index); |
383 | |
384 if (r->n == 1) | |
385 return gcc_type_for_clast_expr (r->elts[0], region, newivs, | |
386 newivs_index, params_index); | |
387 else | |
388 { | |
389 int i; | |
390 for (i = 0; i < r->n; i++) | |
391 { | |
392 tree type = gcc_type_for_clast_expr (r->elts[i], region, | |
393 newivs, newivs_index, | |
394 params_index); | |
395 if (type) | |
396 return type; | |
397 } | |
398 return NULL_TREE; | |
399 } | |
400 } | |
401 | 598 |
402 case expr_bin: | 599 case expr_bin: |
403 { | 600 return gcc_type_for_clast_bin ((struct clast_binary *) e, region, |
404 struct clast_binary *b = (struct clast_binary *) e; | 601 newivs, newivs_index, params_index); |
405 struct clast_expr *lhs = (struct clast_expr *) b->LHS; | |
406 return gcc_type_for_clast_expr (lhs, region, newivs, | |
407 newivs_index, params_index); | |
408 } | |
409 | 602 |
410 default: | 603 default: |
411 gcc_unreachable (); | 604 gcc_unreachable (); |
412 } | 605 } |
413 | 606 |
419 static tree | 612 static tree |
420 gcc_type_for_clast_eq (struct clast_equation *cleq, | 613 gcc_type_for_clast_eq (struct clast_equation *cleq, |
421 sese region, VEC (tree, heap) *newivs, | 614 sese region, VEC (tree, heap) *newivs, |
422 htab_t newivs_index, htab_t params_index) | 615 htab_t newivs_index, htab_t params_index) |
423 { | 616 { |
424 tree type = gcc_type_for_clast_expr (cleq->LHS, region, newivs, | 617 tree l = gcc_type_for_clast_expr (cleq->LHS, region, newivs, |
425 newivs_index, params_index); | 618 newivs_index, params_index); |
426 if (type) | 619 tree r = gcc_type_for_clast_expr (cleq->RHS, region, newivs, |
427 return type; | 620 newivs_index, params_index); |
428 | 621 return max_precision_type (l, r); |
429 return gcc_type_for_clast_expr (cleq->RHS, region, newivs, newivs_index, | |
430 params_index); | |
431 } | 622 } |
432 | 623 |
433 /* Translates a clast equation CLEQ to a tree. */ | 624 /* Translates a clast equation CLEQ to a tree. */ |
434 | 625 |
435 static tree | 626 static tree |
495 newivs_index, params_index); | 686 newivs_index, params_index); |
496 edge exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr); | 687 edge exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr); |
497 return exit_edge; | 688 return exit_edge; |
498 } | 689 } |
499 | 690 |
691 /* Compute the lower bound LOW and upper bound UP for the induction | |
692 variable at LEVEL for the statement PBB, based on the transformed | |
693 scattering of PBB: T|I|G|Cst, with T the scattering transform, I | |
694 the iteration domain, and G the context parameters. */ | |
695 | |
696 static void | |
697 compute_bounds_for_level (poly_bb_p pbb, int level, mpz_t low, mpz_t up) | |
698 { | |
699 ppl_Pointset_Powerset_C_Polyhedron_t ps; | |
700 ppl_Linear_Expression_t le; | |
701 | |
702 combine_context_id_scat (&ps, pbb, false); | |
703 | |
704 /* Prepare the linear expression corresponding to the level that we | |
705 want to maximize/minimize. */ | |
706 { | |
707 ppl_dimension_type dim = pbb_nb_scattering_transform (pbb) | |
708 + pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb); | |
709 | |
710 ppl_new_Linear_Expression_with_dimension (&le, dim); | |
711 ppl_set_coef (le, 2 * level + 1, 1); | |
712 } | |
713 | |
714 ppl_max_for_le_pointset (ps, le, up); | |
715 ppl_min_for_le_pointset (ps, le, low); | |
716 } | |
717 | |
718 /* Compute the type for the induction variable at LEVEL for the | |
719 statement PBB, based on the transformed schedule of PBB. OLD_TYPE | |
720 is the type of the old induction variable for that loop. */ | |
721 | |
722 static tree | |
723 compute_type_for_level_1 (poly_bb_p pbb, int level, tree old_type) | |
724 { | |
725 mpz_t low, up; | |
726 tree type; | |
727 | |
728 value_init (low); | |
729 value_init (up); | |
730 | |
731 compute_bounds_for_level (pbb, level, low, up); | |
732 type = gcc_type_for_interval (low, up, old_type); | |
733 | |
734 value_clear (low); | |
735 value_clear (up); | |
736 return type; | |
737 } | |
738 | |
739 /* Compute the type for the induction variable at LEVEL for the | |
740 statement PBB, based on the transformed schedule of PBB. */ | |
741 | |
742 static tree | |
743 compute_type_for_level (poly_bb_p pbb, int level) | |
744 { | |
745 tree oldiv = pbb_to_depth_to_oldiv (pbb, level); | |
746 tree type = TREE_TYPE (oldiv); | |
747 | |
748 if (type && POINTER_TYPE_P (type)) | |
749 { | |
750 #ifdef ENABLE_CHECKING | |
751 tree ctype = compute_type_for_level_1 (pbb, level, type); | |
752 | |
753 /* In the case of a pointer type, check that after the loop | |
754 transform, the lower and the upper bounds of the type fit the | |
755 oldiv pointer type. */ | |
756 gcc_assert (TYPE_PRECISION (type) >= TYPE_PRECISION (ctype) | |
757 && integer_zerop (lower_bound_in_type (ctype, ctype))); | |
758 #endif | |
759 return type; | |
760 } | |
761 | |
762 return compute_type_for_level_1 (pbb, level, type); | |
763 } | |
764 | |
500 /* Walks a CLAST and returns the first statement in the body of a | 765 /* Walks a CLAST and returns the first statement in the body of a |
501 loop. */ | 766 loop. */ |
502 | 767 |
503 static struct clast_user_stmt * | 768 static struct clast_user_stmt * |
504 clast_get_body_of_loop (struct clast_stmt *stmt) | 769 clast_get_body_of_loop (struct clast_stmt *stmt) |
517 return clast_get_body_of_loop (((struct clast_block *) stmt)->body); | 782 return clast_get_body_of_loop (((struct clast_block *) stmt)->body); |
518 | 783 |
519 gcc_unreachable (); | 784 gcc_unreachable (); |
520 } | 785 } |
521 | 786 |
522 /* Given a CLOOG_IV, returns the type that it should have in GCC land. | 787 /* Returns the type for the induction variable for the loop translated |
523 If the information is not available, i.e. in the case one of the | 788 from STMT_FOR. */ |
524 transforms created the loop, just return integer_type_node. */ | 789 |
525 | 790 static tree |
526 static tree | 791 gcc_type_for_iv_of_clast_loop (struct clast_for *stmt_for, int level, |
527 gcc_type_for_cloog_iv (const char *cloog_iv, gimple_bb_p gbb) | 792 tree lb_type, tree ub_type) |
528 { | |
529 struct ivtype_map_elt_s tmp; | |
530 PTR *slot; | |
531 | |
532 tmp.cloog_iv = cloog_iv; | |
533 slot = htab_find_slot (GBB_CLOOG_IV_TYPES (gbb), &tmp, NO_INSERT); | |
534 | |
535 if (slot && *slot) | |
536 return ((ivtype_map_elt) *slot)->type; | |
537 | |
538 return integer_type_node; | |
539 } | |
540 | |
541 /* Returns the induction variable for the loop that gets translated to | |
542 STMT. */ | |
543 | |
544 static tree | |
545 gcc_type_for_iv_of_clast_loop (struct clast_for *stmt_for) | |
546 { | 793 { |
547 struct clast_stmt *stmt = (struct clast_stmt *) stmt_for; | 794 struct clast_stmt *stmt = (struct clast_stmt *) stmt_for; |
548 struct clast_user_stmt *body = clast_get_body_of_loop (stmt); | 795 struct clast_user_stmt *body = clast_get_body_of_loop (stmt); |
549 const char *cloog_iv = stmt_for->iterator; | |
550 CloogStatement *cs = body->statement; | 796 CloogStatement *cs = body->statement; |
551 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs); | 797 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs); |
552 | 798 |
553 return gcc_type_for_cloog_iv (cloog_iv, PBB_BLACK_BOX (pbb)); | 799 return max_signed_precision_type (lb_type, max_precision_type |
800 (ub_type, compute_type_for_level | |
801 (pbb, level - 1))); | |
554 } | 802 } |
555 | 803 |
556 /* Creates a new LOOP corresponding to Cloog's STMT. Inserts an | 804 /* Creates a new LOOP corresponding to Cloog's STMT. Inserts an |
557 induction variable for the new LOOP. New LOOP is attached to CFG | 805 induction variable for the new LOOP. New LOOP is attached to CFG |
558 starting at ENTRY_EDGE. LOOP is inserted into the loop tree and | 806 starting at ENTRY_EDGE. LOOP is inserted into the loop tree and |
563 | 811 |
564 static struct loop * | 812 static struct loop * |
565 graphite_create_new_loop (sese region, edge entry_edge, | 813 graphite_create_new_loop (sese region, edge entry_edge, |
566 struct clast_for *stmt, | 814 struct clast_for *stmt, |
567 loop_p outer, VEC (tree, heap) **newivs, | 815 loop_p outer, VEC (tree, heap) **newivs, |
568 htab_t newivs_index, htab_t params_index) | 816 htab_t newivs_index, htab_t params_index, int level) |
569 { | 817 { |
570 tree type = gcc_type_for_iv_of_clast_loop (stmt); | 818 tree lb_type = gcc_type_for_clast_expr (stmt->LB, region, *newivs, |
819 newivs_index, params_index); | |
820 tree ub_type = gcc_type_for_clast_expr (stmt->UB, region, *newivs, | |
821 newivs_index, params_index); | |
822 tree type = gcc_type_for_iv_of_clast_loop (stmt, level, lb_type, ub_type); | |
571 tree lb = clast_to_gcc_expression (type, stmt->LB, region, *newivs, | 823 tree lb = clast_to_gcc_expression (type, stmt->LB, region, *newivs, |
572 newivs_index, params_index); | 824 newivs_index, params_index); |
573 tree ub = clast_to_gcc_expression (type, stmt->UB, region, *newivs, | 825 tree ub = clast_to_gcc_expression (type, stmt->UB, region, *newivs, |
574 newivs_index, params_index); | 826 newivs_index, params_index); |
575 tree stride = gmp_cst_to_tree (type, stmt->stride); | 827 tree stride = gmp_cst_to_tree (type, stmt->stride); |
627 PTR *x; | 879 PTR *x; |
628 | 880 |
629 tmp.old_name = old_name; | 881 tmp.old_name = old_name; |
630 x = htab_find_slot (res, &tmp, INSERT); | 882 x = htab_find_slot (res, &tmp, INSERT); |
631 | 883 |
632 if (!*x) | 884 if (x && !*x) |
633 *x = new_rename_map_elt (old_name, expr); | 885 *x = new_rename_map_elt (old_name, expr); |
634 | 886 |
635 return 1; | 887 return 1; |
636 } | 888 } |
637 | 889 |
658 PTR *x; | 910 PTR *x; |
659 | 911 |
660 tmp.bb = bb; | 912 tmp.bb = bb; |
661 x = htab_find_slot (bb_pbb_mapping, &tmp, INSERT); | 913 x = htab_find_slot (bb_pbb_mapping, &tmp, INSERT); |
662 | 914 |
663 if (!*x) | 915 if (x && !*x) |
664 *x = new_bb_pbb_def (bb, pbb); | 916 *x = new_bb_pbb_def (bb, pbb); |
665 } | 917 } |
666 | 918 |
667 /* Find BB's related poly_bb_p in hash table BB_PBB_MAPPING. */ | 919 /* Find BB's related poly_bb_p in hash table BB_PBB_MAPPING. */ |
668 | 920 |
717 | 969 |
718 return false; | 970 return false; |
719 } | 971 } |
720 | 972 |
721 static edge | 973 static edge |
722 translate_clast (sese, struct clast_stmt *, edge, htab_t, VEC (tree, heap) **, | 974 translate_clast (sese, loop_p, struct clast_stmt *, edge, htab_t, |
723 htab_t, htab_t, htab_t); | 975 VEC (tree, heap) **, htab_t, htab_t, int, htab_t); |
724 | 976 |
725 /* Translates a clast user statement STMT to gimple. | 977 /* Translates a clast user statement STMT to gimple. |
726 | 978 |
727 - REGION is the sese region we used to generate the scop. | 979 - REGION is the sese region we used to generate the scop. |
728 - NEXT_E is the edge where new generated code should be attached. | 980 - NEXT_E is the edge where new generated code should be attached. |
981 - CONTEXT_LOOP is the loop in which the generated code will be placed | |
729 - RENAME_MAP contains a set of tuples of new names associated to | 982 - RENAME_MAP contains a set of tuples of new names associated to |
730 the original variables names. | 983 the original variables names. |
731 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. | 984 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. |
732 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in | 985 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in |
733 the sese region. */ | 986 the sese region. */ |
735 translate_clast_user (sese region, struct clast_user_stmt *stmt, edge next_e, | 988 translate_clast_user (sese region, struct clast_user_stmt *stmt, edge next_e, |
736 htab_t rename_map, VEC (tree, heap) **newivs, | 989 htab_t rename_map, VEC (tree, heap) **newivs, |
737 htab_t newivs_index, htab_t bb_pbb_mapping, | 990 htab_t newivs_index, htab_t bb_pbb_mapping, |
738 htab_t params_index) | 991 htab_t params_index) |
739 { | 992 { |
993 gimple_bb_p gbb; | |
994 basic_block new_bb; | |
740 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (stmt->statement); | 995 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (stmt->statement); |
741 gimple_bb_p gbb = PBB_BLACK_BOX (pbb); | 996 gbb = PBB_BLACK_BOX (pbb); |
742 | 997 |
743 if (GBB_BB (gbb) == ENTRY_BLOCK_PTR) | 998 if (GBB_BB (gbb) == ENTRY_BLOCK_PTR) |
744 return next_e; | 999 return next_e; |
745 | 1000 |
746 build_iv_mapping (rename_map, region, *newivs, newivs_index, stmt, | 1001 build_iv_mapping (rename_map, region, *newivs, newivs_index, stmt, |
747 params_index); | 1002 params_index); |
748 next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb), region, | 1003 next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb), region, |
749 next_e, rename_map); | 1004 next_e, rename_map); |
750 mark_bb_with_pbb (pbb, next_e->src, bb_pbb_mapping); | 1005 new_bb = next_e->src; |
1006 mark_bb_with_pbb (pbb, new_bb, bb_pbb_mapping); | |
751 update_ssa (TODO_update_ssa); | 1007 update_ssa (TODO_update_ssa); |
752 | 1008 |
753 return next_e; | 1009 return next_e; |
754 } | 1010 } |
755 | |
756 /* Mark a loop parallel, if the graphite dependency check cannot find any | |
757 dependencies. This triggers parallel code generation in the autopar pass. | |
758 */ | |
759 static void | |
760 try_mark_loop_parallel (sese region, loop_p loop, htab_t bb_pbb_mapping) | |
761 { | |
762 loop_p outermost_loop = SESE_ENTRY (region)->src->loop_father; | |
763 int level = loop_depth (loop) - loop_depth (outermost_loop); | |
764 | |
765 if (flag_loop_parallelize_all | |
766 && !dependency_in_loop_p (loop, bb_pbb_mapping, | |
767 get_scattering_level (level))) | |
768 loop->can_be_parallel = true; | |
769 } | |
770 | |
771 static tree gcc_type_for_iv_of_clast_loop (struct clast_for *); | |
772 | |
773 | 1011 |
774 /* Creates a new if region protecting the loop to be executed, if the execution | 1012 /* Creates a new if region protecting the loop to be executed, if the execution |
775 count is zero (lb > ub). */ | 1013 count is zero (lb > ub). */ |
776 static edge | 1014 static edge |
777 graphite_create_new_loop_guard (sese region, edge entry_edge, | 1015 graphite_create_new_loop_guard (sese region, edge entry_edge, |
779 VEC (tree, heap) *newivs, | 1017 VEC (tree, heap) *newivs, |
780 htab_t newivs_index, htab_t params_index) | 1018 htab_t newivs_index, htab_t params_index) |
781 { | 1019 { |
782 tree cond_expr; | 1020 tree cond_expr; |
783 edge exit_edge; | 1021 edge exit_edge; |
784 tree type = gcc_type_for_iv_of_clast_loop (stmt); | 1022 tree lb_type = gcc_type_for_clast_expr (stmt->LB, region, newivs, |
1023 newivs_index, params_index); | |
1024 tree ub_type = gcc_type_for_clast_expr (stmt->UB, region, newivs, | |
1025 newivs_index, params_index); | |
1026 tree type = max_precision_type (lb_type, ub_type); | |
785 tree lb = clast_to_gcc_expression (type, stmt->LB, region, newivs, | 1027 tree lb = clast_to_gcc_expression (type, stmt->LB, region, newivs, |
786 newivs_index, params_index); | 1028 newivs_index, params_index); |
787 tree ub = clast_to_gcc_expression (type, stmt->UB, region, newivs, | 1029 tree ub = clast_to_gcc_expression (type, stmt->UB, region, newivs, |
788 newivs_index, params_index); | 1030 newivs_index, params_index); |
789 | 1031 tree ub_one; |
790 /* XXX: Adding +1 and using LT_EXPR helps with loop latches that have a | 1032 |
1033 /* Adding +1 and using LT_EXPR helps with loop latches that have a | |
791 loop iteration count of "PARAMETER - 1". For PARAMETER == 0 this becomes | 1034 loop iteration count of "PARAMETER - 1". For PARAMETER == 0 this becomes |
792 2^{32|64}, and the condition lb <= ub is true, even if we do not want this. | 1035 2^{32|64}, and the condition lb <= ub is true, even if we do not want this. |
793 However lb < ub + 1 is false, as expected. | 1036 However lb < ub + 1 is false, as expected. */ |
794 There might be a problem with cases where ub is 2^32. */ | |
795 tree one; | 1037 tree one; |
796 Value gmp_one; | 1038 mpz_t gmp_one; |
797 value_init (gmp_one); | 1039 |
798 value_set_si (gmp_one, 1); | 1040 mpz_init (gmp_one); |
1041 mpz_set_si (gmp_one, 1); | |
799 one = gmp_cst_to_tree (type, gmp_one); | 1042 one = gmp_cst_to_tree (type, gmp_one); |
800 value_clear (gmp_one); | 1043 mpz_clear (gmp_one); |
801 | 1044 |
802 ub = fold_build2 (PLUS_EXPR, type, ub, one); | 1045 ub_one = fold_build2 (POINTER_TYPE_P (type) ? POINTER_PLUS_EXPR : PLUS_EXPR, |
803 cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub); | 1046 type, ub, one); |
1047 | |
1048 /* When ub + 1 wraps around, use lb <= ub. */ | |
1049 if (integer_zerop (ub_one)) | |
1050 cond_expr = fold_build2 (LE_EXPR, boolean_type_node, lb, ub); | |
1051 else | |
1052 cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one); | |
804 | 1053 |
805 exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr); | 1054 exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr); |
806 | 1055 |
807 return exit_edge; | 1056 return exit_edge; |
808 } | 1057 } |
816 the original variables names. | 1065 the original variables names. |
817 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. | 1066 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. |
818 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in | 1067 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in |
819 the sese region. */ | 1068 the sese region. */ |
820 static edge | 1069 static edge |
821 translate_clast_for_loop (sese region, struct clast_for *stmt, edge next_e, | 1070 translate_clast_for_loop (sese region, loop_p context_loop, |
822 htab_t rename_map, VEC (tree, heap) **newivs, | 1071 struct clast_for *stmt, edge next_e, |
823 htab_t newivs_index, htab_t bb_pbb_mapping, | 1072 htab_t rename_map, VEC (tree, heap) **newivs, |
824 htab_t params_index) | 1073 htab_t newivs_index, htab_t bb_pbb_mapping, |
825 { | 1074 int level, htab_t params_index) |
826 loop_p context_loop = next_e->dest->loop_father; | 1075 { |
827 loop_p loop = graphite_create_new_loop (region, next_e, stmt, context_loop, | 1076 struct loop *loop = graphite_create_new_loop (region, next_e, stmt, |
828 newivs, newivs_index, params_index); | 1077 context_loop, newivs, |
1078 newivs_index, params_index, | |
1079 level); | |
829 edge last_e = single_exit (loop); | 1080 edge last_e = single_exit (loop); |
830 edge body = single_succ_edge (loop->header); | 1081 edge to_body = single_succ_edge (loop->header); |
831 | 1082 basic_block after = to_body->dest; |
832 next_e = translate_clast (region, stmt->body, body, rename_map, newivs, | |
833 newivs_index, bb_pbb_mapping, params_index); | |
834 | 1083 |
835 /* Create a basic block for loop close phi nodes. */ | 1084 /* Create a basic block for loop close phi nodes. */ |
836 last_e = single_succ_edge (split_edge (last_e)); | 1085 last_e = single_succ_edge (split_edge (last_e)); |
1086 | |
1087 /* Translate the body of the loop. */ | |
1088 next_e = translate_clast (region, loop, stmt->body, to_body, rename_map, | |
1089 newivs, newivs_index, bb_pbb_mapping, level + 1, | |
1090 params_index); | |
1091 redirect_edge_succ_nodup (next_e, after); | |
1092 set_immediate_dominator (CDI_DOMINATORS, next_e->dest, next_e->src); | |
1093 | |
1094 /* Remove from rename_map all the tuples containing variables | |
1095 defined in loop's body. */ | |
837 insert_loop_close_phis (rename_map, loop); | 1096 insert_loop_close_phis (rename_map, loop); |
838 | 1097 |
839 try_mark_loop_parallel (region, loop, bb_pbb_mapping); | 1098 if (flag_loop_parallelize_all |
1099 && !dependency_in_loop_p (loop, bb_pbb_mapping, | |
1100 get_scattering_level (level))) | |
1101 loop->can_be_parallel = true; | |
840 | 1102 |
841 return last_e; | 1103 return last_e; |
842 } | 1104 } |
843 | 1105 |
844 /* Translates a clast for statement STMT to gimple. First a guard is created | 1106 /* Translates a clast for statement STMT to gimple. First a guard is created |
851 the original variables names. | 1113 the original variables names. |
852 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. | 1114 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. |
853 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in | 1115 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in |
854 the sese region. */ | 1116 the sese region. */ |
855 static edge | 1117 static edge |
856 translate_clast_for (sese region, struct clast_for *stmt, edge next_e, | 1118 translate_clast_for (sese region, loop_p context_loop, struct clast_for *stmt, |
857 htab_t rename_map, VEC (tree, heap) **newivs, | 1119 edge next_e, htab_t rename_map, VEC (tree, heap) **newivs, |
858 htab_t newivs_index, htab_t bb_pbb_mapping, | 1120 htab_t newivs_index, htab_t bb_pbb_mapping, int level, |
859 htab_t params_index) | 1121 htab_t params_index) |
860 { | 1122 { |
861 edge last_e = graphite_create_new_loop_guard (region, next_e, stmt, *newivs, | 1123 edge last_e = graphite_create_new_loop_guard (region, next_e, stmt, *newivs, |
862 newivs_index, params_index); | 1124 newivs_index, params_index); |
863 | 1125 |
864 edge true_e = get_true_edge_from_guard_bb (next_e->dest); | 1126 edge true_e = get_true_edge_from_guard_bb (next_e->dest); |
865 edge false_e = get_false_edge_from_guard_bb (next_e->dest); | 1127 edge false_e = get_false_edge_from_guard_bb (next_e->dest); |
866 edge exit_true_e = single_succ_edge (true_e->dest); | 1128 edge exit_true_e = single_succ_edge (true_e->dest); |
867 edge exit_false_e = single_succ_edge (false_e->dest); | 1129 edge exit_false_e = single_succ_edge (false_e->dest); |
868 | 1130 |
869 htab_t before_guard = htab_create (10, rename_map_elt_info, | 1131 htab_t before_guard = htab_create (10, rename_map_elt_info, |
870 eq_rename_map_elts, free); | 1132 eq_rename_map_elts, free); |
871 htab_traverse (rename_map, copy_renames, before_guard); | 1133 htab_traverse (rename_map, copy_renames, before_guard); |
872 | 1134 |
873 next_e = translate_clast_for_loop (region, stmt, true_e, rename_map, newivs, | 1135 next_e = translate_clast_for_loop (region, context_loop, stmt, true_e, |
874 newivs_index, bb_pbb_mapping, | 1136 rename_map, newivs, |
1137 newivs_index, bb_pbb_mapping, level, | |
875 params_index); | 1138 params_index); |
876 | 1139 |
877 insert_guard_phis (last_e->src, exit_true_e, exit_false_e, | 1140 insert_guard_phis (last_e->src, exit_true_e, exit_false_e, |
878 before_guard, rename_map); | 1141 before_guard, rename_map); |
879 | 1142 |
884 | 1147 |
885 /* Translates a clast guard statement STMT to gimple. | 1148 /* Translates a clast guard statement STMT to gimple. |
886 | 1149 |
887 - REGION is the sese region we used to generate the scop. | 1150 - REGION is the sese region we used to generate the scop. |
888 - NEXT_E is the edge where new generated code should be attached. | 1151 - NEXT_E is the edge where new generated code should be attached. |
1152 - CONTEXT_LOOP is the loop in which the generated code will be placed | |
889 - RENAME_MAP contains a set of tuples of new names associated to | 1153 - RENAME_MAP contains a set of tuples of new names associated to |
890 the original variables names. | 1154 the original variables names. |
891 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. | 1155 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. |
892 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in | 1156 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in |
893 the sese region. */ | 1157 the sese region. */ |
894 static edge | 1158 static edge |
895 translate_clast_guard (sese region, struct clast_guard *stmt, edge next_e, | 1159 translate_clast_guard (sese region, loop_p context_loop, |
1160 struct clast_guard *stmt, edge next_e, | |
896 htab_t rename_map, VEC (tree, heap) **newivs, | 1161 htab_t rename_map, VEC (tree, heap) **newivs, |
897 htab_t newivs_index, htab_t bb_pbb_mapping, | 1162 htab_t newivs_index, htab_t bb_pbb_mapping, int level, |
898 htab_t params_index) | 1163 htab_t params_index) |
899 { | 1164 { |
900 edge last_e = graphite_create_new_guard (region, next_e, stmt, *newivs, | 1165 edge last_e = graphite_create_new_guard (region, next_e, stmt, *newivs, |
901 newivs_index, params_index); | 1166 newivs_index, params_index); |
902 | 1167 |
907 | 1172 |
908 htab_t before_guard = htab_create (10, rename_map_elt_info, | 1173 htab_t before_guard = htab_create (10, rename_map_elt_info, |
909 eq_rename_map_elts, free); | 1174 eq_rename_map_elts, free); |
910 htab_traverse (rename_map, copy_renames, before_guard); | 1175 htab_traverse (rename_map, copy_renames, before_guard); |
911 | 1176 |
912 next_e = translate_clast (region, stmt->then, true_e, | 1177 next_e = translate_clast (region, context_loop, stmt->then, true_e, |
913 rename_map, newivs, newivs_index, bb_pbb_mapping, | 1178 rename_map, newivs, newivs_index, bb_pbb_mapping, |
914 params_index); | 1179 level, params_index); |
915 | 1180 |
916 insert_guard_phis (last_e->src, exit_true_e, exit_false_e, | 1181 insert_guard_phis (last_e->src, exit_true_e, exit_false_e, |
917 before_guard, rename_map); | 1182 before_guard, rename_map); |
918 | 1183 |
919 htab_delete (before_guard); | 1184 htab_delete (before_guard); |
923 | 1188 |
924 /* Translates a CLAST statement STMT to GCC representation in the | 1189 /* Translates a CLAST statement STMT to GCC representation in the |
925 context of a SESE. | 1190 context of a SESE. |
926 | 1191 |
927 - NEXT_E is the edge where new generated code should be attached. | 1192 - NEXT_E is the edge where new generated code should be attached. |
1193 - CONTEXT_LOOP is the loop in which the generated code will be placed | |
928 - RENAME_MAP contains a set of tuples of new names associated to | 1194 - RENAME_MAP contains a set of tuples of new names associated to |
929 the original variables names. | 1195 the original variables names. |
930 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. */ | 1196 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. */ |
931 static edge | 1197 static edge |
932 translate_clast (sese region, struct clast_stmt *stmt, | 1198 translate_clast (sese region, loop_p context_loop, struct clast_stmt *stmt, |
933 edge next_e, htab_t rename_map, VEC (tree, heap) **newivs, | 1199 edge next_e, htab_t rename_map, VEC (tree, heap) **newivs, |
934 htab_t newivs_index, htab_t bb_pbb_mapping, | 1200 htab_t newivs_index, htab_t bb_pbb_mapping, int level, |
935 htab_t params_index) | 1201 htab_t params_index) |
936 { | 1202 { |
937 if (!stmt) | 1203 if (!stmt) |
938 return next_e; | 1204 return next_e; |
939 | 1205 |
944 next_e = translate_clast_user (region, (struct clast_user_stmt *) stmt, | 1210 next_e = translate_clast_user (region, (struct clast_user_stmt *) stmt, |
945 next_e, rename_map, newivs, newivs_index, | 1211 next_e, rename_map, newivs, newivs_index, |
946 bb_pbb_mapping, params_index); | 1212 bb_pbb_mapping, params_index); |
947 | 1213 |
948 else if (CLAST_STMT_IS_A (stmt, stmt_for)) | 1214 else if (CLAST_STMT_IS_A (stmt, stmt_for)) |
949 next_e = translate_clast_for (region, | 1215 next_e = translate_clast_for (region, context_loop, |
950 (struct clast_for *) stmt, next_e, rename_map, | 1216 (struct clast_for *) stmt, next_e, |
951 newivs, newivs_index, bb_pbb_mapping, | 1217 rename_map, newivs, newivs_index, |
952 params_index); | 1218 bb_pbb_mapping, level, params_index); |
953 | 1219 |
954 else if (CLAST_STMT_IS_A (stmt, stmt_guard)) | 1220 else if (CLAST_STMT_IS_A (stmt, stmt_guard)) |
955 next_e = translate_clast_guard (region, (struct clast_guard *) stmt, next_e, | 1221 next_e = translate_clast_guard (region, context_loop, |
1222 (struct clast_guard *) stmt, next_e, | |
956 rename_map, newivs, newivs_index, | 1223 rename_map, newivs, newivs_index, |
957 bb_pbb_mapping, params_index); | 1224 bb_pbb_mapping, level, params_index); |
958 | 1225 |
959 else if (CLAST_STMT_IS_A (stmt, stmt_block)) | 1226 else if (CLAST_STMT_IS_A (stmt, stmt_block)) |
960 next_e = translate_clast (region, ((struct clast_block *) stmt)->body, | 1227 next_e = translate_clast (region, context_loop, |
1228 ((struct clast_block *) stmt)->body, | |
961 next_e, rename_map, newivs, newivs_index, | 1229 next_e, rename_map, newivs, newivs_index, |
962 bb_pbb_mapping, params_index); | 1230 bb_pbb_mapping, level, params_index); |
963 else | 1231 else |
964 gcc_unreachable(); | 1232 gcc_unreachable(); |
965 | 1233 |
966 recompute_all_dominators (); | 1234 recompute_all_dominators (); |
967 graphite_verify (); | 1235 graphite_verify (); |
968 | 1236 |
969 return translate_clast (region, stmt->next, next_e, rename_map, newivs, | 1237 return translate_clast (region, context_loop, stmt->next, next_e, |
970 newivs_index, bb_pbb_mapping, params_index); | 1238 rename_map, newivs, newivs_index, |
971 } | 1239 bb_pbb_mapping, level, params_index); |
972 | |
973 /* Returns the first cloog name used in EXPR. */ | |
974 | |
975 static const char * | |
976 find_cloog_iv_in_expr (struct clast_expr *expr) | |
977 { | |
978 struct clast_term *term = (struct clast_term *) expr; | |
979 | |
980 if (expr->type == expr_term | |
981 && !term->var) | |
982 return NULL; | |
983 | |
984 if (expr->type == expr_term) | |
985 return term->var; | |
986 | |
987 if (expr->type == expr_red) | |
988 { | |
989 int i; | |
990 struct clast_reduction *red = (struct clast_reduction *) expr; | |
991 | |
992 for (i = 0; i < red->n; i++) | |
993 { | |
994 const char *res = find_cloog_iv_in_expr ((red)->elts[i]); | |
995 | |
996 if (res) | |
997 return res; | |
998 } | |
999 } | |
1000 | |
1001 return NULL; | |
1002 } | |
1003 | |
1004 /* Build for a clast_user_stmt USER_STMT a map between the CLAST | |
1005 induction variables and the corresponding GCC old induction | |
1006 variables. This information is stored on each GRAPHITE_BB. */ | |
1007 | |
1008 static void | |
1009 compute_cloog_iv_types_1 (poly_bb_p pbb, struct clast_user_stmt *user_stmt) | |
1010 { | |
1011 gimple_bb_p gbb = PBB_BLACK_BOX (pbb); | |
1012 struct clast_stmt *t; | |
1013 int index = 0; | |
1014 | |
1015 for (t = user_stmt->substitutions; t; t = t->next, index++) | |
1016 { | |
1017 PTR *slot; | |
1018 struct ivtype_map_elt_s tmp; | |
1019 struct clast_expr *expr = (struct clast_expr *) | |
1020 ((struct clast_assignment *)t)->RHS; | |
1021 | |
1022 /* Create an entry (clast_var, type). */ | |
1023 tmp.cloog_iv = find_cloog_iv_in_expr (expr); | |
1024 if (!tmp.cloog_iv) | |
1025 continue; | |
1026 | |
1027 slot = htab_find_slot (GBB_CLOOG_IV_TYPES (gbb), &tmp, INSERT); | |
1028 | |
1029 if (!*slot) | |
1030 { | |
1031 tree oldiv = pbb_to_depth_to_oldiv (pbb, index); | |
1032 tree type = oldiv ? TREE_TYPE (oldiv) : integer_type_node; | |
1033 *slot = new_ivtype_map_elt (tmp.cloog_iv, type); | |
1034 } | |
1035 } | |
1036 } | |
1037 | |
1038 /* Walk the CLAST tree starting from STMT and build for each | |
1039 clast_user_stmt a map between the CLAST induction variables and the | |
1040 corresponding GCC old induction variables. This information is | |
1041 stored on each GRAPHITE_BB. */ | |
1042 | |
1043 static void | |
1044 compute_cloog_iv_types (struct clast_stmt *stmt) | |
1045 { | |
1046 if (!stmt) | |
1047 return; | |
1048 | |
1049 if (CLAST_STMT_IS_A (stmt, stmt_root)) | |
1050 goto next; | |
1051 | |
1052 if (CLAST_STMT_IS_A (stmt, stmt_user)) | |
1053 { | |
1054 CloogStatement *cs = ((struct clast_user_stmt *) stmt)->statement; | |
1055 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs); | |
1056 gimple_bb_p gbb = PBB_BLACK_BOX (pbb); | |
1057 | |
1058 if (!GBB_CLOOG_IV_TYPES (gbb)) | |
1059 GBB_CLOOG_IV_TYPES (gbb) = htab_create (10, ivtype_map_elt_info, | |
1060 eq_ivtype_map_elts, free); | |
1061 | |
1062 compute_cloog_iv_types_1 (pbb, (struct clast_user_stmt *) stmt); | |
1063 goto next; | |
1064 } | |
1065 | |
1066 if (CLAST_STMT_IS_A (stmt, stmt_for)) | |
1067 { | |
1068 struct clast_stmt *s = ((struct clast_for *) stmt)->body; | |
1069 compute_cloog_iv_types (s); | |
1070 goto next; | |
1071 } | |
1072 | |
1073 if (CLAST_STMT_IS_A (stmt, stmt_guard)) | |
1074 { | |
1075 struct clast_stmt *s = ((struct clast_guard *) stmt)->then; | |
1076 compute_cloog_iv_types (s); | |
1077 goto next; | |
1078 } | |
1079 | |
1080 if (CLAST_STMT_IS_A (stmt, stmt_block)) | |
1081 { | |
1082 struct clast_stmt *s = ((struct clast_block *) stmt)->body; | |
1083 compute_cloog_iv_types (s); | |
1084 goto next; | |
1085 } | |
1086 | |
1087 gcc_unreachable (); | |
1088 | |
1089 next: | |
1090 compute_cloog_iv_types (stmt->next); | |
1091 } | 1240 } |
1092 | 1241 |
1093 /* Free the SCATTERING domain list. */ | 1242 /* Free the SCATTERING domain list. */ |
1094 | 1243 |
1095 static void | 1244 static void |
1385 debug_generated_program (scop_p scop) | 1534 debug_generated_program (scop_p scop) |
1386 { | 1535 { |
1387 print_generated_program (stderr, scop); | 1536 print_generated_program (stderr, scop); |
1388 } | 1537 } |
1389 | 1538 |
1390 /* Add CLooG names to parameter index. The index is used to translate back from | 1539 /* Add CLooG names to parameter index. The index is used to translate |
1391 * CLooG names to GCC trees. */ | 1540 back from CLooG names to GCC trees. */ |
1392 | 1541 |
1393 static void | 1542 static void |
1394 create_params_index (htab_t index_table, CloogProgram *prog) { | 1543 create_params_index (htab_t index_table, CloogProgram *prog) { |
1395 CloogNames* names = cloog_program_names (prog); | 1544 CloogNames* names = cloog_program_names (prog); |
1396 int nb_parameters = cloog_names_nb_parameters (names); | 1545 int nb_parameters = cloog_names_nb_parameters (names); |
1405 the given SCOP. Return true if code generation succeeded. | 1554 the given SCOP. Return true if code generation succeeded. |
1406 BB_PBB_MAPPING is a basic_block and it's related poly_bb_p mapping. | 1555 BB_PBB_MAPPING is a basic_block and it's related poly_bb_p mapping. |
1407 */ | 1556 */ |
1408 | 1557 |
1409 bool | 1558 bool |
1410 gloog (scop_p scop, htab_t bb_pbb_mapping) | 1559 gloog (scop_p scop, VEC (scop_p, heap) *scops, htab_t bb_pbb_mapping) |
1411 { | 1560 { |
1412 edge new_scop_exit_edge = NULL; | |
1413 VEC (tree, heap) *newivs = VEC_alloc (tree, heap, 10); | 1561 VEC (tree, heap) *newivs = VEC_alloc (tree, heap, 10); |
1562 loop_p context_loop; | |
1414 sese region = SCOP_REGION (scop); | 1563 sese region = SCOP_REGION (scop); |
1415 ifsese if_region = NULL; | 1564 ifsese if_region = NULL; |
1416 htab_t rename_map, newivs_index, params_index; | 1565 htab_t rename_map, newivs_index, params_index; |
1417 cloog_prog_clast pc; | 1566 cloog_prog_clast pc; |
1567 int i; | |
1418 | 1568 |
1419 timevar_push (TV_GRAPHITE_CODE_GEN); | 1569 timevar_push (TV_GRAPHITE_CODE_GEN); |
1570 gloog_error = false; | |
1420 | 1571 |
1421 pc = scop_to_clast (scop); | 1572 pc = scop_to_clast (scop); |
1422 | 1573 |
1423 if (dump_file && (dump_flags & TDF_DETAILS)) | 1574 if (dump_file && (dump_flags & TDF_DETAILS)) |
1424 { | 1575 { |
1436 if_region->false_region->exit, | 1587 if_region->false_region->exit, |
1437 if_region->true_region->exit); | 1588 if_region->true_region->exit); |
1438 recompute_all_dominators (); | 1589 recompute_all_dominators (); |
1439 graphite_verify (); | 1590 graphite_verify (); |
1440 | 1591 |
1441 compute_cloog_iv_types (pc.stmt); | 1592 context_loop = SESE_ENTRY (region)->src->loop_father; |
1442 rename_map = htab_create (10, rename_map_elt_info, eq_rename_map_elts, free); | 1593 rename_map = htab_create (10, rename_map_elt_info, eq_rename_map_elts, free); |
1443 newivs_index = htab_create (10, clast_name_index_elt_info, | 1594 newivs_index = htab_create (10, clast_name_index_elt_info, |
1444 eq_clast_name_indexes, free); | 1595 eq_clast_name_indexes, free); |
1445 params_index = htab_create (10, clast_name_index_elt_info, | 1596 params_index = htab_create (10, clast_name_index_elt_info, |
1446 eq_clast_name_indexes, free); | 1597 eq_clast_name_indexes, free); |
1447 | 1598 |
1448 create_params_index (params_index, pc.prog); | 1599 create_params_index (params_index, pc.prog); |
1449 | 1600 |
1450 new_scop_exit_edge = translate_clast (region, pc.stmt, | 1601 translate_clast (region, context_loop, pc.stmt, |
1451 if_region->true_region->entry, | 1602 if_region->true_region->entry, |
1452 rename_map, &newivs, newivs_index, | 1603 rename_map, &newivs, newivs_index, |
1453 bb_pbb_mapping, params_index); | 1604 bb_pbb_mapping, 1, params_index); |
1454 graphite_verify (); | 1605 graphite_verify (); |
1455 sese_adjust_liveout_phis (region, rename_map, | 1606 sese_adjust_liveout_phis (region, rename_map, |
1456 if_region->region->exit->src, | 1607 if_region->region->exit->src, |
1457 if_region->false_region->exit, | 1608 if_region->false_region->exit, |
1458 if_region->true_region->exit); | 1609 if_region->true_region->exit); |
1610 scev_reset_htab (); | |
1611 rename_nb_iterations (rename_map); | |
1612 | |
1613 for (i = 0; VEC_iterate (scop_p, scops, i, scop); i++) | |
1614 rename_sese_parameters (rename_map, SCOP_REGION (scop)); | |
1615 | |
1459 recompute_all_dominators (); | 1616 recompute_all_dominators (); |
1460 graphite_verify (); | 1617 graphite_verify (); |
1618 | |
1619 if (gloog_error) | |
1620 set_ifsese_condition (if_region, integer_zero_node); | |
1461 | 1621 |
1462 free (if_region->true_region); | 1622 free (if_region->true_region); |
1463 free (if_region->region); | 1623 free (if_region->region); |
1464 free (if_region); | 1624 free (if_region); |
1465 | 1625 |
1483 | 1643 |
1484 fprintf (dump_file, "\n%d loops carried no dependency.\n", | 1644 fprintf (dump_file, "\n%d loops carried no dependency.\n", |
1485 num_no_dependency); | 1645 num_no_dependency); |
1486 } | 1646 } |
1487 | 1647 |
1488 return true; | 1648 return !gloog_error; |
1489 } | 1649 } |
1490 | 1650 |
1491 #endif | 1651 #endif |