-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathllvm_opt_30.cc
56 lines (44 loc) · 1.68 KB
/
llvm_opt_30.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "llvm_opt_30.h"
void AddOptimizationPasses(PassManagerBase &MPM, FunctionPassManager &FPM, unsigned OptLevel, unsigned SizeLevel) {
PassManagerBuilder Builder;
FPM.add(createVerifierPass());
Builder.OptLevel = OptLevel;
Builder.SizeLevel = SizeLevel;
Builder.Inliner = createAlwaysInlinerPass();
Builder.DisableUnrollLoops = OptLevel == 0;
Builder.populateFunctionPassManager(FPM);
Builder.populateModulePassManager(MPM);
}
static void AddStandardCompilePasses(PassManagerBase &PM) {
PM.add(createVerifierPass()); // Verify that input is correc
PassManagerBuilder Builder;
Builder.Inliner = createFunctionInliningPass();
Builder.OptLevel = 3;
Builder.populateModulePassManager(PM);
}
void optimizeModule(Module *M,int optimize_level) {
PassManager Passes;
FunctionPassManager FPasses(M);
PassRegistry &Registry = *PassRegistry::getPassRegistry();
initializeCore(Registry);
initializeScalarOpts(Registry);
initializeIPO(Registry);
initializeAnalysis(Registry);
initializeIPA(Registry);
initializeTransformUtils(Registry);
initializeInstCombine(Registry);
initializeInstrumentation(Registry);
initializeTarget(Registry);
TargetData *TD = 0;
const std::string &ModuleDataLayout = M->getDataLayout();
TD = new TargetData(ModuleDataLayout);
FPasses.add(new TargetData(*TD));
AddStandardCompilePasses(Passes);
FPasses.doInitialization();
for (Module::iterator F = M->begin(), E = M->end(); F != E; ++F)
FPasses.run(*F);
FPasses.doFinalization();
AddOptimizationPasses(Passes, FPasses, optimize_level, 0);
Passes.add(createVerifierPass());
Passes.run(*M);
}