From 3443493cc71c46cf71c90e478403017063a035f0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 26 Apr 2011 19:50:39 +0000 Subject: [PATCH] add an m_ConstantInt matching predicate that binds to a uint64_t, and add an m_OneUse() predicate that matches if the subexpr has a single use. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130235 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/PatternMatch.h | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h index 948ae5176ee..172480e7ae6 100644 --- a/include/llvm/Support/PatternMatch.h +++ b/include/llvm/Support/PatternMatch.h @@ -40,6 +40,23 @@ bool match(Val *V, const Pattern &P) { return const_cast(P).match(V); } + +template +struct OneUse_match { + SubPattern_t SubPattern; + + OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {} + + template + bool match(OpTy *V) { + return V->hasOneUse() && SubPattern.match(V); + } +}; + +template +inline OneUse_match m_OneUse(const T &SubPattern) { return SubPattern; } + + template struct class_match { template @@ -227,7 +244,25 @@ struct specificval_ty { /// m_Specific - Match if we have a specific specified value. inline specificval_ty m_Specific(const Value *V) { return V; } +struct bind_const_intval_ty { + uint64_t &VR; + bind_const_intval_ty(uint64_t &V) : VR(V) {} + + template + bool match(ITy *V) { + if (ConstantInt *CV = dyn_cast(V)) + if (CV->getBitWidth() <= 64) { + VR = CV->getZExtValue(); + return true; + } + return false; + } +}; +/// 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; } + //===----------------------------------------------------------------------===// // Matchers for specific binary operators. // -- 2.34.1