Change how lb_populate_module_pass_manager handles the LLVMPassManagerBuilder calls

This commit is contained in:
gingerBill
2021-03-29 16:40:39 +01:00
parent 66941aed0a
commit faa0240900
2 changed files with 31 additions and 16 deletions

View File

@@ -13263,13 +13263,20 @@ void lb_generate_code(lbGenerator *gen) {
LLVMCodeGenOptLevel code_gen_level = LLVMCodeGenLevelNone;
switch (build_context.optimization_level) {
case 0: code_gen_level = LLVMCodeGenLevelNone; break;
case 1: code_gen_level = LLVMCodeGenLevelLess; break;
case 2: code_gen_level = LLVMCodeGenLevelDefault; break;
case 3: code_gen_level = LLVMCodeGenLevelAggressive; break;
case 0: code_gen_level = LLVMCodeGenLevelNone; break;
case 1: code_gen_level = LLVMCodeGenLevelLess; break;
case 2: code_gen_level = LLVMCodeGenLevelDefault; break;
case 3: code_gen_level = LLVMCodeGenLevelDefault; break; // NOTE(bill): force -opt:3 to be the same as -opt:2
// case 3: code_gen_level = LLVMCodeGenLevelAggressive; break;
}
LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(target, target_triple, llvm_cpu, llvm_features, code_gen_level, LLVMRelocDefault, code_mode);
// NOTE(bill): Target Machine Creation
LLVMTargetMachineRef target_machine = LLVMCreateTargetMachine(
target, target_triple, llvm_cpu,
llvm_features,
code_gen_level,
LLVMRelocDefault,
code_mode);
defer (LLVMDisposeTargetMachine(target_machine));

View File

@@ -6,11 +6,14 @@ void lb_populate_function_pass_manager(LLVMPassManagerRef fpm, bool ignore_memcp
// 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 (LLVM_USE_BASIC_PASSES) {
optimization_level = 0;
}
if (!ignore_memcpy_pass) {
LLVMAddMemCpyOptPass(fpm);
}
if (LLVM_USE_BASIC_PASSES || optimization_level == 0) {
if (optimization_level == 0) {
LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddEarlyCSEPass(fpm);
@@ -48,9 +51,9 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimizati
LLVMAddJumpThreadingPass(mpm);
if (optimization_level > 2) {
LLVMAddAggressiveInstCombinerPass(mpm);
}
// if (optimization_level > 2) {
// LLVMAddAggressiveInstCombinerPass(mpm);
// }
LLVMAddInstructionCombiningPass(mpm);
LLVMAddSimplifyLibCallsPass(mpm);
@@ -93,21 +96,26 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimizati
void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level) {
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
// 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();
LLVMAddAnalysisPasses(target_machine, mpm);
LLVMPassManagerBuilderPopulateModulePassManager(pmb, mpm);
LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
if (LLVM_USE_BASIC_PASSES) {
optimization_level = 0;
}
LLVMAddAlwaysInlinerPass(mpm);
LLVMAddStripDeadPrototypesPass(mpm);
LLVMAddAnalysisPasses(target_machine, mpm);
LLVMAddPruneEHPass(mpm);
if (LLVM_USE_BASIC_PASSES || optimization_level == 0) {
if (optimization_level == 0) {
// LLVMAddMergeFunctionsPass(mpm);
return;
}
@@ -127,9 +135,9 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
LLVMAddPruneEHPass(mpm);
LLVMAddFunctionInliningPass(mpm);
if (optimization_level > 2) {
LLVMAddArgumentPromotionPass(mpm);
}
// if (optimization_level > 2) {
// LLVMAddArgumentPromotionPass(mpm);
// }
lb_add_function_simplifcation_passes(mpm, optimization_level);
LLVMAddGlobalOptimizerPass(mpm);