Skip to content

Commit 3aab3fe

Browse files
authored
[NPM][NFC] Chain PreservedAnalyses methods (#129505)
1 parent 50ff49e commit 3aab3fe

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

llvm/include/llvm/IR/Analysis.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,36 @@ class PreservedAnalyses {
128128
}
129129

130130
/// Mark an analysis as preserved.
131-
template <typename AnalysisT> void preserve() { preserve(AnalysisT::ID()); }
131+
template <typename AnalysisT> PreservedAnalyses &preserve() {
132+
preserve(AnalysisT::ID());
133+
return *this;
134+
}
132135

133136
/// Given an analysis's ID, mark the analysis as preserved, adding it
134137
/// to the set.
135-
void preserve(AnalysisKey *ID) {
138+
PreservedAnalyses &preserve(AnalysisKey *ID) {
136139
// Clear this ID from the explicit not-preserved set if present.
137140
NotPreservedAnalysisIDs.erase(ID);
138141

139142
// If we're not already preserving all analyses (other than those in
140143
// NotPreservedAnalysisIDs).
141144
if (!areAllPreserved())
142145
PreservedIDs.insert(ID);
146+
return *this;
143147
}
144148

145149
/// Mark an analysis set as preserved.
146-
template <typename AnalysisSetT> void preserveSet() {
150+
template <typename AnalysisSetT> PreservedAnalyses &preserveSet() {
147151
preserveSet(AnalysisSetT::ID());
152+
return *this;
148153
}
149154

150155
/// Mark an analysis set as preserved using its ID.
151-
void preserveSet(AnalysisSetKey *ID) {
156+
PreservedAnalyses &preserveSet(AnalysisSetKey *ID) {
152157
// If we're not already in the saturated 'all' state, add this set.
153158
if (!areAllPreserved())
154159
PreservedIDs.insert(ID);
160+
return *this;
155161
}
156162

157163
/// Mark an analysis as abandoned.
@@ -161,7 +167,10 @@ class PreservedAnalyses {
161167
///
162168
/// Note that you can only abandon a specific analysis, not a *set* of
163169
/// analyses.
164-
template <typename AnalysisT> void abandon() { abandon(AnalysisT::ID()); }
170+
template <typename AnalysisT> PreservedAnalyses &abandon() {
171+
abandon(AnalysisT::ID());
172+
return *this;
173+
}
165174

166175
/// Mark an analysis as abandoned using its ID.
167176
///
@@ -170,9 +179,10 @@ class PreservedAnalyses {
170179
///
171180
/// Note that you can only abandon a specific analysis, not a *set* of
172181
/// analyses.
173-
void abandon(AnalysisKey *ID) {
182+
PreservedAnalyses &abandon(AnalysisKey *ID) {
174183
PreservedIDs.erase(ID);
175184
NotPreservedAnalysisIDs.insert(ID);
185+
return *this;
176186
}
177187

178188
/// Intersect this set with another in place.

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,10 @@ MachineSchedulerPass::run(MachineFunction &MF,
602602
if (!Changed)
603603
return PreservedAnalyses::all();
604604

605-
PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses();
606-
PA.preserveSet<CFGAnalyses>();
607-
PA.preserve<SlotIndexesAnalysis>();
608-
PA.preserve<LiveIntervalsAnalysis>();
609-
return PA;
605+
return getMachineFunctionPassPreservedAnalyses()
606+
.preserveSet<CFGAnalyses>()
607+
.preserve<SlotIndexesAnalysis>()
608+
.preserve<LiveIntervalsAnalysis>();
610609
}
611610

612611
bool PostMachineSchedulerLegacy::runOnMachineFunction(MachineFunction &MF) {

0 commit comments

Comments
 (0)