ppcg_kernel: remove fields referring to original grid size
[ppcg.git] / print.c
blob3025b360fe1e1956b7143b12c43a24da585884fc
1 /*
2 * Copyright 2012 Ecole Normale Superieure
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France
8 */
10 #include <isl/aff.h>
12 #include "print.h"
14 __isl_give isl_printer *ppcg_start_block(__isl_take isl_printer *p)
16 p = isl_printer_start_line(p);
17 p = isl_printer_print_str(p, "{");
18 p = isl_printer_end_line(p);
19 p = isl_printer_indent(p, 2);
20 return p;
23 __isl_give isl_printer *ppcg_end_block(__isl_take isl_printer *p)
25 p = isl_printer_indent(p, -2);
26 p = isl_printer_start_line(p);
27 p = isl_printer_print_str(p, "}");
28 p = isl_printer_end_line(p);
29 return p;
32 /* Print "extent" as a sequence of
34 * [1 + maximal_value]
36 * one for each dimension.
38 static __isl_give isl_printer *print_extent(__isl_take isl_printer *p,
39 __isl_keep isl_set *extent)
41 int i, n;
43 n = isl_set_dim(extent, isl_dim_set);
44 if (n == 0)
45 return p;
47 for (i = 0; i < n; ++i) {
48 isl_set *dom;
49 isl_local_space *ls;
50 isl_aff *one;
51 isl_pw_aff *bound;
53 bound = isl_set_dim_max(isl_set_copy(extent), i);
54 dom = isl_pw_aff_domain(isl_pw_aff_copy(bound));
55 ls = isl_local_space_from_space(isl_set_get_space(dom));
56 one = isl_aff_zero_on_domain(ls);
57 one = isl_aff_add_constant_si(one, 1);
58 bound = isl_pw_aff_add(bound, isl_pw_aff_alloc(dom, one));
60 p = isl_printer_print_str(p, "[");
61 p = isl_printer_print_pw_aff(p, bound);
62 p = isl_printer_print_str(p, "]");
64 isl_pw_aff_free(bound);
67 return p;
70 /* Print declarations for the arrays in "scop" that are declared
71 * and that are exposed (if exposed == 1) or not exposed (if exposed == 0).
73 static __isl_give isl_printer *print_declarations(__isl_take isl_printer *p,
74 struct ppcg_scop *scop, int exposed)
76 int i;
78 if (!scop)
79 return isl_printer_free(p);
81 for (i = 0; i < scop->n_array; ++i) {
82 struct pet_array *array = scop->arrays[i];
83 const char *name;
85 if (!array->declared)
86 continue;
87 if (array->exposed != exposed)
88 continue;
90 name = isl_set_get_tuple_name(array->extent);
92 p = isl_printer_start_line(p);
93 p = isl_printer_print_str(p, array->element_type);
94 p = isl_printer_print_str(p, " ");
95 p = isl_printer_print_str(p, name);
96 p = print_extent(p, array->extent);
97 p = isl_printer_print_str(p, ";");
98 p = isl_printer_end_line(p);
101 return p;
104 /* Print declarations for the arrays in "scop" that are declared
105 * and exposed to the code after the scop.
107 __isl_give isl_printer *ppcg_print_exposed_declarations(
108 __isl_take isl_printer *p, struct ppcg_scop *scop)
110 return print_declarations(p, scop, 1);
113 /* Print declarations for the arrays in "scop" that are declared,
114 * but not exposed to the code after the scop.
116 __isl_give isl_printer *ppcg_print_hidden_declarations(
117 __isl_take isl_printer *p, struct ppcg_scop *scop)
119 return print_declarations(p, scop, 0);