Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 1 | //===- 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 Grosser | 967239c | 2011-10-23 20:59:44 +0000 | [diff] [blame] | 20 | #include "polly/ScheduleOptimizer.h" |
| 21 | |
Tobias Grosser | 67707b7 | 2011-10-23 20:59:40 +0000 | [diff] [blame] | 22 | #include "polly/CodeGeneration.h" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 23 | #include "polly/Dependences.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 24 | #include "polly/LinkAllPasses.h" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 25 | #include "polly/ScopInfo.h" |
| 26 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 27 | #include "isl/aff.h" |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 28 | #include "isl/band.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 29 | #include "isl/constraint.h" |
| 30 | #include "isl/map.h" |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 31 | #include "isl/options.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 32 | #include "isl/schedule.h" |
| 33 | #include "isl/space.h" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 34 | |
Tobias Grosser | 4dca439 | 2011-11-22 19:40:19 +0000 | [diff] [blame] | 35 | #define DEBUG_TYPE "polly-opt-isl" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 36 | #include "llvm/Support/Debug.h" |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 37 | #include "llvm/Support/CommandLine.h" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 38 | |
| 39 | using namespace llvm; |
| 40 | using namespace polly; |
| 41 | |
Tobias Grosser | 967239c | 2011-10-23 20:59:44 +0000 | [diff] [blame] | 42 | namespace polly { |
| 43 | bool DisablePollyTiling; |
| 44 | } |
| 45 | static cl::opt<bool, true> |
Tobias Grosser | 353a268 | 2011-10-23 20:59:26 +0000 | [diff] [blame] | 46 | DisableTiling("polly-no-tiling", |
Tobias Grosser | 967239c | 2011-10-23 20:59:44 +0000 | [diff] [blame] | 47 | cl::desc("Disable tiling in the scheduler"), cl::Hidden, |
| 48 | cl::location(polly::DisablePollyTiling), cl::init(false)); |
Tobias Grosser | 353a268 | 2011-10-23 20:59:26 +0000 | [diff] [blame] | 49 | |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 50 | static cl::opt<std::string> |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 51 | OptimizeDeps("polly-opt-optimize-only", |
| 52 | cl::desc("Only a certain kind of dependences (all/raw)"), |
| 53 | cl::Hidden, cl::init("all")); |
| 54 | |
| 55 | static cl::opt<std::string> |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 56 | SimplifyDeps("polly-opt-simplify-deps", |
| 57 | cl::desc("Dependences should be simplified (yes/no)"), |
| 58 | cl::Hidden, cl::init("yes")); |
| 59 | |
Tobias Grosser | 992e60c | 2012-02-20 08:41:15 +0000 | [diff] [blame] | 60 | static cl::opt<int> |
| 61 | MaxConstantTerm("polly-opt-max-constant-term", |
| 62 | cl::desc("The maximal constant term allowed (-1 is unlimited)"), |
| 63 | cl::Hidden, cl::init(20)); |
| 64 | |
Tobias Grosser | 92f5480 | 2012-02-20 08:41:47 +0000 | [diff] [blame] | 65 | static cl::opt<int> |
| 66 | MaxCoefficient("polly-opt-max-coefficient", |
| 67 | cl::desc("The maximal coefficient allowed (-1 is unlimited)"), |
| 68 | cl::Hidden, cl::init(20)); |
| 69 | |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 70 | static cl::opt<std::string> |
| 71 | FusionStrategy("polly-opt-fusion", |
| 72 | cl::desc("The fusion strategy to choose (min/max)"), |
Tobias Grosser | 50ff31d | 2012-01-30 19:38:58 +0000 | [diff] [blame] | 73 | cl::Hidden, cl::init("min")); |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 74 | |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 75 | static cl::opt<std::string> |
Tobias Grosser | a4ea90b | 2012-01-30 22:43:56 +0000 | [diff] [blame] | 76 | MaximizeBandDepth("polly-opt-maximize-bands", |
| 77 | cl::desc("Maximize the band depth (yes/no)"), |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 78 | cl::Hidden, cl::init("yes")); |
| 79 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 80 | namespace { |
| 81 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 82 | class IslScheduleOptimizer : public ScopPass { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 83 | |
| 84 | public: |
| 85 | static char ID; |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 86 | explicit IslScheduleOptimizer() : ScopPass(ID) {} |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 87 | |
| 88 | virtual bool runOnScop(Scop &S); |
| 89 | void printScop(llvm::raw_ostream &OS) const; |
| 90 | void getAnalysisUsage(AnalysisUsage &AU) const; |
| 91 | }; |
| 92 | |
| 93 | } |
| 94 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 95 | char IslScheduleOptimizer::ID = 0; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 96 | |
| 97 | static int getSingleMap(__isl_take isl_map *map, void *user) { |
| 98 | isl_map **singleMap = (isl_map **) user; |
| 99 | *singleMap = map; |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 104 | static void extendScattering(Scop &S, unsigned NewDimensions) { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 105 | for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) { |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 106 | ScopStmt *Stmt = *SI; |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 107 | unsigned OldDimensions = Stmt->getNumScattering(); |
| 108 | isl_space *Space; |
| 109 | isl_basic_map *ChangeScattering; |
| 110 | |
| 111 | Space = isl_space_alloc(Stmt->getIslCtx(), 0, OldDimensions, NewDimensions); |
| 112 | ChangeScattering = isl_basic_map_universe(isl_space_copy(Space)); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 113 | isl_local_space *LocalSpace = isl_local_space_from_space(Space); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 114 | |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 115 | for (unsigned i = 0; i < OldDimensions; i++) { |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 116 | isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 117 | isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1); |
| 118 | isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1); |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 119 | ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 122 | for (unsigned i = OldDimensions; i < NewDimensions; i++) { |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 123 | isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 124 | isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1); |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 125 | ChangeScattering = isl_basic_map_add_constraint(ChangeScattering, c); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 128 | isl_map *ChangeScatteringMap = isl_map_from_basic_map(ChangeScattering); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 129 | |
Tobias Grosser | cf3942d | 2011-10-06 00:04:05 +0000 | [diff] [blame] | 130 | ChangeScatteringMap = isl_map_align_params(ChangeScatteringMap, |
| 131 | S.getParamSpace()); |
| 132 | isl_map *NewScattering = isl_map_apply_range(Stmt->getScattering(), |
| 133 | ChangeScatteringMap); |
| 134 | Stmt->setScattering(NewScattering); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 135 | isl_local_space_free(LocalSpace); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 139 | // getTileMap - Create a map that describes a n-dimensonal tiling. |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 140 | // |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 141 | // getTileMap creates a map from a n-dimensional scattering space into an |
| 142 | // 2*n-dimensional scattering space. The map describes a rectangular tiling. |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 143 | // |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 144 | // Example: |
| 145 | // scheduleDimensions = 2, parameterDimensions = 1, tileSize = 32 |
| 146 | // |
| 147 | // tileMap := [p0] -> {[s0, s1] -> [t0, t1, s0, s1]: |
| 148 | // t0 % 32 = 0 and t0 <= s0 < t0 + 32 and |
| 149 | // t1 % 32 = 0 and t1 <= s1 < t1 + 32} |
| 150 | // |
| 151 | // Before tiling: |
| 152 | // |
| 153 | // for (i = 0; i < N; i++) |
| 154 | // for (j = 0; j < M; j++) |
| 155 | // S(i,j) |
| 156 | // |
| 157 | // After tiling: |
| 158 | // |
| 159 | // for (t_i = 0; t_i < N; i+=32) |
| 160 | // for (t_j = 0; t_j < M; j+=32) |
| 161 | // for (i = t_i; i < min(t_i + 32, N); i++) | Unknown that N % 32 = 0 |
| 162 | // for (j = t_j; j < t_j + 32; j++) | Known that M % 32 = 0 |
| 163 | // S(i,j) |
| 164 | // |
| 165 | static isl_basic_map *getTileMap(isl_ctx *ctx, int scheduleDimensions, |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 166 | isl_space *SpaceModel, int tileSize = 32) { |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 167 | // We construct |
| 168 | // |
| 169 | // tileMap := [p0] -> {[s0, s1] -> [t0, t1, p0, p1, a0, a1]: |
| 170 | // s0 = a0 * 32 and s0 = p0 and t0 <= p0 < t0 + 32 and |
| 171 | // s1 = a1 * 32 and s1 = p1 and t1 <= p1 < t1 + 32} |
| 172 | // |
| 173 | // and project out the auxilary dimensions a0 and a1. |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 174 | isl_space *Space = isl_space_alloc(ctx, 0, scheduleDimensions, |
| 175 | scheduleDimensions * 3); |
| 176 | isl_basic_map *tileMap = isl_basic_map_universe(isl_space_copy(Space)); |
| 177 | |
| 178 | isl_local_space *LocalSpace = isl_local_space_from_space(Space); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 179 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 180 | for (int x = 0; x < scheduleDimensions; x++) { |
| 181 | int sX = x; |
| 182 | int tX = x; |
| 183 | int pX = scheduleDimensions + x; |
| 184 | int aX = 2 * scheduleDimensions + x; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 185 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 186 | isl_constraint *c; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 187 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 188 | // sX = aX * tileSize; |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 189 | c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 190 | isl_constraint_set_coefficient_si(c, isl_dim_out, sX, 1); |
| 191 | isl_constraint_set_coefficient_si(c, isl_dim_out, aX, -tileSize); |
| 192 | tileMap = isl_basic_map_add_constraint(tileMap, c); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 193 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 194 | // pX = sX; |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 195 | c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 196 | isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1); |
| 197 | isl_constraint_set_coefficient_si(c, isl_dim_in, sX, -1); |
| 198 | tileMap = isl_basic_map_add_constraint(tileMap, c); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 199 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 200 | // tX <= pX |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 201 | c = isl_inequality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 202 | isl_constraint_set_coefficient_si(c, isl_dim_out, pX, 1); |
| 203 | isl_constraint_set_coefficient_si(c, isl_dim_out, tX, -1); |
| 204 | tileMap = isl_basic_map_add_constraint(tileMap, c); |
| 205 | |
| 206 | // pX <= tX + (tileSize - 1) |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 207 | c = isl_inequality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 208 | isl_constraint_set_coefficient_si(c, isl_dim_out, tX, 1); |
| 209 | isl_constraint_set_coefficient_si(c, isl_dim_out, pX, -1); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 210 | isl_constraint_set_constant_si(c, tileSize - 1); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 211 | tileMap = isl_basic_map_add_constraint(tileMap, c); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 214 | // Project out auxilary dimensions. |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 215 | // |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 216 | // The auxilary dimensions are transformed into existentially quantified ones. |
| 217 | // This reduces the number of visible scattering dimensions and allows Cloog |
| 218 | // to produces better code. |
| 219 | tileMap = isl_basic_map_project_out(tileMap, isl_dim_out, |
| 220 | 2 * scheduleDimensions, |
| 221 | scheduleDimensions); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 222 | isl_local_space_free(LocalSpace); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 223 | return tileMap; |
| 224 | } |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 225 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 226 | // getScheduleForBand - Get the schedule for this band. |
| 227 | // |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 228 | // Polly applies transformations like tiling on top of the isl calculated value. |
| 229 | // This can influence the number of scheduling dimension. The number of |
| 230 | // schedule dimensions is returned in the parameter 'Dimension'. |
| 231 | isl_union_map *getScheduleForBand(isl_band *Band, int *Dimensions) { |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 232 | isl_union_map *PartialSchedule; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 233 | isl_ctx *ctx; |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 234 | isl_space *Space; |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 235 | isl_basic_map *TileMap; |
| 236 | isl_union_map *TileUMap; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 237 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 238 | PartialSchedule = isl_band_get_partial_schedule(Band); |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 239 | *Dimensions = isl_band_n_member(Band); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 240 | |
Tobias Grosser | 79b3020 | 2011-11-17 12:56:00 +0000 | [diff] [blame] | 241 | if (DisableTiling) |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 242 | return PartialSchedule; |
Tobias Grosser | 353a268 | 2011-10-23 20:59:26 +0000 | [diff] [blame] | 243 | |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 244 | // It does not make any sense to tile a band with just one dimension. |
| 245 | if (*Dimensions == 1) |
| 246 | return PartialSchedule; |
| 247 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 248 | ctx = isl_union_map_get_ctx(PartialSchedule); |
| 249 | Space = isl_union_map_get_space(PartialSchedule); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 250 | |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 251 | TileMap = getTileMap(ctx, *Dimensions, Space); |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 252 | TileUMap = isl_union_map_from_map(isl_map_from_basic_map(TileMap)); |
| 253 | TileUMap = isl_union_map_align_params(TileUMap, Space); |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 254 | *Dimensions = 2 * *Dimensions; |
| 255 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 256 | return isl_union_map_apply_range(PartialSchedule, TileUMap); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 259 | // Create a map that pre-vectorizes one scheduling dimension. |
| 260 | // |
| 261 | // getPrevectorMap creates a map that maps each input dimension to the same |
| 262 | // output dimension, except for the dimension DimToVectorize. DimToVectorize is |
| 263 | // strip mined by 'VectorWidth' and the newly created point loop of |
| 264 | // DimToVectorize is moved to the innermost level. |
| 265 | // |
| 266 | // Example (DimToVectorize=0, ScheduleDimensions=2, VectorWidth=4): |
| 267 | // |
| 268 | // | Before transformation |
| 269 | // | |
| 270 | // | A[i,j] -> [i,j] |
| 271 | // | |
| 272 | // | for (i = 0; i < 128; i++) |
| 273 | // | for (j = 0; j < 128; j++) |
| 274 | // | A(i,j); |
| 275 | // |
| 276 | // Prevector map: |
| 277 | // [i,j] -> [it,j,ip] : it % 4 = 0 and it <= ip <= it + 3 and i = ip |
| 278 | // |
| 279 | // | After transformation: |
| 280 | // | |
| 281 | // | A[i,j] -> [it,j,ip] : it % 4 = 0 and it <= ip <= it + 3 and i = ip |
| 282 | // | |
| 283 | // | for (it = 0; it < 128; it+=4) |
| 284 | // | for (j = 0; j < 128; j++) |
| 285 | // | for (ip = max(0,it); ip < min(128, it + 3); ip++) |
| 286 | // | A(ip,j); |
| 287 | // |
| 288 | // The goal of this transformation is to create a trivially vectorizable loop. |
| 289 | // This means a parallel loop at the innermost level that has a constant number |
| 290 | // of iterations corresponding to the target vector width. |
| 291 | // |
| 292 | // This transformation creates a loop at the innermost level. The loop has a |
| 293 | // constant number of iterations, if the number of loop iterations at |
Tobias Grosser | f9fbbdf | 2012-04-09 19:46:05 +0000 | [diff] [blame] | 294 | // DimToVectorize can be divided by VectorWidth. The default VectorWidth is |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 295 | // currently constant and not yet target specific. This function does not reason |
| 296 | // about parallelism. |
| 297 | static isl_map *getPrevectorMap(isl_ctx *ctx, int DimToVectorize, |
| 298 | int ScheduleDimensions, |
| 299 | int VectorWidth = 4) { |
| 300 | isl_space *Space; |
| 301 | isl_local_space *LocalSpace, *LocalSpaceRange; |
| 302 | isl_set *Modulo; |
| 303 | isl_map *TilingMap; |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 304 | isl_constraint *c; |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 305 | isl_aff *Aff; |
| 306 | int PointDimension; /* ip */ |
| 307 | int TileDimension; /* it */ |
| 308 | isl_int VectorWidthMP; |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 309 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 310 | assert (0 <= DimToVectorize && DimToVectorize < ScheduleDimensions); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 311 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 312 | Space = isl_space_alloc(ctx, 0, ScheduleDimensions, ScheduleDimensions + 1); |
| 313 | TilingMap = isl_map_universe(isl_space_copy(Space)); |
| 314 | LocalSpace = isl_local_space_from_space(Space); |
| 315 | PointDimension = ScheduleDimensions; |
| 316 | TileDimension = DimToVectorize; |
| 317 | |
| 318 | // Create an identity map for everything except DimToVectorize and map |
| 319 | // DimToVectorize to the point loop at the innermost dimension. |
| 320 | for (int i = 0; i < ScheduleDimensions; i++) { |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 321 | c = isl_equality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 322 | isl_constraint_set_coefficient_si(c, isl_dim_in, i, -1); |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 323 | |
| 324 | if (i == DimToVectorize) |
| 325 | isl_constraint_set_coefficient_si(c, isl_dim_out, PointDimension, 1); |
| 326 | else |
| 327 | isl_constraint_set_coefficient_si(c, isl_dim_out, i, 1); |
| 328 | |
| 329 | TilingMap = isl_map_add_constraint(TilingMap, c); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 332 | // it % 'VectorWidth' = 0 |
| 333 | LocalSpaceRange = isl_local_space_range(isl_local_space_copy(LocalSpace)); |
| 334 | Aff = isl_aff_zero_on_domain(LocalSpaceRange); |
| 335 | Aff = isl_aff_set_constant_si(Aff, VectorWidth); |
| 336 | Aff = isl_aff_set_coefficient_si(Aff, isl_dim_in, TileDimension, 1); |
| 337 | isl_int_init(VectorWidthMP); |
| 338 | isl_int_set_si(VectorWidthMP, VectorWidth); |
| 339 | Aff = isl_aff_mod(Aff, VectorWidthMP); |
| 340 | isl_int_clear(VectorWidthMP); |
| 341 | Modulo = isl_pw_aff_zero_set(isl_pw_aff_from_aff(Aff)); |
| 342 | TilingMap = isl_map_intersect_range(TilingMap, Modulo); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 343 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 344 | // it <= ip |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 345 | c = isl_inequality_alloc(isl_local_space_copy(LocalSpace)); |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 346 | isl_constraint_set_coefficient_si(c, isl_dim_out, TileDimension, -1); |
| 347 | isl_constraint_set_coefficient_si(c, isl_dim_out, PointDimension, 1); |
| 348 | TilingMap = isl_map_add_constraint(TilingMap, c); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 349 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 350 | // ip <= it + ('VectorWidth' - 1) |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 351 | c = isl_inequality_alloc(LocalSpace); |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 352 | isl_constraint_set_coefficient_si(c, isl_dim_out, TileDimension, 1); |
| 353 | isl_constraint_set_coefficient_si(c, isl_dim_out, PointDimension, -1); |
| 354 | isl_constraint_set_constant_si(c, VectorWidth - 1); |
| 355 | TilingMap = isl_map_add_constraint(TilingMap, c); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 356 | |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 357 | return TilingMap; |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 358 | } |
| 359 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 360 | // getScheduleForBandList - Get the scheduling map for a list of bands. |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 361 | // |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 362 | // We walk recursively the forest of bands to combine the schedules of the |
| 363 | // individual bands to the overall schedule. In case tiling is requested, |
| 364 | // the individual bands are tiled. |
| 365 | static isl_union_map *getScheduleForBandList(isl_band_list *BandList) { |
| 366 | int NumBands; |
| 367 | isl_union_map *Schedule; |
| 368 | isl_ctx *ctx; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 369 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 370 | ctx = isl_band_list_get_ctx(BandList); |
| 371 | NumBands = isl_band_list_n_band(BandList); |
Tobias Grosser | 6287201 | 2011-11-17 12:56:04 +0000 | [diff] [blame] | 372 | Schedule = isl_union_map_empty(isl_space_params_alloc(ctx, 0)); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 373 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 374 | for (int i = 0; i < NumBands; i++) { |
| 375 | isl_band *Band; |
| 376 | isl_union_map *PartialSchedule; |
| 377 | int ScheduleDimensions; |
| 378 | isl_space *Space; |
Tobias Grosser | 44f19ac | 2011-07-05 22:15:53 +0000 | [diff] [blame] | 379 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 380 | Band = isl_band_list_get_band(BandList, i); |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 381 | PartialSchedule = getScheduleForBand(Band, &ScheduleDimensions); |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 382 | Space = isl_union_map_get_space(PartialSchedule); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 383 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 384 | if (isl_band_has_children(Band)) { |
| 385 | isl_band_list *Children; |
| 386 | isl_union_map *SuffixSchedule; |
| 387 | |
| 388 | Children = isl_band_get_children(Band); |
| 389 | SuffixSchedule = getScheduleForBandList(Children); |
| 390 | PartialSchedule = isl_union_map_flat_range_product(PartialSchedule, |
| 391 | SuffixSchedule); |
| 392 | isl_band_list_free(Children); |
Tobias Grosser | 67707b7 | 2011-10-23 20:59:40 +0000 | [diff] [blame] | 393 | } else if (EnablePollyVector) { |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 394 | for (int i = ScheduleDimensions - 1 ; i >= 0 ; i--) { |
| 395 | if (isl_band_member_is_zero_distance(Band, i)) { |
| 396 | isl_map *TileMap; |
| 397 | isl_union_map *TileUMap; |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 398 | |
Tobias Grosser | b603339 | 2011-12-08 13:02:58 +0000 | [diff] [blame] | 399 | TileMap = getPrevectorMap(ctx, i, ScheduleDimensions); |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 400 | TileUMap = isl_union_map_from_map(TileMap); |
| 401 | TileUMap = isl_union_map_align_params(TileUMap, |
| 402 | isl_space_copy(Space)); |
| 403 | PartialSchedule = isl_union_map_apply_range(PartialSchedule, |
| 404 | TileUMap); |
Tobias Grosser | 7c5ba83 | 2011-06-30 20:29:20 +0000 | [diff] [blame] | 405 | break; |
| 406 | } |
| 407 | } |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Tobias Grosser | 6287201 | 2011-11-17 12:56:04 +0000 | [diff] [blame] | 410 | Schedule = isl_union_map_union(Schedule, PartialSchedule); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 411 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 412 | isl_band_free(Band); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 413 | isl_space_free(Space); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 414 | } |
| 415 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 416 | return Schedule; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 419 | static isl_union_map *getScheduleMap(isl_schedule *Schedule) { |
| 420 | isl_band_list *BandList = isl_schedule_get_band_forest(Schedule); |
| 421 | isl_union_map *ScheduleMap = getScheduleForBandList(BandList); |
| 422 | isl_band_list_free(BandList); |
| 423 | return ScheduleMap; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 426 | bool IslScheduleOptimizer::runOnScop(Scop &S) { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 427 | Dependences *D = &getAnalysis<Dependences>(); |
| 428 | |
| 429 | // Build input data. |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 430 | int ValidityKinds = Dependences::TYPE_RAW | Dependences::TYPE_WAR |
| 431 | | Dependences::TYPE_WAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 432 | int ProximityKinds; |
| 433 | |
| 434 | if (OptimizeDeps == "all") |
| 435 | ProximityKinds = Dependences::TYPE_RAW | Dependences::TYPE_WAR |
| 436 | | Dependences::TYPE_WAW; |
| 437 | else if (OptimizeDeps == "raw") |
Tobias Grosser | 1e03ad7 | 2012-02-15 09:58:42 +0000 | [diff] [blame] | 438 | ProximityKinds = Dependences::TYPE_RAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 439 | else { |
| 440 | errs() << "Do not know how to optimize for '" << OptimizeDeps << "'" |
| 441 | << " Falling back to optimizing all dependences.\n"; |
| 442 | ProximityKinds = Dependences::TYPE_RAW | Dependences::TYPE_WAR |
| 443 | | Dependences::TYPE_WAW; |
| 444 | |
| 445 | } |
| 446 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 447 | |
Tobias Grosser | 5f9a762 | 2012-02-14 14:02:40 +0000 | [diff] [blame] | 448 | isl_union_set *Domain = S.getDomains(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 449 | |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 450 | if (!Domain) |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 451 | return false; |
| 452 | |
Tobias Grosser | 8a50702 | 2012-03-16 11:51:41 +0000 | [diff] [blame] | 453 | isl_union_map *Validity = D->getDependences(ValidityKinds); |
| 454 | isl_union_map *Proximity = D->getDependences(ProximityKinds); |
| 455 | |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 456 | // Simplify the dependences by removing the constraints introduced by the |
| 457 | // domains. This can speed up the scheduling time significantly, as large |
| 458 | // constant coefficients will be removed from the dependences. The |
| 459 | // introduction of some additional dependences reduces the possible |
| 460 | // transformations, but in most cases, such transformation do not seem to be |
| 461 | // interesting anyway. In some cases this option may stop the scheduler to |
| 462 | // find any schedule. |
| 463 | if (SimplifyDeps == "yes") { |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 464 | Validity = isl_union_map_gist_domain(Validity, isl_union_set_copy(Domain)); |
| 465 | Validity = isl_union_map_gist_range(Validity, isl_union_set_copy(Domain)); |
| 466 | Proximity = isl_union_map_gist_domain(Proximity, |
| 467 | isl_union_set_copy(Domain)); |
| 468 | Proximity = isl_union_map_gist_range(Proximity, isl_union_set_copy(Domain)); |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 469 | } else if (SimplifyDeps != "no") { |
| 470 | errs() << "warning: Option -polly-opt-simplify-deps should either be 'yes' " |
| 471 | "or 'no'. Falling back to default: 'yes'\n"; |
| 472 | } |
| 473 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 474 | DEBUG(dbgs() << "\n\nCompute schedule from: "); |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 475 | DEBUG(dbgs() << "Domain := "; isl_union_set_dump(Domain); dbgs() << ";\n"); |
| 476 | DEBUG(dbgs() << "Proximity := "; isl_union_map_dump(Proximity); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 477 | dbgs() << ";\n"); |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 478 | DEBUG(dbgs() << "Validity := "; isl_union_map_dump(Validity); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 479 | dbgs() << ";\n"); |
| 480 | |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 481 | int IslFusionStrategy; |
| 482 | |
| 483 | if (FusionStrategy == "max") { |
| 484 | IslFusionStrategy = ISL_SCHEDULE_FUSE_MAX; |
| 485 | } else if (FusionStrategy == "min") { |
| 486 | IslFusionStrategy = ISL_SCHEDULE_FUSE_MIN; |
| 487 | } else { |
| 488 | errs() << "warning: Unknown fusion strategy. Falling back to maximal " |
| 489 | "fusion.\n"; |
| 490 | IslFusionStrategy = ISL_SCHEDULE_FUSE_MAX; |
| 491 | } |
| 492 | |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 493 | int IslMaximizeBands; |
| 494 | |
Tobias Grosser | a4ea90b | 2012-01-30 22:43:56 +0000 | [diff] [blame] | 495 | if (MaximizeBandDepth == "yes") { |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 496 | IslMaximizeBands = 1; |
Tobias Grosser | a4ea90b | 2012-01-30 22:43:56 +0000 | [diff] [blame] | 497 | } else if (MaximizeBandDepth == "no") { |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 498 | IslMaximizeBands = 0; |
| 499 | } else { |
| 500 | errs() << "warning: Option -polly-opt-maximize-bands should either be 'yes'" |
| 501 | " or 'no'. Falling back to default: 'yes'\n"; |
| 502 | IslMaximizeBands = 1; |
| 503 | } |
| 504 | |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 505 | isl_options_set_schedule_fuse(S.getIslCtx(), IslFusionStrategy); |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 506 | isl_options_set_schedule_maximize_band_depth(S.getIslCtx(), IslMaximizeBands); |
Tobias Grosser | 992e60c | 2012-02-20 08:41:15 +0000 | [diff] [blame] | 507 | isl_options_set_schedule_max_constant_term(S.getIslCtx(), MaxConstantTerm); |
Tobias Grosser | 92f5480 | 2012-02-20 08:41:47 +0000 | [diff] [blame] | 508 | isl_options_set_schedule_max_coefficient(S.getIslCtx(), MaxCoefficient); |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 509 | |
| 510 | isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_CONTINUE); |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 511 | isl_schedule *Schedule; |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 512 | Schedule = isl_union_set_compute_schedule(Domain, Validity, Proximity); |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 513 | isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_ABORT); |
| 514 | |
| 515 | // In cases the scheduler is not able to optimize the code, we just do not |
| 516 | // touch the schedule. |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 517 | if (!Schedule) |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 518 | return false; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 519 | |
Tobias Grosser | 4d63b9d | 2012-02-20 08:41:21 +0000 | [diff] [blame] | 520 | DEBUG(dbgs() << "Schedule := "; isl_schedule_dump(Schedule); |
| 521 | dbgs() << ";\n"); |
| 522 | |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 523 | isl_union_map *ScheduleMap = getScheduleMap(Schedule); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 524 | |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 525 | for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) { |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 526 | ScopStmt *Stmt = *SI; |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 527 | isl_set *Domain = Stmt->getDomain(); |
| 528 | isl_union_map *StmtBand; |
| 529 | StmtBand = isl_union_map_intersect_domain(isl_union_map_copy(ScheduleMap), |
| 530 | isl_union_set_from_set(Domain)); |
| 531 | isl_map *StmtSchedule; |
| 532 | isl_union_map_foreach_map(StmtBand, getSingleMap, &StmtSchedule); |
| 533 | Stmt->setScattering(StmtSchedule); |
| 534 | isl_union_map_free(StmtBand); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Tobias Grosser | 1ae9a60 | 2011-11-17 12:56:03 +0000 | [diff] [blame] | 537 | isl_union_map_free(ScheduleMap); |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 538 | isl_schedule_free(Schedule); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 539 | |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 540 | unsigned MaxScatDims = 0; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 541 | |
| 542 | for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 543 | MaxScatDims = std::max((*SI)->getNumScattering(), MaxScatDims); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 544 | |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 545 | extendScattering(S, MaxScatDims); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 546 | return false; |
| 547 | } |
| 548 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 549 | void IslScheduleOptimizer::printScop(raw_ostream &OS) const { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 552 | void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 553 | ScopPass::getAnalysisUsage(AU); |
| 554 | AU.addRequired<Dependences>(); |
| 555 | } |
| 556 | |
Tobias Grosser | 4dca439 | 2011-11-22 19:40:19 +0000 | [diff] [blame] | 557 | INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-opt-isl", |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 558 | "Polly - Optimize schedule of SCoP", false, false) |
| 559 | INITIALIZE_PASS_DEPENDENCY(Dependences) |
| 560 | INITIALIZE_PASS_DEPENDENCY(ScopInfo) |
Tobias Grosser | 4dca439 | 2011-11-22 19:40:19 +0000 | [diff] [blame] | 561 | INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-opt-isl", |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 562 | "Polly - Optimize schedule of SCoP", false, false) |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 563 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 564 | Pass* polly::createIslScheduleOptimizerPass() { |
| 565 | return new IslScheduleOptimizer(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 566 | } |