-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[SCEVPatternMatch] Extend with more matchers #138836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-analysis Author: Ramkumar Ramachandra (artagnon) ChangesFull diff: https://github.com/llvm/llvm-project/pull/138836.diff 1 Files Affected:
diff --git a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
index 900f6d0fd05ab..a073f45423dea 100644
--- a/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
+++ b/llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h
@@ -56,6 +56,16 @@ template <typename Class> struct class_match {
template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
};
+inline class_match<const SCEV> m_SCEV() { return class_match<const SCEV>(); }
+
+inline class_match<const SCEVConstant> m_SCEVConstant() {
+ return class_match<const SCEVConstant>();
+}
+
+inline class_match<const SCEVUnknown> m_SCEVUnknown() {
+ return class_match<const SCEVUnknown>();
+}
+
template <typename Class> struct bind_ty {
Class *&VR;
@@ -91,6 +101,25 @@ struct specificscev_ty {
/// Match if we have a specific specified SCEV.
inline specificscev_ty m_Specific(const SCEV *S) { return S; }
+template <typename Op0_t> struct cst_match {
+ Op0_t Op0;
+
+ cst_match(Op0_t Op0) : Op0(Op0) {}
+
+ bool match(const SCEV *S) const {
+ assert((isa<SCEVCouldNotCompute>(S) || !S->getType()->isVectorTy()) &&
+ "no vector types expected from SCEVs");
+ auto *C = dyn_cast<SCEVConstant>(S);
+ return C && C->getAPInt() == Op0;
+ }
+};
+
+/// Match an SCEV constant with an APInt.
+inline cst_match<APInt> m_SCEVConstant(const APInt &V) { return V; }
+
+/// Match an SCEV constant with a plain integer.
+inline cst_match<uint64_t> m_SCEVConstant(uint64_t V) { return V; }
+
/// Match a unary SCEV.
template <typename SCEVTy, typename Op0_t> struct SCEVUnaryExpr_match {
Op0_t Op0;
@@ -147,6 +176,17 @@ m_scev_Add(const Op0_t &Op0, const Op1_t &Op1) {
return m_scev_Binary<SCEVAddExpr>(Op0, Op1);
}
+template <typename Op0_t, typename Op1_t>
+inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>
+m_scev_Mul(const Op0_t &Op0, const Op1_t &Op1) {
+ return m_scev_Binary<SCEVMulExpr>(Op0, Op1);
+}
+
+template <typename Op0_t, typename Op1_t>
+inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>
+m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) {
+ return m_scev_Binary<SCEVUDivExpr>(Op0, Op1);
+}
} // namespace SCEVPatternMatch
} // namespace llvm
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably at least contain changes to use each new matcher, to make sure the instantiations work as expected
To actually use this, I first require #138834 merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ok, but I think the naming needs more consideration. I think the general intention is to use the same names as PatternMatch but with an m_scev prefix, so I left suggestions accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.