diff options
Diffstat (limited to 'include/llvm/IR/PatternMatch.h')
-rw-r--r-- | include/llvm/IR/PatternMatch.h | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/include/llvm/IR/PatternMatch.h b/include/llvm/IR/PatternMatch.h index 2efb294..4783062 100644 --- a/include/llvm/IR/PatternMatch.h +++ b/include/llvm/IR/PatternMatch.h @@ -32,7 +32,7 @@ #include "llvm/IR/CallSite.h" #include "llvm/IR/Constants.h" #include "llvm/IR/Instructions.h" -#include "llvm/IR/IntrinsicInst.h" +#include "llvm/IR/Intrinsics.h" #include "llvm/IR/Operator.h" namespace llvm { @@ -362,6 +362,29 @@ struct bind_const_intval_ty { } }; +/// Match a specified integer value or vector of all elements of that value. +struct specific_intval { + uint64_t Val; + specific_intval(uint64_t V) : Val(V) {} + + template<typename ITy> + bool match(ITy *V) { + ConstantInt *CI = dyn_cast<ConstantInt>(V); + if (!CI && V->getType()->isVectorTy()) + if (const auto *C = dyn_cast<Constant>(V)) + CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()); + + if (CI && CI->getBitWidth() <= 64) + return CI->getZExtValue() == Val; + + return false; + } +}; + +/// Match a specific integer value or vector with all elements equal to the +/// value. +inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); } + /// m_ConstantInt - Match a ConstantInt and bind to its value. This does not /// match ConstantInts wider than 64-bits. inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; } @@ -1135,8 +1158,10 @@ struct IntrinsicID_match { template<typename OpTy> bool match(OpTy *V) { - IntrinsicInst *II = dyn_cast<IntrinsicInst>(V); - return II && II->getIntrinsicID() == ID; + if (const CallInst *CI = dyn_cast<CallInst>(V)) + if (const Function *F = CI->getCalledFunction()) + return F->getIntrinsicID() == ID; + return false; } }; @@ -1205,6 +1230,18 @@ m_BSwap(const Opnd0 &Op0) { return m_Intrinsic<Intrinsic::bswap>(Op0); } +template<typename Opnd0, typename Opnd1> +inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty +m_FMin(const Opnd0 &Op0, const Opnd1 &Op1) { + return m_Intrinsic<Intrinsic::minnum>(Op0, Op1); +} + +template<typename Opnd0, typename Opnd1> +inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty +m_FMax(const Opnd0 &Op0, const Opnd1 &Op1) { + return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1); +} + } // end namespace PatternMatch } // end namespace llvm |