|
@@ -2,11 +2,15 @@
|
|
#define LLVM_USE_BASIC_PASSES 0
|
|
#define LLVM_USE_BASIC_PASSES 0
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-void lb_populate_function_pass_manager(LLVMPassManagerRef fpm, bool ignore_memcpy_pass) {
|
|
|
|
|
|
+void lb_populate_function_pass_manager(LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) {
|
|
|
|
+ // NOTE(bill): Treat -opt:3 as if it was -opt:2
|
|
|
|
+ // TODO(bill): Determine which opt definitions should exist in the first place
|
|
|
|
+ optimization_level = gb_clamp(optimization_level, 0, 2);
|
|
|
|
+
|
|
if (!ignore_memcpy_pass) {
|
|
if (!ignore_memcpy_pass) {
|
|
LLVMAddMemCpyOptPass(fpm);
|
|
LLVMAddMemCpyOptPass(fpm);
|
|
}
|
|
}
|
|
- if (LLVM_USE_BASIC_PASSES || build_context.optimization_level == 0) {
|
|
|
|
|
|
+ if (LLVM_USE_BASIC_PASSES || optimization_level == 0) {
|
|
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
|
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
|
LLVMAddMergedLoadStoreMotionPass(fpm);
|
|
LLVMAddMergedLoadStoreMotionPass(fpm);
|
|
LLVMAddEarlyCSEPass(fpm);
|
|
LLVMAddEarlyCSEPass(fpm);
|
|
@@ -35,7 +39,7 @@ void lb_populate_function_pass_manager(LLVMPassManagerRef fpm, bool ignore_memcp
|
|
LLVMAddLowerExpectIntrinsicPass(fpm);
|
|
LLVMAddLowerExpectIntrinsicPass(fpm);
|
|
}
|
|
}
|
|
|
|
|
|
-void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm) {
|
|
|
|
|
|
+void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) {
|
|
// LLVMAddScalarReplAggregatesPass(mpm);
|
|
// LLVMAddScalarReplAggregatesPass(mpm);
|
|
LLVMAddEarlyCSEMemSSAPass(mpm);
|
|
LLVMAddEarlyCSEMemSSAPass(mpm);
|
|
|
|
|
|
@@ -44,7 +48,7 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm) {
|
|
|
|
|
|
LLVMAddJumpThreadingPass(mpm);
|
|
LLVMAddJumpThreadingPass(mpm);
|
|
|
|
|
|
- if (build_context.optimization_level > 2) {
|
|
|
|
|
|
+ if (optimization_level > 2) {
|
|
LLVMAddAggressiveInstCombinerPass(mpm);
|
|
LLVMAddAggressiveInstCombinerPass(mpm);
|
|
}
|
|
}
|
|
LLVMAddInstructionCombiningPass(mpm);
|
|
LLVMAddInstructionCombiningPass(mpm);
|
|
@@ -88,10 +92,14 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm) {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm) {
|
|
|
|
|
|
+void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) {
|
|
|
|
+ // NOTE(bill): Treat -opt:3 as if it was -opt:2
|
|
|
|
+ // TODO(bill): Determine which opt definitions should exist in the first place
|
|
|
|
+ optimization_level = gb_clamp(optimization_level, 0, 2);
|
|
|
|
+
|
|
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
|
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
|
- LLVMPassManagerBuilderSetOptLevel(pmb, build_context.optimization_level);
|
|
|
|
- LLVMPassManagerBuilderSetSizeLevel(pmb, build_context.optimization_level);
|
|
|
|
|
|
+ LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
|
|
|
+ LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
|
|
|
|
|
|
LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
|
|
LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
|
|
|
|
|
|
@@ -99,7 +107,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
LLVMAddAnalysisPasses(target_machine, mpm);
|
|
LLVMAddAnalysisPasses(target_machine, mpm);
|
|
LLVMAddPruneEHPass(mpm);
|
|
LLVMAddPruneEHPass(mpm);
|
|
- if (LLVM_USE_BASIC_PASSES || build_context.optimization_level == 0) {
|
|
|
|
|
|
+ if (LLVM_USE_BASIC_PASSES || optimization_level == 0) {
|
|
// LLVMAddMergeFunctionsPass(mpm);
|
|
// LLVMAddMergeFunctionsPass(mpm);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -119,10 +127,10 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
|
|
LLVMAddPruneEHPass(mpm);
|
|
LLVMAddPruneEHPass(mpm);
|
|
LLVMAddFunctionInliningPass(mpm);
|
|
LLVMAddFunctionInliningPass(mpm);
|
|
|
|
|
|
- if (build_context.optimization_level > 2) {
|
|
|
|
|
|
+ if (optimization_level > 2) {
|
|
LLVMAddArgumentPromotionPass(mpm);
|
|
LLVMAddArgumentPromotionPass(mpm);
|
|
}
|
|
}
|
|
- lb_add_function_simplifcation_passes(mpm);
|
|
|
|
|
|
+ lb_add_function_simplifcation_passes(mpm, optimization_level);
|
|
|
|
|
|
LLVMAddGlobalOptimizerPass(mpm);
|
|
LLVMAddGlobalOptimizerPass(mpm);
|
|
|
|
|
|
@@ -133,7 +141,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
|
|
LLVMAddLoopVectorizePass(mpm);
|
|
LLVMAddLoopVectorizePass(mpm);
|
|
|
|
|
|
LLVMAddInstructionCombiningPass(mpm);
|
|
LLVMAddInstructionCombiningPass(mpm);
|
|
- if (build_context.optimization_level >= 2) {
|
|
|
|
|
|
+ if (optimization_level >= 2) {
|
|
LLVMAddEarlyCSEPass(mpm);
|
|
LLVMAddEarlyCSEPass(mpm);
|
|
LLVMAddCorrelatedValuePropagationPass(mpm);
|
|
LLVMAddCorrelatedValuePropagationPass(mpm);
|
|
LLVMAddLICMPass(mpm);
|
|
LLVMAddLICMPass(mpm);
|
|
@@ -151,7 +159,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
|
|
|
|
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
|
|
|
|
- if (build_context.optimization_level >= 2) {
|
|
|
|
|
|
+ if (optimization_level >= 2) {
|
|
LLVMAddGlobalDCEPass(mpm);
|
|
LLVMAddGlobalDCEPass(mpm);
|
|
LLVMAddConstantMergePass(mpm);
|
|
LLVMAddConstantMergePass(mpm);
|
|
}
|
|
}
|
|
@@ -163,7 +171,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
|
|
LLVMAddAlwaysInlinerPass(mpm);
|
|
LLVMAddAlwaysInlinerPass(mpm);
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
LLVMAddStripDeadPrototypesPass(mpm);
|
|
LLVMAddAnalysisPasses(target_machine, mpm);
|
|
LLVMAddAnalysisPasses(target_machine, mpm);
|
|
- if (build_context.optimization_level >= 2) {
|
|
|
|
|
|
+ if (optimization_level >= 2) {
|
|
LLVMAddArgumentPromotionPass(mpm);
|
|
LLVMAddArgumentPromotionPass(mpm);
|
|
LLVMAddConstantMergePass(mpm);
|
|
LLVMAddConstantMergePass(mpm);
|
|
LLVMAddGlobalDCEPass(mpm);
|
|
LLVMAddGlobalDCEPass(mpm);
|