revert r183799: scop detection: remove an iteration over all uses
llvm-svn: 184128
diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp
index 3e1b1e5..262281e 100644
--- a/polly/lib/Analysis/ScopDetection.cpp
+++ b/polly/lib/Analysis/ScopDetection.cpp
@@ -142,6 +142,7 @@
BADSCOP_STAT(LoopBound, "Loop bounds can not be computed");
BADSCOP_STAT(FuncCall, "Function call with side effects appeared");
BADSCOP_STAT(AffFunc, "Expression not affine");
+BADSCOP_STAT(Scalar, "Found scalar dependency");
BADSCOP_STAT(Alias, "Found base address alias");
BADSCOP_STAT(SimpleLoop, "Loop not in -loop-simplify form");
BADSCOP_STAT(Other, "Others");
@@ -326,6 +327,30 @@
return true;
}
+bool ScopDetection::hasScalarDependency(Instruction &Inst,
+ Region &RefRegion) const {
+ for (Instruction::use_iterator UI = Inst.use_begin(), UE = Inst.use_end();
+ UI != UE; ++UI)
+ if (Instruction *Use = dyn_cast<Instruction>(*UI))
+ if (!RefRegion.contains(Use->getParent())) {
+ // DirtyHack 1: PHINode user outside the Scop is not allow, if this
+ // PHINode is induction variable, the scalar to array transform may
+ // break it and introduce a non-indvar PHINode, which is not allow in
+ // Scop.
+ // This can be fix by:
+ // Introduce a IndependentBlockPrepare pass, which translate all
+ // PHINodes not in Scop to array.
+ // The IndependentBlockPrepare pass can also split the entry block of
+ // the function to hold the alloca instruction created by scalar to
+ // array. and split the exit block of the Scop so the new create load
+ // instruction for escape users will not break other Scops.
+ if (isa<PHINode>(Use))
+ return true;
+ }
+
+ return false;
+}
+
bool ScopDetection::isValidInstruction(Instruction &Inst,
DetectionContext &Context) const {
if (PHINode *PN = dyn_cast<PHINode>(&Inst))
@@ -337,6 +362,10 @@
INVALID(IndVar, "Non canonical PHI node: " << Inst);
}
+ // Scalar dependencies are not allowed.
+ if (hasScalarDependency(Inst, Context.CurRegion))
+ INVALID(Scalar, "Scalar dependency found: " << Inst);
+
// We only check the call instruction but not invoke instruction.
if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
if (isValidCallInst(*CI))