[llvm] [PatternMatching] Add generic API for matching constants using custom conditions (PR #85676)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 25 22:14:52 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 and 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) {
+ api_pred_ty<custom_checkfn<APInt>> P(V);
+ P.CheckFn = CheckFn;
+ return P;
+}
+
+// Match and float or vector where CheckFn(ele) for each element is true.
+// For vectors, poison elements are assumed to match.
----------------
nikic wrote:
```suggestion
/// Match and float or vector where CheckFn(ele) for each element is true.
/// For vectors, poison elements are assumed to match.
```
https://github.com/llvm/llvm-project/pull/85676
More information about the llvm-commits
mailing list