Skip to content

Commit 96605c8

Browse files
committed
[Pass] Add variadic function templates for PreservedAnalyses
So it is possible to use `PA.preserve<Analysis1, Analysis2>();`
1 parent 148a7ae commit 96605c8

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

llvm/include/llvm/IR/Analysis.h

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,9 @@ class PreservedAnalyses {
127127
return PA;
128128
}
129129

130-
/// Mark an analysis as preserved.
131-
template <typename AnalysisT> PreservedAnalyses &preserve() {
132-
preserve(AnalysisT::ID());
133-
return *this;
130+
/// Mark analyses as preserved.
131+
template <typename... AnalysisTs> PreservedAnalyses &preserve() {
132+
return preserve(AnalysisTs::ID()...);
134133
}
135134

136135
/// Given an analysis's ID, mark the analysis as preserved, adding it
@@ -146,10 +145,15 @@ class PreservedAnalyses {
146145
return *this;
147146
}
148147

149-
/// Mark an analysis set as preserved.
150-
template <typename AnalysisSetT> PreservedAnalyses &preserveSet() {
151-
preserveSet(AnalysisSetT::ID());
152-
return *this;
148+
/// Mark analyses as preserved using IDs.
149+
template <typename... AnalysisKeyPtrs>
150+
PreservedAnalyses &preserve(AnalysisKeyPtrs... IDs) {
151+
return (preserve(IDs), ..., *this);
152+
}
153+
154+
/// Mark analysis sets as preserved.
155+
template <typename... AnalysisSetTs> PreservedAnalyses &preserveSet() {
156+
return preserveSet(AnalysisSetTs::ID()...);
153157
}
154158

155159
/// Mark an analysis set as preserved using its ID.
@@ -160,16 +164,21 @@ class PreservedAnalyses {
160164
return *this;
161165
}
162166

163-
/// Mark an analysis as abandoned.
167+
/// Mark analysis sets as preserved using IDs.
168+
template <typename... AnalysisSetKeyPtrs>
169+
PreservedAnalyses &preserveSet(AnalysisSetKeyPtrs... IDs) {
170+
return (preserveSet(IDs), ..., *this);
171+
}
172+
173+
/// Mark an analyses as abandoned.
164174
///
165175
/// An abandoned analysis is not preserved, even if it is nominally covered
166176
/// by some other set or was previously explicitly marked as preserved.
167177
///
168178
/// Note that you can only abandon a specific analysis, not a *set* of
169179
/// analyses.
170-
template <typename AnalysisT> PreservedAnalyses &abandon() {
171-
abandon(AnalysisT::ID());
172-
return *this;
180+
template <typename... AnalysisTs> PreservedAnalyses &abandon() {
181+
return abandon(AnalysisTs::ID()...);
173182
}
174183

175184
/// Mark an analysis as abandoned using its ID.
@@ -185,6 +194,12 @@ class PreservedAnalyses {
185194
return *this;
186195
}
187196

197+
/// Mark analyses as abandoned using IDs.
198+
template <typename... AnalysisKeyPtrs>
199+
PreservedAnalyses &abandon(AnalysisKeyPtrs... IDs) {
200+
return (abandon(IDs), ..., *this);
201+
}
202+
188203
/// Intersect this set with another in place.
189204
///
190205
/// This is a mutating operation on this preserved set, removing all

0 commit comments

Comments
 (0)