blob: 6cfc0369a42a386f3d071308b8d4341f221908c9 [file] [log] [blame]
Torok Edwin24c78352009-06-29 18:49:09 +00001//===- llvm/unittest/VMCore/PassManager.cpp - Constants unit tests ------===//
2//
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//===----------------------------------------------------------------------===//
9
Torok Edwin24c78352009-06-29 18:49:09 +000010#include "llvm/PassManager.h"
11#include "llvm/ADT/SmallVector.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000012#include "llvm/Analysis/LoopInfo.h"
13#include "llvm/Analysis/LoopPass.h"
Torok Edwin24c78352009-06-29 18:49:09 +000014#include "llvm/Analysis/Verifier.h"
15#include "llvm/Assembly/PrintModulePass.h"
Chandler Carruth130cec22012-12-04 10:23:08 +000016#include "llvm/BasicBlock.h"
17#include "llvm/CallGraphSCCPass.h"
18#include "llvm/CallingConv.h"
19#include "llvm/Constants.h"
20#include "llvm/DataLayout.h"
21#include "llvm/DerivedTypes.h"
22#include "llvm/Function.h"
23#include "llvm/GlobalVariable.h"
24#include "llvm/InlineAsm.h"
25#include "llvm/Instructions.h"
26#include "llvm/LLVMContext.h"
27#include "llvm/Module.h"
28#include "llvm/Pass.h"
29#include "llvm/Support/MathExtras.h"
30#include "llvm/Support/raw_ostream.h"
31#include "llvm/Support/raw_ostream.h"
Torok Edwin24c78352009-06-29 18:49:09 +000032#include "gtest/gtest.h"
33
Owen Anderson6c18d1a2010-10-19 17:21:58 +000034using namespace llvm;
35
Torok Edwin24c78352009-06-29 18:49:09 +000036namespace llvm {
Owen Anderson6c18d1a2010-10-19 17:21:58 +000037 void initializeModuleNDMPass(PassRegistry&);
38 void initializeFPassPass(PassRegistry&);
39 void initializeCGPassPass(PassRegistry&);
40 void initializeLPassPass(PassRegistry&);
41 void initializeBPassPass(PassRegistry&);
Duncan Sands6ae98632011-03-31 09:58:51 +000042
Torok Edwin24c78352009-06-29 18:49:09 +000043 namespace {
44 // ND = no deps
45 // NM = no modifications
46 struct ModuleNDNM: public ModulePass {
47 public:
48 static char run;
49 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000050 ModuleNDNM() : ModulePass(ID) { }
Torok Edwin24c78352009-06-29 18:49:09 +000051 virtual bool runOnModule(Module &M) {
52 run++;
53 return false;
54 }
55 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
56 AU.setPreservesAll();
57 }
58 };
59 char ModuleNDNM::ID=0;
60 char ModuleNDNM::run=0;
61
62 struct ModuleNDM : public ModulePass {
63 public:
64 static char run;
65 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000066 ModuleNDM() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000067 virtual bool runOnModule(Module &M) {
68 run++;
69 return true;
70 }
71 };
72 char ModuleNDM::ID=0;
73 char ModuleNDM::run=0;
Torok Edwin24c78352009-06-29 18:49:09 +000074
75 struct ModuleNDM2 : public ModulePass {
76 public:
77 static char run;
78 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000079 ModuleNDM2() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000080 virtual bool runOnModule(Module &M) {
81 run++;
82 return true;
83 }
84 };
85 char ModuleNDM2::ID=0;
86 char ModuleNDM2::run=0;
87
88 struct ModuleDNM : public ModulePass {
89 public:
90 static char run;
91 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000092 ModuleDNM() : ModulePass(ID) {
93 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
94 }
Torok Edwin24c78352009-06-29 18:49:09 +000095 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +000096 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +000097 run++;
98 return false;
99 }
100 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
101 AU.addRequired<ModuleNDM>();
102 AU.setPreservesAll();
103 }
104 };
105 char ModuleDNM::ID=0;
106 char ModuleDNM::run=0;
107
108 template<typename P>
109 struct PassTestBase : public P {
110 protected:
111 static int runc;
112 static bool initialized;
113 static bool finalized;
114 int allocated;
115 void run() {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000116 EXPECT_TRUE(initialized);
117 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000118 EXPECT_EQ(0, allocated);
119 allocated++;
120 runc++;
121 }
122 public:
123 static char ID;
124 static void finishedOK(int run) {
125 EXPECT_GT(runc, 0);
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000126 EXPECT_TRUE(initialized);
127 EXPECT_TRUE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000128 EXPECT_EQ(run, runc);
129 }
Owen Andersona7aed182010-08-06 18:33:48 +0000130 PassTestBase() : P(ID), allocated(0) {
Torok Edwin24c78352009-06-29 18:49:09 +0000131 initialized = false;
132 finalized = false;
133 runc = 0;
134 }
135
136 virtual void releaseMemory() {
137 EXPECT_GT(runc, 0);
138 EXPECT_GT(allocated, 0);
139 allocated--;
140 }
141 };
142 template<typename P> char PassTestBase<P>::ID;
143 template<typename P> int PassTestBase<P>::runc;
144 template<typename P> bool PassTestBase<P>::initialized;
145 template<typename P> bool PassTestBase<P>::finalized;
146
147 template<typename T, typename P>
148 struct PassTest : public PassTestBase<P> {
149 public:
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000150#ifndef _MSC_VER // MSVC complains that Pass is not base class.
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000151 using llvm::Pass::doInitialization;
152 using llvm::Pass::doFinalization;
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000153#endif
Torok Edwin24c78352009-06-29 18:49:09 +0000154 virtual bool doInitialization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000155 EXPECT_FALSE(PassTestBase<P>::initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000156 PassTestBase<P>::initialized = true;
157 return false;
158 }
159 virtual bool doFinalization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000160 EXPECT_FALSE(PassTestBase<P>::finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000161 PassTestBase<P>::finalized = true;
162 EXPECT_EQ(0, PassTestBase<P>::allocated);
163 return false;
164 }
165 };
166
167 struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
168 public:
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000169 CGPass() {
170 initializeCGPassPass(*PassRegistry::getPassRegistry());
171 }
Chris Lattner4422d312010-04-16 22:42:17 +0000172 virtual bool runOnSCC(CallGraphSCC &SCMM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000173 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000174 run();
175 return false;
176 }
177 };
Torok Edwin24c78352009-06-29 18:49:09 +0000178
179 struct FPass : public PassTest<Module, FunctionPass> {
180 public:
181 virtual bool runOnFunction(Function &F) {
182 // FIXME: PR4112
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000183 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000184 run();
185 return false;
186 }
187 };
Torok Edwin24c78352009-06-29 18:49:09 +0000188
189 struct LPass : public PassTestBase<LoopPass> {
190 private:
191 static int initcount;
192 static int fincount;
193 public:
194 LPass() {
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000195 initializeLPassPass(*PassRegistry::getPassRegistry());
Torok Edwin24c78352009-06-29 18:49:09 +0000196 initcount = 0; fincount=0;
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000197 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000198 }
199 static void finishedOK(int run, int finalized) {
200 PassTestBase<LoopPass>::finishedOK(run);
201 EXPECT_EQ(run, initcount);
202 EXPECT_EQ(finalized, fincount);
203 }
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000204 using llvm::Pass::doInitialization;
205 using llvm::Pass::doFinalization;
Torok Edwin24c78352009-06-29 18:49:09 +0000206 virtual bool doInitialization(Loop* L, LPPassManager &LPM) {
207 initialized = true;
208 initcount++;
209 return false;
210 }
211 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000212 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000213 run();
214 return false;
215 }
216 virtual bool doFinalization() {
217 fincount++;
218 finalized = true;
219 return false;
220 }
221 };
222 int LPass::initcount=0;
223 int LPass::fincount=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000224
225 struct BPass : public PassTestBase<BasicBlockPass> {
226 private:
227 static int inited;
228 static int fin;
229 public:
230 static void finishedOK(int run, int N) {
231 PassTestBase<BasicBlockPass>::finishedOK(run);
232 EXPECT_EQ(inited, N);
233 EXPECT_EQ(fin, N);
234 }
235 BPass() {
236 inited = 0;
237 fin = 0;
238 }
239 virtual bool doInitialization(Module &M) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000240 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000241 initialized = true;
242 return false;
243 }
244 virtual bool doInitialization(Function &F) {
245 inited++;
246 return false;
247 }
248 virtual bool runOnBasicBlock(BasicBlock &BB) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000249 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000250 run();
251 return false;
252 }
253 virtual bool doFinalization(Function &F) {
254 fin++;
255 return false;
256 }
257 virtual bool doFinalization(Module &M) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000258 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000259 finalized = true;
260 EXPECT_EQ(0, allocated);
261 return false;
262 }
263 };
264 int BPass::inited=0;
265 int BPass::fin=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000266
267 struct OnTheFlyTest: public ModulePass {
268 public:
269 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000270 OnTheFlyTest() : ModulePass(ID) {
271 initializeFPassPass(*PassRegistry::getPassRegistry());
272 }
Torok Edwin24c78352009-06-29 18:49:09 +0000273 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000274 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
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 }
284 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
285 AU.addRequired<FPass>();
286 }
287 };
288 char OnTheFlyTest::ID=0;
289
290 TEST(PassManager, RunOnce) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000291 Module M("test-once", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000292 struct ModuleNDNM *mNDNM = new ModuleNDNM();
293 struct ModuleDNM *mDNM = new ModuleDNM();
294 struct ModuleNDM *mNDM = new ModuleNDM();
295 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
296
297 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
298
299 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000300 Passes.add(new DataLayout(&M));
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) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000315 Module M("test-rerun", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000316 struct ModuleNDNM *mNDNM = new ModuleNDNM();
317 struct ModuleDNM *mDNM = new ModuleDNM();
318 struct ModuleNDM *mNDM = new ModuleNDM();
319 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
320
321 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
322
323 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000324 Passes.add(new DataLayout(&M));
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
339 Module* makeLLVMModule();
340
341 template<typename T>
342 void MemoryTestHelper(int run) {
Jeffrey Yasskin61e710c2010-03-13 02:15:08 +0000343 OwningPtr<Module> M(makeLLVMModule());
Torok Edwin24c78352009-06-29 18:49:09 +0000344 T *P = new T();
345 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000346 Passes.add(new DataLayout(M.get()));
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) {
354 Module *M = makeLLVMModule();
355 T *P = new T();
356 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000357 Passes.add(new DataLayout(M));
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) {
390 Module *M = makeLLVMModule();
391 {
392 SCOPED_TRACE("Running OnTheFlyTest");
393 struct OnTheFlyTest *O = new OnTheFlyTest();
394 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000395 Passes.add(new DataLayout(M));
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
404 Module* makeLLVMModule() {
405 // Module Construction
Owen Anderson55f1c092009-08-13 21:58:54 +0000406 Module* mod = new Module("test-mem", getGlobalContext());
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-"
409 "a0:0:64-s0:64:64-f80:128:128");
410 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;
Torok Edwin24c78352009-06-29 18:49:09 +0000414 FunctionType* FuncTy_0 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000415 /*Result=*/IntegerType::get(getGlobalContext(), 32),
Torok Edwin24c78352009-06-29 18:49:09 +0000416 /*Params=*/FuncTy_0_args,
417 /*isVarArg=*/false);
418
Jay Foadb804a2b2011-07-12 14:06:48 +0000419 std::vector<Type*>FuncTy_2_args;
Owen Anderson55f1c092009-08-13 21:58:54 +0000420 FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
Torok Edwin24c78352009-06-29 18:49:09 +0000421 FunctionType* FuncTy_2 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000422 /*Result=*/Type::getVoidTy(getGlobalContext()),
Torok Edwin24c78352009-06-29 18:49:09 +0000423 /*Params=*/FuncTy_2_args,
424 /*isVarArg=*/false);
425
426
427 // Function Declarations
428
429 Function* func_test1 = Function::Create(
430 /*Type=*/FuncTy_0,
431 /*Linkage=*/GlobalValue::ExternalLinkage,
432 /*Name=*/"test1", mod);
433 func_test1->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000434 AttributeSet func_test1_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000435 func_test1->setAttributes(func_test1_PAL);
436
437 Function* func_test2 = Function::Create(
438 /*Type=*/FuncTy_0,
439 /*Linkage=*/GlobalValue::ExternalLinkage,
440 /*Name=*/"test2", mod);
441 func_test2->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000442 AttributeSet func_test2_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000443 func_test2->setAttributes(func_test2_PAL);
444
445 Function* func_test3 = Function::Create(
446 /*Type=*/FuncTy_0,
447 /*Linkage=*/GlobalValue::ExternalLinkage,
448 /*Name=*/"test3", mod);
449 func_test3->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000450 AttributeSet func_test3_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000451 func_test3->setAttributes(func_test3_PAL);
452
453 Function* func_test4 = Function::Create(
454 /*Type=*/FuncTy_2,
455 /*Linkage=*/GlobalValue::ExternalLinkage,
456 /*Name=*/"test4", mod);
457 func_test4->setCallingConv(CallingConv::C);
Bill Wendlinge94d8432012-12-07 23:16:57 +0000458 AttributeSet func_test4_PAL;
Torok Edwin24c78352009-06-29 18:49:09 +0000459 func_test4->setAttributes(func_test4_PAL);
460
461 // Global Variable Declarations
462
463
464 // Constant Definitions
465
466 // Global Variable Definitions
467
468 // Function Definitions
469
470 // Function: test1 (func_test1)
471 {
472
Owen Anderson55f1c092009-08-13 21:58:54 +0000473 BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0);
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
Owen Anderson55f1c092009-08-13 21:58:54 +0000481 ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
Torok Edwin24c78352009-06-29 18:49:09 +0000482
483 }
484
485 // Function: test2 (func_test2)
486 {
487
Owen Anderson55f1c092009-08-13 21:58:54 +0000488 BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0);
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
Owen Anderson55f1c092009-08-13 21:58:54 +0000496 ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
Torok Edwin24c78352009-06-29 18:49:09 +0000497
498 }
499
500 // Function: test3 (func_test3)
501 {
502
Owen Anderson55f1c092009-08-13 21:58:54 +0000503 BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0);
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
Owen Anderson55f1c092009-08-13 21:58:54 +0000511 ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
Torok Edwin24c78352009-06-29 18:49:09 +0000512
513 }
514
515 // Function: test4 (func_test4)
516 {
517 Function::arg_iterator args = func_test4->arg_begin();
518 Value* int1_f = args++;
519 int1_f->setName("f");
520
Owen Anderson55f1c092009-08-13 21:58:54 +0000521 BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0);
522 BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0);
523 BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0);
524 BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000525
526 // Block entry (label_entry_11)
527 BranchInst::Create(label_bb, label_entry_11);
528
529 // Block bb (label_bb)
530 BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
531
532 // Block bb1 (label_bb1)
533 BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
534
535 // Block return (label_return)
Owen Anderson55f1c092009-08-13 21:58:54 +0000536 ReturnInst::Create(getGlobalContext(), label_return);
Torok Edwin24c78352009-06-29 18:49:09 +0000537
538 }
539 return mod;
540 }
541
542 }
543}
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000544
545INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
546INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
547INITIALIZE_AG_DEPENDENCY(CallGraph)
548INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
549INITIALIZE_PASS(FPass, "fp","fp", false, false)
550INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
551INITIALIZE_PASS_DEPENDENCY(LoopInfo)
552INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
553INITIALIZE_PASS(BPass, "bp","bp", false, false)