[llvm] [CodeGen] Support start/stop in CodeGenPassBuilder (PR #70912)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 16:52:33 PST 2024
================
@@ -175,73 +183,82 @@ template <typename DerivedT> class CodeGenPassBuilder {
// Function object to maintain state while adding codegen IR passes.
class AddIRPass {
public:
- AddIRPass(ModulePassManager &MPM) : MPM(MPM) {}
+ AddIRPass(ModulePassManager &MPM, const DerivedT &PB) : MPM(MPM), PB(PB) {}
~AddIRPass() {
if (!FPM.isEmpty())
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
- template <typename PassT> void operator()(PassT &&Pass) {
+ template <typename PassT>
+ void operator()(PassT &&Pass, StringRef Name = PassT::name()) {
static_assert((is_detected<is_function_pass_t, PassT>::value ||
is_detected<is_module_pass_t, PassT>::value) &&
"Only module pass and function pass are supported.");
// Add Function Pass
if constexpr (is_detected<is_function_pass_t, PassT>::value) {
+ if (!PB.runBeforeAdding(Name))
+ return;
+
FPM.addPass(std::forward<PassT>(Pass));
+
+ for (auto &C : PB.AfterCallbacks)
+ C(Name);
} else {
// Add Module Pass
+ if (!PB.runBeforeAdding(Name))
+ return;
+
if (!FPM.isEmpty()) {
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
FPM = FunctionPassManager();
}
MPM.addPass(std::forward<PassT>(Pass));
+
+ for (auto &C : PB.AfterCallbacks)
+ C(Name);
}
}
private:
ModulePassManager &MPM;
FunctionPassManager FPM;
+ const DerivedT &PB;
};
// Function object to maintain state while adding codegen machine passes.
class AddMachinePass {
public:
- AddMachinePass(MachineFunctionPassManager &PM) : PM(PM) {}
+ AddMachinePass(MachineFunctionPassManager &PM, const DerivedT &PB)
+ : PM(PM), PB(PB) {}
template <typename PassT> void operator()(PassT &&Pass) {
static_assert(
is_detected<has_key_t, PassT>::value,
"Machine function pass must define a static member variable `Key`.");
- for (auto &C : BeforeCallbacks)
- if (!C(&PassT::Key))
- return;
+
+ if (!PB.runBeforeAdding(PassT::name()))
+ return;
+
PM.addPass(std::forward<PassT>(Pass));
- for (auto &C : AfterCallbacks)
- C(&PassT::Key);
+
+ for (auto &C : PB.AfterCallbacks)
+ C(PassT::name());
}
template <typename PassT> void insertPass(MachinePassKey *ID, PassT Pass) {
----------------
paperchalice wrote:
Currently AMDGPU, Hexagon, PowerPC and RISCV uses `insertPass` to adjust the regalloc pipeline, we need add extension points after `PHIElimination`, `TwoAddressInstruction`, `MachineScheduler`, `RenameIndependentSubregs`, `LiveVariables` and `DetectDeadLanes`.
https://github.com/llvm/llvm-project/pull/70912
More information about the llvm-commits
mailing list