blob: b89374ddd3b4f73b11cd34793d71d28e1d5b5d7d [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//
Tobias Grosser2219d152016-08-03 05:28:09 +000010// This pass generates an entirely new schedule tree from the data dependences
Tobias Grosser234a4822015-08-15 09:34:33 +000011// and iteration domains. The new schedule tree is computed in two steps:
Tobias Grosser30aa24c2011-05-14 19:02:06 +000012//
Tobias Grosser234a4822015-08-15 09:34:33 +000013// 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 Grosser30aa24c2011-05-14 19:02:06 +000047//===----------------------------------------------------------------------===//
48
Tobias Grosser967239c2011-10-23 20:59:44 +000049#include "polly/ScheduleOptimizer.h"
Tobias Grosserba0d0922015-05-09 09:13:42 +000050#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"
Roman Gareev42402c92016-06-22 09:52:37 +000056#include "llvm/Analysis/TargetTransformInfo.h"
Tobias Grosserba0d0922015-05-09 09:13:42 +000057#include "llvm/Support/Debug.h"
Tobias Grosser2493e922011-12-07 07:42:57 +000058#include "isl/aff.h"
Tobias Grosserde68cc92011-06-30 20:01:02 +000059#include "isl/band.h"
Tobias Grosser8ad6bc32012-01-31 13:26:29 +000060#include "isl/constraint.h"
61#include "isl/map.h"
Tobias Grosser42152ff2012-01-30 19:38:47 +000062#include "isl/options.h"
Tobias Grosser97d87452015-05-30 06:46:59 +000063#include "isl/printer.h"
Tobias Grosser8ad6bc32012-01-31 13:26:29 +000064#include "isl/schedule.h"
Tobias Grosserbbb4cec2015-03-22 12:06:39 +000065#include "isl/schedule_node.h"
Tobias Grosser8ad6bc32012-01-31 13:26:29 +000066#include "isl/space.h"
Tobias Grossercd524dc2015-05-09 09:36:38 +000067#include "isl/union_map.h"
68#include "isl/union_set.h"
Tobias Grosser30aa24c2011-05-14 19:02:06 +000069
70using namespace llvm;
71using namespace polly;
72
Chandler Carruth95fef942014-04-22 03:30:19 +000073#define DEBUG_TYPE "polly-opt-isl"
74
Tobias Grossera26db472012-01-30 19:38:43 +000075static cl::opt<std::string>
Tobias Grosser483a90d2014-07-09 10:50:10 +000076 OptimizeDeps("polly-opt-optimize-only",
77 cl::desc("Only a certain kind of dependences (all/raw)"),
78 cl::Hidden, cl::init("all"), cl::ZeroOrMore,
79 cl::cat(PollyCategory));
Tobias Grosser1deda292012-02-14 14:02:48 +000080
81static cl::opt<std::string>
Tobias Grosser483a90d2014-07-09 10:50:10 +000082 SimplifyDeps("polly-opt-simplify-deps",
83 cl::desc("Dependences should be simplified (yes/no)"),
84 cl::Hidden, cl::init("yes"), cl::ZeroOrMore,
85 cl::cat(PollyCategory));
Tobias Grossera26db472012-01-30 19:38:43 +000086
Tobias Grosser483a90d2014-07-09 10:50:10 +000087static cl::opt<int> MaxConstantTerm(
88 "polly-opt-max-constant-term",
89 cl::desc("The maximal constant term allowed (-1 is unlimited)"), cl::Hidden,
90 cl::init(20), cl::ZeroOrMore, cl::cat(PollyCategory));
Tobias Grosser992e60c2012-02-20 08:41:15 +000091
Tobias Grosser483a90d2014-07-09 10:50:10 +000092static cl::opt<int> MaxCoefficient(
93 "polly-opt-max-coefficient",
94 cl::desc("The maximal coefficient allowed (-1 is unlimited)"), cl::Hidden,
95 cl::init(20), cl::ZeroOrMore, cl::cat(PollyCategory));
96
97static cl::opt<std::string> FusionStrategy(
98 "polly-opt-fusion", cl::desc("The fusion strategy to choose (min/max)"),
99 cl::Hidden, cl::init("min"), cl::ZeroOrMore, cl::cat(PollyCategory));
Tobias Grosser92f54802012-02-20 08:41:47 +0000100
Tobias Grossere602a072013-05-07 07:30:56 +0000101static cl::opt<std::string>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000102 MaximizeBandDepth("polly-opt-maximize-bands",
103 cl::desc("Maximize the band depth (yes/no)"), cl::Hidden,
104 cl::init("yes"), cl::ZeroOrMore, cl::cat(PollyCategory));
Tobias Grosserb3ad85b2012-01-30 19:38:50 +0000105
Michael Kruse315aa322016-05-02 11:35:27 +0000106static cl::opt<std::string> OuterCoincidence(
107 "polly-opt-outer-coincidence",
108 cl::desc("Try to construct schedules where the outer member of each band "
109 "satisfies the coincidence constraints (yes/no)"),
110 cl::Hidden, cl::init("no"), cl::ZeroOrMore, cl::cat(PollyCategory));
111
Tobias Grosser07c1c2f2015-08-19 08:46:11 +0000112static cl::opt<int> PrevectorWidth(
113 "polly-prevect-width",
114 cl::desc(
115 "The number of loop iterations to strip-mine for pre-vectorization"),
116 cl::Hidden, cl::init(4), cl::ZeroOrMore, cl::cat(PollyCategory));
117
Tobias Grosser04832712015-08-20 13:45:02 +0000118static cl::opt<bool> FirstLevelTiling("polly-tiling",
119 cl::desc("Enable loop tiling"),
120 cl::init(true), cl::ZeroOrMore,
121 cl::cat(PollyCategory));
122
Roman Gareev42402c92016-06-22 09:52:37 +0000123static cl::opt<int> LatencyVectorFma(
124 "polly-target-latency-vector-fma",
125 cl::desc("The minimal number of cycles between issuing two "
126 "dependent consecutive vector fused multiply-add "
127 "instructions."),
128 cl::Hidden, cl::init(8), cl::ZeroOrMore, cl::cat(PollyCategory));
129
130static cl::opt<int> ThrougputVectorFma(
131 "polly-target-througput-vector-fma",
132 cl::desc("A throughput of the processor floating-point arithmetic units "
133 "expressed in the number of vector fused multiply-add "
134 "instructions per clock cycle."),
135 cl::Hidden, cl::init(1), cl::ZeroOrMore, cl::cat(PollyCategory));
136
Roman Gareev3a18a932016-07-25 09:42:53 +0000137static cl::list<int>
138 CacheLevelAssociativity("polly-target-cache-level-associativity",
139 cl::desc("The associativity of each cache level."),
140 cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated,
141 cl::cat(PollyCategory));
142
143static cl::list<int> CacheLevelSizes(
144 "polly-target-cache-level-sizes",
145 cl::desc("The size of each cache level specified in bytes."), cl::Hidden,
146 cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory));
147
Tobias Grosser04832712015-08-20 13:45:02 +0000148static cl::opt<int> FirstLevelDefaultTileSize(
Tobias Grosser483a90d2014-07-09 10:50:10 +0000149 "polly-default-tile-size",
150 cl::desc("The default tile size (if not enough were provided by"
151 " --polly-tile-sizes)"),
152 cl::Hidden, cl::init(32), cl::ZeroOrMore, cl::cat(PollyCategory));
Johannes Doerfertc3958b22014-05-28 17:21:02 +0000153
Tobias Grosser04832712015-08-20 13:45:02 +0000154static cl::list<int> FirstLevelTileSizes(
155 "polly-tile-sizes", cl::desc("A tile size for each loop dimension, filled "
156 "with --polly-default-tile-size"),
157 cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated, cl::cat(PollyCategory));
158
159static cl::opt<bool>
160 SecondLevelTiling("polly-2nd-level-tiling",
161 cl::desc("Enable a 2nd level loop of loop tiling"),
162 cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
163
164static cl::opt<int> SecondLevelDefaultTileSize(
165 "polly-2nd-level-default-tile-size",
166 cl::desc("The default 2nd-level tile size (if not enough were provided by"
167 " --polly-2nd-level-tile-sizes)"),
168 cl::Hidden, cl::init(16), cl::ZeroOrMore, cl::cat(PollyCategory));
169
170static cl::list<int>
171 SecondLevelTileSizes("polly-2nd-level-tile-sizes",
172 cl::desc("A tile size for each loop dimension, filled "
173 "with --polly-default-tile-size"),
174 cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated,
175 cl::cat(PollyCategory));
176
Tobias Grosser42e24892015-08-20 13:45:05 +0000177static cl::opt<bool> RegisterTiling("polly-register-tiling",
178 cl::desc("Enable register tiling"),
179 cl::init(false), cl::ZeroOrMore,
180 cl::cat(PollyCategory));
181
182static cl::opt<int> RegisterDefaultTileSize(
183 "polly-register-tiling-default-tile-size",
184 cl::desc("The default register tile size (if not enough were provided by"
185 " --polly-register-tile-sizes)"),
186 cl::Hidden, cl::init(2), cl::ZeroOrMore, cl::cat(PollyCategory));
187
188static cl::list<int>
189 RegisterTileSizes("polly-register-tile-sizes",
190 cl::desc("A tile size for each loop dimension, filled "
191 "with --polly-register-tile-size"),
192 cl::Hidden, cl::ZeroOrMore, cl::CommaSeparated,
193 cl::cat(PollyCategory));
194
Roman Gareev9c3eb592016-05-28 16:17:58 +0000195static cl::opt<bool>
196 PMBasedOpts("polly-pattern-matching-based-opts",
197 cl::desc("Perform optimizations based on pattern matching"),
198 cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
199
Roman Gareev5f99f862016-08-21 11:20:39 +0000200static cl::opt<bool> OptimizedScops(
201 "polly-optimized-scops",
202 cl::desc("Polly - Dump polyhedral description of Scops optimized with "
203 "the isl scheduling optimizer and the set of post-scheduling "
204 "transformations is applied on the schedule tree"),
205 cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
206
Tobias Grosserc80d6972016-09-02 06:33:33 +0000207/// Create an isl_union_set, which describes the isolate option based on
208/// IsoalteDomain.
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000209///
210/// @param IsolateDomain An isl_set whose last dimension is the only one that
211/// should belong to the current band node.
212static __isl_give isl_union_set *
213getIsolateOptions(__isl_take isl_set *IsolateDomain) {
214 auto Dims = isl_set_dim(IsolateDomain, isl_dim_set);
215 auto *IsolateRelation = isl_map_from_domain(IsolateDomain);
216 IsolateRelation = isl_map_move_dims(IsolateRelation, isl_dim_out, 0,
217 isl_dim_in, Dims - 1, 1);
218 auto *IsolateOption = isl_map_wrap(IsolateRelation);
Tobias Grosser8dd653d2016-06-22 16:22:00 +0000219 auto *Id = isl_id_alloc(isl_set_get_ctx(IsolateOption), "isolate", nullptr);
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000220 return isl_union_set_from_set(isl_set_set_tuple_id(IsolateOption, Id));
221}
222
Tobias Grosserc80d6972016-09-02 06:33:33 +0000223/// Create an isl_union_set, which describes the atomic option for the dimension
224/// of the current node.
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000225///
226/// It may help to reduce the size of generated code.
227///
228/// @param Ctx An isl_ctx, which is used to create the isl_union_set.
229static __isl_give isl_union_set *getAtomicOptions(__isl_take isl_ctx *Ctx) {
230 auto *Space = isl_space_set_alloc(Ctx, 0, 1);
231 auto *AtomicOption = isl_set_universe(Space);
Tobias Grosser8dd653d2016-06-22 16:22:00 +0000232 auto *Id = isl_id_alloc(Ctx, "atomic", nullptr);
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000233 return isl_union_set_from_set(isl_set_set_tuple_id(AtomicOption, Id));
234}
235
Tobias Grosserc80d6972016-09-02 06:33:33 +0000236/// Make the last dimension of Set to take values from 0 to VectorWidth - 1.
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000237///
238/// @param Set A set, which should be modified.
239/// @param VectorWidth A parameter, which determines the constraint.
240static __isl_give isl_set *addExtentConstraints(__isl_take isl_set *Set,
241 int VectorWidth) {
242 auto Dims = isl_set_dim(Set, isl_dim_set);
243 auto Space = isl_set_get_space(Set);
244 auto *LocalSpace = isl_local_space_from_space(Space);
245 auto *ExtConstr =
246 isl_constraint_alloc_inequality(isl_local_space_copy(LocalSpace));
247 ExtConstr = isl_constraint_set_constant_si(ExtConstr, 0);
248 ExtConstr =
249 isl_constraint_set_coefficient_si(ExtConstr, isl_dim_set, Dims - 1, 1);
250 Set = isl_set_add_constraint(Set, ExtConstr);
251 ExtConstr = isl_constraint_alloc_inequality(LocalSpace);
252 ExtConstr = isl_constraint_set_constant_si(ExtConstr, VectorWidth - 1);
253 ExtConstr =
254 isl_constraint_set_coefficient_si(ExtConstr, isl_dim_set, Dims - 1, -1);
255 return isl_set_add_constraint(Set, ExtConstr);
256}
257
Tobias Grosserc80d6972016-09-02 06:33:33 +0000258/// Build the desired set of partial tile prefixes.
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000259///
260/// We build a set of partial tile prefixes, which are prefixes of the vector
261/// loop that have exactly VectorWidth iterations.
262///
263/// 1. Get all prefixes of the vector loop.
264/// 2. Extend it to a set, which has exactly VectorWidth iterations for
265/// any prefix from the set that was built on the previous step.
266/// 3. Subtract loop domain from it, project out the vector loop dimension and
Roman Gareev76614d32016-05-31 11:22:21 +0000267/// get a set of prefixes, which don't have exactly VectorWidth iterations.
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000268/// 4. Subtract it from all prefixes of the vector loop and get the desired
269/// set.
270///
271/// @param ScheduleRange A range of a map, which describes a prefix schedule
272/// relation.
273static __isl_give isl_set *
274getPartialTilePrefixes(__isl_take isl_set *ScheduleRange, int VectorWidth) {
275 auto Dims = isl_set_dim(ScheduleRange, isl_dim_set);
276 auto *LoopPrefixes = isl_set_project_out(isl_set_copy(ScheduleRange),
277 isl_dim_set, Dims - 1, 1);
278 auto *ExtentPrefixes =
279 isl_set_add_dims(isl_set_copy(LoopPrefixes), isl_dim_set, 1);
280 ExtentPrefixes = addExtentConstraints(ExtentPrefixes, VectorWidth);
281 auto *BadPrefixes = isl_set_subtract(ExtentPrefixes, ScheduleRange);
282 BadPrefixes = isl_set_project_out(BadPrefixes, isl_dim_set, Dims - 1, 1);
283 return isl_set_subtract(LoopPrefixes, BadPrefixes);
284}
285
286__isl_give isl_schedule_node *ScheduleTreeOptimizer::isolateFullPartialTiles(
287 __isl_take isl_schedule_node *Node, int VectorWidth) {
288 assert(isl_schedule_node_get_type(Node) == isl_schedule_node_band);
289 Node = isl_schedule_node_child(Node, 0);
290 Node = isl_schedule_node_child(Node, 0);
291 auto *SchedRelUMap = isl_schedule_node_get_prefix_schedule_relation(Node);
292 auto *ScheduleRelation = isl_map_from_union_map(SchedRelUMap);
293 auto *ScheduleRange = isl_map_range(ScheduleRelation);
294 auto *IsolateDomain = getPartialTilePrefixes(ScheduleRange, VectorWidth);
295 auto *AtomicOption = getAtomicOptions(isl_set_get_ctx(IsolateDomain));
296 auto *IsolateOption = getIsolateOptions(IsolateDomain);
297 Node = isl_schedule_node_parent(Node);
298 Node = isl_schedule_node_parent(Node);
299 auto *Options = isl_union_set_union(IsolateOption, AtomicOption);
300 Node = isl_schedule_node_band_set_ast_build_options(Node, Options);
301 return Node;
302}
303
Tobias Grosserb241d922015-07-28 18:03:36 +0000304__isl_give isl_schedule_node *
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000305ScheduleTreeOptimizer::prevectSchedBand(__isl_take isl_schedule_node *Node,
306 unsigned DimToVectorize,
307 int VectorWidth) {
Tobias Grosserb241d922015-07-28 18:03:36 +0000308 assert(isl_schedule_node_get_type(Node) == isl_schedule_node_band);
Tobias Grosserc6699b72011-06-30 20:29:13 +0000309
Tobias Grosserb241d922015-07-28 18:03:36 +0000310 auto Space = isl_schedule_node_band_get_space(Node);
311 auto ScheduleDimensions = isl_space_dim(Space, isl_dim_set);
312 isl_space_free(Space);
313 assert(DimToVectorize < ScheduleDimensions);
Tobias Grosserf5338802011-10-06 00:03:35 +0000314
Tobias Grosserb241d922015-07-28 18:03:36 +0000315 if (DimToVectorize > 0) {
316 Node = isl_schedule_node_band_split(Node, DimToVectorize);
317 Node = isl_schedule_node_child(Node, 0);
318 }
319 if (DimToVectorize < ScheduleDimensions - 1)
320 Node = isl_schedule_node_band_split(Node, 1);
321 Space = isl_schedule_node_band_get_space(Node);
322 auto Sizes = isl_multi_val_zero(Space);
323 auto Ctx = isl_schedule_node_get_ctx(Node);
324 Sizes =
325 isl_multi_val_set_val(Sizes, 0, isl_val_int_from_si(Ctx, VectorWidth));
326 Node = isl_schedule_node_band_tile(Node, Sizes);
Tobias Grosserca7f5bb2015-10-20 09:12:21 +0000327 Node = isolateFullPartialTiles(Node, VectorWidth);
Tobias Grosserb241d922015-07-28 18:03:36 +0000328 Node = isl_schedule_node_child(Node, 0);
Tobias Grosser42e24892015-08-20 13:45:05 +0000329 // Make sure the "trivially vectorizable loop" is not unrolled. Otherwise,
330 // we will have troubles to match it in the backend.
331 Node = isl_schedule_node_band_set_ast_build_options(
Tobias Grosserfc490a92015-08-20 19:08:16 +0000332 Node, isl_union_set_read_from_str(Ctx, "{ unroll[x]: 1 = 0 }"));
333 Node = isl_schedule_node_band_sink(Node);
Tobias Grosserb241d922015-07-28 18:03:36 +0000334 Node = isl_schedule_node_child(Node, 0);
Roman Gareev11001e12016-02-23 09:00:13 +0000335 if (isl_schedule_node_get_type(Node) == isl_schedule_node_leaf)
336 Node = isl_schedule_node_parent(Node);
337 isl_id *LoopMarker = isl_id_alloc(Ctx, "SIMD", nullptr);
338 Node = isl_schedule_node_insert_mark(Node, LoopMarker);
Tobias Grosserb241d922015-07-28 18:03:36 +0000339 return Node;
Tobias Grosserc6699b72011-06-30 20:29:13 +0000340}
341
Tobias Grosserd891b542015-08-20 12:16:23 +0000342__isl_give isl_schedule_node *
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000343ScheduleTreeOptimizer::tileNode(__isl_take isl_schedule_node *Node,
344 const char *Identifier, ArrayRef<int> TileSizes,
345 int DefaultTileSize) {
Tobias Grosser9bdea572015-08-20 12:22:37 +0000346 auto Ctx = isl_schedule_node_get_ctx(Node);
347 auto Space = isl_schedule_node_band_get_space(Node);
348 auto Dims = isl_space_dim(Space, isl_dim_set);
349 auto Sizes = isl_multi_val_zero(Space);
Tobias Grosser1ac884d2015-08-23 09:11:00 +0000350 std::string IdentifierString(Identifier);
Tobias Grosser9bdea572015-08-20 12:22:37 +0000351 for (unsigned i = 0; i < Dims; i++) {
352 auto tileSize = i < TileSizes.size() ? TileSizes[i] : DefaultTileSize;
353 Sizes = isl_multi_val_set_val(Sizes, i, isl_val_int_from_si(Ctx, tileSize));
354 }
Tobias Grosser1ac884d2015-08-23 09:11:00 +0000355 auto TileLoopMarkerStr = IdentifierString + " - Tiles";
356 isl_id *TileLoopMarker =
357 isl_id_alloc(Ctx, TileLoopMarkerStr.c_str(), nullptr);
358 Node = isl_schedule_node_insert_mark(Node, TileLoopMarker);
359 Node = isl_schedule_node_child(Node, 0);
Tobias Grosser9bdea572015-08-20 12:22:37 +0000360 Node = isl_schedule_node_band_tile(Node, Sizes);
Tobias Grosser1ac884d2015-08-23 09:11:00 +0000361 Node = isl_schedule_node_child(Node, 0);
362 auto PointLoopMarkerStr = IdentifierString + " - Points";
363 isl_id *PointLoopMarker =
364 isl_id_alloc(Ctx, PointLoopMarkerStr.c_str(), nullptr);
365 Node = isl_schedule_node_insert_mark(Node, PointLoopMarker);
366 Node = isl_schedule_node_child(Node, 0);
367 return Node;
Tobias Grosser9bdea572015-08-20 12:22:37 +0000368}
369
Roman Gareevb17b9a82016-06-12 17:20:05 +0000370__isl_give isl_schedule_node *
371ScheduleTreeOptimizer::applyRegisterTiling(__isl_take isl_schedule_node *Node,
372 llvm::ArrayRef<int> TileSizes,
373 int DefaultTileSize) {
374 auto *Ctx = isl_schedule_node_get_ctx(Node);
375 Node = tileNode(Node, "Register tiling", TileSizes, DefaultTileSize);
376 Node = isl_schedule_node_band_set_ast_build_options(
377 Node, isl_union_set_read_from_str(Ctx, "{unroll[x]}"));
378 return Node;
379}
380
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000381bool ScheduleTreeOptimizer::isTileableBandNode(
Tobias Grosser862b9b52015-08-20 12:32:45 +0000382 __isl_keep isl_schedule_node *Node) {
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000383 if (isl_schedule_node_get_type(Node) != isl_schedule_node_band)
Tobias Grosser862b9b52015-08-20 12:32:45 +0000384 return false;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000385
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000386 if (isl_schedule_node_n_children(Node) != 1)
Tobias Grosser862b9b52015-08-20 12:32:45 +0000387 return false;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000388
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000389 if (!isl_schedule_node_band_get_permutable(Node))
Tobias Grosser862b9b52015-08-20 12:32:45 +0000390 return false;
Tobias Grosser44f19ac2011-07-05 22:15:53 +0000391
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000392 auto Space = isl_schedule_node_band_get_space(Node);
393 auto Dims = isl_space_dim(Space, isl_dim_set);
Tobias Grosser9bdea572015-08-20 12:22:37 +0000394 isl_space_free(Space);
Tobias Grosserde68cc92011-06-30 20:01:02 +0000395
Tobias Grosser9bdea572015-08-20 12:22:37 +0000396 if (Dims <= 1)
Tobias Grosser862b9b52015-08-20 12:32:45 +0000397 return false;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000398
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000399 auto Child = isl_schedule_node_get_child(Node, 0);
400 auto Type = isl_schedule_node_get_type(Child);
401 isl_schedule_node_free(Child);
402
Tobias Grosser9bdea572015-08-20 12:22:37 +0000403 if (Type != isl_schedule_node_leaf)
Tobias Grosser862b9b52015-08-20 12:32:45 +0000404 return false;
405
406 return true;
407}
408
409__isl_give isl_schedule_node *
Roman Gareev9c3eb592016-05-28 16:17:58 +0000410ScheduleTreeOptimizer::standardBandOpts(__isl_take isl_schedule_node *Node,
411 void *User) {
Tobias Grosser04832712015-08-20 13:45:02 +0000412 if (FirstLevelTiling)
Tobias Grosser1ac884d2015-08-23 09:11:00 +0000413 Node = tileNode(Node, "1st level tiling", FirstLevelTileSizes,
414 FirstLevelDefaultTileSize);
Tobias Grosser04832712015-08-20 13:45:02 +0000415
416 if (SecondLevelTiling)
Tobias Grosser1ac884d2015-08-23 09:11:00 +0000417 Node = tileNode(Node, "2nd level tiling", SecondLevelTileSizes,
418 SecondLevelDefaultTileSize);
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000419
Roman Gareevb17b9a82016-06-12 17:20:05 +0000420 if (RegisterTiling)
421 Node =
422 applyRegisterTiling(Node, RegisterTileSizes, RegisterDefaultTileSize);
Tobias Grosser42e24892015-08-20 13:45:05 +0000423
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000424 if (PollyVectorizerChoice == VECTORIZER_NONE)
Tobias Grosserf10f4632015-08-19 08:03:37 +0000425 return Node;
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000426
Tobias Grosser862b9b52015-08-20 12:32:45 +0000427 auto Space = isl_schedule_node_band_get_space(Node);
428 auto Dims = isl_space_dim(Space, isl_dim_set);
429 isl_space_free(Space);
430
Tobias Grosserb241d922015-07-28 18:03:36 +0000431 for (int i = Dims - 1; i >= 0; i--)
Tobias Grosserf10f4632015-08-19 08:03:37 +0000432 if (isl_schedule_node_band_member_get_coincident(Node, i)) {
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000433 Node = prevectSchedBand(Node, i, PrevectorWidth);
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000434 break;
435 }
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000436
Tobias Grosserf10f4632015-08-19 08:03:37 +0000437 return Node;
Tobias Grosserde68cc92011-06-30 20:01:02 +0000438}
439
Tobias Grosserc80d6972016-09-02 06:33:33 +0000440/// Check whether output dimensions of the map rely on the specified input
441/// dimension.
Roman Gareev9c3eb592016-05-28 16:17:58 +0000442///
443/// @param IslMap The isl map to be considered.
444/// @param DimNum The number of an input dimension to be checked.
445static bool isInputDimUsed(__isl_take isl_map *IslMap, unsigned DimNum) {
446 auto *CheckedAccessRelation =
447 isl_map_project_out(isl_map_copy(IslMap), isl_dim_in, DimNum, 1);
448 CheckedAccessRelation =
449 isl_map_insert_dims(CheckedAccessRelation, isl_dim_in, DimNum, 1);
450 auto *InputDimsId = isl_map_get_tuple_id(IslMap, isl_dim_in);
451 CheckedAccessRelation =
452 isl_map_set_tuple_id(CheckedAccessRelation, isl_dim_in, InputDimsId);
453 InputDimsId = isl_map_get_tuple_id(IslMap, isl_dim_out);
454 CheckedAccessRelation =
455 isl_map_set_tuple_id(CheckedAccessRelation, isl_dim_out, InputDimsId);
456 auto res = !isl_map_is_equal(CheckedAccessRelation, IslMap);
457 isl_map_free(CheckedAccessRelation);
458 isl_map_free(IslMap);
459 return res;
460}
461
Tobias Grosserc80d6972016-09-02 06:33:33 +0000462/// Check if the SCoP statement could probably be optimized with analytical
463/// modeling.
Roman Gareev9c3eb592016-05-28 16:17:58 +0000464///
465/// containsMatrMult tries to determine whether the following conditions
466/// are true:
467/// 1. all memory accesses of the statement will have stride 0 or 1,
468/// if we interchange loops (switch the variable used in the inner
469/// loop to the outer loop).
470/// 2. all memory accesses of the statement except from the last one, are
471/// read memory access and the last one is write memory access.
Roman Gareev76614d32016-05-31 11:22:21 +0000472/// 3. all subscripts of the last memory access of the statement don't contain
Roman Gareev9c3eb592016-05-28 16:17:58 +0000473/// the variable used in the inner loop.
474///
475/// @param PartialSchedule The PartialSchedule that contains a SCoP statement
476/// to check.
477static bool containsMatrMult(__isl_keep isl_map *PartialSchedule) {
478 auto InputDimsId = isl_map_get_tuple_id(PartialSchedule, isl_dim_in);
479 auto *ScpStmt = static_cast<ScopStmt *>(isl_id_get_user(InputDimsId));
480 isl_id_free(InputDimsId);
481 if (ScpStmt->size() <= 1)
482 return false;
483 auto MemA = ScpStmt->begin();
484 for (unsigned i = 0; i < ScpStmt->size() - 2 && MemA != ScpStmt->end();
485 i++, MemA++)
Roman Gareev76614d32016-05-31 11:22:21 +0000486 if (!(*MemA)->isRead() ||
487 ((*MemA)->isArrayKind() &&
488 !((*MemA)->isStrideOne(isl_map_copy(PartialSchedule)) ||
Roman Gareev9c3eb592016-05-28 16:17:58 +0000489 (*MemA)->isStrideZero(isl_map_copy(PartialSchedule)))))
490 return false;
491 MemA++;
Roman Gareev76614d32016-05-31 11:22:21 +0000492 if (!(*MemA)->isWrite() || !(*MemA)->isArrayKind() ||
493 !((*MemA)->isStrideOne(isl_map_copy(PartialSchedule)) ||
Roman Gareev9c3eb592016-05-28 16:17:58 +0000494 (*MemA)->isStrideZero(isl_map_copy(PartialSchedule))))
495 return false;
496 auto DimNum = isl_map_dim(PartialSchedule, isl_dim_in);
497 return !isInputDimUsed((*MemA)->getAccessRelation(), DimNum - 1);
498}
499
Tobias Grosserc80d6972016-09-02 06:33:33 +0000500/// Circular shift of output dimensions of the integer map.
Roman Gareev9c3eb592016-05-28 16:17:58 +0000501///
502/// @param IslMap The isl map to be modified.
503static __isl_give isl_map *circularShiftOutputDims(__isl_take isl_map *IslMap) {
Roman Gareev9c3eb592016-05-28 16:17:58 +0000504 auto DimNum = isl_map_dim(IslMap, isl_dim_out);
Roman Gareev4b8c7ae2016-06-03 18:46:29 +0000505 if (DimNum == 0)
506 return IslMap;
507 auto InputDimsId = isl_map_get_tuple_id(IslMap, isl_dim_in);
Roman Gareev9c3eb592016-05-28 16:17:58 +0000508 IslMap = isl_map_move_dims(IslMap, isl_dim_in, 0, isl_dim_out, DimNum - 1, 1);
509 IslMap = isl_map_move_dims(IslMap, isl_dim_out, 0, isl_dim_in, 0, 1);
510 return isl_map_set_tuple_id(IslMap, isl_dim_in, InputDimsId);
511}
512
Tobias Grosserc80d6972016-09-02 06:33:33 +0000513/// Permute two dimensions of the band node.
Roman Gareev3a18a932016-07-25 09:42:53 +0000514///
515/// Permute FirstDim and SecondDim dimensions of the Node.
516///
517/// @param Node The band node to be modified.
518/// @param FirstDim The first dimension to be permuted.
519/// @param SecondDim The second dimension to be permuted.
520static __isl_give isl_schedule_node *
521permuteBandNodeDimensions(__isl_take isl_schedule_node *Node, unsigned FirstDim,
522 unsigned SecondDim) {
523 assert(isl_schedule_node_get_type(Node) == isl_schedule_node_band &&
524 isl_schedule_node_band_n_member(Node) > std::max(FirstDim, SecondDim));
525 auto PartialSchedule = isl_schedule_node_band_get_partial_schedule(Node);
526 auto PartialScheduleFirstDim =
527 isl_multi_union_pw_aff_get_union_pw_aff(PartialSchedule, FirstDim);
528 auto PartialScheduleSecondDim =
529 isl_multi_union_pw_aff_get_union_pw_aff(PartialSchedule, SecondDim);
530 PartialSchedule = isl_multi_union_pw_aff_set_union_pw_aff(
531 PartialSchedule, SecondDim, PartialScheduleFirstDim);
532 PartialSchedule = isl_multi_union_pw_aff_set_union_pw_aff(
533 PartialSchedule, FirstDim, PartialScheduleSecondDim);
534 Node = isl_schedule_node_delete(Node);
535 Node = isl_schedule_node_insert_partial_schedule(Node, PartialSchedule);
536 return Node;
537}
538
Roman Gareev2cb4d132016-07-25 07:27:59 +0000539__isl_give isl_schedule_node *ScheduleTreeOptimizer::createMicroKernel(
540 __isl_take isl_schedule_node *Node, MicroKernelParamsTy MicroKernelParams) {
541 return applyRegisterTiling(Node, {MicroKernelParams.Mr, MicroKernelParams.Nr},
542 1);
543}
544
Roman Gareev3a18a932016-07-25 09:42:53 +0000545__isl_give isl_schedule_node *ScheduleTreeOptimizer::createMacroKernel(
546 __isl_take isl_schedule_node *Node, MacroKernelParamsTy MacroKernelParams) {
547 assert(isl_schedule_node_get_type(Node) == isl_schedule_node_band);
548 if (MacroKernelParams.Mc == 1 && MacroKernelParams.Nc == 1 &&
549 MacroKernelParams.Kc == 1)
550 return Node;
551 Node = tileNode(
552 Node, "1st level tiling",
553 {MacroKernelParams.Mc, MacroKernelParams.Nc, MacroKernelParams.Kc}, 1);
554 Node = isl_schedule_node_parent(isl_schedule_node_parent(Node));
555 Node = permuteBandNodeDimensions(Node, 1, 2);
556 return isl_schedule_node_child(isl_schedule_node_child(Node, 0), 0);
557}
558
Roman Gareev2cb4d132016-07-25 07:27:59 +0000559/// Get parameters of the BLIS micro kernel.
560///
561/// We choose the Mr and Nr parameters of the micro kernel to be large enough
562/// such that no stalls caused by the combination of latencies and dependencies
563/// are introduced during the updates of the resulting matrix of the matrix
564/// multiplication. However, they should also be as small as possible to
565/// release more registers for entries of multiplied matrices.
566///
567/// @param TTI Target Transform Info.
568/// @return The structure of type MicroKernelParamsTy.
569/// @see MicroKernelParamsTy
570static struct MicroKernelParamsTy
571getMicroKernelParams(const llvm::TargetTransformInfo *TTI) {
Roman Gareev42402c92016-06-22 09:52:37 +0000572 assert(TTI && "The target transform info should be provided.");
Roman Gareev2cb4d132016-07-25 07:27:59 +0000573
Roman Gareev42402c92016-06-22 09:52:37 +0000574 // Nvec - Number of double-precision floating-point numbers that can be hold
575 // by a vector register. Use 2 by default.
576 auto Nvec = TTI->getRegisterBitWidth(true) / 64;
577 if (Nvec == 0)
578 Nvec = 2;
579 int Nr =
580 ceil(sqrt(Nvec * LatencyVectorFma * ThrougputVectorFma) / Nvec) * Nvec;
581 int Mr = ceil(Nvec * LatencyVectorFma * ThrougputVectorFma / Nr);
Roman Gareev2cb4d132016-07-25 07:27:59 +0000582 return {Mr, Nr};
583}
584
Roman Gareev3a18a932016-07-25 09:42:53 +0000585/// Get parameters of the BLIS macro kernel.
586///
587/// During the computation of matrix multiplication, blocks of partitioned
588/// matrices are mapped to different layers of the memory hierarchy.
589/// To optimize data reuse, blocks should be ideally kept in cache between
590/// iterations. Since parameters of the macro kernel determine sizes of these
591/// blocks, there are upper and lower bounds on these parameters.
592///
593/// @param MicroKernelParams Parameters of the micro-kernel
594/// to be taken into account.
595/// @return The structure of type MacroKernelParamsTy.
596/// @see MacroKernelParamsTy
597/// @see MicroKernelParamsTy
598static struct MacroKernelParamsTy
599getMacroKernelParams(const MicroKernelParamsTy &MicroKernelParams) {
600 // According to www.cs.utexas.edu/users/flame/pubs/TOMS-BLIS-Analytical.pdf,
601 // it requires information about the first two levels of a cache to determine
602 // all the parameters of a macro-kernel. It also checks that an associativity
603 // degree of a cache level is greater than two. Otherwise, another algorithm
604 // for determination of the parameters should be used.
605 if (!(MicroKernelParams.Mr > 0 && MicroKernelParams.Nr > 0 &&
606 CacheLevelSizes.size() >= 2 && CacheLevelAssociativity.size() >= 2 &&
607 CacheLevelSizes[0] > 0 && CacheLevelSizes[1] > 0 &&
608 CacheLevelAssociativity[0] > 2 && CacheLevelAssociativity[1] > 2))
609 return {1, 1, 1};
610 int Cbr = floor(
611 (CacheLevelAssociativity[0] - 1) /
612 (1 + static_cast<double>(MicroKernelParams.Mr) / MicroKernelParams.Nr));
613 int Kc = (Cbr * CacheLevelSizes[0]) /
614 (MicroKernelParams.Nr * CacheLevelAssociativity[0] * 8);
615 double Cac = static_cast<double>(MicroKernelParams.Mr * Kc * 8 *
616 CacheLevelAssociativity[1]) /
617 CacheLevelSizes[1];
618 double Cbc = static_cast<double>(MicroKernelParams.Nr * Kc * 8 *
619 CacheLevelAssociativity[1]) /
620 CacheLevelSizes[1];
621 int Mc = floor(MicroKernelParams.Mr / Cac);
622 int Nc =
623 floor((MicroKernelParams.Nr * (CacheLevelAssociativity[1] - 2)) / Cbc);
624 return {Mc, Nc, Kc};
625}
626
Tobias Grosserc80d6972016-09-02 06:33:33 +0000627/// Identify a memory access through the shape of its memory access relation.
Roman Gareev1c892e92016-08-15 12:22:54 +0000628///
629/// Identify the unique memory access in @p Stmt, that has an access relation
630/// equal to @p ExpectedAccessRelation.
631///
632/// @param Stmt The SCoP statement that contains the memory accesses under
633/// consideration.
634/// @param ExpectedAccessRelation The access relation that identifies
635/// the memory access.
636/// @return The memory access of @p Stmt whose memory access relation is equal
637/// to @p ExpectedAccessRelation. nullptr in case there is no or more
638/// than one such access.
639MemoryAccess *
640identifyAccessByAccessRelation(ScopStmt *Stmt,
641 __isl_take isl_map *ExpectedAccessRelation) {
642 if (isl_map_has_tuple_id(ExpectedAccessRelation, isl_dim_out))
643 ExpectedAccessRelation =
644 isl_map_reset_tuple_id(ExpectedAccessRelation, isl_dim_out);
645 MemoryAccess *IdentifiedAccess = nullptr;
646 for (auto *Access : *Stmt) {
647 auto *AccessRelation = Access->getAccessRelation();
648 AccessRelation = isl_map_reset_tuple_id(AccessRelation, isl_dim_out);
649 if (isl_map_is_equal(ExpectedAccessRelation, AccessRelation)) {
650 if (IdentifiedAccess) {
651 isl_map_free(AccessRelation);
652 isl_map_free(ExpectedAccessRelation);
653 return nullptr;
654 }
655 IdentifiedAccess = Access;
656 }
657 isl_map_free(AccessRelation);
658 }
659 isl_map_free(ExpectedAccessRelation);
660 return IdentifiedAccess;
661}
662
Tobias Grosserc80d6972016-09-02 06:33:33 +0000663/// Create an access relation that is specific to the matrix
Roman Gareev1c892e92016-08-15 12:22:54 +0000664/// multiplication pattern.
665///
666/// Create an access relation of the following form:
667/// Stmt[O0, O1, O2]->[OI, OJ],
668/// where I is @p I, J is @J
669///
670/// @param Stmt The SCoP statement for which to generate the access relation.
671/// @param I The index of the input dimension that is mapped to the first output
672/// dimension.
673/// @param J The index of the input dimension that is mapped to the second
674/// output dimension.
675/// @return The specified access relation.
676__isl_give isl_map *
677getMatMulPatternOriginalAccessRelation(ScopStmt *Stmt, unsigned I, unsigned J) {
678 auto *AccessRelSpace = isl_space_alloc(Stmt->getIslCtx(), 0, 3, 2);
679 auto *AccessRel = isl_map_universe(AccessRelSpace);
680 AccessRel = isl_map_equate(AccessRel, isl_dim_in, I, isl_dim_out, 0);
681 AccessRel = isl_map_equate(AccessRel, isl_dim_in, J, isl_dim_out, 1);
682 AccessRel = isl_map_set_tuple_id(AccessRel, isl_dim_in, Stmt->getDomainId());
683 return AccessRel;
684}
685
Tobias Grosserc80d6972016-09-02 06:33:33 +0000686/// Identify the memory access that corresponds to the access to the second
687/// operand of the matrix multiplication.
Roman Gareev1c892e92016-08-15 12:22:54 +0000688///
689/// Identify the memory access that corresponds to the access
690/// to the matrix B of the matrix multiplication C = A x B.
691///
692/// @param Stmt The SCoP statement that contains the memory accesses
693/// under consideration.
694/// @return The memory access of @p Stmt that corresponds to the access
695/// to the second operand of the matrix multiplication.
696MemoryAccess *identifyAccessA(ScopStmt *Stmt) {
697 auto *OriginalRel = getMatMulPatternOriginalAccessRelation(Stmt, 0, 2);
698 return identifyAccessByAccessRelation(Stmt, OriginalRel);
699}
700
Tobias Grosserc80d6972016-09-02 06:33:33 +0000701/// Identify the memory access that corresponds to the access to the first
702/// operand of the matrix multiplication.
Roman Gareev1c892e92016-08-15 12:22:54 +0000703///
704/// Identify the memory access that corresponds to the access
705/// to the matrix A of the matrix multiplication C = A x B.
706///
707/// @param Stmt The SCoP statement that contains the memory accesses
708/// under consideration.
709/// @return The memory access of @p Stmt that corresponds to the access
710/// to the first operand of the matrix multiplication.
711MemoryAccess *identifyAccessB(ScopStmt *Stmt) {
712 auto *OriginalRel = getMatMulPatternOriginalAccessRelation(Stmt, 2, 1);
713 return identifyAccessByAccessRelation(Stmt, OriginalRel);
714}
715
Tobias Grosserc80d6972016-09-02 06:33:33 +0000716/// Create an access relation that is specific to
Roman Gareev1c892e92016-08-15 12:22:54 +0000717/// the matrix multiplication pattern.
718///
719/// Create an access relation of the following form:
Roman Gareevf5aff702016-09-12 17:08:31 +0000720/// [O0, O1, O2, O3, O4, O5, O6, O7, O8] -> [O5 + K * OI, OJ],
Roman Gareev1c892e92016-08-15 12:22:54 +0000721/// where K is @p Coeff, I is @p FirstDim, J is @p SecondDim.
722///
723/// It can be used, for example, to create relations that helps to consequently
724/// access elements of operands of a matrix multiplication after creation of
725/// the BLIS micro and macro kernels.
726///
727/// @see ScheduleTreeOptimizer::createMicroKernel
728/// @see ScheduleTreeOptimizer::createMacroKernel
729///
730/// Subsequently, the described access relation is applied to the range of
731/// @p MapOldIndVar, that is used to map original induction variables to
732/// the ones, which are produced by schedule transformations. It helps to
733/// define relations using a new space and, at the same time, keep them
734/// in the original one.
735///
736/// @param MapOldIndVar The relation, which maps original induction variables
737/// to the ones, which are produced by schedule
738/// transformations.
739/// @param Coeff The coefficient that is used to define the specified access
740/// relation.
741/// @param FirstDim, SecondDim The input dimensions that are used to define
742/// the specified access relation.
743/// @return The specified access relation.
744__isl_give isl_map *getMatMulAccRel(__isl_take isl_map *MapOldIndVar,
745 unsigned Coeff, unsigned FirstDim,
746 unsigned SecondDim) {
747 auto *Ctx = isl_map_get_ctx(MapOldIndVar);
Roman Gareevf5aff702016-09-12 17:08:31 +0000748 auto *AccessRelSpace = isl_space_alloc(Ctx, 0, 9, 2);
Roman Gareev1c892e92016-08-15 12:22:54 +0000749 auto *AccessRel = isl_map_universe(isl_space_copy(AccessRelSpace));
750 auto *ConstrSpace = isl_local_space_from_space(AccessRelSpace);
751 auto *Constr = isl_constraint_alloc_equality(ConstrSpace);
Roman Gareevf5aff702016-09-12 17:08:31 +0000752 Constr = isl_constraint_set_coefficient_si(Constr, isl_dim_out, 0, -1);
Roman Gareev1c892e92016-08-15 12:22:54 +0000753 Constr = isl_constraint_set_coefficient_si(Constr, isl_dim_in, 5, 1);
754 Constr =
755 isl_constraint_set_coefficient_si(Constr, isl_dim_in, FirstDim, Coeff);
756 AccessRel = isl_map_add_constraint(AccessRel, Constr);
Roman Gareevf5aff702016-09-12 17:08:31 +0000757 AccessRel = isl_map_equate(AccessRel, isl_dim_in, SecondDim, isl_dim_out, 1);
Roman Gareev1c892e92016-08-15 12:22:54 +0000758 return isl_map_apply_range(MapOldIndVar, AccessRel);
759}
760
Tobias Grosserc80d6972016-09-02 06:33:33 +0000761/// Apply the packing transformation.
Roman Gareev1c892e92016-08-15 12:22:54 +0000762///
763/// The packing transformation can be described as a data-layout
764/// transformation that requires to introduce a new array, copy data
765/// to the array, and change memory access locations of the compute kernel
766/// to reference the array.
767///
768/// @param Node The schedule node to be optimized.
769/// @param MapOldIndVar The relation, which maps original induction variables
770/// to the ones, which are produced by schedule
771/// transformations.
772/// @param MicroParams, MacroParams Parameters of the BLIS kernel
773/// to be taken into account.
774/// @return The optimized schedule node.
775static void optimizeDataLayoutMatrMulPattern(__isl_take isl_map *MapOldIndVar,
776 MicroKernelParamsTy MicroParams,
777 MacroKernelParamsTy MacroParams) {
778 auto InputDimsId = isl_map_get_tuple_id(MapOldIndVar, isl_dim_in);
779 auto *Stmt = static_cast<ScopStmt *>(isl_id_get_user(InputDimsId));
780 isl_id_free(InputDimsId);
781 MemoryAccess *MemAccessA = identifyAccessA(Stmt);
782 MemoryAccess *MemAccessB = identifyAccessB(Stmt);
783 if (!MemAccessA || !MemAccessB) {
784 isl_map_free(MapOldIndVar);
785 return;
786 }
787 auto *AccRel =
788 getMatMulAccRel(isl_map_copy(MapOldIndVar), MacroParams.Kc, 3, 6);
789 unsigned FirstDimSize = MacroParams.Mc * MacroParams.Kc / MicroParams.Mr;
790 unsigned SecondDimSize = MicroParams.Mr;
791 auto *SAI = Stmt->getParent()->createScopArrayInfo(
792 MemAccessA->getElementType(), "Packed_A", {FirstDimSize, SecondDimSize});
793 AccRel = isl_map_set_tuple_id(AccRel, isl_dim_out, SAI->getBasePtrId());
794 MemAccessA->setNewAccessRelation(AccRel);
795 AccRel = getMatMulAccRel(MapOldIndVar, MacroParams.Kc, 4, 7);
796 FirstDimSize = MacroParams.Nc * MacroParams.Kc / MicroParams.Nr;
797 SecondDimSize = MicroParams.Nr;
798 SAI = Stmt->getParent()->createScopArrayInfo(
799 MemAccessB->getElementType(), "Packed_B", {FirstDimSize, SecondDimSize});
800 AccRel = isl_map_set_tuple_id(AccRel, isl_dim_out, SAI->getBasePtrId());
801 MemAccessB->setNewAccessRelation(AccRel);
802}
803
Tobias Grosserc80d6972016-09-02 06:33:33 +0000804/// Get a relation mapping induction variables produced by schedule
805/// transformations to the original ones.
Roman Gareev1c892e92016-08-15 12:22:54 +0000806///
807/// @param Node The schedule node produced as the result of creation
808/// of the BLIS kernels.
809/// @param MicroKernelParams, MacroKernelParams Parameters of the BLIS kernel
810/// to be taken into account.
811/// @return The relation mapping original induction variables to the ones
812/// produced by schedule transformation.
813/// @see ScheduleTreeOptimizer::createMicroKernel
814/// @see ScheduleTreeOptimizer::createMacroKernel
815/// @see getMacroKernelParams
816__isl_give isl_map *
817getInductionVariablesSubstitution(__isl_take isl_schedule_node *Node,
818 MicroKernelParamsTy MicroKernelParams,
819 MacroKernelParamsTy MacroKernelParams) {
820 auto *Child = isl_schedule_node_get_child(Node, 0);
821 auto *UnMapOldIndVar = isl_schedule_node_get_prefix_schedule_union_map(Child);
822 isl_schedule_node_free(Child);
823 auto *MapOldIndVar = isl_map_from_union_map(UnMapOldIndVar);
824 if (isl_map_dim(MapOldIndVar, isl_dim_out) > 9)
825 MapOldIndVar =
826 isl_map_project_out(MapOldIndVar, isl_dim_out, 0,
827 isl_map_dim(MapOldIndVar, isl_dim_out) - 9);
828 return MapOldIndVar;
829}
830
Roman Gareev2cb4d132016-07-25 07:27:59 +0000831__isl_give isl_schedule_node *ScheduleTreeOptimizer::optimizeMatMulPattern(
832 __isl_take isl_schedule_node *Node, const llvm::TargetTransformInfo *TTI) {
833 assert(TTI && "The target transform info should be provided.");
834 auto MicroKernelParams = getMicroKernelParams(TTI);
Roman Gareev3a18a932016-07-25 09:42:53 +0000835 auto MacroKernelParams = getMacroKernelParams(MicroKernelParams);
836 Node = createMacroKernel(Node, MacroKernelParams);
Roman Gareev2cb4d132016-07-25 07:27:59 +0000837 Node = createMicroKernel(Node, MicroKernelParams);
Roman Gareev1c892e92016-08-15 12:22:54 +0000838 if (MacroKernelParams.Mc == 1 || MacroKernelParams.Nc == 1 ||
839 MacroKernelParams.Kc == 1)
840 return Node;
841 auto *MapOldIndVar = getInductionVariablesSubstitution(
842 Node, MicroKernelParams, MacroKernelParams);
843 if (!MapOldIndVar)
844 return Node;
845 optimizeDataLayoutMatrMulPattern(MapOldIndVar, MicroKernelParams,
846 MacroKernelParams);
Roman Gareev42402c92016-06-22 09:52:37 +0000847 return Node;
848}
849
Roman Gareev9c3eb592016-05-28 16:17:58 +0000850bool ScheduleTreeOptimizer::isMatrMultPattern(
851 __isl_keep isl_schedule_node *Node) {
852 auto *PartialSchedule =
853 isl_schedule_node_band_get_partial_schedule_union_map(Node);
Roman Gareev397a34a2016-06-22 12:11:30 +0000854 if (isl_schedule_node_band_n_member(Node) != 3 ||
855 isl_union_map_n_map(PartialSchedule) != 1) {
856 isl_union_map_free(PartialSchedule);
Roman Gareev9c3eb592016-05-28 16:17:58 +0000857 return false;
858 }
Roman Gareev397a34a2016-06-22 12:11:30 +0000859 auto *NewPartialSchedule = isl_map_from_union_map(PartialSchedule);
Roman Gareev9c3eb592016-05-28 16:17:58 +0000860 NewPartialSchedule = circularShiftOutputDims(NewPartialSchedule);
861 if (containsMatrMult(NewPartialSchedule)) {
862 isl_map_free(NewPartialSchedule);
863 return true;
864 }
865 isl_map_free(NewPartialSchedule);
866 return false;
867}
868
869__isl_give isl_schedule_node *
870ScheduleTreeOptimizer::optimizeBand(__isl_take isl_schedule_node *Node,
871 void *User) {
872 if (!isTileableBandNode(Node))
873 return Node;
874
Roman Gareev42402c92016-06-22 09:52:37 +0000875 if (PMBasedOpts && User && isMatrMultPattern(Node)) {
Roman Gareev9c3eb592016-05-28 16:17:58 +0000876 DEBUG(dbgs() << "The matrix multiplication pattern was detected\n");
Roman Gareev42402c92016-06-22 09:52:37 +0000877 const llvm::TargetTransformInfo *TTI;
878 TTI = static_cast<const llvm::TargetTransformInfo *>(User);
879 Node = optimizeMatMulPattern(Node, TTI);
880 }
Roman Gareev9c3eb592016-05-28 16:17:58 +0000881
882 return standardBandOpts(Node, User);
883}
884
Tobias Grosser808cd692015-07-14 09:33:13 +0000885__isl_give isl_schedule *
Roman Gareev42402c92016-06-22 09:52:37 +0000886ScheduleTreeOptimizer::optimizeSchedule(__isl_take isl_schedule *Schedule,
887 const llvm::TargetTransformInfo *TTI) {
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000888 isl_schedule_node *Root = isl_schedule_get_root(Schedule);
Roman Gareev42402c92016-06-22 09:52:37 +0000889 Root = optimizeScheduleNode(Root, TTI);
Tobias Grosser808cd692015-07-14 09:33:13 +0000890 isl_schedule_free(Schedule);
Tobias Grosser808cd692015-07-14 09:33:13 +0000891 auto S = isl_schedule_node_get_schedule(Root);
Tobias Grosserbbb4cec2015-03-22 12:06:39 +0000892 isl_schedule_node_free(Root);
Tobias Grosser808cd692015-07-14 09:33:13 +0000893 return S;
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000894}
895
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000896__isl_give isl_schedule_node *ScheduleTreeOptimizer::optimizeScheduleNode(
Roman Gareev42402c92016-06-22 09:52:37 +0000897 __isl_take isl_schedule_node *Node, const llvm::TargetTransformInfo *TTI) {
898 Node = isl_schedule_node_map_descendant_bottom_up(
899 Node, optimizeBand, const_cast<void *>(static_cast<const void *>(TTI)));
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000900 return Node;
901}
902
903bool ScheduleTreeOptimizer::isProfitableSchedule(
Johannes Doerfert7ceb0402015-02-11 17:25:09 +0000904 Scop &S, __isl_keep isl_union_map *NewSchedule) {
905 // To understand if the schedule has been optimized we check if the schedule
906 // has changed at all.
907 // TODO: We can improve this by tracking if any necessarily beneficial
908 // transformations have been performed. This can e.g. be tiling, loop
909 // interchange, or ...) We can track this either at the place where the
910 // transformation has been performed or, in case of automatic ILP based
911 // optimizations, by comparing (yet to be defined) performance metrics
912 // before/after the scheduling optimizer
913 // (e.g., #stride-one accesses)
914 isl_union_map *OldSchedule = S.getSchedule();
915 bool changed = !isl_union_map_is_equal(OldSchedule, NewSchedule);
916 isl_union_map_free(OldSchedule);
917 return changed;
918}
919
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000920namespace {
921class IslScheduleOptimizer : public ScopPass {
922public:
923 static char ID;
924 explicit IslScheduleOptimizer() : ScopPass(ID) { LastSchedule = nullptr; }
925
926 ~IslScheduleOptimizer() { isl_schedule_free(LastSchedule); }
927
Tobias Grosserc80d6972016-09-02 06:33:33 +0000928 /// Optimize the schedule of the SCoP @p S.
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000929 bool runOnScop(Scop &S) override;
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000930
Tobias Grosserc80d6972016-09-02 06:33:33 +0000931 /// Print the new schedule for the SCoP @p S.
Johannes Doerfert45be6442015-09-27 15:43:29 +0000932 void printScop(raw_ostream &OS, Scop &S) const override;
933
Tobias Grosserc80d6972016-09-02 06:33:33 +0000934 /// Register all analyses and transformation required.
Johannes Doerfert45be6442015-09-27 15:43:29 +0000935 void getAnalysisUsage(AnalysisUsage &AU) const override;
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000936
Tobias Grosserc80d6972016-09-02 06:33:33 +0000937 /// Release the internal memory.
Johannes Doerfert0f376302015-09-27 15:42:28 +0000938 void releaseMemory() override {
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000939 isl_schedule_free(LastSchedule);
940 LastSchedule = nullptr;
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000941 }
Johannes Doerfert45be6442015-09-27 15:43:29 +0000942
943private:
944 isl_schedule *LastSchedule;
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000945};
Tobias Grosser522478d2016-06-23 22:17:27 +0000946} // namespace
Tobias Grosserfa57e9b2015-08-24 06:01:47 +0000947
948char IslScheduleOptimizer::ID = 0;
949
Tobias Grosser73600b82011-10-08 00:30:40 +0000950bool IslScheduleOptimizer::runOnScop(Scop &S) {
Johannes Doerfert6f7921f2015-02-14 12:02:24 +0000951
952 // Skip empty SCoPs but still allow code generation as it will delete the
953 // loops present but not needed.
954 if (S.getSize() == 0) {
955 S.markAsOptimized();
956 return false;
957 }
958
Hongbin Zheng2a798852016-03-03 08:15:33 +0000959 const Dependences &D =
960 getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement);
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000961
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000962 if (!D.hasValidDependences())
Tobias Grosser38c36ea2014-02-23 15:15:44 +0000963 return false;
964
Tobias Grosser28781422012-10-16 07:29:19 +0000965 isl_schedule_free(LastSchedule);
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000966 LastSchedule = nullptr;
Tobias Grosser28781422012-10-16 07:29:19 +0000967
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000968 // Build input data.
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000969 int ValidityKinds =
970 Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW;
Tobias Grosser1deda292012-02-14 14:02:48 +0000971 int ProximityKinds;
972
973 if (OptimizeDeps == "all")
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000974 ProximityKinds =
975 Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW;
Tobias Grosser1deda292012-02-14 14:02:48 +0000976 else if (OptimizeDeps == "raw")
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000977 ProximityKinds = Dependences::TYPE_RAW;
Tobias Grosser1deda292012-02-14 14:02:48 +0000978 else {
979 errs() << "Do not know how to optimize for '" << OptimizeDeps << "'"
Tobias Grosser4d96c8d2013-03-23 01:05:07 +0000980 << " Falling back to optimizing all dependences.\n";
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000981 ProximityKinds =
982 Dependences::TYPE_RAW | Dependences::TYPE_WAR | Dependences::TYPE_WAW;
Tobias Grosser1deda292012-02-14 14:02:48 +0000983 }
984
Tobias Grosser5f9a7622012-02-14 14:02:40 +0000985 isl_union_set *Domain = S.getDomains();
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000986
Tobias Grosser98610ee2012-02-13 23:31:39 +0000987 if (!Domain)
Tobias Grosser30aa24c2011-05-14 19:02:06 +0000988 return false;
989
Johannes Doerfert7e6424b2015-03-05 00:43:48 +0000990 isl_union_map *Validity = D.getDependences(ValidityKinds);
991 isl_union_map *Proximity = D.getDependences(ProximityKinds);
Tobias Grosser8a507022012-03-16 11:51:41 +0000992
Tobias Grossera26db472012-01-30 19:38:43 +0000993 // Simplify the dependences by removing the constraints introduced by the
994 // domains. This can speed up the scheduling time significantly, as large
995 // constant coefficients will be removed from the dependences. The
996 // introduction of some additional dependences reduces the possible
997 // transformations, but in most cases, such transformation do not seem to be
998 // interesting anyway. In some cases this option may stop the scheduler to
999 // find any schedule.
1000 if (SimplifyDeps == "yes") {
Tobias Grosser00383a72012-02-14 14:02:44 +00001001 Validity = isl_union_map_gist_domain(Validity, isl_union_set_copy(Domain));
1002 Validity = isl_union_map_gist_range(Validity, isl_union_set_copy(Domain));
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001003 Proximity =
1004 isl_union_map_gist_domain(Proximity, isl_union_set_copy(Domain));
Tobias Grosser00383a72012-02-14 14:02:44 +00001005 Proximity = isl_union_map_gist_range(Proximity, isl_union_set_copy(Domain));
Tobias Grossera26db472012-01-30 19:38:43 +00001006 } else if (SimplifyDeps != "no") {
1007 errs() << "warning: Option -polly-opt-simplify-deps should either be 'yes' "
1008 "or 'no'. Falling back to default: 'yes'\n";
1009 }
1010
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001011 DEBUG(dbgs() << "\n\nCompute schedule from: ");
Tobias Grosser01aea582014-10-22 23:16:28 +00001012 DEBUG(dbgs() << "Domain := " << stringFromIslObj(Domain) << ";\n");
1013 DEBUG(dbgs() << "Proximity := " << stringFromIslObj(Proximity) << ";\n");
1014 DEBUG(dbgs() << "Validity := " << stringFromIslObj(Validity) << ";\n");
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001015
Michael Krusec59f22c2015-06-18 16:45:40 +00001016 unsigned IslSerializeSCCs;
Tobias Grosserb3ad85b2012-01-30 19:38:50 +00001017
1018 if (FusionStrategy == "max") {
Michael Krusec59f22c2015-06-18 16:45:40 +00001019 IslSerializeSCCs = 0;
Tobias Grosserb3ad85b2012-01-30 19:38:50 +00001020 } else if (FusionStrategy == "min") {
Michael Krusec59f22c2015-06-18 16:45:40 +00001021 IslSerializeSCCs = 1;
Tobias Grosserb3ad85b2012-01-30 19:38:50 +00001022 } else {
1023 errs() << "warning: Unknown fusion strategy. Falling back to maximal "
1024 "fusion.\n";
Michael Krusec59f22c2015-06-18 16:45:40 +00001025 IslSerializeSCCs = 0;
Tobias Grosserb3ad85b2012-01-30 19:38:50 +00001026 }
1027
Tobias Grosser95e860c2012-01-30 19:38:54 +00001028 int IslMaximizeBands;
1029
Tobias Grossera4ea90b2012-01-30 22:43:56 +00001030 if (MaximizeBandDepth == "yes") {
Tobias Grosser95e860c2012-01-30 19:38:54 +00001031 IslMaximizeBands = 1;
Tobias Grossera4ea90b2012-01-30 22:43:56 +00001032 } else if (MaximizeBandDepth == "no") {
Tobias Grosser95e860c2012-01-30 19:38:54 +00001033 IslMaximizeBands = 0;
1034 } else {
1035 errs() << "warning: Option -polly-opt-maximize-bands should either be 'yes'"
1036 " or 'no'. Falling back to default: 'yes'\n";
1037 IslMaximizeBands = 1;
1038 }
1039
Michael Kruse315aa322016-05-02 11:35:27 +00001040 int IslOuterCoincidence;
1041
1042 if (OuterCoincidence == "yes") {
1043 IslOuterCoincidence = 1;
1044 } else if (OuterCoincidence == "no") {
1045 IslOuterCoincidence = 0;
1046 } else {
1047 errs() << "warning: Option -polly-opt-outer-coincidence should either be "
1048 "'yes' or 'no'. Falling back to default: 'no'\n";
1049 IslOuterCoincidence = 0;
1050 }
1051
Tobias Grosseraf149932016-06-30 20:42:56 +00001052 isl_ctx *Ctx = S.getIslCtx();
Tobias Grosser42152ff2012-01-30 19:38:47 +00001053
Tobias Grosseraf149932016-06-30 20:42:56 +00001054 isl_options_set_schedule_outer_coincidence(Ctx, IslOuterCoincidence);
1055 isl_options_set_schedule_serialize_sccs(Ctx, IslSerializeSCCs);
1056 isl_options_set_schedule_maximize_band_depth(Ctx, IslMaximizeBands);
1057 isl_options_set_schedule_max_constant_term(Ctx, MaxConstantTerm);
1058 isl_options_set_schedule_max_coefficient(Ctx, MaxCoefficient);
1059 isl_options_set_tile_scale_tile_loops(Ctx, 0);
1060
Tobias Grosser3898a042016-06-30 20:42:58 +00001061 auto OnErrorStatus = isl_options_get_on_error(Ctx);
Tobias Grosseraf149932016-06-30 20:42:56 +00001062 isl_options_set_on_error(Ctx, ISL_ON_ERROR_CONTINUE);
Tobias Grossera38c9242014-01-26 19:36:28 +00001063
1064 isl_schedule_constraints *ScheduleConstraints;
1065 ScheduleConstraints = isl_schedule_constraints_on_domain(Domain);
1066 ScheduleConstraints =
1067 isl_schedule_constraints_set_proximity(ScheduleConstraints, Proximity);
1068 ScheduleConstraints = isl_schedule_constraints_set_validity(
1069 ScheduleConstraints, isl_union_map_copy(Validity));
1070 ScheduleConstraints =
1071 isl_schedule_constraints_set_coincidence(ScheduleConstraints, Validity);
Tobias Grosser00383a72012-02-14 14:02:44 +00001072 isl_schedule *Schedule;
Tobias Grossera38c9242014-01-26 19:36:28 +00001073 Schedule = isl_schedule_constraints_compute_schedule(ScheduleConstraints);
Tobias Grosser3898a042016-06-30 20:42:58 +00001074 isl_options_set_on_error(Ctx, OnErrorStatus);
Tobias Grosser42152ff2012-01-30 19:38:47 +00001075
1076 // In cases the scheduler is not able to optimize the code, we just do not
1077 // touch the schedule.
Tobias Grosser98610ee2012-02-13 23:31:39 +00001078 if (!Schedule)
Tobias Grosser42152ff2012-01-30 19:38:47 +00001079 return false;
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001080
Tobias Grosser97d87452015-05-30 06:46:59 +00001081 DEBUG({
Tobias Grosseraf149932016-06-30 20:42:56 +00001082 auto *P = isl_printer_to_str(Ctx);
Tobias Grosser97d87452015-05-30 06:46:59 +00001083 P = isl_printer_set_yaml_style(P, ISL_YAML_STYLE_BLOCK);
1084 P = isl_printer_print_schedule(P, Schedule);
1085 dbgs() << "NewScheduleTree: \n" << isl_printer_get_str(P) << "\n";
1086 isl_printer_free(P);
1087 });
Tobias Grosser4d63b9d2012-02-20 08:41:21 +00001088
Roman Gareev42402c92016-06-22 09:52:37 +00001089 Function &F = S.getFunction();
1090 auto *TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
1091 isl_schedule *NewSchedule =
1092 ScheduleTreeOptimizer::optimizeSchedule(Schedule, TTI);
Tobias Grosser808cd692015-07-14 09:33:13 +00001093 isl_union_map *NewScheduleMap = isl_schedule_get_map(NewSchedule);
Johannes Doerfert7ceb0402015-02-11 17:25:09 +00001094
Tobias Grosserfa57e9b2015-08-24 06:01:47 +00001095 if (!ScheduleTreeOptimizer::isProfitableSchedule(S, NewScheduleMap)) {
Tobias Grosser808cd692015-07-14 09:33:13 +00001096 isl_union_map_free(NewScheduleMap);
1097 isl_schedule_free(NewSchedule);
Johannes Doerfert7ceb0402015-02-11 17:25:09 +00001098 return false;
1099 }
1100
Tobias Grosser808cd692015-07-14 09:33:13 +00001101 S.setScheduleTree(NewSchedule);
Johannes Doerfert7ceb0402015-02-11 17:25:09 +00001102 S.markAsOptimized();
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001103
Roman Gareev5f99f862016-08-21 11:20:39 +00001104 if (OptimizedScops)
1105 S.dump();
1106
Tobias Grosser808cd692015-07-14 09:33:13 +00001107 isl_union_map_free(NewScheduleMap);
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001108 return false;
1109}
1110
Johannes Doerfert3fe584d2015-03-01 18:40:25 +00001111void IslScheduleOptimizer::printScop(raw_ostream &OS, Scop &) const {
Tobias Grosser28781422012-10-16 07:29:19 +00001112 isl_printer *p;
1113 char *ScheduleStr;
1114
1115 OS << "Calculated schedule:\n";
1116
1117 if (!LastSchedule) {
1118 OS << "n/a\n";
1119 return;
1120 }
1121
1122 p = isl_printer_to_str(isl_schedule_get_ctx(LastSchedule));
1123 p = isl_printer_print_schedule(p, LastSchedule);
1124 ScheduleStr = isl_printer_get_str(p);
1125 isl_printer_free(p);
1126
1127 OS << ScheduleStr << "\n";
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001128}
1129
Tobias Grosser73600b82011-10-08 00:30:40 +00001130void IslScheduleOptimizer::getAnalysisUsage(AnalysisUsage &AU) const {
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001131 ScopPass::getAnalysisUsage(AU);
Johannes Doerfertf6557f92015-03-04 22:43:40 +00001132 AU.addRequired<DependenceInfo>();
Roman Gareev42402c92016-06-22 09:52:37 +00001133 AU.addRequired<TargetTransformInfoWrapperPass>();
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001134}
1135
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001136Pass *polly::createIslScheduleOptimizerPass() {
Tobias Grosser73600b82011-10-08 00:30:40 +00001137 return new IslScheduleOptimizer();
Tobias Grosser30aa24c2011-05-14 19:02:06 +00001138}
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001139
1140INITIALIZE_PASS_BEGIN(IslScheduleOptimizer, "polly-opt-isl",
1141 "Polly - Optimize schedule of SCoP", false, false);
Johannes Doerfertf6557f92015-03-04 22:43:40 +00001142INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
Johannes Doerfert99191c72016-05-31 09:41:04 +00001143INITIALIZE_PASS_DEPENDENCY(ScopInfoRegionPass);
Roman Gareev42402c92016-06-22 09:52:37 +00001144INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass);
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001145INITIALIZE_PASS_END(IslScheduleOptimizer, "polly-opt-isl",
1146 "Polly - Optimize schedule of SCoP", false, false)