blob: a2aeb963f1bcb8316d56121ed834cda1599d58b8 [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>
41Prevector("enable-schedule-prevector",
42 cl::desc("Enable the prevectorization in the scheduler"), cl::Hidden,
43 cl::value_desc("Prevectorization enabled"),
44 cl::init(false));
45
Tobias Grosser30aa24c2011-05-14 19:02:06 +000046namespace {
47
48 class ScheduleOptimizer : public ScopPass {
49
50 public:
51 static char ID;
52 explicit ScheduleOptimizer() : ScopPass(ID) {}
53
54 virtual bool runOnScop(Scop &S);
55 void printScop(llvm::raw_ostream &OS) const;
56 void getAnalysisUsage(AnalysisUsage &AU) const;
57 };
58
59}
60
61char ScheduleOptimizer::ID = 0;
62
63static int getSingleMap(__isl_take isl_map *map, void *user) {
64 isl_map **singleMap = (isl_map **) user;
65 *singleMap = map;
66
67 return 0;
68}
69
Tobias Grosser76747f72011-05-24 12:20:07 +000070static void extendScattering(Scop &S, unsigned scatDimensions) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000071 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
72 ScopStmt *stmt = *SI;
73
74 if (stmt->isFinalRead())
75 continue;
76
77 isl_map *scattering = stmt->getScattering();
Tobias Grosserf5338802011-10-06 00:03:35 +000078 isl_space *Space = isl_space_alloc(isl_map_get_ctx(scattering), 0,
79 isl_map_n_out(scattering), scatDimensions);
80 isl_basic_map *changeScattering = isl_basic_map_universe(
81 isl_space_copy(Space));
82 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000083
84 for (unsigned i = 0; i < isl_map_n_out(scattering); i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000085 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000086 isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
87 isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);
88 changeScattering = isl_basic_map_add_constraint(changeScattering, c);
89 }
90
91 for (unsigned i = isl_map_n_out(scattering); i < scatDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000092 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000093 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
94 changeScattering = isl_basic_map_add_constraint(changeScattering, c);
95 }
96
97 isl_map *changeScatteringMap = isl_map_from_basic_map(changeScattering);
98
Tobias Grosserf5338802011-10-06 00:03:35 +000099 isl_space *SpaceModel = isl_map_get_space(scattering);
100 changeScatteringMap = isl_map_align_params(changeScatteringMap, SpaceModel);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000101 stmt->setScattering(isl_map_apply_range(scattering, changeScatteringMap));
Tobias Grosserf5338802011-10-06 00:03:35 +0000102 isl_local_space_free(LocalSpace);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000103 }
104}
105
Tobias Grosserde68cc92011-06-30 20:01:02 +0000106// getTileMap - Create a map that describes a n-dimensonal tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000107//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000108// getTileMap creates a map from a n-dimensional scattering space into an
109// 2*n-dimensional scattering space. The map describes a rectangular tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000110//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000111// Example:
112// scheduleDimensions = 2, parameterDimensions = 1, tileSize = 32
113//
114// tileMap := [p0] -> {[s0, s1] -> [t0, t1, s0, s1]:
115// t0 % 32 = 0 and t0 <= s0 < t0 + 32 and
116// t1 % 32 = 0 and t1 <= s1 < t1 + 32}
117//
118// Before tiling:
119//
120// for (i = 0; i < N; i++)
121// for (j = 0; j < M; j++)
122// S(i,j)
123//
124// After tiling:
125//
126// for (t_i = 0; t_i < N; i+=32)
127// for (t_j = 0; t_j < M; j+=32)
128// for (i = t_i; i < min(t_i + 32, N); i++) | Unknown that N % 32 = 0
129// for (j = t_j; j < t_j + 32; j++) | Known that M % 32 = 0
130// S(i,j)
131//
132static isl_basic_map *getTileMap(isl_ctx *ctx, int scheduleDimensions,
Tobias Grosserf5338802011-10-06 00:03:35 +0000133 isl_space *SpaceModel, int tileSize = 32) {
Tobias Grosserde68cc92011-06-30 20:01:02 +0000134 // We construct
135 //
136 // tileMap := [p0] -> {[s0, s1] -> [t0, t1, p0, p1, a0, a1]:
137 // s0 = a0 * 32 and s0 = p0 and t0 <= p0 < t0 + 32 and
138 // s1 = a1 * 32 and s1 = p1 and t1 <= p1 < t1 + 32}
139 //
140 // and project out the auxilary dimensions a0 and a1.
Tobias Grosserf5338802011-10-06 00:03:35 +0000141 isl_space *Space = isl_space_alloc(ctx, 0, scheduleDimensions,
142 scheduleDimensions * 3);
143 isl_basic_map *tileMap = isl_basic_map_universe(isl_space_copy(Space));
144
145 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000146
Tobias Grosserde68cc92011-06-30 20:01:02 +0000147 for (int x = 0; x < scheduleDimensions; x++) {
148 int sX = x;
149 int tX = x;
150 int pX = scheduleDimensions + x;
151 int aX = 2 * scheduleDimensions + x;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000152
Tobias Grosserde68cc92011-06-30 20:01:02 +0000153 isl_constraint *c;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000154
Tobias Grosserde68cc92011-06-30 20:01:02 +0000155 // sX = aX * tileSize;
Tobias Grosserf5338802011-10-06 00:03:35 +0000156 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000157 isl_constraint_set_coefficient_si(c, isl_dim_out, sX, 1);
158 isl_constraint_set_coefficient_si(c, isl_dim_out, aX, -tileSize);
159 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000160
Tobias Grosserde68cc92011-06-30 20:01:02 +0000161 // pX = sX;
Tobias Grosserf5338802011-10-06 00:03:35 +0000162 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000163 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
164 isl_constraint_set_coefficient_si(c, isl_dim_in, sX, -1);
165 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000166
Tobias Grosserde68cc92011-06-30 20:01:02 +0000167 // tX <= pX
Tobias Grosserf5338802011-10-06 00:03:35 +0000168 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000169 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
170 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, -1);
171 tileMap = isl_basic_map_add_constraint(tileMap, c);
172
173 // pX <= tX + (tileSize - 1)
Tobias Grosserf5338802011-10-06 00:03:35 +0000174 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000175 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, 1);
176 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, -1);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000177 isl_constraint_set_constant_si(c, tileSize - 1);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000178 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000179 }
180
Tobias Grosserde68cc92011-06-30 20:01:02 +0000181 // Project out auxilary dimensions.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000182 //
Tobias Grosserde68cc92011-06-30 20:01:02 +0000183 // The auxilary dimensions are transformed into existentially quantified ones.
184 // This reduces the number of visible scattering dimensions and allows Cloog
185 // to produces better code.
186 tileMap = isl_basic_map_project_out(tileMap, isl_dim_out,
187 2 * scheduleDimensions,
188 scheduleDimensions);
Tobias Grosserf5338802011-10-06 00:03:35 +0000189 isl_local_space_free(LocalSpace);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000190 return tileMap;
191}
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000192
Tobias Grosserde68cc92011-06-30 20:01:02 +0000193isl_union_map *getTiledPartialSchedule(isl_band *band) {
194 isl_union_map *partialSchedule;
Tobias Grosserc532f122011-08-25 08:40:59 +0000195 int scheduleDimensions;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000196 isl_ctx *ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +0000197 isl_space *Space;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000198 isl_basic_map *tileMap;
199 isl_union_map *tileUnionMap;
200
201 partialSchedule = isl_band_get_partial_schedule(band);
202 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosserf5338802011-10-06 00:03:35 +0000203 Space= isl_union_map_get_space(partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000204 scheduleDimensions = isl_band_n_member(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000205
Tobias Grosserf5338802011-10-06 00:03:35 +0000206 tileMap = getTileMap(ctx, scheduleDimensions, Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000207 tileUnionMap = isl_union_map_from_map(isl_map_from_basic_map(tileMap));
Tobias Grosserf5338802011-10-06 00:03:35 +0000208 tileUnionMap = isl_union_map_align_params(tileUnionMap, Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000209 partialSchedule = isl_union_map_apply_range(partialSchedule, tileUnionMap);
210
Tobias Grosserde68cc92011-06-30 20:01:02 +0000211 return partialSchedule;
212}
213
Tobias Grosserc6699b72011-06-30 20:29:13 +0000214static isl_map *getPrevectorMap(isl_ctx *ctx, int vectorDimension,
215 int scheduleDimensions,
216 int parameterDimensions,
217 int vectorWidth = 4) {
Tobias Grosser2bd3af12011-08-01 22:39:00 +0000218 assert (0 <= vectorDimension && vectorDimension < scheduleDimensions);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000219
Tobias Grosserf5338802011-10-06 00:03:35 +0000220 isl_space *Space = isl_space_alloc(ctx, parameterDimensions,
221 scheduleDimensions, scheduleDimensions + 2);
222 isl_basic_map *tilingMap = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000223
224 isl_constraint *c;
225
Tobias Grosserf5338802011-10-06 00:03:35 +0000226 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
227
Tobias Grosserc6699b72011-06-30 20:29:13 +0000228 for (int i = 0; i < vectorDimension; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000229 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000230 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
231 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
232 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
233 }
234
235 for (int i = vectorDimension + 1; i < scheduleDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000236 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000237 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
238 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
239 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
240 }
241
242 int stepDimension = scheduleDimensions;
243 int auxilaryDimension = scheduleDimensions + 1;
244
Tobias Grosserf5338802011-10-06 00:03:35 +0000245 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000246 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
247 isl_constraint_set_coefficient_si(c, isl_dim_out, auxilaryDimension,
248 -vectorWidth);
249 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
250
Tobias Grosserf5338802011-10-06 00:03:35 +0000251 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000252 isl_constraint_set_coefficient_si(c, isl_dim_in, vectorDimension, -1);
253 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
254 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
255
Tobias Grosserf5338802011-10-06 00:03:35 +0000256 c = isl_inequality_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, stepDimension, 1);
259 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
260
Tobias Grosserf5338802011-10-06 00:03:35 +0000261 c = isl_inequality_alloc(LocalSpace);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000262 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
263 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, -1);
264 isl_constraint_set_constant_si(c, vectorWidth- 1);
265 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
266
267 // Project out auxilary dimensions (introduced to ensure 'ii % tileSize = 0')
268 //
269 // The real dimensions are transformed into existentially quantified ones.
270 // This reduces the number of visible scattering dimensions. Also, Cloog
271 // produces better code, if auxilary dimensions are existentially quantified.
272 tilingMap = isl_basic_map_project_out(tilingMap, isl_dim_out,
273 scheduleDimensions + 1, 1);
274
275 return isl_map_from_basic_map(tilingMap);
276}
277
Tobias Grosserde68cc92011-06-30 20:01:02 +0000278// tileBandList - Tile all bands contained in a band forest.
279//
280// Recursively walk the band forest and tile all bands in the forest. Return
281// a schedule that describes the tiled scattering.
282static isl_union_map *tileBandList(isl_band_list *blist) {
283 int numBands = isl_band_list_n_band(blist);
284
285 isl_union_map *finalSchedule = 0;
286
287 for (int i = 0; i < numBands; i++) {
288 isl_band *band;
289 isl_union_map *partialSchedule;
290 band = isl_band_list_get_band(blist, i);
291 partialSchedule = getTiledPartialSchedule(band);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000292 int scheduleDimensions = isl_band_n_member(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000293 isl_space *Space = isl_union_map_get_space(partialSchedule);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000294
Tobias Grosserde68cc92011-06-30 20:01:02 +0000295
296 if (isl_band_has_children(band)) {
297 isl_band_list *children = isl_band_get_children(band);
298 isl_union_map *suffixSchedule = tileBandList(children);
299 partialSchedule = isl_union_map_flat_range_product(partialSchedule,
300 suffixSchedule);
Tobias Grossera9542422011-08-23 22:35:23 +0000301 isl_band_list_free(children);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000302 } else if (Prevector) {
303 isl_map *tileMap;
304 isl_union_map *tileUnionMap;
305 isl_ctx *ctx;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000306
307 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000308 for (int i = scheduleDimensions - 1 ; i >= 0 ; i--) {
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000309 if (isl_band_member_is_zero_distance(band, i)) {
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000310 tileMap = getPrevectorMap(ctx, scheduleDimensions + i,
Tobias Grosserc532f122011-08-25 08:40:59 +0000311 scheduleDimensions * 2, 0);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000312 tileUnionMap = isl_union_map_from_map(tileMap);
Tobias Grosserc532f122011-08-25 08:40:59 +0000313 tileUnionMap = isl_union_map_align_params(tileUnionMap,
Tobias Grosserf5338802011-10-06 00:03:35 +0000314 isl_space_copy(Space));
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000315 partialSchedule = isl_union_map_apply_range(partialSchedule,
316 tileUnionMap);
317 break;
318 }
319 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000320 }
321
322 if (finalSchedule)
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000323 finalSchedule = isl_union_map_union(finalSchedule, partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000324 else
325 finalSchedule = partialSchedule;
326
327 isl_band_free(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000328 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000329 }
330
331 return finalSchedule;
332}
333
334static isl_union_map *tileSchedule(isl_schedule *schedule) {
335 isl_band_list *blist = isl_schedule_get_band_forest(schedule);
336 isl_union_map *tiledSchedule = tileBandList(blist);
337 isl_band_list_free(blist);
338 return tiledSchedule;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000339}
340
341bool ScheduleOptimizer::runOnScop(Scop &S) {
342 Dependences *D = &getAnalysis<Dependences>();
343
344 // Build input data.
345 int dependencyKinds = Dependences::TYPE_RAW
346 | Dependences::TYPE_WAR
347 | Dependences::TYPE_WAW;
348
349 isl_union_map *validity = D->getDependences(dependencyKinds);
350 isl_union_map *proximity = D->getDependences(dependencyKinds);
351 isl_union_set *domain = NULL;
352
353 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
354 if ((*SI)->isFinalRead())
355 continue;
356 else if (!domain)
357 domain = isl_union_set_from_set((*SI)->getDomain());
358 else
359 domain = isl_union_set_union(domain,
360 isl_union_set_from_set((*SI)->getDomain()));
361
362 if (!domain)
363 return false;
364
365 DEBUG(dbgs() << "\n\nCompute schedule from: ");
366 DEBUG(dbgs() << "Domain := "; isl_union_set_dump(domain); dbgs() << ";\n");
367 DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(proximity);
368 dbgs() << ";\n");
369 DEBUG(dbgs() << "Validity := "; isl_union_map_dump(validity);
370 dbgs() << ";\n");
371
372 isl_schedule *schedule;
373
374 schedule = isl_union_set_compute_schedule(domain, validity, proximity);
375
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000376 DEBUG(dbgs() << "Computed schedule: ");
Tobias Grosserde68cc92011-06-30 20:01:02 +0000377 DEBUG(dbgs() << stringFromIslObj(schedule));
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000378 DEBUG(dbgs() << "Individual bands: ");
379
Tobias Grosserde68cc92011-06-30 20:01:02 +0000380 isl_union_map *tiledSchedule = tileSchedule(schedule);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000381
Tobias Grosserde68cc92011-06-30 20:01:02 +0000382 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
383 ScopStmt *stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000384
Tobias Grosserde68cc92011-06-30 20:01:02 +0000385 if (stmt->isFinalRead())
386 continue;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000387
Tobias Grosserde68cc92011-06-30 20:01:02 +0000388 isl_set *domain = stmt->getDomain();
389 isl_union_map *stmtBand;
390 stmtBand = isl_union_map_intersect_domain(isl_union_map_copy(tiledSchedule),
391 isl_union_set_from_set(domain));
392 isl_map *stmtSchedule;
393 isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule);
Tobias Grosser6e0fdca2011-08-23 12:31:14 +0000394 stmt->setScattering(isl_map_copy(stmtSchedule));
395 isl_union_map_free(stmtBand);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000396 }
397
Tobias Grosserde68cc92011-06-30 20:01:02 +0000398 isl_union_map_free(tiledSchedule);
399 isl_schedule_free(schedule);
400
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000401 unsigned maxScatDims = 0;
402
403 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
404 maxScatDims = std::max(isl_map_n_out((*SI)->getScattering()), maxScatDims);
405
406 extendScattering(S, maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000407 return false;
408}
409
410void ScheduleOptimizer::printScop(raw_ostream &OS) const {
411}
412
413void ScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
414 ScopPass::getAnalysisUsage(AU);
415 AU.addRequired<Dependences>();
416}
417
418static RegisterPass<ScheduleOptimizer> A("polly-optimize-isl",
419 "Polly - Calculate optimized "
420 "schedules using the isl schedule "
421 "calculator");
422
423Pass* polly::createScheduleOptimizerPass() {
424 return new ScheduleOptimizer();
425}