diff options
Diffstat (limited to 'llvm/include/llvm/IR/PatternMatch.h')
-rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 48e07862c07..8b1c6b2f350 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -132,18 +132,6 @@ inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) { return match_combine_and<LTy, RTy>(L, R); } -struct match_zero { - template <typename ITy> bool match(ITy *V) { - if (const auto *C = dyn_cast<Constant>(V)) - return C->isNullValue(); - return false; - } -}; - -/// Match an arbitrary zero/null constant. This includes -/// zero_initializer for vectors and ConstantPointerNull for pointers. -inline match_zero m_Zero() { return match_zero(); } - struct apint_match { const APInt *&Res; @@ -365,6 +353,27 @@ inline cst_pred_ty<is_one> m_One() { return cst_pred_ty<is_one>(); } +struct is_zero_int { + bool isValue(const APInt &C) { return C.isNullValue(); } +}; +/// Match an integer 0 or a vector with all elements equal to 0. +/// For vectors, this includes constants with undefined elements. +inline cst_pred_ty<is_zero_int> m_ZeroInt() { + return cst_pred_ty<is_zero_int>(); +} + +struct is_zero { + template <typename ITy> bool match(ITy *V) { + auto *C = dyn_cast<Constant>(V); + return C && (C->isNullValue() || cst_pred_ty<is_zero_int>().match(C)); + } +}; +/// Match any null constant or a vector with all elements equal to 0. +/// For vectors, this includes constants with undefined elements. +inline is_zero m_Zero() { + return is_zero(); +} + struct is_power2 { bool isValue(const APInt &C) { return C.isPowerOf2(); } }; |