166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===- llvm/unittest/VMCore/PassManager.cpp - Constants unit tests ------===// 266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// The LLVM Compiler Infrastructure 466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// This file is distributed under the University of Illinois Open Source 666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// License. See LICENSE.TXT for details. 766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman// 866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman//===----------------------------------------------------------------------===// 966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 1066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Module.h" 1166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/LLVMContext.h" 1266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/PassManager.h" 1366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Analysis/LoopInfo.h" 1466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Pass.h" 1566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Analysis/LoopPass.h" 1666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/CallGraphSCCPass.h" 1766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Target/TargetData.h" 1866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Support/raw_ostream.h" 1966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/DerivedTypes.h" 2066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Constants.h" 2166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/GlobalVariable.h" 2266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Function.h" 2366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/CallingConv.h" 2466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/BasicBlock.h" 2566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Instructions.h" 2666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/InlineAsm.h" 2766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Support/MathExtras.h" 2866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Support/raw_ostream.h" 2966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/PassManager.h" 3066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/ADT/SmallVector.h" 3166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Analysis/Verifier.h" 3266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "llvm/Assembly/PrintModulePass.h" 3366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman#include "gtest/gtest.h" 3466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumanusing namespace llvm; 3666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 3766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Baumannamespace llvm { 3866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void initializeModuleNDMPass(PassRegistry&); 3966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void initializeFPassPass(PassRegistry&); 4066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void initializeCGPassPass(PassRegistry&); 4166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void initializeLPassPass(PassRegistry&); 4266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void initializeBPassPass(PassRegistry&); 4366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 4466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman namespace { 4566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // ND = no deps 4666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // NM = no modifications 4766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDNM: public ModulePass { 4866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 4966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char run; 5066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 5166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ModuleNDNM() : ModulePass(ID) { } 5266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnModule(Module &M) { 5366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run++; 5466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 5566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 5666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual void getAnalysisUsage(AnalysisUsage &AU) const { 5766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AU.setPreservesAll(); 5866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 5966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 6066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDNM::ID=0; 6166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDNM::run=0; 6266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 6366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM : public ModulePass { 6466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 6566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char run; 6666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 6766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ModuleNDM() : ModulePass(ID) {} 6866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnModule(Module &M) { 6966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run++; 7066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return true; 7166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 7266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 7366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDM::ID=0; 7466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDM::run=0; 7566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 7666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM2 : public ModulePass { 7766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 7866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char run; 7966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 8066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ModuleNDM2() : ModulePass(ID) {} 8166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnModule(Module &M) { 8266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run++; 8366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return true; 8466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 8566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 8666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDM2::ID=0; 8766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleNDM2::run=0; 8866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 8966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleDNM : public ModulePass { 9066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 9166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char run; 9266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 9366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ModuleDNM() : ModulePass(ID) { 9466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initializeModuleNDMPass(*PassRegistry::getPassRegistry()); 9566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 9666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnModule(Module &M) { 9766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 9866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run++; 9966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 10066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 10166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual void getAnalysisUsage(AnalysisUsage &AU) const { 10266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AU.addRequired<ModuleNDM>(); 10366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AU.setPreservesAll(); 10466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 10566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 10666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleDNM::ID=0; 10766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char ModuleDNM::run=0; 10866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 10966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename P> 11066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct PassTestBase : public P { 11166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman protected: 11266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static int runc; 11366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static bool initialized; 11466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static bool finalized; 11566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int allocated; 11666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void run() { 11766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(initialized); 11866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(finalized); 11966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0, allocated); 12066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman allocated++; 12166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman runc++; 12266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 12366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 12466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 12566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static void finishedOK(int run) { 12666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_GT(runc, 0); 12766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(initialized); 12866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(finalized); 12966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(run, runc); 13066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 13166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassTestBase() : P(ID), allocated(0) { 13266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initialized = false; 13366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman finalized = false; 13466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman runc = 0; 13566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 13666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 13766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual void releaseMemory() { 13866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_GT(runc, 0); 13966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_GT(allocated, 0); 14066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman allocated--; 14166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 14266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 14366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename P> char PassTestBase<P>::ID; 14466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename P> int PassTestBase<P>::runc; 14566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename P> bool PassTestBase<P>::initialized; 14666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename P> bool PassTestBase<P>::finalized; 14766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 14866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename T, typename P> 14966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct PassTest : public PassTestBase<P> { 15066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 15166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doInitialization(T &t) { 15266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(PassTestBase<P>::initialized); 15366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassTestBase<P>::initialized = true; 15466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 15566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 15666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doFinalization(T &t) { 15766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(PassTestBase<P>::finalized); 15866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassTestBase<P>::finalized = true; 15966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0, PassTestBase<P>::allocated); 16066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 16166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 16266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 16366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 16466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> { 16566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 16666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman CGPass() { 16766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initializeCGPassPass(*PassRegistry::getPassRegistry()); 16866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 16966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnSCC(CallGraphSCC &SCMM) { 17066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 17166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run(); 17266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 17366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 17466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 17566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 17666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct FPass : public PassTest<Module, FunctionPass> { 17766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 17866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnFunction(Function &F) { 17966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // FIXME: PR4112 18066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 18166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run(); 18266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 18366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 18466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 18566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 18666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct LPass : public PassTestBase<LoopPass> { 18766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman private: 18866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static int initcount; 18966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static int fincount; 19066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 19166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman LPass() { 19266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initializeLPassPass(*PassRegistry::getPassRegistry()); 19366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initcount = 0; fincount=0; 19466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(initialized); 19566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 19666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static void finishedOK(int run, int finalized) { 19766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassTestBase<LoopPass>::finishedOK(run); 19866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(run, initcount); 19966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(finalized, fincount); 20066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 20166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doInitialization(Loop* L, LPPassManager &LPM) { 20266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initialized = true; 20366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initcount++; 20466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 20566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 20666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { 20766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 20866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run(); 20966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 21066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 21166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doFinalization() { 21266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman fincount++; 21366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman finalized = true; 21466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 21566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 21666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 21766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int LPass::initcount=0; 21866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int LPass::fincount=0; 21966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 22066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct BPass : public PassTestBase<BasicBlockPass> { 22166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman private: 22266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static int inited; 22366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static int fin; 22466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 22566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static void finishedOK(int run, int N) { 22666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassTestBase<BasicBlockPass>::finishedOK(run); 22766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(inited, N); 22866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(fin, N); 22966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 23066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BPass() { 23166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman inited = 0; 23266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman fin = 0; 23366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 23466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doInitialization(Module &M) { 23566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(initialized); 23666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initialized = true; 23766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 23866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 23966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doInitialization(Function &F) { 24066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman inited++; 24166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 24266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 24366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnBasicBlock(BasicBlock &BB) { 24466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 24566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman run(); 24666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 24766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 24866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doFinalization(Function &F) { 24966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman fin++; 25066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 25166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 25266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool doFinalization(Module &M) { 25366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_FALSE(finalized); 25466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman finalized = true; 25566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(0, allocated); 25666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 25766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 25866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 25966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int BPass::inited=0; 26066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int BPass::fin=0; 26166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 26266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct OnTheFlyTest: public ModulePass { 26366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman public: 26466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman static char ID; 26566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman OnTheFlyTest() : ModulePass(ID) { 26666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman initializeFPassPass(*PassRegistry::getPassRegistry()); 26766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 26866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual bool runOnModule(Module &M) { 26966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_TRUE(getAnalysisIfAvailable<TargetData>()); 27066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) { 27166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function &F = *I; 27266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 27366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Running on the fly function pass"); 27466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman getAnalysis<FPass>(F); 27566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 27666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 27766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return false; 27866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 27966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman virtual void getAnalysisUsage(AnalysisUsage &AU) const { 28066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AU.addRequired<FPass>(); 28166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 28266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman }; 28366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman char OnTheFlyTest::ID=0; 28466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 28566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman TEST(PassManager, RunOnce) { 28666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module M("test-once", getGlobalContext()); 28766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDNM *mNDNM = new ModuleNDNM(); 28866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleDNM *mDNM = new ModuleDNM(); 28966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM *mNDM = new ModuleNDM(); 29066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM2 *mNDM2 = new ModuleNDM2(); 29166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0; 29366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 29466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassManager Passes; 29566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(new TargetData(&M)); 29666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDM2); 29766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDM); 29866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDNM); 29966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mDNM); 30066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 30166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.run(M); 30266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // each pass must be run exactly once, since nothing invalidates them 30366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mNDM->run); 30466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mNDNM->run); 30566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mDNM->run); 30666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mNDM2->run); 30766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 30866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 30966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman TEST(PassManager, ReRun) { 31066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module M("test-rerun", getGlobalContext()); 31166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDNM *mNDNM = new ModuleNDNM(); 31266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleDNM *mDNM = new ModuleDNM(); 31366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM *mNDM = new ModuleNDM(); 31466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct ModuleNDM2 *mNDM2 = new ModuleNDM2(); 31566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 31666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0; 31766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 31866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassManager Passes; 31966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(new TargetData(&M)); 32066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDM); 32166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDNM); 32266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mNDM2);// invalidates mNDM needed by mDNM 32366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(mDNM); 32466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 32566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.run(M); 32666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Some passes must be rerun because a pass that modified the 32766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // module/function was run inbetween 32866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(2, mNDM->run); 32966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mNDNM->run); 33066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mNDM2->run); 33166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman EXPECT_EQ(1, mDNM->run); 33266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 33366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 33466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module* makeLLVMModule(); 33566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 33666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename T> 33766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void MemoryTestHelper(int run) { 33866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman OwningPtr<Module> M(makeLLVMModule()); 33966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman T *P = new T(); 34066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassManager Passes; 34166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(new TargetData(M.get())); 34266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(P); 34366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.run(*M); 34466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman T::finishedOK(run); 34566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 34666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 34766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman template<typename T> 34866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman void MemoryTestHelper(int run, int N) { 34966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module *M = makeLLVMModule(); 35066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman T *P = new T(); 35166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassManager Passes; 35266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(new TargetData(M)); 35366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(P); 35466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.run(*M); 35566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman T::finishedOK(run, N); 35666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman delete M; 35766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 35866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 35966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman TEST(PassManager, Memory) { 36066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // SCC#1: test1->test2->test3->test1 36166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // SCC#2: test4 36266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // SCC#3: indirect call node 36366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 36466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Callgraph pass"); 36566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman MemoryTestHelper<CGPass>(3); 36666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 36766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 36866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 36966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Function pass"); 37066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman MemoryTestHelper<FPass>(4);// 4 functions 37166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 37266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 37366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 37466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Loop pass"); 37566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function 37666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 37766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 37866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Basic block pass"); 37966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman MemoryTestHelper<BPass>(7, 4); //9 basic blocks 38066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 38166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 38266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 38366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 38466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman TEST(PassManager, MemoryOnTheFly) { 38566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module *M = makeLLVMModule(); 38666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 38766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman SCOPED_TRACE("Running OnTheFlyTest"); 38866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman struct OnTheFlyTest *O = new OnTheFlyTest(); 38966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman PassManager Passes; 39066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(new TargetData(M)); 39166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.add(O); 39266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Passes.run(*M); 39366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 39466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman FPass::finishedOK(4); 39566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 39666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman delete M; 39766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 39866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 39966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module* makeLLVMModule() { 40066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Module Construction 40166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Module* mod = new Module("test-mem", getGlobalContext()); 40266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-" 40366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-" 40466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman "a0:0:64-s0:64:64-f80:128:128"); 40566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman mod->setTargetTriple("x86_64-unknown-linux-gnu"); 40666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 40766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Type Definitions 40866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::vector<Type*>FuncTy_0_args; 40966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman FunctionType* FuncTy_0 = FunctionType::get( 41066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Result=*/IntegerType::get(getGlobalContext(), 32), 41166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Params=*/FuncTy_0_args, 41266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*isVarArg=*/false); 41366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 41466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman std::vector<Type*>FuncTy_2_args; 41566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1)); 41666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman FunctionType* FuncTy_2 = FunctionType::get( 41766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Result=*/Type::getVoidTy(getGlobalContext()), 41866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Params=*/FuncTy_2_args, 41966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*isVarArg=*/false); 42066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 42166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 42266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function Declarations 42366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 42466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function* func_test1 = Function::Create( 42566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Type=*/FuncTy_0, 42666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Linkage=*/GlobalValue::ExternalLinkage, 42766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Name=*/"test1", mod); 42866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test1->setCallingConv(CallingConv::C); 42966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AttrListPtr func_test1_PAL; 43066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test1->setAttributes(func_test1_PAL); 43166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 43266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function* func_test2 = Function::Create( 43366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Type=*/FuncTy_0, 43466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Linkage=*/GlobalValue::ExternalLinkage, 43566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Name=*/"test2", mod); 43666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test2->setCallingConv(CallingConv::C); 43766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AttrListPtr func_test2_PAL; 43866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test2->setAttributes(func_test2_PAL); 43966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 44066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function* func_test3 = Function::Create( 44166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Type=*/FuncTy_0, 44266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Linkage=*/GlobalValue::ExternalLinkage, 44366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Name=*/"test3", mod); 44466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test3->setCallingConv(CallingConv::C); 44566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AttrListPtr func_test3_PAL; 44666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test3->setAttributes(func_test3_PAL); 44766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 44866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function* func_test4 = Function::Create( 44966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Type=*/FuncTy_2, 45066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Linkage=*/GlobalValue::ExternalLinkage, 45166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman /*Name=*/"test4", mod); 45266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test4->setCallingConv(CallingConv::C); 45366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman AttrListPtr func_test4_PAL; 45466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman func_test4->setAttributes(func_test4_PAL); 45566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 45666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Global Variable Declarations 45766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 45866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 45966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Constant Definitions 46066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Global Variable Definitions 46266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function Definitions 46466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function: test1 (func_test1) 46666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 46766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 46866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0); 46966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block entry (label_entry) 47166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry); 47266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_3->setCallingConv(CallingConv::C); 47366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_3->setTailCall(false);AttrListPtr int32_3_PAL; 47466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_3->setAttributes(int32_3_PAL); 47566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ReturnInst::Create(getGlobalContext(), int32_3, label_entry); 47766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 47866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 47966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 48066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function: test2 (func_test2) 48166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 48266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 48366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0); 48466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 48566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block entry (label_entry_5) 48666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5); 48766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_6->setCallingConv(CallingConv::C); 48866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_6->setTailCall(false);AttrListPtr int32_6_PAL; 48966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_6->setAttributes(int32_6_PAL); 49066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5); 49266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 49466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function: test3 (func_test3) 49666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 49766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 49866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0); 49966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 50066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block entry (label_entry_8) 50166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8); 50266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_9->setCallingConv(CallingConv::C); 50366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_9->setTailCall(false);AttrListPtr int32_9_PAL; 50466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int32_9->setAttributes(int32_9_PAL); 50566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 50666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8); 50766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 50866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 50966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 51066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Function: test4 (func_test4) 51166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman { 51266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Function::arg_iterator args = func_test4->arg_begin(); 51366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman Value* int1_f = args++; 51466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman int1_f->setName("f"); 51566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 51666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0); 51766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0); 51866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0); 51966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0); 52066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block entry (label_entry_11) 52266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BranchInst::Create(label_bb, label_entry_11); 52366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block bb (label_bb) 52566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BranchInst::Create(label_bb, label_bb1, int1_f, label_bb); 52666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 52766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block bb1 (label_bb1) 52866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman BranchInst::Create(label_bb1, label_return, int1_f, label_bb1); 52966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 53066b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman // Block return (label_return) 53166b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman ReturnInst::Create(getGlobalContext(), label_return); 53266b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 53366b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 53466b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman return mod; 53566b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 53666b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 53766b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman } 53866b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman} 53966b8ab22586debccb1f787d4d52b7f042d4ddeb8John Bauman 54066b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false) 54166b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false) 54266b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_AG_DEPENDENCY(CallGraph) 54366b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false) 54466b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS(FPass, "fp","fp", false, false) 54566b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false) 54666b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS_DEPENDENCY(LoopInfo) 54766b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS_END(LPass, "lp","lp", false, false) 54866b8ab22586debccb1f787d4d52b7f042d4ddeb8John BaumanINITIALIZE_PASS(BPass, "bp","bp", false, false) 549