Skip to content

Commit 17a32ea

Browse files
committed
[Passes] Generalize ShouldRunExtraVectorPasses to allow re-use (NFCI).
Generalize ShouldRunExtraVectorPasses toj ShouldRunExtraPasses, to allow re-use for other transformations. I intend to use this to let LowerMatrixIntrinsicsPass request EarlyCSE if there are any matrix constructs to lower. This should allow enabling LowerMatrixIntrinsics without a noticable compile-time hit.
1 parent 356df2d commit 17a32ea

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

llvm/include/llvm/IR/PassManager.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,38 @@ struct InvalidateAllAnalysesPass : PassInfoMixin<InvalidateAllAnalysesPass> {
935935
}
936936
};
937937

938+
/// A marker analyss to determine if extra passes should be run on demand.
939+
/// Passes requesting extra transformations to run need to request and preserve
940+
/// this analysis.
941+
struct ShouldRunExtraPasses : public AnalysisInfoMixin<ShouldRunExtraPasses> {
942+
static AnalysisKey Key;
943+
struct Result {
944+
bool invalidate(Function &F, const PreservedAnalyses &PA,
945+
FunctionAnalysisManager::Invalidator &) {
946+
// Check whether the analysis has been explicitly invalidated. Otherwise,
947+
// it remains preserved.
948+
auto PAC = PA.getChecker<ShouldRunExtraPasses>();
949+
return !PAC.preservedWhenStateless();
950+
}
951+
};
952+
953+
Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
954+
};
955+
956+
/// A pass manager to run a set of extra function passes if the
957+
/// ShouldRunExtraPasses marker analysis is present. This allows passes to
958+
/// request additional transformations on demand. An example is extra
959+
/// simplifications after loop-vectorization, if runtime checks have been added.
960+
struct ExtraPassManager : public FunctionPassManager {
961+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
962+
auto PA = PreservedAnalyses::all();
963+
if (AM.getCachedResult<ShouldRunExtraPasses>(F))
964+
PA.intersect(FunctionPassManager::run(F, AM));
965+
PA.abandon<ShouldRunExtraPasses>();
966+
return PA;
967+
}
968+
};
969+
938970
} // end namespace llvm
939971

940972
#endif // LLVM_IR_PASSMANAGER_H

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

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,6 @@ class TargetTransformInfo;
8080
extern cl::opt<bool> EnableLoopInterleaving;
8181
extern cl::opt<bool> EnableLoopVectorization;
8282

83-
/// A marker to determine if extra passes after loop vectorization should be
84-
/// run.
85-
struct ShouldRunExtraVectorPasses
86-
: public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
87-
static AnalysisKey Key;
88-
struct Result {
89-
bool invalidate(Function &F, const PreservedAnalyses &PA,
90-
FunctionAnalysisManager::Invalidator &) {
91-
// Check whether the analysis has been explicitly invalidated. Otherwise,
92-
// it remains preserved.
93-
auto PAC = PA.getChecker<ShouldRunExtraVectorPasses>();
94-
return !PAC.preservedWhenStateless();
95-
}
96-
};
97-
98-
Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
99-
};
100-
101-
/// A pass manager to run a set of extra function simplification passes after
102-
/// vectorization, if requested. LoopVectorize caches the
103-
/// ShouldRunExtraVectorPasses analysis to request extra simplifications, if
104-
/// they could be beneficial.
105-
struct ExtraVectorPassManager : public FunctionPassManager {
106-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
107-
auto PA = PreservedAnalyses::all();
108-
if (AM.getCachedResult<ShouldRunExtraVectorPasses>(F))
109-
PA.intersect(FunctionPassManager::run(F, AM));
110-
PA.abandon<ShouldRunExtraVectorPasses>();
111-
return PA;
112-
}
113-
};
114-
11583
struct LoopVectorizeOptions {
11684
/// If false, consider all loops for interleaving.
11785
/// If true, only loops that explicitly request interleaving are considered.

llvm/lib/IR/PassManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,5 @@ void llvm::printIRUnitNameForStackTrace<Function>(raw_ostream &OS,
160160
AnalysisSetKey CFGAnalyses::SetKey;
161161

162162
AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
163+
164+
AnalysisKey ShouldRunExtraPasses::Key;

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,8 +1306,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
13061306
// Cleanup after the loop optimization passes.
13071307
FPM.addPass(InstCombinePass());
13081308

1309+
ExtraPassManager ExtraPasses;
13091310
if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1310-
ExtraVectorPassManager ExtraPasses;
13111311
// At higher optimization levels, try to clean up any runtime overlap and
13121312
// alignment checks inserted by the vectorizer. We want to track correlated
13131313
// runtime checks for two inner loops in the same outer loop, fold any
@@ -1328,8 +1328,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
13281328
ExtraPasses.addPass(
13291329
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
13301330
ExtraPasses.addPass(InstCombinePass());
1331-
FPM.addPass(std::move(ExtraPasses));
13321331
}
1332+
FPM.addPass(std::move(ExtraPasses));
13331333

13341334
// Now that we've formed fast to execute loop structures, we do further
13351335
// optimizations. These are run afterward as they might block doing complex

llvm/lib/Passes/PassRegistry.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
303303
FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
304304
FUNCTION_ANALYSIS("should-not-run-function-passes",
305305
ShouldNotRunFunctionPassesAnalysis())
306-
FUNCTION_ANALYSIS("should-run-extra-vector-passes",
307-
ShouldRunExtraVectorPasses())
306+
FUNCTION_ANALYSIS("should-run-extra-passes",
307+
ShouldRunExtraPasses())
308308
FUNCTION_ANALYSIS("ssp-layout", SSPLayoutAnalysis())
309309
FUNCTION_ANALYSIS("stack-safety-local", StackSafetyAnalysis())
310310
FUNCTION_ANALYSIS("target-ir",

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ using SCEV2ValueTy = DenseMap<const SCEV *, Value *>;
442442

443443
namespace llvm {
444444

445-
AnalysisKey ShouldRunExtraVectorPasses::Key;
446-
447445
/// InnerLoopVectorizer vectorizes loops which contain only one basic
448446
/// block to a specified vectorization factor (VF).
449447
/// This class performs the widening of scalars into vectors, or multiple
@@ -10476,8 +10474,8 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
1047610474
// extra simplification passes should be run.
1047710475
// TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
1047810476
// be run if runtime checks have been added.
10479-
AM.getResult<ShouldRunExtraVectorPasses>(F);
10480-
PA.preserve<ShouldRunExtraVectorPasses>();
10477+
AM.getResult<ShouldRunExtraPasses>(F);
10478+
PA.preserve<ShouldRunExtraPasses>();
1048110479
} else {
1048210480
PA.preserveSet<CFGAnalyses>();
1048310481
}

0 commit comments

Comments
 (0)