[llvm] [Passes] Generalize ShouldRunExtraVectorPasses to allow re-use (NFCI). (PR #118323)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 4 06:02:43 PST 2024


================
@@ -0,0 +1,56 @@
+//===- ExtraPassManager.h - Loop pass management -----------------*- C++
+//-*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+/// \file
+///
+/// This file provides a pass manager that only runs its passes if the
+/// provided marker analysis has been preserved, together with a class to
+/// define such a marker analysis.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
+#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+/// A marker analysis to determine if extra passes should be run on demand.
+/// Passes requesting extra transformations to run need to request and preserve
+/// this analysis.
+template <typename MarkerTy> struct ShouldRunExtraPasses {
+  struct Result {
+    bool invalidate(Function &F, const PreservedAnalyses &PA,
+                    FunctionAnalysisManager::Invalidator &) {
+      // Check whether the analysis has been explicitly invalidated. Otherwise,
+      // it remains preserved.
+      auto PAC = PA.getChecker<MarkerTy>();
+      return !PAC.preservedWhenStateless();
+    }
+  };
+
+  Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
+};
+
+/// A pass manager to run a set of extra function passes if the
+/// ShouldRunExtraPasses marker analysis is present. This allows passes to
+/// request additional transformations on demand. An example is extra
+/// simplifications after loop-vectorization, if runtime checks have been added.
+template <typename MarkerTy>
+struct ExtraPassManager : public FunctionPassManager {
----------------
fhahn wrote:

Yep, update the name and moved `ExtraLoopPassManager` here as well. Extended `ShouldRunExtraPasses` to support Loops as well

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


More information about the llvm-commits mailing list