-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NPM][NFC] Chain PreservedAnalyses methods #129505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
optimisan
merged 1 commit into
main
from
users/optimisan/03-03-_npm_chain_preservedanalyses_methods
Mar 4, 2025
Merged
[NPM][NFC] Chain PreservedAnalyses methods #129505
optimisan
merged 1 commit into
main
from
users/optimisan/03-03-_npm_chain_preservedanalyses_methods
Mar 4, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-llvm-ir Author: Akshat Oke (optimisan) ChangesFull diff: https://github.com/llvm/llvm-project/pull/129505.diff 2 Files Affected:
diff --git a/llvm/include/llvm/IR/Analysis.h b/llvm/include/llvm/IR/Analysis.h
index 6c80c771d40b4..dd43f5ee5f706 100644
--- a/llvm/include/llvm/IR/Analysis.h
+++ b/llvm/include/llvm/IR/Analysis.h
@@ -128,11 +128,14 @@ class PreservedAnalyses {
}
/// Mark an analysis as preserved.
- template <typename AnalysisT> void preserve() { preserve(AnalysisT::ID()); }
+ template <typename AnalysisT> PreservedAnalyses &preserve() {
+ preserve(AnalysisT::ID());
+ return *this;
+ }
/// Given an analysis's ID, mark the analysis as preserved, adding it
/// to the set.
- void preserve(AnalysisKey *ID) {
+ PreservedAnalyses &preserve(AnalysisKey *ID) {
// Clear this ID from the explicit not-preserved set if present.
NotPreservedAnalysisIDs.erase(ID);
@@ -140,18 +143,21 @@ class PreservedAnalyses {
// NotPreservedAnalysisIDs).
if (!areAllPreserved())
PreservedIDs.insert(ID);
+ return *this;
}
/// Mark an analysis set as preserved.
- template <typename AnalysisSetT> void preserveSet() {
+ template <typename AnalysisSetT> PreservedAnalyses &preserveSet() {
preserveSet(AnalysisSetT::ID());
+ return *this;
}
/// Mark an analysis set as preserved using its ID.
- void preserveSet(AnalysisSetKey *ID) {
+ PreservedAnalyses &preserveSet(AnalysisSetKey *ID) {
// If we're not already in the saturated 'all' state, add this set.
if (!areAllPreserved())
PreservedIDs.insert(ID);
+ return *this;
}
/// Mark an analysis as abandoned.
@@ -161,7 +167,10 @@ class PreservedAnalyses {
///
/// Note that you can only abandon a specific analysis, not a *set* of
/// analyses.
- template <typename AnalysisT> void abandon() { abandon(AnalysisT::ID()); }
+ template <typename AnalysisT> PreservedAnalyses &abandon() {
+ abandon(AnalysisT::ID());
+ return *this;
+ }
/// Mark an analysis as abandoned using its ID.
///
@@ -170,9 +179,10 @@ class PreservedAnalyses {
///
/// Note that you can only abandon a specific analysis, not a *set* of
/// analyses.
- void abandon(AnalysisKey *ID) {
+ PreservedAnalyses &abandon(AnalysisKey *ID) {
PreservedIDs.erase(ID);
NotPreservedAnalysisIDs.insert(ID);
+ return *this;
}
/// Intersect this set with another in place.
diff --git a/llvm/lib/CodeGen/MachineScheduler.cpp b/llvm/lib/CodeGen/MachineScheduler.cpp
index d67e4ef572469..333311f2c2ebd 100644
--- a/llvm/lib/CodeGen/MachineScheduler.cpp
+++ b/llvm/lib/CodeGen/MachineScheduler.cpp
@@ -602,11 +602,10 @@ MachineSchedulerPass::run(MachineFunction &MF,
if (!Changed)
return PreservedAnalyses::all();
- PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses();
- PA.preserveSet<CFGAnalyses>();
- PA.preserve<SlotIndexesAnalysis>();
- PA.preserve<LiveIntervalsAnalysis>();
- return PA;
+ return getMachineFunctionPassPreservedAnalyses()
+ .preserveSet<CFGAnalyses>()
+ .preserve<SlotIndexesAnalysis>()
+ .preserve<LiveIntervalsAnalysis>();
}
bool PostMachineSchedulerLegacy::runOnMachineFunction(MachineFunction &MF) {
|
aeubanks
approved these changes
Mar 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this, I do think it makes it nicer to work with PreservedAnalyses
jph-13
pushed a commit
to jph-13/llvm-project
that referenced
this pull request
Mar 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I think cascading these methods makes sense, but is this just unneeded fluff?