[llvm] [PatternMatching] Add generic API for matching constants using custom conditions (PR #85676)

via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 11:36:21 PDT 2024


================
@@ -460,6 +460,39 @@ template <typename Predicate> struct apf_pred_ty : public Predicate {
 //
 ///////////////////////////////////////////////////////////////////////////////
 
+template <typename APTy> struct custom_checkfn {
+  function_ref<bool(const APTy &)> CheckFn;
+  bool isValue(const APTy &C) { return CheckFn(C); }
+};
+
+/// Match an integer or vector where CheckFn(ele) for each element is true.
+/// For vectors, poison elements are assumed to match.
+inline cst_pred_ty<custom_checkfn<APInt>>
+m_CheckedInt(function_ref<bool(const APInt &)> CheckFn) {
+  return cst_pred_ty<custom_checkfn<APInt>>{CheckFn};
+}
+
+inline api_pred_ty<custom_checkfn<APInt>>
+m_CheckedInt(const APInt *&V, function_ref<bool(const APInt &)> CheckFn) {
----------------
goldsteinn wrote:

See: https://github.com/llvm/llvm-project/pull/91377 decided not to do the other. Didn't seem like much upside and made code less compact.

https://github.com/llvm/llvm-project/pull/85676


More information about the llvm-commits mailing list