[polly] r200411 - ScopDetect: Transitively remove all children after region expansion
Tobias Grosser
tobias at grosser.es
Wed Jan 29 11:05:30 PST 2014
Author: grosser
Date: Wed Jan 29 13:05:30 2014
New Revision: 200411
URL: http://llvm.org/viewvc/llvm-project?rev=200411&view=rev
Log:
ScopDetect: Transitively remove all children after region expansion
In rare cases, a region R which is itself not valid has an indirect child region
that is valid. When R becomes part of a valid region by expansion of another
region, then all children of R have to be erased from the set of valid regions.
This patch ensures that indirect children are erased in addition to direct
children.
Contributed-by: Armin Groesslinger <armin.groesslinger at uni-passau.de>
Tobias: I added a reduced test case and adjusted the logic of the patch to
only recurse until the first child is found.
Added:
polly/trunk/test/ScopDetect/remove_all_children.ll
Modified:
polly/trunk/lib/Analysis/ScopDetection.cpp
Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=200411&r1=200410&r2=200411&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Wed Jan 29 13:05:30 2014
@@ -590,6 +590,24 @@ static bool regionWithoutLoops(Region &R
return true;
}
+// Remove all direct and indirect children of region R from the region set Regs,
+// but do not recurse further if the first child has been found.
+//
+// Return the number of regions erased from Regs.
+static unsigned eraseAllChildren(std::set<const Region *> &Regs,
+ const Region *R) {
+ unsigned Count = 0;
+ for (Region::const_iterator I = R->begin(), E = R->end(); I != E; ++I) {
+ if (Regs.find(*I) != Regs.end()) {
+ ++Count;
+ Regs.erase(*I);
+ } else {
+ Count += eraseAllChildren(Regs, *I);
+ }
+ }
+ return Count;
+}
+
void ScopDetection::findScops(Region &R) {
if (!DetectRegionsWithoutLoops && regionWithoutLoops(R, LI))
@@ -640,9 +658,9 @@ void ScopDetection::findScops(Region &R)
ValidRegions.insert(ExpandedR);
ValidRegions.erase(CurrentRegion);
- for (Region::iterator I = ExpandedR->begin(), E = ExpandedR->end(); I != E;
- ++I)
- ValidRegions.erase(*I);
+ // Erase all (direct and indirect) children of ExpandedR from the valid
+ // regions and update the number of valid regions.
+ ValidRegion -= eraseAllChildren(ValidRegions, ExpandedR);
}
}
Added: polly/trunk/test/ScopDetect/remove_all_children.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopDetect/remove_all_children.ll?rev=200411&view=auto
==============================================================================
--- polly/trunk/test/ScopDetect/remove_all_children.ll (added)
+++ polly/trunk/test/ScopDetect/remove_all_children.ll Wed Jan 29 13:05:30 2014
@@ -0,0 +1,46 @@
+; RUN: opt %loadPolly -polly-detect -analyze < %s | FileCheck %s
+; RUN: opt %loadPolly -polly-detect -polly-codegen-scev -analyze < %s | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @remove_all_children(i32* %eclass) {
+entry:
+ br label %while.body
+
+while.cond.loopexit: ; preds = %while.body50, %while.end44
+ fence seq_cst
+ br label %while.cond.backedge
+
+while.body: ; preds = %while.cond.backedge, %entry
+ br label %if.end33
+
+while.cond.backedge: ; preds = %while.end30, %while.cond.loopexit
+ br i1 false, label %while.body, label %while.end60
+
+if.end33: ; preds = %while.end30
+ br i1 false, label %while.body36, label %while.end44
+
+while.body36: ; preds = %while.body36, %while.body36.lr.ph
+ %indvar77 = phi i64 [ 0, %if.end33 ], [ %indvar.next78, %while.body36 ]
+ %arrayidx40 = getelementptr i32* %eclass, i64 0
+ %indvar.next78 = add i64 %indvar77, 1
+ br i1 false, label %while.body36, label %while.end44
+
+while.end44: ; preds = %while.body36, %if.end33
+ br i1 false, label %while.body50, label %while.cond.loopexit
+
+while.body50: ; preds = %while.body50, %while.body50.lr.ph
+ %indvar79 = phi i64 [ 0, %while.end44 ], [ %indvar.next80, %while.body50 ]
+ %arrayidx55 = getelementptr i32* %eclass, i64 0
+ store i32 0, i32* %arrayidx55, align 4
+ %indvar.next80 = add i64 %indvar79, 1
+ br i1 false, label %while.body50, label %while.cond.loopexit
+
+while.end60: ; preds = %while.cond.backedge
+ ret void
+}
+; remove_all_children
+; CHECK-NOT: Valid Region
+; CHECK: Valid Region for Scop: if.end33 => while.cond.loopexit
+; CHECK-NOT: Valid Region
More information about the llvm-commits
mailing list