summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-11-09 13:09:08 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-11-09 13:09:08 +0000
commit90a835d2a0c8eb65f06cd08eb39795377a7a23a3 (patch)
tree6927cc40070c504e2ae68f393cb6ce2c0cf1dcea /llvm/unittests
parent7caea41545fc9e8afb47073f6699073a5f635c68 (diff)
downloadbcm5719-llvm-90a835d2a0c8eb65f06cd08eb39795377a7a23a3.tar.gz
bcm5719-llvm-90a835d2a0c8eb65f06cd08eb39795377a7a23a3.zip
[PM] Start sketching out the new module and function pass manager.
This is still just a skeleton. I'm trying to pull together the experimentation I've done into committable chunks, and this is the first coherent one. Others will follow in hopefully short order that move this more toward a useful initial implementation. I still expect the design to continue evolving in small ways as I work through the different requirements and features needed here though. Keep in mind, all of this is off by default. Currently, this mostly exercises the use of a polymorphic smart pointer and templates to hide the polymorphism for the pass manager from the pass implementation. The next step will be more significant, adding the first framework of analysis support. llvm-svn: 194325
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/IR/CMakeLists.txt1
-rw-r--r--llvm/unittests/IR/PassManagerTest.cpp88
2 files changed, 89 insertions, 0 deletions
diff --git a/llvm/unittests/IR/CMakeLists.txt b/llvm/unittests/IR/CMakeLists.txt
index 1ab8e384c8a..fd0831f8e1f 100644
--- a/llvm/unittests/IR/CMakeLists.txt
+++ b/llvm/unittests/IR/CMakeLists.txt
@@ -13,6 +13,7 @@ set(IRSources
LegacyPassManagerTest.cpp
MDBuilderTest.cpp
MetadataTest.cpp
+ PassManagerTest.cpp
PatternMatch.cpp
TypeBuilderTest.cpp
TypesTest.cpp
diff --git a/llvm/unittests/IR/PassManagerTest.cpp b/llvm/unittests/IR/PassManagerTest.cpp
new file mode 100644
index 00000000000..f2e04d9e77e
--- /dev/null
+++ b/llvm/unittests/IR/PassManagerTest.cpp
@@ -0,0 +1,88 @@
+//===- llvm/unittest/IR/PassManager.cpp - PassManager tests ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Assembly/Parser.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Support/SourceMgr.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+struct TestModulePass {
+ TestModulePass(int &RunCount) : RunCount(RunCount) {}
+
+ bool run(Module *M) {
+ ++RunCount;
+ return true;
+ }
+
+ int &RunCount;
+};
+
+struct TestFunctionPass {
+ TestFunctionPass(int &RunCount) : RunCount(RunCount) {}
+
+ bool run(Function *F) {
+ ++RunCount;
+ return true;
+ }
+
+ int &RunCount;
+};
+
+Module *parseIR(const char *IR) {
+ LLVMContext &C = getGlobalContext();
+ SMDiagnostic Err;
+ return ParseAssemblyString(IR, 0, Err, C);
+}
+
+class PassManagerTest : public ::testing::Test {
+protected:
+ OwningPtr<Module> M;
+
+public:
+ PassManagerTest()
+ : M(parseIR("define void @f() {\n"
+ "entry:\n"
+ " call void @g()\n"
+ " call void @h()\n"
+ " ret void\n"
+ "}\n"
+ "define void @g() {\n"
+ " ret void\n"
+ "}\n"
+ "define void @h() {\n"
+ " ret void\n"
+ "}\n")) {}
+};
+
+TEST_F(PassManagerTest, Basic) {
+ ModulePassManager MPM(M.get());
+ FunctionPassManager FPM;
+
+ // Count the runs over a module.
+ int ModulePassRunCount = 0;
+ MPM.addPass(TestModulePass(ModulePassRunCount));
+
+ // Count the runs over a Function.
+ int FunctionPassRunCount = 0;
+ FPM.addPass(TestFunctionPass(FunctionPassRunCount));
+ MPM.addPass(FPM);
+
+ MPM.run();
+ EXPECT_EQ(1, ModulePassRunCount);
+ EXPECT_EQ(3, FunctionPassRunCount);
+}
+
+}
OpenPOWER on IntegriCloud