Mercurial > projects > ldc
annotate gen/optimizer.cpp @ 129:8096ba7082db trunk
[svn r133] Fixed some problems with inlining not happening :P
Fixed problems with certain cases of deeply nested classes/functions.
author | lindquist |
---|---|
date | Fri, 28 Dec 2007 22:55:24 +0100 |
parents | c42d245468ea |
children | 5825d48b27d1 |
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 { | |
15 assert(lvl >= 0 && lvl <= 5); | |
16 | |
17 PassManager pm; | |
18 pm.add(new TargetData(m)); | |
19 | |
20 if (lvl >= 1) | |
21 { | |
22 pm.add(createRaiseAllocationsPass()); | |
23 pm.add(createCFGSimplificationPass()); | |
24 pm.add(createPromoteMemoryToRegisterPass()); | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
25 pm.add(createGlobalOptimizerPass()); |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
26 pm.add(createGlobalDCEPass()); |
125 | 27 } |
28 | |
29 if (lvl >= 2) | |
30 { | |
31 pm.add(createIPConstantPropagationPass()); | |
32 pm.add(createDeadArgEliminationPass()); | |
33 pm.add(createInstructionCombiningPass()); | |
34 pm.add(createCFGSimplificationPass()); | |
35 pm.add(createPruneEHPass()); | |
36 } | |
37 | |
38 if (doinline) { | |
39 pm.add(createFunctionInliningPass()); | |
40 } | |
41 | |
42 if (lvl >= 3) | |
43 { | |
44 pm.add(createArgumentPromotionPass()); | |
45 pm.add(createTailDuplicationPass()); | |
46 pm.add(createInstructionCombiningPass()); | |
47 pm.add(createCFGSimplificationPass()); | |
48 pm.add(createScalarReplAggregatesPass()); | |
49 pm.add(createInstructionCombiningPass()); | |
50 pm.add(createCondPropagationPass()); | |
51 | |
52 pm.add(createTailCallEliminationPass()); | |
53 pm.add(createCFGSimplificationPass()); | |
54 pm.add(createReassociatePass()); | |
55 pm.add(createLoopRotatePass()); | |
56 pm.add(createLICMPass()); | |
57 pm.add(createLoopUnswitchPass()); | |
58 pm.add(createInstructionCombiningPass()); | |
59 pm.add(createIndVarSimplifyPass()); | |
60 pm.add(createLoopUnrollPass()); | |
61 pm.add(createInstructionCombiningPass()); | |
62 pm.add(createGVNPass()); | |
63 pm.add(createSCCPPass()); | |
64 | |
65 pm.add(createInstructionCombiningPass()); | |
66 pm.add(createCondPropagationPass()); | |
67 | |
68 pm.add(createDeadStoreEliminationPass()); | |
69 pm.add(createAggressiveDCEPass()); | |
70 pm.add(createCFGSimplificationPass()); | |
71 pm.add(createSimplifyLibCallsPass()); | |
72 pm.add(createDeadTypeEliminationPass()); | |
73 pm.add(createConstantMergePass()); | |
74 } | |
75 | |
76 // level 4 and 5 are linktime optimizations | |
77 | |
129
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
78 if (lvl > 0 || doinline) |
8096ba7082db
[svn r133] Fixed some problems with inlining not happening :P
lindquist
parents:
125
diff
changeset
|
79 pm.run(*m); |
125 | 80 } |