[llvm] [SCEV] Add initial pattern matching for SCEV constants. (NFC) (PR #119389)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 05:11:03 PST 2024
================
@@ -0,0 +1,73 @@
+//===----------------------------------------------------------------------===//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides a simple and efficient mechanism for performing general
+// tree-based pattern matches on SCEVs, based on LLVM's IR pattern matchers.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
+#define LLVM_ANALYSIS_SCALAREVOLUTIONPATTERNMATCH_H
+
+#include "llvm/Analysis/ScalarEvolutionExpressions.h"
+
+namespace llvm {
+namespace SCEVPatternMatch {
+
+template <typename Val, typename Pattern>
+bool match(const SCEV *S, const Pattern &P) {
+ return P.match(S);
+}
+
+template <typename Predicate> struct cst_pred_ty : public Predicate {
+ bool match(const SCEV *S) {
+ auto *C = dyn_cast<SCEVConstant>(S);
+ return C && this->isValue(C->getAPInt());
+ }
+};
+
+struct is_zero_int {
+ bool isValue(const APInt &C) { return C.isZero(); }
+};
+
+/// Match an integer 0 or a vector with all elements equal to 0.
+/// For vectors, this includes constants with undefined elements.
----------------
fhahn wrote:
Yep, simplified thanks, and added an assert that we don't encounter vector types.
https://github.com/llvm/llvm-project/pull/119389
More information about the llvm-commits
mailing list