blob: 1097da61b9d9951ee16b461df19a7dab710f1361 [file] [log] [blame]
Chandler Carruthc779e962013-01-07 15:35:46 +00001//===- llvm/unittest/IR/PassManager.cpp - PassManager unit tests ----------===//
Torok Edwin1970a892009-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//===----------------------------------------------------------------------===//
9
Torok Edwin1970a892009-06-29 18:49:09 +000010#include "llvm/PassManager.h"
11#include "llvm/ADT/SmallVector.h"
Chandler Carruth3251e812013-01-07 15:26:48 +000012#include "llvm/Analysis/CallGraphSCCPass.h"
Chandler Carruth5a88dda2012-12-04 10:23:08 +000013#include "llvm/Analysis/LoopInfo.h"
14#include "llvm/Analysis/LoopPass.h"
Torok Edwin1970a892009-06-29 18:49:09 +000015#include "llvm/Analysis/Verifier.h"
16#include "llvm/Assembly/PrintModulePass.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000017#include "llvm/IR/BasicBlock.h"
18#include "llvm/IR/CallingConv.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/DataLayout.h"
21#include "llvm/IR/DerivedTypes.h"
22#include "llvm/IR/Function.h"
23#include "llvm/IR/GlobalVariable.h"
24#include "llvm/IR/InlineAsm.h"
25#include "llvm/IR/Instructions.h"
26#include "llvm/IR/LLVMContext.h"
27#include "llvm/IR/Module.h"
Chandler Carruth5a88dda2012-12-04 10:23:08 +000028#include "llvm/Pass.h"
29#include "llvm/Support/MathExtras.h"
30#include "llvm/Support/raw_ostream.h"
Torok Edwin1970a892009-06-29 18:49:09 +000031#include "gtest/gtest.h"
32
Owen Anderson081c34b2010-10-19 17:21:58 +000033using namespace llvm;
34
Torok Edwin1970a892009-06-29 18:49:09 +000035namespace llvm {
Owen Anderson081c34b2010-10-19 17:21:58 +000036 void initializeModuleNDMPass(PassRegistry&);
37 void initializeFPassPass(PassRegistry&);
38 void initializeCGPassPass(PassRegistry&);
39 void initializeLPassPass(PassRegistry&);
40 void initializeBPassPass(PassRegistry&);
Duncan Sandsf202c432011-03-31 09:58:51 +000041
Torok Edwin1970a892009-06-29 18:49:09 +000042 namespace {
43 // ND = no deps
44 // NM = no modifications
45 struct ModuleNDNM: public ModulePass {
46 public:
47 static char run;
48 static char ID;
Owen Anderson081c34b2010-10-19 17:21:58 +000049 ModuleNDNM() : ModulePass(ID) { }
Torok Edwin1970a892009-06-29 18:49:09 +000050 virtual bool runOnModule(Module &M) {
51 run++;
52 return false;
53 }
54 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
55 AU.setPreservesAll();
56 }
57 };
58 char ModuleNDNM::ID=0;
59 char ModuleNDNM::run=0;
60
61 struct ModuleNDM : public ModulePass {
62 public:
63 static char run;
64 static char ID;
Owen Anderson90c579d2010-08-06 18:33:48 +000065 ModuleNDM() : ModulePass(ID) {}
Torok Edwin1970a892009-06-29 18:49:09 +000066 virtual bool runOnModule(Module &M) {
67 run++;
68 return true;
69 }
70 };
71 char ModuleNDM::ID=0;
72 char ModuleNDM::run=0;
Torok Edwin1970a892009-06-29 18:49:09 +000073
74 struct ModuleNDM2 : public ModulePass {
75 public:
76 static char run;
77 static char ID;
Owen Anderson90c579d2010-08-06 18:33:48 +000078 ModuleNDM2() : ModulePass(ID) {}
Torok Edwin1970a892009-06-29 18:49:09 +000079 virtual bool runOnModule(Module &M) {
80 run++;
81 return true;
82 }
83 };
84 char ModuleNDM2::ID=0;
85 char ModuleNDM2::run=0;
86
87 struct ModuleDNM : public ModulePass {
88 public:
89 static char run;
90 static char ID;
Owen Anderson081c34b2010-10-19 17:21:58 +000091 ModuleDNM() : ModulePass(ID) {
92 initializeModuleNDMPass(*PassRegistry::getPassRegistry());
93 }
Torok Edwin1970a892009-06-29 18:49:09 +000094 virtual bool runOnModule(Module &M) {
Micah Villmow791cfc22012-10-08 16:39:34 +000095 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +000096 run++;
97 return false;
98 }
99 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
100 AU.addRequired<ModuleNDM>();
101 AU.setPreservesAll();
102 }
103 };
104 char ModuleDNM::ID=0;
105 char ModuleDNM::run=0;
106
107 template<typename P>
108 struct PassTestBase : public P {
109 protected:
110 static int runc;
111 static bool initialized;
112 static bool finalized;
113 int allocated;
114 void run() {
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000115 EXPECT_TRUE(initialized);
116 EXPECT_FALSE(finalized);
Torok Edwin1970a892009-06-29 18:49:09 +0000117 EXPECT_EQ(0, allocated);
118 allocated++;
119 runc++;
120 }
121 public:
122 static char ID;
123 static void finishedOK(int run) {
124 EXPECT_GT(runc, 0);
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000125 EXPECT_TRUE(initialized);
126 EXPECT_TRUE(finalized);
Torok Edwin1970a892009-06-29 18:49:09 +0000127 EXPECT_EQ(run, runc);
128 }
Owen Anderson90c579d2010-08-06 18:33:48 +0000129 PassTestBase() : P(ID), allocated(0) {
Torok Edwin1970a892009-06-29 18:49:09 +0000130 initialized = false;
131 finalized = false;
132 runc = 0;
133 }
134
135 virtual void releaseMemory() {
136 EXPECT_GT(runc, 0);
137 EXPECT_GT(allocated, 0);
138 allocated--;
139 }
140 };
141 template<typename P> char PassTestBase<P>::ID;
142 template<typename P> int PassTestBase<P>::runc;
143 template<typename P> bool PassTestBase<P>::initialized;
144 template<typename P> bool PassTestBase<P>::finalized;
145
146 template<typename T, typename P>
147 struct PassTest : public PassTestBase<P> {
148 public:
NAKAMURA Takumi4cd0a822012-12-04 07:25:24 +0000149#ifndef _MSC_VER // MSVC complains that Pass is not base class.
Matt Beaumont-Gayee721152012-12-04 05:41:27 +0000150 using llvm::Pass::doInitialization;
151 using llvm::Pass::doFinalization;
NAKAMURA Takumi4cd0a822012-12-04 07:25:24 +0000152#endif
Torok Edwin1970a892009-06-29 18:49:09 +0000153 virtual bool doInitialization(T &t) {
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000154 EXPECT_FALSE(PassTestBase<P>::initialized);
Torok Edwin1970a892009-06-29 18:49:09 +0000155 PassTestBase<P>::initialized = true;
156 return false;
157 }
158 virtual bool doFinalization(T &t) {
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000159 EXPECT_FALSE(PassTestBase<P>::finalized);
Torok Edwin1970a892009-06-29 18:49:09 +0000160 PassTestBase<P>::finalized = true;
161 EXPECT_EQ(0, PassTestBase<P>::allocated);
162 return false;
163 }
164 };
165
166 struct CGPass : public PassTest<CallGraph, CallGraphSCCPass> {
167 public:
Owen Anderson081c34b2010-10-19 17:21:58 +0000168 CGPass() {
169 initializeCGPassPass(*PassRegistry::getPassRegistry());
170 }
Chris Lattner2decb222010-04-16 22:42:17 +0000171 virtual bool runOnSCC(CallGraphSCC &SCMM) {
Micah Villmow791cfc22012-10-08 16:39:34 +0000172 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +0000173 run();
174 return false;
175 }
176 };
Torok Edwin1970a892009-06-29 18:49:09 +0000177
178 struct FPass : public PassTest<Module, FunctionPass> {
179 public:
180 virtual bool runOnFunction(Function &F) {
181 // FIXME: PR4112
Micah Villmow791cfc22012-10-08 16:39:34 +0000182 // EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +0000183 run();
184 return false;
185 }
186 };
Torok Edwin1970a892009-06-29 18:49:09 +0000187
188 struct LPass : public PassTestBase<LoopPass> {
189 private:
190 static int initcount;
191 static int fincount;
192 public:
193 LPass() {
Owen Anderson081c34b2010-10-19 17:21:58 +0000194 initializeLPassPass(*PassRegistry::getPassRegistry());
Torok Edwin1970a892009-06-29 18:49:09 +0000195 initcount = 0; fincount=0;
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000196 EXPECT_FALSE(initialized);
Torok Edwin1970a892009-06-29 18:49:09 +0000197 }
198 static void finishedOK(int run, int finalized) {
199 PassTestBase<LoopPass>::finishedOK(run);
200 EXPECT_EQ(run, initcount);
201 EXPECT_EQ(finalized, fincount);
202 }
Matt Beaumont-Gayee721152012-12-04 05:41:27 +0000203 using llvm::Pass::doInitialization;
204 using llvm::Pass::doFinalization;
Torok Edwin1970a892009-06-29 18:49:09 +0000205 virtual bool doInitialization(Loop* L, LPPassManager &LPM) {
206 initialized = true;
207 initcount++;
208 return false;
209 }
210 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
Micah Villmow791cfc22012-10-08 16:39:34 +0000211 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +0000212 run();
213 return false;
214 }
215 virtual bool doFinalization() {
216 fincount++;
217 finalized = true;
218 return false;
219 }
220 };
221 int LPass::initcount=0;
222 int LPass::fincount=0;
Torok Edwin1970a892009-06-29 18:49:09 +0000223
224 struct BPass : public PassTestBase<BasicBlockPass> {
225 private:
226 static int inited;
227 static int fin;
228 public:
229 static void finishedOK(int run, int N) {
230 PassTestBase<BasicBlockPass>::finishedOK(run);
231 EXPECT_EQ(inited, N);
232 EXPECT_EQ(fin, N);
233 }
234 BPass() {
235 inited = 0;
236 fin = 0;
237 }
238 virtual bool doInitialization(Module &M) {
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000239 EXPECT_FALSE(initialized);
Torok Edwin1970a892009-06-29 18:49:09 +0000240 initialized = true;
241 return false;
242 }
243 virtual bool doInitialization(Function &F) {
244 inited++;
245 return false;
246 }
247 virtual bool runOnBasicBlock(BasicBlock &BB) {
Micah Villmow791cfc22012-10-08 16:39:34 +0000248 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +0000249 run();
250 return false;
251 }
252 virtual bool doFinalization(Function &F) {
253 fin++;
254 return false;
255 }
256 virtual bool doFinalization(Module &M) {
Chandler Carruth48b17fa2010-07-13 17:28:05 +0000257 EXPECT_FALSE(finalized);
Torok Edwin1970a892009-06-29 18:49:09 +0000258 finalized = true;
259 EXPECT_EQ(0, allocated);
260 return false;
261 }
262 };
263 int BPass::inited=0;
264 int BPass::fin=0;
Torok Edwin1970a892009-06-29 18:49:09 +0000265
266 struct OnTheFlyTest: public ModulePass {
267 public:
268 static char ID;
Owen Anderson081c34b2010-10-19 17:21:58 +0000269 OnTheFlyTest() : ModulePass(ID) {
270 initializeFPassPass(*PassRegistry::getPassRegistry());
271 }
Torok Edwin1970a892009-06-29 18:49:09 +0000272 virtual bool runOnModule(Module &M) {
Micah Villmow791cfc22012-10-08 16:39:34 +0000273 EXPECT_TRUE(getAnalysisIfAvailable<DataLayout>());
Torok Edwin1970a892009-06-29 18:49:09 +0000274 for (Module::iterator I=M.begin(),E=M.end(); I != E; ++I) {
275 Function &F = *I;
276 {
277 SCOPED_TRACE("Running on the fly function pass");
278 getAnalysis<FPass>(F);
279 }
280 }
281 return false;
282 }
283 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
284 AU.addRequired<FPass>();
285 }
286 };
287 char OnTheFlyTest::ID=0;
288
289 TEST(PassManager, RunOnce) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000290 Module M("test-once", getGlobalContext());
Torok Edwin1970a892009-06-29 18:49:09 +0000291 struct ModuleNDNM *mNDNM = new ModuleNDNM();
292 struct ModuleDNM *mDNM = new ModuleDNM();
293 struct ModuleNDM *mNDM = new ModuleNDM();
294 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
295
296 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
297
298 PassManager Passes;
Micah Villmow791cfc22012-10-08 16:39:34 +0000299 Passes.add(new DataLayout(&M));
Torok Edwin1970a892009-06-29 18:49:09 +0000300 Passes.add(mNDM2);
301 Passes.add(mNDM);
302 Passes.add(mNDNM);
303 Passes.add(mDNM);
304
305 Passes.run(M);
306 // each pass must be run exactly once, since nothing invalidates them
307 EXPECT_EQ(1, mNDM->run);
308 EXPECT_EQ(1, mNDNM->run);
309 EXPECT_EQ(1, mDNM->run);
310 EXPECT_EQ(1, mNDM2->run);
311 }
312
313 TEST(PassManager, ReRun) {
Owen Anderson1d0be152009-08-13 21:58:54 +0000314 Module M("test-rerun", getGlobalContext());
Torok Edwin1970a892009-06-29 18:49:09 +0000315 struct ModuleNDNM *mNDNM = new ModuleNDNM();
316 struct ModuleDNM *mDNM = new ModuleDNM();
317 struct ModuleNDM *mNDM = new ModuleNDM();
318 struct ModuleNDM2 *mNDM2 = new ModuleNDM2();
319
320 mNDM->run = mNDNM->run = mDNM->run = mNDM2->run = 0;
321
322 PassManager Passes;
Micah Villmow791cfc22012-10-08 16:39:34 +0000323 Passes.add(new DataLayout(&M));
Torok Edwin1970a892009-06-29 18:49:09 +0000324 Passes.add(mNDM);
325 Passes.add(mNDNM);
326 Passes.add(mNDM2);// invalidates mNDM needed by mDNM
327 Passes.add(mDNM);
328
329 Passes.run(M);
330 // Some passes must be rerun because a pass that modified the
Benjamin Kramerd9b0b022012-06-02 10:20:22 +0000331 // module/function was run in between
Torok Edwin1970a892009-06-29 18:49:09 +0000332 EXPECT_EQ(2, mNDM->run);
333 EXPECT_EQ(1, mNDNM->run);
334 EXPECT_EQ(1, mNDM2->run);
335 EXPECT_EQ(1, mDNM->run);
336 }
337
338 Module* makeLLVMModule();
339
340 template<typename T>
341 void MemoryTestHelper(int run) {
Jeffrey Yasskin24161152010-03-13 02:15:08 +0000342 OwningPtr<Module> M(makeLLVMModule());
Torok Edwin1970a892009-06-29 18:49:09 +0000343 T *P = new T();
344 PassManager Passes;
Micah Villmow791cfc22012-10-08 16:39:34 +0000345 Passes.add(new DataLayout(M.get()));
Torok Edwin1970a892009-06-29 18:49:09 +0000346 Passes.add(P);
347 Passes.run(*M);
348 T::finishedOK(run);
349 }
350
351 template<typename T>
352 void MemoryTestHelper(int run, int N) {
353 Module *M = makeLLVMModule();
354 T *P = new T();
355 PassManager Passes;
Micah Villmow791cfc22012-10-08 16:39:34 +0000356 Passes.add(new DataLayout(M));
Torok Edwin1970a892009-06-29 18:49:09 +0000357 Passes.add(P);
358 Passes.run(*M);
359 T::finishedOK(run, N);
360 delete M;
361 }
362
363 TEST(PassManager, Memory) {
364 // SCC#1: test1->test2->test3->test1
365 // SCC#2: test4
366 // SCC#3: indirect call node
367 {
368 SCOPED_TRACE("Callgraph pass");
369 MemoryTestHelper<CGPass>(3);
370 }
371
372 {
373 SCOPED_TRACE("Function pass");
374 MemoryTestHelper<FPass>(4);// 4 functions
375 }
376
377 {
378 SCOPED_TRACE("Loop pass");
379 MemoryTestHelper<LPass>(2, 1); //2 loops, 1 function
380 }
381 {
382 SCOPED_TRACE("Basic block pass");
383 MemoryTestHelper<BPass>(7, 4); //9 basic blocks
384 }
385
386 }
387
388 TEST(PassManager, MemoryOnTheFly) {
389 Module *M = makeLLVMModule();
390 {
391 SCOPED_TRACE("Running OnTheFlyTest");
392 struct OnTheFlyTest *O = new OnTheFlyTest();
393 PassManager Passes;
Micah Villmow791cfc22012-10-08 16:39:34 +0000394 Passes.add(new DataLayout(M));
Torok Edwin1970a892009-06-29 18:49:09 +0000395 Passes.add(O);
396 Passes.run(*M);
397
398 FPass::finishedOK(4);
399 }
400 delete M;
401 }
402
403 Module* makeLLVMModule() {
404 // Module Construction
Owen Anderson1d0be152009-08-13 21:58:54 +0000405 Module* mod = new Module("test-mem", getGlobalContext());
Torok Edwin1970a892009-06-29 18:49:09 +0000406 mod->setDataLayout("e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-"
407 "i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-"
408 "a0:0:64-s0:64:64-f80:128:128");
409 mod->setTargetTriple("x86_64-unknown-linux-gnu");
410
411 // Type Definitions
Jay Foad5fdd6c82011-07-12 14:06:48 +0000412 std::vector<Type*>FuncTy_0_args;
Torok Edwin1970a892009-06-29 18:49:09 +0000413 FunctionType* FuncTy_0 = FunctionType::get(
Owen Anderson1d0be152009-08-13 21:58:54 +0000414 /*Result=*/IntegerType::get(getGlobalContext(), 32),
Torok Edwin1970a892009-06-29 18:49:09 +0000415 /*Params=*/FuncTy_0_args,
416 /*isVarArg=*/false);
417
Jay Foad5fdd6c82011-07-12 14:06:48 +0000418 std::vector<Type*>FuncTy_2_args;
Owen Anderson1d0be152009-08-13 21:58:54 +0000419 FuncTy_2_args.push_back(IntegerType::get(getGlobalContext(), 1));
Torok Edwin1970a892009-06-29 18:49:09 +0000420 FunctionType* FuncTy_2 = FunctionType::get(
Owen Anderson1d0be152009-08-13 21:58:54 +0000421 /*Result=*/Type::getVoidTy(getGlobalContext()),
Torok Edwin1970a892009-06-29 18:49:09 +0000422 /*Params=*/FuncTy_2_args,
423 /*isVarArg=*/false);
424
425
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 Wendling99faa3b2012-12-07 23:16:57 +0000433 AttributeSet func_test1_PAL;
Torok Edwin1970a892009-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 Wendling99faa3b2012-12-07 23:16:57 +0000441 AttributeSet func_test2_PAL;
Torok Edwin1970a892009-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 Wendling99faa3b2012-12-07 23:16:57 +0000449 AttributeSet func_test3_PAL;
Torok Edwin1970a892009-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 Wendling99faa3b2012-12-07 23:16:57 +0000457 AttributeSet func_test4_PAL;
Torok Edwin1970a892009-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
Owen Anderson1d0be152009-08-13 21:58:54 +0000472 BasicBlock* label_entry = BasicBlock::Create(getGlobalContext(), "entry",func_test1,0);
Torok Edwin1970a892009-06-29 18:49:09 +0000473
474 // Block entry (label_entry)
475 CallInst* int32_3 = CallInst::Create(func_test2, "", label_entry);
476 int32_3->setCallingConv(CallingConv::C);
Bill Wendling99faa3b2012-12-07 23:16:57 +0000477 int32_3->setTailCall(false);AttributeSet int32_3_PAL;
Torok Edwin1970a892009-06-29 18:49:09 +0000478 int32_3->setAttributes(int32_3_PAL);
479
Owen Anderson1d0be152009-08-13 21:58:54 +0000480 ReturnInst::Create(getGlobalContext(), int32_3, label_entry);
Torok Edwin1970a892009-06-29 18:49:09 +0000481
482 }
483
484 // Function: test2 (func_test2)
485 {
486
Owen Anderson1d0be152009-08-13 21:58:54 +0000487 BasicBlock* label_entry_5 = BasicBlock::Create(getGlobalContext(), "entry",func_test2,0);
Torok Edwin1970a892009-06-29 18:49:09 +0000488
489 // Block entry (label_entry_5)
490 CallInst* int32_6 = CallInst::Create(func_test3, "", label_entry_5);
491 int32_6->setCallingConv(CallingConv::C);
Bill Wendling99faa3b2012-12-07 23:16:57 +0000492 int32_6->setTailCall(false);AttributeSet int32_6_PAL;
Torok Edwin1970a892009-06-29 18:49:09 +0000493 int32_6->setAttributes(int32_6_PAL);
494
Owen Anderson1d0be152009-08-13 21:58:54 +0000495 ReturnInst::Create(getGlobalContext(), int32_6, label_entry_5);
Torok Edwin1970a892009-06-29 18:49:09 +0000496
497 }
498
499 // Function: test3 (func_test3)
500 {
501
Owen Anderson1d0be152009-08-13 21:58:54 +0000502 BasicBlock* label_entry_8 = BasicBlock::Create(getGlobalContext(), "entry",func_test3,0);
Torok Edwin1970a892009-06-29 18:49:09 +0000503
504 // Block entry (label_entry_8)
505 CallInst* int32_9 = CallInst::Create(func_test1, "", label_entry_8);
506 int32_9->setCallingConv(CallingConv::C);
Bill Wendling99faa3b2012-12-07 23:16:57 +0000507 int32_9->setTailCall(false);AttributeSet int32_9_PAL;
Torok Edwin1970a892009-06-29 18:49:09 +0000508 int32_9->setAttributes(int32_9_PAL);
509
Owen Anderson1d0be152009-08-13 21:58:54 +0000510 ReturnInst::Create(getGlobalContext(), int32_9, label_entry_8);
Torok Edwin1970a892009-06-29 18:49:09 +0000511
512 }
513
514 // Function: test4 (func_test4)
515 {
516 Function::arg_iterator args = func_test4->arg_begin();
517 Value* int1_f = args++;
518 int1_f->setName("f");
519
Owen Anderson1d0be152009-08-13 21:58:54 +0000520 BasicBlock* label_entry_11 = BasicBlock::Create(getGlobalContext(), "entry",func_test4,0);
521 BasicBlock* label_bb = BasicBlock::Create(getGlobalContext(), "bb",func_test4,0);
522 BasicBlock* label_bb1 = BasicBlock::Create(getGlobalContext(), "bb1",func_test4,0);
523 BasicBlock* label_return = BasicBlock::Create(getGlobalContext(), "return",func_test4,0);
Torok Edwin1970a892009-06-29 18:49:09 +0000524
525 // Block entry (label_entry_11)
526 BranchInst::Create(label_bb, label_entry_11);
527
528 // Block bb (label_bb)
529 BranchInst::Create(label_bb, label_bb1, int1_f, label_bb);
530
531 // Block bb1 (label_bb1)
532 BranchInst::Create(label_bb1, label_return, int1_f, label_bb1);
533
534 // Block return (label_return)
Owen Anderson1d0be152009-08-13 21:58:54 +0000535 ReturnInst::Create(getGlobalContext(), label_return);
Torok Edwin1970a892009-06-29 18:49:09 +0000536
537 }
538 return mod;
539 }
540
541 }
542}
Owen Anderson081c34b2010-10-19 17:21:58 +0000543
544INITIALIZE_PASS(ModuleNDM, "mndm", "mndm", false, false)
545INITIALIZE_PASS_BEGIN(CGPass, "cgp","cgp", false, false)
546INITIALIZE_AG_DEPENDENCY(CallGraph)
547INITIALIZE_PASS_END(CGPass, "cgp","cgp", false, false)
548INITIALIZE_PASS(FPass, "fp","fp", false, false)
549INITIALIZE_PASS_BEGIN(LPass, "lp","lp", false, false)
550INITIALIZE_PASS_DEPENDENCY(LoopInfo)
551INITIALIZE_PASS_END(LPass, "lp","lp", false, false)
552INITIALIZE_PASS(BPass, "bp","bp", false, false)