1 /* Graphite polyhedral representation.
2 Copyright (C) 2009-2014 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/>. */
27 #include <isl/union_map.h>
28 #include <isl/constraint.h>
33 /* Since ISL-0.13, the extern is in val_gmp.h. */
34 #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
37 #include <isl/val_gmp.h>
38 #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus)
44 #include "coretypes.h"
45 #include "diagnostic-core.h"
53 #include "hard-reg-set.h"
56 #include "dominance.h"
58 #include "basic-block.h"
59 #include "tree-ssa-alias.h"
60 #include "internal-fn.h"
61 #include "gimple-expr.h"
64 #include "gimple-iterator.h"
65 #include "tree-ssa-loop.h"
67 #include "gimple-pretty-print.h"
69 #include "tree-chrec.h"
70 #include "tree-data-ref.h"
71 #include "tree-scalar-evolution.h"
75 #include "graphite-poly.h"
77 #define OPENSCOP_MAX_STRING 256
80 /* Print to STDERR the GMP value VAL. */
83 debug_gmp_value (mpz_t val
)
85 gmp_fprintf (stderr
, "%Zd", val
);
88 /* Return the maximal loop depth in SCOP. */
91 scop_max_loop_depth (scop_p scop
)
97 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
99 int nb_loops
= pbb_dim_iter_domain (pbb
);
100 if (max_nb_loops
< nb_loops
)
101 max_nb_loops
= nb_loops
;
107 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
111 print_scattering_function_1 (FILE *file
, poly_bb_p pbb
, int verbosity
)
117 fprintf (file
, "# scattering bb_%d (\n", pbb_index (pbb
));
118 fprintf (file
, "#eq");
120 for (i
= 0; i
< pbb_nb_scattering_transform (pbb
); i
++)
121 fprintf (file
, " s%d", (int) i
);
123 for (i
= 0; i
< pbb_nb_local_vars (pbb
); i
++)
124 fprintf (file
, " lv%d", (int) i
);
126 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
127 fprintf (file
, " i%d", (int) i
);
129 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
130 fprintf (file
, " p%d", (int) i
);
132 fprintf (file
, " cst\n");
135 fprintf (file
, "isl\n");
136 print_isl_map (file
, pbb
->transformed
? pbb
->transformed
: pbb
->schedule
);
139 fprintf (file
, "#)\n");
142 /* Prints to FILE the scattering function of PBB, at some VERBOSITY
146 print_scattering_function (FILE *file
, poly_bb_p pbb
, int verbosity
)
148 if (!PBB_TRANSFORMED (pbb
))
151 if (pbb
->schedule
|| pbb
->transformed
)
154 fprintf (file
, "# Scattering function is provided\n");
156 fprintf (file
, "1\n");
161 fprintf (file
, "# Scattering function is not provided\n");
163 fprintf (file
, "0\n");
167 print_scattering_function_1 (file
, pbb
, verbosity
);
170 fprintf (file
, "# Scattering names are not provided\n");
172 fprintf (file
, "0\n");
176 /* Prints to FILE the iteration domain of PBB, at some VERBOSITY
180 print_iteration_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
182 print_pbb_domain (file
, pbb
, verbosity
);
185 /* Prints to FILE the scattering functions of every PBB of SCOP. */
188 print_scattering_functions (FILE *file
, scop_p scop
, int verbosity
)
193 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
194 print_scattering_function (file
, pbb
, verbosity
);
197 /* Prints to FILE the iteration domains of every PBB of SCOP, at some
201 print_iteration_domains (FILE *file
, scop_p scop
, int verbosity
)
206 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
207 print_iteration_domain (file
, pbb
, verbosity
);
210 /* Prints to STDERR the scattering function of PBB, at some VERBOSITY
214 debug_scattering_function (poly_bb_p pbb
, int verbosity
)
216 print_scattering_function (stderr
, pbb
, verbosity
);
219 /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY
223 debug_iteration_domain (poly_bb_p pbb
, int verbosity
)
225 print_iteration_domain (stderr
, pbb
, verbosity
);
228 /* Prints to STDERR the scattering functions of every PBB of SCOP, at
229 some VERBOSITY level. */
232 debug_scattering_functions (scop_p scop
, int verbosity
)
234 print_scattering_functions (stderr
, scop
, verbosity
);
237 /* Prints to STDERR the iteration domains of every PBB of SCOP, at
238 some VERBOSITY level. */
241 debug_iteration_domains (scop_p scop
, int verbosity
)
243 print_iteration_domains (stderr
, scop
, verbosity
);
246 /* Apply graphite transformations to all the basic blocks of SCOP. */
249 apply_poly_transforms (scop_p scop
)
251 bool transform_done
= false;
253 /* Generate code even if we did not apply any real transformation.
254 This also allows to check the performance for the identity
255 transformation: GIMPLE -> GRAPHITE -> GIMPLE
256 Keep in mind that CLooG optimizes in control, so the loop structure
257 may change, even if we only use -fgraphite-identity. */
258 if (flag_graphite_identity
)
259 transform_done
= true;
261 if (flag_loop_parallelize_all
)
262 transform_done
= true;
265 transform_done
|= scop_do_block (scop
);
268 if (flag_loop_strip_mine
)
269 transform_done
|= scop_do_strip_mine (scop
, 0);
271 if (flag_loop_interchange
)
272 transform_done
|= scop_do_interchange (scop
);
275 /* This pass needs to be run at the final stage, as it does not
277 if (flag_loop_optimize_isl
|| flag_loop_unroll_jam
)
278 transform_done
|= optimize_isl (scop
);
280 return transform_done
;
283 /* Create a new polyhedral data reference and add it to PBB. It is
284 defined by its ACCESSES, its TYPE, and the number of subscripts
288 new_poly_dr (poly_bb_p pbb
, int dr_base_object_set
,
289 enum poly_dr_type type
, void *cdr
, graphite_dim_t nb_subscripts
,
290 isl_map
*acc
, isl_set
*extent
)
293 poly_dr_p pdr
= XNEW (struct poly_dr
);
296 PDR_BASE_OBJECT_SET (pdr
) = dr_base_object_set
;
297 PDR_NB_REFS (pdr
) = 1;
300 pdr
->extent
= extent
;
301 PDR_TYPE (pdr
) = type
;
303 PDR_NB_SUBSCRIPTS (pdr
) = nb_subscripts
;
304 PBB_DRS (pbb
).safe_push (pdr
);
307 /* Free polyhedral data reference PDR. */
310 free_poly_dr (poly_dr_p pdr
)
312 isl_map_free (pdr
->accesses
);
313 isl_set_free (pdr
->extent
);
317 /* Create a new polyhedral black box. */
320 new_poly_bb (scop_p scop
, void *black_box
)
322 poly_bb_p pbb
= XNEW (struct poly_bb
);
325 pbb
->schedule
= NULL
;
326 pbb
->transformed
= NULL
;
328 pbb
->map_sepclass
= NULL
;
329 PBB_SCOP (pbb
) = scop
;
330 pbb_set_black_box (pbb
, black_box
);
331 PBB_TRANSFORMED (pbb
) = NULL
;
332 PBB_SAVED (pbb
) = NULL
;
333 PBB_ORIGINAL (pbb
) = NULL
;
334 PBB_DRS (pbb
).create (3);
335 PBB_IS_REDUCTION (pbb
) = false;
336 GBB_PBB ((gimple_bb_p
) black_box
) = pbb
;
341 /* Free polyhedral black box. */
344 free_poly_bb (poly_bb_p pbb
)
349 isl_set_free (pbb
->domain
);
350 isl_map_free (pbb
->schedule
);
351 isl_map_free (pbb
->transformed
);
352 isl_map_free (pbb
->saved
);
354 if (PBB_DRS (pbb
).exists ())
355 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
358 PBB_DRS (pbb
).release ();
363 print_pdr_access_layout (FILE *file
, poly_bb_p pbb
, poly_dr_p pdr
)
367 fprintf (file
, "# eq");
369 fprintf (file
, " alias");
371 for (i
= 0; i
< PDR_NB_SUBSCRIPTS (pdr
); i
++)
372 fprintf (file
, " sub%d", (int) i
);
374 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
375 fprintf (file
, " i%d", (int) i
);
377 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
378 fprintf (file
, " p%d", (int) i
);
380 fprintf (file
, " cst\n");
383 /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY
387 print_pdr (FILE *file
, poly_dr_p pdr
, int verbosity
)
391 fprintf (file
, "# pdr_%d (", PDR_ID (pdr
));
393 switch (PDR_TYPE (pdr
))
396 fprintf (file
, "read \n");
400 fprintf (file
, "write \n");
404 fprintf (file
, "may_write \n");
411 dump_data_reference (file
, (data_reference_p
) PDR_CDR (pdr
));
416 fprintf (file
, "# data accesses (\n");
417 print_pdr_access_layout (file
, PDR_PBB (pdr
), pdr
);
420 /* XXX isl dump accesses/subscripts */
423 fprintf (file
, "#)\n");
426 fprintf (file
, "#)\n");
429 /* Prints to STDERR the polyhedral data reference PDR, at some
433 debug_pdr (poly_dr_p pdr
, int verbosity
)
435 print_pdr (stderr
, pdr
, verbosity
);
438 /* Creates a new SCOP containing REGION. */
441 new_scop (void *region
)
443 scop_p scop
= XNEW (struct scop
);
445 scop
->context
= NULL
;
446 scop
->must_raw
= NULL
;
447 scop
->may_raw
= NULL
;
448 scop
->must_raw_no_source
= NULL
;
449 scop
->may_raw_no_source
= NULL
;
450 scop
->must_war
= NULL
;
451 scop
->may_war
= NULL
;
452 scop
->must_war_no_source
= NULL
;
453 scop
->may_war_no_source
= NULL
;
454 scop
->must_waw
= NULL
;
455 scop
->may_waw
= NULL
;
456 scop
->must_waw_no_source
= NULL
;
457 scop
->may_waw_no_source
= NULL
;
458 scop_set_region (scop
, region
);
459 SCOP_BBS (scop
).create (3);
460 SCOP_ORIGINAL_SCHEDULE (scop
) = NULL
;
461 SCOP_TRANSFORMED_SCHEDULE (scop
) = NULL
;
462 SCOP_SAVED_SCHEDULE (scop
) = NULL
;
463 POLY_SCOP_P (scop
) = false;
471 free_scop (scop_p scop
)
476 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
479 SCOP_BBS (scop
).release ();
481 isl_set_free (scop
->context
);
482 isl_union_map_free (scop
->must_raw
);
483 isl_union_map_free (scop
->may_raw
);
484 isl_union_map_free (scop
->must_raw_no_source
);
485 isl_union_map_free (scop
->may_raw_no_source
);
486 isl_union_map_free (scop
->must_war
);
487 isl_union_map_free (scop
->may_war
);
488 isl_union_map_free (scop
->must_war_no_source
);
489 isl_union_map_free (scop
->may_war_no_source
);
490 isl_union_map_free (scop
->must_waw
);
491 isl_union_map_free (scop
->may_waw
);
492 isl_union_map_free (scop
->must_waw_no_source
);
493 isl_union_map_free (scop
->may_waw_no_source
);
494 free_lst (SCOP_ORIGINAL_SCHEDULE (scop
));
495 free_lst (SCOP_TRANSFORMED_SCHEDULE (scop
));
496 free_lst (SCOP_SAVED_SCHEDULE (scop
));
500 /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY
504 openscop_print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity
)
507 gimple_bb_p gbb
= PBB_BLACK_BOX (pbb
);
514 fprintf (file
, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb
)->index
);
515 fprintf (file
, "#eq");
517 for (i
= 0; i
< pbb_dim_iter_domain (pbb
); i
++)
518 fprintf (file
, " i%d", (int) i
);
520 for (i
= 0; i
< pbb_nb_params (pbb
); i
++)
521 fprintf (file
, " p%d", (int) i
);
523 fprintf (file
, " cst\n");
526 fprintf (file
, "XXX isl\n");
529 fprintf (file
, "#)\n");
532 /* Print to FILE the domain of PBB, at some VERBOSITY level. */
535 print_pbb_domain (FILE *file
, poly_bb_p pbb
, int verbosity ATTRIBUTE_UNUSED
)
537 print_isl_set (file
, pbb
->domain
);
540 /* Dump the cases of a graphite basic block GBB on FILE. */
543 dump_gbb_cases (FILE *file
, gimple_bb_p gbb
)
552 cases
= GBB_CONDITION_CASES (gbb
);
553 if (cases
.is_empty ())
556 fprintf (file
, "# cases bb_%d (\n", GBB_BB (gbb
)->index
);
558 FOR_EACH_VEC_ELT (cases
, i
, stmt
)
560 fprintf (file
, "# ");
561 print_gimple_stmt (file
, stmt
, 0, 0);
564 fprintf (file
, "#)\n");
567 /* Dump conditions of a graphite basic block GBB on FILE. */
570 dump_gbb_conditions (FILE *file
, gimple_bb_p gbb
)
574 vec
<gimple
> conditions
;
579 conditions
= GBB_CONDITIONS (gbb
);
580 if (conditions
.is_empty ())
583 fprintf (file
, "# conditions bb_%d (\n", GBB_BB (gbb
)->index
);
585 FOR_EACH_VEC_ELT (conditions
, i
, stmt
)
587 fprintf (file
, "# ");
588 print_gimple_stmt (file
, stmt
, 0, 0);
591 fprintf (file
, "#)\n");
594 /* Print to FILE all the data references of PBB, at some VERBOSITY
598 print_pdrs (FILE *file
, poly_bb_p pbb
, int verbosity
)
605 if (PBB_DRS (pbb
).length () == 0)
608 fprintf (file
, "# Access informations are not provided\n");\
609 fprintf (file
, "0\n");
614 fprintf (file
, "# Data references (\n");
617 fprintf (file
, "# Access informations are provided\n");
618 fprintf (file
, "1\n");
620 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
621 if (PDR_TYPE (pdr
) == PDR_READ
)
627 fprintf (file
, "# Read data references (\n");
630 fprintf (file
, "# Read access informations\n");
631 fprintf (file
, "%d\n", nb_reads
);
633 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
634 if (PDR_TYPE (pdr
) == PDR_READ
)
635 print_pdr (file
, pdr
, verbosity
);
638 fprintf (file
, "#)\n");
641 fprintf (file
, "# Write data references (\n");
644 fprintf (file
, "# Write access informations\n");
645 fprintf (file
, "%d\n", nb_writes
);
647 FOR_EACH_VEC_ELT (PBB_DRS (pbb
), i
, pdr
)
648 if (PDR_TYPE (pdr
) != PDR_READ
)
649 print_pdr (file
, pdr
, verbosity
);
652 fprintf (file
, "#)\n");
655 fprintf (file
, "#)\n");
658 /* Print to STDERR all the data references of PBB. */
661 debug_pdrs (poly_bb_p pbb
, int verbosity
)
663 print_pdrs (stderr
, pbb
, verbosity
);
666 /* Print to FILE the body of PBB, at some VERBOSITY level.
667 If statement_body_provided is false statement body is not printed. */
670 print_pbb_body (FILE *file
, poly_bb_p pbb
, int verbosity
,
671 bool statement_body_provided
)
674 fprintf (file
, "# Body (\n");
676 if (!statement_body_provided
)
679 fprintf (file
, "# Statement body is not provided\n");
681 fprintf (file
, "0\n");
684 fprintf (file
, "#)\n");
689 fprintf (file
, "# Statement body is provided\n");
690 fprintf (file
, "1\n");
693 fprintf (file
, "# Original iterator names\n# Iterator names are not provided yet.\n");
696 fprintf (file
, "# Statement body\n");
698 fprintf (file
, "{\n");
699 dump_bb (file
, pbb_bb (pbb
), 0, 0);
700 fprintf (file
, "}\n");
703 fprintf (file
, "#)\n");
706 /* Print to FILE the domain and scattering function of PBB, at some
710 print_pbb (FILE *file
, poly_bb_p pbb
, int verbosity
)
714 fprintf (file
, "# pbb_%d (\n", pbb_index (pbb
));
715 dump_gbb_conditions (file
, PBB_BLACK_BOX (pbb
));
716 dump_gbb_cases (file
, PBB_BLACK_BOX (pbb
));
719 openscop_print_pbb_domain (file
, pbb
, verbosity
);
720 print_scattering_function (file
, pbb
, verbosity
);
721 print_pdrs (file
, pbb
, verbosity
);
722 print_pbb_body (file
, pbb
, verbosity
, false);
725 fprintf (file
, "#)\n");
728 /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */
731 print_scop_params (FILE *file
, scop_p scop
, int verbosity
)
737 fprintf (file
, "# parameters (\n");
739 if (SESE_PARAMS (SCOP_REGION (scop
)).length ())
742 fprintf (file
, "# Parameter names are provided\n");
744 fprintf (file
, "1\n");
747 fprintf (file
, "# Parameter names\n");
752 fprintf (file
, "# Parameter names are not provided\n");
753 fprintf (file
, "0\n");
756 FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop
)), i
, t
)
758 print_generic_expr (file
, t
, 0);
762 fprintf (file
, "\n");
765 fprintf (file
, "#)\n");
768 /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY
772 openscop_print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
778 fprintf (file
, "# Context (\n");
779 fprintf (file
, "#eq");
781 for (i
= 0; i
< scop_nb_params (scop
); i
++)
782 fprintf (file
, " p%d", (int) i
);
784 fprintf (file
, " cst\n");
788 /* XXX isl print context */
789 fprintf (file
, "XXX isl\n");
791 fprintf (file
, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop
) + 2,
792 (int) scop_nb_params (scop
));
795 fprintf (file
, "# )\n");
798 /* Print to FILE the context of SCoP, at some VERBOSITY level. */
801 print_scop_context (FILE *file
, scop_p scop
, int verbosity
)
807 fprintf (file
, "# Context (\n");
808 fprintf (file
, "#eq");
810 for (i
= 0; i
< scop_nb_params (scop
); i
++)
811 fprintf (file
, " p%d", (int) i
);
813 fprintf (file
, " cst\n");
817 print_isl_set (file
, scop
->context
);
819 fprintf (file
, "no isl context %d\n", (int) scop_nb_params (scop
) + 2);
822 fprintf (file
, "# )\n");
825 /* Print to FILE the SCOP, at some VERBOSITY level. */
828 print_scop (FILE *file
, scop_p scop
, int verbosity
)
833 fprintf (file
, "SCoP 1\n#(\n");
834 fprintf (file
, "# Language\nGimple\n");
835 openscop_print_scop_context (file
, scop
, verbosity
);
836 print_scop_params (file
, scop
, verbosity
);
839 fprintf (file
, "# Number of statements\n");
841 fprintf (file
, "%d\n", SCOP_BBS (scop
).length ());
843 FOR_EACH_VEC_ELT (SCOP_BBS (scop
), i
, pbb
)
844 print_pbb (file
, pbb
, verbosity
);
848 fprintf (file
, "# original_lst (\n");
849 print_lst (file
, SCOP_ORIGINAL_SCHEDULE (scop
), 0);
850 fprintf (file
, "\n#)\n");
852 fprintf (file
, "# transformed_lst (\n");
853 print_lst (file
, SCOP_TRANSFORMED_SCHEDULE (scop
), 0);
854 fprintf (file
, "\n#)\n");
857 fprintf (file
, "#)\n");
860 /* Print to STDERR the domain of PBB, at some VERBOSITY level. */
863 debug_pbb_domain (poly_bb_p pbb
, int verbosity
)
865 print_pbb_domain (stderr
, pbb
, verbosity
);
868 /* Print to FILE the domain and scattering function of PBB, at some
872 debug_pbb (poly_bb_p pbb
, int verbosity
)
874 print_pbb (stderr
, pbb
, verbosity
);
877 /* Print to STDERR the context of SCOP, at some VERBOSITY level. */
880 debug_scop_context (scop_p scop
, int verbosity
)
882 print_scop_context (stderr
, scop
, verbosity
);
885 /* Print to STDERR the SCOP, at some VERBOSITY level. */
888 debug_scop (scop_p scop
, int verbosity
)
890 print_scop (stderr
, scop
, verbosity
);
893 /* Print to STDERR the parameters of SCOP, at some VERBOSITY
897 debug_scop_params (scop_p scop
, int verbosity
)
899 print_scop_params (stderr
, scop
, verbosity
);
902 extern isl_ctx
*the_isl_ctx
;
904 print_isl_set (FILE *f
, isl_set
*set
)
906 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
907 p
= isl_printer_print_set (p
, set
);
908 isl_printer_free (p
);
912 debug_isl_set (isl_set
*set
)
914 print_isl_set (stderr
, set
);
918 print_isl_map (FILE *f
, isl_map
*map
)
920 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
921 p
= isl_printer_print_map (p
, map
);
922 isl_printer_free (p
);
926 debug_isl_map (isl_map
*map
)
928 print_isl_map (stderr
, map
);
932 print_isl_aff (FILE *f
, isl_aff
*aff
)
934 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
935 p
= isl_printer_print_aff (p
, aff
);
936 isl_printer_free (p
);
940 debug_isl_aff (isl_aff
*aff
)
942 print_isl_aff (stderr
, aff
);
946 print_isl_constraint (FILE *f
, isl_constraint
*c
)
948 isl_printer
*p
= isl_printer_to_file (the_isl_ctx
, f
);
949 p
= isl_printer_print_constraint (p
, c
);
950 isl_printer_free (p
);
954 debug_isl_constraint (isl_constraint
*c
)
956 print_isl_constraint (stderr
, c
);
959 /* Returns the number of iterations RES of the loop around PBB at
960 time(scattering) dimension TIME_DEPTH. */
963 pbb_number_of_iterations_at_time (poly_bb_p pbb
,
964 graphite_dim_t time_depth
,
967 isl_set
*transdomain
;
970 isl_val
*isllb
, *islub
;
972 /* Map the iteration domain through the current scatter, and work
973 on the resulting set. */
974 transdomain
= isl_set_apply (isl_set_copy (pbb
->domain
),
975 isl_map_copy (pbb
->transformed
));
977 /* Select the time_depth' dimension via an affine expression. */
978 dc
= isl_set_get_space (transdomain
);
979 aff
= isl_aff_zero_on_domain (isl_local_space_from_space (dc
));
980 aff
= isl_aff_set_coefficient_si (aff
, isl_dim_in
, time_depth
, 1);
982 /* And find the min/max for that function. */
983 /* XXX isl check results? */
984 isllb
= isl_set_min_val (transdomain
, aff
);
985 islub
= isl_set_max_val (transdomain
, aff
);
987 islub
= isl_val_sub (islub
, isllb
);
988 islub
= isl_val_add_ui (islub
, 1);
989 isl_val_get_num_gmp (islub
, res
);
991 isl_val_free (islub
);
993 isl_set_free (transdomain
);
996 /* Translates LOOP to LST. */
999 loop_to_lst (loop_p loop
, vec
<poly_bb_p
> bbs
, int *i
)
1005 for (; bbs
.iterate (*i
, &pbb
); (*i
)++)
1008 basic_block bb
= GBB_BB (PBB_BLACK_BOX (pbb
));
1010 if (bb
->loop_father
== loop
)
1011 stmt
= new_lst_stmt (pbb
);
1012 else if (flow_bb_inside_loop_p (loop
, bb
))
1014 loop_p next
= loop
->inner
;
1016 while (next
&& !flow_bb_inside_loop_p (next
, bb
))
1019 stmt
= loop_to_lst (next
, bbs
, i
);
1024 return new_lst_loop (seq
);
1027 seq
.safe_push (stmt
);
1030 return new_lst_loop (seq
);
1033 /* Reads the original scattering of the SCOP and returns an LST
1037 scop_to_lst (scop_p scop
)
1040 int i
, n
= SCOP_BBS (scop
).length ();
1043 sese region
= SCOP_REGION (scop
);
1045 for (i
= 0; i
< n
; i
++)
1047 poly_bb_p pbb
= SCOP_BBS (scop
)[i
];
1048 loop_p loop
= outermost_loop_in_sese (region
, GBB_BB (PBB_BLACK_BOX (pbb
)));
1050 if (loop_in_sese_p (loop
, region
))
1051 res
= loop_to_lst (loop
, SCOP_BBS (scop
), &i
);
1053 res
= new_lst_stmt (pbb
);
1055 seq
.safe_push (res
);
1058 res
= new_lst_loop (seq
);
1059 SCOP_ORIGINAL_SCHEDULE (scop
) = res
;
1060 SCOP_TRANSFORMED_SCHEDULE (scop
) = copy_lst (res
);
1063 /* Print to FILE on a new line COLUMN white spaces. */
1066 lst_indent_to (FILE *file
, int column
)
1071 fprintf (file
, "\n#");
1073 for (i
= 0; i
< column
; i
++)
1074 fprintf (file
, " ");
1077 /* Print LST to FILE with INDENT spaces of indentation. */
1080 print_lst (FILE *file
, lst_p lst
, int indent
)
1085 lst_indent_to (file
, indent
);
1087 if (LST_LOOP_P (lst
))
1092 if (LST_LOOP_FATHER (lst
))
1093 fprintf (file
, "%d (loop", lst_dewey_number (lst
));
1095 fprintf (file
, "#(root");
1097 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1098 print_lst (file
, l
, indent
+ 2);
1100 fprintf (file
, ")");
1103 fprintf (file
, "%d stmt_%d", lst_dewey_number (lst
), pbb_index (LST_PBB (lst
)));
1106 /* Print LST to STDERR. */
1109 debug_lst (lst_p lst
)
1111 print_lst (stderr
, lst
, 0);
1114 /* Pretty print to FILE the loop statement tree LST in DOT format. */
1117 dot_lst_1 (FILE *file
, lst_p lst
)
1122 if (LST_LOOP_P (lst
))
1127 if (!LST_LOOP_FATHER (lst
))
1128 fprintf (file
, "L -> L_%d_%d\n",
1130 lst_dewey_number (lst
));
1132 fprintf (file
, "L_%d_%d -> L_%d_%d\n",
1133 lst_depth (LST_LOOP_FATHER (lst
)),
1134 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1136 lst_dewey_number (lst
));
1138 FOR_EACH_VEC_ELT (LST_SEQ (lst
), i
, l
)
1139 dot_lst_1 (file
, l
);
1143 fprintf (file
, "L_%d_%d -> S_%d\n",
1144 lst_depth (LST_LOOP_FATHER (lst
)),
1145 lst_dewey_number (LST_LOOP_FATHER (lst
)),
1146 pbb_index (LST_PBB (lst
)));
1150 /* Display the LST using dotty. */
1155 /* When debugging, enable the following code. This cannot be used
1156 in production compilers because it calls "system". */
1158 FILE *stream
= fopen ("/tmp/lst.dot", "w");
1159 gcc_assert (stream
);
1161 fputs ("digraph all {\n", stream
);
1162 dot_lst_1 (stream
, lst
);
1163 fputs ("}\n\n", stream
);
1166 system ("dotty /tmp/lst.dot &");
1168 fputs ("digraph all {\n", stderr
);
1169 dot_lst_1 (stderr
, lst
);
1170 fputs ("}\n\n", stderr
);
1175 /* Reverse the loop around PBB at level DEPTH. */
1178 reverse_loop_at_level (poly_bb_p pbb
, int depth
)
1180 unsigned i
, depth_dim
= psct_dynamic_dim (pbb
, depth
);
1181 isl_space
*d
= isl_map_get_space (pbb
->transformed
);
1182 isl_space
*d1
= isl_space_range (d
);
1183 unsigned n
= isl_space_dim (d1
, isl_dim_out
);
1184 isl_space
*d2
= isl_space_add_dims (d1
, isl_dim_in
, n
);
1185 isl_map
*x
= isl_map_universe (isl_space_copy (d2
));
1186 isl_constraint
*c
= isl_equality_alloc (isl_local_space_from_space (d2
));
1188 for (i
= 0; i
< n
; i
++)
1190 x
= isl_map_equate (x
, isl_dim_in
, i
, isl_dim_out
, i
);
1192 c
= isl_constraint_set_coefficient_si (c
, isl_dim_in
, depth_dim
, 1);
1193 c
= isl_constraint_set_coefficient_si (c
, isl_dim_out
, depth_dim
, 1);
1194 x
= isl_map_add_constraint (x
, c
);
1198 /* Reverse the loop at level DEPTH for all the PBBS. */
1201 reverse_loop_for_pbbs (scop_p scop
, vec
<poly_bb_p
> pbbs
, int depth
)
1205 isl_space
*space
= isl_space_from_domain (isl_set_get_space (scop
->context
));
1206 isl_union_map
*res
= isl_union_map_empty (space
);
1208 for (i
= 0; pbbs
.iterate (i
, &pbb
); i
++)
1209 res
= isl_union_map_add_map (res
, reverse_loop_at_level (pbb
, depth
));