blob: 27977c610b72c0916c7d8b210f8e8f6dd1fa5dca [file] [log] [blame]
Tobias Grosser75805372011-04-29 06:27:02 +00001//===----- ScopDetection.cpp - Detect Scops --------------------*- C++ -*-===//
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// Detect the maximal Scops of a function.
11//
12// A static control part (Scop) is a subgraph of the control flow graph (CFG)
13// that only has statically known control flow and can therefore be described
14// within the polyhedral model.
15//
16// Every Scop fullfills these restrictions:
17//
18// * It is a single entry single exit region
19//
20// * Only affine linear bounds in the loops
21//
22// Every natural loop in a Scop must have a number of loop iterations that can
23// be described as an affine linear function in surrounding loop iterators or
24// parameters. (A parameter is a scalar that does not change its value during
25// execution of the Scop).
26//
27// * Only comparisons of affine linear expressions in conditions
28//
29// * All loops and conditions perfectly nested
30//
31// The control flow needs to be structured such that it could be written using
32// just 'for' and 'if' statements, without the need for any 'goto', 'break' or
33// 'continue'.
34//
35// * Side effect free functions call
36//
37// Only function calls and intrinsics that do not have side effects are allowed
38// (readnone).
39//
40// The Scop detection finds the largest Scops by checking if the largest
41// region is a Scop. If this is not the case, its canonical subregions are
42// checked until a region is a Scop. It is now tried to extend this Scop by
43// creating a larger non canonical region.
44//
45//===----------------------------------------------------------------------===//
46
Tobias Grosserecfe21b2013-03-20 18:03:18 +000047#include "polly/CodeGen/BlockGenerators.h"
Tobias Grosserba0d0922015-05-09 09:13:42 +000048#include "polly/CodeGen/CodeGeneration.h"
Tobias Grosser75805372011-04-29 06:27:02 +000049#include "polly/LinkAllPasses.h"
Tobias Grosser637bd632013-05-07 07:31:10 +000050#include "polly/Options.h"
Tobias Grosserecfe21b2013-03-20 18:03:18 +000051#include "polly/ScopDetection.h"
Tobias Grosserba0d0922015-05-09 09:13:42 +000052#include "polly/ScopDetectionDiagnostic.h"
Tobias Grosser120db6b2011-11-07 12:58:54 +000053#include "polly/Support/SCEVValidator.h"
Tobias Grosser83628182013-05-07 08:11:54 +000054#include "polly/Support/ScopHelper.h"
Tobias Grossera63b7ce2015-05-03 05:21:36 +000055#include "polly/Support/ScopLocation.h"
Tobias Grosser75805372011-04-29 06:27:02 +000056#include "llvm/ADT/Statistic.h"
57#include "llvm/Analysis/AliasAnalysis.h"
Tobias Grosser6e9f25a2011-11-09 22:35:00 +000058#include "llvm/Analysis/LoopInfo.h"
Matt Arsenault8ca36812014-07-19 18:40:17 +000059#include "llvm/Analysis/PostDominators.h"
Tobias Grosser75805372011-04-29 06:27:02 +000060#include "llvm/Analysis/RegionIterator.h"
Tobias Grosser6e9f25a2011-11-09 22:35:00 +000061#include "llvm/Analysis/ScalarEvolution.h"
Tobias Grosserb8710b52011-11-10 12:44:50 +000062#include "llvm/Analysis/ScalarEvolutionExpressions.h"
Chandler Carruth6b96c242014-03-06 00:47:27 +000063#include "llvm/IR/DebugInfo.h"
Tobias Grosser8519f892013-12-18 10:49:53 +000064#include "llvm/IR/DiagnosticInfo.h"
65#include "llvm/IR/DiagnosticPrinter.h"
Tobias Grosserba0d0922015-05-09 09:13:42 +000066#include "llvm/IR/IntrinsicInst.h"
Chandler Carruth6b96c242014-03-06 00:47:27 +000067#include "llvm/IR/LLVMContext.h"
Tobias Grosser75805372011-04-29 06:27:02 +000068#include "llvm/Support/Debug.h"
Tobias Grosser60b54f12011-11-08 15:41:28 +000069#include <set>
70
Tobias Grosser75805372011-04-29 06:27:02 +000071using namespace llvm;
72using namespace polly;
73
Chandler Carruth95fef942014-04-22 03:30:19 +000074#define DEBUG_TYPE "polly-detect"
75
Sebastian Pop8fe6d112013-05-30 17:47:32 +000076static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +000077 DetectScopsWithoutLoops("polly-detect-scops-in-functions-without-loops",
78 cl::desc("Detect scops in functions without loops"),
79 cl::Hidden, cl::init(false), cl::ZeroOrMore,
80 cl::cat(PollyCategory));
Sebastian Pop8fe6d112013-05-30 17:47:32 +000081
Sebastian Pop2c9ec2e2013-06-03 16:35:37 +000082static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +000083 DetectRegionsWithoutLoops("polly-detect-scops-in-regions-without-loops",
84 cl::desc("Detect scops in regions without loops"),
85 cl::Hidden, cl::init(false), cl::ZeroOrMore,
86 cl::cat(PollyCategory));
Sebastian Pop2c9ec2e2013-06-03 16:35:37 +000087
Tobias Grosserd1e33e72015-02-19 05:31:07 +000088static cl::opt<bool> DetectUnprofitable("polly-detect-unprofitable",
89 cl::desc("Detect unprofitable scops"),
90 cl::Hidden, cl::init(false),
91 cl::ZeroOrMore, cl::cat(PollyCategory));
92
Tobias Grosser483a90d2014-07-09 10:50:10 +000093static cl::opt<std::string> OnlyFunction(
94 "polly-only-func",
95 cl::desc("Only run on functions that contain a certain string"),
96 cl::value_desc("string"), cl::ValueRequired, cl::init(""),
97 cl::cat(PollyCategory));
Tobias Grosser2ff87232011-10-23 11:17:06 +000098
Tobias Grosser483a90d2014-07-09 10:50:10 +000099static cl::opt<std::string> OnlyRegion(
100 "polly-only-region",
101 cl::desc("Only run on certain regions (The provided identifier must "
102 "appear in the name of the region's entry block"),
103 cl::value_desc("identifier"), cl::ValueRequired, cl::init(""),
104 cl::cat(PollyCategory));
Tobias Grosser4449e522014-01-27 14:24:53 +0000105
Tobias Grosser60cd9322011-11-10 12:47:26 +0000106static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000107 IgnoreAliasing("polly-ignore-aliasing",
108 cl::desc("Ignore possible aliasing of the array bases"),
109 cl::Hidden, cl::init(false), cl::ZeroOrMore,
110 cl::cat(PollyCategory));
Tobias Grosser2ff87232011-10-23 11:17:06 +0000111
Johannes Doerfertb164c792014-09-18 11:17:17 +0000112bool polly::PollyUseRuntimeAliasChecks;
113static cl::opt<bool, true> XPollyUseRuntimeAliasChecks(
114 "polly-use-runtime-alias-checks",
115 cl::desc("Use runtime alias checks to resolve possible aliasing."),
116 cl::location(PollyUseRuntimeAliasChecks), cl::Hidden, cl::ZeroOrMore,
117 cl::init(true), cl::cat(PollyCategory));
118
Tobias Grosser637bd632013-05-07 07:31:10 +0000119static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000120 ReportLevel("polly-report",
121 cl::desc("Print information about the activities of Polly"),
122 cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
Tobias Grosser531891e2012-11-01 16:45:20 +0000123
124static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000125 AllowNonAffine("polly-allow-nonaffine",
126 cl::desc("Allow non affine access functions in arrays"),
127 cl::Hidden, cl::init(false), cl::ZeroOrMore,
128 cl::cat(PollyCategory));
Tobias Grossera1879642011-12-20 10:43:14 +0000129
Johannes Doerfertba65c162015-02-24 11:45:21 +0000130static cl::opt<bool> AllowNonAffineSubRegions(
131 "polly-allow-nonaffine-branches",
132 cl::desc("Allow non affine conditions for branches"), cl::Hidden,
Johannes Doerferta36842f2015-02-26 11:09:24 +0000133 cl::init(true), cl::ZeroOrMore, cl::cat(PollyCategory));
Johannes Doerfertba65c162015-02-24 11:45:21 +0000134
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000135static cl::opt<bool>
136 AllowNonAffineSubLoops("polly-allow-nonaffine-loops",
137 cl::desc("Allow non affine conditions for loops"),
138 cl::Hidden, cl::init(false), cl::ZeroOrMore,
139 cl::cat(PollyCategory));
140
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000141static cl::opt<bool> AllowUnsigned("polly-allow-unsigned",
142 cl::desc("Allow unsigned expressions"),
143 cl::Hidden, cl::init(false), cl::ZeroOrMore,
144 cl::cat(PollyCategory));
145
Tobias Grosserc7d3fc52013-07-25 03:02:29 +0000146static cl::opt<bool, true>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000147 TrackFailures("polly-detect-track-failures",
148 cl::desc("Track failure strings in detecting scop regions"),
149 cl::location(PollyTrackFailures), cl::Hidden, cl::ZeroOrMore,
Andreas Simbuerger3efe40b2014-08-17 10:09:03 +0000150 cl::init(true), cl::cat(PollyCategory));
Tobias Grosserc7d3fc52013-07-25 03:02:29 +0000151
Andreas Simbuerger04472402014-05-24 09:25:10 +0000152static cl::opt<bool> KeepGoing("polly-detect-keep-going",
153 cl::desc("Do not fail on the first error."),
154 cl::Hidden, cl::ZeroOrMore, cl::init(false),
155 cl::cat(PollyCategory));
156
Sebastian Pop18016682014-04-08 21:20:44 +0000157static cl::opt<bool, true>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000158 PollyDelinearizeX("polly-delinearize",
159 cl::desc("Delinearize array access functions"),
160 cl::location(PollyDelinearize), cl::Hidden,
Tobias Grosser6973cb62015-03-08 15:21:18 +0000161 cl::ZeroOrMore, cl::init(true), cl::cat(PollyCategory));
Sebastian Pop18016682014-04-08 21:20:44 +0000162
Tobias Grossera1689932014-02-18 18:49:49 +0000163static cl::opt<bool>
Tobias Grosser483a90d2014-07-09 10:50:10 +0000164 VerifyScops("polly-detect-verify",
165 cl::desc("Verify the detected SCoPs after each transformation"),
166 cl::Hidden, cl::init(false), cl::ZeroOrMore,
167 cl::cat(PollyCategory));
Tobias Grossera1689932014-02-18 18:49:49 +0000168
Tobias Grosserc7d3fc52013-07-25 03:02:29 +0000169bool polly::PollyTrackFailures = false;
Sebastian Pop18016682014-04-08 21:20:44 +0000170bool polly::PollyDelinearize = false;
Johannes Doerfert43e1ead2014-07-15 21:06:48 +0000171StringRef polly::PollySkipFnAttr = "polly.skip.fn";
Tobias Grosserc7d3fc52013-07-25 03:02:29 +0000172
Tobias Grosser75805372011-04-29 06:27:02 +0000173//===----------------------------------------------------------------------===//
174// Statistics.
175
176STATISTIC(ValidRegion, "Number of regions that a valid part of Scop");
177
Tobias Grosser8519f892013-12-18 10:49:53 +0000178class DiagnosticScopFound : public DiagnosticInfo {
179private:
180 static int PluginDiagnosticKind;
181
182 Function &F;
183 std::string FileName;
184 unsigned EntryLine, ExitLine;
185
186public:
Tobias Grosser1b12f462013-12-18 11:14:36 +0000187 DiagnosticScopFound(Function &F, std::string FileName, unsigned EntryLine,
188 unsigned ExitLine)
Tobias Grosser8519f892013-12-18 10:49:53 +0000189 : DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName),
Tobias Grosser1b12f462013-12-18 11:14:36 +0000190 EntryLine(EntryLine), ExitLine(ExitLine) {}
Tobias Grosser8519f892013-12-18 10:49:53 +0000191
192 virtual void print(DiagnosticPrinter &DP) const;
193
194 static bool classof(const DiagnosticInfo *DI) {
195 return DI->getKind() == PluginDiagnosticKind;
196 }
197};
198
199int DiagnosticScopFound::PluginDiagnosticKind = 10;
200
Tobias Grosser8519f892013-12-18 10:49:53 +0000201void DiagnosticScopFound::print(DiagnosticPrinter &DP) const {
Tobias Grosser1b12f462013-12-18 11:14:36 +0000202 DP << "Polly detected an optimizable loop region (scop) in function '" << F
203 << "'\n";
Tobias Grosser8519f892013-12-18 10:49:53 +0000204
205 if (FileName.empty()) {
206 DP << "Scop location is unknown. Compile with debug info "
207 "(-g) to get more precise information. ";
Tobias Grosser1b12f462013-12-18 11:14:36 +0000208 return;
Tobias Grosser8519f892013-12-18 10:49:53 +0000209 }
210
211 DP << FileName << ":" << EntryLine << ": Start of scop\n";
212 DP << FileName << ":" << ExitLine << ": End of scop";
213}
214
Tobias Grosser75805372011-04-29 06:27:02 +0000215//===----------------------------------------------------------------------===//
216// ScopDetection.
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000217
Johannes Doerfertb164c792014-09-18 11:17:17 +0000218ScopDetection::ScopDetection() : FunctionPass(ID) {
219 if (!PollyUseRuntimeAliasChecks)
220 return;
221
Johannes Doerfert928229f2014-09-29 17:06:29 +0000222 // Disable runtime alias checks if we ignore aliasing all together.
223 if (IgnoreAliasing) {
224 PollyUseRuntimeAliasChecks = false;
225 return;
226 }
227
Johannes Doerfertb164c792014-09-18 11:17:17 +0000228 if (AllowNonAffine) {
229 DEBUG(errs() << "WARNING: We disable runtime alias checks as non affine "
230 "accesses are enabled.\n");
231 PollyUseRuntimeAliasChecks = false;
232 }
Johannes Doerfertb164c792014-09-18 11:17:17 +0000233}
234
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000235template <class RR, typename... Args>
236inline bool ScopDetection::invalid(DetectionContext &Context, bool Assert,
237 Args &&... Arguments) const {
238
239 if (!Context.Verifying) {
Andreas Simbuerger4870e092014-05-24 09:25:01 +0000240 RejectLog &Log = Context.Log;
241 std::shared_ptr<RR> RejectReason = std::make_shared<RR>(Arguments...);
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000242
Andreas Simbuerger8a00c9b2014-05-24 09:25:06 +0000243 if (PollyTrackFailures)
Andreas Simbuerger4870e092014-05-24 09:25:01 +0000244 Log.report(RejectReason);
Andreas Simbuerger4870e092014-05-24 09:25:01 +0000245
246 DEBUG(dbgs() << RejectReason->getMessage());
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000247 DEBUG(dbgs() << "\n");
248 } else {
249 assert(!Assert && "Verification of detected scop failed");
250 }
251
252 return false;
253}
254
Tobias Grossera1689932014-02-18 18:49:49 +0000255bool ScopDetection::isMaxRegionInScop(const Region &R, bool Verify) const {
256 if (!ValidRegions.count(&R))
257 return false;
258
Johannes Doerfert3f1c2852015-02-19 18:11:50 +0000259 if (Verify) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000260 BoxedLoopsSetTy DummyBoxedLoopsSet;
Johannes Doerfertba65c162015-02-24 11:45:21 +0000261 NonAffineSubRegionSetTy DummyNonAffineSubRegionSet;
262 DetectionContext Context(const_cast<Region &>(R), *AA,
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000263 DummyNonAffineSubRegionSet, DummyBoxedLoopsSet,
264 false /*verifying*/);
Johannes Doerfert3f1c2852015-02-19 18:11:50 +0000265 return isValidRegion(Context);
266 }
Tobias Grossera1689932014-02-18 18:49:49 +0000267
268 return true;
Tobias Grosser75805372011-04-29 06:27:02 +0000269}
270
Tobias Grosser4f129a62011-10-08 00:30:55 +0000271std::string ScopDetection::regionIsInvalidBecause(const Region *R) const {
Andreas Simbuerger8a00c9b2014-05-24 09:25:06 +0000272 if (!RejectLogs.count(R))
Tobias Grosser4f129a62011-10-08 00:30:55 +0000273 return "";
274
Andreas Simbuerger8a00c9b2014-05-24 09:25:06 +0000275 // Get the first error we found. Even in keep-going mode, this is the first
276 // reason that caused the candidate to be rejected.
277 RejectLog Errors = RejectLogs.at(R);
Andreas Simbuerger83ed8612014-06-12 07:25:08 +0000278
279 // This can happen when we marked a region invalid, but didn't track
280 // an error for it.
281 if (Errors.size() == 0)
282 return "";
283
284 RejectReasonPtr RR = *Errors.begin();
285 return RR->getMessage();
Tobias Grosser4f129a62011-10-08 00:30:55 +0000286}
287
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000288bool ScopDetection::addOverApproximatedRegion(Region *AR,
289 DetectionContext &Context) const {
290
291 // If we already know about Ar we can exit.
292 if (!Context.NonAffineSubRegionSet.insert(AR))
293 return true;
294
295 // All loops in the region have to be overapproximated too if there
296 // are accesses that depend on the iteration count.
297 for (BasicBlock *BB : AR->blocks()) {
Johannes Doerfertba65c162015-02-24 11:45:21 +0000298 Loop *L = LI->getLoopFor(BB);
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000299 if (AR->contains(L))
300 Context.BoxedLoopsSet.insert(L);
Johannes Doerfertba65c162015-02-24 11:45:21 +0000301 }
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000302
303 return (AllowNonAffineSubLoops || Context.BoxedLoopsSet.empty());
Johannes Doerfertba65c162015-02-24 11:45:21 +0000304}
305
Tobias Grossere602a072013-05-07 07:30:56 +0000306bool ScopDetection::isValidCFG(BasicBlock &BB,
307 DetectionContext &Context) const {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000308 Region &CurRegion = Context.CurRegion;
309
Tobias Grosser75805372011-04-29 06:27:02 +0000310 TerminatorInst *TI = BB.getTerminator();
311
312 // Return instructions are only valid if the region is the top level region.
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000313 if (isa<ReturnInst>(TI) && !CurRegion.getExit() && TI->getNumOperands() == 0)
Tobias Grosser75805372011-04-29 06:27:02 +0000314 return true;
315
316 BranchInst *Br = dyn_cast<BranchInst>(TI);
317
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000318 if (!Br)
319 return invalid<ReportNonBranchTerminator>(Context, /*Assert=*/true, &BB);
Tobias Grosser75805372011-04-29 06:27:02 +0000320
Tobias Grosser74394f02013-01-14 22:40:23 +0000321 if (Br->isUnconditional())
322 return true;
Tobias Grosser75805372011-04-29 06:27:02 +0000323
324 Value *Condition = Br->getCondition();
325
326 // UndefValue is not allowed as condition.
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000327 if (isa<UndefValue>(Condition))
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000328 return invalid<ReportUndefCond>(Context, /*Assert=*/true, Br, &BB);
Tobias Grosser75805372011-04-29 06:27:02 +0000329
330 // Only Constant and ICmpInst are allowed as condition.
Johannes Doerfertba65c162015-02-24 11:45:21 +0000331 if (!(isa<Constant>(Condition) || isa<ICmpInst>(Condition))) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000332 if (!AllowNonAffineSubRegions ||
333 !addOverApproximatedRegion(RI->getRegionFor(&BB), Context))
Johannes Doerfertba65c162015-02-24 11:45:21 +0000334 return invalid<ReportInvalidCond>(Context, /*Assert=*/true, Br, &BB);
335 }
Tobias Grosser75805372011-04-29 06:27:02 +0000336
337 // Allow perfectly nested conditions.
338 assert(Br->getNumSuccessors() == 2 && "Unexpected number of successors");
339
340 if (ICmpInst *ICmp = dyn_cast<ICmpInst>(Condition)) {
341 // Unsigned comparisons are not allowed. They trigger overflow problems
342 // in the code generation.
343 //
344 // TODO: This is not sufficient and just hides bugs. However it does pretty
345 // well.
Tobias Grosserbfbc3692015-01-09 00:01:33 +0000346 if (ICmp->isUnsigned() && !AllowUnsigned)
Tobias Grossera8512b12015-05-20 15:37:11 +0000347 return invalid<ReportUnsignedCond>(Context, /*Assert=*/true, Br, &BB);
Tobias Grosser75805372011-04-29 06:27:02 +0000348
349 // Are both operands of the ICmp affine?
Tobias Grosser74394f02013-01-14 22:40:23 +0000350 if (isa<UndefValue>(ICmp->getOperand(0)) ||
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000351 isa<UndefValue>(ICmp->getOperand(1)))
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000352 return invalid<ReportUndefOperand>(Context, /*Assert=*/true, &BB, ICmp);
Tobias Grosser75805372011-04-29 06:27:02 +0000353
Sebastian Pop9f57c5b2013-04-10 04:05:18 +0000354 Loop *L = LI->getLoopFor(ICmp->getParent());
355 const SCEV *LHS = SE->getSCEVAtScope(ICmp->getOperand(0), L);
356 const SCEV *RHS = SE->getSCEVAtScope(ICmp->getOperand(1), L);
Tobias Grosser75805372011-04-29 06:27:02 +0000357
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000358 if (!isAffineExpr(&CurRegion, LHS, *SE) ||
Johannes Doerfertba65c162015-02-24 11:45:21 +0000359 !isAffineExpr(&CurRegion, RHS, *SE)) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000360 if (!AllowNonAffineSubRegions ||
361 !addOverApproximatedRegion(RI->getRegionFor(&BB), Context))
Johannes Doerfertba65c162015-02-24 11:45:21 +0000362 return invalid<ReportNonAffBranch>(Context, /*Assert=*/true, &BB, LHS,
363 RHS, ICmp);
364 }
Tobias Grosser75805372011-04-29 06:27:02 +0000365 }
366
367 // Allow loop exit conditions.
368 Loop *L = LI->getLoopFor(&BB);
369 if (L && L->getExitingBlock() == &BB)
370 return true;
371
372 // Allow perfectly nested conditions.
373 Region *R = RI->getRegionFor(&BB);
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000374 if (R->getEntry() != &BB)
375 return invalid<ReportCondition>(Context, /*Assert=*/true, &BB);
Tobias Grosser75805372011-04-29 06:27:02 +0000376
377 return true;
378}
379
380bool ScopDetection::isValidCallInst(CallInst &CI) {
Johannes Doerfert3f500fa2015-01-25 18:07:30 +0000381 if (CI.doesNotReturn())
Tobias Grosser75805372011-04-29 06:27:02 +0000382 return false;
383
384 if (CI.doesNotAccessMemory())
385 return true;
386
387 Function *CalledFunction = CI.getCalledFunction();
388
389 // Indirect calls are not supported.
390 if (CalledFunction == 0)
391 return false;
392
Johannes Doerfert3f500fa2015-01-25 18:07:30 +0000393 // Check if we can handle the intrinsic call.
394 if (auto *IT = dyn_cast<IntrinsicInst>(&CI)) {
395 switch (IT->getIntrinsicID()) {
396 // Lifetime markers are supported/ignored.
397 case llvm::Intrinsic::lifetime_start:
398 case llvm::Intrinsic::lifetime_end:
399 // Invariant markers are supported/ignored.
400 case llvm::Intrinsic::invariant_start:
401 case llvm::Intrinsic::invariant_end:
402 // Some misc annotations are supported/ignored.
403 case llvm::Intrinsic::var_annotation:
404 case llvm::Intrinsic::ptr_annotation:
405 case llvm::Intrinsic::annotation:
406 case llvm::Intrinsic::donothing:
407 case llvm::Intrinsic::assume:
408 case llvm::Intrinsic::expect:
409 return true;
410 default:
411 // Other intrinsics which may access the memory are not yet supported.
412 break;
413 }
414 }
415
Tobias Grosser75805372011-04-29 06:27:02 +0000416 return false;
417}
418
Tobias Grosser458fb782014-01-28 12:58:58 +0000419bool ScopDetection::isInvariant(const Value &Val, const Region &Reg) const {
420 // A reference to function argument or constant value is invariant.
421 if (isa<Argument>(Val) || isa<Constant>(Val))
422 return true;
423
424 const Instruction *I = dyn_cast<Instruction>(&Val);
425 if (!I)
426 return false;
427
428 if (!Reg.contains(I))
429 return true;
430
431 if (I->mayHaveSideEffects())
432 return false;
433
434 // When Val is a Phi node, it is likely not invariant. We do not check whether
435 // Phi nodes are actually invariant, we assume that Phi nodes are usually not
436 // invariant. Recursively checking the operators of Phi nodes would lead to
437 // infinite recursion.
438 if (isa<PHINode>(*I))
439 return false;
440
Tobias Grosser26108892014-04-02 20:18:19 +0000441 for (const Use &Operand : I->operands())
Tobias Grosser1d191902014-03-03 13:13:55 +0000442 if (!isInvariant(*Operand, Reg))
Tobias Grosser458fb782014-01-28 12:58:58 +0000443 return false;
Tobias Grosser458fb782014-01-28 12:58:58 +0000444
445 // When the instruction is a load instruction, check that no write to memory
446 // in the region aliases with the load.
447 if (const LoadInst *LI = dyn_cast<LoadInst>(I)) {
Chandler Carruthbdb4a392015-06-04 03:49:46 +0000448 auto Loc = MemoryLocation::get(LI);
Johannes Doerfertca08c442015-02-21 16:18:28 +0000449
Tobias Grosser458fb782014-01-28 12:58:58 +0000450 // Check if any basic block in the region can modify the location pointed to
451 // by 'Loc'. If so, 'Val' is (likely) not invariant in the region.
Tobias Grosser26108892014-04-02 20:18:19 +0000452 for (const BasicBlock *BB : Reg.blocks())
Tobias Grosser1d191902014-03-03 13:13:55 +0000453 if (AA->canBasicBlockModify(*BB, Loc))
Tobias Grosser458fb782014-01-28 12:58:58 +0000454 return false;
Tobias Grosser458fb782014-01-28 12:58:58 +0000455 }
456
457 return true;
458}
459
Sebastian Pop422e33f2014-06-03 18:16:31 +0000460MapInsnToMemAcc InsnToMemAcc;
461
Sebastian Popb57c0992014-05-12 20:24:26 +0000462bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000463 Region &CurRegion = Context.CurRegion;
464
Tobias Grosser230acc42014-09-13 14:47:55 +0000465 for (const SCEVUnknown *BasePointer : Context.NonAffineAccesses) {
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000466 Value *BaseValue = BasePointer->getValue();
Tobias Grossera5c092d2015-06-04 16:03:16 +0000467 auto Shape = std::shared_ptr<ArrayShape>(new ArrayShape(BasePointer));
Tobias Grosser230acc42014-09-13 14:47:55 +0000468 bool BasePtrHasNonAffine = false;
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000469
470 // First step: collect parametric terms in all array references.
471 SmallVector<const SCEV *, 4> Terms;
Tobias Grosser230acc42014-09-13 14:47:55 +0000472 for (const auto &Pair : Context.Accesses[BasePointer]) {
Tobias Grosser1b13dde2015-06-29 14:44:22 +0000473 if (auto *AF = dyn_cast<SCEVAddRecExpr>(Pair.second))
Tobias Grosser23bceb22015-06-29 14:44:17 +0000474 SE->collectParametricTerms(AF, Terms);
Tobias Grosser1b13dde2015-06-29 14:44:22 +0000475
476 // In case the outermost expression is a plain add, we check if any of its
477 // terms has the form 4 * %inst * %param * %param ..., aka a term that
478 // contains a product between a parameter and an instruction that is
479 // inside the scop. Such instructions, if allowed at all, are instructions
480 // SCEV can not represent, but Polly is still looking through. As a
481 // result, these instructions can depend on induction variables and are
482 // most likely no array sizes. However, terms that are multiplied with
483 // them are likely candidates for array sizes.
484 if (auto *AF = dyn_cast<SCEVAddExpr>(Pair.second)) {
485 for (auto Op : AF->operands()) {
486 if (auto *AF2 = dyn_cast<SCEVAddRecExpr>(Op))
487 SE->collectParametricTerms(AF2, Terms);
488 if (auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) {
489 SmallVector<const SCEV *, 0> Operands;
Tobias Grosser1b13dde2015-06-29 14:44:22 +0000490
491 for (auto *MulOp : AF2->operands()) {
492 if (auto *Const = dyn_cast<SCEVConstant>(MulOp))
493 Operands.push_back(Const);
494 if (auto *Unknown = dyn_cast<SCEVUnknown>(MulOp)) {
495 if (auto *Inst = dyn_cast<Instruction>(Unknown->getValue())) {
496 if (!Context.CurRegion.contains(Inst))
497 Operands.push_back(MulOp);
Tobias Grosser1b13dde2015-06-29 14:44:22 +0000498
499 } else {
500 Operands.push_back(MulOp);
501 }
502 }
503 }
504 Terms.push_back(SE->getMulExpr(Operands));
505 }
506 }
507 }
Tobias Grosser230acc42014-09-13 14:47:55 +0000508 }
Sebastian Pope8863b82014-05-12 19:02:02 +0000509
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000510 // Second step: find array shape.
Sebastian Pop422e33f2014-06-03 18:16:31 +0000511 SE->findArrayDimensions(Terms, Shape->DelinearizedSizes,
512 Context.ElementSize[BasePointer]);
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000513
Johannes Doerfert89830312015-05-03 16:03:01 +0000514 if (!AllowNonAffine)
Tobias Grosser80e237b2015-07-29 13:52:05 +0000515 for (const SCEV *DelinearizedSize : Shape->DelinearizedSizes) {
516 if (auto *Unknown = dyn_cast<SCEVUnknown>(DelinearizedSize)) {
517 auto *value = dyn_cast<Value>(Unknown->getValue());
518 if (isa<UndefValue>(value)) {
519 invalid<ReportDifferentArrayElementSize>(
520 Context, /*Assert=*/true,
521 Context.Accesses[BasePointer].front().first, BaseValue);
522 return false;
523 }
524 }
Johannes Doerfert89830312015-05-03 16:03:01 +0000525 if (hasScalarDepsInsideRegion(DelinearizedSize, &CurRegion))
526 invalid<ReportNonAffineAccess>(
527 Context, /*Assert=*/true, DelinearizedSize,
528 Context.Accesses[BasePointer].front().first, BaseValue);
Tobias Grosser80e237b2015-07-29 13:52:05 +0000529 }
Johannes Doerfert89830312015-05-03 16:03:01 +0000530
Tobias Grosser230acc42014-09-13 14:47:55 +0000531 // No array shape derived.
532 if (Shape->DelinearizedSizes.empty()) {
533 if (AllowNonAffine)
534 continue;
Sebastian Pope8863b82014-05-12 19:02:02 +0000535
Tobias Grosser230acc42014-09-13 14:47:55 +0000536 for (const auto &Pair : Context.Accesses[BasePointer]) {
537 const Instruction *Insn = Pair.first;
538 const SCEV *AF = Pair.second;
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000539
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000540 if (!isAffineExpr(&CurRegion, AF, *SE, BaseValue)) {
Tobias Grosser230acc42014-09-13 14:47:55 +0000541 invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Insn,
542 BaseValue);
543 if (!KeepGoing)
544 return false;
545 }
546 }
547 continue;
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000548 }
Tobias Grosser230acc42014-09-13 14:47:55 +0000549
550 // Third step: compute the access functions for each subscript.
551 //
552 // We first store the resulting memory accesses in TempMemoryAccesses. Only
553 // if the access functions for all memory accesses have been successfully
554 // delinearized we continue. Otherwise, we either report a failure or, if
555 // non-affine accesses are allowed, we drop the information. In case the
556 // information is dropped the memory accesses need to be overapproximated
557 // when translated to a polyhedral representation.
558 MapInsnToMemAcc TempMemoryAccesses;
559 for (const auto &Pair : Context.Accesses[BasePointer]) {
560 const Instruction *Insn = Pair.first;
Tobias Grosser1b13dde2015-06-29 14:44:22 +0000561 auto *AF = Pair.second;
Tobias Grosser230acc42014-09-13 14:47:55 +0000562 bool IsNonAffine = false;
Tobias Grosserd8308fb2015-06-05 05:52:15 +0000563 TempMemoryAccesses.insert(std::make_pair(Insn, MemAcc(Insn, Shape)));
Tobias Grossera5c092d2015-06-04 16:03:16 +0000564 MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second;
Tobias Grosser230acc42014-09-13 14:47:55 +0000565
566 if (!AF) {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000567 if (isAffineExpr(&CurRegion, Pair.second, *SE, BaseValue))
Tobias Grosser230acc42014-09-13 14:47:55 +0000568 Acc->DelinearizedSubscripts.push_back(Pair.second);
569 else
570 IsNonAffine = true;
571 } else {
Tobias Grosser23bceb22015-06-29 14:44:17 +0000572 SE->computeAccessFunctions(AF, Acc->DelinearizedSubscripts,
Tobias Grosser230acc42014-09-13 14:47:55 +0000573 Shape->DelinearizedSizes);
574 if (Acc->DelinearizedSubscripts.size() == 0)
575 IsNonAffine = true;
576 for (const SCEV *S : Acc->DelinearizedSubscripts)
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000577 if (!isAffineExpr(&CurRegion, S, *SE, BaseValue))
Tobias Grosser230acc42014-09-13 14:47:55 +0000578 IsNonAffine = true;
579 }
580
581 // (Possibly) report non affine access
582 if (IsNonAffine) {
583 BasePtrHasNonAffine = true;
584 if (!AllowNonAffine)
Tobias Grosser021eaef2015-01-08 19:03:10 +0000585 invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, Pair.second,
586 Insn, BaseValue);
Tobias Grosser230acc42014-09-13 14:47:55 +0000587 if (!KeepGoing && !AllowNonAffine)
588 return false;
589 }
590 }
591
592 if (!BasePtrHasNonAffine)
593 InsnToMemAcc.insert(TempMemoryAccesses.begin(), TempMemoryAccesses.end());
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000594 }
Sebastian Pope8863b82014-05-12 19:02:02 +0000595 return true;
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000596}
597
Tobias Grosser75805372011-04-29 06:27:02 +0000598bool ScopDetection::isValidMemoryAccess(Instruction &Inst,
599 DetectionContext &Context) const {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000600 Region &CurRegion = Context.CurRegion;
601
Tobias Grossere5e171e2011-11-10 12:45:03 +0000602 Value *Ptr = getPointerOperand(Inst);
Sebastian Pop9f57c5b2013-04-10 04:05:18 +0000603 Loop *L = LI->getLoopFor(Inst.getParent());
604 const SCEV *AccessFunction = SE->getSCEVAtScope(Ptr, L);
Tobias Grosserb8710b52011-11-10 12:44:50 +0000605 const SCEVUnknown *BasePointer;
Tobias Grossere5e171e2011-11-10 12:45:03 +0000606 Value *BaseValue;
Tobias Grosser75805372011-04-29 06:27:02 +0000607
Tobias Grosserb8710b52011-11-10 12:44:50 +0000608 BasePointer = dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
609
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000610 if (!BasePointer)
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000611 return invalid<ReportNoBasePtr>(Context, /*Assert=*/true, &Inst);
Tobias Grosserb8710b52011-11-10 12:44:50 +0000612
613 BaseValue = BasePointer->getValue();
614
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000615 if (isa<UndefValue>(BaseValue))
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000616 return invalid<ReportUndefBasePtr>(Context, /*Assert=*/true, &Inst);
Tobias Grosserb8710b52011-11-10 12:44:50 +0000617
Tobias Grosser458fb782014-01-28 12:58:58 +0000618 // Check that the base address of the access is invariant in the current
619 // region.
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000620 if (!isInvariant(*BaseValue, CurRegion))
Tobias Grosserab2227a2014-01-28 13:43:24 +0000621 // Verification of this property is difficult as the independent blocks
622 // pass may introduce aliasing that we did not have when running the
623 // scop detection.
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000624 return invalid<ReportVariantBasePtr>(Context, /*Assert=*/false, BaseValue,
625 &Inst);
Tobias Grosser458fb782014-01-28 12:58:58 +0000626
Tobias Grosserb8710b52011-11-10 12:44:50 +0000627 AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
628
Tobias Grosserbcd4eff2014-09-13 14:47:40 +0000629 const SCEV *Size = SE->getElementSize(&Inst);
630 if (Context.ElementSize.count(BasePointer)) {
631 if (Context.ElementSize[BasePointer] != Size)
632 return invalid<ReportDifferentArrayElementSize>(Context, /*Assert=*/true,
633 &Inst, BaseValue);
634 } else {
635 Context.ElementSize[BasePointer] = Size;
636 }
637
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000638 bool isVariantInNonAffineLoop = false;
639 SetVector<const Loop *> Loops;
640 findLoops(AccessFunction, Loops);
641 for (const Loop *L : Loops)
642 if (Context.BoxedLoopsSet.count(L))
643 isVariantInNonAffineLoop = true;
644
645 if (PollyDelinearize && !isVariantInNonAffineLoop) {
Tobias Grosser230acc42014-09-13 14:47:55 +0000646 Context.Accesses[BasePointer].push_back({&Inst, AccessFunction});
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000647
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000648 if (!isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue))
Tobias Grosser230acc42014-09-13 14:47:55 +0000649 Context.NonAffineAccesses.insert(BasePointer);
650 } else if (!AllowNonAffine) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000651 if (isVariantInNonAffineLoop ||
652 !isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue))
Sebastian Popcd3bb592014-04-10 16:08:11 +0000653 return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true,
Andreas Simbuergerd46b9352014-08-17 10:09:11 +0000654 AccessFunction, &Inst, BaseValue);
Sebastian Pop18016682014-04-08 21:20:44 +0000655 }
Tobias Grosser75805372011-04-29 06:27:02 +0000656
657 // FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions
658 // created by IndependentBlocks Pass.
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000659 if (IntToPtrInst *Inst = dyn_cast<IntToPtrInst>(BaseValue))
660 return invalid<ReportIntToPtr>(Context, /*Assert=*/true, Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000661
Tobias Grosser1eedb672014-09-24 21:04:29 +0000662 if (IgnoreAliasing)
Sebastian Pop8c2d7532013-07-03 22:50:36 +0000663 return true;
Tobias Grosserfff5adc2011-11-10 13:21:43 +0000664
Sebastian Pop8c2d7532013-07-03 22:50:36 +0000665 // Check if the base pointer of the memory access does alias with
666 // any other pointer. This cannot be handled at the moment.
Benjamin Kramerae81abf2014-10-05 11:58:57 +0000667 AAMDNodes AATags;
668 Inst.getAAMetadata(AATags);
669 AliasSet &AS = Context.AST.getAliasSetForPointer(
Chandler Carruthafa4ea72015-06-17 08:29:32 +0000670 BaseValue, MemoryLocation::UnknownSize, AATags);
Tobias Grosser428b3e42013-02-04 15:46:25 +0000671
Sebastian Pop8c2d7532013-07-03 22:50:36 +0000672 // INVALID triggers an assertion in verifying mode, if it detects that a
673 // SCoP was detected by SCoP detection and that this SCoP was invalidated by
674 // a pass that stated it would preserve the SCoPs. We disable this check as
675 // the independent blocks pass may create memory references which seem to
676 // alias, if -basicaa is not available. They actually do not, but as we can
677 // not proof this without -basicaa we would fail. We disable this check to
678 // not cause irrelevant verification failures.
Tobias Grosser1eedb672014-09-24 21:04:29 +0000679 if (!AS.isMustAlias()) {
680 if (PollyUseRuntimeAliasChecks) {
681 bool CanBuildRunTimeCheck = true;
682 // The run-time alias check places code that involves the base pointer at
683 // the beginning of the SCoP. This breaks if the base pointer is defined
684 // inside the scop. Hence, we can only create a run-time check if we are
685 // sure the base pointer is not an instruction defined inside the scop.
686 for (const auto &Ptr : AS) {
687 Instruction *Inst = dyn_cast<Instruction>(Ptr.getValue());
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000688 if (Inst && CurRegion.contains(Inst)) {
Tobias Grosser1eedb672014-09-24 21:04:29 +0000689 CanBuildRunTimeCheck = false;
690 break;
691 }
692 }
693
694 if (CanBuildRunTimeCheck)
695 return true;
696 }
Andreas Simbuergere2c92432014-06-26 10:19:57 +0000697 return invalid<ReportAlias>(Context, /*Assert=*/false, &Inst, AS);
Tobias Grosser1eedb672014-09-24 21:04:29 +0000698 }
Tobias Grosser75805372011-04-29 06:27:02 +0000699
700 return true;
701}
702
Tobias Grosser75805372011-04-29 06:27:02 +0000703bool ScopDetection::isValidInstruction(Instruction &Inst,
704 DetectionContext &Context) const {
Tobias Grosser75805372011-04-29 06:27:02 +0000705 // We only check the call instruction but not invoke instruction.
706 if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
707 if (isValidCallInst(*CI))
708 return true;
709
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000710 return invalid<ReportFuncCall>(Context, /*Assert=*/true, &Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000711 }
712
713 if (!Inst.mayWriteToMemory() && !Inst.mayReadFromMemory()) {
Tobias Grosser5b1a7f22013-07-22 03:50:33 +0000714 if (!isa<AllocaInst>(Inst))
715 return true;
Tobias Grosser75805372011-04-29 06:27:02 +0000716
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000717 return invalid<ReportAlloca>(Context, /*Assert=*/true, &Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000718 }
719
720 // Check the access function.
Tobias Grosserd1e33e72015-02-19 05:31:07 +0000721 if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst)) {
722 Context.hasStores |= isa<StoreInst>(Inst);
723 Context.hasLoads |= isa<LoadInst>(Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000724 return isValidMemoryAccess(Inst, Context);
Tobias Grosserd1e33e72015-02-19 05:31:07 +0000725 }
Tobias Grosser75805372011-04-29 06:27:02 +0000726
727 // We do not know this instruction, therefore we assume it is invalid.
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000728 return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000729}
730
Tobias Grosser75805372011-04-29 06:27:02 +0000731bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const {
Tobias Grosser75805372011-04-29 06:27:02 +0000732 // Is the loop count affine?
733 const SCEV *LoopCount = SE->getBackedgeTakenCount(L);
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000734 if (isAffineExpr(&Context.CurRegion, LoopCount, *SE)) {
735 Context.hasAffineLoops = true;
Johannes Doerfertba65c162015-02-24 11:45:21 +0000736 return true;
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000737 }
738
739 if (AllowNonAffineSubRegions) {
740 Region *R = RI->getRegionFor(L->getHeader());
741 if (R->contains(L))
742 if (addOverApproximatedRegion(R, Context))
743 return true;
744 }
Tobias Grosser75805372011-04-29 06:27:02 +0000745
Johannes Doerfertba65c162015-02-24 11:45:21 +0000746 return invalid<ReportLoopBound>(Context, /*Assert=*/true, L, LoopCount);
Tobias Grosser75805372011-04-29 06:27:02 +0000747}
748
749Region *ScopDetection::expandRegion(Region &R) {
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000750 // Initial no valid region was found (greater than R)
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000751 std::unique_ptr<Region> LastValidRegion;
752 auto ExpandedRegion = std::unique_ptr<Region>(R.getExpandedRegion());
Tobias Grosser75805372011-04-29 06:27:02 +0000753
754 DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n");
755
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000756 while (ExpandedRegion) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000757 DetectionContext Context(
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000758 *ExpandedRegion, *AA, NonAffineSubRegionMap[ExpandedRegion.get()],
759 BoxedLoopsMap[ExpandedRegion.get()], false /* verifying */);
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000760 DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n");
Andreas Simbuergerb379edb2014-06-27 06:21:14 +0000761 // Only expand when we did not collect errors.
Tobias Grosser75805372011-04-29 06:27:02 +0000762
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000763 // Check the exit first (cheap)
Andreas Simbuergerb379edb2014-06-27 06:21:14 +0000764 if (isValidExit(Context) && !Context.Log.hasErrors()) {
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000765 // If the exit is valid check all blocks
766 // - if true, a valid region was found => store it + keep expanding
767 // - if false, .tbd. => stop (should this really end the loop?)
Andreas Simbuergerb379edb2014-06-27 06:21:14 +0000768 if (!allBlocksValid(Context) || Context.Log.hasErrors())
769 break;
770
Tobias Grosserd7e58642013-04-10 06:55:45 +0000771 // Store this region, because it is the greatest valid (encountered so
772 // far).
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000773 LastValidRegion = std::move(ExpandedRegion);
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000774
775 // Create and test the next greater region (if any)
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000776 ExpandedRegion =
777 std::unique_ptr<Region>(LastValidRegion->getExpandedRegion());
Hongbin Zhenged986ab2012-04-07 15:14:28 +0000778
779 } else {
780 // Create and test the next greater region (if any)
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000781 ExpandedRegion =
782 std::unique_ptr<Region>(ExpandedRegion->getExpandedRegion());
Tobias Grosser75805372011-04-29 06:27:02 +0000783 }
Tobias Grosser75805372011-04-29 06:27:02 +0000784 }
785
Tobias Grosser378a9f22013-11-16 19:34:11 +0000786 DEBUG({
787 if (LastValidRegion)
788 dbgs() << "\tto " << LastValidRegion->getNameStr() << "\n";
789 else
790 dbgs() << "\tExpanding " << R.getNameStr() << " failed\n";
791 });
Tobias Grosser75805372011-04-29 06:27:02 +0000792
Tobias Grosserd5d93ec2015-06-04 17:59:54 +0000793 return LastValidRegion.release();
Tobias Grosser75805372011-04-29 06:27:02 +0000794}
Sebastian Pop2c9ec2e2013-06-03 16:35:37 +0000795static bool regionWithoutLoops(Region &R, LoopInfo *LI) {
Tobias Grosser26108892014-04-02 20:18:19 +0000796 for (const BasicBlock *BB : R.blocks())
Tobias Grosser1d191902014-03-03 13:13:55 +0000797 if (R.contains(LI->getLoopFor(BB)))
Sebastian Pop2c9ec2e2013-06-03 16:35:37 +0000798 return false;
799
800 return true;
801}
Tobias Grosser75805372011-04-29 06:27:02 +0000802
Tobias Grosser28a70c52014-01-29 19:05:30 +0000803// Remove all direct and indirect children of region R from the region set Regs,
804// but do not recurse further if the first child has been found.
805//
806// Return the number of regions erased from Regs.
David Peixotto8da2b932014-10-22 20:39:07 +0000807static unsigned eraseAllChildren(ScopDetection::RegionSet &Regs,
David Blaikieb035f6d2014-04-15 18:45:27 +0000808 const Region &R) {
Tobias Grosser28a70c52014-01-29 19:05:30 +0000809 unsigned Count = 0;
David Blaikieb035f6d2014-04-15 18:45:27 +0000810 for (auto &SubRegion : R) {
David Peixotto8da2b932014-10-22 20:39:07 +0000811 if (Regs.count(SubRegion.get())) {
Tobias Grosser28a70c52014-01-29 19:05:30 +0000812 ++Count;
David Peixotto8da2b932014-10-22 20:39:07 +0000813 Regs.remove(SubRegion.get());
Tobias Grosser28a70c52014-01-29 19:05:30 +0000814 } else {
David Blaikieb035f6d2014-04-15 18:45:27 +0000815 Count += eraseAllChildren(Regs, *SubRegion);
Tobias Grosser28a70c52014-01-29 19:05:30 +0000816 }
817 }
818 return Count;
819}
820
Tobias Grosser75805372011-04-29 06:27:02 +0000821void ScopDetection::findScops(Region &R) {
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000822 DetectionContext Context(R, *AA, NonAffineSubRegionMap[&R], BoxedLoopsMap[&R],
Johannes Doerfertba65c162015-02-24 11:45:21 +0000823 false /*verifying*/);
Johannes Doerfert6a4d81c2015-03-08 15:11:50 +0000824
825 bool RegionIsValid = false;
826 if (!DetectRegionsWithoutLoops && regionWithoutLoops(R, LI))
827 invalid<ReportUnprofitable>(Context, /*Assert=*/true, &R);
828 else
829 RegionIsValid = isValidRegion(Context);
830
Johannes Doerfert3f1c2852015-02-19 18:11:50 +0000831 bool HasErrors = !RegionIsValid || Context.Log.size() > 0;
Andreas Simbuerger04472402014-05-24 09:25:10 +0000832
Johannes Doerfert3f1c2852015-02-19 18:11:50 +0000833 if (PollyTrackFailures && HasErrors)
834 RejectLogs.insert(std::make_pair(&R, Context.Log));
835
836 if (!HasErrors) {
Tobias Grosser75805372011-04-29 06:27:02 +0000837 ++ValidRegion;
838 ValidRegions.insert(&R);
839 return;
840 }
841
David Blaikieb035f6d2014-04-15 18:45:27 +0000842 for (auto &SubRegion : R)
Tobias Grosser00dc3092014-03-02 12:02:46 +0000843 findScops(*SubRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000844
845 // Try to expand regions.
846 //
847 // As the region tree normally only contains canonical regions, non canonical
848 // regions that form a Scop are not found. Therefore, those non canonical
849 // regions are checked by expanding the canonical ones.
850
Tobias Grosser0d1eee32013-02-05 11:56:05 +0000851 std::vector<Region *> ToExpand;
Tobias Grosser75805372011-04-29 06:27:02 +0000852
David Blaikieb035f6d2014-04-15 18:45:27 +0000853 for (auto &SubRegion : R)
854 ToExpand.push_back(SubRegion.get());
Tobias Grosser75805372011-04-29 06:27:02 +0000855
Tobias Grosser26108892014-04-02 20:18:19 +0000856 for (Region *CurrentRegion : ToExpand) {
Andreas Simbuergerb379edb2014-06-27 06:21:14 +0000857 // Skip regions that had errors.
858 bool HadErrors = RejectLogs.hasErrors(CurrentRegion);
859 if (HadErrors)
860 continue;
861
Tobias Grosser75805372011-04-29 06:27:02 +0000862 // Skip invalid regions. Regions may become invalid, if they are element of
863 // an already expanded region.
David Peixotto8da2b932014-10-22 20:39:07 +0000864 if (!ValidRegions.count(CurrentRegion))
Tobias Grosser75805372011-04-29 06:27:02 +0000865 continue;
866
867 Region *ExpandedR = expandRegion(*CurrentRegion);
868
869 if (!ExpandedR)
870 continue;
871
872 R.addSubRegion(ExpandedR, true);
873 ValidRegions.insert(ExpandedR);
David Peixotto8da2b932014-10-22 20:39:07 +0000874 ValidRegions.remove(CurrentRegion);
Tobias Grosser75805372011-04-29 06:27:02 +0000875
Tobias Grosser28a70c52014-01-29 19:05:30 +0000876 // Erase all (direct and indirect) children of ExpandedR from the valid
877 // regions and update the number of valid regions.
David Blaikieb035f6d2014-04-15 18:45:27 +0000878 ValidRegion -= eraseAllChildren(ValidRegions, *ExpandedR);
Tobias Grosser75805372011-04-29 06:27:02 +0000879 }
880}
881
882bool ScopDetection::allBlocksValid(DetectionContext &Context) const {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000883 Region &CurRegion = Context.CurRegion;
Tobias Grosser75805372011-04-29 06:27:02 +0000884
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000885 for (const BasicBlock *BB : CurRegion.blocks()) {
Tobias Grosser1d191902014-03-03 13:13:55 +0000886 Loop *L = LI->getLoopFor(BB);
Andreas Simbuerger04472402014-05-24 09:25:10 +0000887 if (L && L->getHeader() == BB && (!isValidLoop(L, Context) && !KeepGoing))
Sebastian Popb88ea5e2013-06-11 22:20:32 +0000888 return false;
889 }
890
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000891 for (BasicBlock *BB : CurRegion.blocks())
Andreas Simbuerger04472402014-05-24 09:25:10 +0000892 if (!isValidCFG(*BB, Context) && !KeepGoing)
Sebastian Pop9e3d2dd2013-06-11 22:20:27 +0000893 return false;
894
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000895 for (BasicBlock *BB : CurRegion.blocks())
Tobias Grosser1d191902014-03-03 13:13:55 +0000896 for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I)
Andreas Simbuerger04472402014-05-24 09:25:10 +0000897 if (!isValidInstruction(*I, Context) && !KeepGoing)
Sebastian Pop8ca899c2013-06-14 20:20:43 +0000898 return false;
Tobias Grosser75805372011-04-29 06:27:02 +0000899
Sebastian Pope8863b82014-05-12 19:02:02 +0000900 if (!hasAffineMemoryAccesses(Context))
Sebastian Pop46e1ecd2014-05-09 22:45:15 +0000901 return false;
902
Tobias Grosser75805372011-04-29 06:27:02 +0000903 return true;
904}
905
906bool ScopDetection::isValidExit(DetectionContext &Context) const {
Tobias Grosser75805372011-04-29 06:27:02 +0000907
908 // PHI nodes are not allowed in the exit basic block.
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000909 if (BasicBlock *Exit = Context.CurRegion.getExit()) {
Tobias Grosser75805372011-04-29 06:27:02 +0000910 BasicBlock::iterator I = Exit->begin();
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000911 if (I != Exit->end() && isa<PHINode>(*I))
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000912 return invalid<ReportPHIinExit>(Context, /*Assert=*/true, I);
Tobias Grosser75805372011-04-29 06:27:02 +0000913 }
914
915 return true;
916}
917
918bool ScopDetection::isValidRegion(DetectionContext &Context) const {
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000919 Region &CurRegion = Context.CurRegion;
Tobias Grosser75805372011-04-29 06:27:02 +0000920
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000921 DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t");
Tobias Grosser75805372011-04-29 06:27:02 +0000922
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000923 if (CurRegion.isTopLevelRegion()) {
Tobias Grosserf084edd2014-10-22 23:00:03 +0000924 DEBUG(dbgs() << "Top level region is invalid\n");
Tobias Grosser75805372011-04-29 06:27:02 +0000925 return false;
926 }
927
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000928 if (!CurRegion.getEntry()->getName().count(OnlyRegion)) {
Tobias Grosser4449e522014-01-27 14:24:53 +0000929 DEBUG({
930 dbgs() << "Region entry does not match -polly-region-only";
931 dbgs() << "\n";
932 });
933 return false;
934 }
935
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000936 if (!CurRegion.getEnteringBlock()) {
937 BasicBlock *entry = CurRegion.getEntry();
Sebastian Pop9d632342013-06-11 22:20:40 +0000938 Loop *L = LI->getLoopFor(entry);
939
940 if (L) {
Andreas Simbuerger01a37a02014-04-02 11:54:01 +0000941 if (!L->isLoopSimplifyForm())
942 return invalid<ReportSimpleLoop>(Context, /*Assert=*/true);
Sebastian Pop9d632342013-06-11 22:20:40 +0000943
944 for (pred_iterator PI = pred_begin(entry), PE = pred_end(entry); PI != PE;
945 ++PI) {
946 // Region entering edges come from the same loop but outside the region
947 // are not allowed.
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000948 if (L->contains(*PI) && !CurRegion.contains(*PI))
Andreas Simbuerger5569bf32014-06-26 10:06:40 +0000949 return invalid<ReportIndEdge>(Context, /*Assert=*/true, *PI);
Sebastian Pop9d632342013-06-11 22:20:40 +0000950 }
951 }
Tobias Grosser8edce4e2013-04-16 08:04:42 +0000952 }
953
Tobias Grosserd654c252012-04-10 18:12:19 +0000954 // SCoP cannot contain the entry block of the function, because we need
Tobias Grosser75805372011-04-29 06:27:02 +0000955 // to insert alloca instruction there when translate scalar to array.
Johannes Doerfertfb79a962015-02-23 14:18:28 +0000956 if (CurRegion.getEntry() ==
957 &(CurRegion.getEntry()->getParent()->getEntryBlock()))
958 return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry());
Tobias Grosser75805372011-04-29 06:27:02 +0000959
Hongbin Zheng94868e62012-04-07 12:29:17 +0000960 if (!isValidExit(Context))
Tobias Grosser75805372011-04-29 06:27:02 +0000961 return false;
962
Hongbin Zheng94868e62012-04-07 12:29:17 +0000963 if (!allBlocksValid(Context))
Tobias Grosser75805372011-04-29 06:27:02 +0000964 return false;
965
Tobias Grosserd1e33e72015-02-19 05:31:07 +0000966 // We can probably not do a lot on scops that only write or only read
967 // data.
968 if (!DetectUnprofitable && (!Context.hasStores || !Context.hasLoads))
Johannes Doerfert6a4d81c2015-03-08 15:11:50 +0000969 invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
Tobias Grosserd1e33e72015-02-19 05:31:07 +0000970
Johannes Doerfertf3e98f42015-04-12 22:52:20 +0000971 // Check if there was at least one non-overapproximated loop in the region or
972 // we allow regions without loops.
973 if (!DetectRegionsWithoutLoops && !Context.hasAffineLoops)
974 invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
975
Tobias Grosser75805372011-04-29 06:27:02 +0000976 DEBUG(dbgs() << "OK\n");
977 return true;
978}
979
Johannes Doerfert43e1ead2014-07-15 21:06:48 +0000980void ScopDetection::markFunctionAsInvalid(Function *F) const {
981 F->addFnAttr(PollySkipFnAttr);
982}
983
Tobias Grosser75805372011-04-29 06:27:02 +0000984bool ScopDetection::isValidFunction(llvm::Function &F) {
Johannes Doerfert43e1ead2014-07-15 21:06:48 +0000985 return !F.hasFnAttribute(PollySkipFnAttr);
Tobias Grosser75805372011-04-29 06:27:02 +0000986}
987
Tobias Grosserb2863ca2013-03-04 19:49:51 +0000988void ScopDetection::printLocations(llvm::Function &F) {
Tobias Grosser26108892014-04-02 20:18:19 +0000989 for (const Region *R : *this) {
Tobias Grosser531891e2012-11-01 16:45:20 +0000990 unsigned LineEntry, LineExit;
991 std::string FileName;
992
Tobias Grosser00dc3092014-03-02 12:02:46 +0000993 getDebugLocation(R, LineEntry, LineExit, FileName);
Tobias Grosser8519f892013-12-18 10:49:53 +0000994 DiagnosticScopFound Diagnostic(F, FileName, LineEntry, LineExit);
995 F.getContext().diagnose(Diagnostic);
Tobias Grosser531891e2012-11-01 16:45:20 +0000996 }
997}
998
Daniel Jasper8a1dea02014-10-27 19:45:31 +0000999void ScopDetection::emitMissedRemarksForValidRegions(
1000 const Function &F, const RegionSet &ValidRegions) {
Andreas Simbuerger5569bf32014-06-26 10:06:40 +00001001 for (const Region *R : ValidRegions) {
1002 const Region *Parent = R->getParent();
1003 if (Parent && !Parent->isTopLevelRegion() && RejectLogs.count(Parent))
1004 emitRejectionRemarks(F, RejectLogs.at(Parent));
1005 }
1006}
1007
1008void ScopDetection::emitMissedRemarksForLeaves(const Function &F,
1009 const Region *R) {
1010 for (const std::unique_ptr<Region> &Child : *R) {
1011 bool IsValid = ValidRegions.count(Child.get());
1012 if (IsValid)
1013 continue;
1014
1015 bool IsLeaf = Child->begin() == Child->end();
1016 if (!IsLeaf)
1017 emitMissedRemarksForLeaves(F, Child.get());
1018 else {
1019 if (RejectLogs.count(Child.get())) {
1020 emitRejectionRemarks(F, RejectLogs.at(Child.get()));
1021 }
1022 }
1023 }
1024}
1025
Tobias Grosser75805372011-04-29 06:27:02 +00001026bool ScopDetection::runOnFunction(llvm::Function &F) {
Chandler Carruthf5579872015-01-17 14:16:56 +00001027 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
Matt Arsenault8ca36812014-07-19 18:40:17 +00001028 RI = &getAnalysis<RegionInfoPass>().getRegionInfo();
Sebastian Pop8fe6d112013-05-30 17:47:32 +00001029 if (!DetectScopsWithoutLoops && LI->empty())
1030 return false;
1031
Tobias Grosser75805372011-04-29 06:27:02 +00001032 AA = &getAnalysis<AliasAnalysis>();
Tobias Grosserc5bcf242015-08-17 10:57:08 +00001033 SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
Tobias Grosser75805372011-04-29 06:27:02 +00001034 Region *TopRegion = RI->getTopLevelRegion();
1035
Tobias Grosser2ff87232011-10-23 11:17:06 +00001036 releaseMemory();
1037
Tobias Grossera3ab27e2014-05-07 11:23:32 +00001038 if (OnlyFunction != "" && !F.getName().count(OnlyFunction))
Tobias Grosser2ff87232011-10-23 11:17:06 +00001039 return false;
1040
Tobias Grosser1bb59b02012-12-29 23:47:38 +00001041 if (!isValidFunction(F))
Tobias Grosser75805372011-04-29 06:27:02 +00001042 return false;
1043
1044 findScops(*TopRegion);
Tobias Grosser531891e2012-11-01 16:45:20 +00001045
Andreas Simbuerger5569bf32014-06-26 10:06:40 +00001046 // Only makes sense when we tracked errors.
1047 if (PollyTrackFailures) {
1048 emitMissedRemarksForValidRegions(F, ValidRegions);
1049 emitMissedRemarksForLeaves(F, TopRegion);
1050 }
1051
1052 for (const Region *R : ValidRegions)
1053 emitValidRemarks(F, R);
1054
Johannes Doerferta05214f2014-10-15 23:24:28 +00001055 if (ReportLevel)
Tobias Grosserb2863ca2013-03-04 19:49:51 +00001056 printLocations(F);
Tobias Grosser531891e2012-11-01 16:45:20 +00001057
Tobias Grosser75805372011-04-29 06:27:02 +00001058 return false;
1059}
1060
Johannes Doerfertba65c162015-02-24 11:45:21 +00001061bool ScopDetection::isNonAffineSubRegion(const Region *SubR,
1062 const Region *ScopR) const {
1063 return NonAffineSubRegionMap.lookup(ScopR).count(SubR);
1064}
1065
Johannes Doerfertf3e98f42015-04-12 22:52:20 +00001066const ScopDetection::BoxedLoopsSetTy *
1067ScopDetection::getBoxedLoops(const Region *R) const {
1068 auto BLMIt = BoxedLoopsMap.find(R);
1069 if (BLMIt == BoxedLoopsMap.end())
1070 return nullptr;
1071 return &BLMIt->second;
1072}
1073
Tobias Grosser75805372011-04-29 06:27:02 +00001074void polly::ScopDetection::verifyRegion(const Region &R) const {
1075 assert(isMaxRegionInScop(R) && "Expect R is a valid region.");
Johannes Doerfertf3e98f42015-04-12 22:52:20 +00001076
1077 BoxedLoopsSetTy DummyBoxedLoopsSet;
Johannes Doerfertba65c162015-02-24 11:45:21 +00001078 NonAffineSubRegionSetTy DummyNonAffineSubRegionSet;
1079 DetectionContext Context(const_cast<Region &>(R), *AA,
Johannes Doerfertf3e98f42015-04-12 22:52:20 +00001080 DummyNonAffineSubRegionSet, DummyBoxedLoopsSet,
1081 true /*verifying*/);
Tobias Grosser75805372011-04-29 06:27:02 +00001082 isValidRegion(Context);
1083}
1084
1085void polly::ScopDetection::verifyAnalysis() const {
Tobias Grossera1689932014-02-18 18:49:49 +00001086 if (!VerifyScops)
1087 return;
1088
Tobias Grosser26108892014-04-02 20:18:19 +00001089 for (const Region *R : ValidRegions)
Tobias Grosser00dc3092014-03-02 12:02:46 +00001090 verifyRegion(*R);
Tobias Grosser75805372011-04-29 06:27:02 +00001091}
1092
1093void ScopDetection::getAnalysisUsage(AnalysisUsage &AU) const {
Chandler Carruthf5579872015-01-17 14:16:56 +00001094 AU.addRequired<LoopInfoWrapperPass>();
Tobias Grosserc5bcf242015-08-17 10:57:08 +00001095 AU.addRequired<ScalarEvolutionWrapperPass>();
Tobias Grosser75805372011-04-29 06:27:02 +00001096 // We also need AA and RegionInfo when we are verifying analysis.
1097 AU.addRequiredTransitive<AliasAnalysis>();
Matt Arsenault8ca36812014-07-19 18:40:17 +00001098 AU.addRequiredTransitive<RegionInfoPass>();
Tobias Grosser75805372011-04-29 06:27:02 +00001099 AU.setPreservesAll();
1100}
1101
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001102void ScopDetection::print(raw_ostream &OS, const Module *) const {
Tobias Grosser26108892014-04-02 20:18:19 +00001103 for (const Region *R : ValidRegions)
Tobias Grosser00dc3092014-03-02 12:02:46 +00001104 OS << "Valid Region for Scop: " << R->getNameStr() << '\n';
Tobias Grosser75805372011-04-29 06:27:02 +00001105
1106 OS << "\n";
1107}
1108
1109void ScopDetection::releaseMemory() {
1110 ValidRegions.clear();
Andreas Simbuerger4870e092014-05-24 09:25:01 +00001111 RejectLogs.clear();
Johannes Doerfertba65c162015-02-24 11:45:21 +00001112 NonAffineSubRegionMap.clear();
Tobias Grosser4b6aa6e2015-04-18 11:01:25 +00001113 InsnToMemAcc.clear();
Andreas Simbuerger4870e092014-05-24 09:25:01 +00001114
Hongbin Zheng94c5df12011-05-06 02:38:20 +00001115 // Do not clear the invalid function set.
Tobias Grosser75805372011-04-29 06:27:02 +00001116}
1117
1118char ScopDetection::ID = 0;
1119
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001120Pass *polly::createScopDetectionPass() { return new ScopDetection(); }
1121
Tobias Grosser73600b82011-10-08 00:30:40 +00001122INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect",
1123 "Polly - Detect static control parts (SCoPs)", false,
Tobias Grosser4d96c8d2013-03-23 01:05:07 +00001124 false);
1125INITIALIZE_AG_DEPENDENCY(AliasAnalysis);
Chandler Carruthf5579872015-01-17 14:16:56 +00001126INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
Matt Arsenault8ca36812014-07-19 18:40:17 +00001127INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
Tobias Grosserc5bcf242015-08-17 10:57:08 +00001128INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
Tobias Grosser73600b82011-10-08 00:30:40 +00001129INITIALIZE_PASS_END(ScopDetection, "polly-detect",
1130 "Polly - Detect static control parts (SCoPs)", false, false)