2013-11-09 13:26:54 +01:00
|
|
|
//===- llvm/unittest/IR/LegacyPassManager.cpp - Legacy PassManager tests --===//
|
2009-06-29 20:49:09 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2013-11-09 13:26:54 +01:00
|
|
|
//
|
|
|
|
// This unit test exercises the legacy pass manager infrastructure. We use the
|
2015-02-13 11:01:29 +01:00
|
|
|
// old names as well to ensure that the source-level compatibility is preserved
|
|
|
|
// where possible.
|
2013-11-09 13:26:54 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-29 20:49:09 +02:00
|
|
|
|
2015-02-13 11:01:29 +01:00
|
|
|
#include "llvm/IR/LegacyPassManager.h"
|
2012-12-04 11:23:08 +01:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-07 16:26:48 +01:00
|
|
|
#include "llvm/Analysis/CallGraphSCCPass.h"
|
2009-06-29 20:49:09 +02:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/CallingConv.h"
|
|
|
|
#include "llvm/IR/Constants.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/GlobalVariable.h"
|
2014-01-12 12:10:32 +01:00
|
|
|
#include "llvm/IR/IRPrintingPasses.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/InlineAsm.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
2014-01-13 10:26:24 +01:00
|
|
|
#include "llvm/IR/Verifier.h"
|
2012-12-04 11:23:08 +01:00
|
|
|
#include "llvm/Pass.h"
|
2009-06-29 20:49:09 +02:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2010-10-19 19:21:58 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-06-29 20:49:09 +02:00
|
|
|
namespace llvm {
|
2010-10-19 19:21:58 +02:00
|
|
|
void initializeModuleNDMPass(PassRegistry&);
|
|
|
|
void initializeFPassPass(PassRegistry&);
|
|
|
|
void initializeCGPassPass(PassRegistry&);
|
|
|
|
void initializeLPassPass(PassRegistry&);
|
|
|
|
void initializeBPassPass(PassRegistry&);
|
2011-03-31 11:58:51 +02:00
|
|
|
|
2009-06-29 20:49:09 +02:00
|
|
|
namespace {
|
|
|
|
// ND = no deps
|
|
|
|
// NM = no modifications
|
|
|
|
struct ModuleNDNM: public ModulePass {
|
|
|
|
public:
|
|
|
|
static char run;
|
|
|
|
static char ID;
|
2010-10-19 19:21:58 +02:00
|
|
|
ModuleNDNM() : ModulePass(ID) { }
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run++;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2009-06-29 20:49:09 +02:00
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char ModuleNDNM::ID=0;
|
|
|
|
char ModuleNDNM::run=0;
|
|
|
|
|
|
|
|
struct ModuleNDM : public ModulePass {
|
|
|
|
public:
|
|
|
|
static char run;
|
|
|
|
static char ID;
|
2010-08-06 20:33:48 +02:00
|
|
|
ModuleNDM() : ModulePass(ID) {}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char ModuleNDM::ID=0;
|
|
|
|
char ModuleNDM::run=0;
|
|
|
|
|
|
|
|
struct ModuleNDM2 : public ModulePass {
|
|
|
|
public:
|
|
|
|
static char run;
|
|
|
|
static char ID;
|
2010-08-06 20:33:48 +02:00
|
|
|
ModuleNDM2() : ModulePass(ID) {}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char ModuleNDM2::ID=0;
|
|
|
|
char ModuleNDM2::run=0;
|
|
|
|
|
|
|
|
struct ModuleDNM : public ModulePass {
|
|
|
|
public:
|
|
|
|
static char run;
|
|
|
|
static char ID;
|
2010-10-19 19:21:58 +02:00
|
|
|
ModuleDNM() : ModulePass(ID) {
|
|
|
|
initializeModuleNDMPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run++;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2009-06-29 20:49:09 +02:00
|
|
|
AU.addRequired<ModuleNDM>();
|
|
|
|
AU.setPreservesAll();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char ModuleDNM::ID=0;
|
|
|
|
char ModuleDNM::run=0;
|
|
|
|
|
|
|
|
template<typename P>
|
|
|
|
struct PassTestBase : public P {
|
|
|
|
protected:
|
|
|
|
static int runc;
|
|
|
|
static bool initialized;
|
|
|
|
static bool finalized;
|
|
|
|
int allocated;
|
|
|
|
void run() {
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_TRUE(initialized);
|
|
|
|
EXPECT_FALSE(finalized);
|
2009-06-29 20:49:09 +02:00
|
|
|
EXPECT_EQ(0, allocated);
|
|
|
|
allocated++;
|
|
|
|
runc++;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
static void finishedOK(int run) {
|
|
|
|
EXPECT_GT(runc, 0);
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_TRUE(initialized);
|
|
|
|
EXPECT_TRUE(finalized);
|
2009-06-29 20:49:09 +02:00
|
|
|
EXPECT_EQ(run, runc);
|
|
|
|
}
|
2010-08-06 20:33:48 +02:00
|
|
|
PassTestBase() : P(ID), allocated(0) {
|
2009-06-29 20:49:09 +02:00
|
|
|
initialized = false;
|
|
|
|
finalized = false;
|
|
|
|
runc = 0;
|
|
|
|
}
|
|
|
|
|
2014-09-10 17:50:08 +02:00
|
|
|
void releaseMemory() override {
|
2009-06-29 20:49:09 +02:00
|
|
|
EXPECT_GT(runc, 0);
|
|
|
|
EXPECT_GT(allocated, 0);
|
|
|
|
allocated--;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<typename P> char PassTestBase<P>::ID;
|
|
|
|
template<typename P> int PassTestBase<P>::runc;
|
|
|
|
template<typename P> bool PassTestBase<P>::initialized;
|
|
|
|
template<typename P> bool PassTestBase<P>::finalized;
|
|
|
|
|
|
|
|
template<typename T, typename P>
|
|
|
|
struct PassTest : public PassTestBase<P> {
|
|
|
|
public:
|
2012-12-04 08:25:24 +01:00
|
|
|
#ifndef _MSC_VER // MSVC complains that Pass is not base class.
|
2012-12-04 06:41:27 +01:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
2012-12-04 08:25:24 +01:00
|
|
|
#endif
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doInitialization(T &t) override {
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_FALSE(PassTestBase<P>::initialized);
|
2009-06-29 20:49:09 +02:00
|
|
|
PassTestBase<P>::initialized = true;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doFinalization(T &t) override {
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_FALSE(PassTestBase<P>::finalized);
|
2009-06-29 20:49:09 +02:00
|
|
|
PassTestBase<P>::finalized = true;
|
|
|
|
EXPECT_EQ(0, PassTestBase<P>::allocated);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
|
|
|
|
public:
|
2010-10-19 19:21:58 +02:00
|
|
|
CGPass() {
|
|
|
|
initializeCGPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnSCC(CallGraphSCC &SCMM) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FPass : public PassTest<Module, FunctionPass> {
|
|
|
|
public:
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnFunction(Function &F) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
// FIXME: PR4112
|
2012-10-08 18:39:34 +02:00
|
|
|
// EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
|
2009-06-29 20:49:09 +02:00
|
|
|
run();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LPass : public PassTestBase<LoopPass> {
|
|
|
|
private:
|
|
|
|
static int initcount;
|
|
|
|
static int fincount;
|
|
|
|
public:
|
|
|
|
LPass() {
|
2010-10-19 19:21:58 +02:00
|
|
|
initializeLPassPass(*PassRegistry::getPassRegistry());
|
2009-06-29 20:49:09 +02:00
|
|
|
initcount = 0; fincount=0;
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_FALSE(initialized);
|
2009-06-29 20:49:09 +02:00
|
|
|
}
|
|
|
|
static void finishedOK(int run, int finalized) {
|
|
|
|
PassTestBase<LoopPass>::finishedOK(run);
|
|
|
|
EXPECT_EQ(run, initcount);
|
|
|
|
EXPECT_EQ(finalized, fincount);
|
|
|
|
}
|
2012-12-04 06:41:27 +01:00
|
|
|
using llvm::Pass::doInitialization;
|
|
|
|
using llvm::Pass::doFinalization;
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doInitialization(Loop* L, LPPassManager &LPM) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
initialized = true;
|
|
|
|
initcount++;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnLoop(Loop *L, LPPassManager &LPM) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run();
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doFinalization() override {
|
2009-06-29 20:49:09 +02:00
|
|
|
fincount++;
|
|
|
|
finalized = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int LPass::initcount=0;
|
|
|
|
int LPass::fincount=0;
|
|
|
|
|
|
|
|
struct BPass : public PassTestBase<BasicBlockPass> {
|
|
|
|
private:
|
|
|
|
static int inited;
|
|
|
|
static int fin;
|
|
|
|
public:
|
|
|
|
static void finishedOK(int run, int N) {
|
|
|
|
PassTestBase<BasicBlockPass>::finishedOK(run);
|
|
|
|
EXPECT_EQ(inited, N);
|
|
|
|
EXPECT_EQ(fin, N);
|
|
|
|
}
|
|
|
|
BPass() {
|
|
|
|
inited = 0;
|
|
|
|
fin = 0;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doInitialization(Module &M) override {
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_FALSE(initialized);
|
2009-06-29 20:49:09 +02:00
|
|
|
initialized = true;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doInitialization(Function &F) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
inited++;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnBasicBlock(BasicBlock &BB) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
run();
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doFinalization(Function &F) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
fin++;
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool doFinalization(Module &M) override {
|
2010-07-13 19:28:05 +02:00
|
|
|
EXPECT_FALSE(finalized);
|
2009-06-29 20:49:09 +02:00
|
|
|
finalized = true;
|
|
|
|
EXPECT_EQ(0, allocated);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
int BPass::inited=0;
|
|
|
|
int BPass::fin=0;
|
|
|
|
|
|
|
|
struct OnTheFlyTest: public ModulePass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2010-10-19 19:21:58 +02:00
|
|
|
OnTheFlyTest() : ModulePass(ID) {
|
|
|
|
initializeFPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
bool runOnModule(Module &M) override {
|
2009-06-29 20:49:09 +02:00
|
|
|
for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
|
|
|
|
Function &F = *I;
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Running on the fly function pass");
|
|
|
|
getAnalysis<FPass>(F);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-10 17:50:08 +02:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2009-06-29 20:49:09 +02:00
|
|
|
AU.addRequired<FPass>();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
char OnTheFlyTest::ID=0;
|
|
|
|
|
|
|
|
TEST(PassManager, RunOnce) {
|
2009-08-13 23:58:54 +02:00
|
|
|
Module M("test-once", getGlobalContext());
|
2009-06-29 20:49:09 +02:00
|
|
|
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
|
|
|
struct ModuleDNM *mDNM = new ModuleDNM();
|
|
|
|
struct ModuleNDM *mNDM = new ModuleNDM();
|
|
|
|
struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
|
|
|
|
|
|
|
|
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
|
|
|
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager Passes;
|
2009-06-29 20:49:09 +02:00
|
|
|
Passes.add(mNDM2);
|
|
|
|
Passes.add(mNDM);
|
|
|
|
Passes.add(mNDNM);
|
|
|
|
Passes.add(mDNM);
|
|
|
|
|
|
|
|
Passes.run(M);
|
|
|
|
// each pass must be run exactly once, since nothing invalidates them
|
|
|
|
EXPECT_EQ(1, mNDM->run);
|
|
|
|
EXPECT_EQ(1, mNDNM->run);
|
|
|
|
EXPECT_EQ(1, mDNM->run);
|
|
|
|
EXPECT_EQ(1, mNDM2->run);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PassManager, ReRun) {
|
2009-08-13 23:58:54 +02:00
|
|
|
Module M("test-rerun", getGlobalContext());
|
2009-06-29 20:49:09 +02:00
|
|
|
struct ModuleNDNM *mNDNM = new ModuleNDNM();
|
|
|
|
struct ModuleDNM *mDNM = new ModuleDNM();
|
|
|
|
struct ModuleNDM *mNDM = new ModuleNDM();
|
|
|
|
struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
|
|
|
|
|
|
|
|
mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
|
|
|
|
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager Passes;
|
2009-06-29 20:49:09 +02:00
|
|
|
Passes.add(mNDM);
|
|
|
|
Passes.add(mNDNM);
|
|
|
|
Passes.add(mNDM2);// invalidates mNDM needed by mDNM
|
|
|
|
Passes.add(mDNM);
|
|
|
|
|
|
|
|
Passes.run(M);
|
|
|
|
// Some passes must be rerun because a pass that modified the
|
2012-06-02 12:20:22 +02:00
|
|
|
// module/function was run in between
|
2009-06-29 20:49:09 +02:00
|
|
|
EXPECT_EQ(2, mNDM->run);
|
|
|
|
EXPECT_EQ(1, mNDNM->run);
|
|
|
|
EXPECT_EQ(1, mNDM2->run);
|
|
|
|
EXPECT_EQ(1, mDNM->run);
|
|
|
|
}
|
|
|
|
|
|
|
|
Module* makeLLVMModule();
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void MemoryTestHelper(int run) {
|
2014-03-06 06:51:42 +01:00
|
|
|
std::unique_ptr<Module> M(makeLLVMModule());
|
2009-06-29 20:49:09 +02:00
|
|
|
T *P = new T();
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager Passes;
|
2009-06-29 20:49:09 +02:00
|
|
|
Passes.add(P);
|
|
|
|
Passes.run(*M);
|
|
|
|
T::finishedOK(run);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void MemoryTestHelper(int run, int N) {
|
|
|
|
Module *M = makeLLVMModule();
|
|
|
|
T *P = new T();
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager Passes;
|
2009-06-29 20:49:09 +02:00
|
|
|
Passes.add(P);
|
|
|
|
Passes.run(*M);
|
|
|
|
T::finishedOK(run, N);
|
|
|
|
delete M;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PassManager, Memory) {
|
|
|
|
// SCC#1: test1->test2->test3->test1
|
|
|
|
// SCC#2: test4
|
|
|
|
// SCC#3: indirect call node
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Callgraph pass");
|
|
|
|
MemoryTestHelper<CGPass>(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Function pass");
|
|
|
|
MemoryTestHelper<FPass>(4);// 4 functions
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Loop pass");
|
|
|
|
MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Basic block pass");
|
|
|
|
MemoryTestHelper<BPass>(7, 4); //9 basic blocks
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PassManager, MemoryOnTheFly) {
|
|
|
|
Module *M = makeLLVMModule();
|
|
|
|
{
|
|
|
|
SCOPED_TRACE("Running OnTheFlyTest");
|
|
|
|
struct OnTheFlyTest *O = new OnTheFlyTest();
|
2015-02-13 11:01:29 +01:00
|
|
|
legacy::PassManager Passes;
|
2009-06-29 20:49:09 +02:00
|
|
|
Passes.add(O);
|
|
|
|
Passes.run(*M);
|
|
|
|
|
|
|
|
FPass::finishedOK(4);
|
|
|
|
}
|
|
|
|
delete M;
|
|
|
|
}
|
|
|
|
|
|
|
|
Module* makeLLVMModule() {
|
|
|
|
// Module Construction
|
2009-08-13 23:58:54 +02:00
|
|
|
Module* mod = new Module("test-mem", getGlobalContext());
|
2009-06-29 20:49:09 +02:00
|
|
|
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-"
|
2013-12-13 19:56:34 +01:00
|
|
|
"a:0:64-s:64:64-f80:128:128");
|
2009-06-29 20:49:09 +02:00
|
|
|
mod->setTargetTriple("x86_64-unknown-linux-gnu");
|
|
|
|
|
|
|
|
// Type Definitions
|
2011-07-12 16:06:48 +02:00
|
|
|
std::vector<Type*>FuncTy_0_args;
|
2009-06-29 20:49:09 +02:00
|
|
|
FunctionType* FuncTy_0 = FunctionType::get(
|
2009-08-13 23:58:54 +02:00
|
|
|
/*Result=*/IntegerType::get(getGlobalContext(), 32),
|
2009-06-29 20:49:09 +02:00
|
|
|
/*Params=*/FuncTy_0_args,
|
|
|
|
/*isVarArg=*/false);
|
|
|
|
|
2011-07-12 16:06:48 +02:00
|
|
|
std::vector<Type*>FuncTy_2_args;
|
2009-08-13 23:58:54 +02:00
|
|
|
FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
|
2009-06-29 20:49:09 +02:00
|
|
|
FunctionType* FuncTy_2 = FunctionType::get(
|
2009-08-13 23:58:54 +02:00
|
|
|
/*Result=*/Type::getVoidTy(getGlobalContext()),
|
2009-06-29 20:49:09 +02:00
|
|
|
/*Params=*/FuncTy_2_args,
|
|
|
|
/*isVarArg=*/false);
|
|
|
|
|
|
|
|
|
|
|
|
// Function Declarations
|
|
|
|
|
|
|
|
Function* func_test1 = Function::Create(
|
|
|
|
/*Type=*/FuncTy_0,
|
|
|
|
/*Linkage=*/GlobalValue::ExternalLinkage,
|
|
|
|
/*Name=*/"test1", mod);
|
|
|
|
func_test1->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet func_test1_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
func_test1->setAttributes(func_test1_PAL);
|
|
|
|
|
|
|
|
Function* func_test2 = Function::Create(
|
|
|
|
/*Type=*/FuncTy_0,
|
|
|
|
/*Linkage=*/GlobalValue::ExternalLinkage,
|
|
|
|
/*Name=*/"test2", mod);
|
|
|
|
func_test2->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet func_test2_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
func_test2->setAttributes(func_test2_PAL);
|
|
|
|
|
|
|
|
Function* func_test3 = Function::Create(
|
|
|
|
/*Type=*/FuncTy_0,
|
|
|
|
/*Linkage=*/GlobalValue::ExternalLinkage,
|
|
|
|
/*Name=*/"test3", mod);
|
|
|
|
func_test3->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet func_test3_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
func_test3->setAttributes(func_test3_PAL);
|
|
|
|
|
|
|
|
Function* func_test4 = Function::Create(
|
|
|
|
/*Type=*/FuncTy_2,
|
|
|
|
/*Linkage=*/GlobalValue::ExternalLinkage,
|
|
|
|
/*Name=*/"test4", mod);
|
|
|
|
func_test4->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
AttributeSet func_test4_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
func_test4->setAttributes(func_test4_PAL);
|
|
|
|
|
|
|
|
// Global Variable Declarations
|
|
|
|
|
|
|
|
|
|
|
|
// Constant Definitions
|
|
|
|
|
|
|
|
// Global Variable Definitions
|
|
|
|
|
|
|
|
// Function Definitions
|
|
|
|
|
|
|
|
// Function: test1 (func_test1)
|
|
|
|
{
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,nullptr);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
// Block entry (label_entry)
|
|
|
|
CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
|
|
|
|
int32_3->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
int32_3->setTailCall(false);AttributeSet int32_3_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
int32_3->setAttributes(int32_3_PAL);
|
|
|
|
|
2009-08-13 23:58:54 +02:00
|
|
|
ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function: test2 (func_test2)
|
|
|
|
{
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,nullptr);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
// Block entry (label_entry_5)
|
|
|
|
CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
|
|
|
|
int32_6->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
int32_6->setTailCall(false);AttributeSet int32_6_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
int32_6->setAttributes(int32_6_PAL);
|
|
|
|
|
2009-08-13 23:58:54 +02:00
|
|
|
ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function: test3 (func_test3)
|
|
|
|
{
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,nullptr);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
// Block entry (label_entry_8)
|
|
|
|
CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
|
|
|
|
int32_9->setCallingConv(CallingConv::C);
|
2012-12-08 00:16:57 +01:00
|
|
|
int32_9->setTailCall(false);AttributeSet int32_9_PAL;
|
2009-06-29 20:49:09 +02:00
|
|
|
int32_9->setAttributes(int32_9_PAL);
|
|
|
|
|
2009-08-13 23:58:54 +02:00
|
|
|
ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function: test4 (func_test4)
|
|
|
|
{
|
|
|
|
Function::arg_iterator args = func_test4->arg_begin();
|
2015-10-20 20:30:20 +02:00
|
|
|
Value *int1_f = &*args++;
|
2009-06-29 20:49:09 +02:00
|
|
|
int1_f->setName("f");
|
|
|
|
|
2014-06-09 00:29:17 +02:00
|
|
|
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);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
// Block entry (label_entry_11)
|
|
|
|
BranchInst::Create(label_bb, label_entry_11);
|
|
|
|
|
|
|
|
// Block bb (label_bb)
|
|
|
|
BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
|
|
|
|
|
|
|
|
// Block bb1 (label_bb1)
|
|
|
|
BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
|
|
|
|
|
|
|
|
// Block return (label_return)
|
2009-08-13 23:58:54 +02:00
|
|
|
ReturnInst::Create(getGlobalContext(), label_return);
|
2009-06-29 20:49:09 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 19:21:58 +02:00
|
|
|
|
|
|
|
INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
|
|
|
|
INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
|
2013-11-26 05:19:30 +01:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
|
2010-10-19 19:21:58 +02:00
|
|
|
INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
|
|
|
|
INITIALIZE_PASS(FPass, "fp","fp", false, false)
|
|
|
|
INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
|
2015-01-17 15:16:18 +01:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
2010-10-19 19:21:58 +02:00
|
|
|
INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
|
|
|
|
INITIALIZE_PASS(BPass, "bp","bp", false, false)
|