1- // ===- ExtraPassManager .h - Loop pass management -------- ---------*- C++
1+ // ===- ExtraFunctionPassManager .h - Run Optimizations on Demand ---------*- C++
22// -*-===//
33//
4+ //
45// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
56// See https://llvm.org/LICENSE.txt for license information.
67// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
1718#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
1819
1920#include " llvm/IR/PassManager.h"
21+ #include " llvm/Transforms/Scalar/LoopPassManager.h"
2022
2123namespace llvm {
2224
@@ -32,17 +34,30 @@ template <typename MarkerTy> struct ShouldRunExtraPasses {
3234 auto PAC = PA.getChecker <MarkerTy>();
3335 return !PAC.preservedWhenStateless ();
3436 }
37+
38+ bool invalidate (Loop &L, const PreservedAnalyses &PA,
39+ LoopAnalysisManager::Invalidator &) {
40+ // Check whether the analysis has been explicitly invalidated. Otherwise,
41+ // it remains preserved.
42+ auto PAC = PA.getChecker <MarkerTy>();
43+ return !PAC.preservedWhenStateless ();
44+ }
3545 };
3646
3747 Result run (Function &F, FunctionAnalysisManager &FAM) { return Result (); }
48+
49+ Result run (Loop &L, LoopAnalysisManager &AM,
50+ LoopStandardAnalysisResults &AR) {
51+ return Result ();
52+ }
3853};
3954
4055// / A pass manager to run a set of extra function passes if the
4156// / ShouldRunExtraPasses marker analysis is present. This allows passes to
4257// / request additional transformations on demand. An example is extra
4358// / simplifications after loop-vectorization, if runtime checks have been added.
4459template <typename MarkerTy>
45- struct ExtraPassManager : public FunctionPassManager {
60+ struct ExtraFunctionPassManager : public FunctionPassManager {
4661 PreservedAnalyses run (Function &F, FunctionAnalysisManager &AM) {
4762 auto PA = PreservedAnalyses::all ();
4863 if (AM.getCachedResult <MarkerTy>(F))
@@ -51,6 +66,24 @@ struct ExtraPassManager : public FunctionPassManager {
5166 return PA;
5267 }
5368};
69+
70+ // / A pass manager to run a set of extra loop passes if the MarkerTy analysis is
71+ // / present. This allows passes to request additional transformations on demand.
72+ // / An example is doing additional runs of SimpleLoopUnswitch.
73+ template <typename MarkerTy>
74+ struct ExtraLoopPassManager : public LoopPassManager {
75+ PreservedAnalyses run (Loop &L, LoopAnalysisManager &AM,
76+ LoopStandardAnalysisResults &AR, LPMUpdater &U) {
77+ auto PA = PreservedAnalyses::all ();
78+ if (AM.getCachedResult <MarkerTy>(L))
79+ PA.intersect (LoopPassManager::run (L, AM, AR, U));
80+ PA.abandon <MarkerTy>();
81+ return PA;
82+ }
83+
84+ static bool isRequired () { return true ; }
85+ };
86+
5487} // namespace llvm
5588
5689#endif // LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
0 commit comments