Index: include/polly/ScopInfo.h =================================================================== --- include/polly/ScopInfo.h +++ include/polly/ScopInfo.h @@ -888,6 +888,32 @@ const Region &CurRegion, SmallVectorImpl &NestLoops); + /// @brief Create the ScopStmt for a BasicBlcok and return its schedule + /// + /// Returns null if the BB is trivial and no stmt has been created + /// + /// @param BB The basic block we build the statement for. + /// @param tempScop The temp SCoP we use as model. + /// @param CurRegion The SCoP region. + /// @param NestLoops A vector of all surrounding loops. + /// + /// @return The ScopStmt's schedule. + __isl_give isl_schedule *buildBBScopStmt(BasicBlock *BB, TempScop &tempScop, + const Region &CurRegion, + SmallVectorImpl &NestLoops); + + /// @brief Create a sequence of two schedules. + /// + /// Either argument may be null and interpreted as the empty schedule. + /// + /// @param Prev Scheduled before Succ + /// @param Succ Scheduled after Prev. + /// + /// @return The sequence of both schedules or null if empty. + __isl_give isl_schedule * + ScheduleCombineSequence(__isl_take isl_schedule *Prev, + __isl_take isl_schedule *Succ); + /// @brief Build Scop and ScopStmts from a given TempScop. /// /// @param TempScop The temporary scop that is translated into an actual Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -1690,6 +1690,13 @@ // Build the iteration domain, access functions and schedule functions // traversing the region tree. Schedule = buildScop(TempScop, getRegion(), NestLoops, LI, SD); + + // Build the statement for PHIs in the exit block (never nested in a + // scopped-loop) + auto StmtSchedule = + buildBBScopStmt(getRegion().getExit(), TempScop, getRegion(), NestLoops); + Schedule = ScheduleCombineSequence(Schedule, StmtSchedule); + if (!Schedule) Schedule = isl_schedule_empty(getParamSpace()); @@ -2088,6 +2095,29 @@ return Stmt; } +__isl_give isl_schedule * +Scop::buildBBScopStmt(BasicBlock *BB, TempScop &tempScop, + const Region &CurRegion, + SmallVectorImpl &NestLoops) { + if (isTrivialBB(BB, tempScop)) + return nullptr; + + auto *Stmt = addScopStmt(BB, nullptr, tempScop, CurRegion, NestLoops); + auto *Domain = Stmt->getDomain(); + return isl_schedule_from_domain(isl_union_set_from_set(Domain)); +} + +__isl_give isl_schedule * +Scop::ScheduleCombineSequence(__isl_take isl_schedule *Prev, + __isl_take isl_schedule *Succ) { + if (!Prev) + return Succ; + if (!Succ) + return Prev; + + return isl_schedule_sequence(Prev, Succ); +} + __isl_give isl_schedule *Scop::buildScop(TempScop &tempScop, const Region &CurRegion, SmallVectorImpl &NestLoops, @@ -2115,21 +2145,10 @@ StmtSchedule = buildScop(tempScop, *I->getNodeAs(), NestLoops, LI, SD); } else { - BasicBlock *BB = I->getNodeAs(); - - if (isTrivialBB(BB, tempScop)) { - continue; - } else { - auto *Stmt = addScopStmt(BB, nullptr, tempScop, CurRegion, NestLoops); - auto *Domain = Stmt->getDomain(); - StmtSchedule = isl_schedule_from_domain(isl_union_set_from_set(Domain)); - } + StmtSchedule = buildBBScopStmt(I->getNodeAs(), tempScop, + CurRegion, NestLoops); } - - if (!Schedule) - Schedule = StmtSchedule; - else if (StmtSchedule) - Schedule = isl_schedule_sequence(Schedule, StmtSchedule); + Schedule = ScheduleCombineSequence(Schedule, StmtSchedule); } if (!L)