blob: 71529e5b75a35c4698e3946a1707ceb8378bfc2a [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//
Tobias Grossera5605d32014-10-29 19:58:28 +000015// This representation is shared among several tools in the polyhedral
Tobias Grosser75805372011-04-29 06:27:02 +000016// community, which are e.g. Cloog, Pluto, Loopo, Graphite.
17//
18//===----------------------------------------------------------------------===//
19
Tobias Grosser75805372011-04-29 06:27:02 +000020#include "polly/LinkAllPasses.h"
Sebastian Pop27c10c62013-03-22 22:07:43 +000021#include "polly/ScopInfo.h"
Johannes Doerfert0ee1f212014-06-17 17:31:36 +000022#include "polly/Options.h"
Tobias Grosser75805372011-04-29 06:27:02 +000023#include "polly/Support/GICHelper.h"
Tobias Grosser60b54f12011-11-08 15:41:28 +000024#include "polly/Support/SCEVValidator.h"
Tobias Grosser83628182013-05-07 08:11:54 +000025#include "polly/Support/ScopHelper.h"
Sebastian Pop27c10c62013-03-22 22:07:43 +000026#include "polly/TempScopInfo.h"
Tobias Grosser75805372011-04-29 06:27:02 +000027#include "llvm/ADT/SetVector.h"
Tobias Grosser83628182013-05-07 08:11:54 +000028#include "llvm/ADT/Statistic.h"
Hongbin Zheng86a37742012-04-25 08:01:38 +000029#include "llvm/ADT/StringExtras.h"
Tobias Grosser83628182013-05-07 08:11:54 +000030#include "llvm/Analysis/LoopInfo.h"
Johannes Doerfertb164c792014-09-18 11:17:17 +000031#include "llvm/Analysis/AliasAnalysis.h"
Tobias Grosser83628182013-05-07 08:11:54 +000032#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 Doerfert9e7b17b2014-08-18 00:40:13 +000058// Multiplicative reductions can be disabled separately as these kind of
Johannes Doerfert0ee1f212014-06-17 17:31:36 +000059// 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 Doerfert9143d672014-09-27 11:02:39 +000066static cl::opt<unsigned> RunTimeChecksMaxParameters(
67 "polly-rtc-max-parameters",
68 cl::desc("The maximal number of parameters allowed in RTCs."), cl::Hidden,
69 cl::ZeroOrMore, cl::init(8), cl::cat(PollyCategory));
70
Tobias Grosser0695ee42013-09-17 03:30:31 +000071/// Translate a 'const SCEV *' expression in an isl_pw_aff.
Tobias Grosserabfbe632013-02-05 12:09:06 +000072struct SCEVAffinator : public SCEVVisitor<SCEVAffinator, isl_pw_aff *> {
Tobias Grosser0695ee42013-09-17 03:30:31 +000073public:
Tobias Grosser0695ee42013-09-17 03:30:31 +000074 /// @brief Translate a 'const SCEV *' to an isl_pw_aff.
75 ///
76 /// @param Stmt The location at which the scalar evolution expression
77 /// is evaluated.
78 /// @param Expr The expression that is translated.
79 static __isl_give isl_pw_aff *getPwAff(ScopStmt *Stmt, const SCEV *Expr);
80
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000081private:
Tobias Grosser3cc99742012-06-06 16:33:15 +000082 isl_ctx *Ctx;
Tobias Grosserf5338802011-10-06 00:03:35 +000083 int NbLoopSpaces;
Tobias Grosser3cc99742012-06-06 16:33:15 +000084 const Scop *S;
Tobias Grosser33ba62ad2011-08-18 06:31:50 +000085
Tobias Grosser0695ee42013-09-17 03:30:31 +000086 SCEVAffinator(const ScopStmt *Stmt);
87 int getLoopDepth(const Loop *L);
Tobias Grosser60b54f12011-11-08 15:41:28 +000088
Tobias Grosser0695ee42013-09-17 03:30:31 +000089 __isl_give isl_pw_aff *visit(const SCEV *Expr);
90 __isl_give isl_pw_aff *visitConstant(const SCEVConstant *Expr);
91 __isl_give isl_pw_aff *visitTruncateExpr(const SCEVTruncateExpr *Expr);
92 __isl_give isl_pw_aff *visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr);
93 __isl_give isl_pw_aff *visitSignExtendExpr(const SCEVSignExtendExpr *Expr);
94 __isl_give isl_pw_aff *visitAddExpr(const SCEVAddExpr *Expr);
95 __isl_give isl_pw_aff *visitMulExpr(const SCEVMulExpr *Expr);
96 __isl_give isl_pw_aff *visitUDivExpr(const SCEVUDivExpr *Expr);
97 __isl_give isl_pw_aff *visitAddRecExpr(const SCEVAddRecExpr *Expr);
98 __isl_give isl_pw_aff *visitSMaxExpr(const SCEVSMaxExpr *Expr);
99 __isl_give isl_pw_aff *visitUMaxExpr(const SCEVUMaxExpr *Expr);
100 __isl_give isl_pw_aff *visitUnknown(const SCEVUnknown *Expr);
Tobias Grosser60b54f12011-11-08 15:41:28 +0000101
Tobias Grosser0695ee42013-09-17 03:30:31 +0000102 friend struct SCEVVisitor<SCEVAffinator, isl_pw_aff *>;
103};
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000104
Tobias Grosser0695ee42013-09-17 03:30:31 +0000105SCEVAffinator::SCEVAffinator(const ScopStmt *Stmt)
106 : Ctx(Stmt->getIslCtx()), NbLoopSpaces(Stmt->getNumIterators()),
107 S(Stmt->getParent()) {}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000108
Tobias Grosser0695ee42013-09-17 03:30:31 +0000109__isl_give isl_pw_aff *SCEVAffinator::getPwAff(ScopStmt *Stmt,
110 const SCEV *Scev) {
111 Scop *S = Stmt->getParent();
112 const Region *Reg = &S->getRegion();
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000113
Tobias Grosser0695ee42013-09-17 03:30:31 +0000114 S->addParams(getParamsInAffineExpr(Reg, Scev, *S->getSE()));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000115
Tobias Grosser0695ee42013-09-17 03:30:31 +0000116 SCEVAffinator Affinator(Stmt);
117 return Affinator.visit(Scev);
118}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000119
Tobias Grosser0695ee42013-09-17 03:30:31 +0000120__isl_give isl_pw_aff *SCEVAffinator::visit(const SCEV *Expr) {
121 // In case the scev is a valid parameter, we do not further analyze this
122 // expression, but create a new parameter in the isl_pw_aff. This allows us
123 // to treat subexpressions that we cannot translate into an piecewise affine
124 // expression, as constant parameters of the piecewise affine expression.
125 if (isl_id *Id = S->getIdForParam(Expr)) {
126 isl_space *Space = isl_space_set_alloc(Ctx, 1, NbLoopSpaces);
127 Space = isl_space_set_dim_id(Space, isl_dim_param, 0, Id);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000128
Tobias Grosser0695ee42013-09-17 03:30:31 +0000129 isl_set *Domain = isl_set_universe(isl_space_copy(Space));
130 isl_aff *Affine = isl_aff_zero_on_domain(isl_local_space_from_space(Space));
131 Affine = isl_aff_add_coefficient_si(Affine, isl_dim_param, 0, 1);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000132
133 return isl_pw_aff_alloc(Domain, Affine);
134 }
135
Tobias Grosser0695ee42013-09-17 03:30:31 +0000136 return SCEVVisitor<SCEVAffinator, isl_pw_aff *>::visit(Expr);
137}
138
Tobias Grosser0d170132013-10-03 13:09:19 +0000139__isl_give isl_pw_aff *SCEVAffinator::visitConstant(const SCEVConstant *Expr) {
Tobias Grosser0695ee42013-09-17 03:30:31 +0000140 ConstantInt *Value = Expr->getValue();
141 isl_val *v;
142
143 // LLVM does not define if an integer value is interpreted as a signed or
144 // unsigned value. Hence, without further information, it is unknown how
145 // this value needs to be converted to GMP. At the moment, we only support
146 // signed operations. So we just interpret it as signed. Later, there are
147 // two options:
148 //
149 // 1. We always interpret any value as signed and convert the values on
150 // demand.
151 // 2. We pass down the signedness of the calculation and use it to interpret
152 // this constant correctly.
153 v = isl_valFromAPInt(Ctx, Value->getValue(), /* isSigned */ true);
154
155 isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
Johannes Doerfert9c147372014-11-19 15:36:59 +0000156 isl_local_space *ls = isl_local_space_from_space(Space);
157 return isl_pw_aff_from_aff(isl_aff_val_on_domain(ls, v));
Tobias Grosser0695ee42013-09-17 03:30:31 +0000158}
159
160__isl_give isl_pw_aff *
161SCEVAffinator::visitTruncateExpr(const SCEVTruncateExpr *Expr) {
162 llvm_unreachable("SCEVTruncateExpr not yet supported");
163}
164
165__isl_give isl_pw_aff *
166SCEVAffinator::visitZeroExtendExpr(const SCEVZeroExtendExpr *Expr) {
167 llvm_unreachable("SCEVZeroExtendExpr not yet supported");
168}
169
170__isl_give isl_pw_aff *
171SCEVAffinator::visitSignExtendExpr(const SCEVSignExtendExpr *Expr) {
172 // Assuming the value is signed, a sign extension is basically a noop.
173 // TODO: Reconsider this as soon as we support unsigned values.
174 return visit(Expr->getOperand());
175}
176
177__isl_give isl_pw_aff *SCEVAffinator::visitAddExpr(const SCEVAddExpr *Expr) {
178 isl_pw_aff *Sum = visit(Expr->getOperand(0));
179
180 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
181 isl_pw_aff *NextSummand = visit(Expr->getOperand(i));
182 Sum = isl_pw_aff_add(Sum, NextSummand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000183 }
184
Tobias Grosser0695ee42013-09-17 03:30:31 +0000185 // TODO: Check for NSW and NUW.
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000186
Tobias Grosser0695ee42013-09-17 03:30:31 +0000187 return Sum;
188}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000189
Tobias Grosser0695ee42013-09-17 03:30:31 +0000190__isl_give isl_pw_aff *SCEVAffinator::visitMulExpr(const SCEVMulExpr *Expr) {
191 isl_pw_aff *Product = visit(Expr->getOperand(0));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000192
Tobias Grosser0695ee42013-09-17 03:30:31 +0000193 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
194 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
195
196 if (!isl_pw_aff_is_cst(Product) && !isl_pw_aff_is_cst(NextOperand)) {
197 isl_pw_aff_free(Product);
198 isl_pw_aff_free(NextOperand);
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000199 return nullptr;
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000200 }
201
Tobias Grosser0695ee42013-09-17 03:30:31 +0000202 Product = isl_pw_aff_mul(Product, NextOperand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000203 }
204
Tobias Grosser0695ee42013-09-17 03:30:31 +0000205 // TODO: Check for NSW and NUW.
206 return Product;
207}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000208
Tobias Grosser0695ee42013-09-17 03:30:31 +0000209__isl_give isl_pw_aff *SCEVAffinator::visitUDivExpr(const SCEVUDivExpr *Expr) {
210 llvm_unreachable("SCEVUDivExpr not yet supported");
211}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000212
Tobias Grosser0695ee42013-09-17 03:30:31 +0000213__isl_give isl_pw_aff *
214SCEVAffinator::visitAddRecExpr(const SCEVAddRecExpr *Expr) {
215 assert(Expr->isAffine() && "Only affine AddRecurrences allowed");
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000216
Tobias Grosser0695ee42013-09-17 03:30:31 +0000217 // Directly generate isl_pw_aff for Expr if 'start' is zero.
218 if (Expr->getStart()->isZero()) {
219 assert(S->getRegion().contains(Expr->getLoop()) &&
220 "Scop does not contain the loop referenced in this AddRec");
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000221
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000222 isl_pw_aff *Start = visit(Expr->getStart());
Tobias Grosser0695ee42013-09-17 03:30:31 +0000223 isl_pw_aff *Step = visit(Expr->getOperand(1));
224 isl_space *Space = isl_space_set_alloc(Ctx, 0, NbLoopSpaces);
225 isl_local_space *LocalSpace = isl_local_space_from_space(Space);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000226
Tobias Grosser0695ee42013-09-17 03:30:31 +0000227 int loopDimension = getLoopDepth(Expr->getLoop());
228
229 isl_aff *LAff = isl_aff_set_coefficient_si(
230 isl_aff_zero_on_domain(LocalSpace), isl_dim_in, loopDimension, 1);
231 isl_pw_aff *LPwAff = isl_pw_aff_from_aff(LAff);
232
233 // TODO: Do we need to check for NSW and NUW?
234 return isl_pw_aff_add(Start, isl_pw_aff_mul(Step, LPwAff));
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000235 }
236
Tobias Grosser0695ee42013-09-17 03:30:31 +0000237 // Translate AddRecExpr from '{start, +, inc}' into 'start + {0, +, inc}'
238 // if 'start' is not zero.
239 ScalarEvolution &SE = *S->getSE();
240 const SCEV *ZeroStartExpr = SE.getAddRecExpr(
241 SE.getConstant(Expr->getStart()->getType(), 0),
242 Expr->getStepRecurrence(SE), Expr->getLoop(), SCEV::FlagAnyWrap);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000243
Tobias Grosser0695ee42013-09-17 03:30:31 +0000244 isl_pw_aff *ZeroStartResult = visit(ZeroStartExpr);
245 isl_pw_aff *Start = visit(Expr->getStart());
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000246
Tobias Grosser0695ee42013-09-17 03:30:31 +0000247 return isl_pw_aff_add(ZeroStartResult, Start);
248}
249
250__isl_give isl_pw_aff *SCEVAffinator::visitSMaxExpr(const SCEVSMaxExpr *Expr) {
251 isl_pw_aff *Max = visit(Expr->getOperand(0));
252
253 for (int i = 1, e = Expr->getNumOperands(); i < e; ++i) {
254 isl_pw_aff *NextOperand = visit(Expr->getOperand(i));
255 Max = isl_pw_aff_max(Max, NextOperand);
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000256 }
257
Tobias Grosser0695ee42013-09-17 03:30:31 +0000258 return Max;
259}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000260
Tobias Grosser0695ee42013-09-17 03:30:31 +0000261__isl_give isl_pw_aff *SCEVAffinator::visitUMaxExpr(const SCEVUMaxExpr *Expr) {
262 llvm_unreachable("SCEVUMaxExpr not yet supported");
263}
264
265__isl_give isl_pw_aff *SCEVAffinator::visitUnknown(const SCEVUnknown *Expr) {
Tobias Grosserf4daf342014-08-16 09:08:55 +0000266 llvm_unreachable("Unknowns are always parameters");
Tobias Grosser0695ee42013-09-17 03:30:31 +0000267}
268
269int SCEVAffinator::getLoopDepth(const Loop *L) {
270 Loop *outerLoop = S->getRegion().outermostLoopInRegion(const_cast<Loop *>(L));
271 assert(outerLoop && "Scop does not contain this loop");
272 return L->getLoopDepth() - outerLoop->getLoopDepth();
273}
Tobias Grosser33ba62ad2011-08-18 06:31:50 +0000274
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000275ScopArrayInfo::ScopArrayInfo(Value *BasePtr, Type *AccessType, isl_ctx *Ctx,
276 const SmallVector<const SCEV *, 4> &DimensionSizes)
277 : BasePtr(BasePtr), AccessType(AccessType), DimensionSizes(DimensionSizes) {
278 const std::string BasePtrName = getIslCompatibleName("MemRef_", BasePtr, "");
279 Id = isl_id_alloc(Ctx, BasePtrName.c_str(), this);
280}
281
282ScopArrayInfo::~ScopArrayInfo() { isl_id_free(Id); }
283
284isl_id *ScopArrayInfo::getBasePtrId() const { return isl_id_copy(Id); }
285
286void ScopArrayInfo::dump() const { print(errs()); }
287
288void ScopArrayInfo::print(raw_ostream &OS) const {
289 OS << "ScopArrayInfo:\n";
290 OS << " Base: " << *getBasePtr() << "\n";
291 OS << " Type: " << *getType() << "\n";
292 OS << " Dimension Sizes:\n";
293 for (unsigned u = 0; u < getNumberOfDimensions(); u++)
294 OS << " " << u << ") " << *DimensionSizes[u] << "\n";
295 OS << "\n";
296}
297
298const ScopArrayInfo *
299ScopArrayInfo::getFromAccessFunction(__isl_keep isl_pw_multi_aff *PMA) {
300 isl_id *Id = isl_pw_multi_aff_get_tuple_id(PMA, isl_dim_out);
301 assert(Id && "Output dimension didn't have an ID");
302 return getFromId(Id);
303}
304
305const ScopArrayInfo *ScopArrayInfo::getFromId(isl_id *Id) {
306 void *User = isl_id_get_user(Id);
307 const ScopArrayInfo *SAI = static_cast<ScopArrayInfo *>(User);
308 isl_id_free(Id);
309 return SAI;
310}
311
Johannes Doerfert32868bf2014-08-01 08:13:25 +0000312const std::string
313MemoryAccess::getReductionOperatorStr(MemoryAccess::ReductionType RT) {
314 switch (RT) {
315 case MemoryAccess::RT_NONE:
316 llvm_unreachable("Requested a reduction operator string for a memory "
317 "access which isn't a reduction");
318 case MemoryAccess::RT_ADD:
319 return "+";
320 case MemoryAccess::RT_MUL:
321 return "*";
322 case MemoryAccess::RT_BOR:
323 return "|";
324 case MemoryAccess::RT_BXOR:
325 return "^";
326 case MemoryAccess::RT_BAND:
327 return "&";
328 }
329 llvm_unreachable("Unknown reduction type");
330 return "";
331}
332
Johannes Doerfertf6183392014-07-01 20:52:51 +0000333/// @brief Return the reduction type for a given binary operator
334static MemoryAccess::ReductionType getReductionType(const BinaryOperator *BinOp,
335 const Instruction *Load) {
336 if (!BinOp)
337 return MemoryAccess::RT_NONE;
338 switch (BinOp->getOpcode()) {
339 case Instruction::FAdd:
340 if (!BinOp->hasUnsafeAlgebra())
341 return MemoryAccess::RT_NONE;
342 // Fall through
343 case Instruction::Add:
344 return MemoryAccess::RT_ADD;
345 case Instruction::Or:
346 return MemoryAccess::RT_BOR;
347 case Instruction::Xor:
348 return MemoryAccess::RT_BXOR;
349 case Instruction::And:
350 return MemoryAccess::RT_BAND;
351 case Instruction::FMul:
352 if (!BinOp->hasUnsafeAlgebra())
353 return MemoryAccess::RT_NONE;
354 // Fall through
355 case Instruction::Mul:
356 if (DisableMultiplicativeReductions)
357 return MemoryAccess::RT_NONE;
358 return MemoryAccess::RT_MUL;
359 default:
360 return MemoryAccess::RT_NONE;
361 }
362}
Tobias Grosser75805372011-04-29 06:27:02 +0000363//===----------------------------------------------------------------------===//
364
365MemoryAccess::~MemoryAccess() {
Tobias Grosser54a86e62011-08-18 06:31:46 +0000366 isl_map_free(AccessRelation);
Raghesh Aloor129e8672011-08-15 02:33:39 +0000367 isl_map_free(newAccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000368}
369
Johannes Doerfert8f7124c2014-09-12 11:00:49 +0000370static MemoryAccess::AccessType getMemoryAccessType(const IRAccess &Access) {
371 switch (Access.getType()) {
372 case IRAccess::READ:
373 return MemoryAccess::READ;
374 case IRAccess::MUST_WRITE:
375 return MemoryAccess::MUST_WRITE;
376 case IRAccess::MAY_WRITE:
377 return MemoryAccess::MAY_WRITE;
378 }
379 llvm_unreachable("Unknown IRAccess type!");
380}
381
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000382const ScopArrayInfo *MemoryAccess::getScopArrayInfo() const {
383 isl_id *ArrayId = getArrayId();
384 void *User = isl_id_get_user(ArrayId);
385 const ScopArrayInfo *SAI = static_cast<ScopArrayInfo *>(User);
386 isl_id_free(ArrayId);
387 return SAI;
388}
389
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000390isl_id *MemoryAccess::getArrayId() const {
391 return isl_map_get_tuple_id(AccessRelation, isl_dim_out);
392}
393
Johannes Doerferta99130f2014-10-13 12:58:03 +0000394isl_pw_multi_aff *
395MemoryAccess::applyScheduleToAccessRelation(isl_union_map *USchedule) const {
396 isl_map *Schedule, *ScheduledAccRel;
397 isl_union_set *UDomain;
398
399 UDomain = isl_union_set_from_set(getStatement()->getDomain());
400 USchedule = isl_union_map_intersect_domain(USchedule, UDomain);
401 Schedule = isl_map_from_union_map(USchedule);
402 ScheduledAccRel = isl_map_apply_domain(getAccessRelation(), Schedule);
403 return isl_pw_multi_aff_from_map(ScheduledAccRel);
404}
405
406isl_map *MemoryAccess::getOriginalAccessRelation() const {
Tobias Grosser5d453812011-10-06 00:04:11 +0000407 return isl_map_copy(AccessRelation);
408}
409
Johannes Doerferta99130f2014-10-13 12:58:03 +0000410std::string MemoryAccess::getOriginalAccessRelationStr() const {
Tobias Grosser5d453812011-10-06 00:04:11 +0000411 return stringFromIslObj(AccessRelation);
412}
413
Johannes Doerferta99130f2014-10-13 12:58:03 +0000414__isl_give isl_space *MemoryAccess::getOriginalAccessRelationSpace() const {
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000415 return isl_map_get_space(AccessRelation);
416}
417
Tobias Grosser5d453812011-10-06 00:04:11 +0000418isl_map *MemoryAccess::getNewAccessRelation() const {
419 return isl_map_copy(newAccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000420}
421
422isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
Tobias Grosser084d8f72012-05-29 09:29:44 +0000423 isl_space *Space = isl_space_set_alloc(Statement->getIslCtx(), 0, 1);
Tobias Grossered295662012-09-11 13:50:21 +0000424 Space = isl_space_align_params(Space, Statement->getDomainSpace());
Tobias Grosser75805372011-04-29 06:27:02 +0000425
Tobias Grosser084d8f72012-05-29 09:29:44 +0000426 return isl_basic_map_from_domain_and_range(
Tobias Grosserabfbe632013-02-05 12:09:06 +0000427 isl_basic_set_universe(Statement->getDomainSpace()),
428 isl_basic_set_universe(Space));
Tobias Grosser75805372011-04-29 06:27:02 +0000429}
430
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000431// Formalize no out-of-bound access assumption
432//
433// When delinearizing array accesses we optimistically assume that the
434// delinearized accesses do not access out of bound locations (the subscript
435// expression of each array evaluates for each statement instance that is
436// executed to a value that is larger than zero and strictly smaller than the
437// size of the corresponding dimension). The only exception is the outermost
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000438// dimension for which we do not need to assume any upper bound. At this point
439// we formalize this assumption to ensure that at code generation time the
440// relevant run-time checks can be generated.
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000441//
442// To find the set of constraints necessary to avoid out of bound accesses, we
443// first build the set of data locations that are not within array bounds. We
444// then apply the reverse access relation to obtain the set of iterations that
445// may contain invalid accesses and reduce this set of iterations to the ones
446// that are actually executed by intersecting them with the domain of the
447// statement. If we now project out all loop dimensions, we obtain a set of
448// parameters that may cause statement instances to be executed that may
449// possibly yield out of bound memory accesses. The complement of these
450// constraints is the set of constraints that needs to be assumed to ensure such
451// statement instances are never executed.
452void MemoryAccess::assumeNoOutOfBound(const IRAccess &Access) {
Johannes Doerferta99130f2014-10-13 12:58:03 +0000453 isl_space *Space = isl_space_range(getOriginalAccessRelationSpace());
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000454 isl_set *Outside = isl_set_empty(isl_space_copy(Space));
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000455 for (int i = 1, Size = Access.Subscripts.size(); i < Size; ++i) {
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000456 isl_local_space *LS = isl_local_space_from_space(isl_space_copy(Space));
457 isl_pw_aff *Var =
458 isl_pw_aff_var_on_domain(isl_local_space_copy(LS), isl_dim_set, i);
459 isl_pw_aff *Zero = isl_pw_aff_zero_on_domain(LS);
460
461 isl_set *DimOutside;
462
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000463 DimOutside = isl_pw_aff_lt_set(isl_pw_aff_copy(Var), Zero);
464 isl_pw_aff *SizeE = SCEVAffinator::getPwAff(Statement, Access.Sizes[i - 1]);
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000465
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000466 SizeE = isl_pw_aff_drop_dims(SizeE, isl_dim_in, 0,
467 Statement->getNumIterators());
468 SizeE = isl_pw_aff_add_dims(SizeE, isl_dim_in,
469 isl_space_dim(Space, isl_dim_set));
470 SizeE = isl_pw_aff_set_tuple_id(SizeE, isl_dim_in,
471 isl_space_get_tuple_id(Space, isl_dim_set));
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000472
Tobias Grosserf57d63f2014-08-03 21:07:30 +0000473 DimOutside = isl_set_union(DimOutside, isl_pw_aff_le_set(SizeE, Var));
Tobias Grosser5e6813d2014-07-02 17:47:48 +0000474
475 Outside = isl_set_union(Outside, DimOutside);
476 }
477
478 Outside = isl_set_apply(Outside, isl_map_reverse(getAccessRelation()));
479 Outside = isl_set_intersect(Outside, Statement->getDomain());
480 Outside = isl_set_params(Outside);
481 Outside = isl_set_complement(Outside);
482 Statement->getParent()->addAssumption(Outside);
483 isl_space_free(Space);
484}
485
Johannes Doerfert13c8cf22014-08-10 08:09:38 +0000486MemoryAccess::MemoryAccess(const IRAccess &Access, Instruction *AccInst,
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000487 ScopStmt *Statement, const ScopArrayInfo *SAI)
Johannes Doerfert4c7ce472014-10-08 10:11:33 +0000488 : AccType(getMemoryAccessType(Access)), Statement(Statement), Inst(AccInst),
Johannes Doerfert8f7124c2014-09-12 11:00:49 +0000489 newAccessRelation(nullptr) {
Tobias Grosser75805372011-04-29 06:27:02 +0000490
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000491 isl_ctx *Ctx = Statement->getIslCtx();
Tobias Grosser9759f852011-11-10 12:44:55 +0000492 BaseAddr = Access.getBase();
Johannes Doerfert79fc23f2014-07-24 23:48:02 +0000493 BaseName = getIslCompatibleName("MemRef_", getBaseAddr(), "");
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000494
495 isl_id *BaseAddrId = SAI->getBasePtrId();
Tobias Grosser5683df42011-11-09 22:34:34 +0000496
Tobias Grossera1879642011-12-20 10:43:14 +0000497 if (!Access.isAffine()) {
Tobias Grosser4f967492013-06-23 05:21:18 +0000498 // We overapproximate non-affine accesses with a possible access to the
499 // whole array. For read accesses it does not make a difference, if an
500 // access must or may happen. However, for write accesses it is important to
501 // differentiate between writes that must happen and writes that may happen.
Tobias Grosser04d6ae62013-06-23 06:04:54 +0000502 AccessRelation = isl_map_from_basic_map(createBasicAccessMap(Statement));
Johannes Doerfert5d83f092014-07-29 08:37:55 +0000503 AccessRelation =
504 isl_map_set_tuple_id(AccessRelation, isl_dim_out, BaseAddrId);
Tobias Grossera1879642011-12-20 10:43:14 +0000505 return;
506 }
507
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 {
Johannes Doerfert4c7ce472014-10-08 10:11:33 +0000562 switch (AccType) {
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";
Johannes Doerferta99130f2014-10-13 12:58:03 +0000574 OS.indent(16) << getOriginalAccessRelationStr() << ";\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);
Johannes Doerferta99130f2014-10-13 12:58:03 +0000627 isl_map *AccessRelation = getAccessRelation();
Sebastian Popa00a0292012-12-18 07:46:06 +0000628 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
Johannes Doerfert75bd66e2014-10-31 23:16:02 +0000720void ScopStmt::buildAccesses(TempScop &tempScop) {
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000721 for (const auto &AccessPair : *tempScop.getAccessFunctions(BB)) {
722 const IRAccess &Access = AccessPair.first;
723 Instruction *AccessInst = AccessPair.second;
724
Johannes Doerfert80ef1102014-11-07 08:31:31 +0000725 Type *AccessType = getAccessInstType(AccessInst)->getPointerTo();
726 const ScopArrayInfo *SAI = getParent()->getOrCreateScopArrayInfo(
727 Access.getBase(), AccessType, Access.Sizes);
728
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000729 MemAccs.push_back(new MemoryAccess(Access, AccessInst, this, SAI));
Tobias Grosserd6aafa72014-02-20 21:29:09 +0000730
731 // We do not track locations for scalar memory accesses at the moment.
732 //
733 // We do not have a use for this information at the moment. If we need this
734 // at some point, the "instruction -> access" mapping needs to be enhanced
735 // as a single instruction could then possibly perform multiple accesses.
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000736 if (!Access.isScalar()) {
737 assert(!InstructionToAccess.count(AccessInst) &&
Tobias Grosser3fc91542014-02-20 21:43:45 +0000738 "Unexpected 1-to-N mapping on instruction to access map!");
Johannes Doerfert1a28a892014-10-05 11:32:18 +0000739 InstructionToAccess[AccessInst] = MemAccs.back();
Tobias Grosserd6aafa72014-02-20 21:29:09 +0000740 }
Tobias Grosser75805372011-04-29 06:27:02 +0000741 }
742}
743
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000744void ScopStmt::realignParams() {
Johannes Doerfertf6752892014-06-13 18:01:45 +0000745 for (MemoryAccess *MA : *this)
746 MA->realignParams();
Tobias Grosser8cae72f2011-11-08 15:41:08 +0000747
748 Domain = isl_set_align_params(Domain, Parent.getParamSpace());
749 Scattering = isl_map_align_params(Scattering, Parent.getParamSpace());
750}
751
Tobias Grosser65b00582011-11-08 15:41:19 +0000752__isl_give isl_set *ScopStmt::buildConditionSet(const Comparison &Comp) {
Tobias Grossera601fbd2011-11-09 22:34:44 +0000753 isl_pw_aff *L = SCEVAffinator::getPwAff(this, Comp.getLHS());
754 isl_pw_aff *R = SCEVAffinator::getPwAff(this, Comp.getRHS());
Tobias Grosser75805372011-04-29 06:27:02 +0000755
Tobias Grosserd2795d02011-08-18 07:51:40 +0000756 switch (Comp.getPred()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000757 case ICmpInst::ICMP_EQ:
Tobias Grosser048c8792011-10-23 20:59:20 +0000758 return isl_pw_aff_eq_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000759 case ICmpInst::ICMP_NE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000760 return isl_pw_aff_ne_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000761 case ICmpInst::ICMP_SLT:
Tobias Grosser048c8792011-10-23 20:59:20 +0000762 return isl_pw_aff_lt_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000763 case ICmpInst::ICMP_SLE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000764 return isl_pw_aff_le_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000765 case ICmpInst::ICMP_SGT:
Tobias Grosser048c8792011-10-23 20:59:20 +0000766 return isl_pw_aff_gt_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000767 case ICmpInst::ICMP_SGE:
Tobias Grosser048c8792011-10-23 20:59:20 +0000768 return isl_pw_aff_ge_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000769 case ICmpInst::ICMP_ULT:
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000770 return isl_pw_aff_lt_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000771 case ICmpInst::ICMP_UGT:
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000772 return isl_pw_aff_gt_set(L, R);
Tobias Grosserd2795d02011-08-18 07:51:40 +0000773 case ICmpInst::ICMP_ULE:
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000774 return isl_pw_aff_le_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000775 case ICmpInst::ICMP_UGE:
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000776 return isl_pw_aff_ge_set(L, R);
Tobias Grosser75805372011-04-29 06:27:02 +0000777 default:
778 llvm_unreachable("Non integer predicate not supported");
779 }
Tobias Grosser75805372011-04-29 06:27:02 +0000780}
781
Tobias Grossere19661e2011-10-07 08:46:57 +0000782__isl_give isl_set *ScopStmt::addLoopBoundsToDomain(__isl_take isl_set *Domain,
Tobias Grosser60b54f12011-11-08 15:41:28 +0000783 TempScop &tempScop) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000784 isl_space *Space;
785 isl_local_space *LocalSpace;
Tobias Grosser75805372011-04-29 06:27:02 +0000786
Tobias Grossere19661e2011-10-07 08:46:57 +0000787 Space = isl_set_get_space(Domain);
788 LocalSpace = isl_local_space_from_space(Space);
Tobias Grosserf5338802011-10-06 00:03:35 +0000789
Johannes Doerfert5ad8a6a2014-11-01 01:14:56 +0000790 ScalarEvolution *SE = getParent()->getSE();
Tobias Grosser75805372011-04-29 06:27:02 +0000791 for (int i = 0, e = getNumIterators(); i != e; ++i) {
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000792 isl_aff *Zero = isl_aff_zero_on_domain(isl_local_space_copy(LocalSpace));
Tobias Grosserabfbe632013-02-05 12:09:06 +0000793 isl_pw_aff *IV =
794 isl_pw_aff_from_aff(isl_aff_set_coefficient_si(Zero, isl_dim_in, i, 1));
Tobias Grosser75805372011-04-29 06:27:02 +0000795
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000796 // 0 <= IV.
797 isl_set *LowerBound = isl_pw_aff_nonneg_set(isl_pw_aff_copy(IV));
798 Domain = isl_set_intersect(Domain, LowerBound);
799
800 // IV <= LatchExecutions.
Hongbin Zheng27f3afb2011-04-30 03:26:51 +0000801 const Loop *L = getLoopForDimension(i);
Johannes Doerfert5ad8a6a2014-11-01 01:14:56 +0000802 const SCEV *LatchExecutions = SE->getBackedgeTakenCount(L);
Tobias Grosser9b13d3d2011-10-06 22:32:58 +0000803 isl_pw_aff *UpperBound = SCEVAffinator::getPwAff(this, LatchExecutions);
804 isl_set *UpperBoundSet = isl_pw_aff_le_set(IV, UpperBound);
Tobias Grosser75805372011-04-29 06:27:02 +0000805 Domain = isl_set_intersect(Domain, UpperBoundSet);
806 }
807
Tobias Grosserf5338802011-10-06 00:03:35 +0000808 isl_local_space_free(LocalSpace);
Tobias Grossere19661e2011-10-07 08:46:57 +0000809 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000810}
811
Tobias Grossere602a072013-05-07 07:30:56 +0000812__isl_give isl_set *ScopStmt::addConditionsToDomain(__isl_take isl_set *Domain,
813 TempScop &tempScop,
814 const Region &CurRegion) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000815 const Region *TopRegion = tempScop.getMaxRegion().getParent(),
Tobias Grosserd7e58642013-04-10 06:55:45 +0000816 *CurrentRegion = &CurRegion;
Tobias Grossere19661e2011-10-07 08:46:57 +0000817 const BasicBlock *BranchingBB = BB;
Tobias Grosser75805372011-04-29 06:27:02 +0000818
Tobias Grosser75805372011-04-29 06:27:02 +0000819 do {
Tobias Grossere19661e2011-10-07 08:46:57 +0000820 if (BranchingBB != CurrentRegion->getEntry()) {
821 if (const BBCond *Condition = tempScop.getBBCond(BranchingBB))
Tobias Grosser083d3d32014-06-28 08:59:45 +0000822 for (const auto &C : *Condition) {
823 isl_set *ConditionSet = buildConditionSet(C);
Tobias Grossere19661e2011-10-07 08:46:57 +0000824 Domain = isl_set_intersect(Domain, ConditionSet);
Tobias Grosser75805372011-04-29 06:27:02 +0000825 }
826 }
Tobias Grossere19661e2011-10-07 08:46:57 +0000827 BranchingBB = CurrentRegion->getEntry();
828 CurrentRegion = CurrentRegion->getParent();
829 } while (TopRegion != CurrentRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000830
Tobias Grossere19661e2011-10-07 08:46:57 +0000831 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000832}
833
Tobias Grossere602a072013-05-07 07:30:56 +0000834__isl_give isl_set *ScopStmt::buildDomain(TempScop &tempScop,
835 const Region &CurRegion) {
Tobias Grossere19661e2011-10-07 08:46:57 +0000836 isl_space *Space;
837 isl_set *Domain;
Tobias Grosser084d8f72012-05-29 09:29:44 +0000838 isl_id *Id;
Tobias Grossere19661e2011-10-07 08:46:57 +0000839
840 Space = isl_space_set_alloc(getIslCtx(), 0, getNumIterators());
841
Tobias Grosser084d8f72012-05-29 09:29:44 +0000842 Id = isl_id_alloc(getIslCtx(), getBaseName(), this);
843
Tobias Grossere19661e2011-10-07 08:46:57 +0000844 Domain = isl_set_universe(Space);
Tobias Grossere19661e2011-10-07 08:46:57 +0000845 Domain = addLoopBoundsToDomain(Domain, tempScop);
846 Domain = addConditionsToDomain(Domain, tempScop, CurRegion);
Tobias Grosser084d8f72012-05-29 09:29:44 +0000847 Domain = isl_set_set_tuple_id(Domain, Id);
Tobias Grossere19661e2011-10-07 08:46:57 +0000848
849 return Domain;
Tobias Grosser75805372011-04-29 06:27:02 +0000850}
851
Tobias Grosser7b50bee2014-11-25 10:51:12 +0000852void ScopStmt::deriveAssumptionsFromGEP(GetElementPtrInst *GEP) {
853 int Dimension = 0;
854 isl_ctx *Ctx = Parent.getIslCtx();
855 isl_local_space *LSpace = isl_local_space_from_space(getDomainSpace());
856 Type *Ty = GEP->getPointerOperandType();
857 ScalarEvolution &SE = *Parent.getSE();
858
859 if (auto *PtrTy = dyn_cast<PointerType>(Ty)) {
860 Dimension = 1;
861 Ty = PtrTy->getElementType();
862 }
863
864 while (auto ArrayTy = dyn_cast<ArrayType>(Ty)) {
865 unsigned int Operand = 1 + Dimension;
866
867 if (GEP->getNumOperands() <= Operand)
868 break;
869
870 const SCEV *Expr = SE.getSCEV(GEP->getOperand(Operand));
871
872 if (isAffineExpr(&Parent.getRegion(), Expr, SE)) {
873 isl_pw_aff *AccessOffset = SCEVAffinator::getPwAff(this, Expr);
874 AccessOffset =
875 isl_pw_aff_set_tuple_id(AccessOffset, isl_dim_in, getDomainId());
876
877 isl_pw_aff *DimSize = isl_pw_aff_from_aff(isl_aff_val_on_domain(
878 isl_local_space_copy(LSpace),
879 isl_val_int_from_si(Ctx, ArrayTy->getNumElements())));
880
881 isl_set *OutOfBound = isl_pw_aff_ge_set(AccessOffset, DimSize);
882 OutOfBound = isl_set_intersect(getDomain(), OutOfBound);
883 OutOfBound = isl_set_params(OutOfBound);
884 isl_set *InBound = isl_set_complement(OutOfBound);
885 isl_set *Executed = isl_set_params(getDomain());
886
887 // A => B == !A or B
888 isl_set *InBoundIfExecuted =
889 isl_set_union(isl_set_complement(Executed), InBound);
890
891 Parent.addAssumption(InBoundIfExecuted);
892 }
893
894 Dimension += 1;
895 Ty = ArrayTy->getElementType();
896 }
897
898 isl_local_space_free(LSpace);
899}
900
901void ScopStmt::deriveAssumptions() {
902 for (Instruction &Inst : *BB)
903 if (auto *GEP = dyn_cast<GetElementPtrInst>(&Inst))
904 deriveAssumptionsFromGEP(GEP);
905}
906
Tobias Grosser74394f02013-01-14 22:40:23 +0000907ScopStmt::ScopStmt(Scop &parent, TempScop &tempScop, const Region &CurRegion,
Sebastian Pop860e0212013-02-15 21:26:44 +0000908 BasicBlock &bb, SmallVectorImpl<Loop *> &Nest,
Tobias Grosser75805372011-04-29 06:27:02 +0000909 SmallVectorImpl<unsigned> &Scatter)
Tobias Grosser683b8e42014-11-30 14:33:31 +0000910 : Parent(parent), BB(&bb), NestLoops(Nest.size()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000911 // Setup the induction variables.
Tobias Grosser683b8e42014-11-30 14:33:31 +0000912 for (unsigned i = 0, e = Nest.size(); i < e; ++i)
Sebastian Pop860e0212013-02-15 21:26:44 +0000913 NestLoops[i] = Nest[i];
Tobias Grosser75805372011-04-29 06:27:02 +0000914
Johannes Doerfert79fc23f2014-07-24 23:48:02 +0000915 BaseName = getIslCompatibleName("Stmt_", &bb, "");
Tobias Grosser75805372011-04-29 06:27:02 +0000916
Tobias Grossere19661e2011-10-07 08:46:57 +0000917 Domain = buildDomain(tempScop, CurRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000918 buildScattering(Scatter);
Johannes Doerfert75bd66e2014-10-31 23:16:02 +0000919 buildAccesses(tempScop);
Johannes Doerferte58a0122014-06-27 20:31:28 +0000920 checkForReductions();
Tobias Grosser7b50bee2014-11-25 10:51:12 +0000921 deriveAssumptions();
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000922}
923
Johannes Doerferte58a0122014-06-27 20:31:28 +0000924/// @brief Collect loads which might form a reduction chain with @p StoreMA
925///
926/// Check if the stored value for @p StoreMA is a binary operator with one or
927/// two loads as operands. If the binary operand is commutative & associative,
928/// used only once (by @p StoreMA) and its load operands are also used only
929/// once, we have found a possible reduction chain. It starts at an operand
930/// load and includes the binary operator and @p StoreMA.
931///
932/// Note: We allow only one use to ensure the load and binary operator cannot
933/// escape this block or into any other store except @p StoreMA.
934void ScopStmt::collectCandiateReductionLoads(
935 MemoryAccess *StoreMA, SmallVectorImpl<MemoryAccess *> &Loads) {
936 auto *Store = dyn_cast<StoreInst>(StoreMA->getAccessInstruction());
937 if (!Store)
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000938 return;
939
940 // Skip if there is not one binary operator between the load and the store
941 auto *BinOp = dyn_cast<BinaryOperator>(Store->getValueOperand());
Johannes Doerferte58a0122014-06-27 20:31:28 +0000942 if (!BinOp)
943 return;
944
945 // Skip if the binary operators has multiple uses
946 if (BinOp->getNumUses() != 1)
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000947 return;
948
949 // Skip if the opcode of the binary operator is not commutative/associative
950 if (!BinOp->isCommutative() || !BinOp->isAssociative())
951 return;
952
Johannes Doerfert9890a052014-07-01 00:32:29 +0000953 // Skip if the binary operator is outside the current SCoP
954 if (BinOp->getParent() != Store->getParent())
955 return;
956
Johannes Doerfert0ee1f212014-06-17 17:31:36 +0000957 // Skip if it is a multiplicative reduction and we disabled them
958 if (DisableMultiplicativeReductions &&
959 (BinOp->getOpcode() == Instruction::Mul ||
960 BinOp->getOpcode() == Instruction::FMul))
961 return;
962
Johannes Doerferte58a0122014-06-27 20:31:28 +0000963 // Check the binary operator operands for a candidate load
964 auto *PossibleLoad0 = dyn_cast<LoadInst>(BinOp->getOperand(0));
965 auto *PossibleLoad1 = dyn_cast<LoadInst>(BinOp->getOperand(1));
966 if (!PossibleLoad0 && !PossibleLoad1)
967 return;
968
969 // A load is only a candidate if it cannot escape (thus has only this use)
970 if (PossibleLoad0 && PossibleLoad0->getNumUses() == 1)
Johannes Doerfert9890a052014-07-01 00:32:29 +0000971 if (PossibleLoad0->getParent() == Store->getParent())
972 Loads.push_back(lookupAccessFor(PossibleLoad0));
Johannes Doerferte58a0122014-06-27 20:31:28 +0000973 if (PossibleLoad1 && PossibleLoad1->getNumUses() == 1)
Johannes Doerfert9890a052014-07-01 00:32:29 +0000974 if (PossibleLoad1->getParent() == Store->getParent())
975 Loads.push_back(lookupAccessFor(PossibleLoad1));
Johannes Doerferte58a0122014-06-27 20:31:28 +0000976}
977
978/// @brief Check for reductions in this ScopStmt
979///
980/// Iterate over all store memory accesses and check for valid binary reduction
981/// like chains. For all candidates we check if they have the same base address
982/// and there are no other accesses which overlap with them. The base address
983/// check rules out impossible reductions candidates early. The overlap check,
984/// together with the "only one user" check in collectCandiateReductionLoads,
985/// guarantees that none of the intermediate results will escape during
986/// execution of the loop nest. We basically check here that no other memory
987/// access can access the same memory as the potential reduction.
988void ScopStmt::checkForReductions() {
989 SmallVector<MemoryAccess *, 2> Loads;
990 SmallVector<std::pair<MemoryAccess *, MemoryAccess *>, 4> Candidates;
991
992 // First collect candidate load-store reduction chains by iterating over all
993 // stores and collecting possible reduction loads.
994 for (MemoryAccess *StoreMA : MemAccs) {
995 if (StoreMA->isRead())
996 continue;
997
998 Loads.clear();
999 collectCandiateReductionLoads(StoreMA, Loads);
1000 for (MemoryAccess *LoadMA : Loads)
1001 Candidates.push_back(std::make_pair(LoadMA, StoreMA));
1002 }
1003
1004 // Then check each possible candidate pair.
1005 for (const auto &CandidatePair : Candidates) {
1006 bool Valid = true;
1007 isl_map *LoadAccs = CandidatePair.first->getAccessRelation();
1008 isl_map *StoreAccs = CandidatePair.second->getAccessRelation();
1009
1010 // Skip those with obviously unequal base addresses.
1011 if (!isl_map_has_equal_space(LoadAccs, StoreAccs)) {
1012 isl_map_free(LoadAccs);
1013 isl_map_free(StoreAccs);
1014 continue;
1015 }
1016
1017 // And check if the remaining for overlap with other memory accesses.
1018 isl_map *AllAccsRel = isl_map_union(LoadAccs, StoreAccs);
1019 AllAccsRel = isl_map_intersect_domain(AllAccsRel, getDomain());
1020 isl_set *AllAccs = isl_map_range(AllAccsRel);
1021
1022 for (MemoryAccess *MA : MemAccs) {
1023 if (MA == CandidatePair.first || MA == CandidatePair.second)
1024 continue;
1025
1026 isl_map *AccRel =
1027 isl_map_intersect_domain(MA->getAccessRelation(), getDomain());
1028 isl_set *Accs = isl_map_range(AccRel);
1029
1030 if (isl_set_has_equal_space(AllAccs, Accs) || isl_set_free(Accs)) {
1031 isl_set *OverlapAccs = isl_set_intersect(Accs, isl_set_copy(AllAccs));
1032 Valid = Valid && isl_set_is_empty(OverlapAccs);
1033 isl_set_free(OverlapAccs);
1034 }
1035 }
1036
1037 isl_set_free(AllAccs);
1038 if (!Valid)
1039 continue;
1040
Johannes Doerfertf6183392014-07-01 20:52:51 +00001041 const LoadInst *Load =
1042 dyn_cast<const LoadInst>(CandidatePair.first->getAccessInstruction());
1043 MemoryAccess::ReductionType RT =
1044 getReductionType(dyn_cast<BinaryOperator>(Load->user_back()), Load);
1045
Johannes Doerferte58a0122014-06-27 20:31:28 +00001046 // If no overlapping access was found we mark the load and store as
1047 // reduction like.
Johannes Doerfertf6183392014-07-01 20:52:51 +00001048 CandidatePair.first->markAsReductionLike(RT);
1049 CandidatePair.second->markAsReductionLike(RT);
Johannes Doerferte58a0122014-06-27 20:31:28 +00001050 }
Tobias Grosser75805372011-04-29 06:27:02 +00001051}
1052
Tobias Grosser74394f02013-01-14 22:40:23 +00001053std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); }
Tobias Grosser75805372011-04-29 06:27:02 +00001054
1055std::string ScopStmt::getScatteringStr() const {
Tobias Grossercf3942d2011-10-06 00:04:05 +00001056 return stringFromIslObj(Scattering);
Tobias Grosser75805372011-04-29 06:27:02 +00001057}
1058
Tobias Grosser74394f02013-01-14 22:40:23 +00001059unsigned ScopStmt::getNumParams() const { return Parent.getNumParams(); }
Tobias Grosser75805372011-04-29 06:27:02 +00001060
1061unsigned ScopStmt::getNumIterators() const {
1062 // The final read has one dimension with one element.
1063 if (!BB)
1064 return 1;
1065
Sebastian Pop860e0212013-02-15 21:26:44 +00001066 return NestLoops.size();
Tobias Grosser75805372011-04-29 06:27:02 +00001067}
1068
1069unsigned ScopStmt::getNumScattering() const {
1070 return isl_map_dim(Scattering, isl_dim_out);
1071}
1072
1073const char *ScopStmt::getBaseName() const { return BaseName.c_str(); }
1074
Hongbin Zheng27f3afb2011-04-30 03:26:51 +00001075const Loop *ScopStmt::getLoopForDimension(unsigned Dimension) const {
Sebastian Pop860e0212013-02-15 21:26:44 +00001076 return NestLoops[Dimension];
Tobias Grosser75805372011-04-29 06:27:02 +00001077}
1078
Tobias Grosser74394f02013-01-14 22:40:23 +00001079isl_ctx *ScopStmt::getIslCtx() const { return Parent.getIslCtx(); }
Tobias Grosser75805372011-04-29 06:27:02 +00001080
Tobias Grosser74394f02013-01-14 22:40:23 +00001081isl_set *ScopStmt::getDomain() const { return isl_set_copy(Domain); }
Tobias Grosserd5a7bfc2011-05-06 19:52:19 +00001082
Tobias Grosser78d8a3d2012-01-17 20:34:23 +00001083isl_space *ScopStmt::getDomainSpace() const {
1084 return isl_set_get_space(Domain);
1085}
1086
Tobias Grosser74394f02013-01-14 22:40:23 +00001087isl_id *ScopStmt::getDomainId() const { return isl_set_get_tuple_id(Domain); }
Tobias Grossercd95b772012-08-30 11:49:38 +00001088
Tobias Grosser75805372011-04-29 06:27:02 +00001089ScopStmt::~ScopStmt() {
1090 while (!MemAccs.empty()) {
1091 delete MemAccs.back();
1092 MemAccs.pop_back();
1093 }
1094
1095 isl_set_free(Domain);
1096 isl_map_free(Scattering);
1097}
1098
1099void ScopStmt::print(raw_ostream &OS) const {
1100 OS << "\t" << getBaseName() << "\n";
Tobias Grosser75805372011-04-29 06:27:02 +00001101 OS.indent(12) << "Domain :=\n";
1102
1103 if (Domain) {
1104 OS.indent(16) << getDomainStr() << ";\n";
1105 } else
1106 OS.indent(16) << "n/a\n";
1107
1108 OS.indent(12) << "Scattering :=\n";
1109
1110 if (Domain) {
1111 OS.indent(16) << getScatteringStr() << ";\n";
1112 } else
1113 OS.indent(16) << "n/a\n";
1114
Tobias Grosser083d3d32014-06-28 08:59:45 +00001115 for (MemoryAccess *Access : MemAccs)
1116 Access->print(OS);
Tobias Grosser75805372011-04-29 06:27:02 +00001117}
1118
1119void ScopStmt::dump() const { print(dbgs()); }
1120
1121//===----------------------------------------------------------------------===//
1122/// Scop class implement
Tobias Grosser60b54f12011-11-08 15:41:28 +00001123
Tobias Grosser7ffe4e82011-11-17 12:56:10 +00001124void Scop::setContext(__isl_take isl_set *NewContext) {
Tobias Grosserff9b54d2011-11-15 11:38:44 +00001125 NewContext = isl_set_align_params(NewContext, isl_set_get_space(Context));
1126 isl_set_free(Context);
1127 Context = NewContext;
1128}
1129
Tobias Grosserabfbe632013-02-05 12:09:06 +00001130void Scop::addParams(std::vector<const SCEV *> NewParameters) {
Tobias Grosser083d3d32014-06-28 08:59:45 +00001131 for (const SCEV *Parameter : NewParameters) {
Tobias Grosser60b54f12011-11-08 15:41:28 +00001132 if (ParameterIds.find(Parameter) != ParameterIds.end())
1133 continue;
1134
1135 int dimension = Parameters.size();
1136
1137 Parameters.push_back(Parameter);
1138 ParameterIds[Parameter] = dimension;
1139 }
1140}
1141
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001142__isl_give isl_id *Scop::getIdForParam(const SCEV *Parameter) const {
1143 ParamIdType::const_iterator IdIter = ParameterIds.find(Parameter);
Tobias Grosser76c2e322011-11-07 12:58:59 +00001144
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001145 if (IdIter == ParameterIds.end())
Tobias Grosser5a56cbf2014-04-16 07:33:47 +00001146 return nullptr;
Tobias Grosser76c2e322011-11-07 12:58:59 +00001147
Tobias Grosser8f99c162011-11-15 11:38:55 +00001148 std::string ParameterName;
1149
1150 if (const SCEVUnknown *ValueParameter = dyn_cast<SCEVUnknown>(Parameter)) {
1151 Value *Val = ValueParameter->getValue();
Tobias Grosser29ee0b12011-11-17 14:52:36 +00001152 ParameterName = Val->getName();
Tobias Grosser8f99c162011-11-15 11:38:55 +00001153 }
1154
1155 if (ParameterName == "" || ParameterName.substr(0, 2) == "p_")
Hongbin Zheng86a37742012-04-25 08:01:38 +00001156 ParameterName = "p_" + utostr_32(IdIter->second);
Tobias Grosser8f99c162011-11-15 11:38:55 +00001157
Tobias Grosser20532b82014-04-11 17:56:49 +00001158 return isl_id_alloc(getIslCtx(), ParameterName.c_str(),
1159 const_cast<void *>((const void *)Parameter));
Tobias Grosser76c2e322011-11-07 12:58:59 +00001160}
Tobias Grosser75805372011-04-29 06:27:02 +00001161
Tobias Grosser6be480c2011-11-08 15:41:13 +00001162void Scop::buildContext() {
1163 isl_space *Space = isl_space_params_alloc(IslCtx, 0);
Tobias Grossere86109f2013-10-29 21:05:49 +00001164 Context = isl_set_universe(isl_space_copy(Space));
1165 AssumedContext = isl_set_universe(Space);
Tobias Grosser0e27e242011-10-06 00:03:48 +00001166}
1167
Tobias Grosser18daaca2012-05-22 10:47:27 +00001168void Scop::addParameterBounds() {
1169 for (unsigned i = 0; i < isl_set_dim(Context, isl_dim_param); ++i) {
Tobias Grosseredab1352013-06-21 06:41:31 +00001170 isl_val *V;
Tobias Grosser18daaca2012-05-22 10:47:27 +00001171 isl_id *Id;
1172 const SCEV *Scev;
1173 const IntegerType *T;
Tobias Grosser55bc4c02015-01-08 19:26:53 +00001174 int Width;
Tobias Grosser18daaca2012-05-22 10:47:27 +00001175
1176 Id = isl_set_get_dim_id(Context, isl_dim_param, i);
Tobias Grosserabfbe632013-02-05 12:09:06 +00001177 Scev = (const SCEV *)isl_id_get_user(Id);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001178 isl_id_free(Id);
1179
Tobias Grosser55bc4c02015-01-08 19:26:53 +00001180 T = dyn_cast<IntegerType>(Scev->getType());
1181
1182 if (!T)
1183 continue;
1184
1185 Width = T->getBitWidth();
Tobias Grosser18daaca2012-05-22 10:47:27 +00001186
Tobias Grosseredab1352013-06-21 06:41:31 +00001187 V = isl_val_int_from_si(IslCtx, Width - 1);
1188 V = isl_val_2exp(V);
1189 V = isl_val_neg(V);
1190 Context = isl_set_lower_bound_val(Context, isl_dim_param, i, V);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001191
Tobias Grosseredab1352013-06-21 06:41:31 +00001192 V = isl_val_int_from_si(IslCtx, Width - 1);
1193 V = isl_val_2exp(V);
1194 V = isl_val_sub_ui(V, 1);
1195 Context = isl_set_upper_bound_val(Context, isl_dim_param, i, V);
Tobias Grosser18daaca2012-05-22 10:47:27 +00001196 }
1197}
1198
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001199void Scop::realignParams() {
Tobias Grosser6be480c2011-11-08 15:41:13 +00001200 // Add all parameters into a common model.
Tobias Grosser60b54f12011-11-08 15:41:28 +00001201 isl_space *Space = isl_space_params_alloc(IslCtx, ParameterIds.size());
Tobias Grosser6be480c2011-11-08 15:41:13 +00001202
Tobias Grosser083d3d32014-06-28 08:59:45 +00001203 for (const auto &ParamID : ParameterIds) {
1204 const SCEV *Parameter = ParamID.first;
Tobias Grosser6be480c2011-11-08 15:41:13 +00001205 isl_id *id = getIdForParam(Parameter);
Tobias Grosser083d3d32014-06-28 08:59:45 +00001206 Space = isl_space_set_dim_id(Space, isl_dim_param, ParamID.second, id);
Tobias Grosser6be480c2011-11-08 15:41:13 +00001207 }
1208
1209 // Align the parameters of all data structures to the model.
1210 Context = isl_set_align_params(Context, Space);
1211
Tobias Grosser083d3d32014-06-28 08:59:45 +00001212 for (ScopStmt *Stmt : *this)
1213 Stmt->realignParams();
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001214}
1215
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001216void Scop::simplifyAssumedContext() {
1217 // The parameter constraints of the iteration domains give us a set of
1218 // constraints that need to hold for all cases where at least a single
1219 // statement iteration is executed in the whole scop. We now simplify the
1220 // assumed context under the assumption that such constraints hold and at
1221 // least a single statement iteration is executed. For cases where no
1222 // statement instances are executed, the assumptions we have taken about
1223 // the executed code do not matter and can be changed.
1224 //
1225 // WARNING: This only holds if the assumptions we have taken do not reduce
1226 // the set of statement instances that are executed. Otherwise we
1227 // may run into a case where the iteration domains suggest that
1228 // for a certain set of parameter constraints no code is executed,
1229 // but in the original program some computation would have been
1230 // performed. In such a case, modifying the run-time conditions and
1231 // possibly influencing the run-time check may cause certain scops
1232 // to not be executed.
1233 //
1234 // Example:
1235 //
1236 // When delinearizing the following code:
1237 //
1238 // for (long i = 0; i < 100; i++)
1239 // for (long j = 0; j < m; j++)
1240 // A[i+p][j] = 1.0;
1241 //
1242 // we assume that the condition m <= 0 or (m >= 1 and p >= 0) holds as
1243 // otherwise we would access out of bound data. Now, knowing that code is
1244 // only executed for the case m >= 0, it is sufficient to assume p >= 0.
1245 AssumedContext =
1246 isl_set_gist_params(AssumedContext, isl_union_set_params(getDomains()));
1247}
1248
Johannes Doerfertb164c792014-09-18 11:17:17 +00001249/// @brief Add the minimal/maximal access in @p Set to @p User.
1250static int buildMinMaxAccess(__isl_take isl_set *Set, void *User) {
1251 Scop::MinMaxVectorTy *MinMaxAccesses = (Scop::MinMaxVectorTy *)User;
1252 isl_pw_multi_aff *MinPMA, *MaxPMA;
1253 isl_pw_aff *LastDimAff;
1254 isl_aff *OneAff;
1255 unsigned Pos;
1256
Johannes Doerfert9143d672014-09-27 11:02:39 +00001257 // Restrict the number of parameters involved in the access as the lexmin/
1258 // lexmax computation will take too long if this number is high.
1259 //
1260 // Experiments with a simple test case using an i7 4800MQ:
1261 //
1262 // #Parameters involved | Time (in sec)
1263 // 6 | 0.01
1264 // 7 | 0.04
1265 // 8 | 0.12
1266 // 9 | 0.40
1267 // 10 | 1.54
1268 // 11 | 6.78
1269 // 12 | 30.38
1270 //
1271 if (isl_set_n_param(Set) > RunTimeChecksMaxParameters) {
1272 unsigned InvolvedParams = 0;
1273 for (unsigned u = 0, e = isl_set_n_param(Set); u < e; u++)
1274 if (isl_set_involves_dims(Set, isl_dim_param, u, 1))
1275 InvolvedParams++;
1276
1277 if (InvolvedParams > RunTimeChecksMaxParameters) {
1278 isl_set_free(Set);
1279 return -1;
1280 }
1281 }
1282
Johannes Doerfertb164c792014-09-18 11:17:17 +00001283 MinPMA = isl_set_lexmin_pw_multi_aff(isl_set_copy(Set));
1284 MaxPMA = isl_set_lexmax_pw_multi_aff(isl_set_copy(Set));
1285
Johannes Doerfert219b20e2014-10-07 14:37:59 +00001286 MinPMA = isl_pw_multi_aff_coalesce(MinPMA);
1287 MaxPMA = isl_pw_multi_aff_coalesce(MaxPMA);
1288
Johannes Doerfertb164c792014-09-18 11:17:17 +00001289 // Adjust the last dimension of the maximal access by one as we want to
1290 // enclose the accessed memory region by MinPMA and MaxPMA. The pointer
1291 // we test during code generation might now point after the end of the
1292 // allocated array but we will never dereference it anyway.
1293 assert(isl_pw_multi_aff_dim(MaxPMA, isl_dim_out) &&
1294 "Assumed at least one output dimension");
1295 Pos = isl_pw_multi_aff_dim(MaxPMA, isl_dim_out) - 1;
1296 LastDimAff = isl_pw_multi_aff_get_pw_aff(MaxPMA, Pos);
1297 OneAff = isl_aff_zero_on_domain(
1298 isl_local_space_from_space(isl_pw_aff_get_domain_space(LastDimAff)));
1299 OneAff = isl_aff_add_constant_si(OneAff, 1);
1300 LastDimAff = isl_pw_aff_add(LastDimAff, isl_pw_aff_from_aff(OneAff));
1301 MaxPMA = isl_pw_multi_aff_set_pw_aff(MaxPMA, Pos, LastDimAff);
1302
1303 MinMaxAccesses->push_back(std::make_pair(MinPMA, MaxPMA));
1304
1305 isl_set_free(Set);
1306 return 0;
1307}
1308
Johannes Doerferteeab05a2014-10-01 12:42:37 +00001309static __isl_give isl_set *getAccessDomain(MemoryAccess *MA) {
1310 isl_set *Domain = MA->getStatement()->getDomain();
1311 Domain = isl_set_project_out(Domain, isl_dim_set, 0, isl_set_n_dim(Domain));
1312 return isl_set_reset_tuple_id(Domain);
1313}
1314
Johannes Doerfert9143d672014-09-27 11:02:39 +00001315bool Scop::buildAliasGroups(AliasAnalysis &AA) {
Johannes Doerfertb164c792014-09-18 11:17:17 +00001316 // To create sound alias checks we perform the following steps:
1317 // o) Use the alias analysis and an alias set tracker to build alias sets
1318 // for all memory accesses inside the SCoP.
1319 // o) For each alias set we then map the aliasing pointers back to the
1320 // memory accesses we know, thus obtain groups of memory accesses which
1321 // might alias.
Johannes Doerferteeab05a2014-10-01 12:42:37 +00001322 // o) We divide each group based on the domains of the minimal/maximal
1323 // accesses. That means two minimal/maximal accesses are only in a group
1324 // if their access domains intersect, otherwise they are in different
1325 // ones.
Johannes Doerfert13771732014-10-01 12:40:46 +00001326 // o) We split groups such that they contain at most one read only base
1327 // address.
1328 // o) For each group with more than one base pointer we then compute minimal
Johannes Doerfertb164c792014-09-18 11:17:17 +00001329 // and maximal accesses to each array in this group.
1330 using AliasGroupTy = SmallVector<MemoryAccess *, 4>;
1331
1332 AliasSetTracker AST(AA);
1333
1334 DenseMap<Value *, MemoryAccess *> PtrToAcc;
Johannes Doerfert13771732014-10-01 12:40:46 +00001335 DenseSet<Value *> HasWriteAccess;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001336 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf1ee2622014-10-06 17:43:00 +00001337
1338 // Skip statements with an empty domain as they will never be executed.
1339 isl_set *StmtDomain = Stmt->getDomain();
1340 bool StmtDomainEmpty = isl_set_is_empty(StmtDomain);
1341 isl_set_free(StmtDomain);
1342 if (StmtDomainEmpty)
1343 continue;
1344
Johannes Doerfertb164c792014-09-18 11:17:17 +00001345 for (MemoryAccess *MA : *Stmt) {
1346 if (MA->isScalar())
1347 continue;
Johannes Doerfert13771732014-10-01 12:40:46 +00001348 if (!MA->isRead())
1349 HasWriteAccess.insert(MA->getBaseAddr());
Johannes Doerfertb164c792014-09-18 11:17:17 +00001350 Instruction *Acc = MA->getAccessInstruction();
1351 PtrToAcc[getPointerOperand(*Acc)] = MA;
1352 AST.add(Acc);
1353 }
1354 }
1355
1356 SmallVector<AliasGroupTy, 4> AliasGroups;
1357 for (AliasSet &AS : AST) {
Johannes Doerfert74f68692014-10-08 02:23:48 +00001358 if (AS.isMustAlias() || AS.isForwardingAliasSet())
Johannes Doerfertb164c792014-09-18 11:17:17 +00001359 continue;
1360 AliasGroupTy AG;
1361 for (auto PR : AS)
1362 AG.push_back(PtrToAcc[PR.getValue()]);
1363 assert(AG.size() > 1 &&
1364 "Alias groups should contain at least two accesses");
1365 AliasGroups.push_back(std::move(AG));
1366 }
1367
Johannes Doerferteeab05a2014-10-01 12:42:37 +00001368 // Split the alias groups based on their domain.
1369 for (unsigned u = 0; u < AliasGroups.size(); u++) {
1370 AliasGroupTy NewAG;
1371 AliasGroupTy &AG = AliasGroups[u];
1372 AliasGroupTy::iterator AGI = AG.begin();
1373 isl_set *AGDomain = getAccessDomain(*AGI);
1374 while (AGI != AG.end()) {
1375 MemoryAccess *MA = *AGI;
1376 isl_set *MADomain = getAccessDomain(MA);
1377 if (isl_set_is_disjoint(AGDomain, MADomain)) {
1378 NewAG.push_back(MA);
1379 AGI = AG.erase(AGI);
1380 isl_set_free(MADomain);
1381 } else {
1382 AGDomain = isl_set_union(AGDomain, MADomain);
1383 AGI++;
1384 }
1385 }
1386 if (NewAG.size() > 1)
1387 AliasGroups.push_back(std::move(NewAG));
1388 isl_set_free(AGDomain);
1389 }
1390
Johannes Doerfert13771732014-10-01 12:40:46 +00001391 DenseMap<const Value *, SmallPtrSet<MemoryAccess *, 8>> ReadOnlyPairs;
1392 SmallPtrSet<const Value *, 4> NonReadOnlyBaseValues;
1393 for (AliasGroupTy &AG : AliasGroups) {
1394 NonReadOnlyBaseValues.clear();
1395 ReadOnlyPairs.clear();
1396
Johannes Doerferteeab05a2014-10-01 12:42:37 +00001397 if (AG.size() < 2) {
1398 AG.clear();
1399 continue;
1400 }
1401
Johannes Doerfert13771732014-10-01 12:40:46 +00001402 for (auto II = AG.begin(); II != AG.end();) {
1403 Value *BaseAddr = (*II)->getBaseAddr();
1404 if (HasWriteAccess.count(BaseAddr)) {
1405 NonReadOnlyBaseValues.insert(BaseAddr);
1406 II++;
1407 } else {
1408 ReadOnlyPairs[BaseAddr].insert(*II);
1409 II = AG.erase(II);
1410 }
1411 }
1412
1413 // If we don't have read only pointers check if there are at least two
1414 // non read only pointers, otherwise clear the alias group.
1415 if (ReadOnlyPairs.empty()) {
1416 if (NonReadOnlyBaseValues.size() <= 1)
1417 AG.clear();
1418 continue;
1419 }
1420
1421 // If we don't have non read only pointers clear the alias group.
1422 if (NonReadOnlyBaseValues.empty()) {
1423 AG.clear();
1424 continue;
1425 }
1426
1427 // If we have both read only and non read only base pointers we combine
1428 // the non read only ones with exactly one read only one at a time into a
1429 // new alias group and clear the old alias group in the end.
1430 for (const auto &ReadOnlyPair : ReadOnlyPairs) {
1431 AliasGroupTy AGNonReadOnly = AG;
1432 for (MemoryAccess *MA : ReadOnlyPair.second)
1433 AGNonReadOnly.push_back(MA);
1434 AliasGroups.push_back(std::move(AGNonReadOnly));
1435 }
1436 AG.clear();
Johannes Doerfertb164c792014-09-18 11:17:17 +00001437 }
1438
Johannes Doerfert9143d672014-09-27 11:02:39 +00001439 bool Valid = true;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001440 for (AliasGroupTy &AG : AliasGroups) {
Johannes Doerfert13771732014-10-01 12:40:46 +00001441 if (AG.empty())
1442 continue;
1443
Johannes Doerfertb164c792014-09-18 11:17:17 +00001444 MinMaxVectorTy *MinMaxAccesses = new MinMaxVectorTy();
1445 MinMaxAccesses->reserve(AG.size());
1446
1447 isl_union_map *Accesses = isl_union_map_empty(getParamSpace());
1448 for (MemoryAccess *MA : AG)
1449 Accesses = isl_union_map_add_map(Accesses, MA->getAccessRelation());
1450 Accesses = isl_union_map_intersect_domain(Accesses, getDomains());
1451
1452 isl_union_set *Locations = isl_union_map_range(Accesses);
1453 Locations = isl_union_set_intersect_params(Locations, getAssumedContext());
1454 Locations = isl_union_set_coalesce(Locations);
1455 Locations = isl_union_set_detect_equalities(Locations);
Johannes Doerfert9143d672014-09-27 11:02:39 +00001456 Valid = (0 == isl_union_set_foreach_set(Locations, buildMinMaxAccess,
1457 MinMaxAccesses));
Johannes Doerfertb164c792014-09-18 11:17:17 +00001458 isl_union_set_free(Locations);
Johannes Doerfertb164c792014-09-18 11:17:17 +00001459 MinMaxAliasGroups.push_back(MinMaxAccesses);
Johannes Doerfert9143d672014-09-27 11:02:39 +00001460
1461 if (!Valid)
1462 break;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001463 }
Johannes Doerfert9143d672014-09-27 11:02:39 +00001464
1465 return Valid;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001466}
1467
Johannes Doerferte3da05a2014-11-01 00:12:13 +00001468static unsigned getMaxLoopDepthInRegion(const Region &R, LoopInfo &LI) {
1469 unsigned MinLD = INT_MAX, MaxLD = 0;
1470 for (BasicBlock *BB : R.blocks()) {
1471 if (Loop *L = LI.getLoopFor(BB)) {
David Peixottodc0a11c2015-01-13 18:31:55 +00001472 if (!R.contains(L))
1473 continue;
Johannes Doerferte3da05a2014-11-01 00:12:13 +00001474 unsigned LD = L->getLoopDepth();
1475 MinLD = std::min(MinLD, LD);
1476 MaxLD = std::max(MaxLD, LD);
1477 }
1478 }
1479
1480 // Handle the case that there is no loop in the SCoP first.
1481 if (MaxLD == 0)
1482 return 1;
1483
1484 assert(MinLD >= 1 && "Minimal loop depth should be at least one");
1485 assert(MaxLD >= MinLD &&
1486 "Maximal loop depth was smaller than mininaml loop depth?");
1487 return MaxLD - MinLD + 1;
1488}
1489
Tobias Grosser3f296192015-01-01 23:01:11 +00001490void Scop::dropConstantScheduleDims() {
1491 isl_union_map *FullSchedule = getSchedule();
1492
1493 if (isl_union_map_n_map(FullSchedule) == 0) {
1494 isl_union_map_free(FullSchedule);
1495 return;
1496 }
1497
1498 isl_set *ScheduleSpace =
1499 isl_set_from_union_set(isl_union_map_range(FullSchedule));
1500 isl_map *DropDimMap = isl_set_identity(isl_set_copy(ScheduleSpace));
1501
1502 int NumDimsDropped = 0;
1503 for (unsigned i = 0; i < isl_set_dim(ScheduleSpace, isl_dim_set); i++)
1504 if (i % 2 == 0) {
1505 isl_val *FixedVal =
1506 isl_set_plain_get_val_if_fixed(ScheduleSpace, isl_dim_set, i);
1507 if (isl_val_is_int(FixedVal)) {
1508 DropDimMap =
1509 isl_map_project_out(DropDimMap, isl_dim_out, i - NumDimsDropped, 1);
1510 NumDimsDropped++;
1511 }
1512 isl_val_free(FixedVal);
1513 }
1514
1515 DropDimMap = isl_map_set_tuple_id(
1516 DropDimMap, isl_dim_out, isl_map_get_tuple_id(DropDimMap, isl_dim_in));
1517 for (auto *S : *this) {
1518 isl_map *Schedule = S->getScattering();
1519 Schedule = isl_map_apply_range(Schedule, isl_map_copy(DropDimMap));
1520 S->setScattering(Schedule);
1521 }
1522 isl_set_free(ScheduleSpace);
1523 isl_map_free(DropDimMap);
1524}
1525
Tobias Grosser0e27e242011-10-06 00:03:48 +00001526Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
1527 isl_ctx *Context)
Tobias Grosserabfbe632013-02-05 12:09:06 +00001528 : SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
Johannes Doerferte3da05a2014-11-01 00:12:13 +00001529 MaxLoopDepth(getMaxLoopDepthInRegion(tempScop.getMaxRegion(), LI)) {
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001530 IslCtx = Context;
Tobias Grosser6be480c2011-11-08 15:41:13 +00001531 buildContext();
Tobias Grosser75805372011-04-29 06:27:02 +00001532
Tobias Grosserabfbe632013-02-05 12:09:06 +00001533 SmallVector<Loop *, 8> NestLoops;
Tobias Grosser75805372011-04-29 06:27:02 +00001534 SmallVector<unsigned, 8> Scatter;
1535
1536 Scatter.assign(MaxLoopDepth + 1, 0);
1537
1538 // Build the iteration domain, access functions and scattering functions
1539 // traversing the region tree.
1540 buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
Tobias Grosser75805372011-04-29 06:27:02 +00001541
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001542 realignParams();
Tobias Grosser18daaca2012-05-22 10:47:27 +00001543 addParameterBounds();
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001544 simplifyAssumedContext();
Tobias Grosser3f296192015-01-01 23:01:11 +00001545 dropConstantScheduleDims();
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001546
Tobias Grosser75805372011-04-29 06:27:02 +00001547 assert(NestLoops.empty() && "NestLoops not empty at top level!");
1548}
1549
1550Scop::~Scop() {
1551 isl_set_free(Context);
Tobias Grossere86109f2013-10-29 21:05:49 +00001552 isl_set_free(AssumedContext);
Tobias Grosser75805372011-04-29 06:27:02 +00001553
1554 // Free the statements;
Tobias Grosser083d3d32014-06-28 08:59:45 +00001555 for (ScopStmt *Stmt : *this)
1556 delete Stmt;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001557
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001558 // Free the ScopArrayInfo objects.
1559 for (auto &ScopArrayInfoPair : ScopArrayInfoMap)
1560 delete ScopArrayInfoPair.second;
1561
Johannes Doerfertb164c792014-09-18 11:17:17 +00001562 // Free the alias groups
1563 for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) {
1564 for (MinMaxAccessTy &MMA : *MinMaxAccesses) {
1565 isl_pw_multi_aff_free(MMA.first);
1566 isl_pw_multi_aff_free(MMA.second);
1567 }
1568 delete MinMaxAccesses;
1569 }
Tobias Grosser75805372011-04-29 06:27:02 +00001570}
1571
Johannes Doerfert80ef1102014-11-07 08:31:31 +00001572const ScopArrayInfo *
1573Scop::getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType,
1574 const SmallVector<const SCEV *, 4> &Sizes) {
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001575 const ScopArrayInfo *&SAI = ScopArrayInfoMap[BasePtr];
Johannes Doerfert80ef1102014-11-07 08:31:31 +00001576 if (!SAI)
1577 SAI = new ScopArrayInfo(BasePtr, AccessType, getIslCtx(), Sizes);
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001578 return SAI;
1579}
1580
1581const ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr) {
1582 const SCEV *PtrSCEV = SE->getSCEV(BasePtr);
1583 const SCEVUnknown *PtrBaseSCEV =
1584 cast<SCEVUnknown>(SE->getPointerBase(PtrSCEV));
1585 const ScopArrayInfo *SAI = ScopArrayInfoMap[PtrBaseSCEV->getValue()];
1586 assert(SAI && "No ScopArrayInfo available for this base pointer");
1587 return SAI;
1588}
1589
Tobias Grosser74394f02013-01-14 22:40:23 +00001590std::string Scop::getContextStr() const { return stringFromIslObj(Context); }
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001591std::string Scop::getAssumedContextStr() const {
1592 return stringFromIslObj(AssumedContext);
1593}
Tobias Grosser75805372011-04-29 06:27:02 +00001594
1595std::string Scop::getNameStr() const {
1596 std::string ExitName, EntryName;
1597 raw_string_ostream ExitStr(ExitName);
1598 raw_string_ostream EntryStr(EntryName);
1599
Tobias Grosserf240b482014-01-09 10:42:15 +00001600 R.getEntry()->printAsOperand(EntryStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001601 EntryStr.str();
1602
1603 if (R.getExit()) {
Tobias Grosserf240b482014-01-09 10:42:15 +00001604 R.getExit()->printAsOperand(ExitStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001605 ExitStr.str();
1606 } else
1607 ExitName = "FunctionExit";
1608
1609 return EntryName + "---" + ExitName;
1610}
1611
Tobias Grosser74394f02013-01-14 22:40:23 +00001612__isl_give isl_set *Scop::getContext() const { return isl_set_copy(Context); }
Tobias Grosser37487052011-10-06 00:03:42 +00001613__isl_give isl_space *Scop::getParamSpace() const {
1614 return isl_set_get_space(this->Context);
1615}
1616
Tobias Grossere86109f2013-10-29 21:05:49 +00001617__isl_give isl_set *Scop::getAssumedContext() const {
1618 return isl_set_copy(AssumedContext);
1619}
1620
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001621void Scop::addAssumption(__isl_take isl_set *Set) {
1622 AssumedContext = isl_set_intersect(AssumedContext, Set);
Tobias Grosser7b50bee2014-11-25 10:51:12 +00001623 AssumedContext = isl_set_coalesce(AssumedContext);
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001624}
1625
Tobias Grosser75805372011-04-29 06:27:02 +00001626void Scop::printContext(raw_ostream &OS) const {
1627 OS << "Context:\n";
1628
1629 if (!Context) {
1630 OS.indent(4) << "n/a\n\n";
1631 return;
1632 }
1633
1634 OS.indent(4) << getContextStr() << "\n";
Tobias Grosser60b54f12011-11-08 15:41:28 +00001635
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001636 OS.indent(4) << "Assumed Context:\n";
1637 if (!AssumedContext) {
1638 OS.indent(4) << "n/a\n\n";
1639 return;
1640 }
1641
1642 OS.indent(4) << getAssumedContextStr() << "\n";
1643
Tobias Grosser083d3d32014-06-28 08:59:45 +00001644 for (const SCEV *Parameter : Parameters) {
Tobias Grosser60b54f12011-11-08 15:41:28 +00001645 int Dim = ParameterIds.find(Parameter)->second;
Tobias Grosser60b54f12011-11-08 15:41:28 +00001646 OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
1647 }
Tobias Grosser75805372011-04-29 06:27:02 +00001648}
1649
Johannes Doerfertb164c792014-09-18 11:17:17 +00001650void Scop::printAliasAssumptions(raw_ostream &OS) const {
1651 OS.indent(4) << "Alias Groups (" << MinMaxAliasGroups.size() << "):\n";
1652 if (MinMaxAliasGroups.empty()) {
1653 OS.indent(8) << "n/a\n";
1654 return;
1655 }
1656 for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) {
1657 OS.indent(8) << "[[";
1658 for (MinMaxAccessTy &MinMacAccess : *MinMaxAccesses)
1659 OS << " <" << MinMacAccess.first << ", " << MinMacAccess.second << ">";
1660 OS << " ]]\n";
1661 }
1662}
1663
Tobias Grosser75805372011-04-29 06:27:02 +00001664void Scop::printStatements(raw_ostream &OS) const {
1665 OS << "Statements {\n";
1666
Tobias Grosser083d3d32014-06-28 08:59:45 +00001667 for (ScopStmt *Stmt : *this)
1668 OS.indent(4) << *Stmt;
Tobias Grosser75805372011-04-29 06:27:02 +00001669
1670 OS.indent(4) << "}\n";
1671}
1672
Tobias Grosser75805372011-04-29 06:27:02 +00001673void Scop::print(raw_ostream &OS) const {
Tobias Grosser4eb7ddb2014-03-18 18:51:11 +00001674 OS.indent(4) << "Function: " << getRegion().getEntry()->getParent()->getName()
1675 << "\n";
Tobias Grosser483fdd42014-03-18 18:05:38 +00001676 OS.indent(4) << "Region: " << getNameStr() << "\n";
David Peixottodc0a11c2015-01-13 18:31:55 +00001677 OS.indent(4) << "Max Loop Depth: " << getMaxLoopDepth() << "\n";
Tobias Grosser75805372011-04-29 06:27:02 +00001678 printContext(OS.indent(4));
Johannes Doerfertb164c792014-09-18 11:17:17 +00001679 printAliasAssumptions(OS);
Tobias Grosser75805372011-04-29 06:27:02 +00001680 printStatements(OS.indent(4));
1681}
1682
1683void Scop::dump() const { print(dbgs()); }
1684
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001685isl_ctx *Scop::getIslCtx() const { return IslCtx; }
Tobias Grosser75805372011-04-29 06:27:02 +00001686
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001687__isl_give isl_union_set *Scop::getDomains() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001688 isl_union_set *Domain = isl_union_set_empty(getParamSpace());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001689
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001690 for (ScopStmt *Stmt : *this)
1691 Domain = isl_union_set_add_set(Domain, Stmt->getDomain());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001692
1693 return Domain;
1694}
1695
Tobias Grosser780ce0f2014-07-11 07:12:10 +00001696__isl_give isl_union_map *Scop::getMustWrites() {
1697 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1698
1699 for (ScopStmt *Stmt : *this) {
1700 for (MemoryAccess *MA : *Stmt) {
1701 if (!MA->isMustWrite())
1702 continue;
1703
1704 isl_set *Domain = Stmt->getDomain();
1705 isl_map *AccessDomain = MA->getAccessRelation();
1706 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1707 Write = isl_union_map_add_map(Write, AccessDomain);
1708 }
1709 }
1710 return isl_union_map_coalesce(Write);
1711}
1712
1713__isl_give isl_union_map *Scop::getMayWrites() {
1714 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1715
1716 for (ScopStmt *Stmt : *this) {
1717 for (MemoryAccess *MA : *Stmt) {
1718 if (!MA->isMayWrite())
1719 continue;
1720
1721 isl_set *Domain = Stmt->getDomain();
1722 isl_map *AccessDomain = MA->getAccessRelation();
1723 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1724 Write = isl_union_map_add_map(Write, AccessDomain);
1725 }
1726 }
1727 return isl_union_map_coalesce(Write);
1728}
1729
Tobias Grosser37eb4222014-02-20 21:43:54 +00001730__isl_give isl_union_map *Scop::getWrites() {
1731 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1732
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001733 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001734 for (MemoryAccess *MA : *Stmt) {
1735 if (!MA->isWrite())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001736 continue;
1737
1738 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001739 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001740 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1741 Write = isl_union_map_add_map(Write, AccessDomain);
1742 }
1743 }
1744 return isl_union_map_coalesce(Write);
1745}
1746
1747__isl_give isl_union_map *Scop::getReads() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001748 isl_union_map *Read = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001749
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001750 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001751 for (MemoryAccess *MA : *Stmt) {
1752 if (!MA->isRead())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001753 continue;
1754
1755 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001756 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001757
1758 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1759 Read = isl_union_map_add_map(Read, AccessDomain);
1760 }
1761 }
1762 return isl_union_map_coalesce(Read);
1763}
1764
1765__isl_give isl_union_map *Scop::getSchedule() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001766 isl_union_map *Schedule = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001767
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001768 for (ScopStmt *Stmt : *this)
Tobias Grosser37eb4222014-02-20 21:43:54 +00001769 Schedule = isl_union_map_add_map(Schedule, Stmt->getScattering());
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001770
Tobias Grosser37eb4222014-02-20 21:43:54 +00001771 return isl_union_map_coalesce(Schedule);
1772}
1773
1774bool Scop::restrictDomains(__isl_take isl_union_set *Domain) {
1775 bool Changed = false;
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001776 for (ScopStmt *Stmt : *this) {
Tobias Grosser37eb4222014-02-20 21:43:54 +00001777 isl_union_set *StmtDomain = isl_union_set_from_set(Stmt->getDomain());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001778 isl_union_set *NewStmtDomain = isl_union_set_intersect(
1779 isl_union_set_copy(StmtDomain), isl_union_set_copy(Domain));
1780
1781 if (isl_union_set_is_subset(StmtDomain, NewStmtDomain)) {
1782 isl_union_set_free(StmtDomain);
1783 isl_union_set_free(NewStmtDomain);
1784 continue;
1785 }
1786
1787 Changed = true;
1788
1789 isl_union_set_free(StmtDomain);
1790 NewStmtDomain = isl_union_set_coalesce(NewStmtDomain);
1791
1792 if (isl_union_set_is_empty(NewStmtDomain)) {
1793 Stmt->restrictDomain(isl_set_empty(Stmt->getDomainSpace()));
1794 isl_union_set_free(NewStmtDomain);
1795 } else
1796 Stmt->restrictDomain(isl_set_from_union_set(NewStmtDomain));
1797 }
1798 isl_union_set_free(Domain);
1799 return Changed;
1800}
1801
Tobias Grosser75805372011-04-29 06:27:02 +00001802ScalarEvolution *Scop::getSE() const { return SE; }
1803
1804bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
1805 if (tempScop.getAccessFunctions(BB))
1806 return false;
1807
1808 return true;
1809}
1810
Tobias Grosser74394f02013-01-14 22:40:23 +00001811void Scop::buildScop(TempScop &tempScop, const Region &CurRegion,
1812 SmallVectorImpl<Loop *> &NestLoops,
1813 SmallVectorImpl<unsigned> &Scatter, LoopInfo &LI) {
Tobias Grosser75805372011-04-29 06:27:02 +00001814 Loop *L = castToLoop(CurRegion, LI);
1815
1816 if (L)
1817 NestLoops.push_back(L);
1818
1819 unsigned loopDepth = NestLoops.size();
1820 assert(Scatter.size() > loopDepth && "Scatter not big enough!");
1821
1822 for (Region::const_element_iterator I = CurRegion.element_begin(),
Tobias Grosserabfbe632013-02-05 12:09:06 +00001823 E = CurRegion.element_end();
1824 I != E; ++I)
Tobias Grosser75805372011-04-29 06:27:02 +00001825 if (I->isSubRegion())
1826 buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
1827 else {
1828 BasicBlock *BB = I->getNodeAs<BasicBlock>();
1829
1830 if (isTrivialBB(BB, tempScop))
1831 continue;
1832
Johannes Doerfert7c494212014-10-31 23:13:39 +00001833 ScopStmt *Stmt =
1834 new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter);
1835
1836 // Insert all statements into the statement map and the statement vector.
1837 StmtMap[BB] = Stmt;
1838 Stmts.push_back(Stmt);
Tobias Grosser75805372011-04-29 06:27:02 +00001839
1840 // Increasing the Scattering function is OK for the moment, because
1841 // we are using a depth first iterator and the program is well structured.
1842 ++Scatter[loopDepth];
1843 }
1844
1845 if (!L)
1846 return;
1847
1848 // Exiting a loop region.
1849 Scatter[loopDepth] = 0;
1850 NestLoops.pop_back();
Tobias Grosser74394f02013-01-14 22:40:23 +00001851 ++Scatter[loopDepth - 1];
Tobias Grosser75805372011-04-29 06:27:02 +00001852}
1853
Johannes Doerfert7c494212014-10-31 23:13:39 +00001854ScopStmt *Scop::getStmtForBasicBlock(BasicBlock *BB) const {
1855 const auto &StmtMapIt = StmtMap.find(BB);
1856 if (StmtMapIt == StmtMap.end())
1857 return nullptr;
1858 return StmtMapIt->second;
1859}
1860
Tobias Grosser75805372011-04-29 06:27:02 +00001861//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +00001862ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
1863 ctx = isl_ctx_alloc();
Tobias Grosser4a8e3562011-12-07 07:42:51 +00001864 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
Tobias Grosserb76f38532011-08-20 11:11:25 +00001865}
1866
1867ScopInfo::~ScopInfo() {
1868 clear();
1869 isl_ctx_free(ctx);
1870}
1871
Tobias Grosser75805372011-04-29 06:27:02 +00001872void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
Chandler Carruthf5579872015-01-17 14:16:56 +00001873 AU.addRequired<LoopInfoWrapperPass>();
Matt Arsenault8ca36812014-07-19 18:40:17 +00001874 AU.addRequired<RegionInfoPass>();
Tobias Grosser75805372011-04-29 06:27:02 +00001875 AU.addRequired<ScalarEvolution>();
1876 AU.addRequired<TempScopInfo>();
Johannes Doerfertb164c792014-09-18 11:17:17 +00001877 AU.addRequired<AliasAnalysis>();
Tobias Grosser75805372011-04-29 06:27:02 +00001878 AU.setPreservesAll();
1879}
1880
1881bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
Chandler Carruthf5579872015-01-17 14:16:56 +00001882 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Johannes Doerfertb164c792014-09-18 11:17:17 +00001883 AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
Tobias Grosser75805372011-04-29 06:27:02 +00001884 ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
1885
1886 TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
1887
1888 // This region is no Scop.
1889 if (!tempScop) {
Tobias Grosserc98a8fc2014-11-14 11:12:31 +00001890 scop = nullptr;
Tobias Grosser75805372011-04-29 06:27:02 +00001891 return false;
1892 }
1893
Tobias Grosserb76f38532011-08-20 11:11:25 +00001894 scop = new Scop(*tempScop, LI, SE, ctx);
Tobias Grosser75805372011-04-29 06:27:02 +00001895
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001896 if (!PollyUseRuntimeAliasChecks) {
1897 // Statistics.
1898 ++ScopFound;
1899 if (scop->getMaxLoopDepth() > 0)
1900 ++RichScopFound;
Johannes Doerfert9143d672014-09-27 11:02:39 +00001901 return false;
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001902 }
Johannes Doerfertb164c792014-09-18 11:17:17 +00001903
Johannes Doerfert9143d672014-09-27 11:02:39 +00001904 // If a problem occurs while building the alias groups we need to delete
1905 // this SCoP and pretend it wasn't valid in the first place.
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001906 if (scop->buildAliasGroups(AA)) {
1907 // Statistics.
1908 ++ScopFound;
1909 if (scop->getMaxLoopDepth() > 0)
1910 ++RichScopFound;
Johannes Doerfert9143d672014-09-27 11:02:39 +00001911 return false;
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001912 }
Johannes Doerfert9143d672014-09-27 11:02:39 +00001913
1914 DEBUG(dbgs()
1915 << "\n\nNOTE: Run time checks for " << scop->getNameStr()
1916 << " could not be created as the number of parameters involved is too "
1917 "high. The SCoP will be "
1918 "dismissed.\nUse:\n\t--polly-rtc-max-parameters=X\nto adjust the "
1919 "maximal number of parameters but be advised that the compile time "
1920 "might increase exponentially.\n\n");
1921
1922 delete scop;
1923 scop = nullptr;
Tobias Grosser75805372011-04-29 06:27:02 +00001924 return false;
1925}
1926
1927char ScopInfo::ID = 0;
1928
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001929Pass *polly::createScopInfoPass() { return new ScopInfo(); }
1930
Tobias Grosser73600b82011-10-08 00:30:40 +00001931INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
1932 "Polly - Create polyhedral description of Scops", false,
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001933 false);
Johannes Doerfertb164c792014-09-18 11:17:17 +00001934INITIALIZE_AG_DEPENDENCY(AliasAnalysis);
Chandler Carruthf5579872015-01-17 14:16:56 +00001935INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
Matt Arsenault8ca36812014-07-19 18:40:17 +00001936INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001937INITIALIZE_PASS_DEPENDENCY(ScalarEvolution);
1938INITIALIZE_PASS_DEPENDENCY(TempScopInfo);
Tobias Grosser73600b82011-10-08 00:30:40 +00001939INITIALIZE_PASS_END(ScopInfo, "polly-scops",
1940 "Polly - Create polyhedral description of Scops", false,
1941 false)