[llvm] [CodeGen][NPM] Do not add required passes to pipeline (PR #135752)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 21 22:43:41 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Akshat Oke (optimisan)
<details>
<summary>Changes</summary>
Extra required passes were being added to debug pipelines (created with `-stop-after`) which should not be added to the pipeline.
The test `llc -stop-after=greedy -enable-new-pm` would still add `greedy` to the pipeline otherwise.
---
Full diff: https://github.com/llvm/llvm-project/pull/135752.diff
3 Files Affected:
- (modified) llvm/include/llvm/Passes/CodeGenPassBuilder.h (+9-11)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-1)
- (modified) llvm/test/tools/llc/new-pm/pipeline.mir (+2)
``````````diff
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index d092049022623..e0445dc75a8bf 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -183,9 +183,6 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
}
protected:
- template <typename PassT>
- using has_required_t = decltype(std::declval<PassT &>().isRequired());
-
template <typename PassT>
using is_module_pass_t = decltype(std::declval<PassT &>().run(
std::declval<Module &>(), std::declval<ModuleAnalysisManager &>()));
@@ -212,14 +209,12 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
}
template <typename PassT>
- void operator()(PassT &&Pass, StringRef Name = PassT::name()) {
+ void operator()(PassT &&Pass, bool Force = false,
+ 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.");
- bool Required = false;
- if constexpr (is_detected<has_required_t, PassT>::value)
- Required = PassT::isRequired();
- if (!PB.runBeforeAdding(Name) && !Required)
+ if (!Force && !PB.runBeforeAdding(Name))
return;
// Add Function Pass
@@ -567,9 +562,12 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
{
AddIRPass addIRPass(MPM, derived());
- addIRPass(RequireAnalysisPass<MachineModuleAnalysis, Module>());
- addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>());
- addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>());
+ addIRPass(RequireAnalysisPass<MachineModuleAnalysis, Module>(),
+ /*Force=*/true);
+ addIRPass(RequireAnalysisPass<ProfileSummaryAnalysis, Module>(),
+ /*Force=*/true);
+ addIRPass(RequireAnalysisPass<CollectorMetadataAnalysis, Module>(),
+ /*Force=*/true);
addISelPasses(addIRPass);
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 90e3489ced923..029f81a890ae5 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -2115,7 +2115,8 @@ void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const {
// FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
// isn't this in addInstSelector?
- addPass(RequireAnalysisPass<UniformityInfoAnalysis, Function>());
+ addPass(RequireAnalysisPass<UniformityInfoAnalysis, Function>(),
+ /*Force=*/true);
}
void AMDGPUCodeGenPassBuilder::addILPOpts(AddMachinePass &addPass) const {
diff --git a/llvm/test/tools/llc/new-pm/pipeline.mir b/llvm/test/tools/llc/new-pm/pipeline.mir
index 761a3a424ee67..8f8e443923b7b 100644
--- a/llvm/test/tools/llc/new-pm/pipeline.mir
+++ b/llvm/test/tools/llc/new-pm/pipeline.mir
@@ -1,8 +1,10 @@
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes=no-op-machine-function --print-pipeline-passes -filetype=null < %s | FileCheck %s --match-full-lines
# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -passes='require<machine-dom-tree>,print<machine-dom-tree>' -print-pipeline-passes < %s | FileCheck --check-prefix=ANALYSIS %s
+# RUN: llc -mtriple=x86_64-pc-linux-gnu -x mir -enable-new-pm -stop-before=greedy -O3 -filetype=null --print-pipeline-passes < %s | FileCheck %s --check-prefix=CHECK-REQ
# CHECK: function(machine-function(no-op-machine-function)),PrintMIRPreparePass,function(machine-function(verify,print))
+# CHECK-REQ-NOT: greedy
# ANALYSIS: require<machine-dom-tree>,print<machine-dom-tree>
---
``````````
</details>
https://github.com/llvm/llvm-project/pull/135752
More information about the llvm-commits
mailing list