Skip to content

[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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions llvm/include/llvm/IR/Analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,36 @@ 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);

// If we're not already preserving all analyses (other than those in
// 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.
Expand All @@ -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.
///
Expand All @@ -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.
Expand Down
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/MachineScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down