blob: fe2bb2e2e577e65aba50f25d9a039b506f3e82b1 [file] [log] [blame]
Chandler Carruth7caea412013-11-09 12:26:54 +00001//===- llvm/unittest/IR/LegacyPassManager.cpp - Legacy PassManager tests --===//
Torok Edwin24c78352009-06-29 18:49:09 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chandler Carruth7caea412013-11-09 12:26:54 +00009//
10// This unit test exercises the legacy pass manager infrastructure. We use the
Chandler Carruth30d69c22015-02-13 10:01:29 +000011// old names as well to ensure that the source-level compatibility is preserved
12// where possible.
Chandler Carruth7caea412013-11-09 12:26:54 +000013//
14//===----------------------------------------------------------------------===//
Torok Edwin24c78352009-06-29 18:49:09 +000015
Chandler Carruth30d69c22015-02-13 10:01:29 +000016#include "llvm/IR/LegacyPassManager.h"
Torok Edwin24c78352009-06-29 18:49:09 +000017#include "llvm/ADT/SmallVector.h"
Chandler Carruth839a98e2013-01-07 15:26:48 +000018#include "llvm/Analysis/CallGraphSCCPass.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000019#include "llvm/Analysis/LoopInfo.h"
20#include "llvm/Analysis/LoopPass.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000021#include "llvm/IR/BasicBlock.h"
22#include "llvm/IR/CallingConv.h"
23#include "llvm/IR/Constants.h"
24#include "llvm/IR/DataLayout.h"
25#include "llvm/IR/DerivedTypes.h"
26#include "llvm/IR/Function.h"
27#include "llvm/IR/GlobalVariable.h"
Chandler Carruthb8ddc702014-01-12 11:10:32 +000028#include "llvm/IR/IRPrintingPasses.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000029#include "llvm/IR/InlineAsm.h"
30#include "llvm/IR/Instructions.h"
31#include "llvm/IR/LLVMContext.h"
32#include "llvm/IR/Module.h"
Chandler Carruth5ad5f152014-01-13 09:26:24 +000033#include "llvm/IR/Verifier.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000034#include "llvm/Pass.h"
35#include "llvm/Support/MathExtras.h"
36#include "llvm/Support/raw_ostream.h"
Torok Edwin24c78352009-06-29 18:49:09 +000037#include "gtest/gtest.h"
38
Owen Anderson6c18d1a2010-10-19 17:21:58 +000039using namespace llvm;
40
Torok Edwin24c78352009-06-29 18:49:09 +000041namespace llvm {
Owen Anderson6c18d1a2010-10-19 17:21:58 +000042 void initializeModuleNDMPass(PassRegistry&);
43 void initializeFPassPass(PassRegistry&);
44 void initializeCGPassPass(PassRegistry&);
45 void initializeLPassPass(PassRegistry&);
46 void initializeBPassPass(PassRegistry&);
Duncan Sands6ae98632011-03-31 09:58:51 +000047
Torok Edwin24c78352009-06-29 18:49:09 +000048 namespace {
49 // ND = no deps
50 // NM = no modifications
51 struct ModuleNDNM: public ModulePass {
52 public:
53 static char run;
54 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000055 ModuleNDNM() : ModulePass(ID) { }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +000056 bool runOnModule(Module &M) override {
Torok Edwin24c78352009-06-29 18:49:09 +000057 run++;
58 return false;
59 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +000060 void getAnalysisUsage(AnalysisUsage &AU) const override {
Torok Edwin24c78352009-06-29 18:49:09 +000061 AU.setPreservesAll();
62 }
63 };
64 char ModuleNDNM::ID=0;
65 char ModuleNDNM::run=0;
66
67 struct ModuleNDM : public ModulePass {
68 public:
69 static char run;
70 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000071 ModuleNDM() : ModulePass(ID) {}
Rafael Espindolad8bd91c2014-09-10 15:50:08 +000072 bool runOnModule(Module &M) override {
Torok Edwin24c78352009-06-29 18:49:09 +000073 run++;
74 return true;
75 }
76 };
77 char ModuleNDM::ID=0;
78 char ModuleNDM::run=0;
Torok Edwin24c78352009-06-29 18:49:09 +000079
80 struct ModuleNDM2 : public ModulePass {
81 public:
82 static char run;
83 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000084 ModuleNDM2() : ModulePass(ID) {}
Rafael Espindolad8bd91c2014-09-10 15:50:08 +000085 bool runOnModule(Module &M) override {
Torok Edwin24c78352009-06-29 18:49:09 +000086 run++;
87 return true;
88 }
89 };
90 char ModuleNDM2::ID=0;
91 char ModuleNDM2::run=0;
92
93 struct ModuleDNM : public ModulePass {
94 public:
95 static char run;
96 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000097 ModuleDNM() : ModulePass(ID) {
98 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
99 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000100 bool runOnModule(Module &M) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000101 run++;
102 return false;
103 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000104 void getAnalysisUsage(AnalysisUsage &AU) const override {
Torok Edwin24c78352009-06-29 18:49:09 +0000105 AU.addRequired<ModuleNDM>();
106 AU.setPreservesAll();
107 }
108 };
109 char ModuleDNM::ID=0;
110 char ModuleDNM::run=0;
111
112 template<typename P>
113 struct PassTestBase : public P {
114 protected:
115 static int runc;
116 static bool initialized;
117 static bool finalized;
118 int allocated;
119 void run() {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000120 EXPECT_TRUE(initialized);
121 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000122 EXPECT_EQ(0, allocated);
123 allocated++;
124 runc++;
125 }
126 public:
127 static char ID;
128 static void finishedOK(int run) {
129 EXPECT_GT(runc, 0);
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000130 EXPECT_TRUE(initialized);
131 EXPECT_TRUE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000132 EXPECT_EQ(run, runc);
133 }
Owen Andersona7aed182010-08-06 18:33:48 +0000134 PassTestBase() : P(ID), allocated(0) {
Torok Edwin24c78352009-06-29 18:49:09 +0000135 initialized = false;
136 finalized = false;
137 runc = 0;
138 }
139
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000140 void releaseMemory() override {
Torok Edwin24c78352009-06-29 18:49:09 +0000141 EXPECT_GT(runc, 0);
142 EXPECT_GT(allocated, 0);
143 allocated--;
144 }
145 };
146 template<typename P> char PassTestBase<P>::ID;
147 template<typename P> int PassTestBase<P>::runc;
148 template<typename P> bool PassTestBase<P>::initialized;
149 template<typename P> bool PassTestBase<P>::finalized;
150
151 template<typename T, typename P>
152 struct PassTest : public PassTestBase<P> {
153 public:
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000154#ifndef _MSC_VER // MSVC complains that Pass is not base class.
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000155 using llvm::Pass::doInitialization;
156 using llvm::Pass::doFinalization;
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000157#endif
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000158 bool doInitialization(T &t) override {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000159 EXPECT_FALSE(PassTestBase<P>::initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000160 PassTestBase<P>::initialized = true;
161 return false;
162 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000163 bool doFinalization(T &t) override {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000164 EXPECT_FALSE(PassTestBase<P>::finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000165 PassTestBase<P>::finalized = true;
166 EXPECT_EQ(0, PassTestBase<P>::allocated);
167 return false;
168 }
169 };
170
171 struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
172 public:
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000173 CGPass() {
174 initializeCGPassPass(*PassRegistry::getPassRegistry());
175 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000176 bool runOnSCC(CallGraphSCC &SCMM) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000177 run();
178 return false;
179 }
180 };
Torok Edwin24c78352009-06-29 18:49:09 +0000181
182 struct FPass : public PassTest<Module, FunctionPass> {
183 public:
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000184 bool runOnFunction(Function &F) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000185 // FIXME: PR4112
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000186 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000187 run();
188 return false;
189 }
190 };
Torok Edwin24c78352009-06-29 18:49:09 +0000191
192 struct LPass : public PassTestBase<LoopPass> {
193 private:
194 static int initcount;
195 static int fincount;
196 public:
197 LPass() {
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000198 initializeLPassPass(*PassRegistry::getPassRegistry());
Torok Edwin24c78352009-06-29 18:49:09 +0000199 initcount = 0; fincount=0;
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000200 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000201 }
202 static void finishedOK(int run, int finalized) {
203 PassTestBase<LoopPass>::finishedOK(run);
204 EXPECT_EQ(run, initcount);
205 EXPECT_EQ(finalized, fincount);
206 }
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000207 using llvm::Pass::doInitialization;
208 using llvm::Pass::doFinalization;
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000209 bool doInitialization(Loop* L, LPPassManager &LPM) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000210 initialized = true;
211 initcount++;
212 return false;
213 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000214 bool runOnLoop(Loop *L, LPPassManager &LPM) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000215 run();
216 return false;
217 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000218 bool doFinalization() override {
Torok Edwin24c78352009-06-29 18:49:09 +0000219 fincount++;
220 finalized = true;
221 return false;
222 }
223 };
224 int LPass::initcount=0;
225 int LPass::fincount=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000226
227 struct BPass : public PassTestBase<BasicBlockPass> {
228 private:
229 static int inited;
230 static int fin;
231 public:
232 static void finishedOK(int run, int N) {
233 PassTestBase<BasicBlockPass>::finishedOK(run);
234 EXPECT_EQ(inited, N);
235 EXPECT_EQ(fin, N);
236 }
237 BPass() {
238 inited = 0;
239 fin = 0;
240 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000241 bool doInitialization(Module &M) override {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000242 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000243 initialized = true;
244 return false;
245 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000246 bool doInitialization(Function &F) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000247 inited++;
248 return false;
249 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000250 bool runOnBasicBlock(BasicBlock &BB) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000251 run();
252 return false;
253 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000254 bool doFinalization(Function &F) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000255 fin++;
256 return false;
257 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000258 bool doFinalization(Module &M) override {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000259 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000260 finalized = true;
261 EXPECT_EQ(0, allocated);
262 return false;
263 }
264 };
265 int BPass::inited=0;
266 int BPass::fin=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000267
268 struct OnTheFlyTest: public ModulePass {
269 public:
270 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000271 OnTheFlyTest() : ModulePass(ID) {
272 initializeFPassPass(*PassRegistry::getPassRegistry());
273 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000274 bool runOnModule(Module &M) override {
Torok Edwin24c78352009-06-29 18:49:09 +0000275 for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
276 Function &F = *I;
277 {
278 SCOPED_TRACE("Running on the fly function pass");
279 getAnalysis<FPass>(F);
280 }
281 }
282 return false;
283 }
Rafael Espindolad8bd91c2014-09-10 15:50:08 +0000284 void getAnalysisUsage(AnalysisUsage &AU) const override {
Torok Edwin24c78352009-06-29 18:49:09 +0000285 AU.addRequired<FPass>();
286 }
287 };
288 char OnTheFlyTest::ID=0;
289
290 TEST(PassManager, RunOnce) {
Mehdi Amini03b42e42016-04-14 21:59:01 +0000291 LLVMContext Context;
292 Module M("test-once", Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000293 struct ModuleNDNM *mNDNM = new ModuleNDNM();
294 struct ModuleDNM *mDNM = new ModuleDNM();
295 struct ModuleNDM *mNDM = new ModuleNDM();
296 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
297
298 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
299
Chandler Carruth30d69c22015-02-13 10:01:29 +0000300 legacy::PassManager Passes;
Torok Edwin24c78352009-06-29 18:49:09 +0000301 Passes.add(mNDM2);
302 Passes.add(mNDM);
303 Passes.add(mNDNM);
304 Passes.add(mDNM);
305
306 Passes.run(M);
307 // each pass must be run exactly once, since nothing invalidates them
308 EXPECT_EQ(1, mNDM->run);
309 EXPECT_EQ(1, mNDNM->run);
310 EXPECT_EQ(1, mDNM->run);
311 EXPECT_EQ(1, mNDM2->run);
312 }
313
314 TEST(PassManager, ReRun) {
Mehdi Amini03b42e42016-04-14 21:59:01 +0000315 LLVMContext Context;
316 Module M("test-rerun", Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000317 struct ModuleNDNM *mNDNM = new ModuleNDNM();
318 struct ModuleDNM *mDNM = new ModuleDNM();
319 struct ModuleNDM *mNDM = new ModuleNDM();
320 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
321
322 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
323
Chandler Carruth30d69c22015-02-13 10:01:29 +0000324 legacy::PassManager Passes;
Torok Edwin24c78352009-06-29 18:49:09 +0000325 Passes.add(mNDM);
326 Passes.add(mNDNM);
327 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
328 Passes.add(mDNM);
329
330 Passes.run(M);
331 // Some passes must be rerun because a pass that modified the
Benjamin Kramerbde91762012-06-02 10:20:22 +0000332 // module/function was run in between
Torok Edwin24c78352009-06-29 18:49:09 +0000333 EXPECT_EQ(2, mNDM->run);
334 EXPECT_EQ(1, mNDNM->run);
335 EXPECT_EQ(1, mNDM2->run);
336 EXPECT_EQ(1, mDNM->run);
337 }
338
Mehdi Amini03b42e42016-04-14 21:59:01 +0000339 Module *makeLLVMModule(LLVMContext &Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000340
341 template<typename T>
342 void MemoryTestHelper(int run) {
Mehdi Amini03b42e42016-04-14 21:59:01 +0000343 LLVMContext Context;
344 std::unique_ptr<Module> M(makeLLVMModule(Context));
Torok Edwin24c78352009-06-29 18:49:09 +0000345 T *P = new T();
Chandler Carruth30d69c22015-02-13 10:01:29 +0000346 legacy::PassManager Passes;
Torok Edwin24c78352009-06-29 18:49:09 +0000347 Passes.add(P);
348 Passes.run(*M);
349 T::finishedOK(run);
350 }
351
352 template<typename T>
353 void MemoryTestHelper(int run, int N) {
Mehdi Amini03b42e42016-04-14 21:59:01 +0000354 LLVMContext Context;
355 Module *M = makeLLVMModule(Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000356 T *P = new T();
Chandler Carruth30d69c22015-02-13 10:01:29 +0000357 legacy::PassManager Passes;
Torok Edwin24c78352009-06-29 18:49:09 +0000358 Passes.add(P);
359 Passes.run(*M);
360 T::finishedOK(run, N);
361 delete M;
362 }
363
364 TEST(PassManager, Memory) {
365 // SCC#1: test1->test2->test3->test1
366 // SCC#2: test4
367 // SCC#3: indirect call node
368 {
369 SCOPED_TRACE("Callgraph pass");
370 MemoryTestHelper<CGPass>(3);
371 }
372
373 {
374 SCOPED_TRACE("Function pass");
375 MemoryTestHelper<FPass>(4);// 4 functions
376 }
377
378 {
379 SCOPED_TRACE("Loop pass");
380 MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
381 }
382 {
383 SCOPED_TRACE("Basic block pass");
384 MemoryTestHelper<BPass>(7, 4); //9 basic blocks
385 }
386
387 }
388
389 TEST(PassManager, MemoryOnTheFly) {
Mehdi Amini03b42e42016-04-14 21:59:01 +0000390 LLVMContext Context;
391 Module *M = makeLLVMModule(Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000392 {
393 SCOPED_TRACE("Running OnTheFlyTest");
394 struct OnTheFlyTest *O = new OnTheFlyTest();
Chandler Carruth30d69c22015-02-13 10:01:29 +0000395 legacy::PassManager Passes;
Torok Edwin24c78352009-06-29 18:49:09 +0000396 Passes.add(O);
397 Passes.run(*M);
398
399 FPass::finishedOK(4);
400 }
401 delete M;
402 }
403
Mehdi Amini03b42e42016-04-14 21:59:01 +0000404 Module *makeLLVMModule(LLVMContext &Context) {
Torok Edwin24c78352009-06-29 18:49:09 +0000405 // Module Construction
Mehdi Amini03b42e42016-04-14 21:59:01 +0000406 Module *mod = new Module("test-mem", Context);
Torok Edwin24c78352009-06-29 18:49:09 +0000407 mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
408 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
Rafael Espindolac6751622013-12-13 18:56:34 +0000409 "a:0:64-s:64:64-f80:128:128");
Torok Edwin24c78352009-06-29 18:49:09 +0000410 mod->setTargetTriple("x86_64-unknown-linux-gnu");
411
412 // Type Definitions
Jay Foadb804a2b2011-07-12 14:06:48 +0000413 std::vector<Type*>FuncTy_0_args;
Mehdi Amini03b42e42016-04-14 21:59:01 +0000414 FunctionType *FuncTy_0 = FunctionType::get(
415 /*Result=*/IntegerType::get(Context, 32),
416 /*Params=*/FuncTy_0_args,
417 /*isVarArg=*/false);
Torok Edwin24c78352009-06-29 18:49:09 +0000418
Jay Foadb804a2b2011-07-12 14:06:48 +0000419 std::vector<Type*>FuncTy_2_args;
Mehdi Amini03b42e42016-04-14 21:59:01 +0000420 FuncTy_2_args.push_back(IntegerType::get(Context, 1));
421 FunctionType *FuncTy_2 = FunctionType::get(
422 /*Result=*/Type::getVoidTy(Context),
423 /*Params=*/FuncTy_2_args,
424 /*isVarArg=*/false);
Torok Edwin24c78352009-06-29 18:49:09 +0000425
426 // Function Declarations
427
428 Function* func_test1 = Function::Create(
429 /*Type=*/FuncTy_0,
430 /*Linkage=*/GlobalValue::ExternalLinkage,
431 /*Name=*/"test1", mod);
432 func_test1->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000433 AttributeSet func_test1_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000434 func_test1->setAttributes(func_test1_PAL);
435
436 Function* func_test2 = Function::Create(
437 /*Type=*/FuncTy_0,
438 /*Linkage=*/GlobalValue::ExternalLinkage,
439 /*Name=*/"test2", mod);
440 func_test2->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000441 AttributeSet func_test2_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000442 func_test2->setAttributes(func_test2_PAL);
443
444 Function* func_test3 = Function::Create(
445 /*Type=*/FuncTy_0,
446 /*Linkage=*/GlobalValue::ExternalLinkage,
447 /*Name=*/"test3", mod);
448 func_test3->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000449 AttributeSet func_test3_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000450 func_test3->setAttributes(func_test3_PAL);
451
452 Function* func_test4 = Function::Create(
453 /*Type=*/FuncTy_2,
454 /*Linkage=*/GlobalValue::ExternalLinkage,
455 /*Name=*/"test4", mod);
456 func_test4->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000457 AttributeSet func_test4_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000458 func_test4->setAttributes(func_test4_PAL);
459
460 // Global Variable Declarations
461
462
463 // Constant Definitions
464
465 // Global Variable Definitions
466
467 // Function Definitions
468
469 // Function: test1 (func_test1)
470 {
471
Mehdi Amini03b42e42016-04-14 21:59:01 +0000472 BasicBlock *label_entry =
473 BasicBlock::Create(Context, "entry", func_test1, nullptr);
Torok Edwin24c78352009-06-29 18:49:09 +0000474
475 // Block entry (label_entry)
476 CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
477 int32_3->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000478 int32_3->setTailCall(false);AttributeSet int32_3_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000479 int32_3->setAttributes(int32_3_PAL);
480
Mehdi Amini03b42e42016-04-14 21:59:01 +0000481 ReturnInst::Create(Context, int32_3, label_entry);
Torok Edwin24c78352009-06-29 18:49:09 +0000482 }
483
484 // Function: test2 (func_test2)
485 {
486
Mehdi Amini03b42e42016-04-14 21:59:01 +0000487 BasicBlock *label_entry_5 =
488 BasicBlock::Create(Context, "entry", func_test2, nullptr);
Torok Edwin24c78352009-06-29 18:49:09 +0000489
490 // Block entry (label_entry_5)
491 CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
492 int32_6->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000493 int32_6->setTailCall(false);AttributeSet int32_6_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000494 int32_6->setAttributes(int32_6_PAL);
495
Mehdi Amini03b42e42016-04-14 21:59:01 +0000496 ReturnInst::Create(Context, int32_6, label_entry_5);
Torok Edwin24c78352009-06-29 18:49:09 +0000497 }
498
499 // Function: test3 (func_test3)
500 {
501
Mehdi Amini03b42e42016-04-14 21:59:01 +0000502 BasicBlock *label_entry_8 =
503 BasicBlock::Create(Context, "entry", func_test3, nullptr);
Torok Edwin24c78352009-06-29 18:49:09 +0000504
505 // Block entry (label_entry_8)
506 CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
507 int32_9->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000508 int32_9->setTailCall(false);AttributeSet int32_9_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000509 int32_9->setAttributes(int32_9_PAL);
510
Mehdi Amini03b42e42016-04-14 21:59:01 +0000511 ReturnInst::Create(Context, int32_9, label_entry_8);
Torok Edwin24c78352009-06-29 18:49:09 +0000512 }
513
514 // Function: test4 (func_test4)
515 {
516 Function::arg_iterator args = func_test4->arg_begin();
Duncan P. N. Exon Smithc8925b12015-10-20 18:30:20 +0000517 Value *int1_f = &*args++;
Torok Edwin24c78352009-06-29 18:49:09 +0000518 int1_f->setName("f");
519
Mehdi Amini03b42e42016-04-14 21:59:01 +0000520 BasicBlock *label_entry_11 =
521 BasicBlock::Create(Context, "entry", func_test4, nullptr);
522 BasicBlock *label_bb =
523 BasicBlock::Create(Context, "bb", func_test4, nullptr);
524 BasicBlock *label_bb1 =
525 BasicBlock::Create(Context, "bb1", func_test4, nullptr);
526 BasicBlock *label_return =
527 BasicBlock::Create(Context, "return", func_test4, nullptr);
Torok Edwin24c78352009-06-29 18:49:09 +0000528
529 // Block entry (label_entry_11)
530 BranchInst::Create(label_bb, label_entry_11);
531
532 // Block bb (label_bb)
533 BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
534
535 // Block bb1 (label_bb1)
536 BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
537
538 // Block return (label_return)
Mehdi Amini03b42e42016-04-14 21:59:01 +0000539 ReturnInst::Create(Context, label_return);
Torok Edwin24c78352009-06-29 18:49:09 +0000540 }
541 return mod;
542 }
543
544 }
545}
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000546
547INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
548INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
Chandler Carruth6378cf52013-11-26 04:19:30 +0000549INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000550INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
551INITIALIZE_PASS(FPass, "fp","fp", false, false)
552INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
Chandler Carruth4f8f3072015-01-17 14:16:18 +0000553INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000554INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
555INITIALIZE_PASS(BPass, "bp","bp", false, false)