[llvm] [IR] Move RepeatedPass into separate header (NFC) (PR #96211)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 09:11:46 PDT 2024
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/96211
I don't think there is a good reason for this pass to be part of the core PassManager.h header (which is included ~everywhere), so move it into a separate one. This should enable us to also drop the PassInstrumentation.h include in PassManager.h in a followup.
>From 671ba6d476c1e4e395d75ea9989d234c1e6ad26f Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 20 Jun 2024 17:51:13 +0200
Subject: [PATCH] [IR] Move RepeatedPass into separate header (NFC)
I don't think there is a good reason for this pass to be part of
the core PassManager.h header, so move it into a separate one.
This should enable us to also drop the PassInstrumentation.h
include in PassManager.h in a followup.
---
llvm/include/llvm/IR/PassManager.h | 52 --------------
llvm/include/llvm/IR/RepeatedPass.h | 70 +++++++++++++++++++
.../llvm/Transforms/Scalar/LoopPassManager.h | 1 +
3 files changed, 71 insertions(+), 52 deletions(-)
create mode 100644 llvm/include/llvm/IR/RepeatedPass.h
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index 5661a1d58c8ec..65ba524bf49c4 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -950,58 +950,6 @@ struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
}
};
-/// A utility pass template that simply runs another pass multiple times.
-///
-/// This can be useful when debugging or testing passes. It also serves as an
-/// example of how to extend the pass manager in ways beyond composition.
-template <typename PassT>
-class RepeatedPass : public PassInfoMixin<RepeatedPass<PassT>> {
-public:
- RepeatedPass(int Count, PassT &&P)
- : Count(Count), P(std::forward<PassT>(P)) {}
-
- template <typename IRUnitT, typename AnalysisManagerT, typename... Ts>
- PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args) {
-
- // Request PassInstrumentation from analysis manager, will use it to run
- // instrumenting callbacks for the passes later.
- // Here we use std::tuple wrapper over getResult which helps to extract
- // AnalysisManager's arguments out of the whole Args set.
- PassInstrumentation PI =
- detail::getAnalysisResult<PassInstrumentationAnalysis>(
- AM, IR, std::tuple<Ts...>(Args...));
-
- auto PA = PreservedAnalyses::all();
- for (int i = 0; i < Count; ++i) {
- // Check the PassInstrumentation's BeforePass callbacks before running the
- // pass, skip its execution completely if asked to (callback returns
- // false).
- if (!PI.runBeforePass<IRUnitT>(P, IR))
- continue;
- PreservedAnalyses IterPA = P.run(IR, AM, std::forward<Ts>(Args)...);
- PA.intersect(IterPA);
- PI.runAfterPass(P, IR, IterPA);
- }
- return PA;
- }
-
- void printPipeline(raw_ostream &OS,
- function_ref<StringRef(StringRef)> MapClassName2PassName) {
- OS << "repeat<" << Count << ">(";
- P.printPipeline(OS, MapClassName2PassName);
- OS << ')';
- }
-
-private:
- int Count;
- PassT P;
-};
-
-template <typename PassT>
-RepeatedPass<PassT> createRepeatedPass(int Count, PassT &&P) {
- return RepeatedPass<PassT>(Count, std::forward<PassT>(P));
-}
-
} // end namespace llvm
#endif // LLVM_IR_PASSMANAGER_H
diff --git a/llvm/include/llvm/IR/RepeatedPass.h b/llvm/include/llvm/IR/RepeatedPass.h
new file mode 100644
index 0000000000000..902324bc28a60
--- /dev/null
+++ b/llvm/include/llvm/IR/RepeatedPass.h
@@ -0,0 +1,70 @@
+//===- RepeatedPass.h - Runs another pass multiple times --------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_REPEATEDPASS_H
+#define LLVM_IR_REPEATEDPASS_H
+
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+/// A utility pass template that simply runs another pass multiple times.
+///
+/// This can be useful when debugging or testing passes. It also serves as an
+/// example of how to extend the pass manager in ways beyond composition.
+template <typename PassT>
+class RepeatedPass : public PassInfoMixin<RepeatedPass<PassT>> {
+public:
+ RepeatedPass(int Count, PassT &&P)
+ : Count(Count), P(std::forward<PassT>(P)) {}
+
+ template <typename IRUnitT, typename AnalysisManagerT, typename... Ts>
+ PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, Ts &&... Args) {
+
+ // Request PassInstrumentation from analysis manager, will use it to run
+ // instrumenting callbacks for the passes later.
+ // Here we use std::tuple wrapper over getResult which helps to extract
+ // AnalysisManager's arguments out of the whole Args set.
+ PassInstrumentation PI =
+ detail::getAnalysisResult<PassInstrumentationAnalysis>(
+ AM, IR, std::tuple<Ts...>(Args...));
+
+ auto PA = PreservedAnalyses::all();
+ for (int i = 0; i < Count; ++i) {
+ // Check the PassInstrumentation's BeforePass callbacks before running the
+ // pass, skip its execution completely if asked to (callback returns
+ // false).
+ if (!PI.runBeforePass<IRUnitT>(P, IR))
+ continue;
+ PreservedAnalyses IterPA = P.run(IR, AM, std::forward<Ts>(Args)...);
+ PA.intersect(IterPA);
+ PI.runAfterPass(P, IR, IterPA);
+ }
+ return PA;
+ }
+
+ void printPipeline(raw_ostream &OS,
+ function_ref<StringRef(StringRef)> MapClassName2PassName) {
+ OS << "repeat<" << Count << ">(";
+ P.printPipeline(OS, MapClassName2PassName);
+ OS << ')';
+ }
+
+private:
+ int Count;
+ PassT P;
+};
+
+template <typename PassT>
+RepeatedPass<PassT> createRepeatedPass(int Count, PassT &&P) {
+ return RepeatedPass<PassT>(Count, std::forward<PassT>(P));
+}
+
+} // end namespace llvm
+
+#endif // LLVM_IR_REPEATEDPASS_H
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
index 6aab1f98e6781..5807892230abb 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
@@ -41,6 +41,7 @@
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopNestAnalysis.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/IR/RepeatedPass.h"
#include "llvm/Transforms/Utils/LCSSA.h"
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
More information about the llvm-commits
mailing list