blob: 3b48bfc154f2dea42360f36fcfb4e30a7ab88a0f [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
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);
205 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosserf5338802011-10-06 00:03:35 +0000206 Space= isl_union_map_get_space(partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000207 scheduleDimensions = isl_band_n_member(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000208
Tobias Grosserf5338802011-10-06 00:03:35 +0000209 tileMap = getTileMap(ctx, scheduleDimensions, Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000210 tileUnionMap = isl_union_map_from_map(isl_map_from_basic_map(tileMap));
Tobias Grosserf5338802011-10-06 00:03:35 +0000211 tileUnionMap = isl_union_map_align_params(tileUnionMap, Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000212 partialSchedule = isl_union_map_apply_range(partialSchedule, tileUnionMap);
213
Tobias Grosserde68cc92011-06-30 20:01:02 +0000214 return partialSchedule;
215}
216
Tobias Grosserc6699b72011-06-30 20:29:13 +0000217static isl_map *getPrevectorMap(isl_ctx *ctx, int vectorDimension,
218 int scheduleDimensions,
219 int parameterDimensions,
220 int vectorWidth = 4) {
Tobias Grosser2bd3af12011-08-01 22:39:00 +0000221 assert (0 <= vectorDimension && vectorDimension < scheduleDimensions);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000222
Tobias Grosserf5338802011-10-06 00:03:35 +0000223 isl_space *Space = isl_space_alloc(ctx, parameterDimensions,
224 scheduleDimensions, scheduleDimensions + 2);
225 isl_basic_map *tilingMap = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000226
227 isl_constraint *c;
228
Tobias Grosserf5338802011-10-06 00:03:35 +0000229 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
230
Tobias Grosserc6699b72011-06-30 20:29:13 +0000231 for (int i = 0; i < vectorDimension; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000232 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000233 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
234 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
235 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
236 }
237
238 for (int i = vectorDimension + 1; i < scheduleDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000239 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000240 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
241 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
242 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
243 }
244
245 int stepDimension = scheduleDimensions;
246 int auxilaryDimension = scheduleDimensions + 1;
247
Tobias Grosserf5338802011-10-06 00:03:35 +0000248 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000249 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
250 isl_constraint_set_coefficient_si(c, isl_dim_out, auxilaryDimension,
251 -vectorWidth);
252 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
253
Tobias Grosserf5338802011-10-06 00:03:35 +0000254 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000255 isl_constraint_set_coefficient_si(c, isl_dim_in, vectorDimension, -1);
256 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
257 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
258
Tobias Grosserf5338802011-10-06 00:03:35 +0000259 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000260 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, -1);
261 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
262 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
263
Tobias Grosserf5338802011-10-06 00:03:35 +0000264 c = isl_inequality_alloc(LocalSpace);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000265 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
266 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, -1);
267 isl_constraint_set_constant_si(c, vectorWidth- 1);
268 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
269
270 // Project out auxilary dimensions (introduced to ensure 'ii % tileSize = 0')
271 //
272 // The real dimensions are transformed into existentially quantified ones.
273 // This reduces the number of visible scattering dimensions. Also, Cloog
274 // produces better code, if auxilary dimensions are existentially quantified.
275 tilingMap = isl_basic_map_project_out(tilingMap, isl_dim_out,
276 scheduleDimensions + 1, 1);
277
278 return isl_map_from_basic_map(tilingMap);
279}
280
Tobias Grosserde68cc92011-06-30 20:01:02 +0000281// tileBandList - Tile all bands contained in a band forest.
282//
283// Recursively walk the band forest and tile all bands in the forest. Return
284// a schedule that describes the tiled scattering.
285static isl_union_map *tileBandList(isl_band_list *blist) {
286 int numBands = isl_band_list_n_band(blist);
287
288 isl_union_map *finalSchedule = 0;
289
290 for (int i = 0; i < numBands; i++) {
291 isl_band *band;
292 isl_union_map *partialSchedule;
293 band = isl_band_list_get_band(blist, i);
294 partialSchedule = getTiledPartialSchedule(band);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000295 int scheduleDimensions = isl_band_n_member(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000296 isl_space *Space = isl_union_map_get_space(partialSchedule);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000297
Tobias Grosserde68cc92011-06-30 20:01:02 +0000298
299 if (isl_band_has_children(band)) {
300 isl_band_list *children = isl_band_get_children(band);
301 isl_union_map *suffixSchedule = tileBandList(children);
302 partialSchedule = isl_union_map_flat_range_product(partialSchedule,
303 suffixSchedule);
Tobias Grossera9542422011-08-23 22:35:23 +0000304 isl_band_list_free(children);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000305 } else if (Prevector) {
306 isl_map *tileMap;
307 isl_union_map *tileUnionMap;
308 isl_ctx *ctx;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000309
310 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000311 for (int i = scheduleDimensions - 1 ; i >= 0 ; i--) {
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000312 if (isl_band_member_is_zero_distance(band, i)) {
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000313 tileMap = getPrevectorMap(ctx, scheduleDimensions + i,
Tobias Grosserc532f122011-08-25 08:40:59 +0000314 scheduleDimensions * 2, 0);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000315 tileUnionMap = isl_union_map_from_map(tileMap);
Tobias Grosserc532f122011-08-25 08:40:59 +0000316 tileUnionMap = isl_union_map_align_params(tileUnionMap,
Tobias Grosserf5338802011-10-06 00:03:35 +0000317 isl_space_copy(Space));
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000318 partialSchedule = isl_union_map_apply_range(partialSchedule,
319 tileUnionMap);
320 break;
321 }
322 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000323 }
324
325 if (finalSchedule)
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000326 finalSchedule = isl_union_map_union(finalSchedule, partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000327 else
328 finalSchedule = partialSchedule;
329
330 isl_band_free(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000331 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000332 }
333
334 return finalSchedule;
335}
336
337static isl_union_map *tileSchedule(isl_schedule *schedule) {
338 isl_band_list *blist = isl_schedule_get_band_forest(schedule);
339 isl_union_map *tiledSchedule = tileBandList(blist);
340 isl_band_list_free(blist);
341 return tiledSchedule;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000342}
343
Tobias Grosser73600b82011-10-08 00:30:40 +0000344bool IslScheduleOptimizer::runOnScop(Scop &S) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000345 Dependences *D = &getAnalysis<Dependences>();
346
347 // Build input data.
348 int dependencyKinds = Dependences::TYPE_RAW
349 | Dependences::TYPE_WAR
350 | Dependences::TYPE_WAW;
351
352 isl_union_map *validity = D->getDependences(dependencyKinds);
353 isl_union_map *proximity = D->getDependences(dependencyKinds);
354 isl_union_set *domain = NULL;
355
356 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
357 if ((*SI)->isFinalRead())
358 continue;
359 else if (!domain)
360 domain = isl_union_set_from_set((*SI)->getDomain());
361 else
362 domain = isl_union_set_union(domain,
363 isl_union_set_from_set((*SI)->getDomain()));
364
365 if (!domain)
366 return false;
367
368 DEBUG(dbgs() << "\n\nCompute schedule from: ");
369 DEBUG(dbgs() << "Domain := "; isl_union_set_dump(domain); dbgs() << ";\n");
370 DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(proximity);
371 dbgs() << ";\n");
372 DEBUG(dbgs() << "Validity := "; isl_union_map_dump(validity);
373 dbgs() << ";\n");
374
375 isl_schedule *schedule;
376
377 schedule = isl_union_set_compute_schedule(domain, validity, proximity);
378
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000379 DEBUG(dbgs() << "Computed schedule: ");
Tobias Grosserde68cc92011-06-30 20:01:02 +0000380 DEBUG(dbgs() << stringFromIslObj(schedule));
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000381 DEBUG(dbgs() << "Individual bands: ");
382
Tobias Grosserde68cc92011-06-30 20:01:02 +0000383 isl_union_map *tiledSchedule = tileSchedule(schedule);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000384
Tobias Grosserde68cc92011-06-30 20:01:02 +0000385 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
386 ScopStmt *stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000387
Tobias Grosserde68cc92011-06-30 20:01:02 +0000388 if (stmt->isFinalRead())
389 continue;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000390
Tobias Grosserde68cc92011-06-30 20:01:02 +0000391 isl_set *domain = stmt->getDomain();
392 isl_union_map *stmtBand;
393 stmtBand = isl_union_map_intersect_domain(isl_union_map_copy(tiledSchedule),
394 isl_union_set_from_set(domain));
395 isl_map *stmtSchedule;
396 isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000397 stmt->setScattering(stmtSchedule);
Tobias Grosser6e0fdca2011-08-23 12:31:14 +0000398 isl_union_map_free(stmtBand);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000399 }
400
Tobias Grosserde68cc92011-06-30 20:01:02 +0000401 isl_union_map_free(tiledSchedule);
402 isl_schedule_free(schedule);
403
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000404 unsigned maxScatDims = 0;
405
406 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
Tobias Grossercf3942d2011-10-06 00:04:05 +0000407 maxScatDims = std::max((*SI)->getNumScattering(), maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000408
409 extendScattering(S, maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000410 return false;
411}
412
Tobias Grosser73600b82011-10-08 00:30:40 +0000413void IslScheduleOptimizer::printScop(raw_ostream &OS) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000414}
415
Tobias Grosser73600b82011-10-08 00:30:40 +0000416void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000417 ScopPass::getAnalysisUsage(AU);
418 AU.addRequired<Dependences>();
419}
420
Tobias Grosser73600b82011-10-08 00:30:40 +0000421INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-optimize-isl",
422 "Polly - Optimize schedule of SCoP", false, false)
423INITIALIZE_PASS_DEPENDENCY(Dependences)
424INITIALIZE_PASS_DEPENDENCY(ScopInfo)
425INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-optimize-isl",
426 "Polly - Optimize schedule of SCoP", false, false)
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000427
Tobias Grosser73600b82011-10-08 00:30:40 +0000428Pass* polly::createIslScheduleOptimizerPass() {
429 return new IslScheduleOptimizer();
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000430}