Fix PR45422
[official-gcc.git] / gcc / graphite-clast-to-gimple.c
blob3f26ad3aaec6320c19b9eab3edcabc9791ce7ba7
1 /* Translation of CLAST (CLooG AST) to Gimple.
2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "ggc.h"
26 #include "tree.h"
27 #include "rtl.h"
28 #include "basic-block.h"
29 #include "diagnostic.h"
30 #include "tree-flow.h"
31 #include "toplev.h"
32 #include "tree-dump.h"
33 #include "timevar.h"
34 #include "cfgloop.h"
35 #include "tree-chrec.h"
36 #include "tree-data-ref.h"
37 #include "tree-scalar-evolution.h"
38 #include "tree-pass.h"
39 #include "domwalk.h"
40 #include "value-prof.h"
41 #include "pointer-set.h"
42 #include "gimple.h"
43 #include "langhooks.h"
44 #include "sese.h"
46 #ifdef HAVE_cloog
47 #include "cloog/cloog.h"
48 #include "ppl_c.h"
49 #include "graphite-cloog-util.h"
50 #include "graphite-ppl.h"
51 #include "graphite.h"
52 #include "graphite-poly.h"
53 #include "graphite-scop-detection.h"
54 #include "graphite-clast-to-gimple.h"
55 #include "graphite-dependences.h"
56 #include "graphite-cloog-compat.h"
58 /* This flag is set when an error occurred during the translation of
59 CLAST to Gimple. */
60 static bool gloog_error;
62 /* Verifies properties that GRAPHITE should maintain during translation. */
64 static inline void
65 graphite_verify (void)
67 #ifdef ENABLE_CHECKING
68 verify_loop_structure ();
69 verify_dominators (CDI_DOMINATORS);
70 verify_dominators (CDI_POST_DOMINATORS);
71 verify_loop_closed_ssa (true);
72 #endif
75 /* Stores the INDEX in a vector for a given clast NAME. */
77 typedef struct clast_name_index {
78 int index;
79 const char *name;
80 } *clast_name_index_p;
82 /* Returns a pointer to a new element of type clast_name_index_p built
83 from NAME and INDEX. */
85 static inline clast_name_index_p
86 new_clast_name_index (const char *name, int index)
88 clast_name_index_p res = XNEW (struct clast_name_index);
90 res->name = name;
91 res->index = index;
92 return res;
95 /* For a given clast NAME, returns -1 if it does not correspond to any
96 parameter, or otherwise, returns the index in the PARAMS or
97 SCATTERING_DIMENSIONS vector. */
99 static inline int
100 clast_name_to_index (clast_name_p name, htab_t index_table)
102 struct clast_name_index tmp;
103 PTR *slot;
105 #ifdef CLOOG_ORG
106 gcc_assert (name->type == clast_expr_name);
107 tmp.name = ((const struct clast_name*) name)->name;
108 #else
109 tmp.name = name;
110 #endif
112 slot = htab_find_slot (index_table, &tmp, NO_INSERT);
114 if (slot && *slot)
115 return ((struct clast_name_index *) *slot)->index;
117 return -1;
120 /* Records in INDEX_TABLE the INDEX for NAME. */
122 static inline void
123 save_clast_name_index (htab_t index_table, const char *name, int index)
125 struct clast_name_index tmp;
126 PTR *slot;
128 tmp.name = name;
129 slot = htab_find_slot (index_table, &tmp, INSERT);
131 if (slot)
133 if (*slot)
134 free (*slot);
136 *slot = new_clast_name_index (name, index);
140 /* Computes a hash function for database element ELT. */
142 static inline hashval_t
143 clast_name_index_elt_info (const void *elt)
145 return htab_hash_pointer (((const struct clast_name_index *) elt)->name);
148 /* Compares database elements E1 and E2. */
150 static inline int
151 eq_clast_name_indexes (const void *e1, const void *e2)
153 const struct clast_name_index *elt1 = (const struct clast_name_index *) e1;
154 const struct clast_name_index *elt2 = (const struct clast_name_index *) e2;
156 return (elt1->name == elt2->name);
159 /* For a given scattering dimension, return the new induction variable
160 associated to it. */
162 static inline tree
163 newivs_to_depth_to_newiv (VEC (tree, heap) *newivs, int depth)
165 return VEC_index (tree, newivs, depth);
170 /* Returns the tree variable from the name NAME that was given in
171 Cloog representation. */
173 static tree
174 clast_name_to_gcc (clast_name_p name, sese region, VEC (tree, heap) *newivs,
175 htab_t newivs_index, htab_t params_index)
177 int index;
178 VEC (tree, heap) *params = SESE_PARAMS (region);
180 if (params && params_index)
182 index = clast_name_to_index (name, params_index);
184 if (index >= 0)
185 return VEC_index (tree, params, index);
188 gcc_assert (newivs && newivs_index);
189 index = clast_name_to_index (name, newivs_index);
190 gcc_assert (index >= 0);
192 return newivs_to_depth_to_newiv (newivs, index);
195 /* Returns the signed maximal precision type for expressions TYPE1 and TYPE2. */
197 static tree
198 max_signed_precision_type (tree type1, tree type2)
200 int p1 = TYPE_PRECISION (type1);
201 int p2 = TYPE_PRECISION (type2);
202 int precision;
203 tree type;
205 if (p1 > p2)
206 precision = TYPE_UNSIGNED (type1) ? p1 * 2 : p1;
207 else
208 precision = TYPE_UNSIGNED (type2) ? p2 * 2 : p2;
210 type = lang_hooks.types.type_for_size (precision, false);
212 if (!type)
214 gloog_error = true;
215 return integer_type_node;
217 return type;
220 /* Returns the maximal precision type for expressions TYPE1 and TYPE2. */
222 static tree
223 max_precision_type (tree type1, tree type2)
225 if (POINTER_TYPE_P (type1))
226 return type1;
228 if (POINTER_TYPE_P (type2))
229 return type2;
231 if (!TYPE_UNSIGNED (type1)
232 || !TYPE_UNSIGNED (type2))
233 return max_signed_precision_type (type1, type2);
235 return TYPE_PRECISION (type1) > TYPE_PRECISION (type2) ? type1 : type2;
238 static tree
239 clast_to_gcc_expression (tree, struct clast_expr *, sese, VEC (tree, heap) *,
240 htab_t, htab_t);
242 /* Converts a Cloog reduction expression R with reduction operation OP
243 to a GCC expression tree of type TYPE. */
245 static tree
246 clast_to_gcc_expression_red (tree type, enum tree_code op,
247 struct clast_reduction *r,
248 sese region, VEC (tree, heap) *newivs,
249 htab_t newivs_index, htab_t params_index)
251 int i;
252 tree res = clast_to_gcc_expression (type, r->elts[0], region, newivs,
253 newivs_index, params_index);
254 tree operand_type = (op == POINTER_PLUS_EXPR) ? sizetype : type;
256 for (i = 1; i < r->n; i++)
258 tree t = clast_to_gcc_expression (operand_type, r->elts[i], region,
259 newivs, newivs_index, params_index);
260 res = fold_build2 (op, type, res, t);
263 return res;
266 /* Converts a Cloog AST expression E back to a GCC expression tree of
267 type TYPE. */
269 static tree
270 clast_to_gcc_expression (tree type, struct clast_expr *e,
271 sese region, VEC (tree, heap) *newivs,
272 htab_t newivs_index, htab_t params_index)
274 switch (e->type)
276 case clast_expr_term:
278 struct clast_term *t = (struct clast_term *) e;
280 if (t->var)
282 if (mpz_cmp_si (t->val, 1) == 0)
284 tree name = clast_name_to_gcc (t->var, region, newivs,
285 newivs_index, params_index);
287 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
288 name = fold_convert (sizetype, name);
290 name = fold_convert (type, name);
291 return name;
294 else if (mpz_cmp_si (t->val, -1) == 0)
296 tree name = clast_name_to_gcc (t->var, region, newivs,
297 newivs_index, params_index);
299 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
300 name = fold_convert (sizetype, name);
302 name = fold_convert (type, name);
304 return fold_build1 (NEGATE_EXPR, type, name);
306 else
308 tree name = clast_name_to_gcc (t->var, region, newivs,
309 newivs_index, params_index);
310 tree cst = gmp_cst_to_tree (type, t->val);
312 if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
313 name = fold_convert (sizetype, name);
315 name = fold_convert (type, name);
317 if (!POINTER_TYPE_P (type))
318 return fold_build2 (MULT_EXPR, type, cst, name);
320 gloog_error = true;
321 return cst;
324 else
325 return gmp_cst_to_tree (type, t->val);
328 case clast_expr_red:
330 struct clast_reduction *r = (struct clast_reduction *) e;
332 switch (r->type)
334 case clast_red_sum:
335 return clast_to_gcc_expression_red
336 (type, POINTER_TYPE_P (type) ? POINTER_PLUS_EXPR : PLUS_EXPR,
337 r, region, newivs, newivs_index, params_index);
339 case clast_red_min:
340 return clast_to_gcc_expression_red (type, MIN_EXPR, r, region,
341 newivs, newivs_index,
342 params_index);
344 case clast_red_max:
345 return clast_to_gcc_expression_red (type, MAX_EXPR, r, region,
346 newivs, newivs_index,
347 params_index);
349 default:
350 gcc_unreachable ();
352 break;
355 case clast_expr_bin:
357 struct clast_binary *b = (struct clast_binary *) e;
358 struct clast_expr *lhs = (struct clast_expr *) b->LHS;
359 tree tl = clast_to_gcc_expression (type, lhs, region, newivs,
360 newivs_index, params_index);
361 tree tr = gmp_cst_to_tree (type, b->RHS);
363 switch (b->type)
365 case clast_bin_fdiv:
366 return fold_build2 (FLOOR_DIV_EXPR, type, tl, tr);
368 case clast_bin_cdiv:
369 return fold_build2 (CEIL_DIV_EXPR, type, tl, tr);
371 case clast_bin_div:
372 return fold_build2 (EXACT_DIV_EXPR, type, tl, tr);
374 case clast_bin_mod:
375 return fold_build2 (TRUNC_MOD_EXPR, type, tl, tr);
377 default:
378 gcc_unreachable ();
382 default:
383 gcc_unreachable ();
386 return NULL_TREE;
389 /* Return the precision needed to represent the value VAL. */
391 static int
392 precision_for_value (mpz_t val)
394 mpz_t x, y, two;
395 int precision;
397 mpz_init (x);
398 mpz_init (y);
399 mpz_init (two);
400 mpz_set_si (x, 2);
401 mpz_set (y, val);
402 mpz_set_si (two, 2);
403 precision = 1;
405 if (mpz_sgn (y) < 0)
406 mpz_neg (y, y);
408 while (mpz_cmp (y, x) > 0)
410 mpz_mul (x, x, two);
411 precision++;
414 mpz_clear (x);
415 mpz_clear (y);
416 mpz_clear (two);
418 return precision;
421 /* Return the precision needed to represent the values between LOW and
422 UP. */
424 static int
425 precision_for_interval (mpz_t low, mpz_t up)
427 mpz_t diff;
428 int precision;
430 gcc_assert (mpz_cmp (low, up) <= 0);
432 mpz_init (diff);
433 mpz_sub (diff, up, low);
434 precision = precision_for_value (diff);
435 mpz_clear (diff);
437 return precision;
440 /* Return a type that could represent the integer value VAL. */
442 static tree
443 gcc_type_for_interval (mpz_t low, mpz_t up)
445 bool unsigned_p = true;
446 int precision, prec_up, prec_int;
447 tree type;
448 enum machine_mode mode;
450 gcc_assert (mpz_cmp (low, up) <= 0);
452 if (mpz_sgn (low) < 0)
453 unsigned_p = false;
455 prec_up = precision_for_value (up);
456 prec_int = precision_for_interval (low, up);
457 precision = MAX (prec_up, prec_int);
459 if (precision > BITS_PER_WORD)
461 gloog_error = true;
462 return integer_type_node;
465 mode = smallest_mode_for_size (precision, MODE_INT);
466 precision = GET_MODE_PRECISION (mode);
467 type = build_nonstandard_integer_type (precision, unsigned_p);
469 if (!type)
471 gloog_error = true;
472 return integer_type_node;
475 return type;
478 /* Return a type that could represent the integer value VAL, or
479 otherwise return NULL_TREE. */
481 static tree
482 gcc_type_for_value (mpz_t val)
484 return gcc_type_for_interval (val, val);
487 /* Return the type for the clast_term T used in STMT. */
489 static tree
490 gcc_type_for_clast_term (struct clast_term *t,
491 sese region, VEC (tree, heap) *newivs,
492 htab_t newivs_index, htab_t params_index)
494 gcc_assert (t->expr.type == clast_expr_term);
496 if (!t->var)
497 return gcc_type_for_value (t->val);
499 return TREE_TYPE (clast_name_to_gcc (t->var, region, newivs,
500 newivs_index, params_index));
503 static tree
504 gcc_type_for_clast_expr (struct clast_expr *, sese,
505 VEC (tree, heap) *, htab_t, htab_t);
507 /* Return the type for the clast_reduction R used in STMT. */
509 static tree
510 gcc_type_for_clast_red (struct clast_reduction *r, sese region,
511 VEC (tree, heap) *newivs,
512 htab_t newivs_index, htab_t params_index)
514 int i;
515 tree type = NULL_TREE;
517 if (r->n == 1)
518 return gcc_type_for_clast_expr (r->elts[0], region, newivs,
519 newivs_index, params_index);
521 switch (r->type)
523 case clast_red_sum:
524 case clast_red_min:
525 case clast_red_max:
526 type = gcc_type_for_clast_expr (r->elts[0], region, newivs,
527 newivs_index, params_index);
528 for (i = 1; i < r->n; i++)
529 type = max_precision_type (type, gcc_type_for_clast_expr
530 (r->elts[i], region, newivs,
531 newivs_index, params_index));
533 return type;
535 default:
536 break;
539 gcc_unreachable ();
540 return NULL_TREE;
543 /* Return the type for the clast_binary B used in STMT. */
545 static tree
546 gcc_type_for_clast_bin (struct clast_binary *b,
547 sese region, VEC (tree, heap) *newivs,
548 htab_t newivs_index, htab_t params_index)
550 tree l = gcc_type_for_clast_expr ((struct clast_expr *) b->LHS, region,
551 newivs, newivs_index, params_index);
552 tree r = gcc_type_for_value (b->RHS);
553 return max_signed_precision_type (l, r);
556 /* Returns the type for the CLAST expression E when used in statement
557 STMT. */
559 static tree
560 gcc_type_for_clast_expr (struct clast_expr *e,
561 sese region, VEC (tree, heap) *newivs,
562 htab_t newivs_index, htab_t params_index)
564 switch (e->type)
566 case clast_expr_term:
567 return gcc_type_for_clast_term ((struct clast_term *) e, region,
568 newivs, newivs_index, params_index);
570 case clast_expr_red:
571 return gcc_type_for_clast_red ((struct clast_reduction *) e, region,
572 newivs, newivs_index, params_index);
574 case clast_expr_bin:
575 return gcc_type_for_clast_bin ((struct clast_binary *) e, region,
576 newivs, newivs_index, params_index);
578 default:
579 gcc_unreachable ();
582 return NULL_TREE;
585 /* Returns the type for the equation CLEQ. */
587 static tree
588 gcc_type_for_clast_eq (struct clast_equation *cleq,
589 sese region, VEC (tree, heap) *newivs,
590 htab_t newivs_index, htab_t params_index)
592 tree l = gcc_type_for_clast_expr (cleq->LHS, region, newivs,
593 newivs_index, params_index);
594 tree r = gcc_type_for_clast_expr (cleq->RHS, region, newivs,
595 newivs_index, params_index);
596 return max_precision_type (l, r);
599 /* Translates a clast equation CLEQ to a tree. */
601 static tree
602 graphite_translate_clast_equation (sese region,
603 struct clast_equation *cleq,
604 VEC (tree, heap) *newivs,
605 htab_t newivs_index, htab_t params_index)
607 enum tree_code comp;
608 tree type = gcc_type_for_clast_eq (cleq, region, newivs, newivs_index,
609 params_index);
610 tree lhs = clast_to_gcc_expression (type, cleq->LHS, region, newivs,
611 newivs_index, params_index);
612 tree rhs = clast_to_gcc_expression (type, cleq->RHS, region, newivs,
613 newivs_index, params_index);
615 if (cleq->sign == 0)
616 comp = EQ_EXPR;
618 else if (cleq->sign > 0)
619 comp = GE_EXPR;
621 else
622 comp = LE_EXPR;
624 return fold_build2 (comp, boolean_type_node, lhs, rhs);
627 /* Creates the test for the condition in STMT. */
629 static tree
630 graphite_create_guard_cond_expr (sese region, struct clast_guard *stmt,
631 VEC (tree, heap) *newivs,
632 htab_t newivs_index, htab_t params_index)
634 tree cond = NULL;
635 int i;
637 for (i = 0; i < stmt->n; i++)
639 tree eq = graphite_translate_clast_equation (region, &stmt->eq[i],
640 newivs, newivs_index,
641 params_index);
643 if (cond)
644 cond = fold_build2 (TRUTH_AND_EXPR, TREE_TYPE (eq), cond, eq);
645 else
646 cond = eq;
649 return cond;
652 /* Creates a new if region corresponding to Cloog's guard. */
654 static edge
655 graphite_create_new_guard (sese region, edge entry_edge,
656 struct clast_guard *stmt,
657 VEC (tree, heap) *newivs,
658 htab_t newivs_index, htab_t params_index)
660 tree cond_expr = graphite_create_guard_cond_expr (region, stmt, newivs,
661 newivs_index, params_index);
662 edge exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr);
663 return exit_edge;
666 /* Compute the lower bound LOW and upper bound UP for the induction
667 variable at LEVEL for the statement PBB, based on the transformed
668 scattering of PBB: T|I|G|Cst, with T the scattering transform, I
669 the iteration domain, and G the context parameters. */
671 static void
672 compute_bounds_for_level (poly_bb_p pbb, int level, mpz_t low, mpz_t up)
674 ppl_Pointset_Powerset_C_Polyhedron_t ps;
675 ppl_Linear_Expression_t le;
677 combine_context_id_scat (&ps, pbb, false);
679 /* Prepare the linear expression corresponding to the level that we
680 want to maximize/minimize. */
682 ppl_dimension_type dim = pbb_nb_scattering_transform (pbb)
683 + pbb_dim_iter_domain (pbb) + pbb_nb_params (pbb);
685 ppl_new_Linear_Expression_with_dimension (&le, dim);
686 ppl_set_coef (le, 2 * level + 1, 1);
689 ppl_max_for_le_pointset (ps, le, up);
690 ppl_min_for_le_pointset (ps, le, low);
693 /* Compute the type for the induction variable at LEVEL for the
694 statement PBB, based on the transformed schedule of PBB. */
696 static tree
697 compute_type_for_level (poly_bb_p pbb, int level)
699 mpz_t low, up;
700 tree type;
702 mpz_init (low);
703 mpz_init (up);
705 compute_bounds_for_level (pbb, level, low, up);
706 type = gcc_type_for_interval (low, up);
708 mpz_clear (low);
709 mpz_clear (up);
710 return type;
713 /* Walks a CLAST and returns the first statement in the body of a
714 loop. */
716 static struct clast_user_stmt *
717 clast_get_body_of_loop (struct clast_stmt *stmt)
719 if (!stmt
720 || CLAST_STMT_IS_A (stmt, stmt_user))
721 return (struct clast_user_stmt *) stmt;
723 if (CLAST_STMT_IS_A (stmt, stmt_for))
724 return clast_get_body_of_loop (((struct clast_for *) stmt)->body);
726 if (CLAST_STMT_IS_A (stmt, stmt_guard))
727 return clast_get_body_of_loop (((struct clast_guard *) stmt)->then);
729 if (CLAST_STMT_IS_A (stmt, stmt_block))
730 return clast_get_body_of_loop (((struct clast_block *) stmt)->body);
732 gcc_unreachable ();
735 /* Returns the type for the induction variable for the loop translated
736 from STMT_FOR. */
738 static tree
739 gcc_type_for_iv_of_clast_loop (struct clast_for *stmt_for, int level,
740 tree lb_type, tree ub_type)
742 struct clast_stmt *stmt = (struct clast_stmt *) stmt_for;
743 struct clast_user_stmt *body = clast_get_body_of_loop (stmt);
744 CloogStatement *cs = body->statement;
745 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs);
747 return max_signed_precision_type (lb_type, max_precision_type
748 (ub_type, compute_type_for_level
749 (pbb, level - 1)));
752 /* Creates a new LOOP corresponding to Cloog's STMT. Inserts an
753 induction variable for the new LOOP. New LOOP is attached to CFG
754 starting at ENTRY_EDGE. LOOP is inserted into the loop tree and
755 becomes the child loop of the OUTER_LOOP. NEWIVS_INDEX binds
756 CLooG's scattering name to the induction variable created for the
757 loop of STMT. The new induction variable is inserted in the NEWIVS
758 vector. */
760 static struct loop *
761 graphite_create_new_loop (sese region, edge entry_edge,
762 struct clast_for *stmt,
763 loop_p outer, VEC (tree, heap) **newivs,
764 htab_t newivs_index, htab_t params_index, int level)
766 tree lb_type = gcc_type_for_clast_expr (stmt->LB, region, *newivs,
767 newivs_index, params_index);
768 tree ub_type = gcc_type_for_clast_expr (stmt->UB, region, *newivs,
769 newivs_index, params_index);
770 tree type = gcc_type_for_iv_of_clast_loop (stmt, level, lb_type, ub_type);
771 tree lb = clast_to_gcc_expression (type, stmt->LB, region, *newivs,
772 newivs_index, params_index);
773 tree ub = clast_to_gcc_expression (type, stmt->UB, region, *newivs,
774 newivs_index, params_index);
775 tree stride = gmp_cst_to_tree (type, stmt->stride);
776 tree ivvar = create_tmp_var (type, "graphite_IV");
777 tree iv, iv_after_increment;
778 loop_p loop = create_empty_loop_on_edge
779 (entry_edge, lb, stride, ub, ivvar, &iv, &iv_after_increment,
780 outer ? outer : entry_edge->src->loop_father);
782 add_referenced_var (ivvar);
784 save_clast_name_index (newivs_index, stmt->iterator,
785 VEC_length (tree, *newivs));
786 VEC_safe_push (tree, heap, *newivs, iv);
787 return loop;
790 /* Inserts in iv_map a tuple (OLD_LOOP->num, NEW_NAME) for the
791 induction variables of the loops around GBB in SESE. */
793 static void
794 build_iv_mapping (VEC (tree, heap) *iv_map, sese region,
795 VEC (tree, heap) *newivs, htab_t newivs_index,
796 struct clast_user_stmt *user_stmt,
797 htab_t params_index)
799 struct clast_stmt *t;
800 int depth = 0;
801 CloogStatement *cs = user_stmt->statement;
802 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (cs);
803 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
805 for (t = user_stmt->substitutions; t; t = t->next, depth++)
807 struct clast_expr *expr = (struct clast_expr *)
808 ((struct clast_assignment *)t)->RHS;
809 tree type = gcc_type_for_clast_expr (expr, region, newivs,
810 newivs_index, params_index);
811 tree new_name = clast_to_gcc_expression (type, expr, region, newivs,
812 newivs_index, params_index);
813 loop_p old_loop = gbb_loop_at_index (gbb, region, depth);
815 VEC_replace (tree, iv_map, old_loop->num, new_name);
819 /* Construct bb_pbb_def with BB and PBB. */
821 static bb_pbb_def *
822 new_bb_pbb_def (basic_block bb, poly_bb_p pbb)
824 bb_pbb_def *bb_pbb_p;
826 bb_pbb_p = XNEW (bb_pbb_def);
827 bb_pbb_p->bb = bb;
828 bb_pbb_p->pbb = pbb;
830 return bb_pbb_p;
833 /* Mark BB with it's relevant PBB via hashing table BB_PBB_MAPPING. */
835 static void
836 mark_bb_with_pbb (poly_bb_p pbb, basic_block bb, htab_t bb_pbb_mapping)
838 bb_pbb_def tmp;
839 PTR *x;
841 tmp.bb = bb;
842 x = htab_find_slot (bb_pbb_mapping, &tmp, INSERT);
844 if (x && !*x)
845 *x = new_bb_pbb_def (bb, pbb);
848 /* Find BB's related poly_bb_p in hash table BB_PBB_MAPPING. */
850 static poly_bb_p
851 find_pbb_via_hash (htab_t bb_pbb_mapping, basic_block bb)
853 bb_pbb_def tmp;
854 PTR *slot;
856 tmp.bb = bb;
857 slot = htab_find_slot (bb_pbb_mapping, &tmp, NO_INSERT);
859 if (slot && *slot)
860 return ((bb_pbb_def *) *slot)->pbb;
862 return NULL;
865 /* Check data dependency in LOOP at scattering level LEVEL.
866 BB_PBB_MAPPING is a basic_block and it's related poly_bb_p
867 mapping. */
869 static bool
870 dependency_in_loop_p (loop_p loop, htab_t bb_pbb_mapping, int level)
872 unsigned i,j;
873 basic_block *bbs = get_loop_body_in_dom_order (loop);
875 for (i = 0; i < loop->num_nodes; i++)
877 poly_bb_p pbb1 = find_pbb_via_hash (bb_pbb_mapping, bbs[i]);
879 if (pbb1 == NULL)
880 continue;
882 for (j = 0; j < loop->num_nodes; j++)
884 poly_bb_p pbb2 = find_pbb_via_hash (bb_pbb_mapping, bbs[j]);
886 if (pbb2 == NULL)
887 continue;
889 if (dependency_between_pbbs_p (pbb1, pbb2, level))
891 free (bbs);
892 return true;
897 free (bbs);
899 return false;
902 /* Translates a clast user statement STMT to gimple.
904 - REGION is the sese region we used to generate the scop.
905 - NEXT_E is the edge where new generated code should be attached.
906 - CONTEXT_LOOP is the loop in which the generated code will be placed
907 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
908 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
909 the sese region. */
910 static edge
911 translate_clast_user (sese region, struct clast_user_stmt *stmt, edge next_e,
912 VEC (tree, heap) **newivs,
913 htab_t newivs_index, htab_t bb_pbb_mapping,
914 htab_t params_index)
916 int i, nb_loops;
917 basic_block new_bb;
918 poly_bb_p pbb = (poly_bb_p) cloog_statement_usr (stmt->statement);
919 gimple_bb_p gbb = PBB_BLACK_BOX (pbb);
920 VEC (tree, heap) *iv_map;
922 if (GBB_BB (gbb) == ENTRY_BLOCK_PTR)
923 return next_e;
925 nb_loops = number_of_loops ();
926 iv_map = VEC_alloc (tree, heap, nb_loops);
927 for (i = 0; i < nb_loops; i++)
928 VEC_quick_push (tree, iv_map, NULL_TREE);
930 build_iv_mapping (iv_map, region, *newivs, newivs_index, stmt, params_index);
931 next_e = copy_bb_and_scalar_dependences (GBB_BB (gbb), region,
932 next_e, iv_map);
933 VEC_free (tree, heap, iv_map);
935 new_bb = next_e->src;
936 mark_bb_with_pbb (pbb, new_bb, bb_pbb_mapping);
937 update_ssa (TODO_update_ssa);
939 return next_e;
942 /* Creates a new if region protecting the loop to be executed, if the execution
943 count is zero (lb > ub). */
945 static edge
946 graphite_create_new_loop_guard (sese region, edge entry_edge,
947 struct clast_for *stmt,
948 VEC (tree, heap) *newivs,
949 htab_t newivs_index, htab_t params_index)
951 tree cond_expr;
952 edge exit_edge;
953 tree lb_type = gcc_type_for_clast_expr (stmt->LB, region, newivs,
954 newivs_index, params_index);
955 tree ub_type = gcc_type_for_clast_expr (stmt->UB, region, newivs,
956 newivs_index, params_index);
957 tree type = max_precision_type (lb_type, ub_type);
958 tree lb = clast_to_gcc_expression (type, stmt->LB, region, newivs,
959 newivs_index, params_index);
960 tree ub = clast_to_gcc_expression (type, stmt->UB, region, newivs,
961 newivs_index, params_index);
962 tree one = POINTER_TYPE_P (type) ? size_one_node
963 : fold_convert (type, integer_one_node);
964 /* Adding +1 and using LT_EXPR helps with loop latches that have a
965 loop iteration count of "PARAMETER - 1". For PARAMETER == 0 this becomes
966 2^{32|64}, and the condition lb <= ub is true, even if we do not want this.
967 However lb < ub + 1 is false, as expected. */
968 tree ub_one = fold_build2 (POINTER_TYPE_P (type) ? POINTER_PLUS_EXPR
969 : PLUS_EXPR, type, ub, one);
971 /* When ub + 1 wraps around, use lb <= ub. */
972 if (integer_zerop (ub_one))
973 cond_expr = fold_build2 (LE_EXPR, boolean_type_node, lb, ub);
974 else
975 cond_expr = fold_build2 (LT_EXPR, boolean_type_node, lb, ub_one);
977 exit_edge = create_empty_if_region_on_edge (entry_edge, cond_expr);
979 return exit_edge;
982 static edge
983 translate_clast (sese, loop_p, struct clast_stmt *, edge,
984 VEC (tree, heap) **, htab_t, htab_t, int, htab_t);
986 /* Create the loop for a clast for statement.
988 - REGION is the sese region we used to generate the scop.
989 - NEXT_E is the edge where new generated code should be attached.
990 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
991 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
992 the sese region. */
993 static edge
994 translate_clast_for_loop (sese region, loop_p context_loop,
995 struct clast_for *stmt, edge next_e,
996 VEC (tree, heap) **newivs,
997 htab_t newivs_index, htab_t bb_pbb_mapping,
998 int level, htab_t params_index)
1000 struct loop *loop = graphite_create_new_loop (region, next_e, stmt,
1001 context_loop, newivs,
1002 newivs_index, params_index,
1003 level);
1004 edge last_e = single_exit (loop);
1005 edge to_body = single_succ_edge (loop->header);
1006 basic_block after = to_body->dest;
1008 /* Create a basic block for loop close phi nodes. */
1009 last_e = single_succ_edge (split_edge (last_e));
1011 /* Translate the body of the loop. */
1012 next_e = translate_clast (region, loop, stmt->body, to_body,
1013 newivs, newivs_index, bb_pbb_mapping, level + 1,
1014 params_index);
1015 redirect_edge_succ_nodup (next_e, after);
1016 set_immediate_dominator (CDI_DOMINATORS, next_e->dest, next_e->src);
1018 if (flag_loop_parallelize_all
1019 && !dependency_in_loop_p (loop, bb_pbb_mapping,
1020 get_scattering_level (level)))
1021 loop->can_be_parallel = true;
1023 return last_e;
1026 /* Translates a clast for statement STMT to gimple. First a guard is created
1027 protecting the loop, if it is executed zero times. In this guard we create
1028 the real loop structure.
1030 - REGION is the sese region we used to generate the scop.
1031 - NEXT_E is the edge where new generated code should be attached.
1032 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
1033 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
1034 the sese region. */
1035 static edge
1036 translate_clast_for (sese region, loop_p context_loop, struct clast_for *stmt,
1037 edge next_e, VEC (tree, heap) **newivs,
1038 htab_t newivs_index, htab_t bb_pbb_mapping, int level,
1039 htab_t params_index)
1041 edge last_e = graphite_create_new_loop_guard (region, next_e, stmt, *newivs,
1042 newivs_index, params_index);
1043 edge true_e = get_true_edge_from_guard_bb (next_e->dest);
1045 translate_clast_for_loop (region, context_loop, stmt, true_e, newivs,
1046 newivs_index, bb_pbb_mapping, level,
1047 params_index);
1048 return last_e;
1051 /* Translates a clast guard statement STMT to gimple.
1053 - REGION is the sese region we used to generate the scop.
1054 - NEXT_E is the edge where new generated code should be attached.
1055 - CONTEXT_LOOP is the loop in which the generated code will be placed
1056 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping.
1057 - PARAMS_INDEX connects the cloog parameters with the gimple parameters in
1058 the sese region. */
1059 static edge
1060 translate_clast_guard (sese region, loop_p context_loop,
1061 struct clast_guard *stmt, edge next_e,
1062 VEC (tree, heap) **newivs,
1063 htab_t newivs_index, htab_t bb_pbb_mapping, int level,
1064 htab_t params_index)
1066 edge last_e = graphite_create_new_guard (region, next_e, stmt, *newivs,
1067 newivs_index, params_index);
1068 edge true_e = get_true_edge_from_guard_bb (next_e->dest);
1070 translate_clast (region, context_loop, stmt->then, true_e,
1071 newivs, newivs_index, bb_pbb_mapping,
1072 level, params_index);
1073 return last_e;
1076 /* Translates a CLAST statement STMT to GCC representation in the
1077 context of a SESE.
1079 - NEXT_E is the edge where new generated code should be attached.
1080 - CONTEXT_LOOP is the loop in which the generated code will be placed
1081 - BB_PBB_MAPPING is is a basic_block and it's related poly_bb_p mapping. */
1082 static edge
1083 translate_clast (sese region, loop_p context_loop, struct clast_stmt *stmt,
1084 edge next_e, VEC (tree, heap) **newivs,
1085 htab_t newivs_index, htab_t bb_pbb_mapping, int level,
1086 htab_t params_index)
1088 if (!stmt)
1089 return next_e;
1091 if (CLAST_STMT_IS_A (stmt, stmt_root))
1092 ; /* Do nothing. */
1094 else if (CLAST_STMT_IS_A (stmt, stmt_user))
1095 next_e = translate_clast_user (region, (struct clast_user_stmt *) stmt,
1096 next_e, newivs, newivs_index,
1097 bb_pbb_mapping, params_index);
1099 else if (CLAST_STMT_IS_A (stmt, stmt_for))
1100 next_e = translate_clast_for (region, context_loop,
1101 (struct clast_for *) stmt, next_e,
1102 newivs, newivs_index,
1103 bb_pbb_mapping, level, params_index);
1105 else if (CLAST_STMT_IS_A (stmt, stmt_guard))
1106 next_e = translate_clast_guard (region, context_loop,
1107 (struct clast_guard *) stmt, next_e,
1108 newivs, newivs_index,
1109 bb_pbb_mapping, level, params_index);
1111 else if (CLAST_STMT_IS_A (stmt, stmt_block))
1112 next_e = translate_clast (region, context_loop,
1113 ((struct clast_block *) stmt)->body,
1114 next_e, newivs, newivs_index,
1115 bb_pbb_mapping, level, params_index);
1116 else
1117 gcc_unreachable();
1119 recompute_all_dominators ();
1120 graphite_verify ();
1122 return translate_clast (region, context_loop, stmt->next, next_e,
1123 newivs, newivs_index,
1124 bb_pbb_mapping, level, params_index);
1127 /* Free the SCATTERING domain list. */
1129 static void
1130 free_scattering (CloogScatteringList *scattering)
1132 while (scattering)
1134 CloogScattering *dom = cloog_scattering (scattering);
1135 CloogScatteringList *next = cloog_next_scattering (scattering);
1137 cloog_scattering_free (dom);
1138 free (scattering);
1139 scattering = next;
1143 /* Initialize Cloog's parameter names from the names used in GIMPLE.
1144 Initialize Cloog's iterator names, using 'graphite_iterator_%d'
1145 from 0 to scop_nb_loops (scop). */
1147 static void
1148 initialize_cloog_names (scop_p scop, CloogProgram *prog)
1150 sese region = SCOP_REGION (scop);
1151 int i;
1152 int nb_iterators = scop_max_loop_depth (scop);
1153 int nb_scattering = cloog_program_nb_scattdims (prog);
1154 int nb_parameters = VEC_length (tree, SESE_PARAMS (region));
1155 char **iterators = XNEWVEC (char *, nb_iterators * 2);
1156 char **scattering = XNEWVEC (char *, nb_scattering);
1157 char **parameters= XNEWVEC (char *, nb_parameters);
1159 cloog_program_set_names (prog, cloog_names_malloc ());
1161 for (i = 0; i < nb_parameters; i++)
1163 tree param = VEC_index (tree, SESE_PARAMS(region), i);
1164 const char *name = get_name (param);
1165 int len;
1167 if (!name)
1168 name = "T";
1170 len = strlen (name);
1171 len += 17;
1172 parameters[i] = XNEWVEC (char, len + 1);
1173 snprintf (parameters[i], len, "%s_%d", name, SSA_NAME_VERSION (param));
1176 cloog_names_set_nb_parameters (cloog_program_names (prog), nb_parameters);
1177 cloog_names_set_parameters (cloog_program_names (prog), parameters);
1179 for (i = 0; i < nb_iterators; i++)
1181 int len = 4 + 16;
1182 iterators[i] = XNEWVEC (char, len);
1183 snprintf (iterators[i], len, "git_%d", i);
1186 cloog_names_set_nb_iterators (cloog_program_names (prog),
1187 nb_iterators);
1188 cloog_names_set_iterators (cloog_program_names (prog),
1189 iterators);
1191 for (i = 0; i < nb_scattering; i++)
1193 int len = 5 + 16;
1194 scattering[i] = XNEWVEC (char, len);
1195 snprintf (scattering[i], len, "scat_%d", i);
1198 cloog_names_set_nb_scattering (cloog_program_names (prog),
1199 nb_scattering);
1200 cloog_names_set_scattering (cloog_program_names (prog),
1201 scattering);
1204 /* Build cloog program for SCoP. */
1206 static void
1207 build_cloog_prog (scop_p scop, CloogProgram *prog,
1208 CloogOptions *options, CloogState *state ATTRIBUTE_UNUSED)
1210 int i;
1211 int max_nb_loops = scop_max_loop_depth (scop);
1212 poly_bb_p pbb;
1213 CloogLoop *loop_list = NULL;
1214 CloogBlockList *block_list = NULL;
1215 CloogScatteringList *scattering = NULL;
1216 int nbs = 2 * max_nb_loops + 1;
1217 int *scaldims;
1219 cloog_program_set_context
1220 (prog, new_Cloog_Domain_from_ppl_Pointset_Powerset (SCOP_CONTEXT (scop),
1221 scop_nb_params (scop), state));
1222 nbs = unify_scattering_dimensions (scop);
1223 scaldims = (int *) xmalloc (nbs * (sizeof (int)));
1224 cloog_program_set_nb_scattdims (prog, nbs);
1225 initialize_cloog_names (scop, prog);
1227 FOR_EACH_VEC_ELT (poly_bb_p, SCOP_BBS (scop), i, pbb)
1229 CloogStatement *stmt;
1230 CloogBlock *block;
1231 CloogDomain *dom;
1233 /* Dead code elimination: when the domain of a PBB is empty,
1234 don't generate code for the PBB. */
1235 if (ppl_Pointset_Powerset_C_Polyhedron_is_empty (PBB_DOMAIN (pbb)))
1236 continue;
1238 /* Build the new statement and its block. */
1239 stmt = cloog_statement_alloc (state, pbb_index (pbb));
1240 dom = new_Cloog_Domain_from_ppl_Pointset_Powerset (PBB_DOMAIN (pbb),
1241 scop_nb_params (scop),
1242 state);
1243 block = cloog_block_alloc (stmt, 0, NULL, pbb_dim_iter_domain (pbb));
1244 cloog_statement_set_usr (stmt, pbb);
1246 /* Build loop list. */
1248 CloogLoop *new_loop_list = cloog_loop_malloc (state);
1249 cloog_loop_set_next (new_loop_list, loop_list);
1250 cloog_loop_set_domain (new_loop_list, dom);
1251 cloog_loop_set_block (new_loop_list, block);
1252 loop_list = new_loop_list;
1255 /* Build block list. */
1257 CloogBlockList *new_block_list = cloog_block_list_malloc ();
1259 cloog_block_list_set_next (new_block_list, block_list);
1260 cloog_block_list_set_block (new_block_list, block);
1261 block_list = new_block_list;
1264 /* Build scattering list. */
1266 /* XXX: Replace with cloog_domain_list_alloc(), when available. */
1267 CloogScatteringList *new_scattering
1268 = (CloogScatteringList *) xmalloc (sizeof (CloogScatteringList));
1269 ppl_Polyhedron_t scat;
1270 CloogScattering *dom;
1272 scat = PBB_TRANSFORMED_SCATTERING (pbb);
1273 dom = new_Cloog_Scattering_from_ppl_Polyhedron
1274 (scat, scop_nb_params (scop), pbb_nb_scattering_transform (pbb),
1275 state);
1277 cloog_set_next_scattering (new_scattering, scattering);
1278 cloog_set_scattering (new_scattering, dom);
1279 scattering = new_scattering;
1283 cloog_program_set_loop (prog, loop_list);
1284 cloog_program_set_blocklist (prog, block_list);
1286 for (i = 0; i < nbs; i++)
1287 scaldims[i] = 0 ;
1289 cloog_program_set_scaldims (prog, scaldims);
1291 /* Extract scalar dimensions to simplify the code generation problem. */
1292 cloog_program_extract_scalars (prog, scattering, options);
1294 /* Apply scattering. */
1295 cloog_program_scatter (prog, scattering, options);
1296 free_scattering (scattering);
1298 /* Iterators corresponding to scalar dimensions have to be extracted. */
1299 cloog_names_scalarize (cloog_program_names (prog), nbs,
1300 cloog_program_scaldims (prog));
1302 /* Free blocklist. */
1304 CloogBlockList *next = cloog_program_blocklist (prog);
1306 while (next)
1308 CloogBlockList *toDelete = next;
1309 next = cloog_block_list_next (next);
1310 cloog_block_list_set_next (toDelete, NULL);
1311 cloog_block_list_set_block (toDelete, NULL);
1312 cloog_block_list_free (toDelete);
1314 cloog_program_set_blocklist (prog, NULL);
1318 /* Return the options that will be used in GLOOG. */
1320 static CloogOptions *
1321 set_cloog_options (CloogState *state ATTRIBUTE_UNUSED)
1323 CloogOptions *options = cloog_options_malloc (state);
1325 /* Change cloog output language to C. If we do use FORTRAN instead, cloog
1326 will stop e.g. with "ERROR: unbounded loops not allowed in FORTRAN.", if
1327 we pass an incomplete program to cloog. */
1328 options->language = LANGUAGE_C;
1330 /* Enable complex equality spreading: removes dummy statements
1331 (assignments) in the generated code which repeats the
1332 substitution equations for statements. This is useless for
1333 GLooG. */
1334 options->esp = 1;
1336 #ifdef CLOOG_ORG
1337 /* Silence CLooG to avoid failing tests due to debug output to stderr. */
1338 options->quiet = 1;
1339 #else
1340 /* Enable C pretty-printing mode: normalizes the substitution
1341 equations for statements. */
1342 options->cpp = 1;
1343 #endif
1345 /* Allow cloog to build strides with a stride width different to one.
1346 This example has stride = 4:
1348 for (i = 0; i < 20; i += 4)
1349 A */
1350 options->strides = 1;
1352 /* Disable optimizations and make cloog generate source code closer to the
1353 input. This is useful for debugging, but later we want the optimized
1354 code.
1356 XXX: We can not disable optimizations, as loop blocking is not working
1357 without them. */
1358 if (0)
1360 options->f = -1;
1361 options->l = INT_MAX;
1364 return options;
1367 /* Prints STMT to STDERR. */
1369 void
1370 print_clast_stmt (FILE *file, struct clast_stmt *stmt)
1372 CloogState *state = cloog_state_malloc ();
1373 CloogOptions *options = set_cloog_options (state);
1375 clast_pprint (file, stmt, 0, options);
1376 cloog_options_free (options);
1377 cloog_state_free (state);
1380 /* Prints STMT to STDERR. */
1382 DEBUG_FUNCTION void
1383 debug_clast_stmt (struct clast_stmt *stmt)
1385 print_clast_stmt (stderr, stmt);
1388 /* Translate SCOP to a CLooG program and clast. These two
1389 representations should be freed together: a clast cannot be used
1390 without a program. */
1392 cloog_prog_clast
1393 scop_to_clast (scop_p scop, CloogState *state)
1395 CloogOptions *options = set_cloog_options (state);
1396 cloog_prog_clast pc;
1398 /* Connect new cloog prog generation to graphite. */
1399 pc.prog = cloog_program_malloc ();
1400 build_cloog_prog (scop, pc.prog, options, state);
1401 pc.prog = cloog_program_generate (pc.prog, options);
1402 pc.stmt = cloog_clast_create (pc.prog, options);
1404 cloog_options_free (options);
1405 return pc;
1408 /* Prints to FILE the code generated by CLooG for SCOP. */
1410 void
1411 print_generated_program (FILE *file, scop_p scop)
1413 CloogState *state = cloog_state_malloc ();
1414 CloogOptions *options = set_cloog_options (state);
1416 cloog_prog_clast pc = scop_to_clast (scop, state);
1418 fprintf (file, " (prog: \n");
1419 cloog_program_print (file, pc.prog);
1420 fprintf (file, " )\n");
1422 fprintf (file, " (clast: \n");
1423 clast_pprint (file, pc.stmt, 0, options);
1424 fprintf (file, " )\n");
1426 cloog_options_free (options);
1427 cloog_clast_free (pc.stmt);
1428 cloog_program_free (pc.prog);
1431 /* Prints to STDERR the code generated by CLooG for SCOP. */
1433 DEBUG_FUNCTION void
1434 debug_generated_program (scop_p scop)
1436 print_generated_program (stderr, scop);
1439 /* Add CLooG names to parameter index. The index is used to translate
1440 back from CLooG names to GCC trees. */
1442 static void
1443 create_params_index (htab_t index_table, CloogProgram *prog) {
1444 CloogNames* names = cloog_program_names (prog);
1445 int nb_parameters = cloog_names_nb_parameters (names);
1446 char **parameters = cloog_names_parameters (names);
1447 int i;
1449 for (i = 0; i < nb_parameters; i++)
1450 save_clast_name_index (index_table, parameters[i], i);
1453 /* GIMPLE Loop Generator: generates loops from STMT in GIMPLE form for
1454 the given SCOP. Return true if code generation succeeded.
1455 BB_PBB_MAPPING is a basic_block and it's related poly_bb_p mapping.
1458 bool
1459 gloog (scop_p scop, htab_t bb_pbb_mapping)
1461 VEC (tree, heap) *newivs = VEC_alloc (tree, heap, 10);
1462 loop_p context_loop;
1463 sese region = SCOP_REGION (scop);
1464 ifsese if_region = NULL;
1465 htab_t newivs_index, params_index;
1466 cloog_prog_clast pc;
1467 CloogState *state;
1469 state = cloog_state_malloc ();
1470 timevar_push (TV_GRAPHITE_CODE_GEN);
1471 gloog_error = false;
1473 pc = scop_to_clast (scop, state);
1475 if (dump_file && (dump_flags & TDF_DETAILS))
1477 fprintf (dump_file, "\nCLAST generated by CLooG: \n");
1478 print_clast_stmt (dump_file, pc.stmt);
1479 fprintf (dump_file, "\n");
1482 recompute_all_dominators ();
1483 graphite_verify ();
1485 if_region = move_sese_in_condition (region);
1486 sese_insert_phis_for_liveouts (region,
1487 if_region->region->exit->src,
1488 if_region->false_region->exit,
1489 if_region->true_region->exit);
1490 recompute_all_dominators ();
1491 graphite_verify ();
1493 context_loop = SESE_ENTRY (region)->src->loop_father;
1494 newivs_index = htab_create (10, clast_name_index_elt_info,
1495 eq_clast_name_indexes, free);
1496 params_index = htab_create (10, clast_name_index_elt_info,
1497 eq_clast_name_indexes, free);
1499 create_params_index (params_index, pc.prog);
1501 translate_clast (region, context_loop, pc.stmt,
1502 if_region->true_region->entry,
1503 &newivs, newivs_index,
1504 bb_pbb_mapping, 1, params_index);
1505 graphite_verify ();
1506 scev_reset_htab ();
1507 recompute_all_dominators ();
1508 graphite_verify ();
1510 if (gloog_error)
1511 set_ifsese_condition (if_region, integer_zero_node);
1513 free (if_region->true_region);
1514 free (if_region->region);
1515 free (if_region);
1517 htab_delete (newivs_index);
1518 htab_delete (params_index);
1519 VEC_free (tree, heap, newivs);
1520 cloog_clast_free (pc.stmt);
1521 cloog_program_free (pc.prog);
1522 timevar_pop (TV_GRAPHITE_CODE_GEN);
1524 if (dump_file && (dump_flags & TDF_DETAILS))
1526 loop_p loop;
1527 loop_iterator li;
1528 int num_no_dependency = 0;
1530 FOR_EACH_LOOP (li, loop, 0)
1531 if (loop->can_be_parallel)
1532 num_no_dependency++;
1534 fprintf (dump_file, "\n%d loops carried no dependency.\n",
1535 num_no_dependency);
1538 cloog_state_free (state);
1540 return !gloog_error;
1542 #endif