blob: 2583057348f5239933325bc7d35e270a9796d613 [file] [log] [blame]
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001//===- Schedule.cpp - Calculate an optimized schedule ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This pass the isl to calculate a schedule that is optimized for parallelism
11// and tileablility. The algorithm used in isl is an optimized version of the
12// algorithm described in following paper:
13//
14// U. Bondhugula, A. Hartono, J. Ramanujam, and P. Sadayappan.
15// A Practical Automatic Polyhedral Parallelizer and Locality Optimizer.
16// In Proceedings of the 2008 ACM SIGPLAN Conference On Programming Language
17// Design and Implementation, PLDI ’08, pages 101–113. ACM, 2008.
18//===----------------------------------------------------------------------===//
19
20#include "polly/Cloog.h"
21#include "polly/LinkAllPasses.h"
22
Tobias Grosserde68cc92011-06-30 20:01:02 +000023#include "polly/Support/GICHelper.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000024#include "polly/Dependences.h"
25#include "polly/ScopInfo.h"
26
Tobias Grosserf5338802011-10-06 00:03:35 +000027#include "isl/space.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000028#include "isl/map.h"
29#include "isl/constraint.h"
30#include "isl/schedule.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000031#include "isl/band.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000032
33#define DEBUG_TYPE "polly-optimize-isl"
34#include "llvm/Support/Debug.h"
Tobias Grosserc6699b72011-06-30 20:29:13 +000035#include "llvm/Support/CommandLine.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000036
37using namespace llvm;
38using namespace polly;
39
Tobias Grosserc6699b72011-06-30 20:29:13 +000040static cl::opt<bool>
Tobias Grosser353a2682011-10-23 20:59:26 +000041DisableTiling("polly-no-tiling",
42 cl::desc("Disable tiling in the isl scheduler"), cl::Hidden,
43 cl::init(false));
44
45static cl::opt<bool>
Tobias Grosser22636bf2011-10-23 20:59:29 +000046Prevector("polly-prevector",
47 cl::desc("Enable prevectorization in the isl scheduler"), cl::Hidden,
Tobias Grosserc6699b72011-06-30 20:29:13 +000048 cl::value_desc("Prevectorization enabled"),
49 cl::init(false));
50
Tobias Grosser30aa24c2011-05-14 19:02:06 +000051namespace {
52
Tobias Grosser73600b82011-10-08 00:30:40 +000053 class IslScheduleOptimizer : public ScopPass {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000054
55 public:
56 static char ID;
Tobias Grosser73600b82011-10-08 00:30:40 +000057 explicit IslScheduleOptimizer() : ScopPass(ID) {}
Tobias Grosser30aa24c2011-05-14 19:02:06 +000058
59 virtual bool runOnScop(Scop &S);
60 void printScop(llvm::raw_ostream &OS) const;
61 void getAnalysisUsage(AnalysisUsage &AU) const;
62 };
63
64}
65
Tobias Grosser73600b82011-10-08 00:30:40 +000066char IslScheduleOptimizer::ID = 0;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000067
68static int getSingleMap(__isl_take isl_map *map, void *user) {
69 isl_map **singleMap = (isl_map **) user;
70 *singleMap = map;
71
72 return 0;
73}
74
Tobias Grossercf3942d2011-10-06 00:04:05 +000075static void extendScattering(Scop &S, unsigned NewDimensions) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000076 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
Tobias Grossercf3942d2011-10-06 00:04:05 +000077 ScopStmt *Stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000078
Tobias Grossercf3942d2011-10-06 00:04:05 +000079 if (Stmt->isFinalRead())
Tobias Grosser30aa24c2011-05-14 19:02:06 +000080 continue;
81
Tobias Grossercf3942d2011-10-06 00:04:05 +000082 unsigned OldDimensions = Stmt->getNumScattering();
83 isl_space *Space;
84 isl_basic_map *ChangeScattering;
85
86 Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions);
87 ChangeScattering = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserf5338802011-10-06 00:03:35 +000088 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000089
Tobias Grossercf3942d2011-10-06 00:04:05 +000090 for (unsigned i = 0; i < OldDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000091 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000092 isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
93 isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);
Tobias Grossercf3942d2011-10-06 00:04:05 +000094 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000095 }
96
Tobias Grossercf3942d2011-10-06 00:04:05 +000097 for (unsigned i = OldDimensions; i < NewDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000098 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000099 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000100 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000101 }
102
Tobias Grossercf3942d2011-10-06 00:04:05 +0000103 isl_map *ChangeScatteringMap = isl_map_from_basic_map(ChangeScattering);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000104
Tobias Grossercf3942d2011-10-06 00:04:05 +0000105 ChangeScatteringMap = isl_map_align_params(ChangeScatteringMap,
106 S.getParamSpace());
107 isl_map *NewScattering = isl_map_apply_range(Stmt->getScattering(),
108 ChangeScatteringMap);
109 Stmt->setScattering(NewScattering);
Tobias Grosserf5338802011-10-06 00:03:35 +0000110 isl_local_space_free(LocalSpace);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000111 }
112}
113
Tobias Grosserde68cc92011-06-30 20:01:02 +0000114// getTileMap - Create a map that describes a n-dimensonal tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000115//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000116// getTileMap creates a map from a n-dimensional scattering space into an
117// 2*n-dimensional scattering space. The map describes a rectangular tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000118//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000119// Example:
120// scheduleDimensions = 2, parameterDimensions = 1, tileSize = 32
121//
122// tileMap := [p0] -> {[s0, s1] -> [t0, t1, s0, s1]:
123// t0 % 32 = 0 and t0 <= s0 < t0 + 32 and
124// t1 % 32 = 0 and t1 <= s1 < t1 + 32}
125//
126// Before tiling:
127//
128// for (i = 0; i < N; i++)
129// for (j = 0; j < M; j++)
130// S(i,j)
131//
132// After tiling:
133//
134// for (t_i = 0; t_i < N; i+=32)
135// for (t_j = 0; t_j < M; j+=32)
136// for (i = t_i; i < min(t_i + 32, N); i++) | Unknown that N % 32 = 0
137// for (j = t_j; j < t_j + 32; j++) | Known that M % 32 = 0
138// S(i,j)
139//
140static isl_basic_map *getTileMap(isl_ctx *ctx, int scheduleDimensions,
Tobias Grosserf5338802011-10-06 00:03:35 +0000141 isl_space *SpaceModel, int tileSize = 32) {
Tobias Grosserde68cc92011-06-30 20:01:02 +0000142 // We construct
143 //
144 // tileMap := [p0] -> {[s0, s1] -> [t0, t1, p0, p1, a0, a1]:
145 // s0 = a0 * 32 and s0 = p0 and t0 <= p0 < t0 + 32 and
146 // s1 = a1 * 32 and s1 = p1 and t1 <= p1 < t1 + 32}
147 //
148 // and project out the auxilary dimensions a0 and a1.
Tobias Grosserf5338802011-10-06 00:03:35 +0000149 isl_space *Space = isl_space_alloc(ctx, 0, scheduleDimensions,
150 scheduleDimensions * 3);
151 isl_basic_map *tileMap = isl_basic_map_universe(isl_space_copy(Space));
152
153 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000154
Tobias Grosserde68cc92011-06-30 20:01:02 +0000155 for (int x = 0; x < scheduleDimensions; x++) {
156 int sX = x;
157 int tX = x;
158 int pX = scheduleDimensions + x;
159 int aX = 2 * scheduleDimensions + x;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000160
Tobias Grosserde68cc92011-06-30 20:01:02 +0000161 isl_constraint *c;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000162
Tobias Grosserde68cc92011-06-30 20:01:02 +0000163 // sX = aX * tileSize;
Tobias Grosserf5338802011-10-06 00:03:35 +0000164 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000165 isl_constraint_set_coefficient_si(c, isl_dim_out, sX, 1);
166 isl_constraint_set_coefficient_si(c, isl_dim_out, aX, -tileSize);
167 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000168
Tobias Grosserde68cc92011-06-30 20:01:02 +0000169 // pX = sX;
Tobias Grosserf5338802011-10-06 00:03:35 +0000170 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000171 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
172 isl_constraint_set_coefficient_si(c, isl_dim_in, sX, -1);
173 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000174
Tobias Grosserde68cc92011-06-30 20:01:02 +0000175 // tX <= pX
Tobias Grosserf5338802011-10-06 00:03:35 +0000176 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000177 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
178 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, -1);
179 tileMap = isl_basic_map_add_constraint(tileMap, c);
180
181 // pX <= tX + (tileSize - 1)
Tobias Grosserf5338802011-10-06 00:03:35 +0000182 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000183 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, 1);
184 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, -1);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000185 isl_constraint_set_constant_si(c, tileSize - 1);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000186 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000187 }
188
Tobias Grosserde68cc92011-06-30 20:01:02 +0000189 // Project out auxilary dimensions.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000190 //
Tobias Grosserde68cc92011-06-30 20:01:02 +0000191 // The auxilary dimensions are transformed into existentially quantified ones.
192 // This reduces the number of visible scattering dimensions and allows Cloog
193 // to produces better code.
194 tileMap = isl_basic_map_project_out(tileMap, isl_dim_out,
195 2 * scheduleDimensions,
196 scheduleDimensions);
Tobias Grosserf5338802011-10-06 00:03:35 +0000197 isl_local_space_free(LocalSpace);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000198 return tileMap;
199}
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000200
Tobias Grosserde68cc92011-06-30 20:01:02 +0000201isl_union_map *getTiledPartialSchedule(isl_band *band) {
202 isl_union_map *partialSchedule;
Tobias Grosserc532f122011-08-25 08:40:59 +0000203 int scheduleDimensions;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000204 isl_ctx *ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +0000205 isl_space *Space;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000206 isl_basic_map *tileMap;
207 isl_union_map *tileUnionMap;
208
209 partialSchedule = isl_band_get_partial_schedule(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000210
Tobias Grosser353a2682011-10-23 20:59:26 +0000211 if (!DisableTiling) {
212 ctx = isl_union_map_get_ctx(partialSchedule);
213 Space= isl_union_map_get_space(partialSchedule);
214 scheduleDimensions = isl_band_n_member(band);
215
216 tileMap = getTileMap(ctx, scheduleDimensions, Space);
217 tileUnionMap = isl_union_map_from_map(isl_map_from_basic_map(tileMap));
218 tileUnionMap = isl_union_map_align_params(tileUnionMap, Space);
219 partialSchedule = isl_union_map_apply_range(partialSchedule, tileUnionMap);
220 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000221
Tobias Grosserde68cc92011-06-30 20:01:02 +0000222 return partialSchedule;
223}
224
Tobias Grosserc6699b72011-06-30 20:29:13 +0000225static isl_map *getPrevectorMap(isl_ctx *ctx, int vectorDimension,
226 int scheduleDimensions,
227 int parameterDimensions,
228 int vectorWidth = 4) {
Tobias Grosser2bd3af12011-08-01 22:39:00 +0000229 assert (0 <= vectorDimension && vectorDimension < scheduleDimensions);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000230
Tobias Grosserf5338802011-10-06 00:03:35 +0000231 isl_space *Space = isl_space_alloc(ctx, parameterDimensions,
232 scheduleDimensions, scheduleDimensions + 2);
233 isl_basic_map *tilingMap = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000234
235 isl_constraint *c;
236
Tobias Grosserf5338802011-10-06 00:03:35 +0000237 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
238
Tobias Grosserc6699b72011-06-30 20:29:13 +0000239 for (int i = 0; i < vectorDimension; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000240 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000241 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
242 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
243 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
244 }
245
246 for (int i = vectorDimension + 1; i < scheduleDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000247 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000248 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
249 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
250 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
251 }
252
253 int stepDimension = scheduleDimensions;
254 int auxilaryDimension = scheduleDimensions + 1;
255
Tobias Grosserf5338802011-10-06 00:03:35 +0000256 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000257 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
258 isl_constraint_set_coefficient_si(c, isl_dim_out, auxilaryDimension,
259 -vectorWidth);
260 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
261
Tobias Grosserf5338802011-10-06 00:03:35 +0000262 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000263 isl_constraint_set_coefficient_si(c, isl_dim_in, vectorDimension, -1);
264 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
265 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
266
Tobias Grosserf5338802011-10-06 00:03:35 +0000267 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000268 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, -1);
269 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
270 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
271
Tobias Grosserf5338802011-10-06 00:03:35 +0000272 c = isl_inequality_alloc(LocalSpace);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000273 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
274 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, -1);
275 isl_constraint_set_constant_si(c, vectorWidth- 1);
276 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
277
278 // Project out auxilary dimensions (introduced to ensure 'ii % tileSize = 0')
279 //
280 // The real dimensions are transformed into existentially quantified ones.
281 // This reduces the number of visible scattering dimensions. Also, Cloog
282 // produces better code, if auxilary dimensions are existentially quantified.
283 tilingMap = isl_basic_map_project_out(tilingMap, isl_dim_out,
284 scheduleDimensions + 1, 1);
285
286 return isl_map_from_basic_map(tilingMap);
287}
288
Tobias Grosserde68cc92011-06-30 20:01:02 +0000289// tileBandList - Tile all bands contained in a band forest.
290//
291// Recursively walk the band forest and tile all bands in the forest. Return
292// a schedule that describes the tiled scattering.
293static isl_union_map *tileBandList(isl_band_list *blist) {
294 int numBands = isl_band_list_n_band(blist);
295
296 isl_union_map *finalSchedule = 0;
297
298 for (int i = 0; i < numBands; i++) {
299 isl_band *band;
300 isl_union_map *partialSchedule;
301 band = isl_band_list_get_band(blist, i);
302 partialSchedule = getTiledPartialSchedule(band);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000303 int scheduleDimensions = isl_band_n_member(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000304 isl_space *Space = isl_union_map_get_space(partialSchedule);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000305
Tobias Grosserde68cc92011-06-30 20:01:02 +0000306
307 if (isl_band_has_children(band)) {
308 isl_band_list *children = isl_band_get_children(band);
309 isl_union_map *suffixSchedule = tileBandList(children);
310 partialSchedule = isl_union_map_flat_range_product(partialSchedule,
311 suffixSchedule);
Tobias Grossera9542422011-08-23 22:35:23 +0000312 isl_band_list_free(children);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000313 } else if (Prevector) {
314 isl_map *tileMap;
315 isl_union_map *tileUnionMap;
316 isl_ctx *ctx;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000317
318 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000319 for (int i = scheduleDimensions - 1 ; i >= 0 ; i--) {
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000320 if (isl_band_member_is_zero_distance(band, i)) {
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000321 tileMap = getPrevectorMap(ctx, scheduleDimensions + i,
Tobias Grosserc532f122011-08-25 08:40:59 +0000322 scheduleDimensions * 2, 0);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000323 tileUnionMap = isl_union_map_from_map(tileMap);
Tobias Grosserc532f122011-08-25 08:40:59 +0000324 tileUnionMap = isl_union_map_align_params(tileUnionMap,
Tobias Grosserf5338802011-10-06 00:03:35 +0000325 isl_space_copy(Space));
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000326 partialSchedule = isl_union_map_apply_range(partialSchedule,
327 tileUnionMap);
328 break;
329 }
330 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000331 }
332
333 if (finalSchedule)
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000334 finalSchedule = isl_union_map_union(finalSchedule, partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000335 else
336 finalSchedule = partialSchedule;
337
338 isl_band_free(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000339 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000340 }
341
342 return finalSchedule;
343}
344
345static isl_union_map *tileSchedule(isl_schedule *schedule) {
346 isl_band_list *blist = isl_schedule_get_band_forest(schedule);
347 isl_union_map *tiledSchedule = tileBandList(blist);
348 isl_band_list_free(blist);
349 return tiledSchedule;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000350}
351
Tobias Grosser73600b82011-10-08 00:30:40 +0000352bool IslScheduleOptimizer::runOnScop(Scop &S) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000353 Dependences *D = &getAnalysis<Dependences>();
354
355 // Build input data.
356 int dependencyKinds = Dependences::TYPE_RAW
357 | Dependences::TYPE_WAR
358 | Dependences::TYPE_WAW;
359
360 isl_union_map *validity = D->getDependences(dependencyKinds);
361 isl_union_map *proximity = D->getDependences(dependencyKinds);
362 isl_union_set *domain = NULL;
363
364 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
365 if ((*SI)->isFinalRead())
366 continue;
367 else if (!domain)
368 domain = isl_union_set_from_set((*SI)->getDomain());
369 else
370 domain = isl_union_set_union(domain,
371 isl_union_set_from_set((*SI)->getDomain()));
372
373 if (!domain)
374 return false;
375
376 DEBUG(dbgs() << "\n\nCompute schedule from: ");
377 DEBUG(dbgs() << "Domain := "; isl_union_set_dump(domain); dbgs() << ";\n");
378 DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(proximity);
379 dbgs() << ";\n");
380 DEBUG(dbgs() << "Validity := "; isl_union_map_dump(validity);
381 dbgs() << ";\n");
382
383 isl_schedule *schedule;
384
385 schedule = isl_union_set_compute_schedule(domain, validity, proximity);
386
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000387 DEBUG(dbgs() << "Computed schedule: ");
Tobias Grosserde68cc92011-06-30 20:01:02 +0000388 DEBUG(dbgs() << stringFromIslObj(schedule));
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000389 DEBUG(dbgs() << "Individual bands: ");
390
Tobias Grosserde68cc92011-06-30 20:01:02 +0000391 isl_union_map *tiledSchedule = tileSchedule(schedule);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000392
Tobias Grosserde68cc92011-06-30 20:01:02 +0000393 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
394 ScopStmt *stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000395
Tobias Grosserde68cc92011-06-30 20:01:02 +0000396 if (stmt->isFinalRead())
397 continue;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000398
Tobias Grosserde68cc92011-06-30 20:01:02 +0000399 isl_set *domain = stmt->getDomain();
400 isl_union_map *stmtBand;
401 stmtBand = isl_union_map_intersect_domain(isl_union_map_copy(tiledSchedule),
402 isl_union_set_from_set(domain));
403 isl_map *stmtSchedule;
404 isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000405 stmt->setScattering(stmtSchedule);
Tobias Grosser6e0fdca2011-08-23 12:31:14 +0000406 isl_union_map_free(stmtBand);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000407 }
408
Tobias Grosserde68cc92011-06-30 20:01:02 +0000409 isl_union_map_free(tiledSchedule);
410 isl_schedule_free(schedule);
411
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000412 unsigned maxScatDims = 0;
413
414 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
Tobias Grossercf3942d2011-10-06 00:04:05 +0000415 maxScatDims = std::max((*SI)->getNumScattering(), maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000416
417 extendScattering(S, maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000418 return false;
419}
420
Tobias Grosser73600b82011-10-08 00:30:40 +0000421void IslScheduleOptimizer::printScop(raw_ostream &OS) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000422}
423
Tobias Grosser73600b82011-10-08 00:30:40 +0000424void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000425 ScopPass::getAnalysisUsage(AU);
426 AU.addRequired<Dependences>();
427}
428
Tobias Grosser73600b82011-10-08 00:30:40 +0000429INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-optimize-isl",
430 "Polly - Optimize schedule of SCoP", false, false)
431INITIALIZE_PASS_DEPENDENCY(Dependences)
432INITIALIZE_PASS_DEPENDENCY(ScopInfo)
433INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-optimize-isl",
434 "Polly - Optimize schedule of SCoP", false, false)
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000435
Tobias Grosser73600b82011-10-08 00:30:40 +0000436Pass* polly::createIslScheduleOptimizerPass() {
437 return new IslScheduleOptimizer();
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000438}