[llvm] r274334 - [PM] refactor LoopAccessInfo code part-2
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 30 22:59:56 PDT 2016
Author: davidxl
Date: Fri Jul 1 00:59:55 2016
New Revision: 274334
URL: http://llvm.org/viewvc/llvm-project?rev=274334&view=rev
Log:
[PM] refactor LoopAccessInfo code part-2
Differential Revision: http://reviews.llvm.org/D21636
Modified:
llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp
llvm/trunk/lib/Transforms/Scalar/LoopLoadElimination.cpp
llvm/trunk/lib/Transforms/Utils/LoopVersioning.cpp
llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopAccessAnalysis.h Fri Jul 1 00:59:55 2016
@@ -515,6 +515,44 @@ public:
const TargetLibraryInfo *TLI, AliasAnalysis *AA,
DominatorTree *DT, LoopInfo *LI);
+ // FIXME:
+ // Hack for MSVC 2013 which sems like it can't synthesize this even
+ // with default keyword:
+ // LoopAccessInfo(LoopAccessInfo &&LAI) = default;
+ LoopAccessInfo(LoopAccessInfo &&LAI)
+ : PSE(std::move(LAI.PSE)), PtrRtChecking(std::move(LAI.PtrRtChecking)),
+ DepChecker(std::move(LAI.DepChecker)), TheLoop(LAI.TheLoop), DL(LAI.DL),
+ TLI(LAI.TLI), AA(LAI.AA), DT(LAI.DT), LI(LAI.LI),
+ NumLoads(LAI.NumLoads), NumStores(LAI.NumStores),
+ MaxSafeDepDistBytes(LAI.MaxSafeDepDistBytes), CanVecMem(LAI.CanVecMem),
+ StoreToLoopInvariantAddress(LAI.StoreToLoopInvariantAddress),
+ Report(std::move(LAI.Report)),
+ SymbolicStrides(std::move(LAI.SymbolicStrides)),
+ StrideSet(std::move(LAI.StrideSet)) {}
+ // LoopAccessInfo &operator=(LoopAccessInfo &&LAI) = default;
+ LoopAccessInfo &operator=(LoopAccessInfo &&LAI) {
+ assert(this != &LAI);
+
+ PSE = std::move(LAI.PSE);
+ PtrRtChecking = std::move(LAI.PtrRtChecking);
+ DepChecker = std::move(LAI.DepChecker);
+ TheLoop = LAI.TheLoop;
+ DL = LAI.DL;
+ TLI = LAI.TLI;
+ AA = LAI.AA;
+ DT = LAI.DT;
+ LI = LAI.LI;
+ NumLoads = LAI.NumLoads;
+ NumStores = LAI.NumStores;
+ MaxSafeDepDistBytes = LAI.MaxSafeDepDistBytes;
+ CanVecMem = LAI.CanVecMem;
+ StoreToLoopInvariantAddress = LAI.StoreToLoopInvariantAddress;
+ Report = std::move(LAI.Report);
+ SymbolicStrides = std::move(LAI.SymbolicStrides);
+ StrideSet = std::move(LAI.StrideSet);
+ return *this;
+ }
+
/// Return true we can analyze the memory accesses in the loop and there are
/// no memory dependence cycles.
bool canVectorizeMemory() const { return CanVecMem; }
@@ -596,7 +634,7 @@ public:
/// should be re-written (and therefore simplified) according to PSE.
/// A user of LoopAccessAnalysis will need to emit the runtime checks
/// associated with this predicate.
- PredicatedScalarEvolution PSE;
+ const PredicatedScalarEvolution &getPSE() const { return *PSE; }
private:
/// \brief Analyze the loop.
@@ -614,6 +652,8 @@ private:
/// invariant.
void collectStridedAccess(Value *LoadOrStoreInst);
+ std::unique_ptr<PredicatedScalarEvolution> PSE;
+
/// We need to check that all of the pointers in this list are disjoint
/// at runtime. Using std::unique_ptr to make using move ctor simpler.
std::unique_ptr<RuntimePointerChecking> PtrRtChecking;
@@ -623,7 +663,7 @@ private:
std::unique_ptr<MemoryDepChecker> DepChecker;
Loop *TheLoop;
- const DataLayout &DL;
+ const DataLayout *DL;
const TargetLibraryInfo *TLI;
AliasAnalysis *AA;
DominatorTree *DT;
Modified: llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopAccessAnalysis.cpp Fri Jul 1 00:59:55 2016
@@ -1492,8 +1492,8 @@ bool LoopAccessInfo::canAnalyzeLoop() {
}
// ScalarEvolution needs to be able to find the exit count.
- const SCEV *ExitCount = PSE.getBackedgeTakenCount();
- if (ExitCount == PSE.getSE()->getCouldNotCompute()) {
+ const SCEV *ExitCount = PSE->getBackedgeTakenCount();
+ if (ExitCount == PSE->getSE()->getCouldNotCompute()) {
emitAnalysis(LoopAccessReport()
<< "could not determine number of loop iterations");
DEBUG(dbgs() << "LAA: SCEV could not compute the loop exit count.\n");
@@ -1598,7 +1598,7 @@ void LoopAccessInfo::analyzeLoop() {
MemoryDepChecker::DepCandidates DependentAccesses;
AccessAnalysis Accesses(TheLoop->getHeader()->getModule()->getDataLayout(),
- AA, LI, DependentAccesses, PSE);
+ AA, LI, DependentAccesses, *PSE);
// Holds the analyzed pointers. We don't want to call GetUnderlyingObjects
// multiple times on the same object. If the ptr is accessed twice, once
@@ -1647,7 +1647,7 @@ void LoopAccessInfo::analyzeLoop() {
// words may be written to the same address.
bool IsReadOnlyPtr = false;
if (Seen.insert(Ptr).second ||
- !getPtrStride(PSE, Ptr, TheLoop, SymbolicStrides)) {
+ !getPtrStride(*PSE, Ptr, TheLoop, SymbolicStrides)) {
++NumReads;
IsReadOnlyPtr = true;
}
@@ -1676,7 +1676,7 @@ void LoopAccessInfo::analyzeLoop() {
// Find pointers with computable bounds. We are going to use this information
// to place a runtime bound check.
- bool CanDoRTIfNeeded = Accesses.canCheckPtrAtRT(*PtrRtChecking, PSE.getSE(),
+ bool CanDoRTIfNeeded = Accesses.canCheckPtrAtRT(*PtrRtChecking, PSE->getSE(),
TheLoop, SymbolicStrides);
if (!CanDoRTIfNeeded) {
emitAnalysis(LoopAccessReport() << "cannot identify array bounds");
@@ -1704,7 +1704,7 @@ void LoopAccessInfo::analyzeLoop() {
PtrRtChecking->reset();
PtrRtChecking->Need = true;
- auto *SE = PSE.getSE();
+ auto *SE = PSE->getSE();
CanDoRTIfNeeded = Accesses.canCheckPtrAtRT(*PtrRtChecking, SE, TheLoop,
SymbolicStrides, true);
@@ -1751,7 +1751,7 @@ void LoopAccessInfo::emitAnalysis(LoopAc
}
bool LoopAccessInfo::isUniform(Value *V) const {
- return (PSE.getSE()->isLoopInvariant(PSE.getSE()->getSCEV(V), TheLoop));
+ return (PSE->getSE()->isLoopInvariant(PSE->getSE()->getSCEV(V), TheLoop));
}
// FIXME: this function is currently a duplicate of the one in
@@ -1832,8 +1832,8 @@ std::pair<Instruction *, Instruction *>
Instruction *Loc,
const SmallVectorImpl<RuntimePointerChecking::PointerCheck> &PointerChecks)
const {
- auto *SE = PSE.getSE();
- SCEVExpander Exp(*SE, DL, "induction");
+ auto *SE = PSE->getSE();
+ SCEVExpander Exp(*SE, *DL, "induction");
auto ExpandedChecks =
expandBounds(PointerChecks, TheLoop, Loc, SE, Exp, *PtrRtChecking);
@@ -1906,7 +1906,7 @@ void LoopAccessInfo::collectStridedAcces
else
return;
- Value *Stride = getStrideFromPointer(Ptr, PSE.getSE(), TheLoop);
+ Value *Stride = getStrideFromPointer(Ptr, PSE->getSE(), TheLoop);
if (!Stride)
return;
@@ -1920,10 +1920,10 @@ LoopAccessInfo::LoopAccessInfo(Loop *L,
const DataLayout &DL,
const TargetLibraryInfo *TLI, AliasAnalysis *AA,
DominatorTree *DT, LoopInfo *LI)
- : PSE(*SE, *L),
+ : PSE(llvm::make_unique<PredicatedScalarEvolution>(*SE, *L)),
PtrRtChecking(llvm::make_unique<RuntimePointerChecking>(SE)),
- DepChecker(llvm::make_unique<MemoryDepChecker>(PSE, L)), TheLoop(L),
- DL(DL), TLI(TLI), AA(AA), DT(DT), LI(LI), NumLoads(0), NumStores(0),
+ DepChecker(llvm::make_unique<MemoryDepChecker>(*PSE, L)), TheLoop(L),
+ DL(&DL), TLI(TLI), AA(AA), DT(DT), LI(LI), NumLoads(0), NumStores(0),
MaxSafeDepDistBytes(-1U), CanVecMem(false),
StoreToLoopInvariantAddress(false) {
if (canAnalyzeLoop())
@@ -1962,12 +1962,12 @@ void LoopAccessInfo::print(raw_ostream &
<< "found in loop.\n";
OS.indent(Depth) << "SCEV assumptions:\n";
- PSE.getUnionPredicate().print(OS, Depth);
+ PSE->getUnionPredicate().print(OS, Depth);
OS << "\n";
OS.indent(Depth) << "Expressions re-written:\n";
- PSE.print(OS, Depth);
+ PSE->print(OS, Depth);
}
const LoopAccessInfo &LoopAccessAnalysis::getInfo(Loop *L) {
Modified: llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopDistribute.cpp Fri Jul 1 00:59:55 2016
@@ -693,7 +693,7 @@ public:
}
// Don't distribute the loop if we need too many SCEV run-time checks.
- const SCEVUnionPredicate &Pred = LAI->PSE.getUnionPredicate();
+ const SCEVUnionPredicate &Pred = LAI->getPSE().getUnionPredicate();
if (Pred.getComplexity() > (IsForced.getValueOr(false)
? PragmaDistributeSCEVCheckThreshold
: DistributeSCEVCheckThreshold))
@@ -722,7 +722,7 @@ public:
DEBUG(LAI->getRuntimePointerChecking()->printChecks(dbgs(), Checks));
LoopVersioning LVer(*LAI, L, LI, DT, SE, false);
LVer.setAliasChecks(std::move(Checks));
- LVer.setSCEVChecks(LAI->PSE.getUnionPredicate());
+ LVer.setSCEVChecks(LAI->getPSE().getUnionPredicate());
LVer.versionLoop(DefsUsedOutside);
LVer.annotateLoopWithNoAlias();
}
Modified: llvm/trunk/lib/Transforms/Scalar/LoopLoadElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopLoadElimination.cpp?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopLoadElimination.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopLoadElimination.cpp Fri Jul 1 00:59:55 2016
@@ -129,7 +129,7 @@ class LoadEliminationForLoop {
public:
LoadEliminationForLoop(Loop *L, LoopInfo *LI, const LoopAccessInfo &LAI,
DominatorTree *DT)
- : L(L), LI(LI), LAI(LAI), DT(DT), PSE(LAI.PSE) {}
+ : L(L), LI(LI), LAI(LAI), DT(DT), PSE(LAI.getPSE()) {}
/// \brief Look through the loop-carried and loop-independent dependences in
/// this loop and find store->load dependences.
@@ -486,13 +486,13 @@ public:
return false;
}
- if (LAI.PSE.getUnionPredicate().getComplexity() >
+ if (LAI.getPSE().getUnionPredicate().getComplexity() >
LoadElimSCEVCheckThreshold) {
DEBUG(dbgs() << "Too many SCEV run-time checks needed.\n");
return false;
}
- if (!Checks.empty() || !LAI.PSE.getUnionPredicate().isAlwaysTrue()) {
+ if (!Checks.empty() || !LAI.getPSE().getUnionPredicate().isAlwaysTrue()) {
if (L->getHeader()->getParent()->optForSize()) {
DEBUG(dbgs() << "Versioning is needed but not allowed when optimizing "
"for size.\n");
@@ -504,7 +504,7 @@ public:
LoopVersioning LV(LAI, L, LI, DT, PSE.getSE(), false);
LV.setAliasChecks(std::move(Checks));
- LV.setSCEVChecks(LAI.PSE.getUnionPredicate());
+ LV.setSCEVChecks(LAI.getPSE().getUnionPredicate());
LV.versionLoop();
}
Modified: llvm/trunk/lib/Transforms/Utils/LoopVersioning.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopVersioning.cpp?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopVersioning.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopVersioning.cpp Fri Jul 1 00:59:55 2016
@@ -39,7 +39,7 @@ LoopVersioning::LoopVersioning(const Loo
assert(L->getLoopPreheader() && "No preheader");
if (UseLAIChecks) {
setAliasChecks(LAI.getRuntimePointerChecking()->getChecks());
- setSCEVChecks(LAI.PSE.getUnionPredicate());
+ setSCEVChecks(LAI.getPSE().getUnionPredicate());
}
}
@@ -64,7 +64,7 @@ void LoopVersioning::versionLoop(
std::tie(FirstCheckInst, MemRuntimeCheck) =
LAI.addRuntimeChecks(RuntimeCheckBB->getTerminator(), AliasChecks);
- const SCEVUnionPredicate &Pred = LAI.PSE.getUnionPredicate();
+ const SCEVUnionPredicate &Pred = LAI.getPSE().getUnionPredicate();
SCEVExpander Exp(*SE, RuntimeCheckBB->getModule()->getDataLayout(),
"scev.check");
SCEVRuntimeCheck =
@@ -279,7 +279,7 @@ public:
for (Loop *L : Worklist) {
const LoopAccessInfo &LAI = LAA->getInfo(L);
if (LAI.getNumRuntimePointerChecks() ||
- !LAI.PSE.getUnionPredicate().isAlwaysTrue()) {
+ !LAI.getPSE().getUnionPredicate().isAlwaysTrue()) {
LoopVersioning LVer(LAI, L, LI, DT, SE);
LVer.versionLoop();
LVer.annotateLoopWithNoAlias();
Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=274334&r1=274333&r2=274334&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Fri Jul 1 00:59:55 2016
@@ -5083,7 +5083,7 @@ bool LoopVectorizationLegality::canVecto
}
Requirements->addRuntimePointerChecks(LAI->getNumRuntimePointerChecks());
- PSE.addPredicate(LAI->PSE.getUnionPredicate());
+ PSE.addPredicate(LAI->getPSE().getUnionPredicate());
return true;
}
More information about the llvm-commits
mailing list