From 1d4b1507045075273cb301efec8722b961b78c22 Mon Sep 17 00:00:00 2001 From: Michael Ilseman Date: Wed, 12 Dec 2012 00:23:43 +0000 Subject: [PATCH] Pattern matchers for floating point values m_ConstantFP - match and bind a float constant m_SpecificConstantFP - match a specific floating point value or vector of floats of that value m_FPOne - match a floating point 1.0 or vector of 1.0s m_NegZero - match -0.0 m_AnyZero - match 0 or -0.0 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169939 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/PatternMatch.h | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 094188082ef..fcd8db167d6 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -88,6 +88,34 @@ struct match_zero { /// zero_initializer for vectors and ConstantPointerNull for pointers. inline match_zero m_Zero() { return match_zero(); } +struct match_neg_zero { + template + bool match(ITy *V) { + if (const Constant *C = dyn_cast(V)) + return C->isNegativeZeroValue(); + return false; + } +}; + +/// m_NegZero() - 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 but not positive +/// 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(); } struct apint_match { const APInt *&Res; @@ -236,6 +264,9 @@ inline bind_ty m_ConstantInt(ConstantInt *&CI) { return CI; } /// m_Constant - Match a Constant, capturing the value if we match. inline bind_ty m_Constant(Constant *&C) { return C; } +/// m_ConstantFP - Match a ConstantFP, capturing the value if we match. +inline bind_ty m_ConstantFP(ConstantFP *&C) { return C; } + /// specificval_ty - Match a specified Value*. struct specificval_ty { const Value *Val; @@ -250,6 +281,31 @@ struct specificval_ty { /// m_Specific - Match if we have a specific specified value. inline specificval_ty m_Specific(const Value *V) { return V; } +/// Match a specified floating point value or vector of all elements of that +/// value. +struct specific_fpval { + double Val; + specific_fpval(double V) : Val(V) {} + + template + bool match(ITy *V) { + if (const ConstantFP *CFP = dyn_cast(V)) + return CFP->isExactlyValue(Val); + if (V->getType()->isVectorTy()) + if (const Constant *C = dyn_cast(V)) + if (ConstantFP *CFP = dyn_cast_or_null(C->getSplatValue())) + return CFP->isExactlyValue(Val); + return false; + } +}; + +/// Match a specific floating point value or vector with all elements equal to +/// the value. +inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); } + +/// Match a float 1.0 or vector with all elements equal to 1.0. +inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); } + struct bind_const_intval_ty { uint64_t &VR; bind_const_intval_ty(uint64_t &V) : VR(V) {}