Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 313:a498b736a0bd trunk
[svn r334] Produce an error for zero-size types instead of segfaulting.
author | ChristianK |
---|---|
date | Sun, 29 Jun 2008 22:22:37 +0200 |
parents | 665b81613475 |
children | e235b80c92bc |
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 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()); | |
44 pm.add(createCFGSimplificationPass()); | |
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 } |