blob: 50d5ac5f90c44ac1ee72f17dbb3d95b52b93e191 [file] [log] [blame]
Tobias Grosser75805372011-04-29 06:27:02 +00001//===--------- ScopInfo.cpp - Create Scops from LLVM IR ------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Create a polyhedral description for a static control flow region.
11//
12// The pass creates a polyhedral description of the Scops detected by the Scop
13// detection derived from their LLVM-IR code.
14//
15// This represantation is shared among several tools in the polyhedral
16// community, which are e.g. Cloog, Pluto, Loopo, Graphite.
17//
18//===----------------------------------------------------------------------===//
19
Sebastian Pop27c10c62013-03-22 22:07:43 +000020#include "polly/CodeGen/BlockGenerators.h"
Tobias Grosser75805372011-04-29 06:27:02 +000021#include "polly/LinkAllPasses.h"
Sebastian Pop27c10c62013-03-22 22:07:43 +000022#include "polly/ScopInfo.h"
Johannes Doerfert0ee1f212014-06-17 17:31:36 +000023#include "polly/Options.h"
Tobias Grosser75805372011-04-29 06:27:02 +000024#include "polly/Support/GICHelper.h"
Tobias Grosser60b54f12011-11-08 15:41:28 +000025#include "polly/Support/SCEVValidator.h"
Tobias Grosser83628182013-05-07 08:11:54 +000026#include "polly/Support/ScopHelper.h"
Sebastian Pop27c10c62013-03-22 22:07:43 +000027#include "polly/TempScopInfo.h"
Tobias Grosser75805372011-04-29 06:27:02 +000028#include "llvm/ADT/SetVector.h"
Tobias Grosser83628182013-05-07 08:11:54 +000029#include "llvm/ADT/Statistic.h"
Hongbin Zheng86a37742012-04-25 08:01:38 +000030#include "llvm/ADT/StringExtras.h"
Tobias Grosser83628182013-05-07 08:11:54 +000031#include "llvm/Analysis/LoopInfo.h"
32#include "llvm/Analysis/RegionIterator.h"
33#include "llvm/Analysis/ScalarEvolutionExpressions.h"
Tobias Grosser75805372011-04-29 06:27:02 +000034#include "llvm/Support/Debug.h"
35
36#include "isl/constraint.h"
37#include "isl/set.h"
38#include "isl/map.h"
Tobias Grosser37eb4222014-02-20 21:43:54 +000039#include "isl/union_map.h"
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000040#include "isl/aff.h"
41#include "isl/printer.h"
Tobias Grosserf5338802011-10-06 00:03:35 +000042#include "isl/local_space.h"
Tobias Grosser4a8e3562011-12-07 07:42:51 +000043#include "isl/options.h"
Tobias Grosseredab1352013-06-21 06:41:31 +000044#include "isl/val.h"
Chandler Carruth95fef942014-04-22 03:30:19 +000045
Tobias Grosser75805372011-04-29 06:27:02 +000046#include <sstream>
47#include <string>
48#include <vector>
49
50using namespace llvm;
51using namespace polly;
52
Chandler Carruth95fef942014-04-22 03:30:19 +000053#define DEBUG_TYPE "polly-scops"
54
Tobias Grosser74394f02013-01-14 22:40:23 +000055STATISTIC(ScopFound, "Number of valid Scops");
56STATISTIC(RichScopFound, "Number of Scops containing a loop");
Tobias Grosser75805372011-04-29 06:27:02 +000057
Johannes Doerfert0ee1f212014-06-17 17:31:36 +000058// Multiplicative reductions can be disabled seperately as these kind of
59// operations can overflow easily. Additive reductions and bit operations
60// are in contrast pretty stable.
Tobias Grosser483a90d2014-07-09 10:50:10 +000061static cl::opt<bool> DisableMultiplicativeReductions(
62 "polly-disable-multiplicative-reductions",
63 cl::desc("Disable multiplicative reductions"), cl::Hidden, cl::ZeroOrMore,
64 cl::init(false), cl::cat(PollyCategory));
Johannes Doerfert0ee1f212014-06-17 17:31:36 +000065
Johannes Doerfert5130c842014-08-15 01:14:11 +000066static int extractAffine(__isl_take isl_set *Set, __isl_take isl_aff *Aff,
67 void *User) {
68 *((isl_aff **)(User)) = Aff;
69 isl_set_free(Set);
70 return 0;
71}
72
Tobias Grosser0695ee42013-09-17 03:30:31 +000073/// Translate a 'const SCEV *' expression in an isl_pw_aff.
Tobias Grosserabfbe632013-02-05 12:09:06 +000074struct SCEVAffinator : public SCEVVisitor<SCEVAffinator, isl_pw_aff *> {
Tobias Grosser0695ee42013-09-17 03:30:31 +000075public:
Tobias Grosser0695ee42013-09-17 03:30:31 +000076 /// @brief Translate a 'const SCEV *' to an isl_pw_aff.
77 ///
78 /// @param Stmt The location at which the scalar evolution expression
79 /// is evaluated.
80 /// @param Expr The expression that is translated.
81 static __isl_give isl_pw_aff *getPwAff(ScopStmt *Stmt, const SCEV *Expr);
82
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000083private:
Tobias Grosser3cc99742012-06-06 16:33:15 +000084 isl_ctx *Ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +000085 int NbLoopSpaces;
Tobias Grosser3cc99742012-06-06 16:33:15 +000086 const Scop *S;
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000087
Tobias Grosser0695ee42013-09-17 03:30:31 +000088 SCEVAffinator(const ScopStmt *Stmt);
89 int getLoopDepth(const Loop *L);
Tobias Grosser60b54f12011-11-08 15:41:28 +000090
Tobias Grosser0695ee42013-09-17 03:30:31 +000091 __isl_give isl_pw_aff *visit(const SCEV *Expr);
92 __isl_give isl_pw_aff *visitConstant(const SCEVConstant *Expr);
93 __isl_give isl_pw_aff *visitTruncateExpr(const SCEVTruncateExpr *Expr);
94 __isl_give isl_pw_aff *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr);
95 __isl_give isl_pw_aff *visitSignExtendExpr(const SCEVSignExtendExpr *Expr);
96 __isl_give isl_pw_aff *visitAddExpr(const SCEVAddExpr *Expr);
97 __isl_give isl_pw_aff *visitMulExpr(const SCEVMulExpr *Expr);
98 __isl_give isl_pw_aff *visitUDivExpr(const SCEVUDivExpr *Expr);
99 __isl_give isl_pw_aff *visitAddRecExpr(const SCEVAddRecExpr *Expr);
100 __isl_give isl_pw_aff *visitSMaxExpr(const SCEVSMaxExpr *Expr);
101 __isl_give isl_pw_aff *visitUMaxExpr(const SCEVUMaxExpr *Expr);
102 __isl_give isl_pw_aff *visitUnknown(const SCEVUnknown *Expr);
Tobias Grosser60b54f12011-11-08 15:41:28 +0000103
Tobias Grosser0695ee42013-09-17 03:30:31 +0000104 friend struct SCEVVisitor<SCEVAffinator, isl_pw_aff *>;
105};
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000106
Tobias Grosser0695ee42013-09-17 03:30:31 +0000107SCEVAffinator::SCEVAffinator(const ScopStmt *Stmt)
108 : Ctx(Stmt->getIslCtx()), NbLoopSpaces(Stmt->getNumIterators()),
109 S(Stmt->getParent()) {}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000110
Tobias Grosser0695ee42013-09-17 03:30:31 +0000111__isl_give isl_pw_aff *SCEVAffinator::getPwAff(ScopStmt *Stmt,
112 const SCEV *Scev) {
113 Scop *S = Stmt->getParent();
114 const Region *Reg = &S->getRegion();
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000115
Tobias Grosser0695ee42013-09-17 03:30:31 +0000116 S->addParams(getParamsInAffineExpr(Reg, Scev, *S->getSE()));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000117
Tobias Grosser0695ee42013-09-17 03:30:31 +0000118 SCEVAffinator Affinator(Stmt);
119 return Affinator.visit(Scev);
120}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000121
Tobias Grosser0695ee42013-09-17 03:30:31 +0000122__isl_give isl_pw_aff *SCEVAffinator::visit(const SCEV *Expr) {
123 // In case the scev is a valid parameter, we do not further analyze this
124 // expression, but create a new parameter in the isl_pw_aff. This allows us
125 // to treat subexpressions that we cannot translate into an piecewise affine
126 // expression, as constant parameters of the piecewise affine expression.
127 if (isl_id *Id = S->getIdForParam(Expr)) {
128 isl_space *Space = isl_space_set_alloc(Ctx, 1, NbLoopSpaces);
129 Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000130
Tobias Grosser0695ee42013-09-17 03:30:31 +0000131 isl_set *Domain = isl_set_universe(isl_space_copy(Space));
132 isl_aff *Affine = isl_aff_zero_on_domain(isl_local_space_from_space(Space));
133 Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000134
135 return isl_pw_aff_alloc(Domain, Affine);
136 }
137
Tobias Grosser0695ee42013-09-17 03:30:31 +0000138 return SCEVVisitor<SCEVAffinator, isl_pw_aff *>::visit(Expr);
139}
140
Tobias Grosser0d170132013-10-03 13:09:19 +0000141__isl_give isl_pw_aff *SCEVAffinator::visitConstant(const SCEVConstant *Expr) {
Tobias Grosser0695ee42013-09-17 03:30:31 +0000142 ConstantInt *Value = Expr->getValue();
143 isl_val *v;
144
145 // LLVM does not define if an integer value is interpreted as a signed or
146 // unsigned value. Hence, without further information, it is unknown how
147 // this value needs to be converted to GMP. At the moment, we only support
148 // signed operations. So we just interpret it as signed. Later, there are
149 // two options:
150 //
151 // 1. We always interpret any value as signed and convert the values on
152 // demand.
153 // 2. We pass down the signedness of the calculation and use it to interpret
154 // this constant correctly.
155 v = isl_valFromAPInt(Ctx, Value->getValue(), /* isSigned */ true);
156
157 isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
158 isl_local_space *ls = isl_local_space_from_space(isl_space_copy(Space));
159 isl_aff *Affine = isl_aff_zero_on_domain(ls);
160 isl_set *Domain = isl_set_universe(Space);
161
162 Affine = isl_aff_add_constant_val(Affine, v);
163
164 return isl_pw_aff_alloc(Domain, Affine);
165}
166
167__isl_give isl_pw_aff *
168SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
169 llvm_unreachable("SCEVTruncateExpr not yet supported");
170}
171
172__isl_give isl_pw_aff *
173SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
Johannes Doerfert5130c842014-08-15 01:14:11 +0000174 ScalarEvolution &SE = *S->getSE();
175
176 const SCEV *OpS = Expr->getOperand();
177 unsigned ModCst = 1 << OpS->getType()->getScalarSizeInBits();
178
179 // Pattern matching rules to capture some bit and modulo computations:
180 //
181 // EXP % 2^C <==>
182 // [A] (i + c) & (2^C - 1) ==> zext iC {c,+,1}<%for_i> to IXX
183 // [B] (p + q) & (2^C - 1) ==> zext iC (trunc iXX %p_add_q to iC) to iXX
184 // [C] (i + p) & (2^C - 1) ==> zext iC {p & (2^C - 1),+,1}<%for_i> to iXX
185 // ==> zext iC {trunc iXX %p to iC,+,1}<%for_i> to
186
187 // Check for [A] and [C].
188 if (auto *OpAR = dyn_cast<SCEVAddRecExpr>(OpS)) {
189 assert(OpAR->getStepRecurrence(SE)->isOne());
190
191 const SCEV *OpARStart = OpAR->getStart();
192 const SCEV *OpARStep = OpAR->getStepRecurrence(SE);
193
194 // Special case for [C].
195 if (auto *OpARStartTR = dyn_cast<SCEVTruncateExpr>(OpARStart)) {
196 OpARStart = OpARStartTR->getOperand();
197 OpARStep = SE.getConstant(OpARStart->getType(), 1);
198 }
199
200 const SCEV *NewAR = SE.getAddRecExpr(OpARStart, OpARStep, OpAR->getLoop(),
201 OpAR->getNoWrapFlags());
202 return isl_pw_aff_mod_val(visit(NewAR), isl_val_int_from_si(Ctx, ModCst));
203 }
204
205 // Check for [B].
206 if (auto *OpTR = dyn_cast<SCEVTruncateExpr>(OpS))
207 return isl_pw_aff_mod_val(visit(OpTR->getOperand()),
208 isl_val_int_from_si(Ctx, ModCst));
209
Tobias Grosser0695ee42013-09-17 03:30:31 +0000210 llvm_unreachable("SCEVZeroExtendExpr not yet supported");
211}
212
213__isl_give isl_pw_aff *
214SCEVAffinator::visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
215 // Assuming the value is signed, a sign extension is basically a noop.
216 // TODO: Reconsider this as soon as we support unsigned values.
217 return visit(Expr->getOperand());
218}
219
220__isl_give isl_pw_aff *SCEVAffinator::visitAddExpr(const SCEVAddExpr *Expr) {
221 isl_pw_aff *Sum = visit(Expr->getOperand(0));
222
223 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
224 isl_pw_aff *NextSummand = visit(Expr->getOperand(i));
225 Sum = isl_pw_aff_add(Sum, NextSummand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000226 }
227
Tobias Grosser0695ee42013-09-17 03:30:31 +0000228 // TODO: Check for NSW and NUW.
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000229
Tobias Grosser0695ee42013-09-17 03:30:31 +0000230 return Sum;
231}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000232
Tobias Grosser0695ee42013-09-17 03:30:31 +0000233__isl_give isl_pw_aff *SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) {
234 isl_pw_aff *Product = visit(Expr->getOperand(0));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000235
Tobias Grosser0695ee42013-09-17 03:30:31 +0000236 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
237 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
238
239 if (!isl_pw_aff_is_cst(Product) && !isl_pw_aff_is_cst(NextOperand)) {
240 isl_pw_aff_free(Product);
241 isl_pw_aff_free(NextOperand);
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000242 return nullptr;
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000243 }
244
Tobias Grosser0695ee42013-09-17 03:30:31 +0000245 Product = isl_pw_aff_mul(Product, NextOperand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000246 }
247
Tobias Grosser0695ee42013-09-17 03:30:31 +0000248 // TODO: Check for NSW and NUW.
249 return Product;
250}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000251
Tobias Grosser0695ee42013-09-17 03:30:31 +0000252__isl_give isl_pw_aff *SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
253 llvm_unreachable("SCEVUDivExpr not yet supported");
254}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000255
Tobias Grosser0695ee42013-09-17 03:30:31 +0000256__isl_give isl_pw_aff *
257SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) {
258 assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000259
Tobias Grosser0695ee42013-09-17 03:30:31 +0000260 // Directly generate isl_pw_aff for Expr if 'start' is zero.
261 if (Expr->getStart()->isZero()) {
262 assert(S->getRegion().contains(Expr->getLoop()) &&
263 "Scop does not contain the loop referenced in this AddRec");
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000264
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000265 isl_pw_aff *Start = visit(Expr->getStart());
Tobias Grosser0695ee42013-09-17 03:30:31 +0000266 isl_pw_aff *Step = visit(Expr->getOperand(1));
267 isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
268 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000269
Tobias Grosser0695ee42013-09-17 03:30:31 +0000270 int loopDimension = getLoopDepth(Expr->getLoop());
271
272 isl_aff *LAff = isl_aff_set_coefficient_si(
273 isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1);
274 isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff);
275
276 // TODO: Do we need to check for NSW and NUW?
277 return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000278 }
279
Tobias Grosser0695ee42013-09-17 03:30:31 +0000280 // Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}'
281 // if 'start' is not zero.
282 ScalarEvolution &SE = *S->getSE();
283 const SCEV *ZeroStartExpr = SE.getAddRecExpr(
284 SE.getConstant(Expr->getStart()->getType(), 0),
285 Expr->getStepRecurrence(SE), Expr->getLoop(), SCEV::FlagAnyWrap);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000286
Tobias Grosser0695ee42013-09-17 03:30:31 +0000287 isl_pw_aff *ZeroStartResult = visit(ZeroStartExpr);
288 isl_pw_aff *Start = visit(Expr->getStart());
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000289
Tobias Grosser0695ee42013-09-17 03:30:31 +0000290 return isl_pw_aff_add(ZeroStartResult, Start);
291}
292
293__isl_give isl_pw_aff *SCEVAffinator::visitSMaxExpr(const SCEVSMaxExpr *Expr) {
294 isl_pw_aff *Max = visit(Expr->getOperand(0));
295
296 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
297 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
298 Max = isl_pw_aff_max(Max, NextOperand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000299 }
300
Tobias Grosser0695ee42013-09-17 03:30:31 +0000301 return Max;
302}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000303
Tobias Grosser0695ee42013-09-17 03:30:31 +0000304__isl_give isl_pw_aff *SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) {
305 llvm_unreachable("SCEVUMaxExpr not yet supported");
306}
307
308__isl_give isl_pw_aff *SCEVAffinator::visitUnknown(const SCEVUnknown *Expr) {
Johannes Doerfert5130c842014-08-15 01:14:11 +0000309 Value *Unknown = Expr->getValue();
310 if (auto *BO = dyn_cast<BinaryOperator>(Unknown)) {
311 isl_pw_aff *RHS, *LHS;
312 isl_aff *RHSAff;
313 isl_val *RHSVal;
314
315 assert(BO->getOpcode() == Instruction::SRem &&
316 "Binary operator unknowns are always signed modulo expressions");
317 LHS = visit(S->getSE()->getSCEV(BO->getOperand(0)));
318 RHS = visit(S->getSE()->getSCEV(BO->getOperand(1)));
319 assert(isl_pw_aff_is_cst(RHS) &&
320 "Modulo expressions are only valid for a constant right hand side");
321 assert(isl_pw_aff_n_piece(RHS) == 1 &&
322 "Modulo expressions are only valid for a non split right hand side");
323 isl_pw_aff_foreach_piece(RHS, extractAffine, &RHSAff);
324 assert(isl_aff_is_cst(RHSAff) &&
325 "Modulo expressions are only valid for a constant right hand side");
326 RHSVal = isl_aff_get_constant_val(RHSAff);
327
328 isl_pw_aff_free(RHS);
329 isl_aff_free(RHSAff);
330
331 return isl_pw_aff_mod_val(LHS, RHSVal);
332 }
333
334 llvm_unreachable("Unknowns are always parameters or modulo expressions");
Tobias Grosser0695ee42013-09-17 03:30:31 +0000335}
336
337int SCEVAffinator::getLoopDepth(const Loop *L) {
338 Loop *outerLoop = S->getRegion().outermostLoopInRegion(const_cast<Loop *>(L));
339 assert(outerLoop && "Scop does not contain this loop");
340 return L->getLoopDepth() - outerLoop->getLoopDepth();
341}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000342
Johannes Doerfert32868bf2014-08-01 08:13:25 +0000343const std::string
344MemoryAccess::getReductionOperatorStr(MemoryAccess::ReductionType RT) {
345 switch (RT) {
346 case MemoryAccess::RT_NONE:
347 llvm_unreachable("Requested a reduction operator string for a memory "
348 "access which isn't a reduction");
349 case MemoryAccess::RT_ADD:
350 return "+";
351 case MemoryAccess::RT_MUL:
352 return "*";
353 case MemoryAccess::RT_BOR:
354 return "|";
355 case MemoryAccess::RT_BXOR:
356 return "^";
357 case MemoryAccess::RT_BAND:
358 return "&";
359 }
360 llvm_unreachable("Unknown reduction type");
361 return "";
362}
363
Johannes Doerfertf6183392014-07-01 20:52:51 +0000364/// @brief Return the reduction type for a given binary operator
365static MemoryAccess::ReductionType getReductionType(const BinaryOperator *BinOp,
366 const Instruction *Load) {
367 if (!BinOp)
368 return MemoryAccess::RT_NONE;
369 switch (BinOp->getOpcode()) {
370 case Instruction::FAdd:
371 if (!BinOp->hasUnsafeAlgebra())
372 return MemoryAccess::RT_NONE;
373 // Fall through
374 case Instruction::Add:
375 return MemoryAccess::RT_ADD;
376 case Instruction::Or:
377 return MemoryAccess::RT_BOR;
378 case Instruction::Xor:
379 return MemoryAccess::RT_BXOR;
380 case Instruction::And:
381 return MemoryAccess::RT_BAND;
382 case Instruction::FMul:
383 if (!BinOp->hasUnsafeAlgebra())
384 return MemoryAccess::RT_NONE;
385 // Fall through
386 case Instruction::Mul:
387 if (DisableMultiplicativeReductions)
388 return MemoryAccess::RT_NONE;
389 return MemoryAccess::RT_MUL;
390 default:
391 return MemoryAccess::RT_NONE;
392 }
393}
Tobias Grosser75805372011-04-29 06:27:02 +0000394//===----------------------------------------------------------------------===//
395
396MemoryAccess::~MemoryAccess() {
Tobias Grosser54a86e62011-08-18 06:31:46 +0000397 isl_map_free(AccessRelation);
Raghesh Aloor129e8672011-08-15 02:33:39 +0000398 isl_map_free(newAccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000399}
400
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000401isl_id *MemoryAccess::getArrayId() const {
402 return isl_map_get_tuple_id(AccessRelation, isl_dim_out);
403}
404
Tobias Grosser5d453812011-10-06 00:04:11 +0000405isl_map *MemoryAccess::getAccessRelation() const {
406 return isl_map_copy(AccessRelation);
407}
408
409std::string MemoryAccess::getAccessRelationStr() const {
410 return stringFromIslObj(AccessRelation);
411}
412
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000413__isl_give isl_space *MemoryAccess::getAccessRelationSpace() const {
414 return isl_map_get_space(AccessRelation);
415}
416
Tobias Grosser5d453812011-10-06 00:04:11 +0000417isl_map *MemoryAccess::getNewAccessRelation() const {
418 return isl_map_copy(newAccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000419}
420
421isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
Tobias Grosser084d8f72012-05-29 09:29:44 +0000422 isl_space *Space = isl_space_set_alloc(Statement->getIslCtx(), 0, 1);
Tobias Grossered295662012-09-11 13:50:21 +0000423 Space = isl_space_align_params(Space, Statement->getDomainSpace());
Tobias Grosser75805372011-04-29 06:27:02 +0000424
Tobias Grosser084d8f72012-05-29 09:29:44 +0000425 return isl_basic_map_from_domain_and_range(
Tobias Grosserabfbe632013-02-05 12:09:06 +0000426 isl_basic_set_universe(Statement->getDomainSpace()),
427 isl_basic_set_universe(Space));
Tobias Grosser75805372011-04-29 06:27:02 +0000428}
429
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000430// Formalize no out-of-bound access assumption
431//
432// When delinearizing array accesses we optimistically assume that the
433// delinearized accesses do not access out of bound locations (the subscript
434// expression of each array evaluates for each statement instance that is
435// executed to a value that is larger than zero and strictly smaller than the
436// size of the corresponding dimension). The only exception is the outermost
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000437// dimension for which we do not need to assume any upper bound. At this point
438// we formalize this assumption to ensure that at code generation time the
439// relevant run-time checks can be generated.
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000440//
441// To find the set of constraints necessary to avoid out of bound accesses, we
442// first build the set of data locations that are not within array bounds. We
443// then apply the reverse access relation to obtain the set of iterations that
444// may contain invalid accesses and reduce this set of iterations to the ones
445// that are actually executed by intersecting them with the domain of the
446// statement. If we now project out all loop dimensions, we obtain a set of
447// parameters that may cause statement instances to be executed that may
448// possibly yield out of bound memory accesses. The complement of these
449// constraints is the set of constraints that needs to be assumed to ensure such
450// statement instances are never executed.
451void MemoryAccess::assumeNoOutOfBound(const IRAccess &Access) {
452 isl_space *Space = isl_space_range(getAccessRelationSpace());
453 isl_set *Outside = isl_set_empty(isl_space_copy(Space));
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000454 for (int i = 1, Size = Access.Subscripts.size(); i < Size; ++i) {
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000455 isl_local_space *LS = isl_local_space_from_space(isl_space_copy(Space));
456 isl_pw_aff *Var =
457 isl_pw_aff_var_on_domain(isl_local_space_copy(LS), isl_dim_set, i);
458 isl_pw_aff *Zero = isl_pw_aff_zero_on_domain(LS);
459
460 isl_set *DimOutside;
461
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000462 DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
463 isl_pw_aff *SizeE = SCEVAffinator::getPwAff(Statement, Access.Sizes[i - 1]);
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000464
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000465 SizeE = isl_pw_aff_drop_dims(SizeE, isl_dim_in, 0,
466 Statement->getNumIterators());
467 SizeE = isl_pw_aff_add_dims(SizeE, isl_dim_in,
468 isl_space_dim(Space, isl_dim_set));
469 SizeE = isl_pw_aff_set_tuple_id(SizeE, isl_dim_in,
470 isl_space_get_tuple_id(Space, isl_dim_set));
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000471
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000472 DimOutside = isl_set_union(DimOutside, isl_pw_aff_le_set(SizeE, Var));
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000473
474 Outside = isl_set_union(Outside, DimOutside);
475 }
476
477 Outside = isl_set_apply(Outside, isl_map_reverse(getAccessRelation()));
478 Outside = isl_set_intersect(Outside, Statement->getDomain());
479 Outside = isl_set_params(Outside);
480 Outside = isl_set_complement(Outside);
481 Statement->getParent()->addAssumption(Outside);
482 isl_space_free(Space);
483}
484
Johannes Doerfert13c8cf22014-08-10 08:09:38 +0000485MemoryAccess::MemoryAccess(const IRAccess &Access, Instruction *AccInst,
Tobias Grosserabfbe632013-02-05 12:09:06 +0000486 ScopStmt *Statement)
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000487 : Statement(Statement), Inst(AccInst), newAccessRelation(nullptr) {
Tobias Grosser75805372011-04-29 06:27:02 +0000488
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000489 isl_ctx *Ctx = Statement->getIslCtx();
Tobias Grosser9759f852011-11-10 12:44:55 +0000490 BaseAddr = Access.getBase();
Johannes Doerfert79fc23f2014-07-24 23:48:02 +0000491 BaseName = getIslCompatibleName("MemRef_", getBaseAddr(), "");
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000492 isl_id *BaseAddrId = isl_id_alloc(Ctx, getBaseName().c_str(), nullptr);
Tobias Grosser5683df42011-11-09 22:34:34 +0000493
Tobias Grossera1879642011-12-20 10:43:14 +0000494 if (!Access.isAffine()) {
Tobias Grosser4f967492013-06-23 05:21:18 +0000495 // We overapproximate non-affine accesses with a possible access to the
496 // whole array. For read accesses it does not make a difference, if an
497 // access must or may happen. However, for write accesses it is important to
498 // differentiate between writes that must happen and writes that may happen.
Tobias Grosser04d6ae62013-06-23 06:04:54 +0000499 AccessRelation = isl_map_from_basic_map(createBasicAccessMap(Statement));
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000500 AccessRelation =
501 isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId);
Tobias Grosserb58f6a42013-07-13 20:41:24 +0000502 Type = Access.isRead() ? READ : MAY_WRITE;
Tobias Grossera1879642011-12-20 10:43:14 +0000503 return;
504 }
505
Tobias Grosserb58f6a42013-07-13 20:41:24 +0000506 Type = Access.isRead() ? READ : MUST_WRITE;
Tobias Grosser4f967492013-06-23 05:21:18 +0000507
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000508 isl_space *Space = isl_space_alloc(Ctx, 0, Statement->getNumIterators(), 0);
Tobias Grosser79baa212014-04-10 08:38:02 +0000509 AccessRelation = isl_map_universe(Space);
Tobias Grossera1879642011-12-20 10:43:14 +0000510
Tobias Grosser79baa212014-04-10 08:38:02 +0000511 for (int i = 0, Size = Access.Subscripts.size(); i < Size; ++i) {
Sebastian Pop18016682014-04-08 21:20:44 +0000512 isl_pw_aff *Affine =
513 SCEVAffinator::getPwAff(Statement, Access.Subscripts[i]);
Tobias Grosser75805372011-04-29 06:27:02 +0000514
Sebastian Pop422e33f2014-06-03 18:16:31 +0000515 if (Size == 1) {
516 // For the non delinearized arrays, divide the access function of the last
517 // subscript by the size of the elements in the array.
Sebastian Pop18016682014-04-08 21:20:44 +0000518 //
519 // A stride one array access in C expressed as A[i] is expressed in
520 // LLVM-IR as something like A[i * elementsize]. This hides the fact that
521 // two subsequent values of 'i' index two values that are stored next to
522 // each other in memory. By this division we make this characteristic
523 // obvious again.
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000524 isl_val *v = isl_val_int_from_si(Ctx, Access.getElemSizeInBytes());
Sebastian Pop18016682014-04-08 21:20:44 +0000525 Affine = isl_pw_aff_scale_down_val(Affine, v);
526 }
527
528 isl_map *SubscriptMap = isl_map_from_pw_aff(Affine);
529
Tobias Grosser79baa212014-04-10 08:38:02 +0000530 AccessRelation = isl_map_flat_range_product(AccessRelation, SubscriptMap);
Sebastian Pop18016682014-04-08 21:20:44 +0000531 }
532
Tobias Grosser79baa212014-04-10 08:38:02 +0000533 Space = Statement->getDomainSpace();
Tobias Grosserabfbe632013-02-05 12:09:06 +0000534 AccessRelation = isl_map_set_tuple_id(
535 AccessRelation, isl_dim_in, isl_space_get_tuple_id(Space, isl_dim_set));
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000536 AccessRelation =
537 isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId);
538
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000539 assumeNoOutOfBound(Access);
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000540 isl_space_free(Space);
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000541}
Tobias Grosser30b8a092011-08-18 07:51:37 +0000542
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000543void MemoryAccess::realignParams() {
Tobias Grosser6defb5b2014-04-10 08:37:44 +0000544 isl_space *ParamSpace = Statement->getParent()->getParamSpace();
Tobias Grosser37487052011-10-06 00:03:42 +0000545 AccessRelation = isl_map_align_params(AccessRelation, ParamSpace);
Tobias Grosser75805372011-04-29 06:27:02 +0000546}
547
Johannes Doerfert32868bf2014-08-01 08:13:25 +0000548const std::string MemoryAccess::getReductionOperatorStr() const {
549 return MemoryAccess::getReductionOperatorStr(getReductionType());
550}
551
Johannes Doerfertf6183392014-07-01 20:52:51 +0000552raw_ostream &polly::operator<<(raw_ostream &OS,
553 MemoryAccess::ReductionType RT) {
Johannes Doerfert32868bf2014-08-01 08:13:25 +0000554 if (RT == MemoryAccess::RT_NONE)
Johannes Doerfertf6183392014-07-01 20:52:51 +0000555 OS << "NONE";
Johannes Doerfert32868bf2014-08-01 08:13:25 +0000556 else
557 OS << MemoryAccess::getReductionOperatorStr(RT);
Johannes Doerfertf6183392014-07-01 20:52:51 +0000558 return OS;
559}
560
Tobias Grosser75805372011-04-29 06:27:02 +0000561void MemoryAccess::print(raw_ostream &OS) const {
Tobias Grosser4f967492013-06-23 05:21:18 +0000562 switch (Type) {
Tobias Grosserb58f6a42013-07-13 20:41:24 +0000563 case READ:
Johannes Doerfert6780bc32014-06-26 18:47:03 +0000564 OS.indent(12) << "ReadAccess :=\t";
Tobias Grosser4f967492013-06-23 05:21:18 +0000565 break;
Tobias Grosserb58f6a42013-07-13 20:41:24 +0000566 case MUST_WRITE:
Johannes Doerfert6780bc32014-06-26 18:47:03 +0000567 OS.indent(12) << "MustWriteAccess :=\t";
Tobias Grosser4f967492013-06-23 05:21:18 +0000568 break;
Tobias Grosserb58f6a42013-07-13 20:41:24 +0000569 case MAY_WRITE:
Johannes Doerfert6780bc32014-06-26 18:47:03 +0000570 OS.indent(12) << "MayWriteAccess :=\t";
Tobias Grosser4f967492013-06-23 05:21:18 +0000571 break;
572 }
Johannes Doerfertf6183392014-07-01 20:52:51 +0000573 OS << "[Reduction Type: " << getReductionType() << "]\n";
Tobias Grosser5d453812011-10-06 00:04:11 +0000574 OS.indent(16) << getAccessRelationStr() << ";\n";
Tobias Grosser75805372011-04-29 06:27:02 +0000575}
576
Tobias Grosser74394f02013-01-14 22:40:23 +0000577void MemoryAccess::dump() const { print(errs()); }
Tobias Grosser75805372011-04-29 06:27:02 +0000578
579// Create a map in the size of the provided set domain, that maps from the
580// one element of the provided set domain to another element of the provided
581// set domain.
582// The mapping is limited to all points that are equal in all but the last
583// dimension and for which the last dimension of the input is strict smaller
584// than the last dimension of the output.
585//
586// getEqualAndLarger(set[i0, i1, ..., iX]):
587//
588// set[i0, i1, ..., iX] -> set[o0, o1, ..., oX]
589// : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1), iX < oX
590//
Tobias Grosserf5338802011-10-06 00:03:35 +0000591static isl_map *getEqualAndLarger(isl_space *setDomain) {
Tobias Grosserc327932c2012-02-01 14:23:36 +0000592 isl_space *Space = isl_space_map_from_set(setDomain);
593 isl_map *Map = isl_map_universe(isl_space_copy(Space));
594 isl_local_space *MapLocalSpace = isl_local_space_from_space(Space);
Sebastian Pop40408762013-10-04 17:14:53 +0000595 unsigned lastDimension = isl_map_dim(Map, isl_dim_in) - 1;
Tobias Grosser75805372011-04-29 06:27:02 +0000596
597 // Set all but the last dimension to be equal for the input and output
598 //
599 // input[i0, i1, ..., iX] -> output[o0, o1, ..., oX]
600 // : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1)
Sebastian Pop40408762013-10-04 17:14:53 +0000601 for (unsigned i = 0; i < lastDimension; ++i)
Tobias Grosserc327932c2012-02-01 14:23:36 +0000602 Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i);
Tobias Grosser75805372011-04-29 06:27:02 +0000603
604 // Set the last dimension of the input to be strict smaller than the
605 // last dimension of the output.
606 //
607 // input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX
608 //
Tobias Grosseredab1352013-06-21 06:41:31 +0000609 isl_val *v;
610 isl_ctx *Ctx = isl_map_get_ctx(Map);
Tobias Grosserf5338802011-10-06 00:03:35 +0000611 isl_constraint *c = isl_inequality_alloc(isl_local_space_copy(MapLocalSpace));
Tobias Grosseredab1352013-06-21 06:41:31 +0000612 v = isl_val_int_from_si(Ctx, -1);
613 c = isl_constraint_set_coefficient_val(c, isl_dim_in, lastDimension, v);
614 v = isl_val_int_from_si(Ctx, 1);
615 c = isl_constraint_set_coefficient_val(c, isl_dim_out, lastDimension, v);
616 v = isl_val_int_from_si(Ctx, -1);
617 c = isl_constraint_set_constant_val(c, v);
Tobias Grosser75805372011-04-29 06:27:02 +0000618
Tobias Grosserc327932c2012-02-01 14:23:36 +0000619 Map = isl_map_add_constraint(Map, c);
Tobias Grosser75805372011-04-29 06:27:02 +0000620
Tobias Grosser23b36662011-10-17 08:32:36 +0000621 isl_local_space_free(MapLocalSpace);
Tobias Grosserc327932c2012-02-01 14:23:36 +0000622 return Map;
Tobias Grosser75805372011-04-29 06:27:02 +0000623}
624
Sebastian Popa00a0292012-12-18 07:46:06 +0000625isl_set *MemoryAccess::getStride(__isl_take const isl_map *Schedule) const {
Tobias Grosserabfbe632013-02-05 12:09:06 +0000626 isl_map *S = const_cast<isl_map *>(Schedule);
Sebastian Popa00a0292012-12-18 07:46:06 +0000627 isl_map *AccessRelation = getAccessRelation();
628 isl_space *Space = isl_space_range(isl_map_get_space(S));
629 isl_map *NextScatt = getEqualAndLarger(Space);
Tobias Grosser75805372011-04-29 06:27:02 +0000630
Sebastian Popa00a0292012-12-18 07:46:06 +0000631 S = isl_map_reverse(S);
632 NextScatt = isl_map_lexmin(NextScatt);
Tobias Grosser75805372011-04-29 06:27:02 +0000633
Sebastian Popa00a0292012-12-18 07:46:06 +0000634 NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(S));
635 NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(AccessRelation));
636 NextScatt = isl_map_apply_domain(NextScatt, S);
637 NextScatt = isl_map_apply_domain(NextScatt, AccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000638
Sebastian Popa00a0292012-12-18 07:46:06 +0000639 isl_set *Deltas = isl_map_deltas(NextScatt);
640 return Deltas;
Tobias Grosser75805372011-04-29 06:27:02 +0000641}
642
Sebastian Popa00a0292012-12-18 07:46:06 +0000643bool MemoryAccess::isStrideX(__isl_take const isl_map *Schedule,
Tobias Grosser28dd4862012-01-24 16:42:16 +0000644 int StrideWidth) const {
645 isl_set *Stride, *StrideX;
646 bool IsStrideX;
Tobias Grosser75805372011-04-29 06:27:02 +0000647
Sebastian Popa00a0292012-12-18 07:46:06 +0000648 Stride = getStride(Schedule);
Tobias Grosser28dd4862012-01-24 16:42:16 +0000649 StrideX = isl_set_universe(isl_set_get_space(Stride));
650 StrideX = isl_set_fix_si(StrideX, isl_dim_set, 0, StrideWidth);
651 IsStrideX = isl_set_is_equal(Stride, StrideX);
Tobias Grosser75805372011-04-29 06:27:02 +0000652
Tobias Grosser28dd4862012-01-24 16:42:16 +0000653 isl_set_free(StrideX);
Tobias Grosserdea98232012-01-17 20:34:27 +0000654 isl_set_free(Stride);
Tobias Grosserb76f38532011-08-20 11:11:25 +0000655
Tobias Grosser28dd4862012-01-24 16:42:16 +0000656 return IsStrideX;
657}
658
Sebastian Popa00a0292012-12-18 07:46:06 +0000659bool MemoryAccess::isStrideZero(const isl_map *Schedule) const {
660 return isStrideX(Schedule, 0);
Tobias Grosser75805372011-04-29 06:27:02 +0000661}
662
Tobias Grosser79baa212014-04-10 08:38:02 +0000663bool MemoryAccess::isScalar() const {
664 return isl_map_n_out(AccessRelation) == 0;
665}
666
Sebastian Popa00a0292012-12-18 07:46:06 +0000667bool MemoryAccess::isStrideOne(const isl_map *Schedule) const {
668 return isStrideX(Schedule, 1);
Tobias Grosser75805372011-04-29 06:27:02 +0000669}
670
Tobias Grosser5d453812011-10-06 00:04:11 +0000671void MemoryAccess::setNewAccessRelation(isl_map *newAccess) {
Tobias Grosserb76f38532011-08-20 11:11:25 +0000672 isl_map_free(newAccessRelation);
Raghesh Aloor7a04f4f2011-08-03 13:47:59 +0000673 newAccessRelation = newAccess;
Raghesh Aloor3cb66282011-07-12 17:14:03 +0000674}
Tobias Grosser75805372011-04-29 06:27:02 +0000675
676//===----------------------------------------------------------------------===//
Tobias Grossercf3942d2011-10-06 00:04:05 +0000677
Tobias Grosser74394f02013-01-14 22:40:23 +0000678isl_map *ScopStmt::getScattering() const { return isl_map_copy(Scattering); }
Tobias Grossercf3942d2011-10-06 00:04:05 +0000679
Tobias Grosser37eb4222014-02-20 21:43:54 +0000680void ScopStmt::restrictDomain(__isl_take isl_set *NewDomain) {
681 assert(isl_set_is_subset(NewDomain, Domain) &&
682 "New domain is not a subset of old domain!");
683 isl_set_free(Domain);
684 Domain = NewDomain;
685 Scattering = isl_map_intersect_domain(Scattering, isl_set_copy(Domain));
686}
687
Tobias Grossercf3942d2011-10-06 00:04:05 +0000688void ScopStmt::setScattering(isl_map *NewScattering) {
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000689 assert(NewScattering && "New scattering is nullptr");
Tobias Grosserb76f38532011-08-20 11:11:25 +0000690 isl_map_free(Scattering);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000691 Scattering = NewScattering;
Tobias Grosserb76f38532011-08-20 11:11:25 +0000692}
693
Tobias Grosser75805372011-04-29 06:27:02 +0000694void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) {
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000695 unsigned NbIterators = getNumIterators();
696 unsigned NbScatteringDims = Parent.getMaxLoopDepth() * 2 + 1;
697
Tobias Grosser084d8f72012-05-29 09:29:44 +0000698 isl_space *Space = isl_space_set_alloc(getIslCtx(), 0, NbScatteringDims);
Tobias Grosserf5338802011-10-06 00:03:35 +0000699 Space = isl_space_set_tuple_name(Space, isl_dim_out, "scattering");
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000700
Tobias Grosser084d8f72012-05-29 09:29:44 +0000701 Scattering = isl_map_from_domain_and_range(isl_set_universe(getDomainSpace()),
702 isl_set_universe(Space));
Tobias Grosser75805372011-04-29 06:27:02 +0000703
704 // Loop dimensions.
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000705 for (unsigned i = 0; i < NbIterators; ++i)
Tobias Grosserabfbe632013-02-05 12:09:06 +0000706 Scattering =
707 isl_map_equate(Scattering, isl_dim_out, 2 * i + 1, isl_dim_in, i);
Tobias Grosser75805372011-04-29 06:27:02 +0000708
709 // Constant dimensions
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000710 for (unsigned i = 0; i < NbIterators + 1; ++i)
711 Scattering = isl_map_fix_si(Scattering, isl_dim_out, 2 * i, Scatter[i]);
Tobias Grosser75805372011-04-29 06:27:02 +0000712
713 // Fill scattering dimensions.
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000714 for (unsigned i = 2 * NbIterators + 1; i < NbScatteringDims; ++i)
715 Scattering = isl_map_fix_si(Scattering, isl_dim_out, i, 0);
Tobias Grosser75805372011-04-29 06:27:02 +0000716
Tobias Grosser37487052011-10-06 00:03:42 +0000717 Scattering = isl_map_align_params(Scattering, Parent.getParamSpace());
Tobias Grosser75805372011-04-29 06:27:02 +0000718}
719
720void ScopStmt::buildAccesses(TempScop &tempScop, const Region &CurRegion) {
Tobias Grosser083d3d32014-06-28 08:59:45 +0000721 for (auto &&Access : *tempScop.getAccessFunctions(BB)) {
722 MemAccs.push_back(new MemoryAccess(Access.first, Access.second, this));
Tobias Grosserd6aafa72014-02-20 21:29:09 +0000723
724 // We do not track locations for scalar memory accesses at the moment.
725 //
726 // We do not have a use for this information at the moment. If we need this
727 // at some point, the "instruction -> access" mapping needs to be enhanced
728 // as a single instruction could then possibly perform multiple accesses.
Tobias Grosser083d3d32014-06-28 08:59:45 +0000729 if (!Access.first.isScalar()) {
730 assert(!InstructionToAccess.count(Access.second) &&
Tobias Grosser3fc91542014-02-20 21:43:45 +0000731 "Unexpected 1-to-N mapping on instruction to access map!");
Tobias Grosser083d3d32014-06-28 08:59:45 +0000732 InstructionToAccess[Access.second] = MemAccs.back();
Tobias Grosserd6aafa72014-02-20 21:29:09 +0000733 }
Tobias Grosser75805372011-04-29 06:27:02 +0000734 }
735}
736
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000737void ScopStmt::realignParams() {
Johannes Doerfertf6752892014-06-13 18:01:45 +0000738 for (MemoryAccess *MA : *this)
739 MA->realignParams();
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000740
741 Domain = isl_set_align_params(Domain, Parent.getParamSpace());
742 Scattering = isl_map_align_params(Scattering, Parent.getParamSpace());
743}
744
Tobias Grosser65b00582011-11-08 15:41:19 +0000745__isl_give isl_set *ScopStmt::buildConditionSet(const Comparison &Comp) {
Tobias Grossera601fbd2011-11-09 22:34:44 +0000746 isl_pw_aff *L = SCEVAffinator::getPwAff(this, Comp.getLHS());
747 isl_pw_aff *R = SCEVAffinator::getPwAff(this, Comp.getRHS());
Tobias Grosser75805372011-04-29 06:27:02 +0000748
Tobias Grosserd2795d02011-08-18 07:51:40 +0000749 switch (Comp.getPred()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000750 case ICmpInst::ICMP_EQ:
Tobias Grosser048c8792011-10-23 20:59:20 +0000751 return isl_pw_aff_eq_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000752 case ICmpInst::ICMP_NE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000753 return isl_pw_aff_ne_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000754 case ICmpInst::ICMP_SLT:
Tobias Grosser048c8792011-10-23 20:59:20 +0000755 return isl_pw_aff_lt_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000756 case ICmpInst::ICMP_SLE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000757 return isl_pw_aff_le_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000758 case ICmpInst::ICMP_SGT:
Tobias Grosser048c8792011-10-23 20:59:20 +0000759 return isl_pw_aff_gt_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000760 case ICmpInst::ICMP_SGE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000761 return isl_pw_aff_ge_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000762 case ICmpInst::ICMP_ULT:
763 case ICmpInst::ICMP_UGT:
764 case ICmpInst::ICMP_ULE:
Tobias Grosser75805372011-04-29 06:27:02 +0000765 case ICmpInst::ICMP_UGE:
Tobias Grosserd2795d02011-08-18 07:51:40 +0000766 llvm_unreachable("Unsigned comparisons not yet supported");
Tobias Grosser75805372011-04-29 06:27:02 +0000767 default:
768 llvm_unreachable("Non integer predicate not supported");
769 }
Tobias Grosser75805372011-04-29 06:27:02 +0000770}
771
Tobias Grossere19661e2011-10-07 08:46:57 +0000772__isl_give isl_set *ScopStmt::addLoopBoundsToDomain(__isl_take isl_set *Domain,
Tobias Grosser60b54f12011-11-08 15:41:28 +0000773 TempScop &tempScop) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000774 isl_space *Space;
775 isl_local_space *LocalSpace;
Tobias Grosser75805372011-04-29 06:27:02 +0000776
Tobias Grossere19661e2011-10-07 08:46:57 +0000777 Space = isl_set_get_space(Domain);
778 LocalSpace = isl_local_space_from_space(Space);
Tobias Grosserf5338802011-10-06 00:03:35 +0000779
Tobias Grosser75805372011-04-29 06:27:02 +0000780 for (int i = 0, e = getNumIterators(); i != e; ++i) {
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000781 isl_aff *Zero = isl_aff_zero_on_domain(isl_local_space_copy(LocalSpace));
Tobias Grosserabfbe632013-02-05 12:09:06 +0000782 isl_pw_aff *IV =
783 isl_pw_aff_from_aff(isl_aff_set_coefficient_si(Zero, isl_dim_in, i, 1));
Tobias Grosser75805372011-04-29 06:27:02 +0000784
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000785 // 0 <= IV.
786 isl_set *LowerBound = isl_pw_aff_nonneg_set(isl_pw_aff_copy(IV));
787 Domain = isl_set_intersect(Domain, LowerBound);
788
789 // IV <= LatchExecutions.
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000790 const Loop *L = getLoopForDimension(i);
Tobias Grosser1179afa2011-11-02 21:37:51 +0000791 const SCEV *LatchExecutions = tempScop.getLoopBound(L);
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000792 isl_pw_aff *UpperBound = SCEVAffinator::getPwAff(this, LatchExecutions);
793 isl_set *UpperBoundSet = isl_pw_aff_le_set(IV, UpperBound);
Tobias Grosser75805372011-04-29 06:27:02 +0000794 Domain = isl_set_intersect(Domain, UpperBoundSet);
795 }
796
Tobias Grosserf5338802011-10-06 00:03:35 +0000797 isl_local_space_free(LocalSpace);
Tobias Grossere19661e2011-10-07 08:46:57 +0000798 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000799}
800
Tobias Grossere602a072013-05-07 07:30:56 +0000801__isl_give isl_set *ScopStmt::addConditionsToDomain(__isl_take isl_set *Domain,
802 TempScop &tempScop,
803 const Region &CurRegion) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000804 const Region *TopRegion = tempScop.getMaxRegion().getParent(),
Tobias Grosserd7e58642013-04-10 06:55:45 +0000805 *CurrentRegion = &CurRegion;
Tobias Grossere19661e2011-10-07 08:46:57 +0000806 const BasicBlock *BranchingBB = BB;
Tobias Grosser75805372011-04-29 06:27:02 +0000807
Tobias Grosser75805372011-04-29 06:27:02 +0000808 do {
Tobias Grossere19661e2011-10-07 08:46:57 +0000809 if (BranchingBB != CurrentRegion->getEntry()) {
810 if (const BBCond *Condition = tempScop.getBBCond(BranchingBB))
Tobias Grosser083d3d32014-06-28 08:59:45 +0000811 for (const auto &C : *Condition) {
812 isl_set *ConditionSet = buildConditionSet(C);
Tobias Grossere19661e2011-10-07 08:46:57 +0000813 Domain = isl_set_intersect(Domain, ConditionSet);
Tobias Grosser75805372011-04-29 06:27:02 +0000814 }
815 }
Tobias Grossere19661e2011-10-07 08:46:57 +0000816 BranchingBB = CurrentRegion->getEntry();
817 CurrentRegion = CurrentRegion->getParent();
818 } while (TopRegion != CurrentRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000819
Tobias Grossere19661e2011-10-07 08:46:57 +0000820 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000821}
822
Tobias Grossere602a072013-05-07 07:30:56 +0000823__isl_give isl_set *ScopStmt::buildDomain(TempScop &tempScop,
824 const Region &CurRegion) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000825 isl_space *Space;
826 isl_set *Domain;
Tobias Grosser084d8f72012-05-29 09:29:44 +0000827 isl_id *Id;
Tobias Grossere19661e2011-10-07 08:46:57 +0000828
829 Space = isl_space_set_alloc(getIslCtx(), 0, getNumIterators());
830
Tobias Grosser084d8f72012-05-29 09:29:44 +0000831 Id = isl_id_alloc(getIslCtx(), getBaseName(), this);
832
Tobias Grossere19661e2011-10-07 08:46:57 +0000833 Domain = isl_set_universe(Space);
Tobias Grossere19661e2011-10-07 08:46:57 +0000834 Domain = addLoopBoundsToDomain(Domain, tempScop);
835 Domain = addConditionsToDomain(Domain, tempScop, CurRegion);
Tobias Grosser084d8f72012-05-29 09:29:44 +0000836 Domain = isl_set_set_tuple_id(Domain, Id);
Tobias Grossere19661e2011-10-07 08:46:57 +0000837
838 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000839}
840
Tobias Grosser74394f02013-01-14 22:40:23 +0000841ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion,
Sebastian Pop860e0212013-02-15 21:26:44 +0000842 BasicBlock &bb, SmallVectorImpl<Loop *> &Nest,
Tobias Grosser75805372011-04-29 06:27:02 +0000843 SmallVectorImpl<unsigned> &Scatter)
Tobias Grosser4d96c8d2013-03-23 01:05:07 +0000844 : Parent(parent), BB(&bb), IVS(Nest.size()), NestLoops(Nest.size()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000845 // Setup the induction variables.
Sebastian Pop860e0212013-02-15 21:26:44 +0000846 for (unsigned i = 0, e = Nest.size(); i < e; ++i) {
Sebastian Pop27c10c62013-03-22 22:07:43 +0000847 if (!SCEVCodegen) {
848 PHINode *PN = Nest[i]->getCanonicalInductionVariable();
849 assert(PN && "Non canonical IV in Scop!");
Tobias Grosser826b2af2013-03-21 16:14:50 +0000850 IVS[i] = PN;
Sebastian Pop27c10c62013-03-22 22:07:43 +0000851 }
Sebastian Pop860e0212013-02-15 21:26:44 +0000852 NestLoops[i] = Nest[i];
Tobias Grosser75805372011-04-29 06:27:02 +0000853 }
854
Johannes Doerfert79fc23f2014-07-24 23:48:02 +0000855 BaseName = getIslCompatibleName("Stmt_", &bb, "");
Tobias Grosser75805372011-04-29 06:27:02 +0000856
Tobias Grossere19661e2011-10-07 08:46:57 +0000857 Domain = buildDomain(tempScop, CurRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000858 buildScattering(Scatter);
859 buildAccesses(tempScop, CurRegion);
Johannes Doerferte58a0122014-06-27 20:31:28 +0000860 checkForReductions();
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000861}
862
Johannes Doerferte58a0122014-06-27 20:31:28 +0000863/// @brief Collect loads which might form a reduction chain with @p StoreMA
864///
865/// Check if the stored value for @p StoreMA is a binary operator with one or
866/// two loads as operands. If the binary operand is commutative & associative,
867/// used only once (by @p StoreMA) and its load operands are also used only
868/// once, we have found a possible reduction chain. It starts at an operand
869/// load and includes the binary operator and @p StoreMA.
870///
871/// Note: We allow only one use to ensure the load and binary operator cannot
872/// escape this block or into any other store except @p StoreMA.
873void ScopStmt::collectCandiateReductionLoads(
874 MemoryAccess *StoreMA, SmallVectorImpl<MemoryAccess *> &Loads) {
875 auto *Store = dyn_cast<StoreInst>(StoreMA->getAccessInstruction());
876 if (!Store)
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000877 return;
878
879 // Skip if there is not one binary operator between the load and the store
880 auto *BinOp = dyn_cast<BinaryOperator>(Store->getValueOperand());
Johannes Doerferte58a0122014-06-27 20:31:28 +0000881 if (!BinOp)
882 return;
883
884 // Skip if the binary operators has multiple uses
885 if (BinOp->getNumUses() != 1)
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000886 return;
887
888 // Skip if the opcode of the binary operator is not commutative/associative
889 if (!BinOp->isCommutative() || !BinOp->isAssociative())
890 return;
891
Johannes Doerfert9890a052014-07-01 00:32:29 +0000892 // Skip if the binary operator is outside the current SCoP
893 if (BinOp->getParent() != Store->getParent())
894 return;
895
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000896 // Skip if it is a multiplicative reduction and we disabled them
897 if (DisableMultiplicativeReductions &&
898 (BinOp->getOpcode() == Instruction::Mul ||
899 BinOp->getOpcode() == Instruction::FMul))
900 return;
901
Johannes Doerferte58a0122014-06-27 20:31:28 +0000902 // Check the binary operator operands for a candidate load
903 auto *PossibleLoad0 = dyn_cast<LoadInst>(BinOp->getOperand(0));
904 auto *PossibleLoad1 = dyn_cast<LoadInst>(BinOp->getOperand(1));
905 if (!PossibleLoad0 && !PossibleLoad1)
906 return;
907
908 // A load is only a candidate if it cannot escape (thus has only this use)
909 if (PossibleLoad0 && PossibleLoad0->getNumUses() == 1)
Johannes Doerfert9890a052014-07-01 00:32:29 +0000910 if (PossibleLoad0->getParent() == Store->getParent())
911 Loads.push_back(lookupAccessFor(PossibleLoad0));
Johannes Doerferte58a0122014-06-27 20:31:28 +0000912 if (PossibleLoad1 && PossibleLoad1->getNumUses() == 1)
Johannes Doerfert9890a052014-07-01 00:32:29 +0000913 if (PossibleLoad1->getParent() == Store->getParent())
914 Loads.push_back(lookupAccessFor(PossibleLoad1));
Johannes Doerferte58a0122014-06-27 20:31:28 +0000915}
916
917/// @brief Check for reductions in this ScopStmt
918///
919/// Iterate over all store memory accesses and check for valid binary reduction
920/// like chains. For all candidates we check if they have the same base address
921/// and there are no other accesses which overlap with them. The base address
922/// check rules out impossible reductions candidates early. The overlap check,
923/// together with the "only one user" check in collectCandiateReductionLoads,
924/// guarantees that none of the intermediate results will escape during
925/// execution of the loop nest. We basically check here that no other memory
926/// access can access the same memory as the potential reduction.
927void ScopStmt::checkForReductions() {
928 SmallVector<MemoryAccess *, 2> Loads;
929 SmallVector<std::pair<MemoryAccess *, MemoryAccess *>, 4> Candidates;
930
931 // First collect candidate load-store reduction chains by iterating over all
932 // stores and collecting possible reduction loads.
933 for (MemoryAccess *StoreMA : MemAccs) {
934 if (StoreMA->isRead())
935 continue;
936
937 Loads.clear();
938 collectCandiateReductionLoads(StoreMA, Loads);
939 for (MemoryAccess *LoadMA : Loads)
940 Candidates.push_back(std::make_pair(LoadMA, StoreMA));
941 }
942
943 // Then check each possible candidate pair.
944 for (const auto &CandidatePair : Candidates) {
945 bool Valid = true;
946 isl_map *LoadAccs = CandidatePair.first->getAccessRelation();
947 isl_map *StoreAccs = CandidatePair.second->getAccessRelation();
948
949 // Skip those with obviously unequal base addresses.
950 if (!isl_map_has_equal_space(LoadAccs, StoreAccs)) {
951 isl_map_free(LoadAccs);
952 isl_map_free(StoreAccs);
953 continue;
954 }
955
956 // And check if the remaining for overlap with other memory accesses.
957 isl_map *AllAccsRel = isl_map_union(LoadAccs, StoreAccs);
958 AllAccsRel = isl_map_intersect_domain(AllAccsRel, getDomain());
959 isl_set *AllAccs = isl_map_range(AllAccsRel);
960
961 for (MemoryAccess *MA : MemAccs) {
962 if (MA == CandidatePair.first || MA == CandidatePair.second)
963 continue;
964
965 isl_map *AccRel =
966 isl_map_intersect_domain(MA->getAccessRelation(), getDomain());
967 isl_set *Accs = isl_map_range(AccRel);
968
969 if (isl_set_has_equal_space(AllAccs, Accs) || isl_set_free(Accs)) {
970 isl_set *OverlapAccs = isl_set_intersect(Accs, isl_set_copy(AllAccs));
971 Valid = Valid && isl_set_is_empty(OverlapAccs);
972 isl_set_free(OverlapAccs);
973 }
974 }
975
976 isl_set_free(AllAccs);
977 if (!Valid)
978 continue;
979
Johannes Doerfertf6183392014-07-01 20:52:51 +0000980 const LoadInst *Load =
981 dyn_cast<const LoadInst>(CandidatePair.first->getAccessInstruction());
982 MemoryAccess::ReductionType RT =
983 getReductionType(dyn_cast<BinaryOperator>(Load->user_back()), Load);
984
Johannes Doerferte58a0122014-06-27 20:31:28 +0000985 // If no overlapping access was found we mark the load and store as
986 // reduction like.
Johannes Doerfertf6183392014-07-01 20:52:51 +0000987 CandidatePair.first->markAsReductionLike(RT);
988 CandidatePair.second->markAsReductionLike(RT);
Johannes Doerferte58a0122014-06-27 20:31:28 +0000989 }
Tobias Grosser75805372011-04-29 06:27:02 +0000990}
991
Tobias Grosser74394f02013-01-14 22:40:23 +0000992std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); }
Tobias Grosser75805372011-04-29 06:27:02 +0000993
994std::string ScopStmt::getScatteringStr() const {
Tobias Grossercf3942d2011-10-06 00:04:05 +0000995 return stringFromIslObj(Scattering);
Tobias Grosser75805372011-04-29 06:27:02 +0000996}
997
Tobias Grosser74394f02013-01-14 22:40:23 +0000998unsigned ScopStmt::getNumParams() const { return Parent.getNumParams(); }
Tobias Grosser75805372011-04-29 06:27:02 +0000999
1000unsigned ScopStmt::getNumIterators() const {
1001 // The final read has one dimension with one element.
1002 if (!BB)
1003 return 1;
1004
Sebastian Pop860e0212013-02-15 21:26:44 +00001005 return NestLoops.size();
Tobias Grosser75805372011-04-29 06:27:02 +00001006}
1007
1008unsigned ScopStmt::getNumScattering() const {
1009 return isl_map_dim(Scattering, isl_dim_out);
1010}
1011
1012const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
1013
Tobias Grosserabfbe632013-02-05 12:09:06 +00001014const PHINode *
1015ScopStmt::getInductionVariableForDimension(unsigned Dimension) const {
Sebastian Popf30d3b22013-02-15 21:26:48 +00001016 return IVS[Dimension];
Hongbin Zheng27f3afb2011-04-30 03:26:51 +00001017}
1018
1019const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
Sebastian Pop860e0212013-02-15 21:26:44 +00001020 return NestLoops[Dimension];
Tobias Grosser75805372011-04-29 06:27:02 +00001021}
1022
Tobias Grosser74394f02013-01-14 22:40:23 +00001023isl_ctx *ScopStmt::getIslCtx() const { return Parent.getIslCtx(); }
Tobias Grosser75805372011-04-29 06:27:02 +00001024
Tobias Grosser74394f02013-01-14 22:40:23 +00001025isl_set *ScopStmt::getDomain() const { return isl_set_copy(Domain); }
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +00001026
Tobias Grosser78d8a3d2012-01-17 20:34:23 +00001027isl_space *ScopStmt::getDomainSpace() const {
1028 return isl_set_get_space(Domain);
1029}
1030
Tobias Grosser74394f02013-01-14 22:40:23 +00001031isl_id *ScopStmt::getDomainId() const { return isl_set_get_tuple_id(Domain); }
Tobias Grossercd95b772012-08-30 11:49:38 +00001032
Tobias Grosser75805372011-04-29 06:27:02 +00001033ScopStmt::~ScopStmt() {
1034 while (!MemAccs.empty()) {
1035 delete MemAccs.back();
1036 MemAccs.pop_back();
1037 }
1038
1039 isl_set_free(Domain);
1040 isl_map_free(Scattering);
1041}
1042
1043void ScopStmt::print(raw_ostream &OS) const {
1044 OS << "\t" << getBaseName() << "\n";
Tobias Grosser75805372011-04-29 06:27:02 +00001045 OS.indent(12) << "Domain :=\n";
1046
1047 if (Domain) {
1048 OS.indent(16) << getDomainStr() << ";\n";
1049 } else
1050 OS.indent(16) << "n/a\n";
1051
1052 OS.indent(12) << "Scattering :=\n";
1053
1054 if (Domain) {
1055 OS.indent(16) << getScatteringStr() << ";\n";
1056 } else
1057 OS.indent(16) << "n/a\n";
1058
Tobias Grosser083d3d32014-06-28 08:59:45 +00001059 for (MemoryAccess *Access : MemAccs)
1060 Access->print(OS);
Tobias Grosser75805372011-04-29 06:27:02 +00001061}
1062
1063void ScopStmt::dump() const { print(dbgs()); }
1064
1065//===----------------------------------------------------------------------===//
1066/// Scop class implement
Tobias Grosser60b54f12011-11-08 15:41:28 +00001067
Tobias Grosser7ffe4e82011-11-17 12:56:10 +00001068void Scop::setContext(__isl_take isl_set *NewContext) {
Tobias Grosserff9b54d2011-11-15 11:38:44 +00001069 NewContext = isl_set_align_params(NewContext, isl_set_get_space(Context));
1070 isl_set_free(Context);
1071 Context = NewContext;
1072}
1073
Tobias Grosserabfbe632013-02-05 12:09:06 +00001074void Scop::addParams(std::vector<const SCEV *> NewParameters) {
Tobias Grosser083d3d32014-06-28 08:59:45 +00001075 for (const SCEV *Parameter : NewParameters) {
Tobias Grosser60b54f12011-11-08 15:41:28 +00001076 if (ParameterIds.find(Parameter) != ParameterIds.end())
1077 continue;
1078
1079 int dimension = Parameters.size();
1080
1081 Parameters.push_back(Parameter);
1082 ParameterIds[Parameter] = dimension;
1083 }
1084}
1085
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001086__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) const {
1087 ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter);
Tobias Grosser76c2e322011-11-07 12:58:59 +00001088
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001089 if (IdIter == ParameterIds.end())
Tobias Grosser5a56cbf2014-04-16 07:33:47 +00001090 return nullptr;
Tobias Grosser76c2e322011-11-07 12:58:59 +00001091
Tobias Grosser8f99c162011-11-15 11:38:55 +00001092 std::string ParameterName;
1093
1094 if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
1095 Value *Val = ValueParameter->getValue();
Tobias Grosser29ee0b12011-11-17 14:52:36 +00001096 ParameterName = Val->getName();
Tobias Grosser8f99c162011-11-15 11:38:55 +00001097 }
1098
1099 if (ParameterName == "" || ParameterName.substr(0, 2) == "p_")
Hongbin Zheng86a37742012-04-25 08:01:38 +00001100 ParameterName = "p_" + utostr_32(IdIter->second);
Tobias Grosser8f99c162011-11-15 11:38:55 +00001101
Tobias Grosser20532b82014-04-11 17:56:49 +00001102 return isl_id_alloc(getIslCtx(), ParameterName.c_str(),
1103 const_cast<void *>((const void *)Parameter));
Tobias Grosser76c2e322011-11-07 12:58:59 +00001104}
Tobias Grosser75805372011-04-29 06:27:02 +00001105
Tobias Grosser6be480c2011-11-08 15:41:13 +00001106void Scop::buildContext() {
1107 isl_space *Space = isl_space_params_alloc(IslCtx, 0);
Tobias Grossere86109f2013-10-29 21:05:49 +00001108 Context = isl_set_universe(isl_space_copy(Space));
1109 AssumedContext = isl_set_universe(Space);
Tobias Grosser0e27e242011-10-06 00:03:48 +00001110}
1111
Tobias Grosser18daaca2012-05-22 10:47:27 +00001112void Scop::addParameterBounds() {
1113 for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
Tobias Grosseredab1352013-06-21 06:41:31 +00001114 isl_val *V;
Tobias Grosser18daaca2012-05-22 10:47:27 +00001115 isl_id *Id;
1116 const SCEV *Scev;
1117 const IntegerType *T;
1118
1119 Id = isl_set_get_dim_id(Context, isl_dim_param, i);
Tobias Grosserabfbe632013-02-05 12:09:06 +00001120 Scev = (const SCEV *)isl_id_get_user(Id);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001121 T = dyn_cast<IntegerType>(Scev->getType());
1122 isl_id_free(Id);
1123
1124 assert(T && "Not an integer type");
1125 int Width = T->getBitWidth();
1126
Tobias Grosseredab1352013-06-21 06:41:31 +00001127 V = isl_val_int_from_si(IslCtx, Width - 1);
1128 V = isl_val_2exp(V);
1129 V = isl_val_neg(V);
1130 Context = isl_set_lower_bound_val(Context, isl_dim_param, i, V);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001131
Tobias Grosseredab1352013-06-21 06:41:31 +00001132 V = isl_val_int_from_si(IslCtx, Width - 1);
1133 V = isl_val_2exp(V);
1134 V = isl_val_sub_ui(V, 1);
1135 Context = isl_set_upper_bound_val(Context, isl_dim_param, i, V);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001136 }
1137}
1138
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001139void Scop::realignParams() {
Tobias Grosser6be480c2011-11-08 15:41:13 +00001140 // Add all parameters into a common model.
Tobias Grosser60b54f12011-11-08 15:41:28 +00001141 isl_space *Space = isl_space_params_alloc(IslCtx, ParameterIds.size());
Tobias Grosser6be480c2011-11-08 15:41:13 +00001142
Tobias Grosser083d3d32014-06-28 08:59:45 +00001143 for (const auto &ParamID : ParameterIds) {
1144 const SCEV *Parameter = ParamID.first;
Tobias Grosser6be480c2011-11-08 15:41:13 +00001145 isl_id *id = getIdForParam(Parameter);
Tobias Grosser083d3d32014-06-28 08:59:45 +00001146 Space = isl_space_set_dim_id(Space, isl_dim_param, ParamID.second, id);
Tobias Grosser6be480c2011-11-08 15:41:13 +00001147 }
1148
1149 // Align the parameters of all data structures to the model.
1150 Context = isl_set_align_params(Context, Space);
1151
Tobias Grosser083d3d32014-06-28 08:59:45 +00001152 for (ScopStmt *Stmt : *this)
1153 Stmt->realignParams();
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001154}
1155
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001156void Scop::simplifyAssumedContext() {
1157 // The parameter constraints of the iteration domains give us a set of
1158 // constraints that need to hold for all cases where at least a single
1159 // statement iteration is executed in the whole scop. We now simplify the
1160 // assumed context under the assumption that such constraints hold and at
1161 // least a single statement iteration is executed. For cases where no
1162 // statement instances are executed, the assumptions we have taken about
1163 // the executed code do not matter and can be changed.
1164 //
1165 // WARNING: This only holds if the assumptions we have taken do not reduce
1166 // the set of statement instances that are executed. Otherwise we
1167 // may run into a case where the iteration domains suggest that
1168 // for a certain set of parameter constraints no code is executed,
1169 // but in the original program some computation would have been
1170 // performed. In such a case, modifying the run-time conditions and
1171 // possibly influencing the run-time check may cause certain scops
1172 // to not be executed.
1173 //
1174 // Example:
1175 //
1176 // When delinearizing the following code:
1177 //
1178 // for (long i = 0; i < 100; i++)
1179 // for (long j = 0; j < m; j++)
1180 // A[i+p][j] = 1.0;
1181 //
1182 // we assume that the condition m <= 0 or (m >= 1 and p >= 0) holds as
1183 // otherwise we would access out of bound data. Now, knowing that code is
1184 // only executed for the case m >= 0, it is sufficient to assume p >= 0.
1185 AssumedContext =
1186 isl_set_gist_params(AssumedContext, isl_union_set_params(getDomains()));
1187}
1188
Tobias Grosser0e27e242011-10-06 00:03:48 +00001189Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
1190 isl_ctx *Context)
Tobias Grosserabfbe632013-02-05 12:09:06 +00001191 : SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
1192 MaxLoopDepth(tempScop.getMaxLoopDepth()) {
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001193 IslCtx = Context;
Tobias Grosser6be480c2011-11-08 15:41:13 +00001194 buildContext();
Tobias Grosser75805372011-04-29 06:27:02 +00001195
Tobias Grosserabfbe632013-02-05 12:09:06 +00001196 SmallVector<Loop *, 8> NestLoops;
Tobias Grosser75805372011-04-29 06:27:02 +00001197 SmallVector<unsigned, 8> Scatter;
1198
1199 Scatter.assign(MaxLoopDepth + 1, 0);
1200
1201 // Build the iteration domain, access functions and scattering functions
1202 // traversing the region tree.
1203 buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
Tobias Grosser75805372011-04-29 06:27:02 +00001204
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001205 realignParams();
Tobias Grosser18daaca2012-05-22 10:47:27 +00001206 addParameterBounds();
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001207 simplifyAssumedContext();
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001208
Tobias Grosser75805372011-04-29 06:27:02 +00001209 assert(NestLoops.empty() && "NestLoops not empty at top level!");
1210}
1211
1212Scop::~Scop() {
1213 isl_set_free(Context);
Tobias Grossere86109f2013-10-29 21:05:49 +00001214 isl_set_free(AssumedContext);
Tobias Grosser75805372011-04-29 06:27:02 +00001215
1216 // Free the statements;
Tobias Grosser083d3d32014-06-28 08:59:45 +00001217 for (ScopStmt *Stmt : *this)
1218 delete Stmt;
Tobias Grosser75805372011-04-29 06:27:02 +00001219}
1220
Tobias Grosser74394f02013-01-14 22:40:23 +00001221std::string Scop::getContextStr() const { return stringFromIslObj(Context); }
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001222std::string Scop::getAssumedContextStr() const {
1223 return stringFromIslObj(AssumedContext);
1224}
Tobias Grosser75805372011-04-29 06:27:02 +00001225
1226std::string Scop::getNameStr() const {
1227 std::string ExitName, EntryName;
1228 raw_string_ostream ExitStr(ExitName);
1229 raw_string_ostream EntryStr(EntryName);
1230
Tobias Grosserf240b482014-01-09 10:42:15 +00001231 R.getEntry()->printAsOperand(EntryStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001232 EntryStr.str();
1233
1234 if (R.getExit()) {
Tobias Grosserf240b482014-01-09 10:42:15 +00001235 R.getExit()->printAsOperand(ExitStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001236 ExitStr.str();
1237 } else
1238 ExitName = "FunctionExit";
1239
1240 return EntryName + "---" + ExitName;
1241}
1242
Tobias Grosser74394f02013-01-14 22:40:23 +00001243__isl_give isl_set *Scop::getContext() const { return isl_set_copy(Context); }
Tobias Grosser37487052011-10-06 00:03:42 +00001244__isl_give isl_space *Scop::getParamSpace() const {
1245 return isl_set_get_space(this->Context);
1246}
1247
Tobias Grossere86109f2013-10-29 21:05:49 +00001248__isl_give isl_set *Scop::getAssumedContext() const {
1249 return isl_set_copy(AssumedContext);
1250}
1251
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001252void Scop::addAssumption(__isl_take isl_set *Set) {
1253 AssumedContext = isl_set_intersect(AssumedContext, Set);
1254}
1255
Tobias Grosser75805372011-04-29 06:27:02 +00001256void Scop::printContext(raw_ostream &OS) const {
1257 OS << "Context:\n";
1258
1259 if (!Context) {
1260 OS.indent(4) << "n/a\n\n";
1261 return;
1262 }
1263
1264 OS.indent(4) << getContextStr() << "\n";
Tobias Grosser60b54f12011-11-08 15:41:28 +00001265
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001266 OS.indent(4) << "Assumed Context:\n";
1267 if (!AssumedContext) {
1268 OS.indent(4) << "n/a\n\n";
1269 return;
1270 }
1271
1272 OS.indent(4) << getAssumedContextStr() << "\n";
1273
Tobias Grosser083d3d32014-06-28 08:59:45 +00001274 for (const SCEV *Parameter : Parameters) {
Tobias Grosser60b54f12011-11-08 15:41:28 +00001275 int Dim = ParameterIds.find(Parameter)->second;
Tobias Grosser60b54f12011-11-08 15:41:28 +00001276 OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
1277 }
Tobias Grosser75805372011-04-29 06:27:02 +00001278}
1279
1280void Scop::printStatements(raw_ostream &OS) const {
1281 OS << "Statements {\n";
1282
Tobias Grosser083d3d32014-06-28 08:59:45 +00001283 for (ScopStmt *Stmt : *this)
1284 OS.indent(4) << *Stmt;
Tobias Grosser75805372011-04-29 06:27:02 +00001285
1286 OS.indent(4) << "}\n";
1287}
1288
Tobias Grosser75805372011-04-29 06:27:02 +00001289void Scop::print(raw_ostream &OS) const {
Tobias Grosser4eb7ddb2014-03-18 18:51:11 +00001290 OS.indent(4) << "Function: " << getRegion().getEntry()->getParent()->getName()
1291 << "\n";
Tobias Grosser483fdd42014-03-18 18:05:38 +00001292 OS.indent(4) << "Region: " << getNameStr() << "\n";
Tobias Grosser75805372011-04-29 06:27:02 +00001293 printContext(OS.indent(4));
1294 printStatements(OS.indent(4));
1295}
1296
1297void Scop::dump() const { print(dbgs()); }
1298
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001299isl_ctx *Scop::getIslCtx() const { return IslCtx; }
Tobias Grosser75805372011-04-29 06:27:02 +00001300
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001301__isl_give isl_union_set *Scop::getDomains() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001302 isl_union_set *Domain = isl_union_set_empty(getParamSpace());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001303
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001304 for (ScopStmt *Stmt : *this)
1305 Domain = isl_union_set_add_set(Domain, Stmt->getDomain());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001306
1307 return Domain;
1308}
1309
Tobias Grosser780ce0f2014-07-11 07:12:10 +00001310__isl_give isl_union_map *Scop::getMustWrites() {
1311 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1312
1313 for (ScopStmt *Stmt : *this) {
1314 for (MemoryAccess *MA : *Stmt) {
1315 if (!MA->isMustWrite())
1316 continue;
1317
1318 isl_set *Domain = Stmt->getDomain();
1319 isl_map *AccessDomain = MA->getAccessRelation();
1320 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1321 Write = isl_union_map_add_map(Write, AccessDomain);
1322 }
1323 }
1324 return isl_union_map_coalesce(Write);
1325}
1326
1327__isl_give isl_union_map *Scop::getMayWrites() {
1328 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1329
1330 for (ScopStmt *Stmt : *this) {
1331 for (MemoryAccess *MA : *Stmt) {
1332 if (!MA->isMayWrite())
1333 continue;
1334
1335 isl_set *Domain = Stmt->getDomain();
1336 isl_map *AccessDomain = MA->getAccessRelation();
1337 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1338 Write = isl_union_map_add_map(Write, AccessDomain);
1339 }
1340 }
1341 return isl_union_map_coalesce(Write);
1342}
1343
Tobias Grosser37eb4222014-02-20 21:43:54 +00001344__isl_give isl_union_map *Scop::getWrites() {
1345 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1346
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001347 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001348 for (MemoryAccess *MA : *Stmt) {
1349 if (!MA->isWrite())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001350 continue;
1351
1352 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001353 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001354 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1355 Write = isl_union_map_add_map(Write, AccessDomain);
1356 }
1357 }
1358 return isl_union_map_coalesce(Write);
1359}
1360
1361__isl_give isl_union_map *Scop::getReads() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001362 isl_union_map *Read = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001363
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001364 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001365 for (MemoryAccess *MA : *Stmt) {
1366 if (!MA->isRead())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001367 continue;
1368
1369 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001370 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001371
1372 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1373 Read = isl_union_map_add_map(Read, AccessDomain);
1374 }
1375 }
1376 return isl_union_map_coalesce(Read);
1377}
1378
1379__isl_give isl_union_map *Scop::getSchedule() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001380 isl_union_map *Schedule = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001381
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001382 for (ScopStmt *Stmt : *this)
Tobias Grosser37eb4222014-02-20 21:43:54 +00001383 Schedule = isl_union_map_add_map(Schedule, Stmt->getScattering());
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001384
Tobias Grosser37eb4222014-02-20 21:43:54 +00001385 return isl_union_map_coalesce(Schedule);
1386}
1387
1388bool Scop::restrictDomains(__isl_take isl_union_set *Domain) {
1389 bool Changed = false;
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001390 for (ScopStmt *Stmt : *this) {
Tobias Grosser37eb4222014-02-20 21:43:54 +00001391 isl_union_set *StmtDomain = isl_union_set_from_set(Stmt->getDomain());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001392 isl_union_set *NewStmtDomain = isl_union_set_intersect(
1393 isl_union_set_copy(StmtDomain), isl_union_set_copy(Domain));
1394
1395 if (isl_union_set_is_subset(StmtDomain, NewStmtDomain)) {
1396 isl_union_set_free(StmtDomain);
1397 isl_union_set_free(NewStmtDomain);
1398 continue;
1399 }
1400
1401 Changed = true;
1402
1403 isl_union_set_free(StmtDomain);
1404 NewStmtDomain = isl_union_set_coalesce(NewStmtDomain);
1405
1406 if (isl_union_set_is_empty(NewStmtDomain)) {
1407 Stmt->restrictDomain(isl_set_empty(Stmt->getDomainSpace()));
1408 isl_union_set_free(NewStmtDomain);
1409 } else
1410 Stmt->restrictDomain(isl_set_from_union_set(NewStmtDomain));
1411 }
1412 isl_union_set_free(Domain);
1413 return Changed;
1414}
1415
Tobias Grosser75805372011-04-29 06:27:02 +00001416ScalarEvolution *Scop::getSE() const { return SE; }
1417
1418bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
1419 if (tempScop.getAccessFunctions(BB))
1420 return false;
1421
1422 return true;
1423}
1424
Tobias Grosser74394f02013-01-14 22:40:23 +00001425void Scop::buildScop(TempScop &tempScop, const Region &CurRegion,
1426 SmallVectorImpl<Loop *> &NestLoops,
1427 SmallVectorImpl<unsigned> &Scatter, LoopInfo &LI) {
Tobias Grosser75805372011-04-29 06:27:02 +00001428 Loop *L = castToLoop(CurRegion, LI);
1429
1430 if (L)
1431 NestLoops.push_back(L);
1432
1433 unsigned loopDepth = NestLoops.size();
1434 assert(Scatter.size() > loopDepth && "Scatter not big enough!");
1435
1436 for (Region::const_element_iterator I = CurRegion.element_begin(),
Tobias Grosserabfbe632013-02-05 12:09:06 +00001437 E = CurRegion.element_end();
1438 I != E; ++I)
Tobias Grosser75805372011-04-29 06:27:02 +00001439 if (I->isSubRegion())
1440 buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
1441 else {
1442 BasicBlock *BB = I->getNodeAs<BasicBlock>();
1443
1444 if (isTrivialBB(BB, tempScop))
1445 continue;
1446
Tobias Grosserabfbe632013-02-05 12:09:06 +00001447 Stmts.push_back(
1448 new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter));
Tobias Grosser75805372011-04-29 06:27:02 +00001449
1450 // Increasing the Scattering function is OK for the moment, because
1451 // we are using a depth first iterator and the program is well structured.
1452 ++Scatter[loopDepth];
1453 }
1454
1455 if (!L)
1456 return;
1457
1458 // Exiting a loop region.
1459 Scatter[loopDepth] = 0;
1460 NestLoops.pop_back();
Tobias Grosser74394f02013-01-14 22:40:23 +00001461 ++Scatter[loopDepth - 1];
Tobias Grosser75805372011-04-29 06:27:02 +00001462}
1463
1464//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +00001465ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
1466 ctx = isl_ctx_alloc();
Tobias Grosser4a8e3562011-12-07 07:42:51 +00001467 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
Tobias Grosserb76f38532011-08-20 11:11:25 +00001468}
1469
1470ScopInfo::~ScopInfo() {
1471 clear();
1472 isl_ctx_free(ctx);
1473}
1474
Tobias Grosser75805372011-04-29 06:27:02 +00001475void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
1476 AU.addRequired<LoopInfo>();
Matt Arsenault8ca36812014-07-19 18:40:17 +00001477 AU.addRequired<RegionInfoPass>();
Tobias Grosser75805372011-04-29 06:27:02 +00001478 AU.addRequired<ScalarEvolution>();
1479 AU.addRequired<TempScopInfo>();
1480 AU.setPreservesAll();
1481}
1482
1483bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
1484 LoopInfo &LI = getAnalysis<LoopInfo>();
1485 ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
1486
1487 TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
1488
1489 // This region is no Scop.
1490 if (!tempScop) {
1491 scop = 0;
1492 return false;
1493 }
1494
1495 // Statistics.
1496 ++ScopFound;
Tobias Grosser74394f02013-01-14 22:40:23 +00001497 if (tempScop->getMaxLoopDepth() > 0)
1498 ++RichScopFound;
Tobias Grosser75805372011-04-29 06:27:02 +00001499
Tobias Grosserb76f38532011-08-20 11:11:25 +00001500 scop = new Scop(*tempScop, LI, SE, ctx);
Tobias Grosser75805372011-04-29 06:27:02 +00001501
1502 return false;
1503}
1504
1505char ScopInfo::ID = 0;
1506
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001507Pass *polly::createScopInfoPass() { return new ScopInfo(); }
1508
Tobias Grosser73600b82011-10-08 00:30:40 +00001509INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
1510 "Polly - Create polyhedral description of Scops", false,
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001511 false);
1512INITIALIZE_PASS_DEPENDENCY(LoopInfo);
Matt Arsenault8ca36812014-07-19 18:40:17 +00001513INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001514INITIALIZE_PASS_DEPENDENCY(ScalarEvolution);
1515INITIALIZE_PASS_DEPENDENCY(TempScopInfo);
Tobias Grosser73600b82011-10-08 00:30:40 +00001516INITIALIZE_PASS_END(ScopInfo, "polly-scops",
1517 "Polly - Create polyhedral description of Scops", false,
1518 false)