]>
Commit | Line | Data |
---|---|---|
2abae5f1 | 1 | /* Graphite polyhedral representation. |
5624e564 | 2 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
2abae5f1 SP |
3 | Contributed by Sebastian Pop <sebastian.pop@amd.com> and |
4 | Tobias Grosser <grosser@fim.uni-passau.de>. | |
5 | ||
6 | This file is part of GCC. | |
7 | ||
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) | |
11 | any later version. | |
12 | ||
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. | |
17 | ||
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/>. */ | |
33ad93b9 | 21 | |
2abae5f1 | 22 | #include "config.h" |
33ad93b9 | 23 | |
eae1a5d4 | 24 | #ifdef HAVE_isl |
4bc190dc JW |
25 | /* Workaround for GMP 5.1.3 bug, see PR56019. */ |
26 | #include <stddef.h> | |
27 | ||
33ad93b9 RG |
28 | #include <isl/set.h> |
29 | #include <isl/map.h> | |
30 | #include <isl/union_map.h> | |
31 | #include <isl/constraint.h> | |
32 | #include <isl/ilp.h> | |
33 | #include <isl/aff.h> | |
b47595f7 | 34 | #include <isl/val.h> |
797d8858 TB |
35 | |
36 | /* Since ISL-0.13, the extern is in val_gmp.h. */ | |
37 | #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus) | |
b47595f7 MN |
38 | extern "C" { |
39 | #endif | |
40 | #include <isl/val_gmp.h> | |
797d8858 | 41 | #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus) |
b47595f7 MN |
42 | } |
43 | #endif | |
eae1a5d4 | 44 | #endif |
33ad93b9 | 45 | |
2abae5f1 SP |
46 | #include "system.h" |
47 | #include "coretypes.h" | |
32a73fc4 | 48 | #include "diagnostic-core.h" |
40e23961 | 49 | #include "alias.h" |
c7131fb2 | 50 | #include "backend.h" |
9fdcd34e | 51 | #include "cfghooks.h" |
40e23961 | 52 | #include "tree.h" |
c7131fb2 | 53 | #include "gimple.h" |
60393bbc | 54 | #include "hard-reg-set.h" |
c7131fb2 AM |
55 | #include "options.h" |
56 | #include "fold-const.h" | |
2fb9a547 | 57 | #include "internal-fn.h" |
5be5c238 | 58 | #include "gimple-iterator.h" |
442b4905 | 59 | #include "tree-ssa-loop.h" |
7ee2468b | 60 | #include "dumpfile.h" |
1bd6497c | 61 | #include "gimple-pretty-print.h" |
2abae5f1 SP |
62 | #include "cfgloop.h" |
63 | #include "tree-chrec.h" | |
64 | #include "tree-data-ref.h" | |
65 | #include "tree-scalar-evolution.h" | |
1bd6497c | 66 | #include "sese.h" |
2abae5f1 | 67 | |
eae1a5d4 | 68 | #ifdef HAVE_isl |
2abae5f1 | 69 | #include "graphite-poly.h" |
2abae5f1 | 70 | |
721c8b1e RB |
71 | #define OPENSCOP_MAX_STRING 256 |
72 | ||
33ad93b9 RG |
73 | |
74 | /* Print to STDERR the GMP value VAL. */ | |
75 | ||
76 | DEBUG_FUNCTION void | |
77 | debug_gmp_value (mpz_t val) | |
78 | { | |
8ac16127 | 79 | gmp_fprintf (stderr, "%Zd", val); |
33ad93b9 RG |
80 | } |
81 | ||
2abae5f1 SP |
82 | /* Return the maximal loop depth in SCOP. */ |
83 | ||
84 | int | |
85 | scop_max_loop_depth (scop_p scop) | |
86 | { | |
87 | int i; | |
88 | poly_bb_p pbb; | |
89 | int max_nb_loops = 0; | |
90 | ||
9771b263 | 91 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
2abae5f1 SP |
92 | { |
93 | int nb_loops = pbb_dim_iter_domain (pbb); | |
94 | if (max_nb_loops < nb_loops) | |
95 | max_nb_loops = nb_loops; | |
96 | } | |
97 | ||
98 | return max_nb_loops; | |
99 | } | |
100 | ||
40bf935e SP |
101 | /* Prints to FILE the scattering function of PBB, at some VERBOSITY |
102 | level. */ | |
2abae5f1 | 103 | |
730a9846 | 104 | static void |
40bf935e | 105 | print_scattering_function_1 (FILE *file, poly_bb_p pbb, int verbosity) |
2abae5f1 SP |
106 | { |
107 | graphite_dim_t i; | |
108 | ||
40bf935e SP |
109 | if (verbosity > 0) |
110 | { | |
111 | fprintf (file, "# scattering bb_%d (\n", pbb_index (pbb)); | |
7241f8c5 | 112 | fprintf (file, "#eq"); |
2abae5f1 | 113 | |
40bf935e SP |
114 | for (i = 0; i < pbb_nb_scattering_transform (pbb); i++) |
115 | fprintf (file, " s%d", (int) i); | |
2abae5f1 | 116 | |
40bf935e SP |
117 | for (i = 0; i < pbb_nb_local_vars (pbb); i++) |
118 | fprintf (file, " lv%d", (int) i); | |
2abae5f1 | 119 | |
40bf935e SP |
120 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) |
121 | fprintf (file, " i%d", (int) i); | |
2abae5f1 | 122 | |
40bf935e SP |
123 | for (i = 0; i < pbb_nb_params (pbb); i++) |
124 | fprintf (file, " p%d", (int) i); | |
2abae5f1 | 125 | |
40bf935e SP |
126 | fprintf (file, " cst\n"); |
127 | } | |
2abae5f1 | 128 | |
33ad93b9 RG |
129 | fprintf (file, "isl\n"); |
130 | print_isl_map (file, pbb->transformed ? pbb->transformed : pbb->schedule); | |
2abae5f1 | 131 | |
40bf935e SP |
132 | if (verbosity > 0) |
133 | fprintf (file, "#)\n"); | |
2abae5f1 SP |
134 | } |
135 | ||
40bf935e SP |
136 | /* Prints to FILE the scattering function of PBB, at some VERBOSITY |
137 | level. */ | |
730a9846 SP |
138 | |
139 | void | |
40bf935e | 140 | print_scattering_function (FILE *file, poly_bb_p pbb, int verbosity) |
730a9846 SP |
141 | { |
142 | if (!PBB_TRANSFORMED (pbb)) | |
143 | return; | |
144 | ||
33ad93b9 | 145 | if (pbb->schedule || pbb->transformed) |
40bf935e SP |
146 | { |
147 | if (verbosity > 0) | |
148 | fprintf (file, "# Scattering function is provided\n"); | |
149 | ||
150 | fprintf (file, "1\n"); | |
151 | } | |
730a9846 SP |
152 | else |
153 | { | |
40bf935e SP |
154 | if (verbosity > 0) |
155 | fprintf (file, "# Scattering function is not provided\n"); | |
156 | ||
157 | fprintf (file, "0\n"); | |
730a9846 SP |
158 | return; |
159 | } | |
160 | ||
33ad93b9 | 161 | print_scattering_function_1 (file, pbb, verbosity); |
ae403f5a RB |
162 | |
163 | if (verbosity > 0) | |
164 | fprintf (file, "# Scattering names are not provided\n"); | |
165 | ||
166 | fprintf (file, "0\n"); | |
167 | ||
730a9846 SP |
168 | } |
169 | ||
40bf935e SP |
170 | /* Prints to FILE the iteration domain of PBB, at some VERBOSITY |
171 | level. */ | |
2abae5f1 SP |
172 | |
173 | void | |
40bf935e | 174 | print_iteration_domain (FILE *file, poly_bb_p pbb, int verbosity) |
2abae5f1 | 175 | { |
40bf935e | 176 | print_pbb_domain (file, pbb, verbosity); |
2abae5f1 SP |
177 | } |
178 | ||
179 | /* Prints to FILE the scattering functions of every PBB of SCOP. */ | |
180 | ||
181 | void | |
40bf935e | 182 | print_scattering_functions (FILE *file, scop_p scop, int verbosity) |
2abae5f1 SP |
183 | { |
184 | int i; | |
185 | poly_bb_p pbb; | |
186 | ||
9771b263 | 187 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
40bf935e | 188 | print_scattering_function (file, pbb, verbosity); |
2abae5f1 SP |
189 | } |
190 | ||
40bf935e SP |
191 | /* Prints to FILE the iteration domains of every PBB of SCOP, at some |
192 | VERBOSITY level. */ | |
2abae5f1 SP |
193 | |
194 | void | |
40bf935e | 195 | print_iteration_domains (FILE *file, scop_p scop, int verbosity) |
2abae5f1 SP |
196 | { |
197 | int i; | |
198 | poly_bb_p pbb; | |
199 | ||
9771b263 | 200 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
40bf935e | 201 | print_iteration_domain (file, pbb, verbosity); |
2abae5f1 SP |
202 | } |
203 | ||
40bf935e SP |
204 | /* Prints to STDERR the scattering function of PBB, at some VERBOSITY |
205 | level. */ | |
2abae5f1 | 206 | |
24e47c76 | 207 | DEBUG_FUNCTION void |
40bf935e | 208 | debug_scattering_function (poly_bb_p pbb, int verbosity) |
2abae5f1 | 209 | { |
40bf935e | 210 | print_scattering_function (stderr, pbb, verbosity); |
2abae5f1 SP |
211 | } |
212 | ||
40bf935e SP |
213 | /* Prints to STDERR the iteration domain of PBB, at some VERBOSITY |
214 | level. */ | |
2abae5f1 | 215 | |
24e47c76 | 216 | DEBUG_FUNCTION void |
40bf935e | 217 | debug_iteration_domain (poly_bb_p pbb, int verbosity) |
2abae5f1 | 218 | { |
40bf935e | 219 | print_iteration_domain (stderr, pbb, verbosity); |
2abae5f1 SP |
220 | } |
221 | ||
40bf935e SP |
222 | /* Prints to STDERR the scattering functions of every PBB of SCOP, at |
223 | some VERBOSITY level. */ | |
2abae5f1 | 224 | |
24e47c76 | 225 | DEBUG_FUNCTION void |
40bf935e | 226 | debug_scattering_functions (scop_p scop, int verbosity) |
2abae5f1 | 227 | { |
40bf935e | 228 | print_scattering_functions (stderr, scop, verbosity); |
2abae5f1 SP |
229 | } |
230 | ||
40bf935e SP |
231 | /* Prints to STDERR the iteration domains of every PBB of SCOP, at |
232 | some VERBOSITY level. */ | |
2abae5f1 | 233 | |
24e47c76 | 234 | DEBUG_FUNCTION void |
40bf935e | 235 | debug_iteration_domains (scop_p scop, int verbosity) |
2abae5f1 | 236 | { |
40bf935e | 237 | print_iteration_domains (stderr, scop, verbosity); |
2abae5f1 SP |
238 | } |
239 | ||
240 | /* Apply graphite transformations to all the basic blocks of SCOP. */ | |
241 | ||
242 | bool | |
243 | apply_poly_transforms (scop_p scop) | |
244 | { | |
245 | bool transform_done = false; | |
721c8b1e | 246 | |
2abae5f1 SP |
247 | /* Generate code even if we did not apply any real transformation. |
248 | This also allows to check the performance for the identity | |
249 | transformation: GIMPLE -> GRAPHITE -> GIMPLE | |
250 | Keep in mind that CLooG optimizes in control, so the loop structure | |
251 | may change, even if we only use -fgraphite-identity. */ | |
252 | if (flag_graphite_identity) | |
253 | transform_done = true; | |
254 | ||
3cf0e270 | 255 | if (flag_loop_parallelize_all) |
2abae5f1 SP |
256 | transform_done = true; |
257 | ||
258 | if (flag_loop_block) | |
25e20d33 | 259 | transform_done |= scop_do_block (scop); |
24c79709 SP |
260 | else |
261 | { | |
262 | if (flag_loop_strip_mine) | |
247fd30e | 263 | transform_done |= scop_do_strip_mine (scop, 0); |
2abae5f1 | 264 | |
24c79709 SP |
265 | if (flag_loop_interchange) |
266 | transform_done |= scop_do_interchange (scop); | |
267 | } | |
2abae5f1 | 268 | |
b60cc080 TG |
269 | /* This pass needs to be run at the final stage, as it does not |
270 | update the lst. */ | |
20d3465b | 271 | if (flag_loop_optimize_isl || flag_loop_unroll_jam) |
b60cc080 TG |
272 | transform_done |= optimize_isl (scop); |
273 | ||
2abae5f1 SP |
274 | return transform_done; |
275 | } | |
276 | ||
25d7cc15 SP |
277 | /* Create a new polyhedral data reference and add it to PBB. It is |
278 | defined by its ACCESSES, its TYPE, and the number of subscripts | |
279 | NB_SUBSCRIPTS. */ | |
2abae5f1 SP |
280 | |
281 | void | |
1825f9a2 | 282 | new_poly_dr (poly_bb_p pbb, int dr_base_object_set, |
33ad93b9 RG |
283 | enum poly_dr_type type, void *cdr, graphite_dim_t nb_subscripts, |
284 | isl_map *acc, isl_set *extent) | |
2abae5f1 | 285 | { |
afae0207 | 286 | static int id = 0; |
211694b6 | 287 | poly_dr_p pdr = XNEW (struct poly_dr); |
2abae5f1 | 288 | |
afae0207 | 289 | PDR_ID (pdr) = id++; |
1825f9a2 | 290 | PDR_BASE_OBJECT_SET (pdr) = dr_base_object_set; |
7bd2a8a7 | 291 | PDR_NB_REFS (pdr) = 1; |
2abae5f1 | 292 | PDR_PBB (pdr) = pbb; |
33ad93b9 RG |
293 | pdr->accesses = acc; |
294 | pdr->extent = extent; | |
2abae5f1 SP |
295 | PDR_TYPE (pdr) = type; |
296 | PDR_CDR (pdr) = cdr; | |
25d7cc15 | 297 | PDR_NB_SUBSCRIPTS (pdr) = nb_subscripts; |
9771b263 | 298 | PBB_DRS (pbb).safe_push (pdr); |
2abae5f1 SP |
299 | } |
300 | ||
301 | /* Free polyhedral data reference PDR. */ | |
302 | ||
303 | void | |
304 | free_poly_dr (poly_dr_p pdr) | |
305 | { | |
33ad93b9 RG |
306 | isl_map_free (pdr->accesses); |
307 | isl_set_free (pdr->extent); | |
2abae5f1 SP |
308 | XDELETE (pdr); |
309 | } | |
310 | ||
311 | /* Create a new polyhedral black box. */ | |
312 | ||
efa21390 SP |
313 | poly_bb_p |
314 | new_poly_bb (scop_p scop, void *black_box) | |
2abae5f1 SP |
315 | { |
316 | poly_bb_p pbb = XNEW (struct poly_bb); | |
317 | ||
33ad93b9 RG |
318 | pbb->domain = NULL; |
319 | pbb->schedule = NULL; | |
320 | pbb->transformed = NULL; | |
321 | pbb->saved = NULL; | |
20d3465b | 322 | pbb->map_sepclass = NULL; |
2abae5f1 SP |
323 | PBB_SCOP (pbb) = scop; |
324 | pbb_set_black_box (pbb, black_box); | |
f4648ed1 SP |
325 | PBB_TRANSFORMED (pbb) = NULL; |
326 | PBB_SAVED (pbb) = NULL; | |
327 | PBB_ORIGINAL (pbb) = NULL; | |
9771b263 | 328 | PBB_DRS (pbb).create (3); |
efa21390 | 329 | PBB_IS_REDUCTION (pbb) = false; |
efa21390 SP |
330 | GBB_PBB ((gimple_bb_p) black_box) = pbb; |
331 | ||
332 | return pbb; | |
2abae5f1 SP |
333 | } |
334 | ||
335 | /* Free polyhedral black box. */ | |
336 | ||
337 | void | |
338 | free_poly_bb (poly_bb_p pbb) | |
339 | { | |
340 | int i; | |
341 | poly_dr_p pdr; | |
342 | ||
33ad93b9 RG |
343 | isl_set_free (pbb->domain); |
344 | isl_map_free (pbb->schedule); | |
345 | isl_map_free (pbb->transformed); | |
346 | isl_map_free (pbb->saved); | |
2abae5f1 | 347 | |
9771b263 DN |
348 | if (PBB_DRS (pbb).exists ()) |
349 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) | |
2abae5f1 SP |
350 | free_poly_dr (pdr); |
351 | ||
9771b263 | 352 | PBB_DRS (pbb).release (); |
2abae5f1 SP |
353 | XDELETE (pbb); |
354 | } | |
355 | ||
356 | static void | |
ae403f5a | 357 | print_pdr_access_layout (FILE *file, poly_bb_p pbb, poly_dr_p pdr) |
2abae5f1 SP |
358 | { |
359 | graphite_dim_t i; | |
360 | ||
361 | fprintf (file, "# eq"); | |
362 | ||
ae403f5a | 363 | fprintf (file, " alias"); |
2abae5f1 | 364 | |
25d7cc15 | 365 | for (i = 0; i < PDR_NB_SUBSCRIPTS (pdr); i++) |
2abae5f1 SP |
366 | fprintf (file, " sub%d", (int) i); |
367 | ||
ae403f5a RB |
368 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) |
369 | fprintf (file, " i%d", (int) i); | |
370 | ||
371 | for (i = 0; i < pbb_nb_params (pbb); i++) | |
372 | fprintf (file, " p%d", (int) i); | |
373 | ||
2abae5f1 SP |
374 | fprintf (file, " cst\n"); |
375 | } | |
376 | ||
40bf935e SP |
377 | /* Prints to FILE the polyhedral data reference PDR, at some VERBOSITY |
378 | level. */ | |
2abae5f1 SP |
379 | |
380 | void | |
40bf935e | 381 | print_pdr (FILE *file, poly_dr_p pdr, int verbosity) |
2abae5f1 | 382 | { |
40bf935e | 383 | if (verbosity > 1) |
2abae5f1 | 384 | { |
40bf935e SP |
385 | fprintf (file, "# pdr_%d (", PDR_ID (pdr)); |
386 | ||
387 | switch (PDR_TYPE (pdr)) | |
388 | { | |
389 | case PDR_READ: | |
390 | fprintf (file, "read \n"); | |
391 | break; | |
2abae5f1 | 392 | |
40bf935e SP |
393 | case PDR_WRITE: |
394 | fprintf (file, "write \n"); | |
395 | break; | |
2abae5f1 | 396 | |
40bf935e SP |
397 | case PDR_MAY_WRITE: |
398 | fprintf (file, "may_write \n"); | |
399 | break; | |
2abae5f1 | 400 | |
40bf935e SP |
401 | default: |
402 | gcc_unreachable (); | |
403 | } | |
404 | ||
405 | dump_data_reference (file, (data_reference_p) PDR_CDR (pdr)); | |
2abae5f1 SP |
406 | } |
407 | ||
40bf935e SP |
408 | if (verbosity > 0) |
409 | { | |
410 | fprintf (file, "# data accesses (\n"); | |
ae403f5a | 411 | print_pdr_access_layout (file, PDR_PBB (pdr), pdr); |
40bf935e | 412 | } |
2abae5f1 | 413 | |
33ad93b9 | 414 | /* XXX isl dump accesses/subscripts */ |
2abae5f1 | 415 | |
40bf935e SP |
416 | if (verbosity > 0) |
417 | fprintf (file, "#)\n"); | |
418 | ||
419 | if (verbosity > 1) | |
420 | fprintf (file, "#)\n"); | |
2abae5f1 SP |
421 | } |
422 | ||
40bf935e SP |
423 | /* Prints to STDERR the polyhedral data reference PDR, at some |
424 | VERBOSITY level. */ | |
2abae5f1 | 425 | |
24e47c76 | 426 | DEBUG_FUNCTION void |
40bf935e | 427 | debug_pdr (poly_dr_p pdr, int verbosity) |
2abae5f1 | 428 | { |
40bf935e | 429 | print_pdr (stderr, pdr, verbosity); |
2abae5f1 SP |
430 | } |
431 | ||
432 | /* Creates a new SCOP containing REGION. */ | |
433 | ||
434 | scop_p | |
435 | new_scop (void *region) | |
436 | { | |
437 | scop_p scop = XNEW (struct scop); | |
438 | ||
33ad93b9 RG |
439 | scop->context = NULL; |
440 | scop->must_raw = NULL; | |
441 | scop->may_raw = NULL; | |
442 | scop->must_raw_no_source = NULL; | |
443 | scop->may_raw_no_source = NULL; | |
444 | scop->must_war = NULL; | |
445 | scop->may_war = NULL; | |
446 | scop->must_war_no_source = NULL; | |
447 | scop->may_war_no_source = NULL; | |
448 | scop->must_waw = NULL; | |
449 | scop->may_waw = NULL; | |
450 | scop->must_waw_no_source = NULL; | |
451 | scop->may_waw_no_source = NULL; | |
2abae5f1 | 452 | scop_set_region (scop, region); |
9771b263 | 453 | SCOP_BBS (scop).create (3); |
f70de156 SP |
454 | SCOP_ORIGINAL_SCHEDULE (scop) = NULL; |
455 | SCOP_TRANSFORMED_SCHEDULE (scop) = NULL; | |
456 | SCOP_SAVED_SCHEDULE (scop) = NULL; | |
a1954f72 SP |
457 | POLY_SCOP_P (scop) = false; |
458 | ||
2abae5f1 SP |
459 | return scop; |
460 | } | |
461 | ||
462 | /* Deletes SCOP. */ | |
463 | ||
464 | void | |
465 | free_scop (scop_p scop) | |
466 | { | |
467 | int i; | |
468 | poly_bb_p pbb; | |
469 | ||
9771b263 | 470 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
2abae5f1 SP |
471 | free_poly_bb (pbb); |
472 | ||
9771b263 | 473 | SCOP_BBS (scop).release (); |
2abae5f1 | 474 | |
33ad93b9 RG |
475 | isl_set_free (scop->context); |
476 | isl_union_map_free (scop->must_raw); | |
477 | isl_union_map_free (scop->may_raw); | |
478 | isl_union_map_free (scop->must_raw_no_source); | |
479 | isl_union_map_free (scop->may_raw_no_source); | |
480 | isl_union_map_free (scop->must_war); | |
481 | isl_union_map_free (scop->may_war); | |
482 | isl_union_map_free (scop->must_war_no_source); | |
483 | isl_union_map_free (scop->may_war_no_source); | |
484 | isl_union_map_free (scop->must_waw); | |
485 | isl_union_map_free (scop->may_waw); | |
486 | isl_union_map_free (scop->must_waw_no_source); | |
487 | isl_union_map_free (scop->may_waw_no_source); | |
f70de156 SP |
488 | free_lst (SCOP_ORIGINAL_SCHEDULE (scop)); |
489 | free_lst (SCOP_TRANSFORMED_SCHEDULE (scop)); | |
490 | free_lst (SCOP_SAVED_SCHEDULE (scop)); | |
2abae5f1 SP |
491 | XDELETE (scop); |
492 | } | |
493 | ||
ae403f5a RB |
494 | /* Print to FILE the domain of PBB in OpenScop format, at some VERBOSITY |
495 | level. */ | |
496 | ||
497 | static void | |
498 | openscop_print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity) | |
499 | { | |
500 | graphite_dim_t i; | |
501 | gimple_bb_p gbb = PBB_BLACK_BOX (pbb); | |
502 | ||
33ad93b9 | 503 | if (!pbb->domain) |
ae403f5a RB |
504 | return; |
505 | ||
506 | if (verbosity > 0) | |
507 | { | |
508 | fprintf (file, "\n# Iteration domain of bb_%d (\n", GBB_BB (gbb)->index); | |
7241f8c5 | 509 | fprintf (file, "#eq"); |
ae403f5a RB |
510 | |
511 | for (i = 0; i < pbb_dim_iter_domain (pbb); i++) | |
512 | fprintf (file, " i%d", (int) i); | |
513 | ||
514 | for (i = 0; i < pbb_nb_params (pbb); i++) | |
515 | fprintf (file, " p%d", (int) i); | |
516 | ||
517 | fprintf (file, " cst\n"); | |
518 | } | |
519 | ||
33ad93b9 | 520 | fprintf (file, "XXX isl\n"); |
ae403f5a RB |
521 | |
522 | if (verbosity > 0) | |
523 | fprintf (file, "#)\n"); | |
524 | } | |
525 | ||
40bf935e | 526 | /* Print to FILE the domain of PBB, at some VERBOSITY level. */ |
2abae5f1 SP |
527 | |
528 | void | |
33ad93b9 | 529 | print_pbb_domain (FILE *file, poly_bb_p pbb, int verbosity ATTRIBUTE_UNUSED) |
2abae5f1 | 530 | { |
33ad93b9 | 531 | print_isl_set (file, pbb->domain); |
2abae5f1 SP |
532 | } |
533 | ||
534 | /* Dump the cases of a graphite basic block GBB on FILE. */ | |
535 | ||
536 | static void | |
537 | dump_gbb_cases (FILE *file, gimple_bb_p gbb) | |
538 | { | |
539 | int i; | |
540 | gimple stmt; | |
9771b263 | 541 | vec<gimple> cases; |
2abae5f1 SP |
542 | |
543 | if (!gbb) | |
544 | return; | |
545 | ||
546 | cases = GBB_CONDITION_CASES (gbb); | |
9771b263 | 547 | if (cases.is_empty ()) |
2abae5f1 SP |
548 | return; |
549 | ||
03922af3 | 550 | fprintf (file, "# cases bb_%d (\n", GBB_BB (gbb)->index); |
2abae5f1 | 551 | |
9771b263 | 552 | FOR_EACH_VEC_ELT (cases, i, stmt) |
03922af3 SP |
553 | { |
554 | fprintf (file, "# "); | |
555 | print_gimple_stmt (file, stmt, 0, 0); | |
556 | } | |
2abae5f1 | 557 | |
03922af3 | 558 | fprintf (file, "#)\n"); |
2abae5f1 SP |
559 | } |
560 | ||
561 | /* Dump conditions of a graphite basic block GBB on FILE. */ | |
562 | ||
563 | static void | |
564 | dump_gbb_conditions (FILE *file, gimple_bb_p gbb) | |
565 | { | |
566 | int i; | |
567 | gimple stmt; | |
9771b263 | 568 | vec<gimple> conditions; |
2abae5f1 SP |
569 | |
570 | if (!gbb) | |
571 | return; | |
572 | ||
573 | conditions = GBB_CONDITIONS (gbb); | |
9771b263 | 574 | if (conditions.is_empty ()) |
2abae5f1 SP |
575 | return; |
576 | ||
03922af3 | 577 | fprintf (file, "# conditions bb_%d (\n", GBB_BB (gbb)->index); |
2abae5f1 | 578 | |
9771b263 | 579 | FOR_EACH_VEC_ELT (conditions, i, stmt) |
03922af3 SP |
580 | { |
581 | fprintf (file, "# "); | |
582 | print_gimple_stmt (file, stmt, 0, 0); | |
583 | } | |
2abae5f1 | 584 | |
03922af3 | 585 | fprintf (file, "#)\n"); |
2abae5f1 SP |
586 | } |
587 | ||
40bf935e SP |
588 | /* Print to FILE all the data references of PBB, at some VERBOSITY |
589 | level. */ | |
2abae5f1 SP |
590 | |
591 | void | |
40bf935e | 592 | print_pdrs (FILE *file, poly_bb_p pbb, int verbosity) |
2abae5f1 SP |
593 | { |
594 | int i; | |
595 | poly_dr_p pdr; | |
03922af3 SP |
596 | int nb_reads = 0; |
597 | int nb_writes = 0; | |
2abae5f1 | 598 | |
9771b263 | 599 | if (PBB_DRS (pbb).length () == 0) |
03922af3 | 600 | { |
40bf935e SP |
601 | if (verbosity > 0) |
602 | fprintf (file, "# Access informations are not provided\n");\ | |
603 | fprintf (file, "0\n"); | |
03922af3 SP |
604 | return; |
605 | } | |
606 | ||
40bf935e SP |
607 | if (verbosity > 1) |
608 | fprintf (file, "# Data references (\n"); | |
609 | ||
610 | if (verbosity > 0) | |
611 | fprintf (file, "# Access informations are provided\n"); | |
612 | fprintf (file, "1\n"); | |
03922af3 | 613 | |
9771b263 | 614 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
03922af3 SP |
615 | if (PDR_TYPE (pdr) == PDR_READ) |
616 | nb_reads++; | |
617 | else | |
618 | nb_writes++; | |
619 | ||
40bf935e SP |
620 | if (verbosity > 1) |
621 | fprintf (file, "# Read data references (\n"); | |
622 | ||
623 | if (verbosity > 0) | |
624 | fprintf (file, "# Read access informations\n"); | |
625 | fprintf (file, "%d\n", nb_reads); | |
626 | ||
9771b263 | 627 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
03922af3 | 628 | if (PDR_TYPE (pdr) == PDR_READ) |
40bf935e SP |
629 | print_pdr (file, pdr, verbosity); |
630 | ||
631 | if (verbosity > 1) | |
632 | fprintf (file, "#)\n"); | |
633 | ||
634 | if (verbosity > 1) | |
635 | fprintf (file, "# Write data references (\n"); | |
636 | ||
637 | if (verbosity > 0) | |
638 | fprintf (file, "# Write access informations\n"); | |
639 | fprintf (file, "%d\n", nb_writes); | |
03922af3 | 640 | |
9771b263 | 641 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
03922af3 | 642 | if (PDR_TYPE (pdr) != PDR_READ) |
40bf935e SP |
643 | print_pdr (file, pdr, verbosity); |
644 | ||
645 | if (verbosity > 1) | |
646 | fprintf (file, "#)\n"); | |
647 | ||
648 | if (verbosity > 1) | |
649 | fprintf (file, "#)\n"); | |
2abae5f1 SP |
650 | } |
651 | ||
652 | /* Print to STDERR all the data references of PBB. */ | |
653 | ||
24e47c76 | 654 | DEBUG_FUNCTION void |
40bf935e | 655 | debug_pdrs (poly_bb_p pbb, int verbosity) |
2abae5f1 | 656 | { |
40bf935e | 657 | print_pdrs (stderr, pbb, verbosity); |
2abae5f1 SP |
658 | } |
659 | ||
ae403f5a RB |
660 | /* Print to FILE the body of PBB, at some VERBOSITY level. |
661 | If statement_body_provided is false statement body is not printed. */ | |
03922af3 SP |
662 | |
663 | static void | |
ae403f5a RB |
664 | print_pbb_body (FILE *file, poly_bb_p pbb, int verbosity, |
665 | bool statement_body_provided) | |
03922af3 | 666 | { |
40bf935e SP |
667 | if (verbosity > 1) |
668 | fprintf (file, "# Body (\n"); | |
669 | ||
ae403f5a | 670 | if (!statement_body_provided) |
0ba82567 SP |
671 | { |
672 | if (verbosity > 0) | |
673 | fprintf (file, "# Statement body is not provided\n"); | |
674 | ||
675 | fprintf (file, "0\n"); | |
ae403f5a | 676 | |
0ba82567 SP |
677 | if (verbosity > 1) |
678 | fprintf (file, "#)\n"); | |
679 | return; | |
680 | } | |
ae403f5a | 681 | |
40bf935e SP |
682 | if (verbosity > 0) |
683 | fprintf (file, "# Statement body is provided\n"); | |
684 | fprintf (file, "1\n"); | |
685 | ||
686 | if (verbosity > 0) | |
687 | fprintf (file, "# Original iterator names\n# Iterator names are not provided yet.\n"); | |
688 | ||
689 | if (verbosity > 0) | |
690 | fprintf (file, "# Statement body\n"); | |
691 | ||
03922af3 | 692 | fprintf (file, "{\n"); |
512ab654 | 693 | dump_bb (file, pbb_bb (pbb), 0, 0); |
03922af3 | 694 | fprintf (file, "}\n"); |
40bf935e SP |
695 | |
696 | if (verbosity > 1) | |
697 | fprintf (file, "#)\n"); | |
03922af3 SP |
698 | } |
699 | ||
40bf935e SP |
700 | /* Print to FILE the domain and scattering function of PBB, at some |
701 | VERBOSITY level. */ | |
2abae5f1 SP |
702 | |
703 | void | |
40bf935e SP |
704 | print_pbb (FILE *file, poly_bb_p pbb, int verbosity) |
705 | { | |
706 | if (verbosity > 1) | |
707 | { | |
708 | fprintf (file, "# pbb_%d (\n", pbb_index (pbb)); | |
709 | dump_gbb_conditions (file, PBB_BLACK_BOX (pbb)); | |
710 | dump_gbb_cases (file, PBB_BLACK_BOX (pbb)); | |
711 | } | |
712 | ||
ae403f5a | 713 | openscop_print_pbb_domain (file, pbb, verbosity); |
40bf935e SP |
714 | print_scattering_function (file, pbb, verbosity); |
715 | print_pdrs (file, pbb, verbosity); | |
ae403f5a | 716 | print_pbb_body (file, pbb, verbosity, false); |
40bf935e SP |
717 | |
718 | if (verbosity > 1) | |
719 | fprintf (file, "#)\n"); | |
2abae5f1 SP |
720 | } |
721 | ||
40bf935e | 722 | /* Print to FILE the parameters of SCOP, at some VERBOSITY level. */ |
2abae5f1 SP |
723 | |
724 | void | |
40bf935e | 725 | print_scop_params (FILE *file, scop_p scop, int verbosity) |
2abae5f1 SP |
726 | { |
727 | int i; | |
728 | tree t; | |
729 | ||
40bf935e SP |
730 | if (verbosity > 1) |
731 | fprintf (file, "# parameters (\n"); | |
03922af3 | 732 | |
9771b263 | 733 | if (SESE_PARAMS (SCOP_REGION (scop)).length ()) |
40bf935e SP |
734 | { |
735 | if (verbosity > 0) | |
736 | fprintf (file, "# Parameter names are provided\n"); | |
737 | ||
738 | fprintf (file, "1\n"); | |
739 | ||
740 | if (verbosity > 0) | |
741 | fprintf (file, "# Parameter names\n"); | |
742 | } | |
03922af3 | 743 | else |
40bf935e SP |
744 | { |
745 | if (verbosity > 0) | |
746 | fprintf (file, "# Parameter names are not provided\n"); | |
747 | fprintf (file, "0\n"); | |
748 | } | |
03922af3 | 749 | |
9771b263 | 750 | FOR_EACH_VEC_ELT (SESE_PARAMS (SCOP_REGION (scop)), i, t) |
2abae5f1 | 751 | { |
2abae5f1 | 752 | print_generic_expr (file, t, 0); |
730a9846 | 753 | fprintf (file, " "); |
2abae5f1 | 754 | } |
40bf935e SP |
755 | |
756 | fprintf (file, "\n"); | |
757 | ||
758 | if (verbosity > 1) | |
759 | fprintf (file, "#)\n"); | |
2abae5f1 SP |
760 | } |
761 | ||
ae403f5a RB |
762 | /* Print to FILE the context of SCoP in OpenScop format, at some VERBOSITY |
763 | level. */ | |
764 | ||
765 | static void | |
766 | openscop_print_scop_context (FILE *file, scop_p scop, int verbosity) | |
767 | { | |
768 | graphite_dim_t i; | |
769 | ||
770 | if (verbosity > 0) | |
771 | { | |
772 | fprintf (file, "# Context (\n"); | |
7241f8c5 | 773 | fprintf (file, "#eq"); |
ae403f5a RB |
774 | |
775 | for (i = 0; i < scop_nb_params (scop); i++) | |
776 | fprintf (file, " p%d", (int) i); | |
777 | ||
778 | fprintf (file, " cst\n"); | |
779 | } | |
780 | ||
33ad93b9 RG |
781 | if (scop->context) |
782 | /* XXX isl print context */ | |
783 | fprintf (file, "XXX isl\n"); | |
ae403f5a RB |
784 | else |
785 | fprintf (file, "0 %d 0 0 0 %d\n", (int) scop_nb_params (scop) + 2, | |
786 | (int) scop_nb_params (scop)); | |
787 | ||
788 | if (verbosity > 0) | |
789 | fprintf (file, "# )\n"); | |
790 | } | |
791 | ||
40bf935e SP |
792 | /* Print to FILE the context of SCoP, at some VERBOSITY level. */ |
793 | ||
2abae5f1 | 794 | void |
40bf935e | 795 | print_scop_context (FILE *file, scop_p scop, int verbosity) |
2abae5f1 SP |
796 | { |
797 | graphite_dim_t i; | |
798 | ||
40bf935e SP |
799 | if (verbosity > 0) |
800 | { | |
801 | fprintf (file, "# Context (\n"); | |
7241f8c5 | 802 | fprintf (file, "#eq"); |
2abae5f1 | 803 | |
40bf935e SP |
804 | for (i = 0; i < scop_nb_params (scop); i++) |
805 | fprintf (file, " p%d", (int) i); | |
2abae5f1 | 806 | |
40bf935e SP |
807 | fprintf (file, " cst\n"); |
808 | } | |
2abae5f1 | 809 | |
33ad93b9 RG |
810 | if (scop->context) |
811 | print_isl_set (file, scop->context); | |
03922af3 | 812 | else |
33ad93b9 | 813 | fprintf (file, "no isl context %d\n", (int) scop_nb_params (scop) + 2); |
2abae5f1 | 814 | |
40bf935e SP |
815 | if (verbosity > 0) |
816 | fprintf (file, "# )\n"); | |
2abae5f1 SP |
817 | } |
818 | ||
0ba82567 | 819 | /* Print to FILE the SCOP, at some VERBOSITY level. */ |
2abae5f1 | 820 | |
0ba82567 SP |
821 | void |
822 | print_scop (FILE *file, scop_p scop, int verbosity) | |
2abae5f1 | 823 | { |
0ba82567 SP |
824 | int i; |
825 | poly_bb_p pbb; | |
826 | ||
ae403f5a | 827 | fprintf (file, "SCoP 1\n#(\n"); |
03922af3 | 828 | fprintf (file, "# Language\nGimple\n"); |
ae403f5a | 829 | openscop_print_scop_context (file, scop, verbosity); |
40bf935e SP |
830 | print_scop_params (file, scop, verbosity); |
831 | ||
832 | if (verbosity > 0) | |
833 | fprintf (file, "# Number of statements\n"); | |
834 | ||
9771b263 | 835 | fprintf (file, "%d\n", SCOP_BBS (scop).length ()); |
2abae5f1 | 836 | |
9771b263 | 837 | FOR_EACH_VEC_ELT (SCOP_BBS (scop), i, pbb) |
40bf935e | 838 | print_pbb (file, pbb, verbosity); |
e31a5bd4 | 839 | |
40bf935e SP |
840 | if (verbosity > 1) |
841 | { | |
842 | fprintf (file, "# original_lst (\n"); | |
843 | print_lst (file, SCOP_ORIGINAL_SCHEDULE (scop), 0); | |
844 | fprintf (file, "\n#)\n"); | |
a36d12e2 | 845 | |
40bf935e SP |
846 | fprintf (file, "# transformed_lst (\n"); |
847 | print_lst (file, SCOP_TRANSFORMED_SCHEDULE (scop), 0); | |
848 | fprintf (file, "\n#)\n"); | |
849 | } | |
f58be90e | 850 | |
03922af3 | 851 | fprintf (file, "#)\n"); |
2abae5f1 SP |
852 | } |
853 | ||
40bf935e | 854 | /* Print to STDERR the domain of PBB, at some VERBOSITY level. */ |
2abae5f1 | 855 | |
24e47c76 | 856 | DEBUG_FUNCTION void |
40bf935e | 857 | debug_pbb_domain (poly_bb_p pbb, int verbosity) |
2abae5f1 | 858 | { |
40bf935e | 859 | print_pbb_domain (stderr, pbb, verbosity); |
2abae5f1 SP |
860 | } |
861 | ||
40bf935e SP |
862 | /* Print to FILE the domain and scattering function of PBB, at some |
863 | VERBOSITY level. */ | |
2abae5f1 | 864 | |
24e47c76 | 865 | DEBUG_FUNCTION void |
40bf935e | 866 | debug_pbb (poly_bb_p pbb, int verbosity) |
2abae5f1 | 867 | { |
40bf935e | 868 | print_pbb (stderr, pbb, verbosity); |
2abae5f1 SP |
869 | } |
870 | ||
40bf935e | 871 | /* Print to STDERR the context of SCOP, at some VERBOSITY level. */ |
2abae5f1 | 872 | |
24e47c76 | 873 | DEBUG_FUNCTION void |
40bf935e | 874 | debug_scop_context (scop_p scop, int verbosity) |
2abae5f1 | 875 | { |
40bf935e | 876 | print_scop_context (stderr, scop, verbosity); |
2abae5f1 SP |
877 | } |
878 | ||
40bf935e | 879 | /* Print to STDERR the SCOP, at some VERBOSITY level. */ |
2abae5f1 | 880 | |
24e47c76 | 881 | DEBUG_FUNCTION void |
40bf935e | 882 | debug_scop (scop_p scop, int verbosity) |
2abae5f1 | 883 | { |
40bf935e | 884 | print_scop (stderr, scop, verbosity); |
2abae5f1 SP |
885 | } |
886 | ||
40bf935e SP |
887 | /* Print to STDERR the parameters of SCOP, at some VERBOSITY |
888 | level. */ | |
2abae5f1 | 889 | |
24e47c76 | 890 | DEBUG_FUNCTION void |
40bf935e | 891 | debug_scop_params (scop_p scop, int verbosity) |
2abae5f1 | 892 | { |
40bf935e | 893 | print_scop_params (stderr, scop, verbosity); |
2abae5f1 SP |
894 | } |
895 | ||
33ad93b9 RG |
896 | extern isl_ctx *the_isl_ctx; |
897 | void | |
898 | print_isl_set (FILE *f, isl_set *set) | |
2abae5f1 | 899 | { |
33ad93b9 RG |
900 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); |
901 | p = isl_printer_print_set (p, set); | |
902 | isl_printer_free (p); | |
903 | } | |
2abae5f1 | 904 | |
33ad93b9 RG |
905 | DEBUG_FUNCTION void |
906 | debug_isl_set (isl_set *set) | |
907 | { | |
908 | print_isl_set (stderr, set); | |
909 | } | |
2abae5f1 | 910 | |
33ad93b9 RG |
911 | void |
912 | print_isl_map (FILE *f, isl_map *map) | |
913 | { | |
914 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
915 | p = isl_printer_print_map (p, map); | |
916 | isl_printer_free (p); | |
917 | } | |
2abae5f1 | 918 | |
33ad93b9 RG |
919 | DEBUG_FUNCTION void |
920 | debug_isl_map (isl_map *map) | |
921 | { | |
922 | print_isl_map (stderr, map); | |
923 | } | |
2abae5f1 | 924 | |
33ad93b9 RG |
925 | void |
926 | print_isl_aff (FILE *f, isl_aff *aff) | |
927 | { | |
928 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
929 | p = isl_printer_print_aff (p, aff); | |
930 | isl_printer_free (p); | |
931 | } | |
2abae5f1 | 932 | |
33ad93b9 RG |
933 | DEBUG_FUNCTION void |
934 | debug_isl_aff (isl_aff *aff) | |
935 | { | |
936 | print_isl_aff (stderr, aff); | |
937 | } | |
2abae5f1 | 938 | |
33ad93b9 RG |
939 | void |
940 | print_isl_constraint (FILE *f, isl_constraint *c) | |
941 | { | |
942 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
943 | p = isl_printer_print_constraint (p, c); | |
944 | isl_printer_free (p); | |
945 | } | |
2abae5f1 | 946 | |
33ad93b9 RG |
947 | DEBUG_FUNCTION void |
948 | debug_isl_constraint (isl_constraint *c) | |
949 | { | |
950 | print_isl_constraint (stderr, c); | |
2abae5f1 SP |
951 | } |
952 | ||
26ccb556 | 953 | /* Returns the number of iterations RES of the loop around PBB at |
baf4b881 KT |
954 | time(scattering) dimension TIME_DEPTH. */ |
955 | ||
956 | void | |
957 | pbb_number_of_iterations_at_time (poly_bb_p pbb, | |
958 | graphite_dim_t time_depth, | |
26ccb556 | 959 | mpz_t res) |
baf4b881 | 960 | { |
33ad93b9 RG |
961 | isl_set *transdomain; |
962 | isl_space *dc; | |
963 | isl_aff *aff; | |
b47595f7 | 964 | isl_val *isllb, *islub; |
2b7c09a8 | 965 | |
33ad93b9 RG |
966 | /* Map the iteration domain through the current scatter, and work |
967 | on the resulting set. */ | |
968 | transdomain = isl_set_apply (isl_set_copy (pbb->domain), | |
969 | isl_map_copy (pbb->transformed)); | |
2b7c09a8 | 970 | |
33ad93b9 RG |
971 | /* Select the time_depth' dimension via an affine expression. */ |
972 | dc = isl_set_get_space (transdomain); | |
973 | aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); | |
974 | aff = isl_aff_set_coefficient_si (aff, isl_dim_in, time_depth, 1); | |
aad78a1a | 975 | |
33ad93b9 RG |
976 | /* And find the min/max for that function. */ |
977 | /* XXX isl check results? */ | |
b47595f7 MN |
978 | isllb = isl_set_min_val (transdomain, aff); |
979 | islub = isl_set_max_val (transdomain, aff); | |
2b7c09a8 | 980 | |
b47595f7 MN |
981 | islub = isl_val_sub (islub, isllb); |
982 | islub = isl_val_add_ui (islub, 1); | |
983 | isl_val_get_num_gmp (islub, res); | |
baf4b881 | 984 | |
b47595f7 | 985 | isl_val_free (islub); |
33ad93b9 RG |
986 | isl_aff_free (aff); |
987 | isl_set_free (transdomain); | |
baf4b881 KT |
988 | } |
989 | ||
a36d12e2 SP |
990 | /* Translates LOOP to LST. */ |
991 | ||
992 | static lst_p | |
9771b263 | 993 | loop_to_lst (loop_p loop, vec<poly_bb_p> bbs, int *i) |
a36d12e2 SP |
994 | { |
995 | poly_bb_p pbb; | |
9771b263 DN |
996 | vec<lst_p> seq; |
997 | seq.create (5); | |
a36d12e2 | 998 | |
9771b263 | 999 | for (; bbs.iterate (*i, &pbb); (*i)++) |
a36d12e2 SP |
1000 | { |
1001 | lst_p stmt; | |
1002 | basic_block bb = GBB_BB (PBB_BLACK_BOX (pbb)); | |
1003 | ||
1004 | if (bb->loop_father == loop) | |
1005 | stmt = new_lst_stmt (pbb); | |
c0fe753b | 1006 | else if (flow_bb_inside_loop_p (loop, bb)) |
a36d12e2 | 1007 | { |
c0fe753b | 1008 | loop_p next = loop->inner; |
a36d12e2 | 1009 | |
c0fe753b SP |
1010 | while (next && !flow_bb_inside_loop_p (next, bb)) |
1011 | next = next->next; | |
a36d12e2 | 1012 | |
c0fe753b SP |
1013 | stmt = loop_to_lst (next, bbs, i); |
1014 | } | |
1015 | else | |
1016 | { | |
1017 | (*i)--; | |
1018 | return new_lst_loop (seq); | |
a36d12e2 SP |
1019 | } |
1020 | ||
9771b263 | 1021 | seq.safe_push (stmt); |
a36d12e2 SP |
1022 | } |
1023 | ||
1024 | return new_lst_loop (seq); | |
1025 | } | |
1026 | ||
1027 | /* Reads the original scattering of the SCOP and returns an LST | |
1028 | representing it. */ | |
1029 | ||
1030 | void | |
1031 | scop_to_lst (scop_p scop) | |
1032 | { | |
5c6c42c9 | 1033 | lst_p res; |
9771b263 DN |
1034 | int i, n = SCOP_BBS (scop).length (); |
1035 | vec<lst_p> seq; | |
1036 | seq.create (5); | |
5c6c42c9 SP |
1037 | sese region = SCOP_REGION (scop); |
1038 | ||
1039 | for (i = 0; i < n; i++) | |
1040 | { | |
9771b263 | 1041 | poly_bb_p pbb = SCOP_BBS (scop)[i]; |
5c6c42c9 SP |
1042 | loop_p loop = outermost_loop_in_sese (region, GBB_BB (PBB_BLACK_BOX (pbb))); |
1043 | ||
1044 | if (loop_in_sese_p (loop, region)) | |
1045 | res = loop_to_lst (loop, SCOP_BBS (scop), &i); | |
1046 | else | |
1047 | res = new_lst_stmt (pbb); | |
1048 | ||
9771b263 | 1049 | seq.safe_push (res); |
5c6c42c9 | 1050 | } |
a36d12e2 | 1051 | |
5c6c42c9 SP |
1052 | res = new_lst_loop (seq); |
1053 | SCOP_ORIGINAL_SCHEDULE (scop) = res; | |
1054 | SCOP_TRANSFORMED_SCHEDULE (scop) = copy_lst (res); | |
a36d12e2 SP |
1055 | } |
1056 | ||
03922af3 SP |
1057 | /* Print to FILE on a new line COLUMN white spaces. */ |
1058 | ||
1059 | static void | |
1060 | lst_indent_to (FILE *file, int column) | |
1061 | { | |
1062 | int i; | |
1063 | ||
1064 | if (column > 0) | |
1065 | fprintf (file, "\n#"); | |
1066 | ||
1067 | for (i = 0; i < column; i++) | |
1068 | fprintf (file, " "); | |
1069 | } | |
1070 | ||
a36d12e2 SP |
1071 | /* Print LST to FILE with INDENT spaces of indentation. */ |
1072 | ||
1073 | void | |
1074 | print_lst (FILE *file, lst_p lst, int indent) | |
1075 | { | |
1076 | if (!lst) | |
1077 | return; | |
1078 | ||
03922af3 | 1079 | lst_indent_to (file, indent); |
a36d12e2 SP |
1080 | |
1081 | if (LST_LOOP_P (lst)) | |
1082 | { | |
1083 | int i; | |
1084 | lst_p l; | |
1085 | ||
5c6c42c9 SP |
1086 | if (LST_LOOP_FATHER (lst)) |
1087 | fprintf (file, "%d (loop", lst_dewey_number (lst)); | |
1088 | else | |
03922af3 | 1089 | fprintf (file, "#(root"); |
a36d12e2 | 1090 | |
9771b263 | 1091 | FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l) |
a36d12e2 SP |
1092 | print_lst (file, l, indent + 2); |
1093 | ||
1094 | fprintf (file, ")"); | |
1095 | } | |
1096 | else | |
1097 | fprintf (file, "%d stmt_%d", lst_dewey_number (lst), pbb_index (LST_PBB (lst))); | |
1098 | } | |
1099 | ||
1100 | /* Print LST to STDERR. */ | |
1101 | ||
24e47c76 | 1102 | DEBUG_FUNCTION void |
a36d12e2 SP |
1103 | debug_lst (lst_p lst) |
1104 | { | |
1105 | print_lst (stderr, lst, 0); | |
1106 | } | |
1107 | ||
bfa00f48 SP |
1108 | /* Pretty print to FILE the loop statement tree LST in DOT format. */ |
1109 | ||
1110 | static void | |
1111 | dot_lst_1 (FILE *file, lst_p lst) | |
1112 | { | |
1113 | if (!lst) | |
1114 | return; | |
1115 | ||
1116 | if (LST_LOOP_P (lst)) | |
1117 | { | |
1118 | int i; | |
1119 | lst_p l; | |
1120 | ||
1121 | if (!LST_LOOP_FATHER (lst)) | |
1122 | fprintf (file, "L -> L_%d_%d\n", | |
1123 | lst_depth (lst), | |
1124 | lst_dewey_number (lst)); | |
1125 | else | |
1126 | fprintf (file, "L_%d_%d -> L_%d_%d\n", | |
1127 | lst_depth (LST_LOOP_FATHER (lst)), | |
1128 | lst_dewey_number (LST_LOOP_FATHER (lst)), | |
1129 | lst_depth (lst), | |
1130 | lst_dewey_number (lst)); | |
1131 | ||
9771b263 | 1132 | FOR_EACH_VEC_ELT (LST_SEQ (lst), i, l) |
bfa00f48 SP |
1133 | dot_lst_1 (file, l); |
1134 | } | |
1135 | ||
1136 | else | |
1137 | fprintf (file, "L_%d_%d -> S_%d\n", | |
1138 | lst_depth (LST_LOOP_FATHER (lst)), | |
1139 | lst_dewey_number (LST_LOOP_FATHER (lst)), | |
1140 | pbb_index (LST_PBB (lst))); | |
1141 | ||
1142 | } | |
1143 | ||
1144 | /* Display the LST using dotty. */ | |
1145 | ||
1f424006 | 1146 | DEBUG_FUNCTION void |
bfa00f48 SP |
1147 | dot_lst (lst_p lst) |
1148 | { | |
1149 | /* When debugging, enable the following code. This cannot be used | |
1150 | in production compilers because it calls "system". */ | |
1151 | #if 0 | |
bfa00f48 SP |
1152 | FILE *stream = fopen ("/tmp/lst.dot", "w"); |
1153 | gcc_assert (stream); | |
1154 | ||
1155 | fputs ("digraph all {\n", stream); | |
1156 | dot_lst_1 (stream, lst); | |
1157 | fputs ("}\n\n", stream); | |
1158 | fclose (stream); | |
1159 | ||
1635d7b0 | 1160 | system ("dotty /tmp/lst.dot &"); |
bfa00f48 SP |
1161 | #else |
1162 | fputs ("digraph all {\n", stderr); | |
1163 | dot_lst_1 (stderr, lst); | |
1164 | fputs ("}\n\n", stderr); | |
1165 | ||
1166 | #endif | |
1167 | } | |
1168 | ||
33ad93b9 RG |
1169 | /* Reverse the loop around PBB at level DEPTH. */ |
1170 | ||
1171 | isl_map * | |
1172 | reverse_loop_at_level (poly_bb_p pbb, int depth) | |
1173 | { | |
1174 | unsigned i, depth_dim = psct_dynamic_dim (pbb, depth); | |
1175 | isl_space *d = isl_map_get_space (pbb->transformed); | |
1176 | isl_space *d1 = isl_space_range (d); | |
1177 | unsigned n = isl_space_dim (d1, isl_dim_out); | |
1178 | isl_space *d2 = isl_space_add_dims (d1, isl_dim_in, n); | |
1179 | isl_map *x = isl_map_universe (isl_space_copy (d2)); | |
1180 | isl_constraint *c = isl_equality_alloc (isl_local_space_from_space (d2)); | |
1181 | ||
1182 | for (i = 0; i < n; i++) | |
1183 | if (i != depth_dim) | |
1184 | x = isl_map_equate (x, isl_dim_in, i, isl_dim_out, i); | |
1185 | ||
1186 | c = isl_constraint_set_coefficient_si (c, isl_dim_in, depth_dim, 1); | |
1187 | c = isl_constraint_set_coefficient_si (c, isl_dim_out, depth_dim, 1); | |
1188 | x = isl_map_add_constraint (x, c); | |
1189 | return x; | |
1190 | } | |
1191 | ||
1192 | /* Reverse the loop at level DEPTH for all the PBBS. */ | |
1193 | ||
1194 | isl_union_map * | |
9771b263 | 1195 | reverse_loop_for_pbbs (scop_p scop, vec<poly_bb_p> pbbs, int depth) |
33ad93b9 RG |
1196 | { |
1197 | poly_bb_p pbb; | |
1198 | int i; | |
1199 | isl_space *space = isl_space_from_domain (isl_set_get_space (scop->context)); | |
1200 | isl_union_map *res = isl_union_map_empty (space); | |
1201 | ||
9771b263 | 1202 | for (i = 0; pbbs.iterate (i, &pbb); i++) |
33ad93b9 RG |
1203 | res = isl_union_map_add_map (res, reverse_loop_at_level (pbb, depth)); |
1204 | ||
1205 | return res; | |
1206 | } | |
1207 | ||
1208 | ||
2abae5f1 SP |
1209 | #endif |
1210 |