rrkLastAffFunc,
rrkLoopBound,
- rrkLoopOverlapWithNonAffineSubRegion,
+ rrkLoopHasNoExit,
rrkFuncCall,
rrkNonSimpleMemoryAccess,
};
//===----------------------------------------------------------------------===//
-/// Captures errors when loop overlap with nonaffine subregion.
-class ReportLoopOverlapWithNonAffineSubRegion : public RejectReason {
+/// Captures errors when loop has no exit.
+class ReportLoopHasNoExit : public RejectReason {
//===--------------------------------------------------------------------===//
- /// If L and R are set then L and R overlap.
-
- /// The loop contains stmt overlapping nonaffine subregion.
+ /// The loop that has no exit.
Loop *L;
- /// The nonaffine subregion that contains infinite loop.
- Region *R;
-
const DebugLoc Loc;
public:
- ReportLoopOverlapWithNonAffineSubRegion(Loop *L, Region *R);
+ ReportLoopHasNoExit(Loop *L)
+ : RejectReason(rrkLoopHasNoExit), L(L), Loc(L->getStartLoc()) {}
/// @name LLVM-RTTI interface
//@{
// All loops in the region have to be overapproximated too if there
// are accesses that depend on the iteration count.
- BoxedLoopsSetTy ARBoxedLoopsSet;
-
for (BasicBlock *BB : AR->blocks()) {
Loop *L = LI->getLoopFor(BB);
- if (AR->contains(L)) {
+ if (AR->contains(L))
Context.BoxedLoopsSet.insert(L);
- ARBoxedLoopsSet.insert(L);
- }
- }
-
- // Reject if the surrounding loop does not entirely contain the nonaffine
- // subregion.
- // This can happen because a region can contain BBs that have no path to the
- // exit block (Infinite loops, UnreachableInst), but such blocks are never
- // part of a loop.
- //
- // _______________
- // | Loop Header | <-----------.
- // --------------- |
- // | |
- // _______________ ______________
- // | RegionEntry |-----> | RegionExit |----->
- // --------------- --------------
- // |
- // _______________
- // | EndlessLoop | <--.
- // --------------- |
- // | |
- // \------------/
- //
- // In the example above, the loop (LoopHeader,RegionEntry,RegionExit) is
- // neither entirely contained in the region RegionEntry->RegionExit
- // (containing RegionEntry,EndlessLoop) nor is the region entirely contained
- // in the loop.
- // The block EndlessLoop is contained is in the region because
- // Region::contains tests whether it is not dominated by RegionExit. This is
- // probably to not having to query the PostdominatorTree.
- // Instead of an endless loop, a dead end can also be formed by
- // UnreachableInst. This case is already caught by isErrorBlock(). We hence
- // only have to test whether there is an endless loop not contained in the
- // surrounding loop.
- BasicBlock *BBEntry = AR->getEntry();
- Loop *L = LI->getLoopFor(BBEntry);
- while (L && AR->contains(L))
- L = L->getParentLoop();
- if (L) {
- for (const auto *ARBoxedLoop : ARBoxedLoopsSet)
- if (!L->contains(ARBoxedLoop))
- return invalid<ReportLoopOverlapWithNonAffineSubRegion>(
- Context, /*Assert=*/true, L, AR);
}
return (AllowNonAffineSubLoops || Context.BoxedLoopsSet.empty());
return invalid<ReportUnknownInst>(Context, /*Assert=*/true, &Inst);
}
+/// Check whether @p L has exiting blocks.
+///
+/// @param L The loop of interest
+///
+/// @return True if the loop has exiting blocks, false otherwise.
+static bool hasExitingBlocks(Loop *L) {
+ SmallVector<BasicBlock *, 4> ExitingBlocks;
+ L->getExitingBlocks(ExitingBlocks);
+ return !ExitingBlocks.empty();
+}
+
bool ScopDetection::canUseISLTripCount(Loop *L,
DetectionContext &Context) const {
// Ensure the loop has valid exiting blocks as well as latches, otherwise we
// need to overapproximate it as a boxed loop.
SmallVector<BasicBlock *, 4> LoopControlBlocks;
L->getExitingBlocks(LoopControlBlocks);
-
- // Loops without exiting blocks cannot be handled by the schedule generation
- // as it depends on a region covering that is not given.
- if (LoopControlBlocks.empty())
- return false;
-
L->getLoopLatches(LoopControlBlocks);
for (BasicBlock *ControlBB : LoopControlBlocks) {
if (!isValidCFG(*ControlBB, true, false, Context))
}
bool ScopDetection::isValidLoop(Loop *L, DetectionContext &Context) const {
+ // Loops that contain part but not all of the blocks of a region cannot be
+ // handled by the schedule generation. Such loop constructs can happen
+ // because a region can contain BBs that have no path to the exit block
+ // (Infinite loops, UnreachableInst), but such blocks are never part of a
+ // loop.
+ //
+ // _______________
+ // | Loop Header | <-----------.
+ // --------------- |
+ // | |
+ // _______________ ______________
+ // | RegionEntry |-----> | RegionExit |----->
+ // --------------- --------------
+ // |
+ // _______________
+ // | EndlessLoop | <--.
+ // --------------- |
+ // | |
+ // \------------/
+ //
+ // In the example above, the loop (LoopHeader,RegionEntry,RegionExit) is
+ // neither entirely contained in the region RegionEntry->RegionExit
+ // (containing RegionEntry,EndlessLoop) nor is the region entirely contained
+ // in the loop.
+ // The block EndlessLoop is contained in the region because Region::contains
+ // tests whether it is not dominated by RegionExit. This is probably to not
+ // having to query the PostdominatorTree. Instead of an endless loop, a dead
+ // end can also be formed by an UnreachableInst. This case is already caught
+ // by isErrorBlock(). We hence only have to reject endless loops here.
+ if (!hasExitingBlocks(L))
+ return invalid<ReportLoopHasNoExit>(Context, /*Assert=*/true, L);
+
if (canUseISLTripCount(L, Context))
return true;
BADSCOP_STAT(CFG, "CFG too complex");
BADSCOP_STAT(LoopBound, "Loop bounds can not be computed");
-BADSCOP_STAT(LoopOverlapWithNonAffineSubRegion,
- "Loop overlap with nonaffine subregion");
BADSCOP_STAT(FuncCall, "Function call with side effects appeared");
BADSCOP_STAT(AffFunc, "Expression not affine");
BADSCOP_STAT(Alias, "Found base address alias");
}
//===----------------------------------------------------------------------===//
-// ReportLoopOverlapWithNonAffineSubRegion.
+// ReportLoopHasNoExit.
-ReportLoopOverlapWithNonAffineSubRegion::
- ReportLoopOverlapWithNonAffineSubRegion(Loop *L, Region *R)
- : RejectReason(rrkLoopOverlapWithNonAffineSubRegion), L(L), R(R),
- Loc(L->getStartLoc()) {
- ++BadLoopOverlapWithNonAffineSubRegionForScop;
+std::string ReportLoopHasNoExit::getMessage() const {
+ return "Loop " + L->getHeader()->getName() + " has no exit.";
}
-std::string ReportLoopOverlapWithNonAffineSubRegion::getMessage() const {
- return "Non affine subregion: " + R->getNameStr() + " overlaps Loop " +
- L->getHeader()->getName();
+bool ReportLoopHasNoExit::classof(const RejectReason *RR) {
+ return RR->getKind() == rrkLoopHasNoExit;
}
-const DebugLoc &ReportLoopOverlapWithNonAffineSubRegion::getDebugLoc() const {
- return Loc;
-}
-
-bool ReportLoopOverlapWithNonAffineSubRegion::classof(const RejectReason *RR) {
- return RR->getKind() == rrkLoopOverlapWithNonAffineSubRegion;
-}
+const DebugLoc &ReportLoopHasNoExit::getDebugLoc() const { return Loc; }
-std::string ReportLoopOverlapWithNonAffineSubRegion::getEndUserMessage() const {
- return "Loop overlaps with nonaffine subregion.";
+std::string ReportLoopHasNoExit::getEndUserMessage() const {
+ return "Loop cannot be handled because it has no exit.";
}
//===----------------------------------------------------------------------===//
-; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops -analyze -polly-detect < %s 2>&1 | FileCheck %s --check-prefix=REJECTLOOPOVERLAPREGION
-; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops=false -analyze -polly-detect < %s 2>&1 | FileCheck %s --check-prefix=REJECTNONAFFINELOOPS
+; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops -analyze -polly-detect < %s 2>&1 | FileCheck %s
+; RUN: opt %loadPolly -pass-remarks-missed="polly-detect" -polly-allow-nonaffine-loops=false -analyze -polly-detect < %s 2>&1 | FileCheck %s
; void func (int param0, int N, int *A)
; {
; A[i] = 2;
; }
-; If we reject non-affine region and loop will be reported:
-;
-; REJECTLOOPOVERLAPREGION: remark: ReportLoopOverlapWithNonAffineRegion.c:3:3: The following errors keep this region from being a Scop.
-; REJECTLOOPOVERLAPREGION: remark: ReportLoopOverlapWithNonAffineRegion.c:3:3: Loop overlaps with nonaffine subregion.
-; REJECTLOOPOVERLAPREGION: remark: ReportLoopOverlapWithNonAffineRegion.c:7:7: Failed to derive an affine function from the loop bounds.
-; REJECTLOOPOVERLAPREGION: remark: ReportLoopOverlapWithNonAffineRegion.c:7:7: Invalid Scop candidate ends here.
-;
-; If we reject non-affine loops the non-affine loop bound will be reported:
-;
-; REJECTNONAFFINELOOPS: remark: ReportLoopOverlapWithNonAffineRegion.c:7:7: The following errors keep this region from being a Scop.
-; REJECTNONAFFINELOOPS: remark: ReportLoopOverlapWithNonAffineRegion.c:7:7: Failed to derive an affine function from the loop bounds.
-; REJECTNONAFFINELOOPS: remark: ReportLoopOverlapWithNonAffineRegion.c:7:7: Invalid Scop candidate ends here.
+; CHECK: remark: ReportLoopHasNoExit.c:7:7: Loop cannot be handled because it has no exit.
!llvm.ident = !{!5}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
-!1 = !DIFile(filename: "ReportLoopOverlapWithNonAffineRegion.c", directory: "test/ScopDetectionDiagnostics/")
+!1 = !DIFile(filename: "ReportLoopHasNoExit.c", directory: "test/ScopDetectionDiagnostics/")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}