blob: 11841bdeac0dddaff59f30ec8248a662cfad705b [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
11// old names as well to ensure that the source-level compatibility wrapper
12// works for out-of-tree code that expects to include llvm/PassManager.h and
13// subclass the core pass classes.
14//
15//===----------------------------------------------------------------------===//
Torok Edwin24c78352009-06-29 18:49:09 +000016
Torok Edwin24c78352009-06-29 18:49:09 +000017#include "llvm/PassManager.h"
18#include "llvm/ADT/SmallVector.h"
Chandler Carruth839a98e2013-01-07 15:26:48 +000019#include "llvm/Analysis/CallGraphSCCPass.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000020#include "llvm/Analysis/LoopInfo.h"
21#include "llvm/Analysis/LoopPass.h"
Torok Edwin24c78352009-06-29 18:49:09 +000022#include "llvm/Analysis/Verifier.h"
23#include "llvm/Assembly/PrintModulePass.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000024#include "llvm/IR/BasicBlock.h"
25#include "llvm/IR/CallingConv.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/DerivedTypes.h"
29#include "llvm/IR/Function.h"
30#include "llvm/IR/GlobalVariable.h"
31#include "llvm/IR/InlineAsm.h"
32#include "llvm/IR/Instructions.h"
33#include "llvm/IR/LLVMContext.h"
34#include "llvm/IR/Module.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000035#include "llvm/Pass.h"
36#include "llvm/Support/MathExtras.h"
37#include "llvm/Support/raw_ostream.h"
Torok Edwin24c78352009-06-29 18:49:09 +000038#include "gtest/gtest.h"
39
Owen Anderson6c18d1a2010-10-19 17:21:58 +000040using namespace llvm;
41
Torok Edwin24c78352009-06-29 18:49:09 +000042namespace llvm {
Owen Anderson6c18d1a2010-10-19 17:21:58 +000043 void initializeModuleNDMPass(PassRegistry&);
44 void initializeFPassPass(PassRegistry&);
45 void initializeCGPassPass(PassRegistry&);
46 void initializeLPassPass(PassRegistry&);
47 void initializeBPassPass(PassRegistry&);
Duncan Sands6ae98632011-03-31 09:58:51 +000048
Torok Edwin24c78352009-06-29 18:49:09 +000049 namespace {
50 // ND = no deps
51 // NM = no modifications
52 struct ModuleNDNM: public ModulePass {
53 public:
54 static char run;
55 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000056 ModuleNDNM() : ModulePass(ID) { }
Torok Edwin24c78352009-06-29 18:49:09 +000057 virtual bool runOnModule(Module &M) {
58 run++;
59 return false;
60 }
61 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
62 AU.setPreservesAll();
63 }
64 };
65 char ModuleNDNM::ID=0;
66 char ModuleNDNM::run=0;
67
68 struct ModuleNDM : public ModulePass {
69 public:
70 static char run;
71 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000072 ModuleNDM() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000073 virtual bool runOnModule(Module &M) {
74 run++;
75 return true;
76 }
77 };
78 char ModuleNDM::ID=0;
79 char ModuleNDM::run=0;
Torok Edwin24c78352009-06-29 18:49:09 +000080
81 struct ModuleNDM2 : public ModulePass {
82 public:
83 static char run;
84 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000085 ModuleNDM2() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000086 virtual bool runOnModule(Module &M) {
87 run++;
88 return true;
89 }
90 };
91 char ModuleNDM2::ID=0;
92 char ModuleNDM2::run=0;
93
94 struct ModuleDNM : public ModulePass {
95 public:
96 static char run;
97 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000098 ModuleDNM() : ModulePass(ID) {
99 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
100 }
Torok Edwin24c78352009-06-29 18:49:09 +0000101 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000102 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000103 run++;
104 return false;
105 }
106 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
107 AU.addRequired<ModuleNDM>();
108 AU.setPreservesAll();
109 }
110 };
111 char ModuleDNM::ID=0;
112 char ModuleDNM::run=0;
113
114 template<typename P>
115 struct PassTestBase : public P {
116 protected:
117 static int runc;
118 static bool initialized;
119 static bool finalized;
120 int allocated;
121 void run() {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000122 EXPECT_TRUE(initialized);
123 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000124 EXPECT_EQ(0, allocated);
125 allocated++;
126 runc++;
127 }
128 public:
129 static char ID;
130 static void finishedOK(int run) {
131 EXPECT_GT(runc, 0);
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000132 EXPECT_TRUE(initialized);
133 EXPECT_TRUE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000134 EXPECT_EQ(run, runc);
135 }
Owen Andersona7aed182010-08-06 18:33:48 +0000136 PassTestBase() : P(ID), allocated(0) {
Torok Edwin24c78352009-06-29 18:49:09 +0000137 initialized = false;
138 finalized = false;
139 runc = 0;
140 }
141
142 virtual void releaseMemory() {
143 EXPECT_GT(runc, 0);
144 EXPECT_GT(allocated, 0);
145 allocated--;
146 }
147 };
148 template<typename P> char PassTestBase<P>::ID;
149 template<typename P> int PassTestBase<P>::runc;
150 template<typename P> bool PassTestBase<P>::initialized;
151 template<typename P> bool PassTestBase<P>::finalized;
152
153 template<typename T, typename P>
154 struct PassTest : public PassTestBase<P> {
155 public:
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000156#ifndef _MSC_VER // MSVC complains that Pass is not base class.
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000157 using llvm::Pass::doInitialization;
158 using llvm::Pass::doFinalization;
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000159#endif
Torok Edwin24c78352009-06-29 18:49:09 +0000160 virtual bool doInitialization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000161 EXPECT_FALSE(PassTestBase<P>::initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000162 PassTestBase<P>::initialized = true;
163 return false;
164 }
165 virtual bool doFinalization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000166 EXPECT_FALSE(PassTestBase<P>::finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000167 PassTestBase<P>::finalized = true;
168 EXPECT_EQ(0, PassTestBase<P>::allocated);
169 return false;
170 }
171 };
172
173 struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
174 public:
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000175 CGPass() {
176 initializeCGPassPass(*PassRegistry::getPassRegistry());
177 }
Chris Lattner4422d312010-04-16 22:42:17 +0000178 virtual bool runOnSCC(CallGraphSCC &SCMM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000179 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000180 run();
181 return false;
182 }
183 };
Torok Edwin24c78352009-06-29 18:49:09 +0000184
185 struct FPass : public PassTest<Module, FunctionPass> {
186 public:
187 virtual bool runOnFunction(Function &F) {
188 // FIXME: PR4112
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000189 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000190 run();
191 return false;
192 }
193 };
Torok Edwin24c78352009-06-29 18:49:09 +0000194
195 struct LPass : public PassTestBase<LoopPass> {
196 private:
197 static int initcount;
198 static int fincount;
199 public:
200 LPass() {
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000201 initializeLPassPass(*PassRegistry::getPassRegistry());
Torok Edwin24c78352009-06-29 18:49:09 +0000202 initcount = 0; fincount=0;
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000203 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000204 }
205 static void finishedOK(int run, int finalized) {
206 PassTestBase<LoopPass>::finishedOK(run);
207 EXPECT_EQ(run, initcount);
208 EXPECT_EQ(finalized, fincount);
209 }
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000210 using llvm::Pass::doInitialization;
211 using llvm::Pass::doFinalization;
Torok Edwin24c78352009-06-29 18:49:09 +0000212 virtual bool doInitialization(Loop* L, LPPassManager &LPM) {
213 initialized = true;
214 initcount++;
215 return false;
216 }
217 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000218 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000219 run();
220 return false;
221 }
222 virtual bool doFinalization() {
223 fincount++;
224 finalized = true;
225 return false;
226 }
227 };
228 int LPass::initcount=0;
229 int LPass::fincount=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000230
231 struct BPass : public PassTestBase<BasicBlockPass> {
232 private:
233 static int inited;
234 static int fin;
235 public:
236 static void finishedOK(int run, int N) {
237 PassTestBase<BasicBlockPass>::finishedOK(run);
238 EXPECT_EQ(inited, N);
239 EXPECT_EQ(fin, N);
240 }
241 BPass() {
242 inited = 0;
243 fin = 0;
244 }
245 virtual bool doInitialization(Module &M) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000246 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000247 initialized = true;
248 return false;
249 }
250 virtual bool doInitialization(Function &F) {
251 inited++;
252 return false;
253 }
254 virtual bool runOnBasicBlock(BasicBlock &BB) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000255 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000256 run();
257 return false;
258 }
259 virtual bool doFinalization(Function &F) {
260 fin++;
261 return false;
262 }
263 virtual bool doFinalization(Module &M) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000264 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000265 finalized = true;
266 EXPECT_EQ(0, allocated);
267 return false;
268 }
269 };
270 int BPass::inited=0;
271 int BPass::fin=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000272
273 struct OnTheFlyTest: public ModulePass {
274 public:
275 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000276 OnTheFlyTest() : ModulePass(ID) {
277 initializeFPassPass(*PassRegistry::getPassRegistry());
278 }
Torok Edwin24c78352009-06-29 18:49:09 +0000279 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000280 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000281 for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
282 Function &F = *I;
283 {
284 SCOPED_TRACE("Running on the fly function pass");
285 getAnalysis<FPass>(F);
286 }
287 }
288 return false;
289 }
290 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
291 AU.addRequired<FPass>();
292 }
293 };
294 char OnTheFlyTest::ID=0;
295
296 TEST(PassManager, RunOnce) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000297 Module M("test-once", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000298 struct ModuleNDNM *mNDNM = new ModuleNDNM();
299 struct ModuleDNM *mDNM = new ModuleDNM();
300 struct ModuleNDM *mNDM = new ModuleNDM();
301 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
302
303 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
304
305 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000306 Passes.add(new DataLayout(&M));
Torok Edwin24c78352009-06-29 18:49:09 +0000307 Passes.add(mNDM2);
308 Passes.add(mNDM);
309 Passes.add(mNDNM);
310 Passes.add(mDNM);
311
312 Passes.run(M);
313 // each pass must be run exactly once, since nothing invalidates them
314 EXPECT_EQ(1, mNDM->run);
315 EXPECT_EQ(1, mNDNM->run);
316 EXPECT_EQ(1, mDNM->run);
317 EXPECT_EQ(1, mNDM2->run);
318 }
319
320 TEST(PassManager, ReRun) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000321 Module M("test-rerun", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000322 struct ModuleNDNM *mNDNM = new ModuleNDNM();
323 struct ModuleDNM *mDNM = new ModuleDNM();
324 struct ModuleNDM *mNDM = new ModuleNDM();
325 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
326
327 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
328
329 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000330 Passes.add(new DataLayout(&M));
Torok Edwin24c78352009-06-29 18:49:09 +0000331 Passes.add(mNDM);
332 Passes.add(mNDNM);
333 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
334 Passes.add(mDNM);
335
336 Passes.run(M);
337 // Some passes must be rerun because a pass that modified the
Benjamin Kramerbde91762012-06-02 10:20:22 +0000338 // module/function was run in between
Torok Edwin24c78352009-06-29 18:49:09 +0000339 EXPECT_EQ(2, mNDM->run);
340 EXPECT_EQ(1, mNDNM->run);
341 EXPECT_EQ(1, mNDM2->run);
342 EXPECT_EQ(1, mDNM->run);
343 }
344
345 Module* makeLLVMModule();
346
347 template<typename T>
348 void MemoryTestHelper(int run) {
Jeffrey Yasskin61e710c2010-03-13 02:15:08 +0000349 OwningPtr<Module> M(makeLLVMModule());
Torok Edwin24c78352009-06-29 18:49:09 +0000350 T *P = new T();
351 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000352 Passes.add(new DataLayout(M.get()));
Torok Edwin24c78352009-06-29 18:49:09 +0000353 Passes.add(P);
354 Passes.run(*M);
355 T::finishedOK(run);
356 }
357
358 template<typename T>
359 void MemoryTestHelper(int run, int N) {
360 Module *M = makeLLVMModule();
361 T *P = new T();
362 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000363 Passes.add(new DataLayout(M));
Torok Edwin24c78352009-06-29 18:49:09 +0000364 Passes.add(P);
365 Passes.run(*M);
366 T::finishedOK(run, N);
367 delete M;
368 }
369
370 TEST(PassManager, Memory) {
371 // SCC#1: test1->test2->test3->test1
372 // SCC#2: test4
373 // SCC#3: indirect call node
374 {
375 SCOPED_TRACE("Callgraph pass");
376 MemoryTestHelper<CGPass>(3);
377 }
378
379 {
380 SCOPED_TRACE("Function pass");
381 MemoryTestHelper<FPass>(4);// 4 functions
382 }
383
384 {
385 SCOPED_TRACE("Loop pass");
386 MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
387 }
388 {
389 SCOPED_TRACE("Basic block pass");
390 MemoryTestHelper<BPass>(7, 4); //9 basic blocks
391 }
392
393 }
394
395 TEST(PassManager, MemoryOnTheFly) {
396 Module *M = makeLLVMModule();
397 {
398 SCOPED_TRACE("Running OnTheFlyTest");
399 struct OnTheFlyTest *O = new OnTheFlyTest();
400 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000401 Passes.add(new DataLayout(M));
Torok Edwin24c78352009-06-29 18:49:09 +0000402 Passes.add(O);
403 Passes.run(*M);
404
405 FPass::finishedOK(4);
406 }
407 delete M;
408 }
409
410 Module* makeLLVMModule() {
411 // Module Construction
Owen Anderson55f1c092009-08-13 21:58:54 +0000412 Module* mod = new Module("test-mem", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000413 mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
414 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
415 "a0:0:64-s0:64:64-f80:128:128");
416 mod->setTargetTriple("x86_64-unknown-linux-gnu");
417
418 // Type Definitions
Jay Foadb804a2b2011-07-12 14:06:48 +0000419 std::vector<Type*>FuncTy_0_args;
Torok Edwin24c78352009-06-29 18:49:09 +0000420 FunctionType* FuncTy_0 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000421 /*Result=*/IntegerType::get(getGlobalContext(), 32),
Torok Edwin24c78352009-06-29 18:49:09 +0000422 /*Params=*/FuncTy_0_args,
423 /*isVarArg=*/false);
424
Jay Foadb804a2b2011-07-12 14:06:48 +0000425 std::vector<Type*>FuncTy_2_args;
Owen Anderson55f1c092009-08-13 21:58:54 +0000426 FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
Torok Edwin24c78352009-06-29 18:49:09 +0000427 FunctionType* FuncTy_2 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000428 /*Result=*/Type::getVoidTy(getGlobalContext()),
Torok Edwin24c78352009-06-29 18:49:09 +0000429 /*Params=*/FuncTy_2_args,
430 /*isVarArg=*/false);
431
432
433 // Function Declarations
434
435 Function* func_test1 = Function::Create(
436 /*Type=*/FuncTy_0,
437 /*Linkage=*/GlobalValue::ExternalLinkage,
438 /*Name=*/"test1", mod);
439 func_test1->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000440 AttributeSet func_test1_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000441 func_test1->setAttributes(func_test1_PAL);
442
443 Function* func_test2 = Function::Create(
444 /*Type=*/FuncTy_0,
445 /*Linkage=*/GlobalValue::ExternalLinkage,
446 /*Name=*/"test2", mod);
447 func_test2->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000448 AttributeSet func_test2_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000449 func_test2->setAttributes(func_test2_PAL);
450
451 Function* func_test3 = Function::Create(
452 /*Type=*/FuncTy_0,
453 /*Linkage=*/GlobalValue::ExternalLinkage,
454 /*Name=*/"test3", mod);
455 func_test3->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000456 AttributeSet func_test3_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000457 func_test3->setAttributes(func_test3_PAL);
458
459 Function* func_test4 = Function::Create(
460 /*Type=*/FuncTy_2,
461 /*Linkage=*/GlobalValue::ExternalLinkage,
462 /*Name=*/"test4", mod);
463 func_test4->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000464 AttributeSet func_test4_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000465 func_test4->setAttributes(func_test4_PAL);
466
467 // Global Variable Declarations
468
469
470 // Constant Definitions
471
472 // Global Variable Definitions
473
474 // Function Definitions
475
476 // Function: test1 (func_test1)
477 {
478
Owen Anderson55f1c092009-08-13 21:58:54 +0000479 BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000480
481 // Block entry (label_entry)
482 CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
483 int32_3->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000484 int32_3->setTailCall(false);AttributeSet int32_3_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000485 int32_3->setAttributes(int32_3_PAL);
486
Owen Anderson55f1c092009-08-13 21:58:54 +0000487 ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
Torok Edwin24c78352009-06-29 18:49:09 +0000488
489 }
490
491 // Function: test2 (func_test2)
492 {
493
Owen Anderson55f1c092009-08-13 21:58:54 +0000494 BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000495
496 // Block entry (label_entry_5)
497 CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
498 int32_6->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000499 int32_6->setTailCall(false);AttributeSet int32_6_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000500 int32_6->setAttributes(int32_6_PAL);
501
Owen Anderson55f1c092009-08-13 21:58:54 +0000502 ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
Torok Edwin24c78352009-06-29 18:49:09 +0000503
504 }
505
506 // Function: test3 (func_test3)
507 {
508
Owen Anderson55f1c092009-08-13 21:58:54 +0000509 BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000510
511 // Block entry (label_entry_8)
512 CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
513 int32_9->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000514 int32_9->setTailCall(false);AttributeSet int32_9_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000515 int32_9->setAttributes(int32_9_PAL);
516
Owen Anderson55f1c092009-08-13 21:58:54 +0000517 ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
Torok Edwin24c78352009-06-29 18:49:09 +0000518
519 }
520
521 // Function: test4 (func_test4)
522 {
523 Function::arg_iterator args = func_test4->arg_begin();
524 Value* int1_f = args++;
525 int1_f->setName("f");
526
Owen Anderson55f1c092009-08-13 21:58:54 +0000527 BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0);
528 BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0);
529 BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0);
530 BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000531
532 // Block entry (label_entry_11)
533 BranchInst::Create(label_bb, label_entry_11);
534
535 // Block bb (label_bb)
536 BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
537
538 // Block bb1 (label_bb1)
539 BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
540
541 // Block return (label_return)
Owen Anderson55f1c092009-08-13 21:58:54 +0000542 ReturnInst::Create(getGlobalContext(), label_return);
Torok Edwin24c78352009-06-29 18:49:09 +0000543
544 }
545 return mod;
546 }
547
548 }
549}
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000550
551INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
552INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
Rafael Espindola6554e5a2013-10-31 03:03:55 +0000553INITIALIZE_PASS_DEPENDENCY(CallGraph)
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000554INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
555INITIALIZE_PASS(FPass, "fp","fp", false, false)
556INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
557INITIALIZE_PASS_DEPENDENCY(LoopInfo)
558INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
559INITIALIZE_PASS(BPass, "bp","bp", false, false)