[PATCH] Add a new matcher m_ICmpWithPred

Sanjoy Das sanjoy at playingwithpointers.com
Tue Dec 16 14:01:29 PST 2014


This simplifies a later change

http://reviews.llvm.org/D6692

Files:
  include/llvm/IR/PatternMatch.h

Index: include/llvm/IR/PatternMatch.h
===================================================================
--- include/llvm/IR/PatternMatch.h
+++ include/llvm/IR/PatternMatch.h
@@ -705,6 +705,24 @@
   }
 };
 
+template<typename LHS_t, typename RHS_t, typename Class, typename PredicateTy, PredicateTy P>
+struct CmpClassPred_match {
+  LHS_t L;
+  RHS_t R;
+
+  CmpClassPred_match(const LHS_t &LHS, const RHS_t &RHS)
+    : L(LHS), R(RHS) {}
+
+  template<typename OpTy>
+  bool match(OpTy *V) {
+    PredicateTy Pred;
+    CmpClass_match<LHS_t, RHS_t, Class, PredicateTy> Inner(Pred, L, R);
+    if (Inner.match(V))
+      return Pred == P;
+    return false;
+  }
+};
+
 template <typename LHS, typename RHS>
 inline CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>
 m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
@@ -717,6 +735,13 @@
   return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(Pred, L, R);
 }
 
+template<ICmpInst::Predicate P, typename LHS, typename RHS>
+inline CmpClassPred_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, P>
+m_ICmpWithPred(const LHS &L, const RHS &R) {
+  return CmpClassPred_match<LHS, RHS,
+                            ICmpInst, ICmpInst::Predicate, P>(L, R);
+}
+
 template <typename LHS, typename RHS>
 inline CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>
 m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6692.17361.patch
Type: text/x-patch
Size: 1400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141216/41c1616d/attachment.bin>


More information about the llvm-commits mailing list