Skip to content

Commit 640bcb1

Browse files
nikicAlexisPerry
authored andcommitted
[NewPM] Move PassManager::run() into Impl.h (NFC)
We use explicit template instantiation for these classes, so there is no need to have the definition in the header. The places that instantiate the method will include the PassManagerImpl.h file.
1 parent 12a2694 commit 640bcb1

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

llvm/include/llvm/IR/PassManager.h

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -199,51 +199,7 @@ class PassManager : public PassInfoMixin<
199199
/// Run all of the passes in this manager over the given unit of IR.
200200
/// ExtraArgs are passed to each pass.
201201
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM,
202-
ExtraArgTs... ExtraArgs) {
203-
PreservedAnalyses PA = PreservedAnalyses::all();
204-
205-
// Request PassInstrumentation from analysis manager, will use it to run
206-
// instrumenting callbacks for the passes later.
207-
// Here we use std::tuple wrapper over getResult which helps to extract
208-
// AnalysisManager's arguments out of the whole ExtraArgs set.
209-
PassInstrumentation PI =
210-
detail::getAnalysisResult<PassInstrumentationAnalysis>(
211-
AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));
212-
213-
// RemoveDIs: if requested, convert debug-info to DbgRecord representation
214-
// for duration of these passes.
215-
ScopedDbgInfoFormatSetter FormatSetter(IR, UseNewDbgInfoFormat);
216-
217-
for (auto &Pass : Passes) {
218-
// Check the PassInstrumentation's BeforePass callbacks before running the
219-
// pass, skip its execution completely if asked to (callback returns
220-
// false).
221-
if (!PI.runBeforePass<IRUnitT>(*Pass, IR))
222-
continue;
223-
224-
PreservedAnalyses PassPA = Pass->run(IR, AM, ExtraArgs...);
225-
226-
// Update the analysis manager as each pass runs and potentially
227-
// invalidates analyses.
228-
AM.invalidate(IR, PassPA);
229-
230-
// Call onto PassInstrumentation's AfterPass callbacks immediately after
231-
// running the pass.
232-
PI.runAfterPass<IRUnitT>(*Pass, IR, PassPA);
233-
234-
// Finally, intersect the preserved analyses to compute the aggregate
235-
// preserved set for this pass manager.
236-
PA.intersect(std::move(PassPA));
237-
}
238-
239-
// Invalidation was handled after each pass in the above loop for the
240-
// current unit of IR. Therefore, the remaining analysis results in the
241-
// AnalysisManager are preserved. We mark this with a set so that we don't
242-
// need to inspect each one individually.
243-
PA.preserveSet<AllAnalysesOn<IRUnitT>>();
244-
245-
return PA;
246-
}
202+
ExtraArgTs... ExtraArgs);
247203

248204
// FIXME: Revert to enable_if style when gcc >= 11.1
249205
template <typename PassT> LLVM_ATTRIBUTE_MINSIZE void addPass(PassT &&Pass) {

llvm/include/llvm/IR/PassManagerImpl.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,54 @@
1919

2020
namespace llvm {
2121

22+
template <typename IRUnitT, typename AnalysisManagerT, typename... ExtraArgTs>
23+
PreservedAnalyses PassManager<IRUnitT, AnalysisManagerT, ExtraArgTs...>::run(
24+
IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs) {
25+
PreservedAnalyses PA = PreservedAnalyses::all();
26+
27+
// Request PassInstrumentation from analysis manager, will use it to run
28+
// instrumenting callbacks for the passes later.
29+
// Here we use std::tuple wrapper over getResult which helps to extract
30+
// AnalysisManager's arguments out of the whole ExtraArgs set.
31+
PassInstrumentation PI =
32+
detail::getAnalysisResult<PassInstrumentationAnalysis>(
33+
AM, IR, std::tuple<ExtraArgTs...>(ExtraArgs...));
34+
35+
// RemoveDIs: if requested, convert debug-info to DbgRecord representation
36+
// for duration of these passes.
37+
ScopedDbgInfoFormatSetter FormatSetter(IR, UseNewDbgInfoFormat);
38+
39+
for (auto &Pass : Passes) {
40+
// Check the PassInstrumentation's BeforePass callbacks before running the
41+
// pass, skip its execution completely if asked to (callback returns
42+
// false).
43+
if (!PI.runBeforePass<IRUnitT>(*Pass, IR))
44+
continue;
45+
46+
PreservedAnalyses PassPA = Pass->run(IR, AM, ExtraArgs...);
47+
48+
// Update the analysis manager as each pass runs and potentially
49+
// invalidates analyses.
50+
AM.invalidate(IR, PassPA);
51+
52+
// Call onto PassInstrumentation's AfterPass callbacks immediately after
53+
// running the pass.
54+
PI.runAfterPass<IRUnitT>(*Pass, IR, PassPA);
55+
56+
// Finally, intersect the preserved analyses to compute the aggregate
57+
// preserved set for this pass manager.
58+
PA.intersect(std::move(PassPA));
59+
}
60+
61+
// Invalidation was handled after each pass in the above loop for the
62+
// current unit of IR. Therefore, the remaining analysis results in the
63+
// AnalysisManager are preserved. We mark this with a set so that we don't
64+
// need to inspect each one individually.
65+
PA.preserveSet<AllAnalysesOn<IRUnitT>>();
66+
67+
return PA;
68+
}
69+
2270
template <typename IRUnitT, typename... ExtraArgTs>
2371
inline AnalysisManager<IRUnitT, ExtraArgTs...>::AnalysisManager() = default;
2472

0 commit comments

Comments
 (0)