Skip to content

Commit c7772d2

Browse files
committed
!fixup move extra loop pass manager and adjust naming & comments
1 parent a43ded1 commit c7772d2

File tree

4 files changed

+49
-39
lines changed

4 files changed

+49
-39
lines changed

llvm/include/llvm/Transforms/Scalar/SimpleLoopUnswitch.h

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/Analysis/LoopAnalysisManager.h"
1414
#include "llvm/IR/PassManager.h"
1515
#include "llvm/Transforms/Scalar/LoopPassManager.h"
16+
#include "llvm/Transforms/Utils/ExtraPassManager.h"
1617

1718
namespace llvm {
1819

@@ -21,40 +22,6 @@ class Loop;
2122
class StringRef;
2223
class raw_ostream;
2324

24-
struct ShouldRunExtraSimpleLoopUnswitch
25-
: public AnalysisInfoMixin<ShouldRunExtraSimpleLoopUnswitch> {
26-
static AnalysisKey Key;
27-
struct Result {
28-
bool invalidate(Loop &L, const PreservedAnalyses &PA,
29-
LoopAnalysisManager::Invalidator &) {
30-
// Check whether the analysis has been explicitly invalidated. Otherwise,
31-
// it remains preserved.
32-
auto PAC = PA.getChecker<ShouldRunExtraSimpleLoopUnswitch>();
33-
return !PAC.preservedWhenStateless();
34-
}
35-
};
36-
37-
Result run(Loop &L, LoopAnalysisManager &AM,
38-
LoopStandardAnalysisResults &AR) {
39-
return Result();
40-
}
41-
42-
static bool isRequired() { return true; }
43-
};
44-
45-
struct ExtraSimpleLoopUnswitchPassManager : public LoopPassManager {
46-
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM,
47-
LoopStandardAnalysisResults &AR, LPMUpdater &U) {
48-
auto PA = PreservedAnalyses::all();
49-
if (AM.getCachedResult<ShouldRunExtraSimpleLoopUnswitch>(L))
50-
PA.intersect(LoopPassManager::run(L, AM, AR, U));
51-
PA.abandon<ShouldRunExtraSimpleLoopUnswitch>();
52-
return PA;
53-
}
54-
55-
static bool isRequired() { return true; }
56-
};
57-
5825
/// This pass transforms loops that contain branches or switches on loop-
5926
/// invariant conditions to have multiple loops. For example, it turns the left
6027
/// into the right code:
@@ -113,6 +80,16 @@ class SimpleLoopUnswitchPass : public PassInfoMixin<SimpleLoopUnswitchPass> {
11380
function_ref<StringRef(StringRef)> MapClassName2PassName);
11481
};
11582

83+
/// A marker analysis to determine if SimpleLoopUnswitch should run again on a
84+
/// given loop.
85+
struct ShouldRunExtraSimpleLoopUnswitch
86+
: public ShouldRunExtraPasses<ShouldRunExtraSimpleLoopUnswitch>,
87+
public AnalysisInfoMixin<ShouldRunExtraSimpleLoopUnswitch> {
88+
static AnalysisKey Key;
89+
90+
static bool isRequired() { return true; }
91+
};
92+
11693
} // end namespace llvm
11794

11895
#endif // LLVM_TRANSFORMS_SCALAR_SIMPLELOOPUNSWITCH_H

llvm/include/llvm/Transforms/Utils/ExtraPassManager.h

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
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
@@ -17,6 +18,7 @@
1718
#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
1819

1920
#include "llvm/IR/PassManager.h"
21+
#include "llvm/Transforms/Scalar/LoopPassManager.h"
2022

2123
namespace 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.
4459
template <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

llvm/include/llvm/Transforms/Vectorize/LoopVectorize.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ void reportVectorizationFailure(const StringRef DebugMsg,
170170
const StringRef OREMsg, const StringRef ORETag,
171171
OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr);
172172

173-
/// A marker analyss to determine if extra passes should be run after loop
173+
/// A marker analysis to determine if extra passes should be run after loop
174174
/// vectorization.
175175
struct ShouldRunExtraVectorPasses
176176
: public ShouldRunExtraPasses<ShouldRunExtraVectorPasses>,

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
661661
LPM2.addPass(IndVarSimplifyPass());
662662

663663
{
664-
ExtraSimpleLoopUnswitchPassManager ExtraPasses;
664+
ExtraLoopPassManager<ShouldRunExtraSimpleLoopUnswitch> ExtraPasses;
665665
ExtraPasses.addPass(SimpleLoopUnswitchPass(/* NonTrivial */ Level ==
666666
OptimizationLevel::O3));
667667
LPM2.addPass(std::move(ExtraPasses));
@@ -1308,7 +1308,7 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
13081308
FPM.addPass(InstCombinePass());
13091309

13101310
if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1311-
ExtraPassManager<ShouldRunExtraVectorPasses> ExtraPasses;
1311+
ExtraFunctionPassManager<ShouldRunExtraVectorPasses> ExtraPasses;
13121312
// At higher optimization levels, try to clean up any runtime overlap and
13131313
// alignment checks inserted by the vectorizer. We want to track correlated
13141314
// runtime checks for two inner loops in the same outer loop, fold any

0 commit comments

Comments
 (0)