Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -609,9 +609,12 @@ /// The underlying Region. Region &R; - /// Max loop depth. + /// The maximal loop depth of any loop in this SCoP/region. unsigned MaxLoopDepth; + /// The minimal loop depth of any loop in this SCoP/region. + unsigned MinLoopDepth; + typedef std::vector StmtSet; /// The statements in this Scop. StmtSet Stmts; @@ -755,10 +758,10 @@ inline const Region &getRegion() const { return R; } inline Region &getRegion() { return R; } - /// @brief Get the maximum depth of the loop. - /// - /// @return The maximum depth of the loop. - inline unsigned getMaxLoopDepth() const { return MaxLoopDepth; } + /// @brief Get the maximum depth of loops completely contained in the SCoP. + inline unsigned getMaxLoopDepthInScop() const { + return MaxLoopDepth - MinLoopDepth + (MinLoopDepth ? 1 : 0); + } /// @brief Get the scattering dimension number of this Scop. /// Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -699,7 +699,7 @@ void ScopStmt::buildScattering(SmallVectorImpl &Scatter) { unsigned NbIterators = getNumIterators(); - unsigned NbScatteringDims = Parent.getMaxLoopDepth() * 2 + 1; + unsigned NbScatteringDims = Parent.getMaxLoopDepthInScop() * 2 + 1; isl_space *Space = isl_space_set_alloc(getIslCtx(), 0, NbScatteringDims); Space = isl_space_set_tuple_name(Space, isl_dim_out, "scattering"); @@ -1420,37 +1420,36 @@ return Valid; } -static unsigned getMaxLoopDepthInRegion(const Region &R, LoopInfo &LI) { - unsigned MinLD = INT_MAX, MaxLD = 0; +static void getLoopDepthsInRegion(const Region &R, LoopInfo &LI, + unsigned &MaxLD, unsigned &MinLD) { + 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); - } + } else + MinLD = 0; } - // 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(getMaxLoopDepthInRegion(tempScop.getMaxRegion(), LI)) { + : SE(&ScalarEvolution), R(tempScop.getMaxRegion()) { + getLoopDepthsInRegion(tempScop.getMaxRegion(), LI, MaxLoopDepth, + MinLoopDepth); IslCtx = Context; buildContext(); SmallVector NestLoops; SmallVector Scatter; - Scatter.assign(MaxLoopDepth + 1, 0); + Scatter.assign(getMaxLoopDepthInScop() + 1, 0); // Build the iteration domain, access functions and scattering functions // traversing the region tree. @@ -1829,7 +1828,7 @@ // Statistics after we know the SCoP is valid. ++ScopFound; - if (scop->getMaxLoopDepth() > 0) + if (scop->getMaxLoopDepthInScop() > 0) ++RichScopFound; return false;