1 /* Graphite polyhedral representation.
2 Copyright (C) 2009 Free Software Foundation, Inc.
3 Contributed by Sebastian Pop <sebastian.pop@amd.com> and
4 Tobias Grosser <grosser@fim.uni-passau.de>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 #include "coretypes.h"
29 #include "basic-block.h"
30 #include "diagnostic.h"
31 #include "tree-flow.h"
33 #include "tree-dump.h"
36 #include "tree-chrec.h"
37 #include "tree-data-ref.h"
38 #include "tree-scalar-evolution.h"
39 #include "tree-pass.h"
41 #include "value-prof.h"
42 #include "pointer-set.h"
47 #include "cloog/cloog.h"
50 #include "graphite-ppl.h"
52 #include "graphite-poly.h"
53 #include "graphite-dependences.h"
55 /* Return the maximal loop depth in SCOP. */
58 scop_max_loop_depth (scop_p scop
)
64 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
66 int nb_loops
= pbb_dim_iter_domain (pbb
);
67 if (max_nb_loops
< nb_loops
)
68 max_nb_loops
= nb_loops
;
74 /* Extend the scattering matrix of PBB to MAX_SCATTERING scattering
78 extend_scattering (poly_bb_p pbb
, int max_scattering
)
80 ppl_dimension_type nb_old_dims
, nb_new_dims
;
82 ppl_Coefficient_t coef
;
85 nb_added_dims
= max_scattering
- pbb_nb_scattering_transform (pbb
);
87 value_set_si (one
, 1);
88 ppl_new_Coefficient (&coef
);
89 ppl_assign_Coefficient_from_mpz_t (coef
, one
);
91 gcc_assert (nb_added_dims
>= 0);
93 nb_old_dims
= pbb_nb_scattering_transform (pbb
) + pbb_dim_iter_domain (pbb
)
94 + scop_nb_params (PBB_SCOP (pbb
));
95 nb_new_dims
= nb_old_dims
+ nb_added_dims
;
97 ppl_insert_dimensions (PBB_TRANSFORMED_SCATTERING (pbb
),
98 pbb_nb_scattering_transform (pbb
), nb_added_dims
);
99 PBB_NB_SCATTERING_TRANSFORM (pbb
) += nb_added_dims
;
101 /* Add identity matrix for the added dimensions. */
102 for (i
= max_scattering
- nb_added_dims
; i
< max_scattering
; i
++)
104 ppl_Constraint_t cstr
;
105 ppl_Linear_Expression_t expr
;
107 ppl_new_Linear_Expression_with_dimension (&expr
, nb_new_dims
);
108 ppl_Linear_Expression_add_to_coefficient (expr
, i
, coef
);
109 ppl_new_Constraint (&cstr
, expr
, PPL_CONSTRAINT_TYPE_EQUAL
);
110 ppl_Polyhedron_add_constraint (PBB_TRANSFORMED_SCATTERING (pbb
), cstr
);
111 ppl_delete_Constraint (cstr
);
112 ppl_delete_Linear_Expression (expr
);
115 ppl_delete_Coefficient (coef
);
119 /* All scattering matrices in SCOP will have the same number of scattering
123 unify_scattering_dimensions (scop_p scop
)
127 graphite_dim_t max_scattering
= 0;
129 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
130 max_scattering
= MAX (pbb_nb_scattering_transform (pbb
), max_scattering
);
132 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
133 extend_scattering (pbb
, max_scattering
);
135 return max_scattering
;
138 /* Prints to FILE the scattering function of PBB. */
141 print_scattering_function (FILE *file
, poly_bb_p pbb
)
145 if (!PBB_TRANSFORMED (pbb
))
148 fprintf (file
, "scattering bb_%d (\n", pbb_index (pbb
));
149 fprintf (file
, "# eq");
151 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
152 fprintf (file
, " s%d", (int) i
);
154 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
155 fprintf (file
, " lv%d", (int) i
);
157 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
158 fprintf (file
, " i%d", (int) i
);
160 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
161 fprintf (file
, " p%d", (int) i
);
163 fprintf (file
, " cst\n");
165 ppl_print_polyhedron_matrix (file
, PBB_TRANSFORMED_SCATTERING (pbb
));
167 fprintf (file
, ")\n");
170 /* Prints to FILE the iteration domain of PBB. */
173 print_iteration_domain (FILE *file
, poly_bb_p pbb
)
175 print_pbb_domain (file
, pbb
);
178 /* Prints to FILE the scattering functions of every PBB of SCOP. */
181 print_scattering_functions (FILE *file
, scop_p scop
)
186 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
187 print_scattering_function (file
, pbb
);
190 /* Prints to FILE the iteration domains of every PBB of SCOP. */
193 print_iteration_domains (FILE *file
, scop_p scop
)
198 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
199 print_iteration_domain (file
, pbb
);
202 /* Prints to STDERR the scattering function of PBB. */
205 debug_scattering_function (poly_bb_p pbb
)
207 print_scattering_function (stderr
, pbb
);
210 /* Prints to STDERR the iteration domain of PBB. */
213 debug_iteration_domain (poly_bb_p pbb
)
215 print_iteration_domain (stderr
, pbb
);
218 /* Prints to STDERR the scattering functions of every PBB of SCOP. */
221 debug_scattering_functions (scop_p scop
)
223 print_scattering_functions (stderr
, scop
);
226 /* Prints to STDERR the iteration domains of every PBB of SCOP. */
229 debug_iteration_domains (scop_p scop
)
231 print_iteration_domains (stderr
, scop
);
235 /* Write to file_name.graphite the transforms for SCOP. */
238 graphite_write_transforms (scop_p scop
)
240 print_scattering_functions (graphite_out_file
, scop
);
243 /* Read transforms from file_name.graphite and set the transforms on
247 graphite_read_transforms (scop_p scop
)
252 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
254 ppl_Polyhedron_t newp
;
255 ppl_read_polyhedron_matrix (&newp
, graphite_in_file
);
256 PBB_TRANSFORMED (pbb
) = poly_scattering_new ();
257 PBB_TRANSFORMED_SCATTERING (pbb
) = newp
;
263 /* Apply graphite transformations to all the basic blocks of SCOP. */
266 apply_poly_transforms (scop_p scop
)
268 bool transform_done
= false;
270 if (flag_graphite_read
)
272 transform_done
|= graphite_read_transforms (scop
);
273 gcc_assert (graphite_legal_transform (scop
));
276 /* Generate code even if we did not apply any real transformation.
277 This also allows to check the performance for the identity
278 transformation: GIMPLE -> GRAPHITE -> GIMPLE
279 Keep in mind that CLooG optimizes in control, so the loop structure
280 may change, even if we only use -fgraphite-identity. */
281 if (flag_graphite_identity
)
282 transform_done
= true;
284 if (flag_loop_parallelize_all
)
285 transform_done
= true;
288 transform_done
|= scop_do_block (scop
);
291 if (flag_loop_strip_mine
)
292 transform_done
|= scop_do_strip_mine (scop
);
294 if (flag_loop_interchange
)
295 transform_done
|= scop_do_interchange (scop
);
298 if (flag_graphite_write
)
299 graphite_write_transforms (scop
);
301 return transform_done
;
304 /* Returns true when it PDR1 is a duplicate of PDR2: same PBB, and
305 their ACCESSES, TYPE, and NB_SUBSCRIPTS are the same. */
308 can_collapse_pdrs (poly_dr_p pdr1
, poly_dr_p pdr2
)
311 ppl_Pointset_Powerset_C_Polyhedron_t af1
, af2
, diff
;
313 if (PDR_PBB (pdr1
) != PDR_PBB (pdr2
)
314 || PDR_NB_SUBSCRIPTS (pdr1
) != PDR_NB_SUBSCRIPTS (pdr2
)
315 || PDR_TYPE (pdr1
) != PDR_TYPE (pdr2
))
318 af1
= PDR_ACCESSES (pdr1
);
319 af2
= PDR_ACCESSES (pdr2
);
320 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
322 ppl_Pointset_Powerset_C_Polyhedron_difference_assign (diff
, af2
);
324 res
= ppl_Pointset_Powerset_C_Polyhedron_is_empty (diff
);
325 ppl_delete_Pointset_Powerset_C_Polyhedron (diff
);
329 /* Removes duplicated data references in PBB. */
332 pbb_remove_duplicate_pdrs (poly_bb_p pbb
)
335 poly_dr_p pdr1
, pdr2
;
336 unsigned n
= VEC_length (poly_dr_p
, PBB_DRS (pbb
));
337 VEC (poly_dr_p
, heap
) *collapsed
= VEC_alloc (poly_dr_p
, heap
, n
);
339 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr1
); i
++)
340 for (j
= 0; VEC_iterate (poly_dr_p
, collapsed
, j
, pdr2
); j
++)
341 if (!can_collapse_pdrs (pdr1
, pdr2
))
342 VEC_quick_push (poly_dr_p
, collapsed
, pdr1
);
344 VEC_free (poly_dr_p
, heap
, collapsed
);
345 PBB_PDR_DUPLICATES_REMOVED (pbb
) = true;
348 /* Create a new polyhedral data reference and add it to PBB. It is
349 defined by its ACCESSES, its TYPE, and the number of subscripts
353 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
354 ppl_Pointset_Powerset_C_Polyhedron_t accesses
,
355 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
)
358 poly_dr_p pdr
= XNEW (struct poly_dr
);
361 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
362 PDR_NB_REFS (pdr
) = 1;
364 PDR_ACCESSES (pdr
) = accesses
;
365 PDR_TYPE (pdr
) = type
;
367 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
368 VEC_safe_push (poly_dr_p
, heap
, PBB_DRS (pbb
), pdr
);
371 /* Free polyhedral data reference PDR. */
374 free_poly_dr (poly_dr_p pdr
)
376 ppl_delete_Pointset_Powerset_C_Polyhedron (PDR_ACCESSES (pdr
));
380 /* Create a new polyhedral black box. */
383 new_poly_bb (scop_p scop
, void *black_box
, bool reduction
)
385 poly_bb_p pbb
= XNEW (struct poly_bb
);
387 PBB_DOMAIN (pbb
) = NULL
;
388 PBB_SCOP (pbb
) = scop
;
389 pbb_set_black_box (pbb
, black_box
);
390 PBB_TRANSFORMED (pbb
) = NULL
;
391 PBB_SAVED (pbb
) = NULL
;
392 PBB_ORIGINAL (pbb
) = NULL
;
393 PBB_DRS (pbb
) = VEC_alloc (poly_dr_p
, heap
, 3);
394 PBB_IS_REDUCTION (pbb
) = reduction
;
395 PBB_PDR_DUPLICATES_REMOVED (pbb
) = false;
396 VEC_safe_push (poly_bb_p
, heap
, SCOP_BBS (scop
), pbb
);
399 /* Free polyhedral black box. */
402 free_poly_bb (poly_bb_p pbb
)
407 ppl_delete_Pointset_Powerset_C_Polyhedron (PBB_DOMAIN (pbb
));
409 if (PBB_TRANSFORMED (pbb
))
410 poly_scattering_free (PBB_TRANSFORMED (pbb
));
413 poly_scattering_free (PBB_SAVED (pbb
));
415 if (PBB_ORIGINAL (pbb
))
416 poly_scattering_free (PBB_ORIGINAL (pbb
));
419 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
422 VEC_free (poly_dr_p
, heap
, PBB_DRS (pbb
));
427 print_pdr_access_layout (FILE *file
, poly_dr_p pdr
)
431 fprintf (file
, "# eq");
433 for (i
= 0; i
< pdr_dim_iter_domain (pdr
); i
++)
434 fprintf (file
, " i%d", (int) i
);
436 for (i
= 0; i
< pdr_nb_params (pdr
); i
++)
437 fprintf (file
, " p%d", (int) i
);
439 fprintf (file
, " alias");
441 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
442 fprintf (file
, " sub%d", (int) i
);
444 fprintf (file
, " cst\n");
447 /* Prints to FILE the polyhedral data reference PDR. */
450 print_pdr (FILE *file
, poly_dr_p pdr
)
452 fprintf (file
, "pdr_%d (", PDR_ID (pdr
));
454 switch (PDR_TYPE (pdr
))
457 fprintf (file
, "read \n");
461 fprintf (file
, "write \n");
465 fprintf (file
, "may_write \n");
472 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
474 fprintf (file
, "data accesses (\n");
475 print_pdr_access_layout (file
, pdr
);
476 ppl_print_powerset_matrix (file
, PDR_ACCESSES (pdr
));
477 fprintf (file
, ")\n");
479 fprintf (file
, ")\n");
482 /* Prints to STDERR the polyhedral data reference PDR. */
485 debug_pdr (poly_dr_p pdr
)
487 print_pdr (stderr
, pdr
);
490 /* Creates a new SCOP containing REGION. */
493 new_scop (void *region
)
495 scop_p scop
= XNEW (struct scop
);
497 SCOP_CONTEXT (scop
) = NULL
;
498 scop_set_region (scop
, region
);
499 SCOP_BBS (scop
) = VEC_alloc (poly_bb_p
, heap
, 3);
500 SCOP_ORIGINAL_PDDRS (scop
) = htab_create (10, hash_poly_ddr_p
,
501 eq_poly_ddr_p
, free_poly_ddr
);
502 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
503 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
504 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
511 free_scop (scop_p scop
)
516 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
519 VEC_free (poly_bb_p
, heap
, SCOP_BBS (scop
));
521 if (SCOP_CONTEXT (scop
))
522 ppl_delete_Pointset_Powerset_C_Polyhedron (SCOP_CONTEXT (scop
));
524 htab_delete (SCOP_ORIGINAL_PDDRS (scop
));
525 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
526 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
527 free_lst (SCOP_SAVED_SCHEDULE (scop
));
531 /* Print to FILE the domain of PBB. */
534 print_pbb_domain (FILE *file
, poly_bb_p pbb
)
537 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
539 if (!PBB_DOMAIN (pbb
))
542 fprintf (file
, "domains bb_%d (\n", GBB_BB (gbb
)->index
);
543 fprintf (file
, "# eq");
545 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
546 fprintf (file
, " i%d", (int) i
);
548 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
549 fprintf (file
, " p%d", (int) i
);
551 fprintf (file
, " cst\n");
553 if (PBB_DOMAIN (pbb
))
554 ppl_print_powerset_matrix (file
, PBB_DOMAIN (pbb
));
556 fprintf (file
, ")\n");
559 /* Dump the cases of a graphite basic block GBB on FILE. */
562 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
566 VEC (gimple
, heap
) *cases
;
571 cases
= GBB_CONDITION_CASES (gbb
);
572 if (VEC_empty (gimple
, cases
))
575 fprintf (file
, "cases bb_%d (", GBB_BB (gbb
)->index
);
577 for (i
= 0; VEC_iterate (gimple
, cases
, i
, stmt
); i
++)
578 print_gimple_stmt (file
, stmt
, 0, 0);
580 fprintf (file
, ")\n");
583 /* Dump conditions of a graphite basic block GBB on FILE. */
586 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
590 VEC (gimple
, heap
) *conditions
;
595 conditions
= GBB_CONDITIONS (gbb
);
596 if (VEC_empty (gimple
, conditions
))
599 fprintf (file
, "conditions bb_%d (", GBB_BB (gbb
)->index
);
601 for (i
= 0; VEC_iterate (gimple
, conditions
, i
, stmt
); i
++)
602 print_gimple_stmt (file
, stmt
, 0, 0);
604 fprintf (file
, ")\n");
607 /* Print to FILE all the data references of PBB. */
610 print_pdrs (FILE *file
, poly_bb_p pbb
)
615 for (i
= 0; VEC_iterate (poly_dr_p
, PBB_DRS (pbb
), i
, pdr
); i
++)
616 print_pdr (file
, pdr
);
619 /* Print to STDERR all the data references of PBB. */
622 debug_pdrs (poly_bb_p pbb
)
624 print_pdrs (stderr
, pbb
);
627 /* Print to FILE the domain and scattering function of PBB. */
630 print_pbb (FILE *file
, poly_bb_p pbb
)
632 fprintf (file
, "pbb_%d (\n", pbb_index (pbb
));
633 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
634 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
635 print_pdrs (file
, pbb
);
636 print_pbb_domain (file
, pbb
);
637 print_scattering_function (file
, pbb
);
638 fprintf (file
, ")\n");
641 /* Print to FILE the parameters of SCOP. */
644 print_scop_params (FILE *file
, scop_p scop
)
649 fprintf (file
, "parameters (\n");
650 for (i
= 0; VEC_iterate (tree
, SESE_PARAMS (SCOP_REGION (scop
)), i
, t
); i
++)
652 fprintf (file
, "p_%d -> ", i
);
653 print_generic_expr (file
, t
, 0);
654 fprintf (file
, "\n");
656 fprintf (file
, ")\n");
659 /* Print to FILE the context of SCoP. */
661 print_scop_context (FILE *file
, scop_p scop
)
665 fprintf (file
, "context (\n");
666 fprintf (file
, "# eq");
668 for (i
= 0; i
< scop_nb_params (scop
); i
++)
669 fprintf (file
, " p%d", (int) i
);
671 fprintf (file
, " cst\n");
673 if (SCOP_CONTEXT (scop
))
674 ppl_print_powerset_matrix (file
, SCOP_CONTEXT (scop
));
676 fprintf (file
, ")\n");
679 /* Print to FILE the SCOP. */
682 print_scop (FILE *file
, scop_p scop
)
687 fprintf (file
, "scop (\n");
688 print_scop_params (file
, scop
);
689 print_scop_context (file
, scop
);
691 for (i
= 0; VEC_iterate (poly_bb_p
, SCOP_BBS (scop
), i
, pbb
); i
++)
692 print_pbb (file
, pbb
);
694 fprintf (file
, "original_lst (\n");
695 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
696 fprintf (file
, ")\n");
698 fprintf (file
, "transformed_lst (\n");
699 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
700 fprintf (file
, ")\n");
702 fprintf (file
, ")\n");
705 /* Print to STDERR the domain of PBB. */
708 debug_pbb_domain (poly_bb_p pbb
)
710 print_pbb_domain (stderr
, pbb
);
713 /* Print to FILE the domain and scattering function of PBB. */
716 debug_pbb (poly_bb_p pbb
)
718 print_pbb (stderr
, pbb
);
721 /* Print to STDERR the context of SCOP. */
724 debug_scop_context (scop_p scop
)
726 print_scop_context (stderr
, scop
);
729 /* Print to STDERR the SCOP. */
732 debug_scop (scop_p scop
)
734 print_scop (stderr
, scop
);
737 /* Print to STDERR the parameters of SCOP. */
740 debug_scop_params (scop_p scop
)
742 print_scop_params (stderr
, scop
);
746 /* The dimension in the transformed scattering polyhedron of PBB
747 containing the scattering iterator for the loop at depth LOOP_DEPTH. */
750 psct_scattering_dim_for_loop_depth (poly_bb_p pbb
, graphite_dim_t loop_depth
)
752 ppl_const_Constraint_System_t pcs
;
753 ppl_Constraint_System_const_iterator_t cit
, cend
;
754 ppl_const_Constraint_t cstr
;
755 ppl_Polyhedron_t ph
= PBB_TRANSFORMED_SCATTERING (pbb
);
756 ppl_dimension_type iter
= psct_iterator_dim (pbb
, loop_depth
);
757 ppl_Linear_Expression_t expr
;
758 ppl_Coefficient_t coef
;
763 ppl_new_Coefficient (&coef
);
764 ppl_Polyhedron_get_constraints (ph
, &pcs
);
765 ppl_new_Constraint_System_const_iterator (&cit
);
766 ppl_new_Constraint_System_const_iterator (&cend
);
768 for (ppl_Constraint_System_begin (pcs
, cit
),
769 ppl_Constraint_System_end (pcs
, cend
);
770 !ppl_Constraint_System_const_iterator_equal_test (cit
, cend
);
771 ppl_Constraint_System_const_iterator_increment (cit
))
773 ppl_Constraint_System_const_iterator_dereference (cit
, &cstr
);
774 ppl_new_Linear_Expression_from_Constraint (&expr
, cstr
);
775 ppl_Linear_Expression_coefficient (expr
, iter
, coef
);
776 ppl_Coefficient_to_mpz_t (coef
, val
);
778 if (value_zero_p (val
))
780 ppl_delete_Linear_Expression (expr
);
784 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
786 ppl_dimension_type scatter
= psct_scattering_dim (pbb
, i
);
788 ppl_Linear_Expression_coefficient (expr
, scatter
, coef
);
789 ppl_Coefficient_to_mpz_t (coef
, val
);
791 if (value_notzero_p (val
))
794 ppl_delete_Linear_Expression (expr
);
795 ppl_delete_Coefficient (coef
);
796 ppl_delete_Constraint_System_const_iterator (cit
);
797 ppl_delete_Constraint_System_const_iterator (cend
);
807 /* Returns the number of iterations NITER of the loop around PBB at
811 pbb_number_of_iterations (poly_bb_p pbb
,
812 graphite_dim_t loop_depth
,
815 ppl_Linear_Expression_t le
;
816 ppl_dimension_type dim
;
818 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (PBB_DOMAIN (pbb
), &dim
);
819 ppl_new_Linear_Expression_with_dimension (&le
, dim
);
820 ppl_set_coef (le
, pbb_iterator_dim (pbb
, loop_depth
), 1);
821 value_set_si (niter
, -1);
822 ppl_max_for_le_pointset (PBB_DOMAIN (pbb
), le
, niter
);
823 ppl_delete_Linear_Expression (le
);
826 /* Returns the number of iterations NITER of the loop around PBB at
827 time(scattering) dimension TIME_DEPTH. */
830 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
831 graphite_dim_t time_depth
,
834 ppl_Pointset_Powerset_C_Polyhedron_t ext_domain
, sctr
;
835 ppl_Linear_Expression_t le
;
836 ppl_dimension_type dim
;
838 /* Takes together domain and scattering polyhedrons, and composes
839 them into the bigger polyhedron that has the following format:
841 t0..t_{n-1} | l0..l_{nlcl-1} | i0..i_{niter-1} | g0..g_{nparm-1}
844 | t0..t_{n-1} are time dimensions (scattering dimensions)
845 | l0..l_{nclc-1} are local variables in scattering function
846 | i0..i_{niter-1} are original iteration variables
847 | g0..g_{nparam-1} are global parameters. */
849 ppl_new_Pointset_Powerset_C_Polyhedron_from_C_Polyhedron (&sctr
,
850 PBB_TRANSFORMED_SCATTERING (pbb
));
852 /* Extend the iteration domain with the scattering dimensions:
853 0..0 | 0..0 | i0..i_{niter-1} | g0..g_{nparm-1}. */
854 ppl_new_Pointset_Powerset_C_Polyhedron_from_Pointset_Powerset_C_Polyhedron
855 (&ext_domain
, PBB_DOMAIN (pbb
));
856 ppl_insert_dimensions_pointset (ext_domain
, 0,
857 pbb_nb_scattering_transform (pbb
)
858 + pbb_nb_local_vars (pbb
));
860 /* Add to sctr the extended domain. */
861 ppl_Pointset_Powerset_C_Polyhedron_intersection_assign (sctr
, ext_domain
);
863 /* Extract the number of iterations. */
864 ppl_Pointset_Powerset_C_Polyhedron_space_dimension (sctr
, &dim
);
865 ppl_new_Linear_Expression_with_dimension (&le
, dim
);
866 ppl_set_coef (le
, time_depth
, 1);
867 value_set_si (niter
, -1);
868 ppl_max_for_le_pointset (sctr
, le
, niter
);
870 ppl_delete_Linear_Expression (le
);
871 ppl_delete_Pointset_Powerset_C_Polyhedron (sctr
);
872 ppl_delete_Pointset_Powerset_C_Polyhedron (ext_domain
);
875 /* Translates LOOP to LST. */
878 loop_to_lst (loop_p loop
, VEC (poly_bb_p
, heap
) *bbs
, int *i
)
881 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
883 for (; VEC_iterate (poly_bb_p
, bbs
, *i
, pbb
); (*i
)++)
886 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
888 if (bb
->loop_father
== loop
)
889 stmt
= new_lst_stmt (pbb
);
890 else if (flow_bb_inside_loop_p (loop
, bb
))
892 loop_p next
= loop
->inner
;
894 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
897 stmt
= loop_to_lst (next
, bbs
, i
);
902 return new_lst_loop (seq
);
905 VEC_safe_push (lst_p
, heap
, seq
, stmt
);
908 return new_lst_loop (seq
);
911 /* Reads the original scattering of the SCOP and returns an LST
915 scop_to_lst (scop_p scop
)
918 int i
, n
= VEC_length (poly_bb_p
, SCOP_BBS (scop
));
919 VEC (lst_p
, heap
) *seq
= VEC_alloc (lst_p
, heap
, 5);
920 sese region
= SCOP_REGION (scop
);
922 for (i
= 0; i
< n
; i
++)
924 poly_bb_p pbb
= VEC_index (poly_bb_p
, SCOP_BBS (scop
), i
);
925 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
927 if (loop_in_sese_p (loop
, region
))
928 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
930 res
= new_lst_stmt (pbb
);
932 VEC_safe_push (lst_p
, heap
, seq
, res
);
935 res
= new_lst_loop (seq
);
936 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
937 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
940 /* Print LST to FILE with INDENT spaces of indentation. */
943 print_lst (FILE *file
, lst_p lst
, int indent
)
948 indent_to (file
, indent
);
950 if (LST_LOOP_P (lst
))
955 if (LST_LOOP_FATHER (lst
))
956 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
958 fprintf (file
, "(root");
960 for (i
= 0; VEC_iterate (lst_p
, LST_SEQ (lst
), i
, l
); i
++)
961 print_lst (file
, l
, indent
+ 2);
966 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
969 /* Print LST to STDERR. */
972 debug_lst (lst_p lst
)
974 print_lst (stderr
, lst
, 0);
977 /* Pretty print to FILE the loop statement tree LST in DOT format. */
980 dot_lst_1 (FILE *file
, lst_p lst
)
985 if (LST_LOOP_P (lst
))
990 if (!LST_LOOP_FATHER (lst
))
991 fprintf (file
, "L -> L_%d_%d\n",
993 lst_dewey_number (lst
));
995 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
996 lst_depth (LST_LOOP_FATHER (lst
)),
997 lst_dewey_number (LST_LOOP_FATHER (lst
)),
999 lst_dewey_number (lst
));
1001 for (i
= 0; VEC_iterate (lst_p
, LST_SEQ (lst
), i
, l
); i
++)
1002 dot_lst_1 (file
, l
);
1006 fprintf (file
, "L_%d_%d -> S_%d\n",
1007 lst_depth (LST_LOOP_FATHER (lst
)),
1008 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1009 pbb_index (LST_PBB (lst
)));
1013 /* Display the LST using dotty. */
1018 /* When debugging, enable the following code. This cannot be used
1019 in production compilers because it calls "system". */
1022 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1023 gcc_assert (stream
);
1025 fputs ("digraph all {\n", stream
);
1026 dot_lst_1 (stream
, lst
);
1027 fputs ("}\n\n", stream
);
1030 x
= system ("dotty /tmp/lst.dot");
1032 fputs ("digraph all {\n", stderr
);
1033 dot_lst_1 (stderr
, lst
);
1034 fputs ("}\n\n", stderr
);