[polly] r309273 - [ScopBuilder/Simplify] Refactor isEscaping. NFC.
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 07:39:52 PDT 2017
Author: meinersbur
Date: Thu Jul 27 07:39:52 2017
New Revision: 309273
URL: http://llvm.org/viewvc/llvm-project?rev=309273&view=rev
Log:
[ScopBuilder/Simplify] Refactor isEscaping. NFC.
ScopBuilder and Simplify (through VirtualInstruction.cpp) previously
used this functionality in their own implementation. Refactor them
both into a common one into the Scop class.
BlockGenerator also makes use of a similiar functionality, but also
records outside users and takes place after region simplification.
Merging it as well would be more complicated.
Modified:
polly/trunk/include/polly/ScopInfo.h
polly/trunk/lib/Analysis/ScopBuilder.cpp
polly/trunk/lib/Analysis/ScopInfo.cpp
polly/trunk/lib/Support/VirtualInstruction.cpp
Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=309273&r1=309272&r2=309273&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu Jul 27 07:39:52 2017
@@ -2974,6 +2974,9 @@ public:
/// Return all MemoryAccesses for all incoming statements of a PHINode,
/// represented by a ScopArrayInfo.
ArrayRef<MemoryAccess *> getPHIIncomings(const ScopArrayInfo *SAI) const;
+
+ /// Return whether @p Inst has a use outside of this SCoP.
+ bool isEscaping(Instruction *Inst);
};
/// Print Scop scop to raw_ostream O.
Modified: polly/trunk/lib/Analysis/ScopBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopBuilder.cpp?rev=309273&r1=309272&r2=309273&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopBuilder.cpp (original)
+++ polly/trunk/lib/Analysis/ScopBuilder.cpp Thu Jul 27 07:39:52 2017
@@ -105,27 +105,8 @@ void ScopBuilder::buildEscapingDependenc
// Check for uses of this instruction outside the scop. Because we do not
// iterate over such instructions and therefore did not "ensure" the existence
// of a write, we must determine such use here.
- for (Use &U : Inst->uses()) {
- Instruction *UI = dyn_cast<Instruction>(U.getUser());
- if (!UI)
- continue;
-
- BasicBlock *UseParent = getUseBlock(U);
- BasicBlock *UserParent = UI->getParent();
-
- // An escaping value is either used by an instruction not within the scop,
- // or (when the scop region's exit needs to be simplified) by a PHI in the
- // scop's exit block. This is because region simplification before code
- // generation inserts new basic blocks before the PHI such that its incoming
- // blocks are not in the scop anymore.
- if (!scop->contains(UseParent) ||
- (isa<PHINode>(UI) && scop->isExit(UserParent) &&
- scop->hasSingleExitEdge())) {
- // At least one escaping use found.
- ensureValueWrite(Inst);
- break;
- }
- }
+ if (scop->isEscaping(Inst))
+ ensureValueWrite(Inst);
}
/// Check that a value is a Fortran Array descriptor.
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=309273&r1=309272&r2=309273&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Jul 27 07:39:52 2017
@@ -5138,6 +5138,25 @@ ArrayRef<MemoryAccess *> Scop::getPHIInc
return It->second;
}
+bool Scop::isEscaping(Instruction *Inst) {
+ assert(contains(Inst) && "The concept of escaping makes only sense for "
+ "values defined inside the SCoP");
+
+ for (Use &Use : Inst->uses()) {
+ BasicBlock *UserBB = getUseBlock(Use);
+ if (!contains(UserBB))
+ return true;
+
+ // When the SCoP region exit needs to be simplified, PHIs in the region exit
+ // move to a new basic block such that its incoming blocks are not in the
+ // SCoP anymore.
+ if (hasSingleExitEdge() && isa<PHINode>(Use.getUser()) &&
+ isExit(cast<PHINode>(Use.getUser())->getParent()))
+ return true;
+ }
+ return false;
+}
+
raw_ostream &polly::operator<<(raw_ostream &O, const Scop &scop) {
scop.print(O, PollyPrintInstructions);
return O;
Modified: polly/trunk/lib/Support/VirtualInstruction.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/VirtualInstruction.cpp?rev=309273&r1=309272&r2=309273&view=diff
==============================================================================
--- polly/trunk/lib/Support/VirtualInstruction.cpp (original)
+++ polly/trunk/lib/Support/VirtualInstruction.cpp Thu Jul 27 07:39:52 2017
@@ -163,30 +163,12 @@ static bool isRoot(const Instruction *In
return false;
}
-/// Return true if @p ComputingInst is used after SCoP @p S. It must not be
-/// removed in order for its value to be available after the SCoP.
-static bool isEscaping(Scop *S, Instruction *ComputingInst) {
- for (Use &Use : ComputingInst->uses()) {
- BasicBlock *UserBB = getUseBlock(Use);
- if (!S->contains(UserBB))
- return true;
-
- // When the SCoP region exit needs to be simplified, PHIs in the region exit
- // move to a new basic block such that its incoming blocks are not in the
- // scop anymore.
- if (S->hasSingleExitEdge() && isa<PHINode>(Use.getUser()) &&
- S->isExit(cast<PHINode>(Use.getUser())->getParent()))
- return true;
- }
- return false;
-}
-
/// Return true for MemoryAccesses that cannot be removed because it represents
/// an llvm::Value that is used after the SCoP.
static bool isEscaping(MemoryAccess *MA) {
assert(MA->isOriginalValueKind());
- return isEscaping(MA->getStatement()->getParent(),
- cast<Instruction>(MA->getAccessValue()));
+ Scop *S = MA->getStatement()->getParent();
+ return S->isEscaping(cast<Instruction>(MA->getAccessValue()));
}
/// Add non-removable virtual instructions in @p Stmt to @p RootInsts.
More information about the llvm-commits
mailing list