blob: b5015d16ce7eff6d2974170427a0fbef58961010 [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
10#include "llvm/Module.h"
Owen Anderson8bc174a2009-07-01 18:14:20 +000011#include "llvm/LLVMContext.h"
Torok Edwin24c78352009-06-29 18:49:09 +000012#include "llvm/PassManager.h"
13#include "llvm/Analysis/LoopInfo.h"
14#include "llvm/Pass.h"
15#include "llvm/Analysis/LoopPass.h"
16#include "llvm/CallGraphSCCPass.h"
Micah Villmow9cfc13d2012-10-08 16:39:34 +000017#include "llvm/DataLayout.h"
Torok Edwin24c78352009-06-29 18:49:09 +000018#include "llvm/Support/raw_ostream.h"
19#include "llvm/DerivedTypes.h"
20#include "llvm/Constants.h"
21#include "llvm/GlobalVariable.h"
22#include "llvm/Function.h"
23#include "llvm/CallingConv.h"
24#include "llvm/BasicBlock.h"
25#include "llvm/Instructions.h"
26#include "llvm/InlineAsm.h"
27#include "llvm/Support/MathExtras.h"
28#include "llvm/Support/raw_ostream.h"
29#include "llvm/PassManager.h"
30#include "llvm/ADT/SmallVector.h"
31#include "llvm/Analysis/Verifier.h"
32#include "llvm/Assembly/PrintModulePass.h"
33#include "gtest/gtest.h"
34
Owen Anderson6c18d1a2010-10-19 17:21:58 +000035using namespace llvm;
36
Torok Edwin24c78352009-06-29 18:49:09 +000037namespace llvm {
Owen Anderson6c18d1a2010-10-19 17:21:58 +000038 void initializeModuleNDMPass(PassRegistry&);
39 void initializeFPassPass(PassRegistry&);
40 void initializeCGPassPass(PassRegistry&);
41 void initializeLPassPass(PassRegistry&);
42 void initializeBPassPass(PassRegistry&);
Duncan Sands6ae98632011-03-31 09:58:51 +000043
Torok Edwin24c78352009-06-29 18:49:09 +000044 namespace {
45 // ND = no deps
46 // NM = no modifications
47 struct ModuleNDNM: public ModulePass {
48 public:
49 static char run;
50 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000051 ModuleNDNM() : ModulePass(ID) { }
Torok Edwin24c78352009-06-29 18:49:09 +000052 virtual bool runOnModule(Module &M) {
53 run++;
54 return false;
55 }
56 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
57 AU.setPreservesAll();
58 }
59 };
60 char ModuleNDNM::ID=0;
61 char ModuleNDNM::run=0;
62
63 struct ModuleNDM : public ModulePass {
64 public:
65 static char run;
66 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000067 ModuleNDM() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000068 virtual bool runOnModule(Module &M) {
69 run++;
70 return true;
71 }
72 };
73 char ModuleNDM::ID=0;
74 char ModuleNDM::run=0;
Torok Edwin24c78352009-06-29 18:49:09 +000075
76 struct ModuleNDM2 : public ModulePass {
77 public:
78 static char run;
79 static char ID;
Owen Andersona7aed182010-08-06 18:33:48 +000080 ModuleNDM2() : ModulePass(ID) {}
Torok Edwin24c78352009-06-29 18:49:09 +000081 virtual bool runOnModule(Module &M) {
82 run++;
83 return true;
84 }
85 };
86 char ModuleNDM2::ID=0;
87 char ModuleNDM2::run=0;
88
89 struct ModuleDNM : public ModulePass {
90 public:
91 static char run;
92 static char ID;
Owen Anderson6c18d1a2010-10-19 17:21:58 +000093 ModuleDNM() : ModulePass(ID) {
94 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
95 }
Torok Edwin24c78352009-06-29 18:49:09 +000096 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +000097 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +000098 run++;
99 return false;
100 }
101 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
102 AU.addRequired<ModuleNDM>();
103 AU.setPreservesAll();
104 }
105 };
106 char ModuleDNM::ID=0;
107 char ModuleDNM::run=0;
108
109 template<typename P>
110 struct PassTestBase : public P {
111 protected:
112 static int runc;
113 static bool initialized;
114 static bool finalized;
115 int allocated;
116 void run() {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000117 EXPECT_TRUE(initialized);
118 EXPECT_FALSE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000119 EXPECT_EQ(0, allocated);
120 allocated++;
121 runc++;
122 }
123 public:
124 static char ID;
125 static void finishedOK(int run) {
126 EXPECT_GT(runc, 0);
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000127 EXPECT_TRUE(initialized);
128 EXPECT_TRUE(finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000129 EXPECT_EQ(run, runc);
130 }
Owen Andersona7aed182010-08-06 18:33:48 +0000131 PassTestBase() : P(ID), allocated(0) {
Torok Edwin24c78352009-06-29 18:49:09 +0000132 initialized = false;
133 finalized = false;
134 runc = 0;
135 }
136
137 virtual void releaseMemory() {
138 EXPECT_GT(runc, 0);
139 EXPECT_GT(allocated, 0);
140 allocated--;
141 }
142 };
143 template<typename P> char PassTestBase<P>::ID;
144 template<typename P> int PassTestBase<P>::runc;
145 template<typename P> bool PassTestBase<P>::initialized;
146 template<typename P> bool PassTestBase<P>::finalized;
147
148 template<typename T, typename P>
149 struct PassTest : public PassTestBase<P> {
150 public:
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000151#ifndef _MSC_VER // MSVC complains that Pass is not base class.
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000152 using llvm::Pass::doInitialization;
153 using llvm::Pass::doFinalization;
NAKAMURA Takumi0e9acc92012-12-04 07:25:24 +0000154#endif
Torok Edwin24c78352009-06-29 18:49:09 +0000155 virtual bool doInitialization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000156 EXPECT_FALSE(PassTestBase<P>::initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000157 PassTestBase<P>::initialized = true;
158 return false;
159 }
160 virtual bool doFinalization(T &t) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000161 EXPECT_FALSE(PassTestBase<P>::finalized);
Torok Edwin24c78352009-06-29 18:49:09 +0000162 PassTestBase<P>::finalized = true;
163 EXPECT_EQ(0, PassTestBase<P>::allocated);
164 return false;
165 }
166 };
167
168 struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
169 public:
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000170 CGPass() {
171 initializeCGPassPass(*PassRegistry::getPassRegistry());
172 }
Chris Lattner4422d312010-04-16 22:42:17 +0000173 virtual bool runOnSCC(CallGraphSCC &SCMM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000174 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000175 run();
176 return false;
177 }
178 };
Torok Edwin24c78352009-06-29 18:49:09 +0000179
180 struct FPass : public PassTest<Module, FunctionPass> {
181 public:
182 virtual bool runOnFunction(Function &F) {
183 // FIXME: PR4112
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000184 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000185 run();
186 return false;
187 }
188 };
Torok Edwin24c78352009-06-29 18:49:09 +0000189
190 struct LPass : public PassTestBase<LoopPass> {
191 private:
192 static int initcount;
193 static int fincount;
194 public:
195 LPass() {
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000196 initializeLPassPass(*PassRegistry::getPassRegistry());
Torok Edwin24c78352009-06-29 18:49:09 +0000197 initcount = 0; fincount=0;
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000198 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000199 }
200 static void finishedOK(int run, int finalized) {
201 PassTestBase<LoopPass>::finishedOK(run);
202 EXPECT_EQ(run, initcount);
203 EXPECT_EQ(finalized, fincount);
204 }
Matt Beaumont-Gayabfc4462012-12-04 05:41:27 +0000205 using llvm::Pass::doInitialization;
206 using llvm::Pass::doFinalization;
Torok Edwin24c78352009-06-29 18:49:09 +0000207 virtual bool doInitialization(Loop* L, LPPassManager &LPM) {
208 initialized = true;
209 initcount++;
210 return false;
211 }
212 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000213 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000214 run();
215 return false;
216 }
217 virtual bool doFinalization() {
218 fincount++;
219 finalized = true;
220 return false;
221 }
222 };
223 int LPass::initcount=0;
224 int LPass::fincount=0;
Torok Edwin24c78352009-06-29 18:49:09 +0000225
226 struct BPass : public PassTestBase<BasicBlockPass> {
227 private:
228 static int inited;
229 static int fin;
230 public:
231 static void finishedOK(int run, int N) {
232 PassTestBase<BasicBlockPass>::finishedOK(run);
233 EXPECT_EQ(inited, N);
234 EXPECT_EQ(fin, N);
235 }
236 BPass() {
237 inited = 0;
238 fin = 0;
239 }
240 virtual bool doInitialization(Module &M) {
Chandler Carruthbc3e8a72010-07-13 17:28:05 +0000241 EXPECT_FALSE(initialized);
Torok Edwin24c78352009-06-29 18:49:09 +0000242 initialized = true;
243 return false;
244 }
245 virtual bool doInitialization(Function &F) {
246 inited++;
247 return false;
248 }
249 virtual bool runOnBasicBlock(BasicBlock &BB) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000250 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000251 run();
252 return false;
253 }
254 virtual bool doFinalization(Function &F) {
255 fin++;
256 return false;
257 }
258 virtual bool doFinalization(Module &M) {
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 }
Torok Edwin24c78352009-06-29 18:49:09 +0000274 virtual bool runOnModule(Module &M) {
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000275 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin24c78352009-06-29 18:49:09 +0000276 for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
277 Function &F = *I;
278 {
279 SCOPED_TRACE("Running on the fly function pass");
280 getAnalysis<FPass>(F);
281 }
282 }
283 return false;
284 }
285 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
286 AU.addRequired<FPass>();
287 }
288 };
289 char OnTheFlyTest::ID=0;
290
291 TEST(PassManager, RunOnce) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000292 Module M("test-once", getGlobalContext());
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
300 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000301 Passes.add(new DataLayout(&M));
Torok Edwin24c78352009-06-29 18:49:09 +0000302 Passes.add(mNDM2);
303 Passes.add(mNDM);
304 Passes.add(mNDNM);
305 Passes.add(mDNM);
306
307 Passes.run(M);
308 // each pass must be run exactly once, since nothing invalidates them
309 EXPECT_EQ(1, mNDM->run);
310 EXPECT_EQ(1, mNDNM->run);
311 EXPECT_EQ(1, mDNM->run);
312 EXPECT_EQ(1, mNDM2->run);
313 }
314
315 TEST(PassManager, ReRun) {
Owen Anderson55f1c092009-08-13 21:58:54 +0000316 Module M("test-rerun", getGlobalContext());
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
324 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000325 Passes.add(new DataLayout(&M));
Torok Edwin24c78352009-06-29 18:49:09 +0000326 Passes.add(mNDM);
327 Passes.add(mNDNM);
328 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
329 Passes.add(mDNM);
330
331 Passes.run(M);
332 // Some passes must be rerun because a pass that modified the
Benjamin Kramerbde91762012-06-02 10:20:22 +0000333 // module/function was run in between
Torok Edwin24c78352009-06-29 18:49:09 +0000334 EXPECT_EQ(2, mNDM->run);
335 EXPECT_EQ(1, mNDNM->run);
336 EXPECT_EQ(1, mNDM2->run);
337 EXPECT_EQ(1, mDNM->run);
338 }
339
340 Module* makeLLVMModule();
341
342 template<typename T>
343 void MemoryTestHelper(int run) {
Jeffrey Yasskin61e710c2010-03-13 02:15:08 +0000344 OwningPtr<Module> M(makeLLVMModule());
Torok Edwin24c78352009-06-29 18:49:09 +0000345 T *P = new T();
346 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000347 Passes.add(new DataLayout(M.get()));
Torok Edwin24c78352009-06-29 18:49:09 +0000348 Passes.add(P);
349 Passes.run(*M);
350 T::finishedOK(run);
351 }
352
353 template<typename T>
354 void MemoryTestHelper(int run, int N) {
355 Module *M = makeLLVMModule();
356 T *P = new T();
357 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000358 Passes.add(new DataLayout(M));
Torok Edwin24c78352009-06-29 18:49:09 +0000359 Passes.add(P);
360 Passes.run(*M);
361 T::finishedOK(run, N);
362 delete M;
363 }
364
365 TEST(PassManager, Memory) {
366 // SCC#1: test1->test2->test3->test1
367 // SCC#2: test4
368 // SCC#3: indirect call node
369 {
370 SCOPED_TRACE("Callgraph pass");
371 MemoryTestHelper<CGPass>(3);
372 }
373
374 {
375 SCOPED_TRACE("Function pass");
376 MemoryTestHelper<FPass>(4);// 4 functions
377 }
378
379 {
380 SCOPED_TRACE("Loop pass");
381 MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
382 }
383 {
384 SCOPED_TRACE("Basic block pass");
385 MemoryTestHelper<BPass>(7, 4); //9 basic blocks
386 }
387
388 }
389
390 TEST(PassManager, MemoryOnTheFly) {
391 Module *M = makeLLVMModule();
392 {
393 SCOPED_TRACE("Running OnTheFlyTest");
394 struct OnTheFlyTest *O = new OnTheFlyTest();
395 PassManager Passes;
Micah Villmow9cfc13d2012-10-08 16:39:34 +0000396 Passes.add(new DataLayout(M));
Torok Edwin24c78352009-06-29 18:49:09 +0000397 Passes.add(O);
398 Passes.run(*M);
399
400 FPass::finishedOK(4);
401 }
402 delete M;
403 }
404
405 Module* makeLLVMModule() {
406 // Module Construction
Owen Anderson55f1c092009-08-13 21:58:54 +0000407 Module* mod = new Module("test-mem", getGlobalContext());
Torok Edwin24c78352009-06-29 18:49:09 +0000408 mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
409 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
410 "a0:0:64-s0:64:64-f80:128:128");
411 mod->setTargetTriple("x86_64-unknown-linux-gnu");
412
413 // Type Definitions
Jay Foadb804a2b2011-07-12 14:06:48 +0000414 std::vector<Type*>FuncTy_0_args;
Torok Edwin24c78352009-06-29 18:49:09 +0000415 FunctionType* FuncTy_0 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000416 /*Result=*/IntegerType::get(getGlobalContext(), 32),
Torok Edwin24c78352009-06-29 18:49:09 +0000417 /*Params=*/FuncTy_0_args,
418 /*isVarArg=*/false);
419
Jay Foadb804a2b2011-07-12 14:06:48 +0000420 std::vector<Type*>FuncTy_2_args;
Owen Anderson55f1c092009-08-13 21:58:54 +0000421 FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
Torok Edwin24c78352009-06-29 18:49:09 +0000422 FunctionType* FuncTy_2 = FunctionType::get(
Owen Anderson55f1c092009-08-13 21:58:54 +0000423 /*Result=*/Type::getVoidTy(getGlobalContext()),
Torok Edwin24c78352009-06-29 18:49:09 +0000424 /*Params=*/FuncTy_2_args,
425 /*isVarArg=*/false);
426
427
428 // Function Declarations
429
430 Function* func_test1 = Function::Create(
431 /*Type=*/FuncTy_0,
432 /*Linkage=*/GlobalValue::ExternalLinkage,
433 /*Name=*/"test1", mod);
434 func_test1->setCallingConv(CallingConv::C);
435 AttrListPtr func_test1_PAL;
436 func_test1->setAttributes(func_test1_PAL);
437
438 Function* func_test2 = Function::Create(
439 /*Type=*/FuncTy_0,
440 /*Linkage=*/GlobalValue::ExternalLinkage,
441 /*Name=*/"test2", mod);
442 func_test2->setCallingConv(CallingConv::C);
443 AttrListPtr func_test2_PAL;
444 func_test2->setAttributes(func_test2_PAL);
445
446 Function* func_test3 = Function::Create(
447 /*Type=*/FuncTy_0,
448 /*Linkage=*/GlobalValue::ExternalLinkage,
449 /*Name=*/"test3", mod);
450 func_test3->setCallingConv(CallingConv::C);
451 AttrListPtr func_test3_PAL;
452 func_test3->setAttributes(func_test3_PAL);
453
454 Function* func_test4 = Function::Create(
455 /*Type=*/FuncTy_2,
456 /*Linkage=*/GlobalValue::ExternalLinkage,
457 /*Name=*/"test4", mod);
458 func_test4->setCallingConv(CallingConv::C);
459 AttrListPtr func_test4_PAL;
460 func_test4->setAttributes(func_test4_PAL);
461
462 // Global Variable Declarations
463
464
465 // Constant Definitions
466
467 // Global Variable Definitions
468
469 // Function Definitions
470
471 // Function: test1 (func_test1)
472 {
473
Owen Anderson55f1c092009-08-13 21:58:54 +0000474 BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000475
476 // Block entry (label_entry)
477 CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
478 int32_3->setCallingConv(CallingConv::C);
479 int32_3->setTailCall(false);AttrListPtr int32_3_PAL;
480 int32_3->setAttributes(int32_3_PAL);
481
Owen Anderson55f1c092009-08-13 21:58:54 +0000482 ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
Torok Edwin24c78352009-06-29 18:49:09 +0000483
484 }
485
486 // Function: test2 (func_test2)
487 {
488
Owen Anderson55f1c092009-08-13 21:58:54 +0000489 BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000490
491 // Block entry (label_entry_5)
492 CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
493 int32_6->setCallingConv(CallingConv::C);
494 int32_6->setTailCall(false);AttrListPtr int32_6_PAL;
495 int32_6->setAttributes(int32_6_PAL);
496
Owen Anderson55f1c092009-08-13 21:58:54 +0000497 ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
Torok Edwin24c78352009-06-29 18:49:09 +0000498
499 }
500
501 // Function: test3 (func_test3)
502 {
503
Owen Anderson55f1c092009-08-13 21:58:54 +0000504 BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000505
506 // Block entry (label_entry_8)
507 CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
508 int32_9->setCallingConv(CallingConv::C);
509 int32_9->setTailCall(false);AttrListPtr int32_9_PAL;
510 int32_9->setAttributes(int32_9_PAL);
511
Owen Anderson55f1c092009-08-13 21:58:54 +0000512 ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
Torok Edwin24c78352009-06-29 18:49:09 +0000513
514 }
515
516 // Function: test4 (func_test4)
517 {
518 Function::arg_iterator args = func_test4->arg_begin();
519 Value* int1_f = args++;
520 int1_f->setName("f");
521
Owen Anderson55f1c092009-08-13 21:58:54 +0000522 BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0);
523 BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0);
524 BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0);
525 BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0);
Torok Edwin24c78352009-06-29 18:49:09 +0000526
527 // Block entry (label_entry_11)
528 BranchInst::Create(label_bb, label_entry_11);
529
530 // Block bb (label_bb)
531 BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
532
533 // Block bb1 (label_bb1)
534 BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
535
536 // Block return (label_return)
Owen Anderson55f1c092009-08-13 21:58:54 +0000537 ReturnInst::Create(getGlobalContext(), label_return);
Torok Edwin24c78352009-06-29 18:49:09 +0000538
539 }
540 return mod;
541 }
542
543 }
544}
Owen Anderson6c18d1a2010-10-19 17:21:58 +0000545
546INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
547INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
548INITIALIZE_AG_DEPENDENCY(CallGraph)
549INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
550INITIALIZE_PASS(FPass, "fp","fp", false, false)
551INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
552INITIALIZE_PASS_DEPENDENCY(LoopInfo)
553INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
554INITIALIZE_PASS(BPass, "bp","bp", false, false)