blob: 0252722025896e0d3372b687478f85e6b5b38b16 [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 Grosser67707b72011-10-23 20:59:40 +000023#include "polly/CodeGeneration.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000024#include "polly/Support/GICHelper.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000025#include "polly/Dependences.h"
26#include "polly/ScopInfo.h"
27
Tobias Grosserf5338802011-10-06 00:03:35 +000028#include "isl/space.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000029#include "isl/map.h"
30#include "isl/constraint.h"
31#include "isl/schedule.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000032#include "isl/band.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000033
34#define DEBUG_TYPE "polly-optimize-isl"
35#include "llvm/Support/Debug.h"
Tobias Grosserc6699b72011-06-30 20:29:13 +000036#include "llvm/Support/CommandLine.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000037
38using namespace llvm;
39using namespace polly;
40
Tobias Grosserc6699b72011-06-30 20:29:13 +000041static cl::opt<bool>
Tobias Grosser353a2682011-10-23 20:59:26 +000042DisableTiling("polly-no-tiling",
43 cl::desc("Disable tiling in the isl scheduler"), cl::Hidden,
44 cl::init(false));
45
Tobias Grosser30aa24c2011-05-14 19:02:06 +000046namespace {
47
Tobias Grosser73600b82011-10-08 00:30:40 +000048 class IslScheduleOptimizer : public ScopPass {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000049
50 public:
51 static char ID;
Tobias Grosser73600b82011-10-08 00:30:40 +000052 explicit IslScheduleOptimizer() : ScopPass(ID) {}
Tobias Grosser30aa24c2011-05-14 19:02:06 +000053
54 virtual bool runOnScop(Scop &S);
55 void printScop(llvm::raw_ostream &OS) const;
56 void getAnalysisUsage(AnalysisUsage &AU) const;
57 };
58
59}
60
Tobias Grosser73600b82011-10-08 00:30:40 +000061char IslScheduleOptimizer::ID = 0;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000062
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 Grossercf3942d2011-10-06 00:04:05 +000070static void extendScattering(Scop &S, unsigned NewDimensions) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000071 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
Tobias Grossercf3942d2011-10-06 00:04:05 +000072 ScopStmt *Stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000073
Tobias Grossercf3942d2011-10-06 00:04:05 +000074 if (Stmt->isFinalRead())
Tobias Grosser30aa24c2011-05-14 19:02:06 +000075 continue;
76
Tobias Grossercf3942d2011-10-06 00:04:05 +000077 unsigned OldDimensions = Stmt->getNumScattering();
78 isl_space *Space;
79 isl_basic_map *ChangeScattering;
80
81 Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions);
82 ChangeScattering = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserf5338802011-10-06 00:03:35 +000083 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000084
Tobias Grossercf3942d2011-10-06 00:04:05 +000085 for (unsigned i = 0; i < OldDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000086 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000087 isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
88 isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);
Tobias Grossercf3942d2011-10-06 00:04:05 +000089 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000090 }
91
Tobias Grossercf3942d2011-10-06 00:04:05 +000092 for (unsigned i = OldDimensions; i < NewDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000093 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000094 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
Tobias Grossercf3942d2011-10-06 00:04:05 +000095 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000096 }
97
Tobias Grossercf3942d2011-10-06 00:04:05 +000098 isl_map *ChangeScatteringMap = isl_map_from_basic_map(ChangeScattering);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000099
Tobias Grossercf3942d2011-10-06 00:04:05 +0000100 ChangeScatteringMap = isl_map_align_params(ChangeScatteringMap,
101 S.getParamSpace());
102 isl_map *NewScattering = isl_map_apply_range(Stmt->getScattering(),
103 ChangeScatteringMap);
104 Stmt->setScattering(NewScattering);
Tobias Grosserf5338802011-10-06 00:03:35 +0000105 isl_local_space_free(LocalSpace);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000106 }
107}
108
Tobias Grosserde68cc92011-06-30 20:01:02 +0000109// getTileMap - Create a map that describes a n-dimensonal tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000110//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000111// getTileMap creates a map from a n-dimensional scattering space into an
112// 2*n-dimensional scattering space. The map describes a rectangular tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000113//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000114// Example:
115// scheduleDimensions = 2, parameterDimensions = 1, tileSize = 32
116//
117// tileMap := [p0] -> {[s0, s1] -> [t0, t1, s0, s1]:
118// t0 % 32 = 0 and t0 <= s0 < t0 + 32 and
119// t1 % 32 = 0 and t1 <= s1 < t1 + 32}
120//
121// Before tiling:
122//
123// for (i = 0; i < N; i++)
124// for (j = 0; j < M; j++)
125// S(i,j)
126//
127// After tiling:
128//
129// for (t_i = 0; t_i < N; i+=32)
130// for (t_j = 0; t_j < M; j+=32)
131// for (i = t_i; i < min(t_i + 32, N); i++) | Unknown that N % 32 = 0
132// for (j = t_j; j < t_j + 32; j++) | Known that M % 32 = 0
133// S(i,j)
134//
135static isl_basic_map *getTileMap(isl_ctx *ctx, int scheduleDimensions,
Tobias Grosserf5338802011-10-06 00:03:35 +0000136 isl_space *SpaceModel, int tileSize = 32) {
Tobias Grosserde68cc92011-06-30 20:01:02 +0000137 // We construct
138 //
139 // tileMap := [p0] -> {[s0, s1] -> [t0, t1, p0, p1, a0, a1]:
140 // s0 = a0 * 32 and s0 = p0 and t0 <= p0 < t0 + 32 and
141 // s1 = a1 * 32 and s1 = p1 and t1 <= p1 < t1 + 32}
142 //
143 // and project out the auxilary dimensions a0 and a1.
Tobias Grosserf5338802011-10-06 00:03:35 +0000144 isl_space *Space = isl_space_alloc(ctx, 0, scheduleDimensions,
145 scheduleDimensions * 3);
146 isl_basic_map *tileMap = isl_basic_map_universe(isl_space_copy(Space));
147
148 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000149
Tobias Grosserde68cc92011-06-30 20:01:02 +0000150 for (int x = 0; x < scheduleDimensions; x++) {
151 int sX = x;
152 int tX = x;
153 int pX = scheduleDimensions + x;
154 int aX = 2 * scheduleDimensions + x;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000155
Tobias Grosserde68cc92011-06-30 20:01:02 +0000156 isl_constraint *c;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000157
Tobias Grosserde68cc92011-06-30 20:01:02 +0000158 // sX = aX * tileSize;
Tobias Grosserf5338802011-10-06 00:03:35 +0000159 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000160 isl_constraint_set_coefficient_si(c, isl_dim_out, sX, 1);
161 isl_constraint_set_coefficient_si(c, isl_dim_out, aX, -tileSize);
162 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000163
Tobias Grosserde68cc92011-06-30 20:01:02 +0000164 // pX = sX;
Tobias Grosserf5338802011-10-06 00:03:35 +0000165 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000166 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
167 isl_constraint_set_coefficient_si(c, isl_dim_in, sX, -1);
168 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000169
Tobias Grosserde68cc92011-06-30 20:01:02 +0000170 // tX <= pX
Tobias Grosserf5338802011-10-06 00:03:35 +0000171 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000172 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
173 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, -1);
174 tileMap = isl_basic_map_add_constraint(tileMap, c);
175
176 // pX <= tX + (tileSize - 1)
Tobias Grosserf5338802011-10-06 00:03:35 +0000177 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000178 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, 1);
179 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, -1);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000180 isl_constraint_set_constant_si(c, tileSize - 1);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000181 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000182 }
183
Tobias Grosserde68cc92011-06-30 20:01:02 +0000184 // Project out auxilary dimensions.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000185 //
Tobias Grosserde68cc92011-06-30 20:01:02 +0000186 // The auxilary dimensions are transformed into existentially quantified ones.
187 // This reduces the number of visible scattering dimensions and allows Cloog
188 // to produces better code.
189 tileMap = isl_basic_map_project_out(tileMap, isl_dim_out,
190 2 * scheduleDimensions,
191 scheduleDimensions);
Tobias Grosserf5338802011-10-06 00:03:35 +0000192 isl_local_space_free(LocalSpace);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000193 return tileMap;
194}
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000195
Tobias Grosserde68cc92011-06-30 20:01:02 +0000196isl_union_map *getTiledPartialSchedule(isl_band *band) {
197 isl_union_map *partialSchedule;
Tobias Grosserc532f122011-08-25 08:40:59 +0000198 int scheduleDimensions;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000199 isl_ctx *ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +0000200 isl_space *Space;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000201 isl_basic_map *tileMap;
202 isl_union_map *tileUnionMap;
203
204 partialSchedule = isl_band_get_partial_schedule(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000205
Tobias Grosser353a2682011-10-23 20:59:26 +0000206 if (!DisableTiling) {
207 ctx = isl_union_map_get_ctx(partialSchedule);
208 Space= isl_union_map_get_space(partialSchedule);
209 scheduleDimensions = isl_band_n_member(band);
210
211 tileMap = getTileMap(ctx, scheduleDimensions, Space);
212 tileUnionMap = isl_union_map_from_map(isl_map_from_basic_map(tileMap));
213 tileUnionMap = isl_union_map_align_params(tileUnionMap, Space);
214 partialSchedule = isl_union_map_apply_range(partialSchedule, tileUnionMap);
215 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000216
Tobias Grosserde68cc92011-06-30 20:01:02 +0000217 return partialSchedule;
218}
219
Tobias Grosserc6699b72011-06-30 20:29:13 +0000220static isl_map *getPrevectorMap(isl_ctx *ctx, int vectorDimension,
221 int scheduleDimensions,
222 int parameterDimensions,
223 int vectorWidth = 4) {
Tobias Grosser2bd3af12011-08-01 22:39:00 +0000224 assert (0 <= vectorDimension && vectorDimension < scheduleDimensions);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000225
Tobias Grosserf5338802011-10-06 00:03:35 +0000226 isl_space *Space = isl_space_alloc(ctx, parameterDimensions,
227 scheduleDimensions, scheduleDimensions + 2);
228 isl_basic_map *tilingMap = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000229
230 isl_constraint *c;
231
Tobias Grosserf5338802011-10-06 00:03:35 +0000232 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
233
Tobias Grosserc6699b72011-06-30 20:29:13 +0000234 for (int i = 0; i < vectorDimension; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000235 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000236 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
237 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
238 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
239 }
240
241 for (int i = vectorDimension + 1; i < scheduleDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000242 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000243 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
244 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
245 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
246 }
247
248 int stepDimension = scheduleDimensions;
249 int auxilaryDimension = scheduleDimensions + 1;
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_out, vectorDimension, 1);
253 isl_constraint_set_coefficient_si(c, isl_dim_out, auxilaryDimension,
254 -vectorWidth);
255 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
256
Tobias Grosserf5338802011-10-06 00:03:35 +0000257 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000258 isl_constraint_set_coefficient_si(c, isl_dim_in, vectorDimension, -1);
259 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
260 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
261
Tobias Grosserf5338802011-10-06 00:03:35 +0000262 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000263 isl_constraint_set_coefficient_si(c, isl_dim_out, 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(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 isl_constraint_set_constant_si(c, vectorWidth- 1);
271 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
272
273 // Project out auxilary dimensions (introduced to ensure 'ii % tileSize = 0')
274 //
275 // The real dimensions are transformed into existentially quantified ones.
276 // This reduces the number of visible scattering dimensions. Also, Cloog
277 // produces better code, if auxilary dimensions are existentially quantified.
278 tilingMap = isl_basic_map_project_out(tilingMap, isl_dim_out,
279 scheduleDimensions + 1, 1);
280
281 return isl_map_from_basic_map(tilingMap);
282}
283
Tobias Grosserde68cc92011-06-30 20:01:02 +0000284// tileBandList - Tile all bands contained in a band forest.
285//
286// Recursively walk the band forest and tile all bands in the forest. Return
287// a schedule that describes the tiled scattering.
288static isl_union_map *tileBandList(isl_band_list *blist) {
289 int numBands = isl_band_list_n_band(blist);
290
291 isl_union_map *finalSchedule = 0;
292
293 for (int i = 0; i < numBands; i++) {
294 isl_band *band;
295 isl_union_map *partialSchedule;
296 band = isl_band_list_get_band(blist, i);
297 partialSchedule = getTiledPartialSchedule(band);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000298 int scheduleDimensions = isl_band_n_member(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000299 isl_space *Space = isl_union_map_get_space(partialSchedule);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000300
Tobias Grosserde68cc92011-06-30 20:01:02 +0000301
302 if (isl_band_has_children(band)) {
303 isl_band_list *children = isl_band_get_children(band);
304 isl_union_map *suffixSchedule = tileBandList(children);
305 partialSchedule = isl_union_map_flat_range_product(partialSchedule,
306 suffixSchedule);
Tobias Grossera9542422011-08-23 22:35:23 +0000307 isl_band_list_free(children);
Tobias Grosser67707b72011-10-23 20:59:40 +0000308 } else if (EnablePollyVector) {
Tobias Grosserc6699b72011-06-30 20:29:13 +0000309 isl_map *tileMap;
310 isl_union_map *tileUnionMap;
311 isl_ctx *ctx;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000312
313 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000314 for (int i = scheduleDimensions - 1 ; i >= 0 ; i--) {
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000315 if (isl_band_member_is_zero_distance(band, i)) {
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000316 tileMap = getPrevectorMap(ctx, scheduleDimensions + i,
Tobias Grosserc532f122011-08-25 08:40:59 +0000317 scheduleDimensions * 2, 0);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000318 tileUnionMap = isl_union_map_from_map(tileMap);
Tobias Grosserc532f122011-08-25 08:40:59 +0000319 tileUnionMap = isl_union_map_align_params(tileUnionMap,
Tobias Grosserf5338802011-10-06 00:03:35 +0000320 isl_space_copy(Space));
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000321 partialSchedule = isl_union_map_apply_range(partialSchedule,
322 tileUnionMap);
323 break;
324 }
325 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000326 }
327
328 if (finalSchedule)
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000329 finalSchedule = isl_union_map_union(finalSchedule, partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000330 else
331 finalSchedule = partialSchedule;
332
333 isl_band_free(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000334 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000335 }
336
337 return finalSchedule;
338}
339
340static isl_union_map *tileSchedule(isl_schedule *schedule) {
341 isl_band_list *blist = isl_schedule_get_band_forest(schedule);
342 isl_union_map *tiledSchedule = tileBandList(blist);
343 isl_band_list_free(blist);
344 return tiledSchedule;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000345}
346
Tobias Grosser73600b82011-10-08 00:30:40 +0000347bool IslScheduleOptimizer::runOnScop(Scop &S) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000348 Dependences *D = &getAnalysis<Dependences>();
349
350 // Build input data.
351 int dependencyKinds = Dependences::TYPE_RAW
352 | Dependences::TYPE_WAR
353 | Dependences::TYPE_WAW;
354
355 isl_union_map *validity = D->getDependences(dependencyKinds);
356 isl_union_map *proximity = D->getDependences(dependencyKinds);
357 isl_union_set *domain = NULL;
358
359 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
360 if ((*SI)->isFinalRead())
361 continue;
362 else if (!domain)
363 domain = isl_union_set_from_set((*SI)->getDomain());
364 else
365 domain = isl_union_set_union(domain,
366 isl_union_set_from_set((*SI)->getDomain()));
367
368 if (!domain)
369 return false;
370
371 DEBUG(dbgs() << "\n\nCompute schedule from: ");
372 DEBUG(dbgs() << "Domain := "; isl_union_set_dump(domain); dbgs() << ";\n");
373 DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(proximity);
374 dbgs() << ";\n");
375 DEBUG(dbgs() << "Validity := "; isl_union_map_dump(validity);
376 dbgs() << ";\n");
377
378 isl_schedule *schedule;
379
380 schedule = isl_union_set_compute_schedule(domain, validity, proximity);
381
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000382 DEBUG(dbgs() << "Computed schedule: ");
Tobias Grosserde68cc92011-06-30 20:01:02 +0000383 DEBUG(dbgs() << stringFromIslObj(schedule));
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000384 DEBUG(dbgs() << "Individual bands: ");
385
Tobias Grosserde68cc92011-06-30 20:01:02 +0000386 isl_union_map *tiledSchedule = tileSchedule(schedule);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000387
Tobias Grosserde68cc92011-06-30 20:01:02 +0000388 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
389 ScopStmt *stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000390
Tobias Grosserde68cc92011-06-30 20:01:02 +0000391 if (stmt->isFinalRead())
392 continue;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000393
Tobias Grosserde68cc92011-06-30 20:01:02 +0000394 isl_set *domain = stmt->getDomain();
395 isl_union_map *stmtBand;
396 stmtBand = isl_union_map_intersect_domain(isl_union_map_copy(tiledSchedule),
397 isl_union_set_from_set(domain));
398 isl_map *stmtSchedule;
399 isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000400 stmt->setScattering(stmtSchedule);
Tobias Grosser6e0fdca2011-08-23 12:31:14 +0000401 isl_union_map_free(stmtBand);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000402 }
403
Tobias Grosserde68cc92011-06-30 20:01:02 +0000404 isl_union_map_free(tiledSchedule);
405 isl_schedule_free(schedule);
406
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000407 unsigned maxScatDims = 0;
408
409 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
Tobias Grossercf3942d2011-10-06 00:04:05 +0000410 maxScatDims = std::max((*SI)->getNumScattering(), maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000411
412 extendScattering(S, maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000413 return false;
414}
415
Tobias Grosser73600b82011-10-08 00:30:40 +0000416void IslScheduleOptimizer::printScop(raw_ostream &OS) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000417}
418
Tobias Grosser73600b82011-10-08 00:30:40 +0000419void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000420 ScopPass::getAnalysisUsage(AU);
421 AU.addRequired<Dependences>();
422}
423
Tobias Grosser73600b82011-10-08 00:30:40 +0000424INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-optimize-isl",
425 "Polly - Optimize schedule of SCoP", false, false)
426INITIALIZE_PASS_DEPENDENCY(Dependences)
427INITIALIZE_PASS_DEPENDENCY(ScopInfo)
428INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-optimize-isl",
429 "Polly - Optimize schedule of SCoP", false, false)
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000430
Tobias Grosser73600b82011-10-08 00:30:40 +0000431Pass* polly::createIslScheduleOptimizerPass() {
432 return new IslScheduleOptimizer();
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000433}