Prepare for LLVM 12.0.1 compatibility

This commit is contained in:
gingerBill
2021-09-11 16:53:18 +01:00
parent 344abf2cb2
commit e3359a2639
2 changed files with 37 additions and 23 deletions
+23 -15
View File
@@ -1968,24 +1968,32 @@ void lb_add_procedure_value(lbModule *m, lbProcedure *p) {
LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) { LLVMAttributeRef lb_create_enum_attribute_with_type(LLVMContextRef ctx, char const *name, LLVMTypeRef type) {
unsigned kind = 0;
String s = make_string_c(name); String s = make_string_c(name);
// NOTE(2021-02-25, bill); All this attributes require a type associated with them #if (LLVM_VERSION_MAJOR > 12 || (LLVM_VERSION_MAJOR == 12 && (LLVM_VERSION_MINOR > 0 || LLVM_VERSION_PATCH >= 1)))
// and the current LLVM C API does not expose this functionality yet. kind = LLVMGetEnumAttributeKindForName(name, s.len);
// It is better to ignore the attributes for the time being GB_ASSERT_MSG(kind != 0, "unknown attribute: %s", name);
if (s == "byval") { return LLVMCreateTypeAttribute(ctx, kind, type);
// return nullptr; #else
} else if (s == "byref") { // NOTE(2021-02-25, bill); All this attributes require a type associated with them
return nullptr; // and the current LLVM C API does not expose this functionality yet.
} else if (s == "preallocated") { // It is better to ignore the attributes for the time being
return nullptr; if (s == "byval") {
} else if (s == "sret") { // return nullptr;
// return nullptr; } else if (s == "byref") {
} return nullptr;
} else if (s == "preallocated") {
return nullptr;
} else if (s == "sret") {
// return nullptr;
}
unsigned kind = LLVMGetEnumAttributeKindForName(name, s.len);
GB_ASSERT_MSG(kind != 0, "unknown attribute: %s", name); kind = LLVMGetEnumAttributeKindForName(name, s.len);
return LLVMCreateEnumAttribute(ctx, kind, 0); GB_ASSERT_MSG(kind != 0, "unknown attribute: %s", name);
return LLVMCreateEnumAttribute(ctx, kind, 0);
#endif
} }
LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) { LLVMAttributeRef lb_create_enum_attribute(LLVMContextRef ctx, char const *name, u64 value) {
+14 -8
View File
@@ -21,13 +21,19 @@ void lb_add_must_preserve_predicate_pass(lbModule *m, LLVMPassManagerRef fpm, i3
} }
#if LLVM_VERSION_MAJOR < 12
#define LLVM_ADD_CONSTNAT_VALUE_PASS LLVMAddConstantPropagationPass
#else
#define LLVM_ADD_CONSTNAT_VALUE_PASS LLVMAddCorrelatedValuePropagationPass
#endif
void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm) { void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm) {
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddEarlyCSEPass(fpm); LLVMAddEarlyCSEPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddCFGSimplificationPass(fpm); LLVMAddCFGSimplificationPass(fpm);
@@ -58,10 +64,10 @@ void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool
LLVMAddMemCpyOptPass(fpm); LLVMAddMemCpyOptPass(fpm);
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddEarlyCSEPass(fpm); LLVMAddEarlyCSEPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddCFGSimplificationPass(fpm); LLVMAddCFGSimplificationPass(fpm);
@@ -99,10 +105,10 @@ void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef
LLVMAddMemCpyOptPass(fpm); LLVMAddMemCpyOptPass(fpm);
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddEarlyCSEPass(fpm); LLVMAddEarlyCSEPass(fpm);
LLVMAddConstantPropagationPass(fpm); LLVM_ADD_CONSTNAT_VALUE_PASS(fpm);
LLVMAddMergedLoadStoreMotionPass(fpm); LLVMAddMergedLoadStoreMotionPass(fpm);
LLVMAddPromoteMemoryToRegisterPass(fpm); LLVMAddPromoteMemoryToRegisterPass(fpm);
LLVMAddCFGSimplificationPass(fpm); LLVMAddCFGSimplificationPass(fpm);
@@ -159,7 +165,7 @@ void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimizati
LLVMAddInstructionCombiningPass(mpm); LLVMAddInstructionCombiningPass(mpm);
LLVMAddJumpThreadingPass(mpm); LLVMAddJumpThreadingPass(mpm);
LLVMAddCorrelatedValuePropagationPass(mpm); LLVM_ADD_CONSTNAT_VALUE_PASS(mpm);
LLVMAddDeadStoreEliminationPass(mpm); LLVMAddDeadStoreEliminationPass(mpm);
LLVMAddLICMPass(mpm); LLVMAddLICMPass(mpm);
@@ -225,7 +231,7 @@ void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPa
LLVMAddInstructionCombiningPass(mpm); LLVMAddInstructionCombiningPass(mpm);
if (optimization_level >= 2) { if (optimization_level >= 2) {
LLVMAddEarlyCSEPass(mpm); LLVMAddEarlyCSEPass(mpm);
LLVMAddCorrelatedValuePropagationPass(mpm); LLVM_ADD_CONSTNAT_VALUE_PASS(mpm);
LLVMAddLICMPass(mpm); LLVMAddLICMPass(mpm);
LLVMAddLoopUnswitchPass(mpm); LLVMAddLoopUnswitchPass(mpm);
LLVMAddCFGSimplificationPass(mpm); LLVMAddCFGSimplificationPass(mpm);