X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=unittests%2FVMCore%2FPassManagerTest.cpp;h=60d33c19c337e8ba3b2cbd383b2932f5f086954b;hb=d9b0b025612992a0b724eeca8bdf10b1d7a5c355;hp=092ce3d928b2390e210d03d39e0b61f0893796d7;hpb=8dd0ab074a86ea5eaadfb970323ce133328a2860;p=oota-llvm.git diff --git a/unittests/VMCore/PassManagerTest.cpp b/unittests/VMCore/PassManagerTest.cpp index 092ce3d928b..60d33c19c33 100644 --- a/unittests/VMCore/PassManagerTest.cpp +++ b/unittests/VMCore/PassManagerTest.cpp @@ -32,11 +32,15 @@ #include "llvm/Assembly/PrintModulePass.h" #include "gtest/gtest.h" -int dummy; - -#if 0 +using namespace llvm; namespace llvm { + void initializeModuleNDMPass(PassRegistry&); + void initializeFPassPass(PassRegistry&); + void initializeCGPassPass(PassRegistry&); + void initializeLPassPass(PassRegistry&); + void initializeBPassPass(PassRegistry&); + namespace { // ND = no deps // NM = no modifications @@ -44,7 +48,7 @@ namespace llvm { public: static char run; static char ID; - ModuleNDNM() : ModulePass(&ID) {} + ModuleNDNM() : ModulePass(ID) { } virtual bool runOnModule(Module &M) { run++; return false; @@ -60,7 +64,7 @@ namespace llvm { public: static char run; static char ID; - ModuleNDM() : ModulePass(&ID) {} + ModuleNDM() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { run++; return true; @@ -68,13 +72,12 @@ namespace llvm { }; char ModuleNDM::ID=0; char ModuleNDM::run=0; - RegisterPass X("mndm","mndm",false,false); struct ModuleNDM2 : public ModulePass { public: static char run; static char ID; - ModuleNDM2() : ModulePass(&ID) {} + ModuleNDM2() : ModulePass(ID) {} virtual bool runOnModule(Module &M) { run++; return true; @@ -87,7 +90,9 @@ namespace llvm { public: static char run; static char ID; - ModuleDNM() : ModulePass(&ID) {} + ModuleDNM() : ModulePass(ID) { + initializeModuleNDMPass(*PassRegistry::getPassRegistry()); + } virtual bool runOnModule(Module &M) { EXPECT_TRUE(getAnalysisIfAvailable()); run++; @@ -109,8 +114,8 @@ namespace llvm { static bool finalized; int allocated; void run() { - EXPECT_EQ(true, initialized); - EXPECT_EQ(false, finalized); + EXPECT_TRUE(initialized); + EXPECT_FALSE(finalized); EXPECT_EQ(0, allocated); allocated++; runc++; @@ -119,11 +124,11 @@ namespace llvm { static char ID; static void finishedOK(int run) { EXPECT_GT(runc, 0); - EXPECT_EQ(true, initialized); - EXPECT_EQ(true, finalized); + EXPECT_TRUE(initialized); + EXPECT_TRUE(finalized); EXPECT_EQ(run, runc); } - PassTestBase() : P(&ID), allocated(0) { + PassTestBase() : P(ID), allocated(0) { initialized = false; finalized = false; runc = 0; @@ -144,12 +149,12 @@ namespace llvm { struct PassTest : public PassTestBase

{ public: virtual bool doInitialization(T &t) { - EXPECT_EQ(false, PassTestBase

::initialized); + EXPECT_FALSE(PassTestBase

::initialized); PassTestBase

::initialized = true; return false; } virtual bool doFinalization(T &t) { - EXPECT_EQ(false, PassTestBase

::finalized); + EXPECT_FALSE(PassTestBase

::finalized); PassTestBase

::finalized = true; EXPECT_EQ(0, PassTestBase

::allocated); return false; @@ -158,13 +163,15 @@ namespace llvm { struct CGPass : public PassTest { public: - virtual bool runOnSCC(std::vector &SCMM) { + CGPass() { + initializeCGPassPass(*PassRegistry::getPassRegistry()); + } + virtual bool runOnSCC(CallGraphSCC &SCMM) { EXPECT_TRUE(getAnalysisIfAvailable()); run(); return false; } }; - RegisterPass X1("cgp","cgp"); struct FPass : public PassTest { public: @@ -175,7 +182,6 @@ namespace llvm { return false; } }; - RegisterPass X2("fp","fp"); struct LPass : public PassTestBase { private: @@ -183,8 +189,9 @@ namespace llvm { static int fincount; public: LPass() { + initializeLPassPass(*PassRegistry::getPassRegistry()); initcount = 0; fincount=0; - EXPECT_EQ(false, initialized); + EXPECT_FALSE(initialized); } static void finishedOK(int run, int finalized) { PassTestBase::finishedOK(run); @@ -209,7 +216,6 @@ namespace llvm { }; int LPass::initcount=0; int LPass::fincount=0; - RegisterPass X3("lp","lp"); struct BPass : public PassTestBase { private: @@ -226,7 +232,7 @@ namespace llvm { fin = 0; } virtual bool doInitialization(Module &M) { - EXPECT_EQ(false, initialized); + EXPECT_FALSE(initialized); initialized = true; return false; } @@ -244,7 +250,7 @@ namespace llvm { return false; } virtual bool doFinalization(Module &M) { - EXPECT_EQ(false, finalized); + EXPECT_FALSE(finalized); finalized = true; EXPECT_EQ(0, allocated); return false; @@ -252,12 +258,13 @@ namespace llvm { }; int BPass::inited=0; int BPass::fin=0; - RegisterPass X4("bp","bp"); struct OnTheFlyTest: public ModulePass { public: static char ID; - OnTheFlyTest() : ModulePass(&ID) {} + OnTheFlyTest() : ModulePass(ID) { + initializeFPassPass(*PassRegistry::getPassRegistry()); + } virtual bool runOnModule(Module &M) { EXPECT_TRUE(getAnalysisIfAvailable()); for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) { @@ -317,7 +324,7 @@ namespace llvm { Passes.run(M); // Some passes must be rerun because a pass that modified the - // module/function was run inbetween + // module/function was run in between EXPECT_EQ(2, mNDM->run); EXPECT_EQ(1, mNDNM->run); EXPECT_EQ(1, mNDM2->run); @@ -328,10 +335,10 @@ namespace llvm { template void MemoryTestHelper(int run) { - Module *M = makeLLVMModule(); + OwningPtr M(makeLLVMModule()); T *P = new T(); PassManager Passes; - Passes.add(new TargetData(M)); + Passes.add(new TargetData(M.get())); Passes.add(P); Passes.run(*M); T::finishedOK(run); @@ -398,13 +405,13 @@ namespace llvm { mod->setTargetTriple("x86_64-unknown-linux-gnu"); // Type Definitions - std::vectorFuncTy_0_args; + std::vectorFuncTy_0_args; FunctionType* FuncTy_0 = FunctionType::get( /*Result=*/IntegerType::get(getGlobalContext(), 32), /*Params=*/FuncTy_0_args, /*isVarArg=*/false); - std::vectorFuncTy_2_args; + std::vectorFuncTy_2_args; FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1)); FunctionType* FuncTy_2 = FunctionType::get( /*Result=*/Type::getVoidTy(getGlobalContext()), @@ -529,4 +536,13 @@ namespace llvm { } } -#endif + +INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false) +INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false) +INITIALIZE_AG_DEPENDENCY(CallGraph) +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_END(LPass, "lp","lp", false, false) +INITIALIZE_PASS(BPass, "bp","bp", false, false)