aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2017-07-09 07:23:27 +0000
committerChandler Carruth <chandlerc@gmail.com>2017-07-09 07:23:27 +0000
commit79b7faac9615a29fc9baf92e083d2da385e051b8 (patch)
tree41501ce62efe6306968e9179772c41eb0e609d98
parenteb41f6a3452f9ff8985ee6ed9ebdc33f9ca75119 (diff)
[PM] Teach PreservedAnalyses to have an `allInSet` static factory
function template to simplify building a quick object with a set marked as preserved. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307493 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/IR/PassManager.h8
-rw-r--r--unittests/IR/PassManagerTest.cpp7
2 files changed, 15 insertions, 0 deletions
diff --git a/include/llvm/IR/PassManager.h b/include/llvm/IR/PassManager.h
index d03b7b65f81..ab9b1e84401 100644
--- a/include/llvm/IR/PassManager.h
+++ b/include/llvm/IR/PassManager.h
@@ -162,6 +162,14 @@ public:
return PA;
}
+ /// \brief Construct a preserved analyses object with a single preserved set.
+ template <typename AnalysisSetT>
+ static PreservedAnalyses allInSet() {
+ PreservedAnalyses PA;
+ PA.preserveSet<AnalysisSetT>();
+ return PA;
+ }
+
/// Mark an analysis as preserved.
template <typename AnalysisT> void preserve() { preserve(AnalysisT::ID()); }
diff --git a/unittests/IR/PassManagerTest.cpp b/unittests/IR/PassManagerTest.cpp
index ad06cc4778f..0131bce3d2b 100644
--- a/unittests/IR/PassManagerTest.cpp
+++ b/unittests/IR/PassManagerTest.cpp
@@ -210,6 +210,13 @@ TEST(PreservedAnalysesTest, Basic) {
EXPECT_FALSE(PAC.preserved());
EXPECT_FALSE(PAC.preservedSet<AllAnalysesOn<Function>>());
}
+ auto PA5 = PreservedAnalyses::allInSet<AllAnalysesOn<Function>>();
+ {
+ auto PAC = PA5.getChecker<TestFunctionAnalysis>();
+ EXPECT_FALSE(PAC.preserved());
+ EXPECT_TRUE(PAC.preservedSet<AllAnalysesOn<Function>>());
+ EXPECT_FALSE(PAC.preservedSet<AllAnalysesOn<Module>>());
+ }
}
TEST(PreservedAnalysesTest, Preserve) {