Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 1157:ee8db0b7bb62
Fix path to llvmasm.di in runtime CMakeList
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 28 Mar 2009 10:50:44 +0100 |
parents | 6aaa3d3c1183 |
children | e40c65bd8c5d |
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 | |
663
6aaa3d3c1183
First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents:
607
diff
changeset
|
13 void ldc_optimize_module(Module* m, char lvl, bool doinline) |
125 | 14 { |
131 | 15 if (!doinline && lvl < 0) |
16 return; | |
17 | |
125 | 18 PassManager pm; |
19 pm.add(new TargetData(m)); | |
20 | |
131 | 21 // -O0 |
22 if (lvl >= 0) | |
23 { | |
24 //pm.add(createStripDeadPrototypesPass()); | |
25 pm.add(createGlobalDCEPass()); | |
26 } | |
27 | |
28 // -O1 | |
125 | 29 if (lvl >= 1) |
30 { | |
31 pm.add(createRaiseAllocationsPass()); | |
32 pm.add(createCFGSimplificationPass()); | |
33 pm.add(createPromoteMemoryToRegisterPass()); | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
34 pm.add(createGlobalOptimizerPass()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
35 pm.add(createGlobalDCEPass()); |
125 | 36 } |
37 | |
131 | 38 // -O2 |
125 | 39 if (lvl >= 2) |
40 { | |
41 pm.add(createIPConstantPropagationPass()); | |
42 pm.add(createDeadArgEliminationPass()); | |
43 pm.add(createInstructionCombiningPass()); | |
607
9526b29ae342
Fixed the optimizer thing, since llvm PR 2800 is already fixed, users need to upgrade LLVM to latest svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
605
diff
changeset
|
44 pm.add(createCFGSimplificationPass()); |
125 | 45 pm.add(createPruneEHPass()); |
46 } | |
47 | |
131 | 48 // -inline |
125 | 49 if (doinline) { |
50 pm.add(createFunctionInliningPass()); | |
51 } | |
52 | |
131 | 53 // -O3 |
125 | 54 if (lvl >= 3) |
55 { | |
56 pm.add(createArgumentPromotionPass()); | |
57 pm.add(createTailDuplicationPass()); | |
58 pm.add(createInstructionCombiningPass()); | |
59 pm.add(createCFGSimplificationPass()); | |
60 pm.add(createScalarReplAggregatesPass()); | |
61 pm.add(createInstructionCombiningPass()); | |
62 pm.add(createCondPropagationPass()); | |
63 | |
64 pm.add(createTailCallEliminationPass()); | |
65 pm.add(createCFGSimplificationPass()); | |
66 pm.add(createReassociatePass()); | |
67 pm.add(createLoopRotatePass()); | |
68 pm.add(createLICMPass()); | |
69 pm.add(createLoopUnswitchPass()); | |
70 pm.add(createInstructionCombiningPass()); | |
71 pm.add(createIndVarSimplifyPass()); | |
72 pm.add(createLoopUnrollPass()); | |
73 pm.add(createInstructionCombiningPass()); | |
74 pm.add(createGVNPass()); | |
75 pm.add(createSCCPPass()); | |
76 | |
77 pm.add(createInstructionCombiningPass()); | |
78 pm.add(createCondPropagationPass()); | |
79 | |
80 pm.add(createDeadStoreEliminationPass()); | |
81 pm.add(createAggressiveDCEPass()); | |
82 pm.add(createCFGSimplificationPass()); | |
83 pm.add(createSimplifyLibCallsPass()); | |
84 pm.add(createDeadTypeEliminationPass()); | |
85 pm.add(createConstantMergePass()); | |
86 } | |
87 | |
131 | 88 // level -O4 and -O5 are linktime optimizations |
125 | 89 |
131 | 90 pm.run(*m); |
125 | 91 } |