-
Notifications
You must be signed in to change notification settings - Fork 14k
[IR] Remove RepeatedPass #96211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[IR] Remove RepeatedPass #96211
Conversation
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/pr-subscribers-coroutines @llvm/pr-subscribers-llvm-transforms Author: Nikita Popov (nikic) ChangesI 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. Full diff: https://github.com/llvm/llvm-project/pull/96211.diff 3 Files Affected:
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"
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be able to remove RepeatedPass altogether, nothing uses it and it's not really that useful
Good point. I went ahead and dropped it entirely. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This pass is not used in any pipeline, barely used in tests and not really useful, so drop it. The only place where we "repeat" passes is devirt repetition, and that is done using a separate pass.
This pass is not used in any pipeline, barely used in tests and not really useful, so drop it. The only place where we "repeat" passes is devirt repetition, and that is done using a separate pass.