LLVM 20.0.0git
ExtraPassManager.h
Go to the documentation of this file.
1//===- ExtraFunctionPassManager.h - Run Optimizations on Demand -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file provides a pass manager that only runs its passes if the
11/// provided marker analysis has been preserved, together with a class to
12/// define such a marker analysis.
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
16#define LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
17
18#include "llvm/IR/PassManager.h"
20
21namespace 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.
26template <typename MarkerTy> struct ShouldRunExtraPasses {
27 struct Result {
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 bool invalidate(Loop &L, const PreservedAnalyses &PA,
38 // Check whether the analysis has been explicitly invalidated. Otherwise,
39 // it remains preserved.
40 auto PAC = PA.getChecker<MarkerTy>();
41 return !PAC.preservedWhenStateless();
42 }
43 };
44
46
49 return Result();
50 }
51};
52
53/// A pass manager to run a set of extra function passes if the
54/// ShouldRunExtraPasses marker analysis is present. This allows passes to
55/// request additional transformations on demand. An example is extra
56/// simplifications after loop-vectorization, if runtime checks have been added.
57template <typename MarkerTy>
59 : public PassInfoMixin<ExtraFunctionPassManager<MarkerTy>> {
60 FunctionPassManager InnerFPM;
61
62public:
63 template <typename PassT> void addPass(PassT &&Pass) {
64 InnerFPM.addPass(std::move(Pass));
65 }
66
68 auto PA = PreservedAnalyses::all();
69 if (AM.getCachedResult<MarkerTy>(F))
70 PA.intersect(InnerFPM.run(F, AM));
71 PA.abandon<MarkerTy>();
72 return PA;
73 }
74
75 static bool isRequired() { return true; }
76};
77
78/// A pass manager to run a set of extra loop passes if the MarkerTy analysis is
79/// present. This allows passes to request additional transformations on demand.
80/// An example is doing additional runs of SimpleLoopUnswitch.
81template <typename MarkerTy>
83 : public PassInfoMixin<ExtraLoopPassManager<MarkerTy>> {
84 LoopPassManager InnerLPM;
85
86public:
87 template <typename PassT> void addPass(PassT &&Pass) {
88 InnerLPM.addPass(std::move(Pass));
89 }
90
93 auto PA = PreservedAnalyses::all();
94 if (AM.getCachedResult<MarkerTy>(L))
95 PA.intersect(InnerLPM.run(L, AM, AR, U));
96 PA.abandon<MarkerTy>();
97 return PA;
98 }
99
100 static bool isRequired() { return true; }
101};
102
103} // namespace llvm
104
105#endif // LLVM_TRANSFORMS_UTILS_EXTRAPASSMANAGER_H
This header defines various interfaces for pass management in LLVM.
This header provides classes for managing a pipeline of passes over loops in LLVM IR.
#define F(x, y, z)
Definition: MD5.cpp:55
FunctionAnalysisManager FAM
API to communicate dependencies between analyses during invalidation.
Definition: PassManager.h:292
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
Definition: PassManager.h:429
A pass manager to run a set of extra function passes if the ShouldRunExtraPasses marker analysis is p...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
A pass manager to run a set of extra loop passes if the MarkerTy analysis is present.
void addPass(PassT &&Pass)
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:39
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t< is_detected< HasRunOnLoopT, PassT >::value > addPass(PassT &&Pass)
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Add either a loop pass or a loop-nest pass to the pass manager.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
Definition: PassManager.h:195
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:94
bool preservedWhenStateless()
Return true if the checker's analysis was not abandoned, i.e.
Definition: Analysis.h:247
A set of analyses that are preserved following a run of a transformation pass.
Definition: Analysis.h:111
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: Analysis.h:117
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition: Analysis.h:264
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:69
bool invalidate(Loop &L, const PreservedAnalyses &PA, LoopAnalysisManager::Invalidator &)
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &)
A marker analysis to determine if extra passes should be run on demand.
Result run(Function &F, FunctionAnalysisManager &FAM)
Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR)