Merging r261365:
[oota-llvm.git] / unittests / IR / LegacyPassManagerTest.cpp
index 00b7fd7cc569dbc726a7def62cb83b301e8e0714..1f88283dc0ce3845295b59f653a879ecc5789432 100644 (file)
@@ -8,19 +8,16 @@
 //===----------------------------------------------------------------------===//
 //
 // This unit test exercises the legacy pass manager infrastructure. We use the
-// old names as well to ensure that the source-level compatibility wrapper
-// works for out-of-tree code that expects to include llvm/PassManager.h and
-// subclass the core pass classes.
+// old names as well to ensure that the source-level compatibility is preserved
+// where possible.
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/PassManager.h"
+#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/Analysis/CallGraphSCCPass.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/LoopPass.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CallingConv.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Verifier.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -54,11 +53,11 @@ namespace llvm {
       static char run;
       static char ID;
       ModuleNDNM() : ModulePass(ID) { }
-      virtual bool runOnModule(Module &M) {
+      bool runOnModule(Module &M) override {
         run++;
         return false;
       }
-      virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      void getAnalysisUsage(AnalysisUsage &AU) const override {
         AU.setPreservesAll();
       }
     };
@@ -70,7 +69,7 @@ namespace llvm {
       static char run;
       static char ID;
       ModuleNDM() : ModulePass(ID) {}
-      virtual bool runOnModule(Module &M) {
+      bool runOnModule(Module &M) override {
         run++;
         return true;
       }
@@ -83,7 +82,7 @@ namespace llvm {
       static char run;
       static char ID;
       ModuleNDM2() : ModulePass(ID) {}
-      virtual bool runOnModule(Module &M) {
+      bool runOnModule(Module &M) override {
         run++;
         return true;
       }
@@ -98,12 +97,11 @@ namespace llvm {
       ModuleDNM() : ModulePass(ID) {
         initializeModuleNDMPass(*PassRegistry::getPassRegistry());
       }
-      virtual bool runOnModule(Module &M) {
-        EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
+      bool runOnModule(Module &M) override {
         run++;
         return false;
       }
-      virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      void getAnalysisUsage(AnalysisUsage &AU) const override {
         AU.addRequired<ModuleNDM>();
         AU.setPreservesAll();
       }
@@ -139,7 +137,7 @@ namespace llvm {
         runc = 0;
       }
 
-      virtual void releaseMemory() {
+      void releaseMemory() override {
         EXPECT_GT(runc, 0);
         EXPECT_GT(allocated, 0);
         allocated--;
@@ -157,12 +155,12 @@ namespace llvm {
       using llvm::Pass::doInitialization;
       using llvm::Pass::doFinalization;
 #endif
-      virtual bool doInitialization(T &t) {
+      bool doInitialization(T &t) override {
         EXPECT_FALSE(PassTestBase<P>::initialized);
         PassTestBase<P>::initialized = true;
         return false;
       }
-      virtual bool doFinalization(T &t) {
+      bool doFinalization(T &t) override {
         EXPECT_FALSE(PassTestBase<P>::finalized);
         PassTestBase<P>::finalized = true;
         EXPECT_EQ(0, PassTestBase<P>::allocated);
@@ -175,8 +173,7 @@ namespace llvm {
       CGPass() {
         initializeCGPassPass(*PassRegistry::getPassRegistry());
       }
-      virtual bool runOnSCC(CallGraphSCC &SCMM) {
-        EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
+      bool runOnSCC(CallGraphSCC &SCMM) override {
         run();
         return false;
       }
@@ -184,7 +181,7 @@ namespace llvm {
 
     struct FPass : public PassTest<Module, FunctionPass> {
     public:
-      virtual bool runOnFunction(Function &F) {
+      bool runOnFunction(Function &F) override {
         // FIXME: PR4112
         // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
         run();
@@ -209,17 +206,16 @@ namespace llvm {
       }
       using llvm::Pass::doInitialization;
       using llvm::Pass::doFinalization;
-      virtual bool doInitialization(Loop* L, LPPassManager &LPM) {
+      bool doInitialization(Loop* L, LPPassManager &LPM) override {
         initialized = true;
         initcount++;
         return false;
       }
-      virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
-        EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
+      bool runOnLoop(Loop *L, LPPassManager &LPM) override {
         run();
         return false;
       }
-      virtual bool doFinalization() {
+      bool doFinalization() override {
         fincount++;
         finalized = true;
         return false;
@@ -242,25 +238,24 @@ namespace llvm {
         inited = 0;
         fin = 0;
       }
-      virtual bool doInitialization(Module &M) {
+      bool doInitialization(Module &M) override {
         EXPECT_FALSE(initialized);
         initialized = true;
         return false;
       }
-      virtual bool doInitialization(Function &F) {
+      bool doInitialization(Function &F) override {
         inited++;
         return false;
       }
-      virtual bool runOnBasicBlock(BasicBlock &BB) {
-        EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
+      bool runOnBasicBlock(BasicBlock &BB) override {
         run();
         return false;
       }
-      virtual bool doFinalization(Function &F) {
+      bool doFinalization(Function &F) override {
         fin++;
         return false;
       }
-      virtual bool doFinalization(Module &M) {
+      bool doFinalization(Module &M) override {
         EXPECT_FALSE(finalized);
         finalized = true;
         EXPECT_EQ(0, allocated);
@@ -276,8 +271,7 @@ namespace llvm {
       OnTheFlyTest() : ModulePass(ID) {
         initializeFPassPass(*PassRegistry::getPassRegistry());
       }
-      virtual bool runOnModule(Module &M) {
-        EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
+      bool runOnModule(Module &M) override {
         for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
           Function &F = *I;
           {
@@ -287,7 +281,7 @@ namespace llvm {
         }
         return false;
       }
-      virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      void getAnalysisUsage(AnalysisUsage &AU) const override {
         AU.addRequired<FPass>();
       }
     };
@@ -302,8 +296,7 @@ namespace llvm {
 
       mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
 
-      PassManager Passes;
-      Passes.add(new DataLayout(&M));
+      legacy::PassManager Passes;
       Passes.add(mNDM2);
       Passes.add(mNDM);
       Passes.add(mNDNM);
@@ -326,8 +319,7 @@ namespace llvm {
 
       mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
 
-      PassManager Passes;
-      Passes.add(new DataLayout(&M));
+      legacy::PassManager Passes;
       Passes.add(mNDM);
       Passes.add(mNDNM);
       Passes.add(mNDM2);// invalidates mNDM needed by mDNM
@@ -346,10 +338,9 @@ namespace llvm {
 
     template<typename T>
     void MemoryTestHelper(int run) {
-      OwningPtr<Module> M(makeLLVMModule());
+      std::unique_ptr<Module> M(makeLLVMModule());
       T *P = new T();
-      PassManager Passes;
-      Passes.add(new DataLayout(M.get()));
+      legacy::PassManager Passes;
       Passes.add(P);
       Passes.run(*M);
       T::finishedOK(run);
@@ -359,8 +350,7 @@ namespace llvm {
     void MemoryTestHelper(int run, int N) {
       Module *M = makeLLVMModule();
       T *P = new T();
-      PassManager Passes;
-      Passes.add(new DataLayout(M));
+      legacy::PassManager Passes;
       Passes.add(P);
       Passes.run(*M);
       T::finishedOK(run, N);
@@ -397,8 +387,7 @@ namespace llvm {
       {
         SCOPED_TRACE("Running OnTheFlyTest");
         struct OnTheFlyTest *O = new OnTheFlyTest();
-        PassManager Passes;
-        Passes.add(new DataLayout(M));
+        legacy::PassManager Passes;
         Passes.add(O);
         Passes.run(*M);
 
@@ -412,7 +401,7 @@ namespace llvm {
       Module* mod = new Module("test-mem", getGlobalContext());
       mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
                          "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
-                         "a0:0:64-s0:64:64-f80:128:128");
+                         "a:0:64-s:64:64-f80:128:128");
       mod->setTargetTriple("x86_64-unknown-linux-gnu");
 
       // Type Definitions
@@ -476,7 +465,7 @@ namespace llvm {
       // Function: test1 (func_test1)
       {
 
-        BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0);
+        BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,nullptr);
 
         // Block entry (label_entry)
         CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
@@ -491,7 +480,7 @@ namespace llvm {
       // Function: test2 (func_test2)
       {
 
-        BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0);
+        BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,nullptr);
 
         // Block entry (label_entry_5)
         CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
@@ -506,7 +495,7 @@ namespace llvm {
       // Function: test3 (func_test3)
       {
 
-        BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0);
+        BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,nullptr);
 
         // Block entry (label_entry_8)
         CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
@@ -521,13 +510,13 @@ namespace llvm {
       // Function: test4 (func_test4)
       {
         Function::arg_iterator args = func_test4->arg_begin();
-        Value* int1_f = args++;
+        Value *int1_f = &*args++;
         int1_f->setName("f");
 
-        BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0);
-        BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0);
-        BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0);
-        BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0);
+        BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,nullptr);
+        BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,nullptr);
+        BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,nullptr);
+        BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,nullptr);
 
         // Block entry (label_entry_11)
         BranchInst::Create(label_bb, label_entry_11);
@@ -554,6 +543,6 @@ INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
 INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
 INITIALIZE_PASS(FPass, "fp","fp", false, false)
 INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
-INITIALIZE_PASS_DEPENDENCY(LoopInfo)
+INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
 INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
 INITIALIZE_PASS(BPass, "bp","bp", false, false)