Index: polly/trunk/include/polly/TempScopInfo.h =================================================================== --- polly/trunk/include/polly/TempScopInfo.h +++ polly/trunk/include/polly/TempScopInfo.h @@ -127,9 +127,6 @@ // The Region. Region &R; - // The max loop depth of this Scop - unsigned MaxLoopDepth; - // Remember the bounds of loops, to help us build iteration domain of BBs. const LoopBoundMapType &LoopBounds; const BBCondMapType &BBConds; @@ -141,8 +138,7 @@ explicit TempScop(Region &r, LoopBoundMapType &loopBounds, BBCondMapType &BBCmps, AccFuncMapType &accFuncMap) - : R(r), MaxLoopDepth(0), LoopBounds(loopBounds), BBConds(BBCmps), - AccFuncMap(accFuncMap) {} + : R(r), LoopBounds(loopBounds), BBConds(BBCmps), AccFuncMap(accFuncMap) {} public: ~TempScop(); @@ -152,11 +148,6 @@ /// @return The maximum Region contained by this Scop. Region &getMaxRegion() const { return R; } - /// @brief Get the maximum loop depth of Region R. - /// - /// @return The maximum loop depth of Region R. - unsigned getMaxLoopDepth() const { return MaxLoopDepth; } - /// @brief Get the loop bounds of the given loop. /// /// @param L The loop to get the bounds. Index: polly/trunk/lib/Analysis/ScopInfo.cpp =================================================================== --- polly/trunk/lib/Analysis/ScopInfo.cpp +++ polly/trunk/lib/Analysis/ScopInfo.cpp @@ -1416,10 +1416,30 @@ return Valid; } +static unsigned getMaxLoopDepthInRegion(const Region &R, LoopInfo &LI) { + unsigned MinLD = INT_MAX, MaxLD = 0; + for (BasicBlock *BB : R.blocks()) { + if (Loop *L = LI.getLoopFor(BB)) { + unsigned LD = L->getLoopDepth(); + MinLD = std::min(MinLD, LD); + MaxLD = std::max(MaxLD, LD); + } + } + + // Handle the case that there is no loop in the SCoP first. + if (MaxLD == 0) + return 1; + + assert(MinLD >= 1 && "Minimal loop depth should be at least one"); + assert(MaxLD >= MinLD && + "Maximal loop depth was smaller than mininaml loop depth?"); + return MaxLD - MinLD + 1; +} + Scop::Scop(TempScop &tempScop, LoopInfo &LI, ScalarEvolution &ScalarEvolution, isl_ctx *Context) : SE(&ScalarEvolution), R(tempScop.getMaxRegion()), - MaxLoopDepth(tempScop.getMaxLoopDepth()) { + MaxLoopDepth(getMaxLoopDepthInRegion(tempScop.getMaxRegion(), LI)) { IslCtx = Context; buildContext(); @@ -1785,7 +1805,7 @@ // Statistics. ++ScopFound; - if (tempScop->getMaxLoopDepth() > 0) + if (scop->getMaxLoopDepth() > 0) ++RichScopFound; scop = new Scop(*tempScop, LI, SE, ctx); Index: polly/trunk/lib/Analysis/TempScopInfo.cpp =================================================================== --- polly/trunk/lib/Analysis/TempScopInfo.cpp +++ polly/trunk/lib/Analysis/TempScopInfo.cpp @@ -73,8 +73,7 @@ TempScop::~TempScop() {} void TempScop::print(raw_ostream &OS, ScalarEvolution *SE, LoopInfo *LI) const { - OS << "Scop: " << R.getNameStr() << ", Max Loop Depth: " << MaxLoopDepth - << "\n"; + OS << "Scop: " << R.getNameStr() << "\n"; printDetail(OS, SE, LI, &R, 0); } @@ -216,7 +215,6 @@ void TempScopInfo::buildLoopBounds(TempScop &Scop) { Region &R = Scop.getMaxRegion(); - unsigned MaxLoopDepth = 0; for (auto const &BB : R.blocks()) { Loop *L = LI->getLoopFor(BB); @@ -229,15 +227,7 @@ const SCEV *BackedgeTakenCount = SE->getBackedgeTakenCount(L); LoopBounds[L] = BackedgeTakenCount; - - Loop *OL = R.outermostLoopInRegion(L); - unsigned LoopDepth = L->getLoopDepth() - OL->getLoopDepth() + 1; - - if (LoopDepth > MaxLoopDepth) - MaxLoopDepth = LoopDepth; } - - Scop.MaxLoopDepth = MaxLoopDepth; } void TempScopInfo::buildAffineCondition(Value &V, bool inverted,