[llvm] [CodeGen] Allow `CodeGenPassBuilder` to add module pass after function pass (PR #77084)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 06:05:32 PST 2024
================
@@ -175,45 +175,33 @@ template <typename DerivedT> class CodeGenPassBuilder {
// Function object to maintain state while adding codegen IR passes.
class AddIRPass {
public:
- AddIRPass(ModulePassManager &MPM, bool DebugPM, bool Check = true)
- : MPM(MPM) {
- if (Check)
- AddingFunctionPasses = false;
- }
+ AddIRPass(ModulePassManager &MPM) : MPM(MPM) {}
~AddIRPass() {
- MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
- }
-
- // Add Function Pass
- template <typename PassT>
- std::enable_if_t<is_detected<is_function_pass_t, PassT>::value>
- operator()(PassT &&Pass) {
- if (AddingFunctionPasses && !*AddingFunctionPasses)
- AddingFunctionPasses = true;
- FPM.addPass(std::forward<PassT>(Pass));
+ if (!FPM.isEmpty())
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
}
- // Add Module Pass
- template <typename PassT>
- std::enable_if_t<is_detected<is_module_pass_t, PassT>::value &&
- !is_detected<is_function_pass_t, PassT>::value>
- operator()(PassT &&Pass) {
- assert((!AddingFunctionPasses || !*AddingFunctionPasses) &&
- "could not add module pass after adding function pass");
- MPM.addPass(std::forward<PassT>(Pass));
+ template <typename PassT> void operator()(PassT &&Pass) {
+ // Add Function Pass
+ if constexpr (is_detected<is_function_pass_t, PassT>::value) {
+ FPM.addPass(std::forward<PassT>(Pass));
+ return;
+ }
+
+ // Add Module Pass
+ if constexpr (is_detected<is_module_pass_t, PassT>::value &&
+ !is_detected<is_function_pass_t, PassT>::value) {
----------------
arsenm wrote:
Why are both conditions necessary? Can there really be a pass that is both a module and function pass?
https://github.com/llvm/llvm-project/pull/77084
More information about the llvm-commits
mailing list