blob: 829c11afb91cd60c0c97fc25a4c69cfbb2ffce88 [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 Doerfert0ff23ec2015-02-06 20:13:15 +0000573 OS << "[Reduction Type: " << getReductionType() << "] ";
574 OS << "[Scalar: " << isScalar() << "]\n";
Johannes Doerferta99130f2014-10-13 12:58:03 +0000575 OS.indent(16) << getOriginalAccessRelationStr() << ";\n";
Tobias Grosser75805372011-04-29 06:27:02 +0000576}
577
Tobias Grosser74394f02013-01-14 22:40:23 +0000578void MemoryAccess::dump() const { print(errs()); }
Tobias Grosser75805372011-04-29 06:27:02 +0000579
580// Create a map in the size of the provided set domain, that maps from the
581// one element of the provided set domain to another element of the provided
582// set domain.
583// The mapping is limited to all points that are equal in all but the last
584// dimension and for which the last dimension of the input is strict smaller
585// than the last dimension of the output.
586//
587// getEqualAndLarger(set[i0, i1, ..., iX]):
588//
589// set[i0, i1, ..., iX] -> set[o0, o1, ..., oX]
590// : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1), iX < oX
591//
Tobias Grosserf5338802011-10-06 00:03:35 +0000592static isl_map *getEqualAndLarger(isl_space *setDomain) {
Tobias Grosserc327932c2012-02-01 14:23:36 +0000593 isl_space *Space = isl_space_map_from_set(setDomain);
594 isl_map *Map = isl_map_universe(isl_space_copy(Space));
595 isl_local_space *MapLocalSpace = isl_local_space_from_space(Space);
Sebastian Pop40408762013-10-04 17:14:53 +0000596 unsigned lastDimension = isl_map_dim(Map, isl_dim_in) - 1;
Tobias Grosser75805372011-04-29 06:27:02 +0000597
598 // Set all but the last dimension to be equal for the input and output
599 //
600 // input[i0, i1, ..., iX] -> output[o0, o1, ..., oX]
601 // : i0 = o0, i1 = o1, ..., i(X-1) = o(X-1)
Sebastian Pop40408762013-10-04 17:14:53 +0000602 for (unsigned i = 0; i < lastDimension; ++i)
Tobias Grosserc327932c2012-02-01 14:23:36 +0000603 Map = isl_map_equate(Map, isl_dim_in, i, isl_dim_out, i);
Tobias Grosser75805372011-04-29 06:27:02 +0000604
605 // Set the last dimension of the input to be strict smaller than the
606 // last dimension of the output.
607 //
608 // input[?,?,?,...,iX] -> output[?,?,?,...,oX] : iX < oX
609 //
Tobias Grosseredab1352013-06-21 06:41:31 +0000610 isl_val *v;
611 isl_ctx *Ctx = isl_map_get_ctx(Map);
Tobias Grosserf5338802011-10-06 00:03:35 +0000612 isl_constraint *c = isl_inequality_alloc(isl_local_space_copy(MapLocalSpace));
Tobias Grosseredab1352013-06-21 06:41:31 +0000613 v = isl_val_int_from_si(Ctx, -1);
614 c = isl_constraint_set_coefficient_val(c, isl_dim_in, lastDimension, v);
615 v = isl_val_int_from_si(Ctx, 1);
616 c = isl_constraint_set_coefficient_val(c, isl_dim_out, lastDimension, v);
617 v = isl_val_int_from_si(Ctx, -1);
618 c = isl_constraint_set_constant_val(c, v);
Tobias Grosser75805372011-04-29 06:27:02 +0000619
Tobias Grosserc327932c2012-02-01 14:23:36 +0000620 Map = isl_map_add_constraint(Map, c);
Tobias Grosser75805372011-04-29 06:27:02 +0000621
Tobias Grosser23b36662011-10-17 08:32:36 +0000622 isl_local_space_free(MapLocalSpace);
Tobias Grosserc327932c2012-02-01 14:23:36 +0000623 return Map;
Tobias Grosser75805372011-04-29 06:27:02 +0000624}
625
Sebastian Popa00a0292012-12-18 07:46:06 +0000626isl_set *MemoryAccess::getStride(__isl_take const isl_map *Schedule) const {
Tobias Grosserabfbe632013-02-05 12:09:06 +0000627 isl_map *S = const_cast<isl_map *>(Schedule);
Johannes Doerferta99130f2014-10-13 12:58:03 +0000628 isl_map *AccessRelation = getAccessRelation();
Sebastian Popa00a0292012-12-18 07:46:06 +0000629 isl_space *Space = isl_space_range(isl_map_get_space(S));
630 isl_map *NextScatt = getEqualAndLarger(Space);
Tobias Grosser75805372011-04-29 06:27:02 +0000631
Sebastian Popa00a0292012-12-18 07:46:06 +0000632 S = isl_map_reverse(S);
633 NextScatt = isl_map_lexmin(NextScatt);
Tobias Grosser75805372011-04-29 06:27:02 +0000634
Sebastian Popa00a0292012-12-18 07:46:06 +0000635 NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(S));
636 NextScatt = isl_map_apply_range(NextScatt, isl_map_copy(AccessRelation));
637 NextScatt = isl_map_apply_domain(NextScatt, S);
638 NextScatt = isl_map_apply_domain(NextScatt, AccessRelation);
Tobias Grosser75805372011-04-29 06:27:02 +0000639
Sebastian Popa00a0292012-12-18 07:46:06 +0000640 isl_set *Deltas = isl_map_deltas(NextScatt);
641 return Deltas;
Tobias Grosser75805372011-04-29 06:27:02 +0000642}
643
Sebastian Popa00a0292012-12-18 07:46:06 +0000644bool MemoryAccess::isStrideX(__isl_take const isl_map *Schedule,
Tobias Grosser28dd4862012-01-24 16:42:16 +0000645 int StrideWidth) const {
646 isl_set *Stride, *StrideX;
647 bool IsStrideX;
Tobias Grosser75805372011-04-29 06:27:02 +0000648
Sebastian Popa00a0292012-12-18 07:46:06 +0000649 Stride = getStride(Schedule);
Tobias Grosser28dd4862012-01-24 16:42:16 +0000650 StrideX = isl_set_universe(isl_set_get_space(Stride));
651 StrideX = isl_set_fix_si(StrideX, isl_dim_set, 0, StrideWidth);
652 IsStrideX = isl_set_is_equal(Stride, StrideX);
Tobias Grosser75805372011-04-29 06:27:02 +0000653
Tobias Grosser28dd4862012-01-24 16:42:16 +0000654 isl_set_free(StrideX);
Tobias Grosserdea98232012-01-17 20:34:27 +0000655 isl_set_free(Stride);
Tobias Grosserb76f38532011-08-20 11:11:25 +0000656
Tobias Grosser28dd4862012-01-24 16:42:16 +0000657 return IsStrideX;
658}
659
Sebastian Popa00a0292012-12-18 07:46:06 +0000660bool MemoryAccess::isStrideZero(const isl_map *Schedule) const {
661 return isStrideX(Schedule, 0);
Tobias Grosser75805372011-04-29 06:27:02 +0000662}
663
Tobias Grosser79baa212014-04-10 08:38:02 +0000664bool MemoryAccess::isScalar() const {
665 return isl_map_n_out(AccessRelation) == 0;
666}
667
Sebastian Popa00a0292012-12-18 07:46:06 +0000668bool MemoryAccess::isStrideOne(const isl_map *Schedule) const {
669 return isStrideX(Schedule, 1);
Tobias Grosser75805372011-04-29 06:27:02 +0000670}
671
Tobias Grosser5d453812011-10-06 00:04:11 +0000672void MemoryAccess::setNewAccessRelation(isl_map *newAccess) {
Tobias Grosserb76f38532011-08-20 11:11:25 +0000673 isl_map_free(newAccessRelation);
Raghesh Aloor7a04f4f2011-08-03 13:47:59 +0000674 newAccessRelation = newAccess;
Raghesh Aloor3cb66282011-07-12 17:14:03 +0000675}
Tobias Grosser75805372011-04-29 06:27:02 +0000676
677//===----------------------------------------------------------------------===//
Tobias Grossercf3942d2011-10-06 00:04:05 +0000678
Tobias Grosser74394f02013-01-14 22:40:23 +0000679isl_map *ScopStmt::getScattering() const { return isl_map_copy(Scattering); }
Tobias Grossercf3942d2011-10-06 00:04:05 +0000680
Tobias Grosser37eb4222014-02-20 21:43:54 +0000681void ScopStmt::restrictDomain(__isl_take isl_set *NewDomain) {
682 assert(isl_set_is_subset(NewDomain, Domain) &&
683 "New domain is not a subset of old domain!");
684 isl_set_free(Domain);
685 Domain = NewDomain;
686 Scattering = isl_map_intersect_domain(Scattering, isl_set_copy(Domain));
687}
688
Tobias Grossercf3942d2011-10-06 00:04:05 +0000689void ScopStmt::setScattering(isl_map *NewScattering) {
Tobias Grosser5a56cbf2014-04-16 07:33:47 +0000690 assert(NewScattering && "New scattering is nullptr");
Tobias Grosserb76f38532011-08-20 11:11:25 +0000691 isl_map_free(Scattering);
Tobias Grossercf3942d2011-10-06 00:04:05 +0000692 Scattering = NewScattering;
Tobias Grosserb76f38532011-08-20 11:11:25 +0000693}
694
Tobias Grosser75805372011-04-29 06:27:02 +0000695void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) {
Tobias Grosser78d8a3d2012-01-17 20:34:23 +0000696 unsigned NbIterators = getNumIterators();
697 unsigned NbScatteringDims = Parent.getMaxLoopDepth() * 2 + 1;
698
Tobias Grosser084d8f72012-05-29 09:29:44 +0000699 isl_space *Space = isl_space_set_alloc(getIslCtx(), 0, NbScatteringDims);
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)
Johannes Doerfertbe9c9112015-02-06 21:39:31 +0000910 : Parent(parent), BB(&bb), Build(nullptr), 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
Tobias Grosser3f296192015-01-01 23:01:11 +00001515 for (auto *S : *this) {
1516 isl_map *Schedule = S->getScattering();
1517 Schedule = isl_map_apply_range(Schedule, isl_map_copy(DropDimMap));
1518 S->setScattering(Schedule);
1519 }
1520 isl_set_free(ScheduleSpace);
1521 isl_map_free(DropDimMap);
1522}
1523
Tobias Grosser0e27e242011-10-06 00:03:48 +00001524Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution,
1525 isl_ctx *Context)
Tobias Grosserabfbe632013-02-05 12:09:06 +00001526 : SE(&ScalarEvolution), R(tempScop.getMaxRegion()),
Johannes Doerferte3da05a2014-11-01 00:12:13 +00001527 MaxLoopDepth(getMaxLoopDepthInRegion(tempScop.getMaxRegion(), LI)) {
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001528 IslCtx = Context;
Tobias Grosser6be480c2011-11-08 15:41:13 +00001529 buildContext();
Tobias Grosser75805372011-04-29 06:27:02 +00001530
Tobias Grosserabfbe632013-02-05 12:09:06 +00001531 SmallVector<Loop *, 8> NestLoops;
Tobias Grosser75805372011-04-29 06:27:02 +00001532 SmallVector<unsigned, 8> Scatter;
1533
1534 Scatter.assign(MaxLoopDepth + 1, 0);
1535
1536 // Build the iteration domain, access functions and scattering functions
1537 // traversing the region tree.
1538 buildScop(tempScop, getRegion(), NestLoops, Scatter, LI);
Tobias Grosser75805372011-04-29 06:27:02 +00001539
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001540 realignParams();
Tobias Grosser18daaca2012-05-22 10:47:27 +00001541 addParameterBounds();
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001542 simplifyAssumedContext();
Tobias Grosser3f296192015-01-01 23:01:11 +00001543 dropConstantScheduleDims();
Tobias Grosser8cae72f2011-11-08 15:41:08 +00001544
Tobias Grosser75805372011-04-29 06:27:02 +00001545 assert(NestLoops.empty() && "NestLoops not empty at top level!");
1546}
1547
1548Scop::~Scop() {
1549 isl_set_free(Context);
Tobias Grossere86109f2013-10-29 21:05:49 +00001550 isl_set_free(AssumedContext);
Tobias Grosser75805372011-04-29 06:27:02 +00001551
1552 // Free the statements;
Tobias Grosser083d3d32014-06-28 08:59:45 +00001553 for (ScopStmt *Stmt : *this)
1554 delete Stmt;
Johannes Doerfertb164c792014-09-18 11:17:17 +00001555
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001556 // Free the ScopArrayInfo objects.
1557 for (auto &ScopArrayInfoPair : ScopArrayInfoMap)
1558 delete ScopArrayInfoPair.second;
1559
Johannes Doerfertb164c792014-09-18 11:17:17 +00001560 // Free the alias groups
1561 for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) {
1562 for (MinMaxAccessTy &MMA : *MinMaxAccesses) {
1563 isl_pw_multi_aff_free(MMA.first);
1564 isl_pw_multi_aff_free(MMA.second);
1565 }
1566 delete MinMaxAccesses;
1567 }
Tobias Grosser75805372011-04-29 06:27:02 +00001568}
1569
Johannes Doerfert80ef1102014-11-07 08:31:31 +00001570const ScopArrayInfo *
1571Scop::getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType,
1572 const SmallVector<const SCEV *, 4> &Sizes) {
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001573 const ScopArrayInfo *&SAI = ScopArrayInfoMap[BasePtr];
Johannes Doerfert80ef1102014-11-07 08:31:31 +00001574 if (!SAI)
1575 SAI = new ScopArrayInfo(BasePtr, AccessType, getIslCtx(), Sizes);
Johannes Doerfert1a28a892014-10-05 11:32:18 +00001576 return SAI;
1577}
1578
1579const ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr) {
1580 const SCEV *PtrSCEV = SE->getSCEV(BasePtr);
1581 const SCEVUnknown *PtrBaseSCEV =
1582 cast<SCEVUnknown>(SE->getPointerBase(PtrSCEV));
1583 const ScopArrayInfo *SAI = ScopArrayInfoMap[PtrBaseSCEV->getValue()];
1584 assert(SAI && "No ScopArrayInfo available for this base pointer");
1585 return SAI;
1586}
1587
Tobias Grosser74394f02013-01-14 22:40:23 +00001588std::string Scop::getContextStr() const { return stringFromIslObj(Context); }
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001589std::string Scop::getAssumedContextStr() const {
1590 return stringFromIslObj(AssumedContext);
1591}
Tobias Grosser75805372011-04-29 06:27:02 +00001592
1593std::string Scop::getNameStr() const {
1594 std::string ExitName, EntryName;
1595 raw_string_ostream ExitStr(ExitName);
1596 raw_string_ostream EntryStr(EntryName);
1597
Tobias Grosserf240b482014-01-09 10:42:15 +00001598 R.getEntry()->printAsOperand(EntryStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001599 EntryStr.str();
1600
1601 if (R.getExit()) {
Tobias Grosserf240b482014-01-09 10:42:15 +00001602 R.getExit()->printAsOperand(ExitStr, false);
Tobias Grosser75805372011-04-29 06:27:02 +00001603 ExitStr.str();
1604 } else
1605 ExitName = "FunctionExit";
1606
1607 return EntryName + "---" + ExitName;
1608}
1609
Tobias Grosser74394f02013-01-14 22:40:23 +00001610__isl_give isl_set *Scop::getContext() const { return isl_set_copy(Context); }
Tobias Grosser37487052011-10-06 00:03:42 +00001611__isl_give isl_space *Scop::getParamSpace() const {
1612 return isl_set_get_space(this->Context);
1613}
1614
Tobias Grossere86109f2013-10-29 21:05:49 +00001615__isl_give isl_set *Scop::getAssumedContext() const {
1616 return isl_set_copy(AssumedContext);
1617}
1618
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001619void Scop::addAssumption(__isl_take isl_set *Set) {
1620 AssumedContext = isl_set_intersect(AssumedContext, Set);
Tobias Grosser7b50bee2014-11-25 10:51:12 +00001621 AssumedContext = isl_set_coalesce(AssumedContext);
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001622}
1623
Tobias Grosser75805372011-04-29 06:27:02 +00001624void Scop::printContext(raw_ostream &OS) const {
1625 OS << "Context:\n";
1626
1627 if (!Context) {
1628 OS.indent(4) << "n/a\n\n";
1629 return;
1630 }
1631
1632 OS.indent(4) << getContextStr() << "\n";
Tobias Grosser60b54f12011-11-08 15:41:28 +00001633
Tobias Grosser5e6813d2014-07-02 17:47:48 +00001634 OS.indent(4) << "Assumed Context:\n";
1635 if (!AssumedContext) {
1636 OS.indent(4) << "n/a\n\n";
1637 return;
1638 }
1639
1640 OS.indent(4) << getAssumedContextStr() << "\n";
1641
Tobias Grosser083d3d32014-06-28 08:59:45 +00001642 for (const SCEV *Parameter : Parameters) {
Tobias Grosser60b54f12011-11-08 15:41:28 +00001643 int Dim = ParameterIds.find(Parameter)->second;
Tobias Grosser60b54f12011-11-08 15:41:28 +00001644 OS.indent(4) << "p" << Dim << ": " << *Parameter << "\n";
1645 }
Tobias Grosser75805372011-04-29 06:27:02 +00001646}
1647
Johannes Doerfertb164c792014-09-18 11:17:17 +00001648void Scop::printAliasAssumptions(raw_ostream &OS) const {
1649 OS.indent(4) << "Alias Groups (" << MinMaxAliasGroups.size() << "):\n";
1650 if (MinMaxAliasGroups.empty()) {
1651 OS.indent(8) << "n/a\n";
1652 return;
1653 }
1654 for (MinMaxVectorTy *MinMaxAccesses : MinMaxAliasGroups) {
1655 OS.indent(8) << "[[";
1656 for (MinMaxAccessTy &MinMacAccess : *MinMaxAccesses)
1657 OS << " <" << MinMacAccess.first << ", " << MinMacAccess.second << ">";
1658 OS << " ]]\n";
1659 }
1660}
1661
Tobias Grosser75805372011-04-29 06:27:02 +00001662void Scop::printStatements(raw_ostream &OS) const {
1663 OS << "Statements {\n";
1664
Tobias Grosser083d3d32014-06-28 08:59:45 +00001665 for (ScopStmt *Stmt : *this)
1666 OS.indent(4) << *Stmt;
Tobias Grosser75805372011-04-29 06:27:02 +00001667
1668 OS.indent(4) << "}\n";
1669}
1670
Tobias Grosser75805372011-04-29 06:27:02 +00001671void Scop::print(raw_ostream &OS) const {
Tobias Grosser4eb7ddb2014-03-18 18:51:11 +00001672 OS.indent(4) << "Function: " << getRegion().getEntry()->getParent()->getName()
1673 << "\n";
Tobias Grosser483fdd42014-03-18 18:05:38 +00001674 OS.indent(4) << "Region: " << getNameStr() << "\n";
David Peixottodc0a11c2015-01-13 18:31:55 +00001675 OS.indent(4) << "Max Loop Depth: " << getMaxLoopDepth() << "\n";
Tobias Grosser75805372011-04-29 06:27:02 +00001676 printContext(OS.indent(4));
Johannes Doerfertb164c792014-09-18 11:17:17 +00001677 printAliasAssumptions(OS);
Tobias Grosser75805372011-04-29 06:27:02 +00001678 printStatements(OS.indent(4));
1679}
1680
1681void Scop::dump() const { print(dbgs()); }
1682
Tobias Grosser9a38ab82011-11-08 15:41:03 +00001683isl_ctx *Scop::getIslCtx() const { return IslCtx; }
Tobias Grosser75805372011-04-29 06:27:02 +00001684
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001685__isl_give isl_union_set *Scop::getDomains() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001686 isl_union_set *Domain = isl_union_set_empty(getParamSpace());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001687
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001688 for (ScopStmt *Stmt : *this)
1689 Domain = isl_union_set_add_set(Domain, Stmt->getDomain());
Tobias Grosser5f9a7622012-02-14 14:02:40 +00001690
1691 return Domain;
1692}
1693
Tobias Grosser780ce0f2014-07-11 07:12:10 +00001694__isl_give isl_union_map *Scop::getMustWrites() {
1695 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1696
1697 for (ScopStmt *Stmt : *this) {
1698 for (MemoryAccess *MA : *Stmt) {
1699 if (!MA->isMustWrite())
1700 continue;
1701
1702 isl_set *Domain = Stmt->getDomain();
1703 isl_map *AccessDomain = MA->getAccessRelation();
1704 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1705 Write = isl_union_map_add_map(Write, AccessDomain);
1706 }
1707 }
1708 return isl_union_map_coalesce(Write);
1709}
1710
1711__isl_give isl_union_map *Scop::getMayWrites() {
1712 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1713
1714 for (ScopStmt *Stmt : *this) {
1715 for (MemoryAccess *MA : *Stmt) {
1716 if (!MA->isMayWrite())
1717 continue;
1718
1719 isl_set *Domain = Stmt->getDomain();
1720 isl_map *AccessDomain = MA->getAccessRelation();
1721 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1722 Write = isl_union_map_add_map(Write, AccessDomain);
1723 }
1724 }
1725 return isl_union_map_coalesce(Write);
1726}
1727
Tobias Grosser37eb4222014-02-20 21:43:54 +00001728__isl_give isl_union_map *Scop::getWrites() {
1729 isl_union_map *Write = isl_union_map_empty(this->getParamSpace());
1730
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001731 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001732 for (MemoryAccess *MA : *Stmt) {
1733 if (!MA->isWrite())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001734 continue;
1735
1736 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001737 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001738 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1739 Write = isl_union_map_add_map(Write, AccessDomain);
1740 }
1741 }
1742 return isl_union_map_coalesce(Write);
1743}
1744
1745__isl_give isl_union_map *Scop::getReads() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001746 isl_union_map *Read = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001747
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001748 for (ScopStmt *Stmt : *this) {
Johannes Doerfertf6752892014-06-13 18:01:45 +00001749 for (MemoryAccess *MA : *Stmt) {
1750 if (!MA->isRead())
Tobias Grosser37eb4222014-02-20 21:43:54 +00001751 continue;
1752
1753 isl_set *Domain = Stmt->getDomain();
Johannes Doerfertf6752892014-06-13 18:01:45 +00001754 isl_map *AccessDomain = MA->getAccessRelation();
Tobias Grosser37eb4222014-02-20 21:43:54 +00001755
1756 AccessDomain = isl_map_intersect_domain(AccessDomain, Domain);
1757 Read = isl_union_map_add_map(Read, AccessDomain);
1758 }
1759 }
1760 return isl_union_map_coalesce(Read);
1761}
1762
1763__isl_give isl_union_map *Scop::getSchedule() {
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001764 isl_union_map *Schedule = isl_union_map_empty(getParamSpace());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001765
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001766 for (ScopStmt *Stmt : *this)
Tobias Grosser37eb4222014-02-20 21:43:54 +00001767 Schedule = isl_union_map_add_map(Schedule, Stmt->getScattering());
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001768
Tobias Grosser37eb4222014-02-20 21:43:54 +00001769 return isl_union_map_coalesce(Schedule);
1770}
1771
1772bool Scop::restrictDomains(__isl_take isl_union_set *Domain) {
1773 bool Changed = false;
Tobias Grosserbc4ef902014-06-28 08:59:38 +00001774 for (ScopStmt *Stmt : *this) {
Tobias Grosser37eb4222014-02-20 21:43:54 +00001775 isl_union_set *StmtDomain = isl_union_set_from_set(Stmt->getDomain());
Tobias Grosser37eb4222014-02-20 21:43:54 +00001776 isl_union_set *NewStmtDomain = isl_union_set_intersect(
1777 isl_union_set_copy(StmtDomain), isl_union_set_copy(Domain));
1778
1779 if (isl_union_set_is_subset(StmtDomain, NewStmtDomain)) {
1780 isl_union_set_free(StmtDomain);
1781 isl_union_set_free(NewStmtDomain);
1782 continue;
1783 }
1784
1785 Changed = true;
1786
1787 isl_union_set_free(StmtDomain);
1788 NewStmtDomain = isl_union_set_coalesce(NewStmtDomain);
1789
1790 if (isl_union_set_is_empty(NewStmtDomain)) {
1791 Stmt->restrictDomain(isl_set_empty(Stmt->getDomainSpace()));
1792 isl_union_set_free(NewStmtDomain);
1793 } else
1794 Stmt->restrictDomain(isl_set_from_union_set(NewStmtDomain));
1795 }
1796 isl_union_set_free(Domain);
1797 return Changed;
1798}
1799
Tobias Grosser75805372011-04-29 06:27:02 +00001800ScalarEvolution *Scop::getSE() const { return SE; }
1801
1802bool Scop::isTrivialBB(BasicBlock *BB, TempScop &tempScop) {
1803 if (tempScop.getAccessFunctions(BB))
1804 return false;
1805
1806 return true;
1807}
1808
Tobias Grosser74394f02013-01-14 22:40:23 +00001809void Scop::buildScop(TempScop &tempScop, const Region &CurRegion,
1810 SmallVectorImpl<Loop *> &NestLoops,
1811 SmallVectorImpl<unsigned> &Scatter, LoopInfo &LI) {
Tobias Grosser75805372011-04-29 06:27:02 +00001812 Loop *L = castToLoop(CurRegion, LI);
1813
1814 if (L)
1815 NestLoops.push_back(L);
1816
1817 unsigned loopDepth = NestLoops.size();
1818 assert(Scatter.size() > loopDepth && "Scatter not big enough!");
1819
1820 for (Region::const_element_iterator I = CurRegion.element_begin(),
Tobias Grosserabfbe632013-02-05 12:09:06 +00001821 E = CurRegion.element_end();
1822 I != E; ++I)
Tobias Grosser75805372011-04-29 06:27:02 +00001823 if (I->isSubRegion())
1824 buildScop(tempScop, *(I->getNodeAs<Region>()), NestLoops, Scatter, LI);
1825 else {
1826 BasicBlock *BB = I->getNodeAs<BasicBlock>();
1827
1828 if (isTrivialBB(BB, tempScop))
1829 continue;
1830
Johannes Doerfert7c494212014-10-31 23:13:39 +00001831 ScopStmt *Stmt =
1832 new ScopStmt(*this, tempScop, CurRegion, *BB, NestLoops, Scatter);
1833
1834 // Insert all statements into the statement map and the statement vector.
1835 StmtMap[BB] = Stmt;
1836 Stmts.push_back(Stmt);
Tobias Grosser75805372011-04-29 06:27:02 +00001837
1838 // Increasing the Scattering function is OK for the moment, because
1839 // we are using a depth first iterator and the program is well structured.
1840 ++Scatter[loopDepth];
1841 }
1842
1843 if (!L)
1844 return;
1845
1846 // Exiting a loop region.
1847 Scatter[loopDepth] = 0;
1848 NestLoops.pop_back();
Tobias Grosser74394f02013-01-14 22:40:23 +00001849 ++Scatter[loopDepth - 1];
Tobias Grosser75805372011-04-29 06:27:02 +00001850}
1851
Johannes Doerfert7c494212014-10-31 23:13:39 +00001852ScopStmt *Scop::getStmtForBasicBlock(BasicBlock *BB) const {
1853 const auto &StmtMapIt = StmtMap.find(BB);
1854 if (StmtMapIt == StmtMap.end())
1855 return nullptr;
1856 return StmtMapIt->second;
1857}
1858
Tobias Grosser75805372011-04-29 06:27:02 +00001859//===----------------------------------------------------------------------===//
Tobias Grosserb76f38532011-08-20 11:11:25 +00001860ScopInfo::ScopInfo() : RegionPass(ID), scop(0) {
1861 ctx = isl_ctx_alloc();
Tobias Grosser4a8e3562011-12-07 07:42:51 +00001862 isl_options_set_on_error(ctx, ISL_ON_ERROR_ABORT);
Tobias Grosserb76f38532011-08-20 11:11:25 +00001863}
1864
1865ScopInfo::~ScopInfo() {
1866 clear();
1867 isl_ctx_free(ctx);
1868}
1869
Tobias Grosser75805372011-04-29 06:27:02 +00001870void ScopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
Chandler Carruthf5579872015-01-17 14:16:56 +00001871 AU.addRequired<LoopInfoWrapperPass>();
Matt Arsenault8ca36812014-07-19 18:40:17 +00001872 AU.addRequired<RegionInfoPass>();
Tobias Grosser75805372011-04-29 06:27:02 +00001873 AU.addRequired<ScalarEvolution>();
1874 AU.addRequired<TempScopInfo>();
Johannes Doerfertb164c792014-09-18 11:17:17 +00001875 AU.addRequired<AliasAnalysis>();
Tobias Grosser75805372011-04-29 06:27:02 +00001876 AU.setPreservesAll();
1877}
1878
1879bool ScopInfo::runOnRegion(Region *R, RGPassManager &RGM) {
Chandler Carruthf5579872015-01-17 14:16:56 +00001880 LoopInfo &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Johannes Doerfertb164c792014-09-18 11:17:17 +00001881 AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
Tobias Grosser75805372011-04-29 06:27:02 +00001882 ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
1883
1884 TempScop *tempScop = getAnalysis<TempScopInfo>().getTempScop(R);
1885
1886 // This region is no Scop.
1887 if (!tempScop) {
Tobias Grosserc98a8fc2014-11-14 11:12:31 +00001888 scop = nullptr;
Tobias Grosser75805372011-04-29 06:27:02 +00001889 return false;
1890 }
1891
Tobias Grosserb76f38532011-08-20 11:11:25 +00001892 scop = new Scop(*tempScop, LI, SE, ctx);
Tobias Grosser75805372011-04-29 06:27:02 +00001893
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001894 if (!PollyUseRuntimeAliasChecks) {
1895 // Statistics.
1896 ++ScopFound;
1897 if (scop->getMaxLoopDepth() > 0)
1898 ++RichScopFound;
Johannes Doerfert9143d672014-09-27 11:02:39 +00001899 return false;
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001900 }
Johannes Doerfertb164c792014-09-18 11:17:17 +00001901
Johannes Doerfert9143d672014-09-27 11:02:39 +00001902 // If a problem occurs while building the alias groups we need to delete
1903 // this SCoP and pretend it wasn't valid in the first place.
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001904 if (scop->buildAliasGroups(AA)) {
1905 // Statistics.
1906 ++ScopFound;
1907 if (scop->getMaxLoopDepth() > 0)
1908 ++RichScopFound;
Johannes Doerfert9143d672014-09-27 11:02:39 +00001909 return false;
Johannes Doerfert21aa3dc2014-11-01 01:30:11 +00001910 }
Johannes Doerfert9143d672014-09-27 11:02:39 +00001911
1912 DEBUG(dbgs()
1913 << "\n\nNOTE: Run time checks for " << scop->getNameStr()
1914 << " could not be created as the number of parameters involved is too "
1915 "high. The SCoP will be "
1916 "dismissed.\nUse:\n\t--polly-rtc-max-parameters=X\nto adjust the "
1917 "maximal number of parameters but be advised that the compile time "
1918 "might increase exponentially.\n\n");
1919
1920 delete scop;
1921 scop = nullptr;
Tobias Grosser75805372011-04-29 06:27:02 +00001922 return false;
1923}
1924
1925char ScopInfo::ID = 0;
1926
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001927Pass *polly::createScopInfoPass() { return new ScopInfo(); }
1928
Tobias Grosser73600b82011-10-08 00:30:40 +00001929INITIALIZE_PASS_BEGIN(ScopInfo, "polly-scops",
1930 "Polly - Create polyhedral description of Scops", false,
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001931 false);
Johannes Doerfertb164c792014-09-18 11:17:17 +00001932INITIALIZE_AG_DEPENDENCY(AliasAnalysis);
Chandler Carruthf5579872015-01-17 14:16:56 +00001933INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
Matt Arsenault8ca36812014-07-19 18:40:17 +00001934INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001935INITIALIZE_PASS_DEPENDENCY(ScalarEvolution);
1936INITIALIZE_PASS_DEPENDENCY(TempScopInfo);
Tobias Grosser73600b82011-10-08 00:30:40 +00001937INITIALIZE_PASS_END(ScopInfo, "polly-scops",
1938 "Polly - Create polyhedral description of Scops", false,
1939 false)