Skip to content

Commit de7cf73

Browse files
committed
[SCEVPatternMatch] Extend with more matchers
1 parent aec3929 commit de7cf73

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

llvm/include/llvm/Analysis/ScalarEvolutionPatternMatch.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ template <typename Class> struct class_match {
5656
template <typename ITy> bool match(ITy *V) const { return isa<Class>(V); }
5757
};
5858

59+
inline class_match<const SCEV> m_SCEV() { return class_match<const SCEV>(); }
60+
61+
inline class_match<const SCEVConstant> m_SCEVConstant() {
62+
return class_match<const SCEVConstant>();
63+
}
64+
65+
inline class_match<const SCEVUnknown> m_SCEVUnknown() {
66+
return class_match<const SCEVUnknown>();
67+
}
68+
5969
template <typename Class> struct bind_ty {
6070
Class *&VR;
6171

@@ -91,6 +101,25 @@ struct specificscev_ty {
91101
/// Match if we have a specific specified SCEV.
92102
inline specificscev_ty m_Specific(const SCEV *S) { return S; }
93103

104+
template <typename Op0_t> struct cst_match {
105+
Op0_t Op0;
106+
107+
cst_match(Op0_t Op0) : Op0(Op0) {}
108+
109+
bool match(const SCEV *S) const {
110+
assert((isa<SCEVCouldNotCompute>(S) || !S->getType()->isVectorTy()) &&
111+
"no vector types expected from SCEVs");
112+
auto *C = dyn_cast<SCEVConstant>(S);
113+
return C && C->getAPInt() == Op0;
114+
}
115+
};
116+
117+
/// Match an SCEV constant with an APInt.
118+
inline cst_match<APInt> m_SCEVConstant(const APInt &V) { return V; }
119+
120+
/// Match an SCEV constant with a plain integer.
121+
inline cst_match<uint64_t> m_SCEVConstant(uint64_t V) { return V; }
122+
94123
/// Match a unary SCEV.
95124
template <typename SCEVTy, typename Op0_t> struct SCEVUnaryExpr_match {
96125
Op0_t Op0;
@@ -147,6 +176,17 @@ m_scev_Add(const Op0_t &Op0, const Op1_t &Op1) {
147176
return m_scev_Binary<SCEVAddExpr>(Op0, Op1);
148177
}
149178

179+
template <typename Op0_t, typename Op1_t>
180+
inline SCEVBinaryExpr_match<SCEVMulExpr, Op0_t, Op1_t>
181+
m_scev_Mul(const Op0_t &Op0, const Op1_t &Op1) {
182+
return m_scev_Binary<SCEVMulExpr>(Op0, Op1);
183+
}
184+
185+
template <typename Op0_t, typename Op1_t>
186+
inline SCEVBinaryExpr_match<SCEVUDivExpr, Op0_t, Op1_t>
187+
m_scev_UDiv(const Op0_t &Op0, const Op1_t &Op1) {
188+
return m_scev_Binary<SCEVUDivExpr>(Op0, Op1);
189+
}
150190
} // namespace SCEVPatternMatch
151191
} // namespace llvm
152192

0 commit comments

Comments
 (0)