Skip to content

Commit 171bcd0

Browse files
committed
!fixup move to separate header
1 parent 62d3210 commit 171bcd0

File tree

8 files changed

+75
-39
lines changed

8 files changed

+75
-39
lines changed

llvm/include/llvm/IR/PassManager.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -935,38 +935,6 @@ 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-
970938
} // end namespace llvm
971939

972940
#endif // LLVM_IR_PASSMANAGER_H
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//===- ExtraPassManager.h - Loop pass management -----------------*- C++
2+
//-*-===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
/// \file
10+
///
11+
/// This file provides a pass manager that only runs its passes if the
12+
/// provided marker analysis has been preserved, together with a class to
13+
/// define such a marker analysis.
14+
//===----------------------------------------------------------------------===//
15+
16+
#ifndef LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
17+
#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
18+
19+
#include "llvm/IR/PassManager.h"
20+
21+
namespace llvm {
22+
23+
/// A marker analysis to determine if extra passes should be run on demand.
24+
/// Passes requesting extra transformations to run need to request and preserve
25+
/// this analysis.
26+
template <typename MarkerTy> struct ShouldRunExtraPasses {
27+
struct Result {
28+
bool invalidate(Function &F, const PreservedAnalyses &PA,
29+
FunctionAnalysisManager::Invalidator &) {
30+
// Check whether the analysis has been explicitly invalidated. Otherwise,
31+
// it remains preserved.
32+
auto PAC = PA.getChecker<MarkerTy>();
33+
return !PAC.preservedWhenStateless();
34+
}
35+
};
36+
37+
Result run(Function &F, FunctionAnalysisManager &FAM) { return Result(); }
38+
};
39+
40+
/// A pass manager to run a set of extra function passes if the
41+
/// ShouldRunExtraPasses marker analysis is present. This allows passes to
42+
/// request additional transformations on demand. An example is extra
43+
/// simplifications after loop-vectorization, if runtime checks have been added.
44+
template <typename MarkerTy>
45+
struct ExtraPassManager : public FunctionPassManager {
46+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM) {
47+
auto PA = PreservedAnalyses::all();
48+
if (AM.getCachedResult<MarkerTy>(F))
49+
PA.intersect(FunctionPassManager::run(F, AM));
50+
PA.abandon<MarkerTy>();
51+
return PA;
52+
}
53+
};
54+
} // namespace llvm
55+
56+
#endif // LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
#include "llvm/IR/PassManager.h"
6060
#include "llvm/Support/CommandLine.h"
61+
#include "llvm/Transforms/Utils/ExtraPassManager.h"
6162
#include <functional>
6263

6364
namespace llvm {
@@ -169,6 +170,13 @@ void reportVectorizationFailure(const StringRef DebugMsg,
169170
const StringRef OREMsg, const StringRef ORETag,
170171
OptimizationRemarkEmitter *ORE, Loop *TheLoop, Instruction *I = nullptr);
171172

173+
/// A marker analyss to determine if extra passes should be run after loop
174+
/// vectorization.
175+
struct ShouldRunExtraVectorPasses
176+
: public ShouldRunExtraPasses<ShouldRunExtraVectorPasses>,
177+
public AnalysisInfoMixin<ShouldRunExtraVectorPasses> {
178+
static AnalysisKey Key;
179+
};
172180
} // end namespace llvm
173181

174182
#endif // LLVM_TRANSFORMS_VECTORIZE_LOOPVECTORIZE_H

llvm/lib/IR/PassManager.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,3 @@ AnalysisSetKey CFGAnalyses::SetKey;
161161

162162
AnalysisSetKey PreservedAnalyses::AllAnalysesKey;
163163

164-
AnalysisKey ShouldRunExtraPasses::Key;

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@
311311
#include "llvm/Transforms/Utils/DXILUpgrade.h"
312312
#include "llvm/Transforms/Utils/Debugify.h"
313313
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
314+
#include "llvm/Transforms/Utils/ExtraPassManager.h"
314315
#include "llvm/Transforms/Utils/FixIrreducible.h"
315316
#include "llvm/Transforms/Utils/HelloWorld.h"
316317
#include "llvm/Transforms/Utils/IRNormalizer.h"

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
135135
#include "llvm/Transforms/Utils/CountVisits.h"
136136
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
137+
#include "llvm/Transforms/Utils/ExtraPassManager.h"
137138
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
138139
#include "llvm/Transforms/Utils/LibCallsShrinkWrap.h"
139140
#include "llvm/Transforms/Utils/Mem2Reg.h"
@@ -1306,8 +1307,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
13061307
// Cleanup after the loop optimization passes.
13071308
FPM.addPass(InstCombinePass());
13081309

1309-
ExtraPassManager ExtraPasses;
13101310
if (Level.getSpeedupLevel() > 1 && ExtraVectorizerPasses) {
1311+
ExtraPassManager<ShouldRunExtraVectorPasses> ExtraPasses;
13111312
// At higher optimization levels, try to clean up any runtime overlap and
13121313
// alignment checks inserted by the vectorizer. We want to track correlated
13131314
// runtime checks for two inner loops in the same outer loop, fold any
@@ -1328,8 +1329,8 @@ void PassBuilder::addVectorPasses(OptimizationLevel Level,
13281329
ExtraPasses.addPass(
13291330
SimplifyCFGPass(SimplifyCFGOptions().convertSwitchRangeToICmp(true)));
13301331
ExtraPasses.addPass(InstCombinePass());
1332+
FPM.addPass(std::move(ExtraPasses));
13311333
}
1332-
FPM.addPass(std::move(ExtraPasses));
13331334

13341335
// Now that we've formed fast to execute loop structures, we do further
13351336
// 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-passes",
307-
ShouldRunExtraPasses())
306+
FUNCTION_ANALYSIS("should-run-extra-vector-passes",
307+
ShouldRunExtraVectorPasses())
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
#include "llvm/Support/NativeFormatting.h"
135135
#include "llvm/Support/raw_ostream.h"
136136
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
137+
#include "llvm/Transforms/Utils/ExtraPassManager.h"
137138
#include "llvm/Transforms/Utils/InjectTLIMappings.h"
138139
#include "llvm/Transforms/Utils/Local.h"
139140
#include "llvm/Transforms/Utils/LoopSimplify.h"
@@ -442,6 +443,8 @@ using SCEV2ValueTy = DenseMap<const SCEV *, Value *>;
442443

443444
namespace llvm {
444445

446+
AnalysisKey ShouldRunExtraVectorPasses::Key;
447+
445448
/// InnerLoopVectorizer vectorizes loops which contain only one basic
446449
/// block to a specified vectorization factor (VF).
447450
/// This class performs the widening of scalars into vectors, or multiple
@@ -10475,8 +10478,8 @@ PreservedAnalyses LoopVectorizePass::run(Function &F,
1047510478
// extra simplification passes should be run.
1047610479
// TODO: MadeCFGChanges is not a prefect proxy. Extra passes should only
1047710480
// be run if runtime checks have been added.
10478-
AM.getResult<ShouldRunExtraPasses>(F);
10479-
PA.preserve<ShouldRunExtraPasses>();
10481+
AM.getResult<ShouldRunExtraVectorPasses>(F);
10482+
PA.preserve<ShouldRunExtraVectorPasses>();
1048010483
} else {
1048110484
PA.preserveSet<CFGAnalyses>();
1048210485
}

0 commit comments

Comments
 (0)