blob: ff77b3bf7bc67e359bcee57d2c970e14c677d906 [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
47#include "polly/ScopDetection.h"
48
49#include "polly/LinkAllPasses.h"
50#include "polly/Support/ScopHelper.h"
51#include "polly/Support/AffineSCEVIterator.h"
52
53#include "llvm/LLVMContext.h"
54#include "llvm/ADT/Statistic.h"
55#include "llvm/Analysis/AliasAnalysis.h"
56#include "llvm/Analysis/RegionIterator.h"
57#include "llvm/Support/CommandLine.h"
58#include "llvm/Assembly/Writer.h"
59
60#define DEBUG_TYPE "polly-detect"
61#include "llvm/Support/Debug.h"
62
63using namespace llvm;
64using namespace polly;
65
66//===----------------------------------------------------------------------===//
67// Statistics.
68
69STATISTIC(ValidRegion, "Number of regions that a valid part of Scop");
70
71#define BADSCOP_STAT(NAME, DESC) STATISTIC(Bad##NAME##ForScop, \
72 "Number of bad regions for Scop: "\
73 DESC)
74
75#define STATSCOP(NAME); assert(!Context.Verifying && #NAME); \
76 if (!Context.Verifying) ++Bad##NAME##ForScop;
77
Tobias Grosserc4a0bd12011-10-08 00:30:48 +000078#define INVALID(NAME, MESSAGE) \
79 do { \
Tobias Grosser4f129a62011-10-08 00:30:55 +000080 std::string Buf; \
81 raw_string_ostream fmt(Buf); \
82 fmt << MESSAGE; \
83 fmt.flush(); \
84 LastFailure = Buf; \
Tobias Grosserc4a0bd12011-10-08 00:30:48 +000085 DEBUG(dbgs() << MESSAGE); \
86 DEBUG(dbgs() << "\n"); \
87 STATSCOP(NAME); \
88 return false; \
89 } while (0);
90
91
Tobias Grosser75805372011-04-29 06:27:02 +000092BADSCOP_STAT(CFG, "CFG too complex");
93BADSCOP_STAT(IndVar, "Non canonical induction variable in loop");
94BADSCOP_STAT(LoopBound, "Loop bounds can not be computed");
95BADSCOP_STAT(FuncCall, "Function call with side effects appeared");
96BADSCOP_STAT(AffFunc, "Expression not affine");
97BADSCOP_STAT(Scalar, "Found scalar dependency");
98BADSCOP_STAT(Alias, "Found base address alias");
99BADSCOP_STAT(SimpleRegion, "Region not simple");
100BADSCOP_STAT(Other, "Others");
101
102//===----------------------------------------------------------------------===//
103// ScopDetection.
104
105bool ScopDetection::isMaxRegionInScop(const Region &R) const {
106 // The Region is valid only if it could be found in the set.
107 return ValidRegions.count(&R);
108}
109
Tobias Grosser4f129a62011-10-08 00:30:55 +0000110std::string ScopDetection::regionIsInvalidBecause(const Region *R) const {
111 if (!InvalidRegions.count(R))
112 return "";
113
114 return InvalidRegions.find(R)->second;
115}
116
117
Tobias Grosser75805372011-04-29 06:27:02 +0000118bool ScopDetection::isValidAffineFunction(const SCEV *S, Region &RefRegion,
119 Value **BasePtr) const {
120 assert(S && "S must not be null!");
121 bool isMemoryAccess = (BasePtr != 0);
122 if (isMemoryAccess) *BasePtr = 0;
123 DEBUG(dbgs() << "Checking " << *S << " ... ");
124
125 if (isa<SCEVCouldNotCompute>(S)) {
126 DEBUG(dbgs() << "Non Affine: SCEV could not be computed\n");
127 return false;
128 }
129
130 for (AffineSCEVIterator I = affine_begin(S, SE), E = affine_end(); I != E;
131 ++I) {
132 // The constant part must be a SCEVConstant.
133 // TODO: support sizeof in coefficient.
134 if (!isa<SCEVConstant>(I->second)) {
135 DEBUG(dbgs() << "Non Affine: Right hand side is not constant\n");
136 return false;
137 }
138
139 const SCEV *Var = I->first;
140
141 // A constant offset is affine.
142 if(isa<SCEVConstant>(Var))
143 continue;
144
145 // Memory accesses are allowed to have a base pointer.
146 if (Var->getType()->isPointerTy()) {
147 if (!isMemoryAccess) {
148 DEBUG(dbgs() << "Non Affine: Pointer in non memory access\n");
149 return false;
150 }
151
152 assert(I->second->isOne() && "Only one as pointer coefficient allowed.\n");
153 const SCEVUnknown *BaseAddr = dyn_cast<SCEVUnknown>(Var);
154
155 if (!BaseAddr || isa<UndefValue>(BaseAddr->getValue())){
156 DEBUG(dbgs() << "Cannot handle base: " << *Var << "\n");
157 return false;
158 }
159
160 // BaseAddr must be invariant in Scop.
161 if (!isParameter(BaseAddr, RefRegion, *LI, *SE)) {
162 DEBUG(dbgs() << "Non Affine: Base address not invariant in SCoP\n");
163 return false;
164 }
165
166 assert(*BasePtr == 0 && "Found second base pointer.\n");
167 *BasePtr = BaseAddr->getValue();
168 continue;
169 }
170
171 if (isParameter(Var, RefRegion, *LI, *SE)
172 || isIndVar(Var, RefRegion, *LI, *SE))
173 continue;
174
175 DEBUG(dbgs() << "Non Affine: " ;
176 Var->print(dbgs());
177 dbgs() << " is neither parameter nor induction variable\n");
178 return false;
179 }
180
181 DEBUG(dbgs() << " is affine.\n");
182 return !isMemoryAccess || (*BasePtr != 0);
183}
184
185bool ScopDetection::isValidCFG(BasicBlock &BB, DetectionContext &Context) const
186{
187 Region &RefRegion = Context.CurRegion;
188 TerminatorInst *TI = BB.getTerminator();
189
190 // Return instructions are only valid if the region is the top level region.
191 if (isa<ReturnInst>(TI) && !RefRegion.getExit() && TI->getNumOperands() == 0)
192 return true;
193
194 BranchInst *Br = dyn_cast<BranchInst>(TI);
195
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000196 if (!Br)
197 INVALID(CFG, "Non branch instruction terminates BB: " + BB.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000198
199 if (Br->isUnconditional()) return true;
200
201 Value *Condition = Br->getCondition();
202
203 // UndefValue is not allowed as condition.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000204 if (isa<UndefValue>(Condition))
205 INVALID(AffFunc, "Condition based on 'undef' value in BB: "
206 + BB.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000207
208 // Only Constant and ICmpInst are allowed as condition.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000209 if (!(isa<Constant>(Condition) || isa<ICmpInst>(Condition)))
210 INVALID(AffFunc, "Condition in BB '" + BB.getNameStr() + "' neither "
211 "constant nor an icmp instruction");
Tobias Grosser75805372011-04-29 06:27:02 +0000212
213 // Allow perfectly nested conditions.
214 assert(Br->getNumSuccessors() == 2 && "Unexpected number of successors");
215
216 if (ICmpInst *ICmp = dyn_cast<ICmpInst>(Condition)) {
217 // Unsigned comparisons are not allowed. They trigger overflow problems
218 // in the code generation.
219 //
220 // TODO: This is not sufficient and just hides bugs. However it does pretty
221 // well.
222 if(ICmp->isUnsigned())
223 return false;
224
225 // Are both operands of the ICmp affine?
226 if (isa<UndefValue>(ICmp->getOperand(0))
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000227 || isa<UndefValue>(ICmp->getOperand(1)))
228 INVALID(AffFunc, "undef operand in branch at BB: " + BB.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000229
230 const SCEV *ScevLHS = SE->getSCEV(ICmp->getOperand(0));
231 const SCEV *ScevRHS = SE->getSCEV(ICmp->getOperand(1));
232
233 bool affineLHS = isValidAffineFunction(ScevLHS, RefRegion);
234 bool affineRHS = isValidAffineFunction(ScevRHS, RefRegion);
235
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000236 if (!affineLHS || !affineRHS)
237 INVALID(AffFunc, "Non affine branch in BB: " + BB.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000238 }
239
240 // Allow loop exit conditions.
241 Loop *L = LI->getLoopFor(&BB);
242 if (L && L->getExitingBlock() == &BB)
243 return true;
244
245 // Allow perfectly nested conditions.
246 Region *R = RI->getRegionFor(&BB);
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000247 if (R->getEntry() != &BB)
248 INVALID(CFG, "Not well structured condition at BB: " + BB.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000249
250 return true;
251}
252
253bool ScopDetection::isValidCallInst(CallInst &CI) {
254 if (CI.mayHaveSideEffects() || CI.doesNotReturn())
255 return false;
256
257 if (CI.doesNotAccessMemory())
258 return true;
259
260 Function *CalledFunction = CI.getCalledFunction();
261
262 // Indirect calls are not supported.
263 if (CalledFunction == 0)
264 return false;
265
266 // TODO: Intrinsics.
267 return false;
268}
269
270bool ScopDetection::isValidMemoryAccess(Instruction &Inst,
271 DetectionContext &Context) const {
272 Value *Ptr = getPointerOperand(Inst), *BasePtr;
273 const SCEV *AccessFunction = SE->getSCEV(Ptr);
274
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000275 if (!isValidAffineFunction(AccessFunction, Context.CurRegion, &BasePtr))
276 INVALID(AffFunc, "Bad memory address " << *AccessFunction);
Tobias Grosser75805372011-04-29 06:27:02 +0000277
278 // FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions
279 // created by IndependentBlocks Pass.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000280 if (isa<IntToPtrInst>(BasePtr))
281 INVALID(Other, "Find bad intoptr prt: " << *BasePtr);
Tobias Grosser75805372011-04-29 06:27:02 +0000282
283 // Check if the base pointer of the memory access does alias with
284 // any other pointer. This cannot be handled at the moment.
285 AliasSet &AS =
286 Context.AST.getAliasSetForPointer(BasePtr, AliasAnalysis::UnknownSize,
287 Inst.getMetadata(LLVMContext::MD_tbaa));
288 if (!AS.isMustAlias()) {
289 DEBUG(dbgs() << "Bad pointer alias found:" << *BasePtr << "\nAS:\n" << AS);
290
291 // STATSCOP triggers an assertion if we are in verifying mode.
292 // This is generally good to check that we do not change the SCoP after we
293 // run the SCoP detection and consequently to ensure that we can still
294 // represent that SCoP. However, in case of aliasing this does not work.
295 // The independent blocks pass may create memory references which seem to
296 // alias, if -basicaa is not available. They actually do not. As we do not
297 // not know this and we would fail here if we verify it.
298 if (!Context.Verifying) {
299 STATSCOP(Alias);
300 }
301
302 return false;
303 }
304
305 return true;
306}
307
308
309bool ScopDetection::hasScalarDependency(Instruction &Inst,
310 Region &RefRegion) const {
311 for (Instruction::use_iterator UI = Inst.use_begin(), UE = Inst.use_end();
312 UI != UE; ++UI)
313 if (Instruction *Use = dyn_cast<Instruction>(*UI))
314 if (!RefRegion.contains(Use->getParent())) {
315 // DirtyHack 1: PHINode user outside the Scop is not allow, if this
316 // PHINode is induction variable, the scalar to array transform may
317 // break it and introduce a non-indvar PHINode, which is not allow in
318 // Scop.
319 // This can be fix by:
320 // Introduce a IndependentBlockPrepare pass, which translate all
321 // PHINodes not in Scop to array.
322 // The IndependentBlockPrepare pass can also split the entry block of
323 // the function to hold the alloca instruction created by scalar to
324 // array. and split the exit block of the Scop so the new create load
325 // instruction for escape users will not break other Scops.
326 if (isa<PHINode>(Use))
327 return true;
328 }
329
330 return false;
331}
332
333bool ScopDetection::isValidInstruction(Instruction &Inst,
334 DetectionContext &Context) const {
335 // Only canonical IVs are allowed.
336 if (PHINode *PN = dyn_cast<PHINode>(&Inst))
337 if (!isIndVar(PN, LI)) {
338 DEBUG(dbgs() << "Non canonical PHI node found: ";
339 WriteAsOperand(dbgs(), &Inst, false);
340 dbgs() << "\n");
341 return false;
342 }
343
344 // Scalar dependencies are not allowed.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000345 if (hasScalarDependency(Inst, Context.CurRegion))
346 INVALID(Scalar, "Scalar dependency found: " << Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000347
348 // We only check the call instruction but not invoke instruction.
349 if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
350 if (isValidCallInst(*CI))
351 return true;
352
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000353 INVALID(FuncCall, "Call instruction not allowed: " << Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000354 }
355
356 if (!Inst.mayWriteToMemory() && !Inst.mayReadFromMemory()) {
357 // Handle cast instruction.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000358 if (isa<IntToPtrInst>(Inst) || isa<BitCastInst>(Inst))
359 INVALID(Other, "Cast instruction not allowed: " << Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000360
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000361 if (isa<AllocaInst>(Inst))
362 INVALID(Other, "Alloca instruction not allowed: " << Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000363
364 return true;
365 }
366
367 // Check the access function.
368 if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
369 return isValidMemoryAccess(Inst, Context);
370
371 // We do not know this instruction, therefore we assume it is invalid.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000372 INVALID(Other, "Unknown instruction: " << Inst);
Tobias Grosser75805372011-04-29 06:27:02 +0000373}
374
375bool ScopDetection::isValidBasicBlock(BasicBlock &BB,
376 DetectionContext &Context) const {
377 if (!isValidCFG(BB, Context))
378 return false;
379
380 // Check all instructions, except the terminator instruction.
381 for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I)
382 if (!isValidInstruction(*I, Context))
383 return false;
384
385 Loop *L = LI->getLoopFor(&BB);
386 if (L && L->getHeader() == &BB && !isValidLoop(L, Context))
387 return false;
388
389 return true;
390}
391
392bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const {
393 PHINode *IndVar = L->getCanonicalInductionVariable();
394 // No canonical induction variable.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000395 if (!IndVar)
396 INVALID(IndVar, "No single induction variable for loop: "
397 << L->getHeader()->getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000398
399 // Is the loop count affine?
400 const SCEV *LoopCount = SE->getBackedgeTakenCount(L);
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000401 if (!isValidAffineFunction(LoopCount, Context.CurRegion))
402 INVALID(LoopBound, "Non affine loop bound for loop: "
403 << L->getHeader()->getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000404
405 return true;
406}
407
408Region *ScopDetection::expandRegion(Region &R) {
409 Region *CurrentRegion = &R;
410 Region *TmpRegion = R.getExpandedRegion();
411
412 DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n");
413
414 while (TmpRegion) {
415 DetectionContext Context(*TmpRegion, *AA, false /*verifying*/);
416 DEBUG(dbgs() << "\t\tTrying " << TmpRegion->getNameStr() << "\n");
417
418 if (!allBlocksValid(Context))
419 break;
420
421 if (isValidExit(Context)) {
422 if (CurrentRegion != &R)
423 delete CurrentRegion;
424
425 CurrentRegion = TmpRegion;
426 }
427
428 Region *TmpRegion2 = TmpRegion->getExpandedRegion();
429
430 if (TmpRegion != &R && TmpRegion != CurrentRegion)
431 delete TmpRegion;
432
433 TmpRegion = TmpRegion2;
434 }
435
436 if (&R == CurrentRegion)
437 return NULL;
438
439 DEBUG(dbgs() << "\tto " << CurrentRegion->getNameStr() << "\n");
440
441 return CurrentRegion;
442}
443
444
445void ScopDetection::findScops(Region &R) {
446 DetectionContext Context(R, *AA, false /*verifying*/);
447
448 if (isValidRegion(Context)) {
449 ++ValidRegion;
450 ValidRegions.insert(&R);
451 return;
452 }
453
Tobias Grosser4f129a62011-10-08 00:30:55 +0000454 InvalidRegions[&R] = LastFailure;
455
Tobias Grosser75805372011-04-29 06:27:02 +0000456 for (Region::iterator I = R.begin(), E = R.end(); I != E; ++I)
457 findScops(**I);
458
459 // Try to expand regions.
460 //
461 // As the region tree normally only contains canonical regions, non canonical
462 // regions that form a Scop are not found. Therefore, those non canonical
463 // regions are checked by expanding the canonical ones.
464
465 std::vector<Region*> ToExpand;
466
467 for (Region::iterator I = R.begin(), E = R.end(); I != E; ++I)
468 ToExpand.push_back(*I);
469
470 for (std::vector<Region*>::iterator RI = ToExpand.begin(),
471 RE = ToExpand.end(); RI != RE; ++RI) {
472 Region *CurrentRegion = *RI;
473
474 // Skip invalid regions. Regions may become invalid, if they are element of
475 // an already expanded region.
476 if (ValidRegions.find(CurrentRegion) == ValidRegions.end())
477 continue;
478
479 Region *ExpandedR = expandRegion(*CurrentRegion);
480
481 if (!ExpandedR)
482 continue;
483
484 R.addSubRegion(ExpandedR, true);
485 ValidRegions.insert(ExpandedR);
486 ValidRegions.erase(CurrentRegion);
487
488 for (Region::iterator I = ExpandedR->begin(), E = ExpandedR->end(); I != E;
489 ++I)
490 ValidRegions.erase(*I);
491 }
492}
493
494bool ScopDetection::allBlocksValid(DetectionContext &Context) const {
495 Region &R = Context.CurRegion;
496
497 for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E;
498 ++I)
499 if (!isValidBasicBlock(*(I->getNodeAs<BasicBlock>()), Context))
500 return false;
501
502 return true;
503}
504
505bool ScopDetection::isValidExit(DetectionContext &Context) const {
506 Region &R = Context.CurRegion;
507
508 // PHI nodes are not allowed in the exit basic block.
509 if (BasicBlock *Exit = R.getExit()) {
510 BasicBlock::iterator I = Exit->begin();
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000511 if (I != Exit->end() && isa<PHINode> (*I))
512 INVALID(Other, "PHI node in exit BB");
Tobias Grosser75805372011-04-29 06:27:02 +0000513 }
514
515 return true;
516}
517
518bool ScopDetection::isValidRegion(DetectionContext &Context) const {
519 Region &R = Context.CurRegion;
520
521 DEBUG(dbgs() << "Checking region: " << R.getNameStr() << "\n\t");
522
523 // The toplevel region is no valid region.
524 if (!R.getParent()) {
525 DEBUG(dbgs() << "Top level region is invalid";
526 dbgs() << "\n");
527 return false;
528 }
529
530 // SCoP can not contains the entry block of the function, because we need
531 // to insert alloca instruction there when translate scalar to array.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000532 if (R.getEntry() == &(R.getEntry()->getParent()->getEntryBlock()))
533 INVALID(Other, "Region containing entry block of function is invalid!");
Tobias Grosser75805372011-04-29 06:27:02 +0000534
535 // Only a simple region is allowed.
Tobias Grosserc4a0bd12011-10-08 00:30:48 +0000536 if (!R.isSimple())
537 INVALID(SimpleRegion, "Region not simple: " << R.getNameStr());
Tobias Grosser75805372011-04-29 06:27:02 +0000538
539 if (!allBlocksValid(Context))
540 return false;
541
542 if (!isValidExit(Context))
543 return false;
544
545 DEBUG(dbgs() << "OK\n");
546 return true;
547}
548
549bool ScopDetection::isValidFunction(llvm::Function &F) {
Hongbin Zheng94c5df12011-05-06 02:38:20 +0000550 return !InvalidFunctions.count(&F);
Tobias Grosser75805372011-04-29 06:27:02 +0000551}
552
553bool ScopDetection::runOnFunction(llvm::Function &F) {
554 AA = &getAnalysis<AliasAnalysis>();
555 SE = &getAnalysis<ScalarEvolution>();
556 LI = &getAnalysis<LoopInfo>();
557 RI = &getAnalysis<RegionInfo>();
558 Region *TopRegion = RI->getTopLevelRegion();
559
560 if(!isValidFunction(F))
561 return false;
562
563 findScops(*TopRegion);
564 return false;
565}
566
567
568void polly::ScopDetection::verifyRegion(const Region &R) const {
569 assert(isMaxRegionInScop(R) && "Expect R is a valid region.");
570 DetectionContext Context(const_cast<Region&>(R), *AA, true /*verifying*/);
571 isValidRegion(Context);
572}
573
574void polly::ScopDetection::verifyAnalysis() const {
575 for (RegionSet::const_iterator I = ValidRegions.begin(),
576 E = ValidRegions.end(); I != E; ++I)
577 verifyRegion(**I);
578}
579
580void ScopDetection::getAnalysisUsage(AnalysisUsage &AU) const {
581 AU.addRequired<DominatorTree>();
582 AU.addRequired<PostDominatorTree>();
583 AU.addRequired<LoopInfo>();
584 AU.addRequired<ScalarEvolution>();
585 // We also need AA and RegionInfo when we are verifying analysis.
586 AU.addRequiredTransitive<AliasAnalysis>();
587 AU.addRequiredTransitive<RegionInfo>();
588 AU.setPreservesAll();
589}
590
591void ScopDetection::print(raw_ostream &OS, const Module *) const {
592 for (RegionSet::const_iterator I = ValidRegions.begin(),
593 E = ValidRegions.end(); I != E; ++I)
594 OS << "Valid Region for Scop: " << (*I)->getNameStr() << '\n';
595
596 OS << "\n";
597}
598
599void ScopDetection::releaseMemory() {
600 ValidRegions.clear();
Tobias Grosser4f129a62011-10-08 00:30:55 +0000601 InvalidRegions.clear();
Hongbin Zheng94c5df12011-05-06 02:38:20 +0000602 // Do not clear the invalid function set.
Tobias Grosser75805372011-04-29 06:27:02 +0000603}
604
605char ScopDetection::ID = 0;
606
Tobias Grosser73600b82011-10-08 00:30:40 +0000607INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect",
608 "Polly - Detect static control parts (SCoPs)", false,
609 false)
610INITIALIZE_AG_DEPENDENCY(AliasAnalysis)
611INITIALIZE_PASS_DEPENDENCY(DominatorTree)
612INITIALIZE_PASS_DEPENDENCY(LoopInfo)
613INITIALIZE_PASS_DEPENDENCY(PostDominatorTree)
614INITIALIZE_PASS_DEPENDENCY(RegionInfo)
615INITIALIZE_PASS_DEPENDENCY(ScalarEvolution)
616INITIALIZE_PASS_END(ScopDetection, "polly-detect",
617 "Polly - Detect static control parts (SCoPs)", false, false)
Tobias Grosser75805372011-04-29 06:27:02 +0000618
Tobias Grosser83f5c432011-08-23 22:35:08 +0000619Pass *polly::createScopDetectionPass() {
620 return new ScopDetection();
621}