Re-land: Generate targets for each lit suite.
[oota-llvm.git] / unittests / Analysis / CFGTest.cpp
index bc029e37863469a4eecadd07e63a732bffe506e7..4b4ebb610ef035afe888b68f3863965a43101b96 100644 (file)
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Analysis/CFG.h"
-#include "llvm/ADT/OwningPtr.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/Dominators.h"
@@ -17,7 +16,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
-#include "llvm/PassManager.h"
+#include "llvm/IR/LegacyPassManager.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/SourceMgr.h"
 #include "gtest/gtest.h"
@@ -31,26 +30,22 @@ namespace {
 class IsPotentiallyReachableTest : public testing::Test {
 protected:
   void ParseAssembly(const char *Assembly) {
-    M.reset(new Module("Module", getGlobalContext()));
-
     SMDiagnostic Error;
-    bool Parsed = ParseAssemblyString(Assembly, M.get(),
-                                      Error, M->getContext()) == M.get();
+    M = parseAssemblyString(Assembly, Error, getGlobalContext());
 
     std::string errMsg;
     raw_string_ostream os(errMsg);
     Error.print("", os);
 
-    if (!Parsed) {
-      // A failure here means that the test itself is buggy.
+    // A failure here means that the test itself is buggy.
+    if (!M)
       report_fatal_error(os.str().c_str());
-    }
 
     Function *F = M->getFunction("test");
-    if (F == NULL)
+    if (F == nullptr)
       report_fatal_error("Test must have a function named @test");
 
-    A = B = NULL;
+    A = B = nullptr;
     for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
       if (I->hasName()) {
         if (I->getName() == "A")
@@ -59,9 +54,9 @@ protected:
           B = &*I;
       }
     }
-    if (A == NULL)
+    if (A == nullptr)
       report_fatal_error("@test must have an instruction %A");
-    if (B == NULL)
+    if (B == nullptr)
       report_fatal_error("@test must have an instruction %B");
   }
 
@@ -75,9 +70,9 @@ protected:
 
       static int initialize() {
         PassInfo *PI = new PassInfo("isPotentiallyReachable testing pass",
-                                    "", &ID, 0, true, true);
+                                    "", &ID, nullptr, true, true);
         PassRegistry::getPassRegistry()->registerPass(*PI, false);
-        initializeLoopInfoPass(*PassRegistry::getPassRegistry());
+        initializeLoopInfoWrapperPassPass(*PassRegistry::getPassRegistry());
         initializeDominatorTreeWrapperPassPass(
             *PassRegistry::getPassRegistry());
         return 0;
@@ -85,7 +80,7 @@ protected:
 
       void getAnalysisUsage(AnalysisUsage &AU) const {
         AU.setPreservesAll();
-        AU.addRequired<LoopInfo>();
+        AU.addRequired<LoopInfoWrapperPass>();
         AU.addRequired<DominatorTreeWrapperPass>();
       }
 
@@ -93,12 +88,13 @@ protected:
         if (!F.hasName() || F.getName() != "test")
           return false;
 
-        LoopInfo *LI = &getAnalysis<LoopInfo>();
+        LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
         DominatorTree *DT =
             &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
-        EXPECT_EQ(isPotentiallyReachable(A, B, 0, 0), ExpectedResult);
-        EXPECT_EQ(isPotentiallyReachable(A, B, DT, 0), ExpectedResult);
-        EXPECT_EQ(isPotentiallyReachable(A, B, 0, LI), ExpectedResult);
+        EXPECT_EQ(isPotentiallyReachable(A, B, nullptr, nullptr),
+                  ExpectedResult);
+        EXPECT_EQ(isPotentiallyReachable(A, B, DT, nullptr), ExpectedResult);
+        EXPECT_EQ(isPotentiallyReachable(A, B, nullptr, LI), ExpectedResult);
         EXPECT_EQ(isPotentiallyReachable(A, B, DT, LI), ExpectedResult);
         return false;
       }
@@ -111,12 +107,12 @@ protected:
 
     IsPotentiallyReachableTestPass *P =
         new IsPotentiallyReachableTestPass(ExpectedResult, A, B);
-    PassManager PM;
+    legacy::PassManager PM;
     PM.add(P);
     PM.run(*M);
   }
 
-  OwningPtr<Module> M;
+  std::unique_ptr<Module> M;
   Instruction *A, *B;
 };