From eae97523817a184326d31aaf8a2ac4278d4ae67f Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Thu, 13 Dec 2012 02:55:53 +0000 Subject: [PATCH] m_CombineOr and m_CombineAnd pattern combinators llvm-svn: 170086 --- llvm/include/llvm/Support/PatternMatch.h | 59 ++++++++++++++++++++---- 1 file changed, 49 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/Support/PatternMatch.h b/llvm/include/llvm/Support/PatternMatch.h index fcd8db167d6c..edf997de59d7 100644 --- a/llvm/include/llvm/Support/PatternMatch.h +++ b/llvm/include/llvm/Support/PatternMatch.h @@ -75,6 +75,52 @@ inline class_match m_Undef() { return class_match(); } inline class_match m_Constant() { return class_match(); } +/// Matching combinators +template +struct match_combine_or { + LTy L; + RTy R; + + match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) { } + + template + bool match(ITy *V) { + if (L.match(V)) + return true; + if (R.match(V)) + return true; + return false; + } +}; + +template +struct match_combine_and { + LTy L; + RTy R; + + match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) { } + + template + bool match(ITy *V) { + if (L.match(V)) + if (R.match(V)) + return true; + return false; + } +}; + +/// Combine two pattern matchers matching L || R +template +inline match_combine_or m_CombineOr(const LTy &L, const RTy &R) { + return match_combine_or(L, R); +} + +/// Combine two pattern matchers matching L && R +template +inline match_combine_and m_CombineAnd(const LTy &L, const RTy &R) { + return match_combine_and(L, R); +} + struct match_zero { template bool match(ITy *V) { @@ -103,19 +149,12 @@ struct match_neg_zero { /// zero inline match_neg_zero m_NegZero() { return match_neg_zero(); } -struct match_any_zero { - template - bool match(ITy *V) { - if (const Constant *C = dyn_cast(V)) - return C->isNullValue() || C->isNegativeZeroValue(); - return false; - } -}; - /// m_AnyZero() - Match an arbitrary zero/null constant. This includes /// zero_initializer for vectors and ConstantPointerNull for pointers. For /// floating point constants, this will match negative zero and positive zero -inline match_any_zero m_AnyZero() { return match_any_zero(); } +inline match_combine_or m_AnyZero() { + return m_CombineOr(m_Zero(), m_NegZero()); +} struct apint_match { const APInt *&Res;