]>
Commit | Line | Data |
---|---|---|
c6bb733d | 1 | /* Graphite polyhedral representation. |
d353bf18 | 2 | Copyright (C) 2009-2015 Free Software Foundation, Inc. |
c6bb733d | 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/>. */ | |
87e20041 | 21 | |
d8a2c81e | 22 | #define USES_ISL |
23 | ||
c6bb733d | 24 | #include "config.h" |
87e20041 | 25 | |
429cca51 | 26 | #ifdef HAVE_isl |
d8a2c81e | 27 | |
28 | #include "system.h" | |
29 | #include "coretypes.h" | |
30 | #include "backend.h" | |
31 | #include "tree.h" | |
32 | #include "gimple.h" | |
33 | #include "cfghooks.h" | |
34 | #include "gimple-pretty-print.h" | |
35 | #include "diagnostic-core.h" | |
36 | #include "fold-const.h" | |
37 | #include "gimple-iterator.h" | |
38 | #include "tree-ssa-loop.h" | |
39 | #include "cfgloop.h" | |
40 | #include "tree-data-ref.h" | |
40bdfbcc | 41 | |
a26dad6a | 42 | #include <isl/constraint.h> |
87e20041 | 43 | #include <isl/set.h> |
44 | #include <isl/map.h> | |
45 | #include <isl/union_map.h> | |
46 | #include <isl/constraint.h> | |
47 | #include <isl/ilp.h> | |
48 | #include <isl/aff.h> | |
ea48ac01 | 49 | #include <isl/val.h> |
f5627b55 | 50 | |
51 | /* Since ISL-0.13, the extern is in val_gmp.h. */ | |
52 | #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus) | |
ea48ac01 | 53 | extern "C" { |
54 | #endif | |
55 | #include <isl/val_gmp.h> | |
f5627b55 | 56 | #if !defined(HAVE_ISL_SCHED_CONSTRAINTS_COMPUTE_SCHEDULE) && defined(__cplusplus) |
ea48ac01 | 57 | } |
58 | #endif | |
87e20041 | 59 | |
c6bb733d | 60 | #include "graphite-poly.h" |
c6bb733d | 61 | |
63b03ccf | 62 | #define OPENSCOP_MAX_STRING 256 |
63 | ||
87e20041 | 64 | |
65 | /* Print to STDERR the GMP value VAL. */ | |
66 | ||
67 | DEBUG_FUNCTION void | |
68 | debug_gmp_value (mpz_t val) | |
69 | { | |
de2e6b8a | 70 | gmp_fprintf (stderr, "%Zd", val); |
87e20041 | 71 | } |
72 | ||
a765cde0 | 73 | /* Prints to FILE the iteration domain of PBB. */ |
c6bb733d | 74 | |
75 | void | |
a765cde0 | 76 | print_iteration_domain (FILE *file, poly_bb_p pbb) |
c6bb733d | 77 | { |
a765cde0 | 78 | print_pbb_domain (file, pbb); |
c6bb733d | 79 | } |
80 | ||
a765cde0 | 81 | /* Prints to FILE the iteration domains of every PBB of SCOP. */ |
c6bb733d | 82 | |
83 | void | |
a765cde0 | 84 | print_iteration_domains (FILE *file, scop_p scop) |
c6bb733d | 85 | { |
86 | int i; | |
87 | poly_bb_p pbb; | |
88 | ||
0e526381 | 89 | FOR_EACH_VEC_ELT (scop->pbbs, i, pbb) |
a765cde0 | 90 | print_iteration_domain (file, pbb); |
c6bb733d | 91 | } |
92 | ||
a765cde0 | 93 | /* Prints to STDERR the iteration domain of PBB. */ |
c6bb733d | 94 | |
4b987fac | 95 | DEBUG_FUNCTION void |
a765cde0 | 96 | debug_iteration_domain (poly_bb_p pbb) |
c6bb733d | 97 | { |
a765cde0 | 98 | print_iteration_domain (stderr, pbb); |
c6bb733d | 99 | } |
100 | ||
a765cde0 | 101 | /* Prints to STDERR the iteration domains of every PBB of SCOP. */ |
c6bb733d | 102 | |
4b987fac | 103 | DEBUG_FUNCTION void |
a765cde0 | 104 | debug_iteration_domains (scop_p scop) |
c6bb733d | 105 | { |
a765cde0 | 106 | print_iteration_domains (stderr, scop); |
c6bb733d | 107 | } |
108 | ||
109 | /* Apply graphite transformations to all the basic blocks of SCOP. */ | |
110 | ||
111 | bool | |
112 | apply_poly_transforms (scop_p scop) | |
113 | { | |
114 | bool transform_done = false; | |
63b03ccf | 115 | |
c6bb733d | 116 | /* Generate code even if we did not apply any real transformation. |
117 | This also allows to check the performance for the identity | |
4cc0f4e2 | 118 | transformation: GIMPLE -> GRAPHITE -> GIMPLE. */ |
c6bb733d | 119 | if (flag_graphite_identity) |
120 | transform_done = true; | |
121 | ||
16848556 | 122 | if (flag_loop_parallelize_all) |
c6bb733d | 123 | transform_done = true; |
124 | ||
a5bc39b7 | 125 | if (flag_loop_optimize_isl) |
89049f25 | 126 | transform_done |= optimize_isl (scop); |
127 | ||
c6bb733d | 128 | return transform_done; |
129 | } | |
130 | ||
85f74b79 | 131 | /* Create a new polyhedral data reference and add it to PBB. It is |
132 | defined by its ACCESSES, its TYPE, and the number of subscripts | |
133 | NB_SUBSCRIPTS. */ | |
c6bb733d | 134 | |
135 | void | |
30162daa | 136 | new_poly_dr (poly_bb_p pbb, gimple *stmt, enum poly_dr_type type, |
fc25c670 | 137 | isl_map *acc, isl_set *subscript_sizes) |
c6bb733d | 138 | { |
96b6d5d7 | 139 | static int id = 0; |
9e3531b5 | 140 | poly_dr_p pdr = XNEW (struct poly_dr); |
c6bb733d | 141 | |
30162daa | 142 | pdr->stmt = stmt; |
96b6d5d7 | 143 | PDR_ID (pdr) = id++; |
11b2102e | 144 | PDR_NB_REFS (pdr) = 1; |
c6bb733d | 145 | PDR_PBB (pdr) = pbb; |
87e20041 | 146 | pdr->accesses = acc; |
fc25c670 | 147 | pdr->subscript_sizes = subscript_sizes; |
c6bb733d | 148 | PDR_TYPE (pdr) = type; |
f1f41a6c | 149 | PBB_DRS (pbb).safe_push (pdr); |
c6bb733d | 150 | } |
151 | ||
152 | /* Free polyhedral data reference PDR. */ | |
153 | ||
154 | void | |
155 | free_poly_dr (poly_dr_p pdr) | |
156 | { | |
87e20041 | 157 | isl_map_free (pdr->accesses); |
fc25c670 | 158 | isl_set_free (pdr->subscript_sizes); |
c6bb733d | 159 | XDELETE (pdr); |
160 | } | |
161 | ||
162 | /* Create a new polyhedral black box. */ | |
163 | ||
8c6b3774 | 164 | poly_bb_p |
3b9ce1aa | 165 | new_poly_bb (scop_p scop, gimple_poly_bb_p black_box) |
c6bb733d | 166 | { |
167 | poly_bb_p pbb = XNEW (struct poly_bb); | |
168 | ||
87e20041 | 169 | pbb->domain = NULL; |
170 | pbb->schedule = NULL; | |
171 | pbb->transformed = NULL; | |
172 | pbb->saved = NULL; | |
c6bb733d | 173 | PBB_SCOP (pbb) = scop; |
174 | pbb_set_black_box (pbb, black_box); | |
f1f41a6c | 175 | PBB_DRS (pbb).create (3); |
8c6b3774 | 176 | PBB_IS_REDUCTION (pbb) = false; |
e0c0be18 | 177 | GBB_PBB ((gimple_poly_bb_p) black_box) = pbb; |
8c6b3774 | 178 | |
179 | return pbb; | |
c6bb733d | 180 | } |
181 | ||
182 | /* Free polyhedral black box. */ | |
183 | ||
184 | void | |
185 | free_poly_bb (poly_bb_p pbb) | |
186 | { | |
187 | int i; | |
188 | poly_dr_p pdr; | |
189 | ||
87e20041 | 190 | isl_set_free (pbb->domain); |
191 | isl_map_free (pbb->schedule); | |
192 | isl_map_free (pbb->transformed); | |
193 | isl_map_free (pbb->saved); | |
c6bb733d | 194 | |
f1f41a6c | 195 | if (PBB_DRS (pbb).exists ()) |
196 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) | |
c6bb733d | 197 | free_poly_dr (pdr); |
198 | ||
f1f41a6c | 199 | PBB_DRS (pbb).release (); |
c6bb733d | 200 | XDELETE (pbb); |
201 | } | |
202 | ||
a765cde0 | 203 | /* Prints to FILE the polyhedral data reference PDR. */ |
c6bb733d | 204 | |
205 | void | |
a765cde0 | 206 | print_pdr (FILE *file, poly_dr_p pdr) |
c6bb733d | 207 | { |
a765cde0 | 208 | fprintf (file, "pdr_%d (", PDR_ID (pdr)); |
c6bb733d | 209 | |
a765cde0 | 210 | switch (PDR_TYPE (pdr)) |
211 | { | |
212 | case PDR_READ: | |
213 | fprintf (file, "read \n"); | |
214 | break; | |
c6bb733d | 215 | |
a765cde0 | 216 | case PDR_WRITE: |
217 | fprintf (file, "write \n"); | |
218 | break; | |
c6bb733d | 219 | |
a765cde0 | 220 | case PDR_MAY_WRITE: |
221 | fprintf (file, "may_write \n"); | |
222 | break; | |
ff4c7a5a | 223 | |
a765cde0 | 224 | default: |
225 | gcc_unreachable (); | |
c6bb733d | 226 | } |
227 | ||
30162daa | 228 | fprintf (file, "in gimple stmt: "); |
229 | print_gimple_stmt (file, pdr->stmt, 0, 0); | |
a765cde0 | 230 | fprintf (file, "data accesses: "); |
231 | print_isl_map (file, pdr->accesses); | |
232 | fprintf (file, "subscript sizes: "); | |
233 | print_isl_set (file, pdr->subscript_sizes); | |
234 | fprintf (file, ")\n"); | |
c6bb733d | 235 | } |
236 | ||
a765cde0 | 237 | /* Prints to STDERR the polyhedral data reference PDR. */ |
c6bb733d | 238 | |
4b987fac | 239 | DEBUG_FUNCTION void |
a765cde0 | 240 | debug_pdr (poly_dr_p pdr) |
c6bb733d | 241 | { |
a765cde0 | 242 | print_pdr (stderr, pdr); |
c6bb733d | 243 | } |
244 | ||
118a202b | 245 | /* Store the GRAPHITE representation of BB. */ |
246 | ||
247 | gimple_poly_bb_p | |
30162daa | 248 | new_gimple_poly_bb (basic_block bb, vec<data_reference_p> drs, |
249 | vec<scalar_use> reads, vec<tree> writes) | |
118a202b | 250 | { |
30162daa | 251 | gimple_poly_bb_p gbb = XNEW (struct gimple_poly_bb); |
118a202b | 252 | GBB_BB (gbb) = bb; |
253 | GBB_DATA_REFS (gbb) = drs; | |
30162daa | 254 | gbb->read_scalar_refs = reads; |
255 | gbb->write_scalar_refs = writes; | |
118a202b | 256 | GBB_CONDITIONS (gbb).create (0); |
257 | GBB_CONDITION_CASES (gbb).create (0); | |
258 | ||
259 | return gbb; | |
260 | } | |
261 | ||
118a202b | 262 | /* Frees GBB. */ |
263 | ||
264 | void | |
265 | free_gimple_poly_bb (gimple_poly_bb_p gbb) | |
266 | { | |
118a202b | 267 | free_data_refs (GBB_DATA_REFS (gbb)); |
118a202b | 268 | GBB_CONDITIONS (gbb).release (); |
269 | GBB_CONDITION_CASES (gbb).release (); | |
30162daa | 270 | gbb->read_scalar_refs.release (); |
271 | gbb->write_scalar_refs.release (); | |
118a202b | 272 | XDELETE (gbb); |
273 | } | |
274 | ||
275 | /* Deletes all gimple bbs in SCOP. */ | |
276 | ||
277 | static void | |
278 | remove_gbbs_in_scop (scop_p scop) | |
279 | { | |
280 | int i; | |
281 | poly_bb_p pbb; | |
282 | ||
0e526381 | 283 | FOR_EACH_VEC_ELT (scop->pbbs, i, pbb) |
118a202b | 284 | free_gimple_poly_bb (PBB_BLACK_BOX (pbb)); |
285 | } | |
286 | ||
287 | /* Creates a new SCOP containing the region (ENTRY, EXIT). */ | |
c6bb733d | 288 | |
289 | scop_p | |
118a202b | 290 | new_scop (edge entry, edge exit) |
c6bb733d | 291 | { |
f032380c | 292 | sese_info_p region = new_sese_info (entry, exit); |
c6bb733d | 293 | scop_p scop = XNEW (struct scop); |
294 | ||
3b9ce1aa | 295 | scop->param_context = NULL; |
87e20041 | 296 | scop->must_raw = NULL; |
297 | scop->may_raw = NULL; | |
298 | scop->must_raw_no_source = NULL; | |
299 | scop->may_raw_no_source = NULL; | |
300 | scop->must_war = NULL; | |
301 | scop->may_war = NULL; | |
302 | scop->must_war_no_source = NULL; | |
303 | scop->may_war_no_source = NULL; | |
304 | scop->must_waw = NULL; | |
305 | scop->may_waw = NULL; | |
306 | scop->must_waw_no_source = NULL; | |
307 | scop->may_waw_no_source = NULL; | |
c6bb733d | 308 | scop_set_region (scop, region); |
3c7086ac | 309 | scop->original_schedule = NULL; |
0e526381 | 310 | scop->pbbs.create (3); |
b1d20e3d | 311 | scop->drs.create (3); |
94bdcd77 | 312 | |
c6bb733d | 313 | return scop; |
314 | } | |
315 | ||
316 | /* Deletes SCOP. */ | |
317 | ||
318 | void | |
319 | free_scop (scop_p scop) | |
320 | { | |
321 | int i; | |
322 | poly_bb_p pbb; | |
323 | ||
118a202b | 324 | remove_gbbs_in_scop (scop); |
5828c94d | 325 | free_sese_info (scop->scop_info); |
118a202b | 326 | |
0e526381 | 327 | FOR_EACH_VEC_ELT (scop->pbbs, i, pbb) |
c6bb733d | 328 | free_poly_bb (pbb); |
329 | ||
0e526381 | 330 | scop->pbbs.release (); |
5e6359b9 | 331 | scop->drs.release (); |
c6bb733d | 332 | |
3b9ce1aa | 333 | isl_set_free (scop->param_context); |
87e20041 | 334 | isl_union_map_free (scop->must_raw); |
335 | isl_union_map_free (scop->may_raw); | |
336 | isl_union_map_free (scop->must_raw_no_source); | |
337 | isl_union_map_free (scop->may_raw_no_source); | |
338 | isl_union_map_free (scop->must_war); | |
339 | isl_union_map_free (scop->may_war); | |
340 | isl_union_map_free (scop->must_war_no_source); | |
341 | isl_union_map_free (scop->may_war_no_source); | |
342 | isl_union_map_free (scop->must_waw); | |
343 | isl_union_map_free (scop->may_waw); | |
344 | isl_union_map_free (scop->must_waw_no_source); | |
345 | isl_union_map_free (scop->may_waw_no_source); | |
3c7086ac | 346 | isl_union_map_free (scop->original_schedule); |
c6bb733d | 347 | XDELETE (scop); |
348 | } | |
349 | ||
a765cde0 | 350 | /* Print to FILE the domain of PBB. */ |
c6bb733d | 351 | |
352 | void | |
a765cde0 | 353 | print_pbb_domain (FILE *file, poly_bb_p pbb) |
c6bb733d | 354 | { |
87e20041 | 355 | print_isl_set (file, pbb->domain); |
c6bb733d | 356 | } |
357 | ||
358 | /* Dump the cases of a graphite basic block GBB on FILE. */ | |
359 | ||
360 | static void | |
e0c0be18 | 361 | dump_gbb_cases (FILE *file, gimple_poly_bb_p gbb) |
c6bb733d | 362 | { |
363 | int i; | |
42acab1c | 364 | gimple *stmt; |
365 | vec<gimple *> cases; | |
c6bb733d | 366 | |
367 | if (!gbb) | |
368 | return; | |
369 | ||
370 | cases = GBB_CONDITION_CASES (gbb); | |
f1f41a6c | 371 | if (cases.is_empty ()) |
c6bb733d | 372 | return; |
373 | ||
a765cde0 | 374 | fprintf (file, "cases bb_%d (\n", GBB_BB (gbb)->index); |
c6bb733d | 375 | |
f1f41a6c | 376 | FOR_EACH_VEC_ELT (cases, i, stmt) |
a765cde0 | 377 | print_gimple_stmt (file, stmt, 0, 0); |
c6bb733d | 378 | |
a765cde0 | 379 | fprintf (file, ")\n"); |
c6bb733d | 380 | } |
381 | ||
382 | /* Dump conditions of a graphite basic block GBB on FILE. */ | |
383 | ||
384 | static void | |
e0c0be18 | 385 | dump_gbb_conditions (FILE *file, gimple_poly_bb_p gbb) |
c6bb733d | 386 | { |
387 | int i; | |
42acab1c | 388 | gimple *stmt; |
389 | vec<gimple *> conditions; | |
c6bb733d | 390 | |
391 | if (!gbb) | |
392 | return; | |
393 | ||
394 | conditions = GBB_CONDITIONS (gbb); | |
f1f41a6c | 395 | if (conditions.is_empty ()) |
c6bb733d | 396 | return; |
397 | ||
a765cde0 | 398 | fprintf (file, "conditions bb_%d (\n", GBB_BB (gbb)->index); |
c6bb733d | 399 | |
f1f41a6c | 400 | FOR_EACH_VEC_ELT (conditions, i, stmt) |
a765cde0 | 401 | print_gimple_stmt (file, stmt, 0, 0); |
c6bb733d | 402 | |
a765cde0 | 403 | fprintf (file, ")\n"); |
c6bb733d | 404 | } |
405 | ||
a765cde0 | 406 | /* Print to FILE all the data references of PBB. */ |
c6bb733d | 407 | |
408 | void | |
a765cde0 | 409 | print_pdrs (FILE *file, poly_bb_p pbb) |
c6bb733d | 410 | { |
411 | int i; | |
412 | poly_dr_p pdr; | |
5dc5fe13 | 413 | int nb_reads = 0; |
414 | int nb_writes = 0; | |
c6bb733d | 415 | |
a765cde0 | 416 | if (PBB_DRS (pbb).is_empty ()) |
417 | return; | |
ff4c7a5a | 418 | |
a765cde0 | 419 | fprintf (file, "Data references (\n"); |
5dc5fe13 | 420 | |
f1f41a6c | 421 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 422 | if (PDR_TYPE (pdr) == PDR_READ) |
423 | nb_reads++; | |
424 | else | |
425 | nb_writes++; | |
426 | ||
a765cde0 | 427 | fprintf (file, "Read data references (\n"); |
ff4c7a5a | 428 | |
f1f41a6c | 429 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 430 | if (PDR_TYPE (pdr) == PDR_READ) |
a765cde0 | 431 | print_pdr (file, pdr); |
5dc5fe13 | 432 | |
a765cde0 | 433 | fprintf (file, ")\n"); |
434 | fprintf (file, "Write data references (\n"); | |
f1f41a6c | 435 | FOR_EACH_VEC_ELT (PBB_DRS (pbb), i, pdr) |
5dc5fe13 | 436 | if (PDR_TYPE (pdr) != PDR_READ) |
a765cde0 | 437 | print_pdr (file, pdr); |
438 | fprintf (file, ")\n"); | |
439 | fprintf (file, ")\n"); | |
c6bb733d | 440 | } |
441 | ||
442 | /* Print to STDERR all the data references of PBB. */ | |
443 | ||
4b987fac | 444 | DEBUG_FUNCTION void |
a765cde0 | 445 | debug_pdrs (poly_bb_p pbb) |
c6bb733d | 446 | { |
a765cde0 | 447 | print_pdrs (stderr, pbb); |
c6bb733d | 448 | } |
449 | ||
a765cde0 | 450 | /* Print to FILE the body of PBB. */ |
5dc5fe13 | 451 | |
452 | static void | |
a765cde0 | 453 | print_pbb_body (FILE *file, poly_bb_p pbb) |
5dc5fe13 | 454 | { |
a765cde0 | 455 | fprintf (file, "Body (\n"); |
35e5655c | 456 | dump_bb (file, pbb_bb (pbb), 0, 0); |
a765cde0 | 457 | fprintf (file, ")\n"); |
5dc5fe13 | 458 | } |
459 | ||
a765cde0 | 460 | /* Print to FILE the domain and scattering function of PBB. */ |
c6bb733d | 461 | |
462 | void | |
a765cde0 | 463 | print_pbb (FILE *file, poly_bb_p pbb) |
ff4c7a5a | 464 | { |
a765cde0 | 465 | fprintf (file, "pbb_%d (\n", pbb_index (pbb)); |
466 | dump_gbb_conditions (file, PBB_BLACK_BOX (pbb)); | |
467 | dump_gbb_cases (file, PBB_BLACK_BOX (pbb)); | |
ff4c7a5a | 468 | |
a765cde0 | 469 | print_pbb_domain (file, pbb); |
470 | print_pdrs (file, pbb); | |
471 | print_pbb_body (file, pbb); | |
ff4c7a5a | 472 | |
a765cde0 | 473 | fprintf (file, ")\n"); |
c6bb733d | 474 | } |
475 | ||
a765cde0 | 476 | /* Print to FILE the parameters of SCOP. */ |
c6bb733d | 477 | |
478 | void | |
a765cde0 | 479 | print_scop_params (FILE *file, scop_p scop) |
c6bb733d | 480 | { |
30162daa | 481 | if (scop->scop_info->params.is_empty ()) |
a765cde0 | 482 | return; |
483 | ||
c6bb733d | 484 | int i; |
485 | tree t; | |
a765cde0 | 486 | fprintf (file, "parameters ("); |
30162daa | 487 | FOR_EACH_VEC_ELT (scop->scop_info->params, i, t) |
c6bb733d | 488 | { |
c6bb733d | 489 | print_generic_expr (file, t, 0); |
a765cde0 | 490 | fprintf (file, ", "); |
c6bb733d | 491 | } |
a765cde0 | 492 | fprintf (file, ")\n"); |
c6bb733d | 493 | } |
494 | ||
a765cde0 | 495 | /* Print to FILE the context of SCoP. */ |
ff4c7a5a | 496 | |
c6bb733d | 497 | void |
a765cde0 | 498 | print_scop_context (FILE *file, scop_p scop) |
c6bb733d | 499 | { |
a765cde0 | 500 | if (!scop->param_context) |
501 | return; | |
c6bb733d | 502 | |
a765cde0 | 503 | fprintf (file, "Context (\n"); |
504 | print_isl_set (file, scop->param_context); | |
505 | fprintf (file, ")\n"); | |
c6bb733d | 506 | } |
507 | ||
a765cde0 | 508 | /* Print to FILE the SCOP. */ |
c6bb733d | 509 | |
d2cd543b | 510 | void |
a765cde0 | 511 | print_scop (FILE *file, scop_p scop) |
c6bb733d | 512 | { |
d2cd543b | 513 | int i; |
514 | poly_bb_p pbb; | |
515 | ||
a765cde0 | 516 | fprintf (file, "SCoP (\n"); |
517 | print_scop_context (file, scop); | |
518 | print_scop_params (file, scop); | |
ff4c7a5a | 519 | |
a765cde0 | 520 | fprintf (file, "Number of statements: "); |
0e526381 | 521 | fprintf (file, "%d\n", scop->pbbs.length ()); |
c6bb733d | 522 | |
0e526381 | 523 | FOR_EACH_VEC_ELT (scop->pbbs, i, pbb) |
a765cde0 | 524 | print_pbb (file, pbb); |
95b2e0d3 | 525 | |
a765cde0 | 526 | fprintf (file, ")\n"); |
c6bb733d | 527 | } |
528 | ||
a765cde0 | 529 | /* Print to STDERR the domain of PBB. */ |
c6bb733d | 530 | |
4b987fac | 531 | DEBUG_FUNCTION void |
a765cde0 | 532 | debug_pbb_domain (poly_bb_p pbb) |
c6bb733d | 533 | { |
a765cde0 | 534 | print_pbb_domain (stderr, pbb); |
c6bb733d | 535 | } |
536 | ||
a765cde0 | 537 | /* Print to FILE the domain and scattering function of PBB. */ |
c6bb733d | 538 | |
4b987fac | 539 | DEBUG_FUNCTION void |
a765cde0 | 540 | debug_pbb (poly_bb_p pbb) |
c6bb733d | 541 | { |
a765cde0 | 542 | print_pbb (stderr, pbb); |
c6bb733d | 543 | } |
544 | ||
a765cde0 | 545 | /* Print to STDERR the context of SCOP. */ |
c6bb733d | 546 | |
4b987fac | 547 | DEBUG_FUNCTION void |
a765cde0 | 548 | debug_scop_context (scop_p scop) |
c6bb733d | 549 | { |
a765cde0 | 550 | print_scop_context (stderr, scop); |
c6bb733d | 551 | } |
552 | ||
a765cde0 | 553 | /* Print to STDERR the SCOP. */ |
c6bb733d | 554 | |
4b987fac | 555 | DEBUG_FUNCTION void |
a765cde0 | 556 | debug_scop (scop_p scop) |
c6bb733d | 557 | { |
a765cde0 | 558 | print_scop (stderr, scop); |
c6bb733d | 559 | } |
560 | ||
a765cde0 | 561 | /* Print to STDERR the parameters of SCOP. */ |
c6bb733d | 562 | |
4b987fac | 563 | DEBUG_FUNCTION void |
a765cde0 | 564 | debug_scop_params (scop_p scop) |
c6bb733d | 565 | { |
a765cde0 | 566 | print_scop_params (stderr, scop); |
c6bb733d | 567 | } |
568 | ||
87e20041 | 569 | extern isl_ctx *the_isl_ctx; |
570 | void | |
571 | print_isl_set (FILE *f, isl_set *set) | |
c6bb733d | 572 | { |
87e20041 | 573 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); |
574 | p = isl_printer_print_set (p, set); | |
4cc0f4e2 | 575 | p = isl_printer_print_str (p, "\n"); |
87e20041 | 576 | isl_printer_free (p); |
577 | } | |
c6bb733d | 578 | |
87e20041 | 579 | DEBUG_FUNCTION void |
580 | debug_isl_set (isl_set *set) | |
581 | { | |
582 | print_isl_set (stderr, set); | |
583 | } | |
c6bb733d | 584 | |
87e20041 | 585 | void |
586 | print_isl_map (FILE *f, isl_map *map) | |
587 | { | |
588 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
589 | p = isl_printer_print_map (p, map); | |
4cc0f4e2 | 590 | p = isl_printer_print_str (p, "\n"); |
87e20041 | 591 | isl_printer_free (p); |
592 | } | |
c6bb733d | 593 | |
87e20041 | 594 | DEBUG_FUNCTION void |
595 | debug_isl_map (isl_map *map) | |
596 | { | |
597 | print_isl_map (stderr, map); | |
598 | } | |
c6bb733d | 599 | |
d9ac4c34 | 600 | void |
601 | print_isl_union_map (FILE *f, isl_union_map *map) | |
602 | { | |
603 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
604 | p = isl_printer_print_union_map (p, map); | |
605 | p = isl_printer_print_str (p, "\n"); | |
606 | isl_printer_free (p); | |
607 | } | |
608 | ||
609 | DEBUG_FUNCTION void | |
610 | debug_isl_union_map (isl_union_map *map) | |
611 | { | |
612 | print_isl_union_map (stderr, map); | |
613 | } | |
614 | ||
615 | ||
87e20041 | 616 | void |
617 | print_isl_aff (FILE *f, isl_aff *aff) | |
618 | { | |
619 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
620 | p = isl_printer_print_aff (p, aff); | |
4cc0f4e2 | 621 | p = isl_printer_print_str (p, "\n"); |
87e20041 | 622 | isl_printer_free (p); |
623 | } | |
c6bb733d | 624 | |
87e20041 | 625 | DEBUG_FUNCTION void |
626 | debug_isl_aff (isl_aff *aff) | |
627 | { | |
628 | print_isl_aff (stderr, aff); | |
629 | } | |
c6bb733d | 630 | |
87e20041 | 631 | void |
632 | print_isl_constraint (FILE *f, isl_constraint *c) | |
633 | { | |
634 | isl_printer *p = isl_printer_to_file (the_isl_ctx, f); | |
635 | p = isl_printer_print_constraint (p, c); | |
4cc0f4e2 | 636 | p = isl_printer_print_str (p, "\n"); |
87e20041 | 637 | isl_printer_free (p); |
638 | } | |
c6bb733d | 639 | |
87e20041 | 640 | DEBUG_FUNCTION void |
641 | debug_isl_constraint (isl_constraint *c) | |
642 | { | |
643 | print_isl_constraint (stderr, c); | |
c6bb733d | 644 | } |
645 | ||
bd432164 | 646 | /* Returns the number of iterations RES of the loop around PBB at |
ee0d08ad | 647 | time(scattering) dimension TIME_DEPTH. */ |
648 | ||
649 | void | |
650 | pbb_number_of_iterations_at_time (poly_bb_p pbb, | |
651 | graphite_dim_t time_depth, | |
bd432164 | 652 | mpz_t res) |
ee0d08ad | 653 | { |
87e20041 | 654 | isl_set *transdomain; |
655 | isl_space *dc; | |
656 | isl_aff *aff; | |
ea48ac01 | 657 | isl_val *isllb, *islub; |
d9e94834 | 658 | |
87e20041 | 659 | /* Map the iteration domain through the current scatter, and work |
660 | on the resulting set. */ | |
661 | transdomain = isl_set_apply (isl_set_copy (pbb->domain), | |
662 | isl_map_copy (pbb->transformed)); | |
d9e94834 | 663 | |
87e20041 | 664 | /* Select the time_depth' dimension via an affine expression. */ |
665 | dc = isl_set_get_space (transdomain); | |
666 | aff = isl_aff_zero_on_domain (isl_local_space_from_space (dc)); | |
667 | aff = isl_aff_set_coefficient_si (aff, isl_dim_in, time_depth, 1); | |
dd37d9f7 | 668 | |
87e20041 | 669 | /* And find the min/max for that function. */ |
670 | /* XXX isl check results? */ | |
ea48ac01 | 671 | isllb = isl_set_min_val (transdomain, aff); |
672 | islub = isl_set_max_val (transdomain, aff); | |
d9e94834 | 673 | |
ea48ac01 | 674 | islub = isl_val_sub (islub, isllb); |
675 | islub = isl_val_add_ui (islub, 1); | |
676 | isl_val_get_num_gmp (islub, res); | |
ee0d08ad | 677 | |
ea48ac01 | 678 | isl_val_free (islub); |
87e20041 | 679 | isl_aff_free (aff); |
680 | isl_set_free (transdomain); | |
ee0d08ad | 681 | } |
682 | ||
26bd1f19 | 683 | #endif /* HAVE_isl */ |
c6bb733d | 684 |