[llvm] [Pass] Convert methods in `PreservedAnalyses` to variadic template (PR #130749)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 11 05:15:26 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-ir

Author: None (paperchalice)

<details>
<summary>Changes</summary>

So it is possible to use `PA.preserve<Analysis1, Analysis2>();`

---
Full diff: https://github.com/llvm/llvm-project/pull/130749.diff


1 Files Affected:

- (modified) llvm/include/llvm/IR/Analysis.h (+27-12) 


``````````diff
diff --git a/llvm/include/llvm/IR/Analysis.h b/llvm/include/llvm/IR/Analysis.h
index dd43f5ee5f706..979a246542001 100644
--- a/llvm/include/llvm/IR/Analysis.h
+++ b/llvm/include/llvm/IR/Analysis.h
@@ -127,10 +127,9 @@ class PreservedAnalyses {
     return PA;
   }
 
-  /// Mark an analysis as preserved.
-  template <typename AnalysisT> PreservedAnalyses &preserve() {
-    preserve(AnalysisT::ID());
-    return *this;
+  /// Mark analyses as preserved.
+  template <typename... AnalysisTs> PreservedAnalyses &preserve() {
+    return preserve(AnalysisTs::ID()...);
   }
 
   /// Given an analysis's ID, mark the analysis as preserved, adding it
@@ -146,10 +145,15 @@ class PreservedAnalyses {
     return *this;
   }
 
-  /// Mark an analysis set as preserved.
-  template <typename AnalysisSetT> PreservedAnalyses &preserveSet() {
-    preserveSet(AnalysisSetT::ID());
-    return *this;
+  /// Mark analyses as preserved using IDs.
+  template <typename... AnalysisKeyPtrs>
+  PreservedAnalyses &preserve(AnalysisKeyPtrs... IDs) {
+    return (preserve(IDs), ..., *this);
+  }
+
+  /// Mark analysis sets as preserved.
+  template <typename... AnalysisSetTs> PreservedAnalyses &preserveSet() {
+    return preserveSet(AnalysisSetTs::ID()...);
   }
 
   /// Mark an analysis set as preserved using its ID.
@@ -160,16 +164,21 @@ class PreservedAnalyses {
     return *this;
   }
 
-  /// Mark an analysis as abandoned.
+  /// Mark analysis sets as preserved using IDs.
+  template <typename... AnalysisSetKeyPtrs>
+  PreservedAnalyses &preserveSet(AnalysisSetKeyPtrs... IDs) {
+    return (preserveSet(IDs), ..., *this);
+  }
+
+  /// Mark an analyses as abandoned.
   ///
   /// An abandoned analysis is not preserved, even if it is nominally covered
   /// by some other set or was previously explicitly marked as preserved.
   ///
   /// Note that you can only abandon a specific analysis, not a *set* of
   /// analyses.
-  template <typename AnalysisT> PreservedAnalyses &abandon() {
-    abandon(AnalysisT::ID());
-    return *this;
+  template <typename... AnalysisTs> PreservedAnalyses &abandon() {
+    return abandon(AnalysisTs::ID()...);
   }
 
   /// Mark an analysis as abandoned using its ID.
@@ -185,6 +194,12 @@ class PreservedAnalyses {
     return *this;
   }
 
+  /// Mark analyses as abandoned using IDs.
+  template <typename... AnalysisKeyPtrs>
+  PreservedAnalyses &abandon(AnalysisKeyPtrs... IDs) {
+    return (abandon(IDs), ..., *this);
+  }
+
   /// Intersect this set with another in place.
   ///
   /// This is a mutating operation on this preserved set, removing all

``````````

</details>


https://github.com/llvm/llvm-project/pull/130749


More information about the llvm-commits mailing list