Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 1 | //===----- 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 | |
| 63 | using namespace llvm; |
| 64 | using namespace polly; |
| 65 | |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 66 | static cl::opt<std::string> |
| 67 | OnlyFunction("polly-detect-only", |
| 68 | cl::desc("Only detect scops in function"), cl::Hidden, |
| 69 | cl::value_desc("The function name to detect scops in"), |
| 70 | cl::ValueRequired, cl::init("")); |
| 71 | |
| 72 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 73 | //===----------------------------------------------------------------------===// |
| 74 | // Statistics. |
| 75 | |
| 76 | STATISTIC(ValidRegion, "Number of regions that a valid part of Scop"); |
| 77 | |
| 78 | #define BADSCOP_STAT(NAME, DESC) STATISTIC(Bad##NAME##ForScop, \ |
| 79 | "Number of bad regions for Scop: "\ |
| 80 | DESC) |
| 81 | |
| 82 | #define STATSCOP(NAME); assert(!Context.Verifying && #NAME); \ |
| 83 | if (!Context.Verifying) ++Bad##NAME##ForScop; |
| 84 | |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 85 | #define INVALID(NAME, MESSAGE) \ |
| 86 | do { \ |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 87 | std::string Buf; \ |
| 88 | raw_string_ostream fmt(Buf); \ |
| 89 | fmt << MESSAGE; \ |
| 90 | fmt.flush(); \ |
| 91 | LastFailure = Buf; \ |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 92 | DEBUG(dbgs() << MESSAGE); \ |
| 93 | DEBUG(dbgs() << "\n"); \ |
| 94 | STATSCOP(NAME); \ |
| 95 | return false; \ |
| 96 | } while (0); |
| 97 | |
| 98 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 99 | BADSCOP_STAT(CFG, "CFG too complex"); |
| 100 | BADSCOP_STAT(IndVar, "Non canonical induction variable in loop"); |
| 101 | BADSCOP_STAT(LoopBound, "Loop bounds can not be computed"); |
| 102 | BADSCOP_STAT(FuncCall, "Function call with side effects appeared"); |
| 103 | BADSCOP_STAT(AffFunc, "Expression not affine"); |
| 104 | BADSCOP_STAT(Scalar, "Found scalar dependency"); |
| 105 | BADSCOP_STAT(Alias, "Found base address alias"); |
| 106 | BADSCOP_STAT(SimpleRegion, "Region not simple"); |
| 107 | BADSCOP_STAT(Other, "Others"); |
| 108 | |
| 109 | //===----------------------------------------------------------------------===// |
| 110 | // ScopDetection. |
| 111 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 112 | namespace SCEVType { |
| 113 | enum TYPE {INT, PARAM, IV, INVALID}; |
| 114 | } |
| 115 | |
| 116 | /// Check if a SCEV is valid in a SCoP. |
| 117 | struct SCEVValidator : public SCEVVisitor<SCEVValidator, SCEVType::TYPE> { |
| 118 | private: |
| 119 | const Region *R; |
| 120 | ScalarEvolution &SE; |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 121 | Value **BaseAddress; |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 122 | |
| 123 | public: |
| 124 | static bool isValid(const Region *R, const SCEV *Scev, |
| 125 | ScalarEvolution &SE, |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 126 | Value **BaseAddress = NULL) { |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 127 | if (isa<SCEVCouldNotCompute>(Scev)) |
| 128 | return false; |
| 129 | |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 130 | if (BaseAddress) |
| 131 | *BaseAddress = NULL; |
| 132 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 133 | SCEVValidator Validator(R, SE, BaseAddress); |
| 134 | return Validator.visit(Scev) != SCEVType::INVALID; |
| 135 | } |
| 136 | |
| 137 | SCEVValidator(const Region *R, ScalarEvolution &SE, |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 138 | Value **BaseAddress) : R(R), SE(SE), |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 139 | BaseAddress(BaseAddress) {}; |
| 140 | |
| 141 | SCEVType::TYPE visitConstant(const SCEVConstant *Constant) { |
| 142 | return SCEVType::INT; |
| 143 | } |
| 144 | |
| 145 | SCEVType::TYPE visitTruncateExpr(const SCEVTruncateExpr* Expr) { |
| 146 | SCEVType::TYPE Op = visit(Expr->getOperand()); |
| 147 | |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 148 | // We currently do not represent a truncate expression as an affine |
| 149 | // expression. If it is constant during Scop execution, we treat it as a |
| 150 | // parameter, otherwise we bail out. |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 151 | if (Op == SCEVType::INT || Op == SCEVType::PARAM) |
| 152 | return SCEVType::PARAM; |
| 153 | |
| 154 | return SCEVType::INVALID; |
| 155 | } |
| 156 | |
| 157 | SCEVType::TYPE visitZeroExtendExpr(const SCEVZeroExtendExpr * Expr) { |
| 158 | SCEVType::TYPE Op = visit(Expr->getOperand()); |
| 159 | |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 160 | // We currently do not represent a zero extend expression as an affine |
| 161 | // expression. If it is constant during Scop execution, we treat it as a |
| 162 | // parameter, otherwise we bail out. |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 163 | if (Op == SCEVType::INT || Op == SCEVType::PARAM) |
| 164 | return SCEVType::PARAM; |
| 165 | |
| 166 | return SCEVType::INVALID; |
| 167 | } |
| 168 | |
| 169 | SCEVType::TYPE visitSignExtendExpr(const SCEVSignExtendExpr* Expr) { |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 170 | // We currently allow only signed SCEV expressions. In the case of a |
| 171 | // signed value, a sign extend is a noop. |
| 172 | // |
| 173 | // TODO: Reconsider this when we add support for unsigned values. |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 174 | return visit(Expr->getOperand()); |
| 175 | } |
| 176 | |
| 177 | SCEVType::TYPE visitAddExpr(const SCEVAddExpr* Expr) { |
| 178 | SCEVType::TYPE Return = SCEVType::INT; |
| 179 | |
| 180 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 181 | SCEVType::TYPE OpType = visit(Expr->getOperand(i)); |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 182 | |
| 183 | if (OpType == SCEVType::INVALID) |
| 184 | return SCEVType::INVALID; |
| 185 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 186 | Return = std::max(Return, OpType); |
| 187 | } |
| 188 | |
| 189 | // TODO: Check for NSW and NUW. |
| 190 | return Return; |
| 191 | } |
| 192 | |
| 193 | SCEVType::TYPE visitMulExpr(const SCEVMulExpr* Expr) { |
| 194 | SCEVType::TYPE Return = SCEVType::INT; |
| 195 | |
| 196 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 197 | SCEVType::TYPE OpType = visit(Expr->getOperand(i)); |
| 198 | |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 199 | if (OpType == SCEVType::INT) |
| 200 | continue; |
| 201 | |
| 202 | if (OpType == SCEVType::INVALID || Return != SCEVType::INT) |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 203 | return SCEVType::INVALID; |
| 204 | |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 205 | Return = OpType; |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | // TODO: Check for NSW and NUW. |
| 209 | return Return; |
| 210 | } |
| 211 | |
| 212 | SCEVType::TYPE visitUDivExpr(const SCEVUDivExpr* Expr) { |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 213 | SCEVType::TYPE LHS = visit(Expr->getLHS()); |
| 214 | SCEVType::TYPE RHS = visit(Expr->getRHS()); |
| 215 | |
| 216 | // We currently do not represent a unsigned devision as an affine |
| 217 | // expression. If the division is constant during Scop execution we treat it |
| 218 | // as a parameter, otherwise we bail out. |
| 219 | if (LHS == SCEVType::INT || LHS == SCEVType::PARAM || |
| 220 | RHS == SCEVType::INT || RHS == SCEVType::PARAM) |
| 221 | return SCEVType::PARAM; |
| 222 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 223 | return SCEVType::INVALID; |
| 224 | } |
| 225 | |
| 226 | SCEVType::TYPE visitAddRecExpr(const SCEVAddRecExpr* Expr) { |
| 227 | if (!Expr->isAffine()) |
| 228 | return SCEVType::INVALID; |
| 229 | |
| 230 | SCEVType::TYPE Start = visit(Expr->getStart()); |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 231 | SCEVType::TYPE Recurrence = visit(Expr->getStepRecurrence(SE)); |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 232 | |
| 233 | if (Start == SCEVType::INVALID || |
| 234 | Recurrence == SCEVType::INVALID || |
| 235 | Recurrence == SCEVType::IV) |
| 236 | return SCEVType::INVALID; |
| 237 | |
| 238 | if (!R->contains(Expr->getLoop())) { |
| 239 | if (Start == SCEVType::IV) |
| 240 | return SCEVType::INVALID; |
| 241 | else |
| 242 | return SCEVType::PARAM; |
| 243 | } |
| 244 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 245 | if (Recurrence != SCEVType::INT) |
| 246 | return SCEVType::INVALID; |
| 247 | |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 248 | return SCEVType::IV; |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | SCEVType::TYPE visitSMaxExpr(const SCEVSMaxExpr* Expr) { |
| 252 | SCEVType::TYPE Return = SCEVType::INT; |
| 253 | |
| 254 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 255 | SCEVType::TYPE OpType = visit(Expr->getOperand(i)); |
| 256 | |
| 257 | if (OpType == SCEVType::INVALID) |
| 258 | return SCEVType::INVALID; |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 259 | |
| 260 | Return = std::max(Return, OpType); |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | return Return; |
| 264 | } |
| 265 | |
| 266 | SCEVType::TYPE visitUMaxExpr(const SCEVUMaxExpr* Expr) { |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 267 | // We do not support unsigned operations. If 'Expr' is constant during Scop |
| 268 | // execution we treat this as a parameter, otherwise we bail out. |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 269 | for (int i = 0, e = Expr->getNumOperands(); i < e; ++i) { |
| 270 | SCEVType::TYPE OpType = visit(Expr->getOperand(i)); |
| 271 | |
| 272 | if (OpType != SCEVType::INT && OpType != SCEVType::PARAM) |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 273 | return SCEVType::INVALID; |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return SCEVType::PARAM; |
| 277 | } |
| 278 | |
| 279 | SCEVType::TYPE visitUnknown(const SCEVUnknown* Expr) { |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 280 | Value *V = Expr->getValue(); |
| 281 | |
| 282 | if (isa<UndefValue>(V)) |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 283 | return SCEVType::INVALID; |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 284 | |
| 285 | if (BaseAddress) { |
| 286 | if (*BaseAddress) |
| 287 | return SCEVType::INVALID; |
| 288 | else |
| 289 | *BaseAddress = V; |
| 290 | } |
| 291 | |
Tobias Grosser | ad96c4b | 2011-11-03 21:03:01 +0000 | [diff] [blame] | 292 | if (Instruction *I = dyn_cast<Instruction>(Expr->getValue())) |
| 293 | if (R->contains(I)) |
| 294 | return SCEVType::INVALID; |
Tobias Grosser | 2d0b1f9 | 2011-11-04 10:08:08 +0000 | [diff] [blame] | 295 | |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 296 | return SCEVType::PARAM; |
| 297 | } |
| 298 | }; |
| 299 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 300 | bool ScopDetection::isMaxRegionInScop(const Region &R) const { |
| 301 | // The Region is valid only if it could be found in the set. |
| 302 | return ValidRegions.count(&R); |
| 303 | } |
| 304 | |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 305 | std::string ScopDetection::regionIsInvalidBecause(const Region *R) const { |
| 306 | if (!InvalidRegions.count(R)) |
| 307 | return ""; |
| 308 | |
| 309 | return InvalidRegions.find(R)->second; |
| 310 | } |
| 311 | |
| 312 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 313 | bool ScopDetection::isValidAffineFunction(const SCEV *S, Region &RefRegion, |
| 314 | Value **BasePtr) const { |
| 315 | assert(S && "S must not be null!"); |
| 316 | bool isMemoryAccess = (BasePtr != 0); |
| 317 | if (isMemoryAccess) *BasePtr = 0; |
| 318 | DEBUG(dbgs() << "Checking " << *S << " ... "); |
| 319 | |
| 320 | if (isa<SCEVCouldNotCompute>(S)) { |
| 321 | DEBUG(dbgs() << "Non Affine: SCEV could not be computed\n"); |
| 322 | return false; |
| 323 | } |
| 324 | |
| 325 | for (AffineSCEVIterator I = affine_begin(S, SE), E = affine_end(); I != E; |
| 326 | ++I) { |
| 327 | // The constant part must be a SCEVConstant. |
| 328 | // TODO: support sizeof in coefficient. |
| 329 | if (!isa<SCEVConstant>(I->second)) { |
| 330 | DEBUG(dbgs() << "Non Affine: Right hand side is not constant\n"); |
| 331 | return false; |
| 332 | } |
| 333 | |
| 334 | const SCEV *Var = I->first; |
| 335 | |
| 336 | // A constant offset is affine. |
| 337 | if(isa<SCEVConstant>(Var)) |
| 338 | continue; |
| 339 | |
| 340 | // Memory accesses are allowed to have a base pointer. |
| 341 | if (Var->getType()->isPointerTy()) { |
| 342 | if (!isMemoryAccess) { |
| 343 | DEBUG(dbgs() << "Non Affine: Pointer in non memory access\n"); |
| 344 | return false; |
| 345 | } |
| 346 | |
| 347 | assert(I->second->isOne() && "Only one as pointer coefficient allowed.\n"); |
| 348 | const SCEVUnknown *BaseAddr = dyn_cast<SCEVUnknown>(Var); |
| 349 | |
| 350 | if (!BaseAddr || isa<UndefValue>(BaseAddr->getValue())){ |
| 351 | DEBUG(dbgs() << "Cannot handle base: " << *Var << "\n"); |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | // BaseAddr must be invariant in Scop. |
| 356 | if (!isParameter(BaseAddr, RefRegion, *LI, *SE)) { |
| 357 | DEBUG(dbgs() << "Non Affine: Base address not invariant in SCoP\n"); |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | assert(*BasePtr == 0 && "Found second base pointer.\n"); |
| 362 | *BasePtr = BaseAddr->getValue(); |
| 363 | continue; |
| 364 | } |
| 365 | |
| 366 | if (isParameter(Var, RefRegion, *LI, *SE) |
| 367 | || isIndVar(Var, RefRegion, *LI, *SE)) |
| 368 | continue; |
| 369 | |
| 370 | DEBUG(dbgs() << "Non Affine: " ; |
| 371 | Var->print(dbgs()); |
| 372 | dbgs() << " is neither parameter nor induction variable\n"); |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | DEBUG(dbgs() << " is affine.\n"); |
| 377 | return !isMemoryAccess || (*BasePtr != 0); |
| 378 | } |
| 379 | |
| 380 | bool ScopDetection::isValidCFG(BasicBlock &BB, DetectionContext &Context) const |
| 381 | { |
| 382 | Region &RefRegion = Context.CurRegion; |
| 383 | TerminatorInst *TI = BB.getTerminator(); |
| 384 | |
| 385 | // Return instructions are only valid if the region is the top level region. |
| 386 | if (isa<ReturnInst>(TI) && !RefRegion.getExit() && TI->getNumOperands() == 0) |
| 387 | return true; |
| 388 | |
| 389 | BranchInst *Br = dyn_cast<BranchInst>(TI); |
| 390 | |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 391 | if (!Br) |
| 392 | INVALID(CFG, "Non branch instruction terminates BB: " + BB.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 393 | |
| 394 | if (Br->isUnconditional()) return true; |
| 395 | |
| 396 | Value *Condition = Br->getCondition(); |
| 397 | |
| 398 | // UndefValue is not allowed as condition. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 399 | if (isa<UndefValue>(Condition)) |
| 400 | INVALID(AffFunc, "Condition based on 'undef' value in BB: " |
| 401 | + BB.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 402 | |
| 403 | // Only Constant and ICmpInst are allowed as condition. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 404 | if (!(isa<Constant>(Condition) || isa<ICmpInst>(Condition))) |
| 405 | INVALID(AffFunc, "Condition in BB '" + BB.getNameStr() + "' neither " |
| 406 | "constant nor an icmp instruction"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 407 | |
| 408 | // Allow perfectly nested conditions. |
| 409 | assert(Br->getNumSuccessors() == 2 && "Unexpected number of successors"); |
| 410 | |
| 411 | if (ICmpInst *ICmp = dyn_cast<ICmpInst>(Condition)) { |
| 412 | // Unsigned comparisons are not allowed. They trigger overflow problems |
| 413 | // in the code generation. |
| 414 | // |
| 415 | // TODO: This is not sufficient and just hides bugs. However it does pretty |
| 416 | // well. |
| 417 | if(ICmp->isUnsigned()) |
| 418 | return false; |
| 419 | |
| 420 | // Are both operands of the ICmp affine? |
| 421 | if (isa<UndefValue>(ICmp->getOperand(0)) |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 422 | || isa<UndefValue>(ICmp->getOperand(1))) |
| 423 | INVALID(AffFunc, "undef operand in branch at BB: " + BB.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 424 | |
| 425 | const SCEV *ScevLHS = SE->getSCEV(ICmp->getOperand(0)); |
| 426 | const SCEV *ScevRHS = SE->getSCEV(ICmp->getOperand(1)); |
| 427 | |
Tobias Grosser | 2fea5c6 | 2011-11-03 21:03:14 +0000 | [diff] [blame] | 428 | bool affineLHS = SCEVValidator::isValid(&Context.CurRegion, ScevLHS, *SE); |
| 429 | bool affineRHS = SCEVValidator::isValid(&Context.CurRegion, ScevRHS, *SE); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 430 | |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 431 | if (!affineLHS || !affineRHS) |
| 432 | INVALID(AffFunc, "Non affine branch in BB: " + BB.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | // Allow loop exit conditions. |
| 436 | Loop *L = LI->getLoopFor(&BB); |
| 437 | if (L && L->getExitingBlock() == &BB) |
| 438 | return true; |
| 439 | |
| 440 | // Allow perfectly nested conditions. |
| 441 | Region *R = RI->getRegionFor(&BB); |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 442 | if (R->getEntry() != &BB) |
| 443 | INVALID(CFG, "Not well structured condition at BB: " + BB.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 444 | |
| 445 | return true; |
| 446 | } |
| 447 | |
| 448 | bool ScopDetection::isValidCallInst(CallInst &CI) { |
| 449 | if (CI.mayHaveSideEffects() || CI.doesNotReturn()) |
| 450 | return false; |
| 451 | |
| 452 | if (CI.doesNotAccessMemory()) |
| 453 | return true; |
| 454 | |
| 455 | Function *CalledFunction = CI.getCalledFunction(); |
| 456 | |
| 457 | // Indirect calls are not supported. |
| 458 | if (CalledFunction == 0) |
| 459 | return false; |
| 460 | |
| 461 | // TODO: Intrinsics. |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | bool ScopDetection::isValidMemoryAccess(Instruction &Inst, |
| 466 | DetectionContext &Context) const { |
| 467 | Value *Ptr = getPointerOperand(Inst), *BasePtr; |
| 468 | const SCEV *AccessFunction = SE->getSCEV(Ptr); |
| 469 | |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 470 | if (!SCEVValidator::isValid(&Context.CurRegion, AccessFunction, *SE, |
| 471 | &BasePtr)) |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 472 | INVALID(AffFunc, "Bad memory address " << *AccessFunction); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 473 | |
Tobias Grosser | 7616467 | 2011-11-03 21:03:18 +0000 | [diff] [blame] | 474 | // FIXME: Also check with isValidAffineFunction, as for the moment it is |
| 475 | // protecting us to fail because of not supported features in TempScop. |
| 476 | // As soon as TempScop is fixed, this needs to be removed. |
| 477 | if (!isValidAffineFunction(AccessFunction, Context.CurRegion, &BasePtr)) |
| 478 | INVALID(AffFunc, "Access not supported in TempScop" << *AccessFunction); |
| 479 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 480 | // FIXME: Alias Analysis thinks IntToPtrInst aliases with alloca instructions |
| 481 | // created by IndependentBlocks Pass. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 482 | if (isa<IntToPtrInst>(BasePtr)) |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 483 | INVALID(Other, "Find bad intToptr prt: " << *BasePtr); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 484 | |
| 485 | // Check if the base pointer of the memory access does alias with |
| 486 | // any other pointer. This cannot be handled at the moment. |
| 487 | AliasSet &AS = |
| 488 | Context.AST.getAliasSetForPointer(BasePtr, AliasAnalysis::UnknownSize, |
| 489 | Inst.getMetadata(LLVMContext::MD_tbaa)); |
| 490 | if (!AS.isMustAlias()) { |
| 491 | DEBUG(dbgs() << "Bad pointer alias found:" << *BasePtr << "\nAS:\n" << AS); |
| 492 | |
| 493 | // STATSCOP triggers an assertion if we are in verifying mode. |
| 494 | // This is generally good to check that we do not change the SCoP after we |
| 495 | // run the SCoP detection and consequently to ensure that we can still |
| 496 | // represent that SCoP. However, in case of aliasing this does not work. |
| 497 | // The independent blocks pass may create memory references which seem to |
| 498 | // alias, if -basicaa is not available. They actually do not. As we do not |
| 499 | // not know this and we would fail here if we verify it. |
| 500 | if (!Context.Verifying) { |
| 501 | STATSCOP(Alias); |
| 502 | } |
| 503 | |
| 504 | return false; |
| 505 | } |
| 506 | |
| 507 | return true; |
| 508 | } |
| 509 | |
| 510 | |
| 511 | bool ScopDetection::hasScalarDependency(Instruction &Inst, |
| 512 | Region &RefRegion) const { |
| 513 | for (Instruction::use_iterator UI = Inst.use_begin(), UE = Inst.use_end(); |
| 514 | UI != UE; ++UI) |
| 515 | if (Instruction *Use = dyn_cast<Instruction>(*UI)) |
| 516 | if (!RefRegion.contains(Use->getParent())) { |
| 517 | // DirtyHack 1: PHINode user outside the Scop is not allow, if this |
| 518 | // PHINode is induction variable, the scalar to array transform may |
| 519 | // break it and introduce a non-indvar PHINode, which is not allow in |
| 520 | // Scop. |
| 521 | // This can be fix by: |
| 522 | // Introduce a IndependentBlockPrepare pass, which translate all |
| 523 | // PHINodes not in Scop to array. |
| 524 | // The IndependentBlockPrepare pass can also split the entry block of |
| 525 | // the function to hold the alloca instruction created by scalar to |
| 526 | // array. and split the exit block of the Scop so the new create load |
| 527 | // instruction for escape users will not break other Scops. |
| 528 | if (isa<PHINode>(Use)) |
| 529 | return true; |
| 530 | } |
| 531 | |
| 532 | return false; |
| 533 | } |
| 534 | |
| 535 | bool ScopDetection::isValidInstruction(Instruction &Inst, |
| 536 | DetectionContext &Context) const { |
| 537 | // Only canonical IVs are allowed. |
| 538 | if (PHINode *PN = dyn_cast<PHINode>(&Inst)) |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 539 | if (!isIndVar(PN, LI)) |
| 540 | INVALID(IndVar, "Non canonical PHI node: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 541 | |
| 542 | // Scalar dependencies are not allowed. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 543 | if (hasScalarDependency(Inst, Context.CurRegion)) |
| 544 | INVALID(Scalar, "Scalar dependency found: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 545 | |
| 546 | // We only check the call instruction but not invoke instruction. |
| 547 | if (CallInst *CI = dyn_cast<CallInst>(&Inst)) { |
| 548 | if (isValidCallInst(*CI)) |
| 549 | return true; |
| 550 | |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 551 | INVALID(FuncCall, "Call instruction: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | if (!Inst.mayWriteToMemory() && !Inst.mayReadFromMemory()) { |
| 555 | // Handle cast instruction. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 556 | if (isa<IntToPtrInst>(Inst) || isa<BitCastInst>(Inst)) |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 557 | INVALID(Other, "Cast instruction: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 558 | |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 559 | if (isa<AllocaInst>(Inst)) |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 560 | INVALID(Other, "Alloca instruction: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 561 | |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | // Check the access function. |
| 566 | if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst)) |
| 567 | return isValidMemoryAccess(Inst, Context); |
| 568 | |
| 569 | // We do not know this instruction, therefore we assume it is invalid. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 570 | INVALID(Other, "Unknown instruction: " << Inst); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | bool ScopDetection::isValidBasicBlock(BasicBlock &BB, |
| 574 | DetectionContext &Context) const { |
| 575 | if (!isValidCFG(BB, Context)) |
| 576 | return false; |
| 577 | |
| 578 | // Check all instructions, except the terminator instruction. |
| 579 | for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) |
| 580 | if (!isValidInstruction(*I, Context)) |
| 581 | return false; |
| 582 | |
| 583 | Loop *L = LI->getLoopFor(&BB); |
| 584 | if (L && L->getHeader() == &BB && !isValidLoop(L, Context)) |
| 585 | return false; |
| 586 | |
| 587 | return true; |
| 588 | } |
| 589 | |
| 590 | bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const { |
| 591 | PHINode *IndVar = L->getCanonicalInductionVariable(); |
| 592 | // No canonical induction variable. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 593 | if (!IndVar) |
Tobias Grosser | b43ba82 | 2011-10-08 00:49:30 +0000 | [diff] [blame] | 594 | INVALID(IndVar, "No canonical IV at loop header: " |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 595 | << L->getHeader()->getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 596 | |
| 597 | // Is the loop count affine? |
| 598 | const SCEV *LoopCount = SE->getBackedgeTakenCount(L); |
Tobias Grosser | 3fb4992 | 2011-11-02 21:40:08 +0000 | [diff] [blame] | 599 | if (!SCEVValidator::isValid(&Context.CurRegion, LoopCount, *SE)) |
Tobias Grosser | bd54f32 | 2011-10-26 01:27:49 +0000 | [diff] [blame] | 600 | INVALID(LoopBound, "Non affine loop bound '" << *LoopCount << "' in loop: " |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 601 | << L->getHeader()->getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 602 | |
| 603 | return true; |
| 604 | } |
| 605 | |
| 606 | Region *ScopDetection::expandRegion(Region &R) { |
| 607 | Region *CurrentRegion = &R; |
| 608 | Region *TmpRegion = R.getExpandedRegion(); |
| 609 | |
| 610 | DEBUG(dbgs() << "\tExpanding " << R.getNameStr() << "\n"); |
| 611 | |
| 612 | while (TmpRegion) { |
| 613 | DetectionContext Context(*TmpRegion, *AA, false /*verifying*/); |
| 614 | DEBUG(dbgs() << "\t\tTrying " << TmpRegion->getNameStr() << "\n"); |
| 615 | |
| 616 | if (!allBlocksValid(Context)) |
| 617 | break; |
| 618 | |
| 619 | if (isValidExit(Context)) { |
| 620 | if (CurrentRegion != &R) |
| 621 | delete CurrentRegion; |
| 622 | |
| 623 | CurrentRegion = TmpRegion; |
| 624 | } |
| 625 | |
| 626 | Region *TmpRegion2 = TmpRegion->getExpandedRegion(); |
| 627 | |
| 628 | if (TmpRegion != &R && TmpRegion != CurrentRegion) |
| 629 | delete TmpRegion; |
| 630 | |
| 631 | TmpRegion = TmpRegion2; |
| 632 | } |
| 633 | |
| 634 | if (&R == CurrentRegion) |
| 635 | return NULL; |
| 636 | |
| 637 | DEBUG(dbgs() << "\tto " << CurrentRegion->getNameStr() << "\n"); |
| 638 | |
| 639 | return CurrentRegion; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | void ScopDetection::findScops(Region &R) { |
| 644 | DetectionContext Context(R, *AA, false /*verifying*/); |
| 645 | |
| 646 | if (isValidRegion(Context)) { |
| 647 | ++ValidRegion; |
| 648 | ValidRegions.insert(&R); |
| 649 | return; |
| 650 | } |
| 651 | |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 652 | InvalidRegions[&R] = LastFailure; |
| 653 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 654 | for (Region::iterator I = R.begin(), E = R.end(); I != E; ++I) |
| 655 | findScops(**I); |
| 656 | |
| 657 | // Try to expand regions. |
| 658 | // |
| 659 | // As the region tree normally only contains canonical regions, non canonical |
| 660 | // regions that form a Scop are not found. Therefore, those non canonical |
| 661 | // regions are checked by expanding the canonical ones. |
| 662 | |
| 663 | std::vector<Region*> ToExpand; |
| 664 | |
| 665 | for (Region::iterator I = R.begin(), E = R.end(); I != E; ++I) |
| 666 | ToExpand.push_back(*I); |
| 667 | |
| 668 | for (std::vector<Region*>::iterator RI = ToExpand.begin(), |
| 669 | RE = ToExpand.end(); RI != RE; ++RI) { |
| 670 | Region *CurrentRegion = *RI; |
| 671 | |
| 672 | // Skip invalid regions. Regions may become invalid, if they are element of |
| 673 | // an already expanded region. |
| 674 | if (ValidRegions.find(CurrentRegion) == ValidRegions.end()) |
| 675 | continue; |
| 676 | |
| 677 | Region *ExpandedR = expandRegion(*CurrentRegion); |
| 678 | |
| 679 | if (!ExpandedR) |
| 680 | continue; |
| 681 | |
| 682 | R.addSubRegion(ExpandedR, true); |
| 683 | ValidRegions.insert(ExpandedR); |
| 684 | ValidRegions.erase(CurrentRegion); |
| 685 | |
| 686 | for (Region::iterator I = ExpandedR->begin(), E = ExpandedR->end(); I != E; |
| 687 | ++I) |
| 688 | ValidRegions.erase(*I); |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | bool ScopDetection::allBlocksValid(DetectionContext &Context) const { |
| 693 | Region &R = Context.CurRegion; |
| 694 | |
| 695 | for (Region::block_iterator I = R.block_begin(), E = R.block_end(); I != E; |
| 696 | ++I) |
| 697 | if (!isValidBasicBlock(*(I->getNodeAs<BasicBlock>()), Context)) |
| 698 | return false; |
| 699 | |
| 700 | return true; |
| 701 | } |
| 702 | |
| 703 | bool ScopDetection::isValidExit(DetectionContext &Context) const { |
| 704 | Region &R = Context.CurRegion; |
| 705 | |
| 706 | // PHI nodes are not allowed in the exit basic block. |
| 707 | if (BasicBlock *Exit = R.getExit()) { |
| 708 | BasicBlock::iterator I = Exit->begin(); |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 709 | if (I != Exit->end() && isa<PHINode> (*I)) |
| 710 | INVALID(Other, "PHI node in exit BB"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | return true; |
| 714 | } |
| 715 | |
| 716 | bool ScopDetection::isValidRegion(DetectionContext &Context) const { |
| 717 | Region &R = Context.CurRegion; |
| 718 | |
| 719 | DEBUG(dbgs() << "Checking region: " << R.getNameStr() << "\n\t"); |
| 720 | |
| 721 | // The toplevel region is no valid region. |
| 722 | if (!R.getParent()) { |
| 723 | DEBUG(dbgs() << "Top level region is invalid"; |
| 724 | dbgs() << "\n"); |
| 725 | return false; |
| 726 | } |
| 727 | |
| 728 | // SCoP can not contains the entry block of the function, because we need |
| 729 | // to insert alloca instruction there when translate scalar to array. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 730 | if (R.getEntry() == &(R.getEntry()->getParent()->getEntryBlock())) |
| 731 | INVALID(Other, "Region containing entry block of function is invalid!"); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 732 | |
| 733 | // Only a simple region is allowed. |
Tobias Grosser | c4a0bd1 | 2011-10-08 00:30:48 +0000 | [diff] [blame] | 734 | if (!R.isSimple()) |
| 735 | INVALID(SimpleRegion, "Region not simple: " << R.getNameStr()); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 736 | |
| 737 | if (!allBlocksValid(Context)) |
| 738 | return false; |
| 739 | |
| 740 | if (!isValidExit(Context)) |
| 741 | return false; |
| 742 | |
| 743 | DEBUG(dbgs() << "OK\n"); |
| 744 | return true; |
| 745 | } |
| 746 | |
| 747 | bool ScopDetection::isValidFunction(llvm::Function &F) { |
Hongbin Zheng | 94c5df1 | 2011-05-06 02:38:20 +0000 | [diff] [blame] | 748 | return !InvalidFunctions.count(&F); |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | bool ScopDetection::runOnFunction(llvm::Function &F) { |
| 752 | AA = &getAnalysis<AliasAnalysis>(); |
| 753 | SE = &getAnalysis<ScalarEvolution>(); |
| 754 | LI = &getAnalysis<LoopInfo>(); |
| 755 | RI = &getAnalysis<RegionInfo>(); |
| 756 | Region *TopRegion = RI->getTopLevelRegion(); |
| 757 | |
Tobias Grosser | 2ff8723 | 2011-10-23 11:17:06 +0000 | [diff] [blame] | 758 | releaseMemory(); |
| 759 | |
| 760 | if (OnlyFunction != "" && F.getNameStr() != OnlyFunction) |
| 761 | return false; |
| 762 | |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 763 | if(!isValidFunction(F)) |
| 764 | return false; |
| 765 | |
| 766 | findScops(*TopRegion); |
| 767 | return false; |
| 768 | } |
| 769 | |
| 770 | |
| 771 | void polly::ScopDetection::verifyRegion(const Region &R) const { |
| 772 | assert(isMaxRegionInScop(R) && "Expect R is a valid region."); |
| 773 | DetectionContext Context(const_cast<Region&>(R), *AA, true /*verifying*/); |
| 774 | isValidRegion(Context); |
| 775 | } |
| 776 | |
| 777 | void polly::ScopDetection::verifyAnalysis() const { |
| 778 | for (RegionSet::const_iterator I = ValidRegions.begin(), |
| 779 | E = ValidRegions.end(); I != E; ++I) |
| 780 | verifyRegion(**I); |
| 781 | } |
| 782 | |
| 783 | void ScopDetection::getAnalysisUsage(AnalysisUsage &AU) const { |
| 784 | AU.addRequired<DominatorTree>(); |
| 785 | AU.addRequired<PostDominatorTree>(); |
| 786 | AU.addRequired<LoopInfo>(); |
| 787 | AU.addRequired<ScalarEvolution>(); |
| 788 | // We also need AA and RegionInfo when we are verifying analysis. |
| 789 | AU.addRequiredTransitive<AliasAnalysis>(); |
| 790 | AU.addRequiredTransitive<RegionInfo>(); |
| 791 | AU.setPreservesAll(); |
| 792 | } |
| 793 | |
| 794 | void ScopDetection::print(raw_ostream &OS, const Module *) const { |
| 795 | for (RegionSet::const_iterator I = ValidRegions.begin(), |
| 796 | E = ValidRegions.end(); I != E; ++I) |
| 797 | OS << "Valid Region for Scop: " << (*I)->getNameStr() << '\n'; |
| 798 | |
| 799 | OS << "\n"; |
| 800 | } |
| 801 | |
| 802 | void ScopDetection::releaseMemory() { |
| 803 | ValidRegions.clear(); |
Tobias Grosser | 4f129a6 | 2011-10-08 00:30:55 +0000 | [diff] [blame] | 804 | InvalidRegions.clear(); |
Hongbin Zheng | 94c5df1 | 2011-05-06 02:38:20 +0000 | [diff] [blame] | 805 | // Do not clear the invalid function set. |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | char ScopDetection::ID = 0; |
| 809 | |
Tobias Grosser | 73600b8 | 2011-10-08 00:30:40 +0000 | [diff] [blame] | 810 | INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect", |
| 811 | "Polly - Detect static control parts (SCoPs)", false, |
| 812 | false) |
| 813 | INITIALIZE_AG_DEPENDENCY(AliasAnalysis) |
| 814 | INITIALIZE_PASS_DEPENDENCY(DominatorTree) |
| 815 | INITIALIZE_PASS_DEPENDENCY(LoopInfo) |
| 816 | INITIALIZE_PASS_DEPENDENCY(PostDominatorTree) |
| 817 | INITIALIZE_PASS_DEPENDENCY(RegionInfo) |
| 818 | INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) |
| 819 | INITIALIZE_PASS_END(ScopDetection, "polly-detect", |
| 820 | "Polly - Detect static control parts (SCoPs)", false, false) |
Tobias Grosser | 7580537 | 2011-04-29 06:27:02 +0000 | [diff] [blame] | 821 | |
Tobias Grosser | 83f5c43 | 2011-08-23 22:35:08 +0000 | [diff] [blame] | 822 | Pass *polly::createScopDetectionPass() { |
| 823 | return new ScopDetection(); |
| 824 | } |