2 * Copyright 2010-2011 INRIA Saclay
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7 * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
17 #include <isl/constraint.h>
22 /* Add parameters with identifiers "ids" to "set".
24 static __isl_give isl_set
*add_params(__isl_take isl_set
*set
,
25 __isl_keep isl_id_list
*ids
)
30 n
= isl_id_list_n_id(ids
);
32 nparam
= isl_set_dim(set
, isl_dim_param
);
33 set
= isl_set_add_dims(set
, isl_dim_param
, n
);
35 for (i
= 0; i
< n
; ++i
) {
38 id
= isl_id_list_get_id(ids
, i
);
39 set
= isl_set_set_dim_id(set
, isl_dim_param
, nparam
+ i
, id
);
45 /* Equate the dimensions of "set" starting at "first" to
46 * freshly created parameters with identifiers "ids".
47 * The number of equated dimensions is equal to the number of elements in "ids".
49 static __isl_give isl_set
*parametrize(__isl_take isl_set
*set
,
50 int first
, __isl_keep isl_id_list
*ids
)
55 nparam
= isl_set_dim(set
, isl_dim_param
);
57 set
= add_params(set
, ids
);
59 n
= isl_id_list_n_id(ids
);
60 for (i
= 0; i
< n
; ++i
)
61 set
= isl_set_equate(set
, isl_dim_param
, nparam
+ i
,
62 isl_dim_set
, first
+ i
);
67 /* Given a parameter space "space", create a set of dimension "len"
68 * of which the dimensions starting at "first" are equated to
69 * freshly created parameters with identifiers "ids".
71 __isl_give isl_set
*parametrization(__isl_take isl_space
*space
,
72 int len
, int first
, __isl_keep isl_id_list
*ids
)
76 space
= isl_space_set_from_params(space
);
77 space
= isl_space_add_dims(space
, isl_dim_set
, len
);
78 set
= isl_set_universe(space
);
80 return parametrize(set
, first
, ids
);
83 /* Load and return a schedule from a file called "filename".
85 static __isl_give isl_schedule
*load_schedule(isl_ctx
*ctx
,
89 isl_schedule
*schedule
;
91 file
= fopen(filename
, "r");
93 fprintf(stderr
, "Unable to open '%s' for reading\n", filename
);
96 schedule
= isl_schedule_read_from_file(ctx
, file
);
102 /* Save the schedule "schedule" to a file called "filename".
103 * The schedule is printed in block style.
105 static void save_schedule(__isl_keep isl_schedule
*schedule
,
106 const char *filename
)
115 file
= fopen(filename
, "w");
117 fprintf(stderr
, "Unable to open '%s' for writing\n", filename
);
120 ctx
= isl_schedule_get_ctx(schedule
);
121 p
= isl_printer_to_file(ctx
, file
);
122 p
= isl_printer_set_yaml_style(p
, ISL_YAML_STYLE_BLOCK
);
123 p
= isl_printer_print_schedule(p
, schedule
);
128 /* Compute a schedule on the domain of "sc" that respects the schedule
129 * constraints in "sc", without trying to combine groups of statements.
131 __isl_give isl_schedule
*ppcg_compute_non_grouping_schedule(
132 __isl_take isl_schedule_constraints
*sc
, struct ppcg_options
*options
)
134 if (options
->debug
->dump_schedule_constraints
)
135 isl_schedule_constraints_dump(sc
);
136 return isl_schedule_constraints_compute_schedule(sc
);
139 /* Compute a schedule on the domain of "sc" that respects the schedule
140 * constraints in "sc".
142 * "schedule" is a known correct schedule that is used to combine
143 * groups of statements if options->group_chains is set.
145 __isl_give isl_schedule
*ppcg_compute_schedule(
146 __isl_take isl_schedule_constraints
*sc
,
147 __isl_keep isl_schedule
*schedule
, struct ppcg_options
*options
)
149 if (options
->group_chains
)
150 return ppcg_compute_grouping_schedule(sc
, schedule
, options
);
151 return ppcg_compute_non_grouping_schedule(sc
, options
);
154 /* Obtain a schedule, either by reading it form a file
155 * or by computing it using "compute".
156 * Also take care of saving the computed schedule and/or
157 * dumping the obtained schedule if requested by the user.
159 __isl_give isl_schedule
*ppcg_get_schedule(isl_ctx
*ctx
,
160 struct ppcg_options
*options
,
161 __isl_give isl_schedule
*(*compute
)(void *user
), void *user
)
163 isl_schedule
*schedule
;
165 if (options
->load_schedule_file
) {
166 schedule
= load_schedule(ctx
, options
->load_schedule_file
);
168 schedule
= compute(user
);
169 if (options
->save_schedule_file
)
170 save_schedule(schedule
, options
->save_schedule_file
);
172 if (options
->debug
->dump_schedule
)
173 isl_schedule_dump(schedule
);
178 /* Mark all dimensions in the band node "node" to be of "type".
180 __isl_give isl_schedule_node
*ppcg_set_schedule_node_type(
181 __isl_take isl_schedule_node
*node
, enum isl_ast_loop_type type
)
185 n
= isl_schedule_node_band_n_member(node
);
186 for (i
= 0; i
< n
; ++i
)
187 node
= isl_schedule_node_band_member_set_ast_loop_type(node
, i
,