summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/IR
diff options
context:
space:
mode:
authorFedor Sergeev <fedor.sergeev@azul.com>2018-04-05 10:29:37 +0000
committerFedor Sergeev <fedor.sergeev@azul.com>2018-04-05 10:29:37 +0000
commitd29884c7e6fac28d8af07ab6c818575c75664d3b (patch)
treec601cf05f93870f25ce0be44d33d4d6d4078054d /llvm/unittests/IR
parent978502f4758216ef21ff478ea0d9eb5cc5b2369f (diff)
downloadbcm5719-llvm-d29884c7e6fac28d8af07ab6c818575c75664d3b.tar.gz
bcm5719-llvm-d29884c7e6fac28d8af07ab6c818575c75664d3b.zip
allow custom OptBisect classes set to LLVMContext
This patch introduces a way to set custom OptPassGate instances to LLVMContext. A new instance field OptBisector and a new method setOptBisect() are added to the LLVMContext classes. These changes allow to set a custom OptBisect class that can make its own decisions on skipping optional passes. Another important feature of this change is ability to set different instances of OptPassGate to different LLVMContexts. So the different contexts can be used independently in several compiling threads of one process. One unit test is added. Patch by Yevgeny Rouban. Reviewers: andrew.w.kaylor, fedor.sergeev, vsk, dberlin, Eugene.Zelenko, reames, skatkov Reviewed By: andrew.w.kaylor, fedor.sergeev Differential Revision: https://reviews.llvm.org/D44464 llvm-svn: 329267
Diffstat (limited to 'llvm/unittests/IR')
-rw-r--r--llvm/unittests/IR/LegacyPassManagerTest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/llvm/unittests/IR/LegacyPassManagerTest.cpp b/llvm/unittests/IR/LegacyPassManagerTest.cpp
index 0ff2ec71759..9f5f431a558 100644
--- a/llvm/unittests/IR/LegacyPassManagerTest.cpp
+++ b/llvm/unittests/IR/LegacyPassManagerTest.cpp
@@ -26,6 +26,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
+#include "llvm/IR/OptBisect.h"
#include "llvm/Pass.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
@@ -396,6 +397,67 @@ namespace llvm {
delete M;
}
+ // Skips or runs optional passes.
+ struct CustomOptPassGate : public OptPassGate {
+ bool Skip;
+ CustomOptPassGate(bool Skip) : Skip(Skip) { }
+ bool shouldRunPass(const Pass *P, const Module &U) { return !Skip; }
+ };
+
+ // Optional module pass.
+ struct ModuleOpt: public ModulePass {
+ char run = 0;
+ static char ID;
+ ModuleOpt() : ModulePass(ID) { }
+ bool runOnModule(Module &M) override {
+ if (!skipModule(M))
+ run++;
+ return false;
+ }
+ };
+ char ModuleOpt::ID=0;
+
+ TEST(PassManager, CustomOptPassGate) {
+ LLVMContext Context0;
+ LLVMContext Context1;
+ LLVMContext Context2;
+ CustomOptPassGate SkipOptionalPasses(true);
+ CustomOptPassGate RunOptionalPasses(false);
+
+ Module M0("custom-opt-bisect", Context0);
+ Module M1("custom-opt-bisect", Context1);
+ Module M2("custom-opt-bisect2", Context2);
+ struct ModuleOpt *mOpt0 = new ModuleOpt();
+ struct ModuleOpt *mOpt1 = new ModuleOpt();
+ struct ModuleOpt *mOpt2 = new ModuleOpt();
+
+ mOpt0->run = mOpt1->run = mOpt2->run = 0;
+
+ legacy::PassManager Passes0;
+ legacy::PassManager Passes1;
+ legacy::PassManager Passes2;
+
+ Passes0.add(mOpt0);
+ Passes1.add(mOpt1);
+ Passes2.add(mOpt2);
+
+ Context1.setOptPassGate(SkipOptionalPasses);
+ Context2.setOptPassGate(RunOptionalPasses);
+
+ Passes0.run(M0);
+ Passes1.run(M1);
+ Passes2.run(M2);
+
+ // By default optional passes are run.
+ EXPECT_EQ(1, mOpt0->run);
+
+ // The first context skips optional passes.
+ EXPECT_EQ(0, mOpt1->run);
+
+ // The second context runs optional passes.
+ EXPECT_EQ(1, mOpt2->run);
+ }
+
Module *makeLLVMModule(LLVMContext &Context) {
// Module Construction
Module *mod = new Module("test-mem", Context);
OpenPOWER on IntegriCloud