Mercurial > projects > ldc
comparison gen/optimizer.cpp @ 125:c42d245468ea trunk
[svn r129] Started AA literals.
Fixed #15, passing -O will now invoke the optimizer before writing bitcode.
author | lindquist |
---|---|
date | Wed, 28 Nov 2007 04:52:35 +0100 |
parents | |
children | 8096ba7082db |
comparison
equal
deleted
inserted
replaced
124:a939ec89fc72 | 125:c42d245468ea |
---|---|
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 if (lvl == 0) | |
17 return; | |
18 | |
19 PassManager pm; | |
20 pm.add(new TargetData(m)); | |
21 | |
22 if (lvl >= 1) | |
23 { | |
24 pm.add(createRaiseAllocationsPass()); | |
25 pm.add(createCFGSimplificationPass()); | |
26 pm.add(createPromoteMemoryToRegisterPass()); | |
27 } | |
28 | |
29 if (lvl >= 2) | |
30 { | |
31 pm.add(createGlobalOptimizerPass()); | |
32 pm.add(createGlobalDCEPass()); | |
33 pm.add(createIPConstantPropagationPass()); | |
34 pm.add(createDeadArgEliminationPass()); | |
35 pm.add(createInstructionCombiningPass()); | |
36 pm.add(createCFGSimplificationPass()); | |
37 pm.add(createPruneEHPass()); | |
38 } | |
39 | |
40 if (doinline) { | |
41 pm.add(createFunctionInliningPass()); | |
42 } | |
43 | |
44 if (lvl >= 3) | |
45 { | |
46 pm.add(createArgumentPromotionPass()); | |
47 pm.add(createTailDuplicationPass()); | |
48 pm.add(createInstructionCombiningPass()); | |
49 pm.add(createCFGSimplificationPass()); | |
50 pm.add(createScalarReplAggregatesPass()); | |
51 pm.add(createInstructionCombiningPass()); | |
52 pm.add(createCondPropagationPass()); | |
53 | |
54 pm.add(createTailCallEliminationPass()); | |
55 pm.add(createCFGSimplificationPass()); | |
56 pm.add(createReassociatePass()); | |
57 pm.add(createLoopRotatePass()); | |
58 pm.add(createLICMPass()); | |
59 pm.add(createLoopUnswitchPass()); | |
60 pm.add(createInstructionCombiningPass()); | |
61 pm.add(createIndVarSimplifyPass()); | |
62 pm.add(createLoopUnrollPass()); | |
63 pm.add(createInstructionCombiningPass()); | |
64 pm.add(createGVNPass()); | |
65 pm.add(createSCCPPass()); | |
66 | |
67 pm.add(createInstructionCombiningPass()); | |
68 pm.add(createCondPropagationPass()); | |
69 | |
70 pm.add(createDeadStoreEliminationPass()); | |
71 pm.add(createAggressiveDCEPass()); | |
72 pm.add(createCFGSimplificationPass()); | |
73 pm.add(createSimplifyLibCallsPass()); | |
74 pm.add(createDeadTypeEliminationPass()); | |
75 pm.add(createConstantMergePass()); | |
76 } | |
77 | |
78 // level 4 and 5 are linktime optimizations | |
79 | |
80 pm.run(*m); | |
81 } |