[llvm] [Pass] Add variadic function templates for `PreservedAnalyses` (PR #130749)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 11 04:21:14 PDT 2025
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/130749
>From 96605c8201fd68cef8ade867d7a4bfab598e80c0 Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Tue, 11 Mar 2025 18:48:45 +0800
Subject: [PATCH] [Pass] Add variadic function templates for
`PreservedAnalyses`
So it is possible to use `PA.preserve<Analysis1, Analysis2>();`
---
llvm/include/llvm/IR/Analysis.h | 39 +++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 12 deletions(-)
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
More information about the llvm-commits
mailing list