[llvm] 95af971 - [PatternMatch] Improve m_Deferred() documentation (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 24 12:00:38 PDT 2021


Author: Nikita Popov
Date: 2021-04-24T21:00:24+02:00
New Revision: 95af971764186a2af6158af26e5aa905a55be586

URL: https://github.com/llvm/llvm-project/commit/95af971764186a2af6158af26e5aa905a55be586
DIFF: https://github.com/llvm/llvm-project/commit/95af971764186a2af6158af26e5aa905a55be586.diff

LOG: [PatternMatch] Improve m_Deferred() documentation (NFC)

m_Deferred() has nothing to do with commutative matchers, it needs
to be used whenever the value to match is determinde as part of
the same match expression.

Added: 
    

Modified: 
    llvm/include/llvm/IR/PatternMatch.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index cdc8d272b3226..a67e666ca059c 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -811,7 +811,12 @@ template <typename Class> struct deferredval_ty {
   template <typename ITy> bool match(ITy *const V) { return V == Val; }
 };
 
-/// A commutative-friendly version of m_Specific().
+/// Like m_Specific(), but works if the specific value to match is determined
+/// as part of the same match() expression. For example:
+/// m_Add(m_Value(X), m_Specific(X)) is incorrect, because m_Specific() will
+/// bind X before the pattern match starts.
+/// m_Add(m_Value(X), m_Deferred(X)) is correct, and will check against
+/// whichever value m_Value(X) populated.
 inline deferredval_ty<Value> m_Deferred(Value *const &V) { return V; }
 inline deferredval_ty<const Value> m_Deferred(const Value *const &V) {
   return V;


        


More information about the llvm-commits mailing list