Skip to content

[Pass] Convert methods in PreservedAnalyses to variadic template #130749

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

Closed
wants to merge 1 commit into from

Conversation

paperchalice
Copy link
Contributor

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

So it is possible to use `PA.preserve<Analysis1, Analysis2>();`
@paperchalice paperchalice changed the title [Pass] Add variadic function templates for PreservedAnalyses [Pass] Convert methods in PreservedAnalyses to variadic template Mar 11, 2025
@paperchalice paperchalice marked this pull request as ready for review March 11, 2025 12:14
@paperchalice paperchalice requested review from optimisan and aeubanks and removed request for optimisan March 11, 2025 12:14
@llvmbot
Copy link
Member

llvmbot commented Mar 11, 2025

@llvm/pr-subscribers-llvm-ir

Author: None (paperchalice)

Changes

So it is possible to use PA.preserve&lt;Analysis1, Analysis2&gt;();


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

1 Files Affected:

  • (modified) llvm/include/llvm/IR/Analysis.h (+27-12)
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

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see a reason for this over #129505, I think that API is enough. I'm not a fan of making APIs more templatey if it doesn't make it significantly easier to use/understand the API

@paperchalice paperchalice deleted the var-ids branch March 12, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants