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 | // |
Tobias Grosser | 234a482 | 2015-08-15 09:34:33 +0000 | [diff] [blame] | 10 | // This pass generates an entirey new schedule tree from the data dependences |
| 11 | // and iteration domains. The new schedule tree is computed in two steps: |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 12 | // |
Tobias Grosser | 234a482 | 2015-08-15 09:34:33 +0000 | [diff] [blame] | 13 | // 1) The isl scheduling optimizer is run |
| 14 | // |
| 15 | // The isl scheduling optimizer creates a new schedule tree that maximizes |
| 16 | // parallelism and tileability and minimizes data-dependence distances. The |
| 17 | // algorithm used is a modified version of the ``Pluto'' algorithm: |
| 18 | // |
| 19 | // U. Bondhugula, A. Hartono, J. Ramanujam, and P. Sadayappan. |
| 20 | // A Practical Automatic Polyhedral Parallelizer and Locality Optimizer. |
| 21 | // In Proceedings of the 2008 ACM SIGPLAN Conference On Programming Language |
| 22 | // Design and Implementation, PLDI ’08, pages 101–113. ACM, 2008. |
| 23 | // |
| 24 | // 2) A set of post-scheduling transformations is applied on the schedule tree. |
| 25 | // |
| 26 | // These optimizations include: |
| 27 | // |
| 28 | // - Tiling of the innermost tilable bands |
| 29 | // - Prevectorization - The coice of a possible outer loop that is strip-mined |
| 30 | // to the innermost level to enable inner-loop |
| 31 | // vectorization. |
| 32 | // - Some optimizations for spatial locality are also planned. |
| 33 | // |
| 34 | // For a detailed description of the schedule tree itself please see section 6 |
| 35 | // of: |
| 36 | // |
| 37 | // Polyhedral AST generation is more than scanning polyhedra |
| 38 | // Tobias Grosser, Sven Verdoolaege, Albert Cohen |
| 39 | // ACM Transations on Programming Languages and Systems (TOPLAS), |
| 40 | // 37(4), July 2015 |
| 41 | // http://www.grosser.es/#pub-polyhedral-AST-generation |
| 42 | // |
| 43 | // This publication also contains a detailed discussion of the different options |
| 44 | // for polyhedral loop unrolling, full/partial tile separation and other uses |
| 45 | // of the schedule tree. |
| 46 | // |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 47 | //===----------------------------------------------------------------------===// |
| 48 | |
Tobias Grosser | 967239c | 2011-10-23 20:59:44 +0000 | [diff] [blame] | 49 | #include "polly/ScheduleOptimizer.h" |
Tobias Grosser | ba0d092 | 2015-05-09 09:13:42 +0000 | [diff] [blame] | 50 | #include "polly/CodeGen/CodeGeneration.h" |
| 51 | #include "polly/DependenceInfo.h" |
| 52 | #include "polly/LinkAllPasses.h" |
| 53 | #include "polly/Options.h" |
| 54 | #include "polly/ScopInfo.h" |
| 55 | #include "polly/Support/GICHelper.h" |
| 56 | #include "llvm/Support/Debug.h" |
Tobias Grosser | 2493e92 | 2011-12-07 07:42:57 +0000 | [diff] [blame] | 57 | #include "isl/aff.h" |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 58 | #include "isl/band.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 59 | #include "isl/constraint.h" |
| 60 | #include "isl/map.h" |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 61 | #include "isl/options.h" |
Tobias Grosser | 97d8745 | 2015-05-30 06:46:59 +0000 | [diff] [blame] | 62 | #include "isl/printer.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 63 | #include "isl/schedule.h" |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 64 | #include "isl/schedule_node.h" |
Tobias Grosser | 8ad6bc3 | 2012-01-31 13:26:29 +0000 | [diff] [blame] | 65 | #include "isl/space.h" |
Tobias Grosser | cd524dc | 2015-05-09 09:36:38 +0000 | [diff] [blame] | 66 | #include "isl/union_map.h" |
| 67 | #include "isl/union_set.h" |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 68 | |
| 69 | using namespace llvm; |
| 70 | using namespace polly; |
| 71 | |
Chandler Carruth | 95fef94 | 2014-04-22 03:30:19 +0000 | [diff] [blame] | 72 | #define DEBUG_TYPE "polly-opt-isl" |
| 73 | |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 74 | static cl::opt<std::string> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 75 | OptimizeDeps("polly-opt-optimize-only", |
| 76 | cl::desc("Only a certain kind of dependences (all/raw)"), |
| 77 | cl::Hidden, cl::init("all"), cl::ZeroOrMore, |
| 78 | cl::cat(PollyCategory)); |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 79 | |
| 80 | static cl::opt<std::string> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 81 | SimplifyDeps("polly-opt-simplify-deps", |
| 82 | cl::desc("Dependences should be simplified (yes/no)"), |
| 83 | cl::Hidden, cl::init("yes"), cl::ZeroOrMore, |
| 84 | cl::cat(PollyCategory)); |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 85 | |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 86 | static cl::opt<int> MaxConstantTerm( |
| 87 | "polly-opt-max-constant-term", |
| 88 | cl::desc("The maximal constant term allowed (-1 is unlimited)"), cl::Hidden, |
| 89 | cl::init(20), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 992e60c | 2012-02-20 08:41:15 +0000 | [diff] [blame] | 90 | |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 91 | static cl::opt<int> MaxCoefficient( |
| 92 | "polly-opt-max-coefficient", |
| 93 | cl::desc("The maximal coefficient allowed (-1 is unlimited)"), cl::Hidden, |
| 94 | cl::init(20), cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 95 | |
| 96 | static cl::opt<std::string> FusionStrategy( |
| 97 | "polly-opt-fusion", cl::desc("The fusion strategy to choose (min/max)"), |
| 98 | cl::Hidden, cl::init("min"), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | 92f5480 | 2012-02-20 08:41:47 +0000 | [diff] [blame] | 99 | |
Tobias Grosser | e602a07 | 2013-05-07 07:30:56 +0000 | [diff] [blame] | 100 | static cl::opt<std::string> |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 101 | MaximizeBandDepth("polly-opt-maximize-bands", |
| 102 | cl::desc("Maximize the band depth (yes/no)"), cl::Hidden, |
| 103 | cl::init("yes"), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 104 | |
Tobias Grosser | 07c1c2f | 2015-08-19 08:46:11 +0000 | [diff] [blame] | 105 | static cl::opt<int> PrevectorWidth( |
| 106 | "polly-prevect-width", |
| 107 | cl::desc( |
| 108 | "The number of loop iterations to strip-mine for pre-vectorization"), |
| 109 | cl::Hidden, cl::init(4), cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 110 | |
Tobias Grosser | 0483271 | 2015-08-20 13:45:02 +0000 | [diff] [blame] | 111 | static cl::opt<bool> FirstLevelTiling("polly-tiling", |
| 112 | cl::desc("Enable loop tiling"), |
| 113 | cl::init(true), cl::ZeroOrMore, |
| 114 | cl::cat(PollyCategory)); |
| 115 | |
| 116 | static cl::opt<int> FirstLevelDefaultTileSize( |
Tobias Grosser | 483a90d | 2014-07-09 10:50:10 +0000 | [diff] [blame] | 117 | "polly-default-tile-size", |
| 118 | cl::desc("The default tile size (if not enough were provided by" |
| 119 | " --polly-tile-sizes)"), |
| 120 | cl::Hidden, cl::init(32), cl::ZeroOrMore, cl::cat(PollyCategory)); |
Johannes Doerfert | c3958b2 | 2014-05-28 17:21:02 +0000 | [diff] [blame] | 121 | |
Tobias Grosser | 0483271 | 2015-08-20 13:45:02 +0000 | [diff] [blame] | 122 | static cl::list<int> FirstLevelTileSizes( |
| 123 | "polly-tile-sizes", cl::desc("A tile size for each loop dimension, filled " |
| 124 | "with --polly-default-tile-size"), |
| 125 | cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory)); |
| 126 | |
| 127 | static cl::opt<bool> |
| 128 | SecondLevelTiling("polly-2nd-level-tiling", |
| 129 | cl::desc("Enable a 2nd level loop of loop tiling"), |
| 130 | cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 131 | |
| 132 | static cl::opt<int> SecondLevelDefaultTileSize( |
| 133 | "polly-2nd-level-default-tile-size", |
| 134 | cl::desc("The default 2nd-level tile size (if not enough were provided by" |
| 135 | " --polly-2nd-level-tile-sizes)"), |
| 136 | cl::Hidden, cl::init(16), cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 137 | |
| 138 | static cl::list<int> |
| 139 | SecondLevelTileSizes("polly-2nd-level-tile-sizes", |
| 140 | cl::desc("A tile size for each loop dimension, filled " |
| 141 | "with --polly-default-tile-size"), |
| 142 | cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated, |
| 143 | cl::cat(PollyCategory)); |
| 144 | |
Tobias Grosser | 42e2489 | 2015-08-20 13:45:05 +0000 | [diff] [blame^] | 145 | static cl::opt<bool> RegisterTiling("polly-register-tiling", |
| 146 | cl::desc("Enable register tiling"), |
| 147 | cl::init(false), cl::ZeroOrMore, |
| 148 | cl::cat(PollyCategory)); |
| 149 | |
| 150 | static cl::opt<int> RegisterDefaultTileSize( |
| 151 | "polly-register-tiling-default-tile-size", |
| 152 | cl::desc("The default register tile size (if not enough were provided by" |
| 153 | " --polly-register-tile-sizes)"), |
| 154 | cl::Hidden, cl::init(2), cl::ZeroOrMore, cl::cat(PollyCategory)); |
| 155 | |
| 156 | static cl::list<int> |
| 157 | RegisterTileSizes("polly-register-tile-sizes", |
| 158 | cl::desc("A tile size for each loop dimension, filled " |
| 159 | "with --polly-register-tile-size"), |
| 160 | cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated, |
| 161 | cl::cat(PollyCategory)); |
| 162 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 163 | namespace { |
| 164 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 165 | class IslScheduleOptimizer : public ScopPass { |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 166 | public: |
| 167 | static char ID; |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 168 | explicit IslScheduleOptimizer() : ScopPass(ID) { LastSchedule = nullptr; } |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 169 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 170 | ~IslScheduleOptimizer() { isl_schedule_free(LastSchedule); } |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 171 | |
Johannes Doerfert | 909a3bf | 2015-03-01 18:42:08 +0000 | [diff] [blame] | 172 | bool runOnScop(Scop &S) override; |
| 173 | void printScop(raw_ostream &OS, Scop &S) const override; |
| 174 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
Tobias Grosser | 460e9a4 | 2012-04-25 13:22:43 +0000 | [diff] [blame] | 175 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 176 | private: |
| 177 | isl_schedule *LastSchedule; |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 178 | |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 179 | /// @brief Decide if the @p NewSchedule is profitable for @p S. |
| 180 | /// |
| 181 | /// @param S The SCoP we optimize. |
| 182 | /// @param NewSchedule The new schedule we computed. |
| 183 | /// |
| 184 | /// @return True, if we believe @p NewSchedule is an improvement for @p S. |
| 185 | bool isProfitableSchedule(Scop &S, __isl_keep isl_union_map *NewSchedule); |
| 186 | |
Tobias Grosser | 9bdea57 | 2015-08-20 12:22:37 +0000 | [diff] [blame] | 187 | /// @brief Tile a schedule node. |
| 188 | /// |
| 189 | /// @param Node The node to tile. |
| 190 | /// @param TileSizes A vector of tile sizes that should be used for |
| 191 | /// tiling. |
| 192 | /// @param DefaultTileSize A default tile size that is used for dimensions |
| 193 | /// that are not covered by the TileSizes vector. |
| 194 | static __isl_give isl_schedule_node * |
| 195 | tileNode(__isl_take isl_schedule_node *Node, ArrayRef<int> TileSizes, |
| 196 | int DefaultTileSize); |
| 197 | |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 198 | /// @brief Check if this node is a band node we want to tile. |
| 199 | /// |
| 200 | /// We look for innermost band nodes where individual dimensions are marked as |
| 201 | /// permutable. |
| 202 | /// |
| 203 | /// @param Node The node to check. |
| 204 | static bool isTileableBandNode(__isl_keep isl_schedule_node *Node); |
| 205 | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 206 | /// @brief Pre-vectorizes one scheduling dimension of a schedule band. |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 207 | /// |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 208 | /// prevectSchedBand splits out the dimension DimToVectorize, tiles it and |
| 209 | /// sinks the resulting point loop. |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 210 | /// |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 211 | /// Example (DimToVectorize=0, VectorWidth=4): |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 212 | /// |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 213 | /// | Before transformation: |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 214 | /// | |
| 215 | /// | A[i,j] -> [i,j] |
| 216 | /// | |
| 217 | /// | for (i = 0; i < 128; i++) |
| 218 | /// | for (j = 0; j < 128; j++) |
| 219 | /// | A(i,j); |
| 220 | /// |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 221 | /// | After transformation: |
| 222 | /// | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 223 | /// | for (it = 0; it < 32; it+=1) |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 224 | /// | for (j = 0; j < 128; j++) |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 225 | /// | for (ip = 0; ip <= 3; ip++) |
| 226 | /// | A(4 * it + ip,j); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 227 | /// |
| 228 | /// The goal of this transformation is to create a trivially vectorizable |
| 229 | /// loop. This means a parallel loop at the innermost level that has a |
| 230 | /// constant number of iterations corresponding to the target vector width. |
| 231 | /// |
| 232 | /// This transformation creates a loop at the innermost level. The loop has |
| 233 | /// a constant number of iterations, if the number of loop iterations at |
| 234 | /// DimToVectorize can be divided by VectorWidth. The default VectorWidth is |
| 235 | /// currently constant and not yet target specific. This function does not |
| 236 | /// reason about parallelism. |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 237 | static __isl_give isl_schedule_node * |
| 238 | prevectSchedBand(__isl_take isl_schedule_node *Node, unsigned DimToVectorize, |
Tobias Grosser | 07c1c2f | 2015-08-19 08:46:11 +0000 | [diff] [blame] | 239 | int VectorWidth); |
Tobias Grosser | 460e9a4 | 2012-04-25 13:22:43 +0000 | [diff] [blame] | 240 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 241 | /// @brief Apply additional optimizations on the bands in the schedule tree. |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 242 | /// |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 243 | /// We are looking for an innermost band node and apply the following |
| 244 | /// transformations: |
| 245 | /// |
| 246 | /// - Tile the band |
| 247 | /// - if the band is tileable |
| 248 | /// - if the band has more than one loop dimension |
| 249 | /// |
Tobias Grosser | 3b10c94 | 2015-07-25 12:28:56 +0000 | [diff] [blame] | 250 | /// - Prevectorize the schedule of the band (or the point loop in case of |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 251 | /// tiling). |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 252 | /// - if vectorization is enabled |
| 253 | /// |
| 254 | /// @param Node The schedule node to (possibly) optimize. |
| 255 | /// @param User A pointer to forward some use information (currently unused). |
| 256 | static isl_schedule_node *optimizeBand(isl_schedule_node *Node, void *User); |
Tobias Grosser | 460e9a4 | 2012-04-25 13:22:43 +0000 | [diff] [blame] | 257 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 258 | /// @brief Apply post-scheduling transformations. |
| 259 | /// |
| 260 | /// This function applies a set of additional local transformations on the |
| 261 | /// schedule tree as it computed by the isl scheduler. Local transformations |
| 262 | /// applied include: |
| 263 | /// |
| 264 | /// - Tiling |
| 265 | /// - Prevectorization |
| 266 | /// |
| 267 | /// @param Schedule The schedule object post-transformations will be applied |
| 268 | /// on. |
| 269 | /// @returns The transformed schedule. |
| 270 | static __isl_give isl_schedule * |
| 271 | addPostTransforms(__isl_take isl_schedule *Schedule); |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 272 | |
Tobias Grosser | 20532b8 | 2014-04-11 17:56:49 +0000 | [diff] [blame] | 273 | using llvm::Pass::doFinalization; |
| 274 | |
Johannes Doerfert | 909a3bf | 2015-03-01 18:42:08 +0000 | [diff] [blame] | 275 | virtual bool doFinalization() override { |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 276 | isl_schedule_free(LastSchedule); |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 277 | LastSchedule = nullptr; |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 278 | return true; |
| 279 | } |
| 280 | }; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 283 | char IslScheduleOptimizer::ID = 0; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 284 | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 285 | __isl_give isl_schedule_node * |
| 286 | IslScheduleOptimizer::prevectSchedBand(__isl_take isl_schedule_node *Node, |
| 287 | unsigned DimToVectorize, |
| 288 | int VectorWidth) { |
| 289 | assert(isl_schedule_node_get_type(Node) == isl_schedule_node_band); |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 290 | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 291 | auto Space = isl_schedule_node_band_get_space(Node); |
| 292 | auto ScheduleDimensions = isl_space_dim(Space, isl_dim_set); |
| 293 | isl_space_free(Space); |
| 294 | assert(DimToVectorize < ScheduleDimensions); |
Tobias Grosser | f533880 | 2011-10-06 00:03:35 +0000 | [diff] [blame] | 295 | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 296 | if (DimToVectorize > 0) { |
| 297 | Node = isl_schedule_node_band_split(Node, DimToVectorize); |
| 298 | Node = isl_schedule_node_child(Node, 0); |
| 299 | } |
| 300 | if (DimToVectorize < ScheduleDimensions - 1) |
| 301 | Node = isl_schedule_node_band_split(Node, 1); |
| 302 | Space = isl_schedule_node_band_get_space(Node); |
| 303 | auto Sizes = isl_multi_val_zero(Space); |
| 304 | auto Ctx = isl_schedule_node_get_ctx(Node); |
| 305 | Sizes = |
| 306 | isl_multi_val_set_val(Sizes, 0, isl_val_int_from_si(Ctx, VectorWidth)); |
| 307 | Node = isl_schedule_node_band_tile(Node, Sizes); |
| 308 | Node = isl_schedule_node_child(Node, 0); |
| 309 | Node = isl_schedule_node_band_sink(Node); |
Tobias Grosser | 42e2489 | 2015-08-20 13:45:05 +0000 | [diff] [blame^] | 310 | |
| 311 | // Make sure the "trivially vectorizable loop" is not unrolled. Otherwise, |
| 312 | // we will have troubles to match it in the backend. |
| 313 | Node = isl_schedule_node_band_set_ast_build_options( |
| 314 | Node, isl_union_set_read_from_str(Ctx, "{unroll[x]: 1 = 0}")); |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 315 | Node = isl_schedule_node_child(Node, 0); |
| 316 | return Node; |
Tobias Grosser | c6699b7 | 2011-06-30 20:29:13 +0000 | [diff] [blame] | 317 | } |
| 318 | |
Tobias Grosser | d891b54 | 2015-08-20 12:16:23 +0000 | [diff] [blame] | 319 | __isl_give isl_schedule_node * |
Tobias Grosser | 9bdea57 | 2015-08-20 12:22:37 +0000 | [diff] [blame] | 320 | IslScheduleOptimizer::tileNode(__isl_take isl_schedule_node *Node, |
| 321 | ArrayRef<int> TileSizes, int DefaultTileSize) { |
| 322 | auto Ctx = isl_schedule_node_get_ctx(Node); |
| 323 | auto Space = isl_schedule_node_band_get_space(Node); |
| 324 | auto Dims = isl_space_dim(Space, isl_dim_set); |
| 325 | auto Sizes = isl_multi_val_zero(Space); |
| 326 | for (unsigned i = 0; i < Dims; i++) { |
| 327 | auto tileSize = i < TileSizes.size() ? TileSizes[i] : DefaultTileSize; |
| 328 | Sizes = isl_multi_val_set_val(Sizes, i, isl_val_int_from_si(Ctx, tileSize)); |
| 329 | } |
| 330 | Node = isl_schedule_node_band_tile(Node, Sizes); |
| 331 | return isl_schedule_node_child(Node, 0); |
| 332 | } |
| 333 | |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 334 | bool IslScheduleOptimizer::isTileableBandNode( |
| 335 | __isl_keep isl_schedule_node *Node) { |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 336 | if (isl_schedule_node_get_type(Node) != isl_schedule_node_band) |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 337 | return false; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 338 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 339 | if (isl_schedule_node_n_children(Node) != 1) |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 340 | return false; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 341 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 342 | if (!isl_schedule_node_band_get_permutable(Node)) |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 343 | return false; |
Tobias Grosser | 44f19ac | 2011-07-05 22:15:53 +0000 | [diff] [blame] | 344 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 345 | auto Space = isl_schedule_node_band_get_space(Node); |
| 346 | auto Dims = isl_space_dim(Space, isl_dim_set); |
Tobias Grosser | 9bdea57 | 2015-08-20 12:22:37 +0000 | [diff] [blame] | 347 | isl_space_free(Space); |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 348 | |
Tobias Grosser | 9bdea57 | 2015-08-20 12:22:37 +0000 | [diff] [blame] | 349 | if (Dims <= 1) |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 350 | return false; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 351 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 352 | auto Child = isl_schedule_node_get_child(Node, 0); |
| 353 | auto Type = isl_schedule_node_get_type(Child); |
| 354 | isl_schedule_node_free(Child); |
| 355 | |
Tobias Grosser | 9bdea57 | 2015-08-20 12:22:37 +0000 | [diff] [blame] | 356 | if (Type != isl_schedule_node_leaf) |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 357 | return false; |
| 358 | |
| 359 | return true; |
| 360 | } |
| 361 | |
| 362 | __isl_give isl_schedule_node * |
| 363 | IslScheduleOptimizer::optimizeBand(__isl_take isl_schedule_node *Node, |
| 364 | void *User) { |
| 365 | if (!isTileableBandNode(Node)) |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 366 | return Node; |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 367 | |
Tobias Grosser | 0483271 | 2015-08-20 13:45:02 +0000 | [diff] [blame] | 368 | if (FirstLevelTiling) |
| 369 | Node = tileNode(Node, FirstLevelTileSizes, FirstLevelDefaultTileSize); |
| 370 | |
| 371 | if (SecondLevelTiling) |
| 372 | Node = tileNode(Node, SecondLevelTileSizes, SecondLevelDefaultTileSize); |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 373 | |
Tobias Grosser | 42e2489 | 2015-08-20 13:45:05 +0000 | [diff] [blame^] | 374 | if (RegisterTiling) { |
| 375 | auto *Ctx = isl_schedule_node_get_ctx(Node); |
| 376 | Node = tileNode(Node, RegisterTileSizes, RegisterDefaultTileSize); |
| 377 | Node = isl_schedule_node_band_set_ast_build_options( |
| 378 | Node, isl_union_set_read_from_str(Ctx, "{unroll[x]}")); |
| 379 | } |
| 380 | |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 381 | if (PollyVectorizerChoice == VECTORIZER_NONE) |
Tobias Grosser | f10f463 | 2015-08-19 08:03:37 +0000 | [diff] [blame] | 382 | return Node; |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 383 | |
Tobias Grosser | 862b9b5 | 2015-08-20 12:32:45 +0000 | [diff] [blame] | 384 | auto Space = isl_schedule_node_band_get_space(Node); |
| 385 | auto Dims = isl_space_dim(Space, isl_dim_set); |
| 386 | isl_space_free(Space); |
| 387 | |
Tobias Grosser | b241d92 | 2015-07-28 18:03:36 +0000 | [diff] [blame] | 388 | for (int i = Dims - 1; i >= 0; i--) |
Tobias Grosser | f10f463 | 2015-08-19 08:03:37 +0000 | [diff] [blame] | 389 | if (isl_schedule_node_band_member_get_coincident(Node, i)) { |
Tobias Grosser | 07c1c2f | 2015-08-19 08:46:11 +0000 | [diff] [blame] | 390 | Node = IslScheduleOptimizer::prevectSchedBand(Node, i, PrevectorWidth); |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 391 | break; |
| 392 | } |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 393 | |
Tobias Grosser | f10f463 | 2015-08-19 08:03:37 +0000 | [diff] [blame] | 394 | return Node; |
Tobias Grosser | de68cc9 | 2011-06-30 20:01:02 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 397 | __isl_give isl_schedule * |
| 398 | IslScheduleOptimizer::addPostTransforms(__isl_take isl_schedule *Schedule) { |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 399 | isl_schedule_node *Root = isl_schedule_get_root(Schedule); |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 400 | isl_schedule_free(Schedule); |
Tobias Grosser | b2f3992 | 2015-05-28 13:32:11 +0000 | [diff] [blame] | 401 | Root = isl_schedule_node_map_descendant_bottom_up( |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 402 | Root, IslScheduleOptimizer::optimizeBand, NULL); |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 403 | auto S = isl_schedule_node_get_schedule(Root); |
Tobias Grosser | bbb4cec | 2015-03-22 12:06:39 +0000 | [diff] [blame] | 404 | isl_schedule_node_free(Root); |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 405 | return S; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 408 | bool IslScheduleOptimizer::isProfitableSchedule( |
| 409 | Scop &S, __isl_keep isl_union_map *NewSchedule) { |
| 410 | // To understand if the schedule has been optimized we check if the schedule |
| 411 | // has changed at all. |
| 412 | // TODO: We can improve this by tracking if any necessarily beneficial |
| 413 | // transformations have been performed. This can e.g. be tiling, loop |
| 414 | // interchange, or ...) We can track this either at the place where the |
| 415 | // transformation has been performed or, in case of automatic ILP based |
| 416 | // optimizations, by comparing (yet to be defined) performance metrics |
| 417 | // before/after the scheduling optimizer |
| 418 | // (e.g., #stride-one accesses) |
| 419 | isl_union_map *OldSchedule = S.getSchedule(); |
| 420 | bool changed = !isl_union_map_is_equal(OldSchedule, NewSchedule); |
| 421 | isl_union_map_free(OldSchedule); |
| 422 | return changed; |
| 423 | } |
| 424 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 425 | bool IslScheduleOptimizer::runOnScop(Scop &S) { |
Johannes Doerfert | 6f7921f | 2015-02-14 12:02:24 +0000 | [diff] [blame] | 426 | |
| 427 | // Skip empty SCoPs but still allow code generation as it will delete the |
| 428 | // loops present but not needed. |
| 429 | if (S.getSize() == 0) { |
| 430 | S.markAsOptimized(); |
| 431 | return false; |
| 432 | } |
| 433 | |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 434 | const Dependences &D = getAnalysis<DependenceInfo>().getDependences(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 435 | |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 436 | if (!D.hasValidDependences()) |
Tobias Grosser | 38c36ea | 2014-02-23 15:15:44 +0000 | [diff] [blame] | 437 | return false; |
| 438 | |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 439 | isl_schedule_free(LastSchedule); |
Tobias Grosser | 5a56cbf | 2014-04-16 07:33:47 +0000 | [diff] [blame] | 440 | LastSchedule = nullptr; |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 441 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 442 | // Build input data. |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 443 | int ValidityKinds = |
| 444 | Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 445 | int ProximityKinds; |
| 446 | |
| 447 | if (OptimizeDeps == "all") |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 448 | ProximityKinds = |
| 449 | Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 450 | else if (OptimizeDeps == "raw") |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 451 | ProximityKinds = Dependences::TYPE_RAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 452 | else { |
| 453 | errs() << "Do not know how to optimize for '" << OptimizeDeps << "'" |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 454 | << " Falling back to optimizing all dependences.\n"; |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 455 | ProximityKinds = |
| 456 | Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW; |
Tobias Grosser | 1deda29 | 2012-02-14 14:02:48 +0000 | [diff] [blame] | 457 | } |
| 458 | |
Tobias Grosser | 5f9a762 | 2012-02-14 14:02:40 +0000 | [diff] [blame] | 459 | isl_union_set *Domain = S.getDomains(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 460 | |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 461 | if (!Domain) |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 462 | return false; |
| 463 | |
Johannes Doerfert | 7e6424b | 2015-03-05 00:43:48 +0000 | [diff] [blame] | 464 | isl_union_map *Validity = D.getDependences(ValidityKinds); |
| 465 | isl_union_map *Proximity = D.getDependences(ProximityKinds); |
Tobias Grosser | 8a50702 | 2012-03-16 11:51:41 +0000 | [diff] [blame] | 466 | |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 467 | // Simplify the dependences by removing the constraints introduced by the |
| 468 | // domains. This can speed up the scheduling time significantly, as large |
| 469 | // constant coefficients will be removed from the dependences. The |
| 470 | // introduction of some additional dependences reduces the possible |
| 471 | // transformations, but in most cases, such transformation do not seem to be |
| 472 | // interesting anyway. In some cases this option may stop the scheduler to |
| 473 | // find any schedule. |
| 474 | if (SimplifyDeps == "yes") { |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 475 | Validity = isl_union_map_gist_domain(Validity, isl_union_set_copy(Domain)); |
| 476 | Validity = isl_union_map_gist_range(Validity, isl_union_set_copy(Domain)); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 477 | Proximity = |
| 478 | isl_union_map_gist_domain(Proximity, isl_union_set_copy(Domain)); |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 479 | Proximity = isl_union_map_gist_range(Proximity, isl_union_set_copy(Domain)); |
Tobias Grosser | a26db47 | 2012-01-30 19:38:43 +0000 | [diff] [blame] | 480 | } else if (SimplifyDeps != "no") { |
| 481 | errs() << "warning: Option -polly-opt-simplify-deps should either be 'yes' " |
| 482 | "or 'no'. Falling back to default: 'yes'\n"; |
| 483 | } |
| 484 | |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 485 | DEBUG(dbgs() << "\n\nCompute schedule from: "); |
Tobias Grosser | 01aea58 | 2014-10-22 23:16:28 +0000 | [diff] [blame] | 486 | DEBUG(dbgs() << "Domain := " << stringFromIslObj(Domain) << ";\n"); |
| 487 | DEBUG(dbgs() << "Proximity := " << stringFromIslObj(Proximity) << ";\n"); |
| 488 | DEBUG(dbgs() << "Validity := " << stringFromIslObj(Validity) << ";\n"); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 489 | |
Michael Kruse | c59f22c | 2015-06-18 16:45:40 +0000 | [diff] [blame] | 490 | unsigned IslSerializeSCCs; |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 491 | |
| 492 | if (FusionStrategy == "max") { |
Michael Kruse | c59f22c | 2015-06-18 16:45:40 +0000 | [diff] [blame] | 493 | IslSerializeSCCs = 0; |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 494 | } else if (FusionStrategy == "min") { |
Michael Kruse | c59f22c | 2015-06-18 16:45:40 +0000 | [diff] [blame] | 495 | IslSerializeSCCs = 1; |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 496 | } else { |
| 497 | errs() << "warning: Unknown fusion strategy. Falling back to maximal " |
| 498 | "fusion.\n"; |
Michael Kruse | c59f22c | 2015-06-18 16:45:40 +0000 | [diff] [blame] | 499 | IslSerializeSCCs = 0; |
Tobias Grosser | b3ad85b | 2012-01-30 19:38:50 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 502 | int IslMaximizeBands; |
| 503 | |
Tobias Grosser | a4ea90b | 2012-01-30 22:43:56 +0000 | [diff] [blame] | 504 | if (MaximizeBandDepth == "yes") { |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 505 | IslMaximizeBands = 1; |
Tobias Grosser | a4ea90b | 2012-01-30 22:43:56 +0000 | [diff] [blame] | 506 | } else if (MaximizeBandDepth == "no") { |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 507 | IslMaximizeBands = 0; |
| 508 | } else { |
| 509 | errs() << "warning: Option -polly-opt-maximize-bands should either be 'yes'" |
| 510 | " or 'no'. Falling back to default: 'yes'\n"; |
| 511 | IslMaximizeBands = 1; |
| 512 | } |
| 513 | |
Michael Kruse | c59f22c | 2015-06-18 16:45:40 +0000 | [diff] [blame] | 514 | isl_options_set_schedule_serialize_sccs(S.getIslCtx(), IslSerializeSCCs); |
Tobias Grosser | 95e860c | 2012-01-30 19:38:54 +0000 | [diff] [blame] | 515 | isl_options_set_schedule_maximize_band_depth(S.getIslCtx(), IslMaximizeBands); |
Tobias Grosser | 992e60c | 2012-02-20 08:41:15 +0000 | [diff] [blame] | 516 | isl_options_set_schedule_max_constant_term(S.getIslCtx(), MaxConstantTerm); |
Tobias Grosser | 92f5480 | 2012-02-20 08:41:47 +0000 | [diff] [blame] | 517 | isl_options_set_schedule_max_coefficient(S.getIslCtx(), MaxCoefficient); |
Tobias Grosser | 4f6bcef | 2015-03-31 07:52:36 +0000 | [diff] [blame] | 518 | isl_options_set_tile_scale_tile_loops(S.getIslCtx(), 0); |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 519 | |
| 520 | isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_CONTINUE); |
Tobias Grosser | a38c924 | 2014-01-26 19:36:28 +0000 | [diff] [blame] | 521 | |
| 522 | isl_schedule_constraints *ScheduleConstraints; |
| 523 | ScheduleConstraints = isl_schedule_constraints_on_domain(Domain); |
| 524 | ScheduleConstraints = |
| 525 | isl_schedule_constraints_set_proximity(ScheduleConstraints, Proximity); |
| 526 | ScheduleConstraints = isl_schedule_constraints_set_validity( |
| 527 | ScheduleConstraints, isl_union_map_copy(Validity)); |
| 528 | ScheduleConstraints = |
| 529 | isl_schedule_constraints_set_coincidence(ScheduleConstraints, Validity); |
Tobias Grosser | 00383a7 | 2012-02-14 14:02:44 +0000 | [diff] [blame] | 530 | isl_schedule *Schedule; |
Tobias Grosser | a38c924 | 2014-01-26 19:36:28 +0000 | [diff] [blame] | 531 | Schedule = isl_schedule_constraints_compute_schedule(ScheduleConstraints); |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 532 | isl_options_set_on_error(S.getIslCtx(), ISL_ON_ERROR_ABORT); |
| 533 | |
| 534 | // In cases the scheduler is not able to optimize the code, we just do not |
| 535 | // touch the schedule. |
Tobias Grosser | 98610ee | 2012-02-13 23:31:39 +0000 | [diff] [blame] | 536 | if (!Schedule) |
Tobias Grosser | 42152ff | 2012-01-30 19:38:47 +0000 | [diff] [blame] | 537 | return false; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 538 | |
Tobias Grosser | 97d8745 | 2015-05-30 06:46:59 +0000 | [diff] [blame] | 539 | DEBUG({ |
| 540 | auto *P = isl_printer_to_str(S.getIslCtx()); |
| 541 | P = isl_printer_set_yaml_style(P, ISL_YAML_STYLE_BLOCK); |
| 542 | P = isl_printer_print_schedule(P, Schedule); |
| 543 | dbgs() << "NewScheduleTree: \n" << isl_printer_get_str(P) << "\n"; |
| 544 | isl_printer_free(P); |
| 545 | }); |
Tobias Grosser | 4d63b9d | 2012-02-20 08:41:21 +0000 | [diff] [blame] | 546 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 547 | isl_schedule *NewSchedule = addPostTransforms(Schedule); |
| 548 | isl_union_map *NewScheduleMap = isl_schedule_get_map(NewSchedule); |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 549 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 550 | if (!isProfitableSchedule(S, NewScheduleMap)) { |
| 551 | isl_union_map_free(NewScheduleMap); |
| 552 | isl_schedule_free(NewSchedule); |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 553 | return false; |
| 554 | } |
| 555 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 556 | S.setScheduleTree(NewSchedule); |
Johannes Doerfert | 7ceb040 | 2015-02-11 17:25:09 +0000 | [diff] [blame] | 557 | S.markAsOptimized(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 558 | |
Tobias Grosser | 808cd69 | 2015-07-14 09:33:13 +0000 | [diff] [blame] | 559 | isl_union_map_free(NewScheduleMap); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 560 | return false; |
| 561 | } |
| 562 | |
Johannes Doerfert | 3fe584d | 2015-03-01 18:40:25 +0000 | [diff] [blame] | 563 | void IslScheduleOptimizer::printScop(raw_ostream &OS, Scop &) const { |
Tobias Grosser | 2878142 | 2012-10-16 07:29:19 +0000 | [diff] [blame] | 564 | isl_printer *p; |
| 565 | char *ScheduleStr; |
| 566 | |
| 567 | OS << "Calculated schedule:\n"; |
| 568 | |
| 569 | if (!LastSchedule) { |
| 570 | OS << "n/a\n"; |
| 571 | return; |
| 572 | } |
| 573 | |
| 574 | p = isl_printer_to_str(isl_schedule_get_ctx(LastSchedule)); |
| 575 | p = isl_printer_print_schedule(p, LastSchedule); |
| 576 | ScheduleStr = isl_printer_get_str(p); |
| 577 | isl_printer_free(p); |
| 578 | |
| 579 | OS << ScheduleStr << "\n"; |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 582 | void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const { |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 583 | ScopPass::getAnalysisUsage(AU); |
Johannes Doerfert | f6557f9 | 2015-03-04 22:43:40 +0000 | [diff] [blame] | 584 | AU.addRequired<DependenceInfo>(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 587 | Pass *polly::createIslScheduleOptimizerPass() { |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 588 | return new IslScheduleOptimizer(); |
Tobias Grosser | 30aa24c | 2011-05-14 19:02:06 +0000 | [diff] [blame] | 589 | } |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 590 | |
| 591 | INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-opt-isl", |
| 592 | "Polly - Optimize schedule of SCoP", false, false); |
Johannes Doerfert | f6557f9 | 2015-03-04 22:43:40 +0000 | [diff] [blame] | 593 | INITIALIZE_PASS_DEPENDENCY(DependenceInfo); |
Tobias Grosser | 4d96c8d | 2013-03-23 01:05:07 +0000 | [diff] [blame] | 594 | INITIALIZE_PASS_DEPENDENCY(ScopInfo); |
| 595 | INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-opt-isl", |
| 596 | "Polly - Optimize schedule of SCoP", false, false) |