Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 153:2c447715c047 trunk
[svn r159] added some code to help diagnose ticket #35
author | lindquist |
---|---|
date | Tue, 25 Mar 2008 16:33:19 +0100 |
parents | 5825d48b27d1 |
children | 665b81613475 |
rev | line source |
---|---|
125 | 1 #include "llvm/PassManager.h" |
2 #include "llvm/LinkAllPasses.h" | |
3 #include "llvm/Analysis/LoopPass.h" | |
4 #include "llvm/Target/TargetData.h" | |
5 | |
6 using namespace llvm; | |
7 | |
8 ////////////////////////////////////////////////////////////////////////////////////////// | |
9 | |
10 // this function runs some or all of the std-compile-opts passes depending on the | |
11 // optimization level given. | |
12 | |
13 void llvmdc_optimize_module(Module* m, char lvl, bool doinline) | |
14 { | |
131 | 15 if (!doinline && lvl < 0) |
16 return; | |
17 | |
125 | 18 assert(lvl >= 0 && lvl <= 5); |
19 | |
20 PassManager pm; | |
21 pm.add(new TargetData(m)); | |
22 | |
131 | 23 // -O0 |
24 if (lvl >= 0) | |
25 { | |
26 //pm.add(createStripDeadPrototypesPass()); | |
27 pm.add(createGlobalDCEPass()); | |
28 } | |
29 | |
30 // -O1 | |
125 | 31 if (lvl >= 1) |
32 { | |
33 pm.add(createRaiseAllocationsPass()); | |
34 pm.add(createCFGSimplificationPass()); | |
35 pm.add(createPromoteMemoryToRegisterPass()); | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
36 pm.add(createGlobalOptimizerPass()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
37 pm.add(createGlobalDCEPass()); |
125 | 38 } |
39 | |
131 | 40 // -O2 |
125 | 41 if (lvl >= 2) |
42 { | |
43 pm.add(createIPConstantPropagationPass()); | |
44 pm.add(createDeadArgEliminationPass()); | |
45 pm.add(createInstructionCombiningPass()); | |
46 pm.add(createCFGSimplificationPass()); | |
47 pm.add(createPruneEHPass()); | |
48 } | |
49 | |
131 | 50 // -inline |
125 | 51 if (doinline) { |
52 pm.add(createFunctionInliningPass()); | |
53 } | |
54 | |
131 | 55 // -O3 |
125 | 56 if (lvl >= 3) |
57 { | |
58 pm.add(createArgumentPromotionPass()); | |
59 pm.add(createTailDuplicationPass()); | |
60 pm.add(createInstructionCombiningPass()); | |
61 pm.add(createCFGSimplificationPass()); | |
62 pm.add(createScalarReplAggregatesPass()); | |
63 pm.add(createInstructionCombiningPass()); | |
64 pm.add(createCondPropagationPass()); | |
65 | |
66 pm.add(createTailCallEliminationPass()); | |
67 pm.add(createCFGSimplificationPass()); | |
68 pm.add(createReassociatePass()); | |
69 pm.add(createLoopRotatePass()); | |
70 pm.add(createLICMPass()); | |
71 pm.add(createLoopUnswitchPass()); | |
72 pm.add(createInstructionCombiningPass()); | |
73 pm.add(createIndVarSimplifyPass()); | |
74 pm.add(createLoopUnrollPass()); | |
75 pm.add(createInstructionCombiningPass()); | |
76 pm.add(createGVNPass()); | |
77 pm.add(createSCCPPass()); | |
78 | |
79 pm.add(createInstructionCombiningPass()); | |
80 pm.add(createCondPropagationPass()); | |
81 | |
82 pm.add(createDeadStoreEliminationPass()); | |
83 pm.add(createAggressiveDCEPass()); | |
84 pm.add(createCFGSimplificationPass()); | |
85 pm.add(createSimplifyLibCallsPass()); | |
86 pm.add(createDeadTypeEliminationPass()); | |
87 pm.add(createConstantMergePass()); | |
88 } | |
89 | |
131 | 90 // level -O4 and -O5 are linktime optimizations |
125 | 91 |
131 | 92 pm.run(*m); |
125 | 93 } |