[llvm] fea4a48 - [SCEV][NFC] API for tracking of SCEV users
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 24 22:15:15 PDT 2021
Author: Max Kazantsev
Date: 2021-10-25T12:14:18+07:00
New Revision: fea4a48c0baabb4732e6a7fd826755f011e19e0a
URL: https://github.com/llvm/llvm-project/commit/fea4a48c0baabb4732e6a7fd826755f011e19e0a
DIFF: https://github.com/llvm/llvm-project/commit/fea4a48c0baabb4732e6a7fd826755f011e19e0a.diff
LOG: [SCEV][NFC] API for tracking of SCEV users
This patch introduces API that keeps track of SCEVs users of
another SCEVs, required to handle invalidations of users along
with operands that comes in follow-up patches.
Differential Revision: https://reviews.llvm.org/D112295
Reviewed By: reames
Added:
Modified:
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
index ae7f16cff3530..1165981d0b564 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -537,6 +537,9 @@ class ScalarEvolution {
std::pair<SCEV::NoWrapFlags, bool /*Deduced*/>
getStrengthenedNoWrapFlagsFromBinOp(const OverflowingBinaryOperator *OBO);
+ /// Notify this ScalarEvolution that \p User directly uses SCEVs in \p Ops.
+ void registerUser(const SCEV *User, ArrayRef<const SCEV *> Ops);
+
/// Return a SCEV expression for the full generality of the specified
/// expression.
const SCEV *getSCEV(Value *V);
@@ -1506,6 +1509,9 @@ class ScalarEvolution {
/// Compute a BlockDisposition value.
BlockDisposition computeBlockDisposition(const SCEV *S, const BasicBlock *BB);
+ /// Stores all SCEV that use a given SCEV as its direct operand.
+ DenseMap<const SCEV *, SmallPtrSet<const SCEV *, 8> > SCEVUsers;
+
/// Memoized results from getRange
DenseMap<const SCEV *, ConstantRange> UnsignedRanges;
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 33fe59e714e65..7898438399c34 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1099,6 +1099,7 @@ const SCEV *ScalarEvolution::getLosslessPtrToIntExpr(const SCEV *Op,
SCEVPtrToIntExpr(ID.Intern(SCEVAllocator), Op, IntPtrTy);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -1219,6 +1220,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty,
new (SCEVAllocator) SCEVTruncateExpr(ID.Intern(SCEVAllocator), Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -1273,6 +1275,7 @@ const SCEV *ScalarEvolution::getTruncateExpr(const SCEV *Op, Type *Ty,
Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -1602,6 +1605,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -1871,6 +1875,7 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -1910,6 +1915,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Op);
return S;
}
@@ -2107,6 +2113,7 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
Op, Ty);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, { Op });
return S;
}
@@ -2892,6 +2899,7 @@ ScalarEvolution::getOrCreateAddExpr(ArrayRef<const SCEV *> Ops,
SCEVAddExpr(ID.Intern(SCEVAllocator), O, Ops.size());
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Ops);
}
S->setNoWrapFlags(Flags);
return S;
@@ -2915,6 +2923,7 @@ ScalarEvolution::getOrCreateAddRecExpr(ArrayRef<const SCEV *> Ops,
SCEVAddRecExpr(ID.Intern(SCEVAllocator), O, Ops.size(), L);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Ops);
}
setNoWrapFlags(S, Flags);
return S;
@@ -2937,6 +2946,7 @@ ScalarEvolution::getOrCreateMulExpr(ArrayRef<const SCEV *> Ops,
O, Ops.size());
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Ops);
}
S->setNoWrapFlags(Flags);
return S;
@@ -3446,6 +3456,7 @@ const SCEV *ScalarEvolution::getUDivExpr(const SCEV *LHS,
LHS, RHS);
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, {LHS, RHS});
return S;
}
@@ -3840,6 +3851,7 @@ const SCEV *ScalarEvolution::getMinMaxExpr(SCEVTypes Kind,
UniqueSCEVs.InsertNode(S, IP);
addToLoopUseLists(S);
+ registerUser(S, Ops);
return S;
}
@@ -12325,6 +12337,7 @@ ScalarEvolution::ScalarEvolution(ScalarEvolution &&Arg)
LoopDispositions(std::move(Arg.LoopDispositions)),
LoopPropertiesCache(std::move(Arg.LoopPropertiesCache)),
BlockDispositions(std::move(Arg.BlockDispositions)),
+ SCEVUsers(std::move(Arg.SCEVUsers)),
UnsignedRanges(std::move(Arg.UnsignedRanges)),
SignedRanges(std::move(Arg.SignedRanges)),
UniqueSCEVs(std::move(Arg.UniqueSCEVs)),
@@ -13288,6 +13301,12 @@ PredicatedScalarEvolution::PredicatedScalarEvolution(ScalarEvolution &SE,
Loop &L)
: SE(SE), L(L) {}
+void ScalarEvolution::registerUser(const SCEV *User,
+ ArrayRef<const SCEV *> Ops) {
+ for (auto *Op : Ops)
+ SCEVUsers[Op].insert(User);
+}
+
const SCEV *PredicatedScalarEvolution::getSCEV(Value *V) {
const SCEV *Expr = SE.getSCEV(V);
RewriteEntry &Entry = RewriteMap[Expr];
More information about the llvm-commits
mailing list