blob: 694cf0cdc96b0718ca9f589abbe4fbdf631b3bc1 [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
Tobias Grosser967239c2011-10-23 20:59:44 +000020#include "polly/ScheduleOptimizer.h"
21
Tobias Grosser30aa24c2011-05-14 19:02:06 +000022#include "polly/Cloog.h"
23#include "polly/LinkAllPasses.h"
Tobias Grosser67707b72011-10-23 20:59:40 +000024#include "polly/CodeGeneration.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000025#include "polly/Support/GICHelper.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000026#include "polly/Dependences.h"
27#include "polly/ScopInfo.h"
28
Tobias Grosserf5338802011-10-06 00:03:35 +000029#include "isl/space.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000030#include "isl/map.h"
31#include "isl/constraint.h"
32#include "isl/schedule.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000033#include "isl/band.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000034
35#define DEBUG_TYPE "polly-optimize-isl"
36#include "llvm/Support/Debug.h"
Tobias Grosserc6699b72011-06-30 20:29:13 +000037#include "llvm/Support/CommandLine.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000038
39using namespace llvm;
40using namespace polly;
41
Tobias Grosser967239c2011-10-23 20:59:44 +000042namespace polly {
43 bool DisablePollyTiling;
44}
45static cl::opt<bool, true>
Tobias Grosser353a2682011-10-23 20:59:26 +000046DisableTiling("polly-no-tiling",
Tobias Grosser967239c2011-10-23 20:59:44 +000047 cl::desc("Disable tiling in the scheduler"), cl::Hidden,
48 cl::location(polly::DisablePollyTiling), cl::init(false));
Tobias Grosser353a2682011-10-23 20:59:26 +000049
Tobias Grosser30aa24c2011-05-14 19:02:06 +000050namespace {
51
Tobias Grosser73600b82011-10-08 00:30:40 +000052 class IslScheduleOptimizer : public ScopPass {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000053
54 public:
55 static char ID;
Tobias Grosser73600b82011-10-08 00:30:40 +000056 explicit IslScheduleOptimizer() : ScopPass(ID) {}
Tobias Grosser30aa24c2011-05-14 19:02:06 +000057
58 virtual bool runOnScop(Scop &S);
59 void printScop(llvm::raw_ostream &OS) const;
60 void getAnalysisUsage(AnalysisUsage &AU) const;
61 };
62
63}
64
Tobias Grosser73600b82011-10-08 00:30:40 +000065char IslScheduleOptimizer::ID = 0;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000066
67static int getSingleMap(__isl_take isl_map *map, void *user) {
68 isl_map **singleMap = (isl_map **) user;
69 *singleMap = map;
70
71 return 0;
72}
73
Tobias Grossercf3942d2011-10-06 00:04:05 +000074static void extendScattering(Scop &S, unsigned NewDimensions) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +000075 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
Tobias Grossercf3942d2011-10-06 00:04:05 +000076 ScopStmt *Stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +000077
Tobias Grossercf3942d2011-10-06 00:04:05 +000078 if (Stmt->isFinalRead())
Tobias Grosser30aa24c2011-05-14 19:02:06 +000079 continue;
80
Tobias Grossercf3942d2011-10-06 00:04:05 +000081 unsigned OldDimensions = Stmt->getNumScattering();
82 isl_space *Space;
83 isl_basic_map *ChangeScattering;
84
85 Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions);
86 ChangeScattering = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserf5338802011-10-06 00:03:35 +000087 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000088
Tobias Grossercf3942d2011-10-06 00:04:05 +000089 for (unsigned i = 0; i < OldDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000090 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000091 isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
92 isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);
Tobias Grossercf3942d2011-10-06 00:04:05 +000093 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +000094 }
95
Tobias Grossercf3942d2011-10-06 00:04:05 +000096 for (unsigned i = OldDimensions; i < NewDimensions; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +000097 isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosser30aa24c2011-05-14 19:02:06 +000098 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
Tobias Grossercf3942d2011-10-06 00:04:05 +000099 ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000100 }
101
Tobias Grossercf3942d2011-10-06 00:04:05 +0000102 isl_map *ChangeScatteringMap = isl_map_from_basic_map(ChangeScattering);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000103
Tobias Grossercf3942d2011-10-06 00:04:05 +0000104 ChangeScatteringMap = isl_map_align_params(ChangeScatteringMap,
105 S.getParamSpace());
106 isl_map *NewScattering = isl_map_apply_range(Stmt->getScattering(),
107 ChangeScatteringMap);
108 Stmt->setScattering(NewScattering);
Tobias Grosserf5338802011-10-06 00:03:35 +0000109 isl_local_space_free(LocalSpace);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000110 }
111}
112
Tobias Grosserde68cc92011-06-30 20:01:02 +0000113// getTileMap - Create a map that describes a n-dimensonal tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000114//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000115// getTileMap creates a map from a n-dimensional scattering space into an
116// 2*n-dimensional scattering space. The map describes a rectangular tiling.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000117//
Tobias Grosserde68cc92011-06-30 20:01:02 +0000118// Example:
119// scheduleDimensions = 2, parameterDimensions = 1, tileSize = 32
120//
121// tileMap := [p0] -> {[s0, s1] -> [t0, t1, s0, s1]:
122// t0 % 32 = 0 and t0 <= s0 < t0 + 32 and
123// t1 % 32 = 0 and t1 <= s1 < t1 + 32}
124//
125// Before tiling:
126//
127// for (i = 0; i < N; i++)
128// for (j = 0; j < M; j++)
129// S(i,j)
130//
131// After tiling:
132//
133// for (t_i = 0; t_i < N; i+=32)
134// for (t_j = 0; t_j < M; j+=32)
135// for (i = t_i; i < min(t_i + 32, N); i++) | Unknown that N % 32 = 0
136// for (j = t_j; j < t_j + 32; j++) | Known that M % 32 = 0
137// S(i,j)
138//
139static isl_basic_map *getTileMap(isl_ctx *ctx, int scheduleDimensions,
Tobias Grosserf5338802011-10-06 00:03:35 +0000140 isl_space *SpaceModel, int tileSize = 32) {
Tobias Grosserde68cc92011-06-30 20:01:02 +0000141 // We construct
142 //
143 // tileMap := [p0] -> {[s0, s1] -> [t0, t1, p0, p1, a0, a1]:
144 // s0 = a0 * 32 and s0 = p0 and t0 <= p0 < t0 + 32 and
145 // s1 = a1 * 32 and s1 = p1 and t1 <= p1 < t1 + 32}
146 //
147 // and project out the auxilary dimensions a0 and a1.
Tobias Grosserf5338802011-10-06 00:03:35 +0000148 isl_space *Space = isl_space_alloc(ctx, 0, scheduleDimensions,
149 scheduleDimensions * 3);
150 isl_basic_map *tileMap = isl_basic_map_universe(isl_space_copy(Space));
151
152 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000153
Tobias Grosserde68cc92011-06-30 20:01:02 +0000154 for (int x = 0; x < scheduleDimensions; x++) {
155 int sX = x;
156 int tX = x;
157 int pX = scheduleDimensions + x;
158 int aX = 2 * scheduleDimensions + x;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000159
Tobias Grosserde68cc92011-06-30 20:01:02 +0000160 isl_constraint *c;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000161
Tobias Grosserde68cc92011-06-30 20:01:02 +0000162 // sX = aX * tileSize;
Tobias Grosserf5338802011-10-06 00:03:35 +0000163 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000164 isl_constraint_set_coefficient_si(c, isl_dim_out, sX, 1);
165 isl_constraint_set_coefficient_si(c, isl_dim_out, aX, -tileSize);
166 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000167
Tobias Grosserde68cc92011-06-30 20:01:02 +0000168 // pX = sX;
Tobias Grosserf5338802011-10-06 00:03:35 +0000169 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000170 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
171 isl_constraint_set_coefficient_si(c, isl_dim_in, sX, -1);
172 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000173
Tobias Grosserde68cc92011-06-30 20:01:02 +0000174 // tX <= pX
Tobias Grosserf5338802011-10-06 00:03:35 +0000175 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000176 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1);
177 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, -1);
178 tileMap = isl_basic_map_add_constraint(tileMap, c);
179
180 // pX <= tX + (tileSize - 1)
Tobias Grosserf5338802011-10-06 00:03:35 +0000181 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserde68cc92011-06-30 20:01:02 +0000182 isl_constraint_set_coefficient_si(c, isl_dim_out, tX, 1);
183 isl_constraint_set_coefficient_si(c, isl_dim_out, pX, -1);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000184 isl_constraint_set_constant_si(c, tileSize - 1);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000185 tileMap = isl_basic_map_add_constraint(tileMap, c);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000186 }
187
Tobias Grosserde68cc92011-06-30 20:01:02 +0000188 // Project out auxilary dimensions.
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000189 //
Tobias Grosserde68cc92011-06-30 20:01:02 +0000190 // The auxilary dimensions are transformed into existentially quantified ones.
191 // This reduces the number of visible scattering dimensions and allows Cloog
192 // to produces better code.
193 tileMap = isl_basic_map_project_out(tileMap, isl_dim_out,
194 2 * scheduleDimensions,
195 scheduleDimensions);
Tobias Grosserf5338802011-10-06 00:03:35 +0000196 isl_local_space_free(LocalSpace);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000197 return tileMap;
198}
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000199
Tobias Grosserde68cc92011-06-30 20:01:02 +0000200isl_union_map *getTiledPartialSchedule(isl_band *band) {
201 isl_union_map *partialSchedule;
Tobias Grosserc532f122011-08-25 08:40:59 +0000202 int scheduleDimensions;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000203 isl_ctx *ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +0000204 isl_space *Space;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000205 isl_basic_map *tileMap;
206 isl_union_map *tileUnionMap;
207
208 partialSchedule = isl_band_get_partial_schedule(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000209
Tobias Grosser79b30202011-11-17 12:56:00 +0000210 if (DisableTiling)
211 return partialSchedule;
Tobias Grosser353a2682011-10-23 20:59:26 +0000212
Tobias Grosser79b30202011-11-17 12:56:00 +0000213 ctx = isl_union_map_get_ctx(partialSchedule);
214 Space = isl_union_map_get_space(partialSchedule);
215 scheduleDimensions = isl_band_n_member(band);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000216
Tobias Grosser79b30202011-11-17 12:56:00 +0000217 tileMap = getTileMap(ctx, scheduleDimensions, Space);
218 tileUnionMap = isl_union_map_from_map(isl_map_from_basic_map(tileMap));
219 tileUnionMap = isl_union_map_align_params(tileUnionMap, Space);
220 return isl_union_map_apply_range(partialSchedule, tileUnionMap);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000221}
222
Tobias Grosserc6699b72011-06-30 20:29:13 +0000223static isl_map *getPrevectorMap(isl_ctx *ctx, int vectorDimension,
224 int scheduleDimensions,
225 int parameterDimensions,
226 int vectorWidth = 4) {
Tobias Grosser2bd3af12011-08-01 22:39:00 +0000227 assert (0 <= vectorDimension && vectorDimension < scheduleDimensions);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000228
Tobias Grosserf5338802011-10-06 00:03:35 +0000229 isl_space *Space = isl_space_alloc(ctx, parameterDimensions,
230 scheduleDimensions, scheduleDimensions + 2);
231 isl_basic_map *tilingMap = isl_basic_map_universe(isl_space_copy(Space));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000232
233 isl_constraint *c;
234
Tobias Grosserf5338802011-10-06 00:03:35 +0000235 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
236
Tobias Grosserc6699b72011-06-30 20:29:13 +0000237 for (int i = 0; i < vectorDimension; i++) {
Tobias Grosserf5338802011-10-06 00:03:35 +0000238 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000239 isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1);
240 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
241 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
242 }
243
244 for (int i = vectorDimension + 1; i < scheduleDimensions; i++) {
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_in, i, -1);
247 isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1);
248 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
249 }
250
251 int stepDimension = scheduleDimensions;
252 int auxilaryDimension = scheduleDimensions + 1;
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_out, vectorDimension, 1);
256 isl_constraint_set_coefficient_si(c, isl_dim_out, auxilaryDimension,
257 -vectorWidth);
258 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
259
Tobias Grosserf5338802011-10-06 00:03:35 +0000260 c = isl_equality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000261 isl_constraint_set_coefficient_si(c, isl_dim_in, vectorDimension, -1);
262 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
263 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
264
Tobias Grosserf5338802011-10-06 00:03:35 +0000265 c = isl_inequality_alloc(isl_local_space_copy(LocalSpace));
Tobias Grosserc6699b72011-06-30 20:29:13 +0000266 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, -1);
267 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, 1);
268 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
269
Tobias Grosserf5338802011-10-06 00:03:35 +0000270 c = isl_inequality_alloc(LocalSpace);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000271 isl_constraint_set_coefficient_si(c, isl_dim_out, vectorDimension, 1);
272 isl_constraint_set_coefficient_si(c, isl_dim_out, stepDimension, -1);
273 isl_constraint_set_constant_si(c, vectorWidth- 1);
274 tilingMap = isl_basic_map_add_constraint(tilingMap, c);
275
276 // Project out auxilary dimensions (introduced to ensure 'ii % tileSize = 0')
277 //
278 // The real dimensions are transformed into existentially quantified ones.
279 // This reduces the number of visible scattering dimensions. Also, Cloog
280 // produces better code, if auxilary dimensions are existentially quantified.
281 tilingMap = isl_basic_map_project_out(tilingMap, isl_dim_out,
282 scheduleDimensions + 1, 1);
283
284 return isl_map_from_basic_map(tilingMap);
285}
286
Tobias Grosserde68cc92011-06-30 20:01:02 +0000287// tileBandList - Tile all bands contained in a band forest.
288//
289// Recursively walk the band forest and tile all bands in the forest. Return
290// a schedule that describes the tiled scattering.
291static isl_union_map *tileBandList(isl_band_list *blist) {
292 int numBands = isl_band_list_n_band(blist);
293
294 isl_union_map *finalSchedule = 0;
295
296 for (int i = 0; i < numBands; i++) {
297 isl_band *band;
298 isl_union_map *partialSchedule;
299 band = isl_band_list_get_band(blist, i);
300 partialSchedule = getTiledPartialSchedule(band);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000301 int scheduleDimensions = isl_band_n_member(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000302 isl_space *Space = isl_union_map_get_space(partialSchedule);
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000303
Tobias Grosserde68cc92011-06-30 20:01:02 +0000304
305 if (isl_band_has_children(band)) {
306 isl_band_list *children = isl_band_get_children(band);
307 isl_union_map *suffixSchedule = tileBandList(children);
308 partialSchedule = isl_union_map_flat_range_product(partialSchedule,
309 suffixSchedule);
Tobias Grossera9542422011-08-23 22:35:23 +0000310 isl_band_list_free(children);
Tobias Grosser67707b72011-10-23 20:59:40 +0000311 } else if (EnablePollyVector) {
Tobias Grosserc6699b72011-06-30 20:29:13 +0000312 isl_map *tileMap;
313 isl_union_map *tileUnionMap;
314 isl_ctx *ctx;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000315
316 ctx = isl_union_map_get_ctx(partialSchedule);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000317 for (int i = scheduleDimensions - 1 ; i >= 0 ; i--) {
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000318 if (isl_band_member_is_zero_distance(band, i)) {
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000319 tileMap = getPrevectorMap(ctx, scheduleDimensions + i,
Tobias Grosserc532f122011-08-25 08:40:59 +0000320 scheduleDimensions * 2, 0);
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000321 tileUnionMap = isl_union_map_from_map(tileMap);
Tobias Grosserc532f122011-08-25 08:40:59 +0000322 tileUnionMap = isl_union_map_align_params(tileUnionMap,
Tobias Grosserf5338802011-10-06 00:03:35 +0000323 isl_space_copy(Space));
Tobias Grosser7c5ba832011-06-30 20:29:20 +0000324 partialSchedule = isl_union_map_apply_range(partialSchedule,
325 tileUnionMap);
326 break;
327 }
328 }
Tobias Grosserde68cc92011-06-30 20:01:02 +0000329 }
330
331 if (finalSchedule)
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000332 finalSchedule = isl_union_map_union(finalSchedule, partialSchedule);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000333 else
334 finalSchedule = partialSchedule;
335
336 isl_band_free(band);
Tobias Grosserf5338802011-10-06 00:03:35 +0000337 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000338 }
339
340 return finalSchedule;
341}
342
343static isl_union_map *tileSchedule(isl_schedule *schedule) {
344 isl_band_list *blist = isl_schedule_get_band_forest(schedule);
345 isl_union_map *tiledSchedule = tileBandList(blist);
346 isl_band_list_free(blist);
347 return tiledSchedule;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000348}
349
Tobias Grosser73600b82011-10-08 00:30:40 +0000350bool IslScheduleOptimizer::runOnScop(Scop &S) {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000351 Dependences *D = &getAnalysis<Dependences>();
352
353 // Build input data.
354 int dependencyKinds = Dependences::TYPE_RAW
355 | Dependences::TYPE_WAR
356 | Dependences::TYPE_WAW;
357
358 isl_union_map *validity = D->getDependences(dependencyKinds);
359 isl_union_map *proximity = D->getDependences(dependencyKinds);
360 isl_union_set *domain = NULL;
361
362 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
363 if ((*SI)->isFinalRead())
364 continue;
365 else if (!domain)
366 domain = isl_union_set_from_set((*SI)->getDomain());
367 else
368 domain = isl_union_set_union(domain,
369 isl_union_set_from_set((*SI)->getDomain()));
370
371 if (!domain)
372 return false;
373
374 DEBUG(dbgs() << "\n\nCompute schedule from: ");
375 DEBUG(dbgs() << "Domain := "; isl_union_set_dump(domain); dbgs() << ";\n");
376 DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(proximity);
377 dbgs() << ";\n");
378 DEBUG(dbgs() << "Validity := "; isl_union_map_dump(validity);
379 dbgs() << ";\n");
380
381 isl_schedule *schedule;
382
383 schedule = isl_union_set_compute_schedule(domain, validity, proximity);
384
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000385 DEBUG(dbgs() << "Computed schedule: ");
Tobias Grosserde68cc92011-06-30 20:01:02 +0000386 DEBUG(dbgs() << stringFromIslObj(schedule));
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000387 DEBUG(dbgs() << "Individual bands: ");
388
Tobias Grosserde68cc92011-06-30 20:01:02 +0000389 isl_union_map *tiledSchedule = tileSchedule(schedule);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000390
Tobias Grosserde68cc92011-06-30 20:01:02 +0000391 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
392 ScopStmt *stmt = *SI;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000393
Tobias Grosserde68cc92011-06-30 20:01:02 +0000394 if (stmt->isFinalRead())
395 continue;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000396
Tobias Grosserde68cc92011-06-30 20:01:02 +0000397 isl_set *domain = stmt->getDomain();
398 isl_union_map *stmtBand;
399 stmtBand = isl_union_map_intersect_domain(isl_union_map_copy(tiledSchedule),
400 isl_union_set_from_set(domain));
401 isl_map *stmtSchedule;
402 isl_union_map_foreach_map(stmtBand, getSingleMap, &stmtSchedule);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000403 stmt->setScattering(stmtSchedule);
Tobias Grosser6e0fdca2011-08-23 12:31:14 +0000404 isl_union_map_free(stmtBand);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000405 }
406
Tobias Grosserde68cc92011-06-30 20:01:02 +0000407 isl_union_map_free(tiledSchedule);
408 isl_schedule_free(schedule);
409
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000410 unsigned maxScatDims = 0;
411
412 for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI)
Tobias Grossercf3942d2011-10-06 00:04:05 +0000413 maxScatDims = std::max((*SI)->getNumScattering(), maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000414
415 extendScattering(S, maxScatDims);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000416 return false;
417}
418
Tobias Grosser73600b82011-10-08 00:30:40 +0000419void IslScheduleOptimizer::printScop(raw_ostream &OS) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000420}
421
Tobias Grosser73600b82011-10-08 00:30:40 +0000422void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000423 ScopPass::getAnalysisUsage(AU);
424 AU.addRequired<Dependences>();
425}
426
Tobias Grosser73600b82011-10-08 00:30:40 +0000427INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-optimize-isl",
428 "Polly - Optimize schedule of SCoP", false, false)
429INITIALIZE_PASS_DEPENDENCY(Dependences)
430INITIALIZE_PASS_DEPENDENCY(ScopInfo)
431INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-optimize-isl",
432 "Polly - Optimize schedule of SCoP", false, false)
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000433
Tobias Grosser73600b82011-10-08 00:30:40 +0000434Pass* polly::createIslScheduleOptimizerPass() {
435 return new IslScheduleOptimizer();
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000436}