[llvm] [Pass] Add `RequiredPassMixin` for non skippable passes (PR #115692)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 10 23:30:33 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: None (paperchalice)
<details>
<summary>Changes</summary>
Follow the idea in #<!-- -->115471, add a new kind of mix-in. This PR demonstrates how it works:
```c++
// A required pass
struct SomePass : PassInfoMixin<SomePass>, RequiredPassMixin {
PreservedAnalysis run(...);
};
```
Rather than provide `isRequired` for each pass, it seems that checking the sub-class relationship is enough.
---
Full diff: https://github.com/llvm/llvm-project/pull/115692.diff
2 Files Affected:
- (modified) llvm/include/llvm/IR/PassManager.h (+11)
- (modified) llvm/include/llvm/IR/PassManagerInternal.h (+5-1)
``````````diff
diff --git a/llvm/include/llvm/IR/PassManager.h b/llvm/include/llvm/IR/PassManager.h
index d269221fac0701..dd4bbb7da165ce 100644
--- a/llvm/include/llvm/IR/PassManager.h
+++ b/llvm/include/llvm/IR/PassManager.h
@@ -112,6 +112,17 @@ struct AnalysisInfoMixin : PassInfoMixin<DerivedT> {
}
};
+/// A mix-in indicates that the pass cannot be skipped
+/// in pass instrumentation.
+struct RequiredPassMixin {};
+
+/// A convenient mix-in to indicate the pass cannot be skipped
+/// in pass instrumentation.
+///
+/// It automatically mixes in \c PassInfoMixin and \c RequiredPassMixin.
+template <typename DerivedT>
+struct RequiredPassInfoMixin : PassInfoMixin<DerivedT>, RequiredPassMixin {};
+
namespace detail {
/// Actual unpacker of extra arguments in getAnalysisResult,
diff --git a/llvm/include/llvm/IR/PassManagerInternal.h b/llvm/include/llvm/IR/PassManagerInternal.h
index 4ada6ee5dd6831..3fdc584c091afe 100644
--- a/llvm/include/llvm/IR/PassManagerInternal.h
+++ b/llvm/include/llvm/IR/PassManagerInternal.h
@@ -29,6 +29,7 @@ namespace llvm {
template <typename IRUnitT> class AllAnalysesOn;
template <typename IRUnitT, typename... ExtraArgTs> class AnalysisManager;
class PreservedAnalyses;
+struct RequiredPassMixin;
// Implementation details of the pass manager interfaces.
namespace detail {
@@ -112,7 +113,10 @@ struct PassModel : PassConcept<IRUnitT, AnalysisManagerT, ExtraArgTs...> {
return false;
}
- bool isRequired() const override { return passIsRequiredImpl<PassT>(); }
+ bool isRequired() const override {
+ return passIsRequiredImpl<PassT>() ||
+ std::is_base_of_v<RequiredPassMixin, PassT>;
+ }
PassT Pass;
};
``````````
</details>
https://github.com/llvm/llvm-project/pull/115692
More information about the llvm-commits
mailing list