1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2015 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/>. */
25 /* Workaround for GMP 5.1.3 bug, see PR56019. */
28 #include <isl/constraint.h>
31 #include <isl/union_map.h>
32 #include <isl/constraint.h>
37 /* Since ISL-0.13, the extern is in val_gmp.h. */
38 #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
41 #include <isl/val_gmp.h>
42 #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
47 #include "coretypes.h"
49 #include "diagnostic-core.h"
53 #include "fold-const.h"
54 #include "gimple-iterator.h"
55 #include "tree-ssa-loop.h"
56 #include "gimple-pretty-print.h"
58 #include "tree-data-ref.h"
59 #include "graphite-poly.h"
61 #define OPENSCOP_MAX_STRING 256
64 /* Print to STDERR the GMP value VAL. */
67 debug_gmp_value (mpz_t val
)
69 gmp_fprintf (stderr
, "%Zd", val
);
72 /* Return the maximal loop depth in SCOP. */
75 scop_max_loop_depth (scop_p scop
)
81 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
83 int nb_loops
= pbb_dim_iter_domain (pbb
);
84 if (max_nb_loops
< nb_loops
)
85 max_nb_loops
= nb_loops
;
91 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
95 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
101 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
102 fprintf (file
, "#eq");
104 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
105 fprintf (file
, " s%d", (int) i
);
107 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
108 fprintf (file
, " lv%d", (int) i
);
110 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
111 fprintf (file
, " i%d", (int) i
);
113 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
114 fprintf (file
, " p%d", (int) i
);
116 fprintf (file
, " cst\n");
119 fprintf (file
, "isl\n");
120 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
123 fprintf (file
, "#)\n");
126 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
130 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
132 if (!PBB_TRANSFORMED (pbb
))
135 if (pbb
->schedule
|| pbb
->transformed
)
138 fprintf (file
, "# Scattering function is provided\n");
140 fprintf (file
, "1\n");
145 fprintf (file
, "# Scattering function is not provided\n");
147 fprintf (file
, "0\n");
151 print_scattering_function_1 (file
, pbb
, verbosity
);
154 fprintf (file
, "# Scattering names are not provided\n");
156 fprintf (file
, "0\n");
160 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
164 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
166 print_pbb_domain (file
, pbb
, verbosity
);
169 /* Prints to FILE the scattering functions of every PBB of SCOP. */
172 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
177 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
178 print_scattering_function (file
, pbb
, verbosity
);
181 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
185 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
190 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
191 print_iteration_domain (file
, pbb
, verbosity
);
194 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
198 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
200 print_scattering_function (stderr
, pbb
, verbosity
);
203 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
207 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
209 print_iteration_domain (stderr
, pbb
, verbosity
);
212 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
213 some VERBOSITY level. */
216 debug_scattering_functions (scop_p scop
, int verbosity
)
218 print_scattering_functions (stderr
, scop
, verbosity
);
221 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
222 some VERBOSITY level. */
225 debug_iteration_domains (scop_p scop
, int verbosity
)
227 print_iteration_domains (stderr
, scop
, verbosity
);
230 /* Apply graphite transformations to all the basic blocks of SCOP. */
233 apply_poly_transforms (scop_p scop
)
235 bool transform_done
= false;
237 /* Generate code even if we did not apply any real transformation.
238 This also allows to check the performance for the identity
239 transformation: GIMPLE -> GRAPHITE -> GIMPLE
240 Keep in mind that CLooG optimizes in control, so the loop structure
241 may change, even if we only use -fgraphite-identity. */
242 if (flag_graphite_identity
)
243 transform_done
= true;
245 if (flag_loop_parallelize_all
)
246 transform_done
= true;
249 transform_done
|= scop_do_block (scop
);
252 if (flag_loop_strip_mine
)
253 transform_done
|= scop_do_strip_mine (scop
, 0);
255 if (flag_loop_interchange
)
256 transform_done
|= scop_do_interchange (scop
);
259 /* This pass needs to be run at the final stage, as it does not
261 if (flag_loop_optimize_isl
|| flag_loop_unroll_jam
)
262 transform_done
|= optimize_isl (scop
);
264 return transform_done
;
267 /* Create a new polyhedral data reference and add it to PBB. It is
268 defined by its ACCESSES, its TYPE, and the number of subscripts
272 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
273 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
274 isl_map
*acc
, isl_set
*subscript_sizes
)
277 poly_dr_p pdr
= XNEW (struct poly_dr
);
280 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
281 PDR_NB_REFS (pdr
) = 1;
284 pdr
->subscript_sizes
= subscript_sizes
;
285 PDR_TYPE (pdr
) = type
;
287 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
288 PBB_DRS (pbb
).safe_push (pdr
);
291 /* Free polyhedral data reference PDR. */
294 free_poly_dr (poly_dr_p pdr
)
296 isl_map_free (pdr
->accesses
);
297 isl_set_free (pdr
->subscript_sizes
);
301 /* Create a new polyhedral black box. */
304 new_poly_bb (scop_p scop
, void *black_box
)
306 poly_bb_p pbb
= XNEW (struct poly_bb
);
309 pbb
->schedule
= NULL
;
310 pbb
->transformed
= NULL
;
312 pbb
->map_sepclass
= NULL
;
313 PBB_SCOP (pbb
) = scop
;
314 pbb_set_black_box (pbb
, black_box
);
315 PBB_TRANSFORMED (pbb
) = NULL
;
316 PBB_SAVED (pbb
) = NULL
;
317 PBB_ORIGINAL (pbb
) = NULL
;
318 PBB_DRS (pbb
).create (3);
319 PBB_IS_REDUCTION (pbb
) = false;
320 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
325 /* Free polyhedral black box. */
328 free_poly_bb (poly_bb_p pbb
)
333 isl_set_free (pbb
->domain
);
334 isl_map_free (pbb
->schedule
);
335 isl_map_free (pbb
->transformed
);
336 isl_map_free (pbb
->saved
);
338 if (PBB_DRS (pbb
).exists ())
339 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
342 PBB_DRS (pbb
).release ();
347 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
351 fprintf (file
, "# eq");
353 fprintf (file
, " alias");
355 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
356 fprintf (file
, " sub%d", (int) i
);
358 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
359 fprintf (file
, " i%d", (int) i
);
361 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
362 fprintf (file
, " p%d", (int) i
);
364 fprintf (file
, " cst\n");
367 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
371 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
375 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
377 switch (PDR_TYPE (pdr
))
380 fprintf (file
, "read \n");
384 fprintf (file
, "write \n");
388 fprintf (file
, "may_write \n");
395 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
400 fprintf (file
, "# data accesses (\n");
401 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
404 /* XXX isl dump accesses/subscripts */
407 fprintf (file
, "#)\n");
410 fprintf (file
, "#)\n");
413 /* Prints to STDERR the polyhedral data reference PDR, at some
417 debug_pdr (poly_dr_p pdr
, int verbosity
)
419 print_pdr (stderr
, pdr
, verbosity
);
422 /* Creates a new SCOP containing REGION. */
425 new_scop (void *region
)
427 scop_p scop
= XNEW (struct scop
);
429 scop
->context
= NULL
;
430 scop
->must_raw
= NULL
;
431 scop
->may_raw
= NULL
;
432 scop
->must_raw_no_source
= NULL
;
433 scop
->may_raw_no_source
= NULL
;
434 scop
->must_war
= NULL
;
435 scop
->may_war
= NULL
;
436 scop
->must_war_no_source
= NULL
;
437 scop
->may_war_no_source
= NULL
;
438 scop
->must_waw
= NULL
;
439 scop
->may_waw
= NULL
;
440 scop
->must_waw_no_source
= NULL
;
441 scop
->may_waw_no_source
= NULL
;
442 scop_set_region (scop
, region
);
443 SCOP_BBS (scop
).create (3);
444 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
445 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
446 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
447 POLY_SCOP_P (scop
) = false;
455 free_scop (scop_p scop
)
460 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
463 SCOP_BBS (scop
).release ();
465 isl_set_free (scop
->context
);
466 isl_union_map_free (scop
->must_raw
);
467 isl_union_map_free (scop
->may_raw
);
468 isl_union_map_free (scop
->must_raw_no_source
);
469 isl_union_map_free (scop
->may_raw_no_source
);
470 isl_union_map_free (scop
->must_war
);
471 isl_union_map_free (scop
->may_war
);
472 isl_union_map_free (scop
->must_war_no_source
);
473 isl_union_map_free (scop
->may_war_no_source
);
474 isl_union_map_free (scop
->must_waw
);
475 isl_union_map_free (scop
->may_waw
);
476 isl_union_map_free (scop
->must_waw_no_source
);
477 isl_union_map_free (scop
->may_waw_no_source
);
478 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
479 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
480 free_lst (SCOP_SAVED_SCHEDULE (scop
));
484 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
488 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
491 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
498 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
499 fprintf (file
, "#eq");
501 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
502 fprintf (file
, " i%d", (int) i
);
504 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
505 fprintf (file
, " p%d", (int) i
);
507 fprintf (file
, " cst\n");
510 fprintf (file
, "XXX isl\n");
513 fprintf (file
, "#)\n");
516 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
519 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
521 print_isl_set (file
, pbb
->domain
);
524 /* Dump the cases of a graphite basic block GBB on FILE. */
527 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
536 cases
= GBB_CONDITION_CASES (gbb
);
537 if (cases
.is_empty ())
540 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
542 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
544 fprintf (file
, "# ");
545 print_gimple_stmt (file
, stmt
, 0, 0);
548 fprintf (file
, "#)\n");
551 /* Dump conditions of a graphite basic block GBB on FILE. */
554 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
558 vec
<gimple
> conditions
;
563 conditions
= GBB_CONDITIONS (gbb
);
564 if (conditions
.is_empty ())
567 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
569 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
571 fprintf (file
, "# ");
572 print_gimple_stmt (file
, stmt
, 0, 0);
575 fprintf (file
, "#)\n");
578 /* Print to FILE all the data references of PBB, at some VERBOSITY
582 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
589 if (PBB_DRS (pbb
).length () == 0)
592 fprintf (file
, "# Access informations are not provided\n");\
593 fprintf (file
, "0\n");
598 fprintf (file
, "# Data references (\n");
601 fprintf (file
, "# Access informations are provided\n");
602 fprintf (file
, "1\n");
604 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
605 if (PDR_TYPE (pdr
) == PDR_READ
)
611 fprintf (file
, "# Read data references (\n");
614 fprintf (file
, "# Read access informations\n");
615 fprintf (file
, "%d\n", nb_reads
);
617 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
618 if (PDR_TYPE (pdr
) == PDR_READ
)
619 print_pdr (file
, pdr
, verbosity
);
622 fprintf (file
, "#)\n");
625 fprintf (file
, "# Write data references (\n");
628 fprintf (file
, "# Write access informations\n");
629 fprintf (file
, "%d\n", nb_writes
);
631 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
632 if (PDR_TYPE (pdr
) != PDR_READ
)
633 print_pdr (file
, pdr
, verbosity
);
636 fprintf (file
, "#)\n");
639 fprintf (file
, "#)\n");
642 /* Print to STDERR all the data references of PBB. */
645 debug_pdrs (poly_bb_p pbb
, int verbosity
)
647 print_pdrs (stderr
, pbb
, verbosity
);
650 /* Print to FILE the body of PBB, at some VERBOSITY level.
651 If statement_body_provided is false statement body is not printed. */
654 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
655 bool statement_body_provided
)
658 fprintf (file
, "# Body (\n");
660 if (!statement_body_provided
)
663 fprintf (file
, "# Statement body is not provided\n");
665 fprintf (file
, "0\n");
668 fprintf (file
, "#)\n");
673 fprintf (file
, "# Statement body is provided\n");
674 fprintf (file
, "1\n");
677 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
680 fprintf (file
, "# Statement body\n");
682 fprintf (file
, "{\n");
683 dump_bb (file
, pbb_bb (pbb
), 0, 0);
684 fprintf (file
, "}\n");
687 fprintf (file
, "#)\n");
690 /* Print to FILE the domain and scattering function of PBB, at some
694 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
698 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
699 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
700 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
703 openscop_print_pbb_domain (file
, pbb
, verbosity
);
704 print_scattering_function (file
, pbb
, verbosity
);
705 print_pdrs (file
, pbb
, verbosity
);
706 print_pbb_body (file
, pbb
, verbosity
, false);
709 fprintf (file
, "#)\n");
712 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
715 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
721 fprintf (file
, "# parameters (\n");
723 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
726 fprintf (file
, "# Parameter names are provided\n");
728 fprintf (file
, "1\n");
731 fprintf (file
, "# Parameter names\n");
736 fprintf (file
, "# Parameter names are not provided\n");
737 fprintf (file
, "0\n");
740 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
742 print_generic_expr (file
, t
, 0);
746 fprintf (file
, "\n");
749 fprintf (file
, "#)\n");
752 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
756 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
762 fprintf (file
, "# Context (\n");
763 fprintf (file
, "#eq");
765 for (i
= 0; i
< scop_nb_params (scop
); i
++)
766 fprintf (file
, " p%d", (int) i
);
768 fprintf (file
, " cst\n");
772 /* XXX isl print context */
773 fprintf (file
, "XXX isl\n");
775 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
776 (int) scop_nb_params (scop
));
779 fprintf (file
, "# )\n");
782 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
785 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
791 fprintf (file
, "# Context (\n");
792 fprintf (file
, "#eq");
794 for (i
= 0; i
< scop_nb_params (scop
); i
++)
795 fprintf (file
, " p%d", (int) i
);
797 fprintf (file
, " cst\n");
801 print_isl_set (file
, scop
->context
);
803 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
806 fprintf (file
, "# )\n");
809 /* Print to FILE the SCOP, at some VERBOSITY level. */
812 print_scop (FILE *file
, scop_p scop
, int verbosity
)
817 fprintf (file
, "SCoP 1\n#(\n");
818 fprintf (file
, "# Language\nGimple\n");
819 openscop_print_scop_context (file
, scop
, verbosity
);
820 print_scop_params (file
, scop
, verbosity
);
823 fprintf (file
, "# Number of statements\n");
825 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
827 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
828 print_pbb (file
, pbb
, verbosity
);
832 fprintf (file
, "# original_lst (\n");
833 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
834 fprintf (file
, "\n#)\n");
836 fprintf (file
, "# transformed_lst (\n");
837 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
838 fprintf (file
, "\n#)\n");
841 fprintf (file
, "#)\n");
844 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
847 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
849 print_pbb_domain (stderr
, pbb
, verbosity
);
852 /* Print to FILE the domain and scattering function of PBB, at some
856 debug_pbb (poly_bb_p pbb
, int verbosity
)
858 print_pbb (stderr
, pbb
, verbosity
);
861 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
864 debug_scop_context (scop_p scop
, int verbosity
)
866 print_scop_context (stderr
, scop
, verbosity
);
869 /* Print to STDERR the SCOP, at some VERBOSITY level. */
872 debug_scop (scop_p scop
, int verbosity
)
874 print_scop (stderr
, scop
, verbosity
);
877 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
881 debug_scop_params (scop_p scop
, int verbosity
)
883 print_scop_params (stderr
, scop
, verbosity
);
886 extern isl_ctx
*the_isl_ctx
;
888 print_isl_set (FILE *f
, isl_set
*set
)
890 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
891 p
= isl_printer_print_set (p
, set
);
892 isl_printer_free (p
);
896 debug_isl_set (isl_set
*set
)
898 print_isl_set (stderr
, set
);
902 print_isl_map (FILE *f
, isl_map
*map
)
904 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
905 p
= isl_printer_print_map (p
, map
);
906 isl_printer_free (p
);
910 debug_isl_map (isl_map
*map
)
912 print_isl_map (stderr
, map
);
916 print_isl_aff (FILE *f
, isl_aff
*aff
)
918 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
919 p
= isl_printer_print_aff (p
, aff
);
920 isl_printer_free (p
);
924 debug_isl_aff (isl_aff
*aff
)
926 print_isl_aff (stderr
, aff
);
930 print_isl_constraint (FILE *f
, isl_constraint
*c
)
932 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
933 p
= isl_printer_print_constraint (p
, c
);
934 isl_printer_free (p
);
938 debug_isl_constraint (isl_constraint
*c
)
940 print_isl_constraint (stderr
, c
);
943 /* Returns the number of iterations RES of the loop around PBB at
944 time(scattering) dimension TIME_DEPTH. */
947 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
948 graphite_dim_t time_depth
,
951 isl_set
*transdomain
;
954 isl_val
*isllb
, *islub
;
956 /* Map the iteration domain through the current scatter, and work
957 on the resulting set. */
958 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
959 isl_map_copy (pbb
->transformed
));
961 /* Select the time_depth' dimension via an affine expression. */
962 dc
= isl_set_get_space (transdomain
);
963 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
964 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
966 /* And find the min/max for that function. */
967 /* XXX isl check results? */
968 isllb
= isl_set_min_val (transdomain
, aff
);
969 islub
= isl_set_max_val (transdomain
, aff
);
971 islub
= isl_val_sub (islub
, isllb
);
972 islub
= isl_val_add_ui (islub
, 1);
973 isl_val_get_num_gmp (islub
, res
);
975 isl_val_free (islub
);
977 isl_set_free (transdomain
);
980 /* Translates LOOP to LST. */
983 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
989 for (; bbs
.iterate (*i
, &pbb
); (*i
)++)
992 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
994 if (bb
->loop_father
== loop
)
995 stmt
= new_lst_stmt (pbb
);
996 else if (flow_bb_inside_loop_p (loop
, bb
))
998 loop_p next
= loop
->inner
;
1000 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1003 stmt
= loop_to_lst (next
, bbs
, i
);
1008 return new_lst_loop (seq
);
1011 seq
.safe_push (stmt
);
1014 return new_lst_loop (seq
);
1017 /* Reads the original scattering of the SCOP and returns an LST
1021 scop_to_lst (scop_p scop
)
1024 int i
, n
= SCOP_BBS (scop
).length ();
1027 sese region
= SCOP_REGION (scop
);
1029 for (i
= 0; i
< n
; i
++)
1031 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1032 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1034 if (loop_in_sese_p (loop
, region
))
1035 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1037 res
= new_lst_stmt (pbb
);
1039 seq
.safe_push (res
);
1042 res
= new_lst_loop (seq
);
1043 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1044 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1047 /* Print to FILE on a new line COLUMN white spaces. */
1050 lst_indent_to (FILE *file
, int column
)
1055 fprintf (file
, "\n#");
1057 for (i
= 0; i
< column
; i
++)
1058 fprintf (file
, " ");
1061 /* Print LST to FILE with INDENT spaces of indentation. */
1064 print_lst (FILE *file
, lst_p lst
, int indent
)
1069 lst_indent_to (file
, indent
);
1071 if (LST_LOOP_P (lst
))
1076 if (LST_LOOP_FATHER (lst
))
1077 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1079 fprintf (file
, "#(root");
1081 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1082 print_lst (file
, l
, indent
+ 2);
1084 fprintf (file
, ")");
1087 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1090 /* Print LST to STDERR. */
1093 debug_lst (lst_p lst
)
1095 print_lst (stderr
, lst
, 0);
1098 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1101 dot_lst_1 (FILE *file
, lst_p lst
)
1106 if (LST_LOOP_P (lst
))
1111 if (!LST_LOOP_FATHER (lst
))
1112 fprintf (file
, "L -> L_%d_%d\n",
1114 lst_dewey_number (lst
));
1116 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1117 lst_depth (LST_LOOP_FATHER (lst
)),
1118 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1120 lst_dewey_number (lst
));
1122 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1123 dot_lst_1 (file
, l
);
1127 fprintf (file
, "L_%d_%d -> S_%d\n",
1128 lst_depth (LST_LOOP_FATHER (lst
)),
1129 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1130 pbb_index (LST_PBB (lst
)));
1134 /* Display the LST using dotty. */
1139 /* When debugging, enable the following code. This cannot be used
1140 in production compilers because it calls "system". */
1142 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1143 gcc_assert (stream
);
1145 fputs ("digraph all {\n", stream
);
1146 dot_lst_1 (stream
, lst
);
1147 fputs ("}\n\n", stream
);
1150 system ("dotty /tmp/lst.dot &");
1152 fputs ("digraph all {\n", stderr
);
1153 dot_lst_1 (stderr
, lst
);
1154 fputs ("}\n\n", stderr
);
1159 /* Reverse the loop around PBB at level DEPTH. */
1162 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1164 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1165 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1166 isl_space
*d1
= isl_space_range (d
);
1167 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1168 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1169 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1170 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1172 for (i
= 0; i
< n
; i
++)
1174 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1176 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1177 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1178 x
= isl_map_add_constraint (x
, c
);
1182 /* Reverse the loop at level DEPTH for all the PBBS. */
1185 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1189 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1190 isl_union_map
*res
= isl_union_map_empty (space
);
1192 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1193 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));
1199 #endif /* HAVE_isl */