[llvm] [Pass] Add variadic function templates for `PreservedAnalyses` (PR #130749)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 11 03:49:58 PDT 2025
https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/130749
So it is possible to use `PA.preserve<Analysis1, Analysis2>();`
>From 3e516b7a49ac7597bb545f7801960e9a9b72d678 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 | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/llvm/include/llvm/IR/Analysis.h b/llvm/include/llvm/IR/Analysis.h
index dd43f5ee5f706..d6aa32d36ffa7 100644
--- a/llvm/include/llvm/IR/Analysis.h
+++ b/llvm/include/llvm/IR/Analysis.h
@@ -133,6 +133,11 @@ class PreservedAnalyses {
return *this;
}
+ /// Mark multiple analyses as preserved.
+ template <typename... AnalysisTs> PreservedAnalyses &preserve() {
+ return preserve(AnalysisTs::ID()...);
+ }
+
/// Given an analysis's ID, mark the analysis as preserved, adding it
/// to the set.
PreservedAnalyses &preserve(AnalysisKey *ID) {
@@ -146,12 +151,23 @@ class PreservedAnalyses {
return *this;
}
+ /// Mark analyses as preserved using IDs.
+ template <typename... AnalysisKeyPtrs>
+ PreservedAnalyses &preserve(AnalysisKeyPtrs... IDs) {
+ return preserve(IDs), ..., *this;
+ }
+
/// Mark an analysis set as preserved.
template <typename AnalysisSetT> PreservedAnalyses &preserveSet() {
preserveSet(AnalysisSetT::ID());
return *this;
}
+ /// Mark analysis sets as preserved.
+ template <typename AnalysisSetTs> PreservedAnalyses &preserveSet() {
+ return preserveSet(AnalysisSetT::ID()...);
+ }
+
/// Mark an analysis set as preserved using its ID.
PreservedAnalyses &preserveSet(AnalysisSetKey *ID) {
// If we're not already in the saturated 'all' state, add this set.
@@ -160,6 +176,12 @@ class PreservedAnalyses {
return *this;
}
+ /// Mark analysis sets as preserved using IDs.
+ template <typename... AnalysisSetKeyPtrs>
+ PreservedAnalyses &preserveSet(AnalysisSetKeyPtrs... IDs) {
+ return preserveSet(IDs), ..., *this;
+ }
+
/// Mark an analysis as abandoned.
///
/// An abandoned analysis is not preserved, even if it is nominally covered
@@ -172,6 +194,11 @@ class PreservedAnalyses {
return *this;
}
+ /// Mark analyses as abandoned.
+ template <typename... AnalysisTs> PreservedAnalyses &abandon() {
+ return abandon(AnalysisTs::ID()...);
+ }
+
/// Mark an analysis as abandoned using its ID.
///
/// An abandoned analysis is not preserved, even if it is nominally covered
@@ -185,6 +212,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