comparison gen/optimizer.cpp @ 131:5825d48b27d1 trunk

[svn r135] * Merged DMD 1.025 * * Fixed a minor linking order mishap * * Added an command line option -annotate * * Fixed some problems with running optimizations * * Added std.stdio and dependencies to lphobos (still not 100% working, but compiles and links) * * Fixed problems with passing aggregate types to variadic functions * * Added initial code towards full GC support, currently based on malloc and friends, not all the runtime calls the GC yet for memory * * Fixed problems with resolving nested function context pointers for some heavily nested cases * * Redid function argument passing + other minor code cleanups, still lots to do on this end... *
author lindquist
date Fri, 04 Jan 2008 01:38:42 +0100
parents 8096ba7082db
children 665b81613475
comparison
equal deleted inserted replaced
130:a7dfa0ed966c 131:5825d48b27d1
10 // this function runs some or all of the std-compile-opts passes depending on the 10 // this function runs some or all of the std-compile-opts passes depending on the
11 // optimization level given. 11 // optimization level given.
12 12
13 void llvmdc_optimize_module(Module* m, char lvl, bool doinline) 13 void llvmdc_optimize_module(Module* m, char lvl, bool doinline)
14 { 14 {
15 if (!doinline && lvl < 0)
16 return;
17
15 assert(lvl >= 0 && lvl <= 5); 18 assert(lvl >= 0 && lvl <= 5);
16 19
17 PassManager pm; 20 PassManager pm;
18 pm.add(new TargetData(m)); 21 pm.add(new TargetData(m));
19 22
23 // -O0
24 if (lvl >= 0)
25 {
26 //pm.add(createStripDeadPrototypesPass());
27 pm.add(createGlobalDCEPass());
28 }
29
30 // -O1
20 if (lvl >= 1) 31 if (lvl >= 1)
21 { 32 {
22 pm.add(createRaiseAllocationsPass()); 33 pm.add(createRaiseAllocationsPass());
23 pm.add(createCFGSimplificationPass()); 34 pm.add(createCFGSimplificationPass());
24 pm.add(createPromoteMemoryToRegisterPass()); 35 pm.add(createPromoteMemoryToRegisterPass());
25 pm.add(createGlobalOptimizerPass()); 36 pm.add(createGlobalOptimizerPass());
26 pm.add(createGlobalDCEPass()); 37 pm.add(createGlobalDCEPass());
27 } 38 }
28 39
40 // -O2
29 if (lvl >= 2) 41 if (lvl >= 2)
30 { 42 {
31 pm.add(createIPConstantPropagationPass()); 43 pm.add(createIPConstantPropagationPass());
32 pm.add(createDeadArgEliminationPass()); 44 pm.add(createDeadArgEliminationPass());
33 pm.add(createInstructionCombiningPass()); 45 pm.add(createInstructionCombiningPass());
34 pm.add(createCFGSimplificationPass()); 46 pm.add(createCFGSimplificationPass());
35 pm.add(createPruneEHPass()); 47 pm.add(createPruneEHPass());
36 } 48 }
37 49
50 // -inline
38 if (doinline) { 51 if (doinline) {
39 pm.add(createFunctionInliningPass()); 52 pm.add(createFunctionInliningPass());
40 } 53 }
41 54
55 // -O3
42 if (lvl >= 3) 56 if (lvl >= 3)
43 { 57 {
44 pm.add(createArgumentPromotionPass()); 58 pm.add(createArgumentPromotionPass());
45 pm.add(createTailDuplicationPass()); 59 pm.add(createTailDuplicationPass());
46 pm.add(createInstructionCombiningPass()); 60 pm.add(createInstructionCombiningPass());
71 pm.add(createSimplifyLibCallsPass()); 85 pm.add(createSimplifyLibCallsPass());
72 pm.add(createDeadTypeEliminationPass()); 86 pm.add(createDeadTypeEliminationPass());
73 pm.add(createConstantMergePass()); 87 pm.add(createConstantMergePass());
74 } 88 }
75 89
76 // level 4 and 5 are linktime optimizations 90 // level -O4 and -O5 are linktime optimizations
77 91
78 if (lvl > 0 || doinline) 92 pm.run(*m);
79 pm.run(*m);
80 } 93 }