mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-26 15:01:31 +00:00
Merge pull request #6918 from Kelimion/deprecate-llvm-14
Remove LLVM 14 support
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#!/usr/bin/env sh
|
||||
set -eu
|
||||
|
||||
SUPPORTED_LLVM_VERSIONS="22 21 20 19 18 17"
|
||||
SUGGESTED_LLVM_VERSION="22"
|
||||
MINIMUM_LLVM_VERSION="17"
|
||||
|
||||
: ${CPPFLAGS=}
|
||||
: ${CXXFLAGS=}
|
||||
: ${LDFLAGS=}
|
||||
@@ -26,8 +30,6 @@ error() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
SUPPORTED_LLVM_VERSIONS="22 21 20 19 18 17 14"
|
||||
|
||||
# Brew advises people not to add llvm to their $PATH, so try and use brew to find it.
|
||||
if [ -z "$LLVM_CONFIG" ] && [ -n "$(command -v brew)" ]; then
|
||||
for V in $SUPPORTED_LLVM_VERSIONS; do
|
||||
@@ -61,7 +63,22 @@ if [ -z "$LLVM_CONFIG" ]; then
|
||||
done
|
||||
|
||||
if [ -z "$LLVM_CONFIG" ]; then
|
||||
error "No supported llvm-config command found. Set LLVM_CONFIG to proceed."
|
||||
if [ -f "/etc/os-release" ]; then
|
||||
. /etc/os-release
|
||||
case "$ID" in
|
||||
ubuntu|debian|linuxmint|pop|zorin|kali|elementary|raspbian)
|
||||
echo "ERROR: No supported llvm-config command found. Set LLVM_CONFIG to proceed."
|
||||
echo "We suggest installing LLVM $SUGGESTED_LLVM_VERSION from https://apt.llvm.org"
|
||||
exit 1
|
||||
;;
|
||||
fedora|centos|rocky|almalinux|rhel|amzn|ol|centos-stream)
|
||||
echo "ERROR: No supported llvm-config command found. Set LLVM_CONFIG to proceed."
|
||||
echo "We suggest installing LLVM $SUGGESTED_LLVM_VERSION via COPR, e.g. dnf copr enable fedora-llvm-team/llvm-snapshots"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
error "No supported llvm-config command found. Set LLVM_CONFIG to proceed. We suggest LLVM $SUGGESTED_LLVM_VERSION."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -78,8 +95,8 @@ LLVM_VERSION_MAJOR="$(echo $LLVM_VERSION | awk -F. '{print $1}')"
|
||||
LLVM_VERSION_MINOR="$(echo $LLVM_VERSION | awk -F. '{print $2}')"
|
||||
LLVM_VERSION_PATCH="$(echo $LLVM_VERSION | awk -F. '{print $3}')"
|
||||
|
||||
if [ $LLVM_VERSION_MAJOR -lt 14 ] || ([ $LLVM_VERSION_MAJOR -gt 14 ] && [ $LLVM_VERSION_MAJOR -lt 17 ]) || [ $LLVM_VERSION_MAJOR -gt 22 ]; then
|
||||
error "Invalid LLVM version $LLVM_VERSION: must be 14, 17, 18, 19, 20, 21 or 22"
|
||||
if [ $LLVM_VERSION_MAJOR -lt $MINIMUM_LLVM_VERSION ]; then
|
||||
error "Unsupported LLVM version $LLVM_VERSION: must be 17, 18, 19, 20, 21 or 22"
|
||||
fi
|
||||
|
||||
case "$OS_NAME" in
|
||||
|
||||
@@ -1109,7 +1109,6 @@ gb_internal i64 odin_compile_timestamp(void) {
|
||||
return ns_after_1970;
|
||||
}
|
||||
|
||||
gb_internal bool lb_use_new_pass_system(void);
|
||||
|
||||
gb_internal void init_universal(void) {
|
||||
BuildContext *bc = &build_context;
|
||||
@@ -1383,7 +1382,8 @@ gb_internal void init_universal(void) {
|
||||
}
|
||||
|
||||
{
|
||||
bool f16_supported = lb_use_new_pass_system();
|
||||
// Available since LLVM 17 / new pass system, which is the minimum now.
|
||||
bool f16_supported = true;
|
||||
if (is_arch_wasm()) {
|
||||
f16_supported = false;
|
||||
} else if (build_context.metrics.os == TargetOs_darwin && build_context.metrics.arch == TargetArch_amd64) {
|
||||
|
||||
@@ -13,6 +13,7 @@ struct LinkerData {
|
||||
gb_internal i32 system_exec_command_line_app(char const *name, char const *fmt, ...);
|
||||
gb_internal bool system_exec_command_line_app_output(char const *command, gbString *output);
|
||||
|
||||
// No longer required not that LLVM 14 is removed(?)
|
||||
gb_internal void linker_enable_system_library_linking(LinkerData *ld) {
|
||||
ld->needs_system_library_linked = true;
|
||||
}
|
||||
|
||||
@@ -2408,10 +2408,6 @@ gb_internal WORKER_TASK_PROC(lb_llvm_function_pass_per_module) {
|
||||
LLVMInitializeFunctionPassManager(m->function_pass_managers[i]);
|
||||
}
|
||||
|
||||
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default], false, build_context.optimization_level);
|
||||
lb_populate_function_pass_manager(m, m->function_pass_managers[lbFunctionPassManager_default_without_memcpy], true, build_context.optimization_level);
|
||||
lb_populate_function_pass_manager_specific(m, m->function_pass_managers[lbFunctionPassManager_none], -1);
|
||||
|
||||
for (i32 i = 0; i < lbFunctionPassManager_COUNT; i++) {
|
||||
LLVMFinalizeFunctionPassManager(m->function_pass_managers[i]);
|
||||
}
|
||||
@@ -2480,11 +2476,8 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
|
||||
auto wd = cast(lbLLVMModulePassWorkerData *)data;
|
||||
|
||||
LLVMPassManagerRef module_pass_manager = LLVMCreatePassManager();
|
||||
lb_populate_module_pass_manager(wd->target_machine, module_pass_manager, build_context.optimization_level);
|
||||
LLVMRunPassManager(module_pass_manager, wd->m->mod);
|
||||
|
||||
|
||||
#if LB_USE_NEW_PASS_SYSTEM
|
||||
auto passes = array_make<char const *>(heap_allocator(), 0, 64);
|
||||
defer (array_free(&passes));
|
||||
|
||||
@@ -2560,7 +2553,6 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
|
||||
exit_with_errors();
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (LLVM_IGNORE_VERIFICATION) {
|
||||
return 0;
|
||||
@@ -2864,7 +2856,6 @@ gb_internal bool lb_llvm_object_generation(lbGenerator *gen, bool do_threading)
|
||||
|
||||
gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime, lbProcedure *cleanup_runtime) {
|
||||
LLVMPassManagerRef default_function_pass_manager = LLVMCreateFunctionPassManagerForModule(m->mod);
|
||||
lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level);
|
||||
LLVMFinalizeFunctionPassManager(default_function_pass_manager);
|
||||
|
||||
Type *params = alloc_type_tuple();
|
||||
@@ -3173,9 +3164,6 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
|
||||
// GB_ASSERT_MSG(LLVMTargetHasAsmBackend(target));
|
||||
|
||||
LLVMCodeGenOptLevel code_gen_level = LLVMCodeGenLevelNone;
|
||||
if (!LB_USE_NEW_PASS_SYSTEM) {
|
||||
build_context.optimization_level = gb_clamp(build_context.optimization_level, -1, 2);
|
||||
}
|
||||
switch (build_context.optimization_level) {
|
||||
default:/*fallthrough*/
|
||||
case 0: code_gen_level = LLVMCodeGenLevelNone; break;
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include <llvm/Config/llvm-config.h>
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR < 17
|
||||
#error "LLVM Version 17 is the minimum required"
|
||||
#endif
|
||||
|
||||
#include <llvm-c/Core.h>
|
||||
#include <llvm-c/ExecutionEngine.h>
|
||||
#include <llvm-c/Target.h>
|
||||
@@ -11,46 +15,14 @@
|
||||
#include <llvm-c/Object.h>
|
||||
#include <llvm-c/BitWriter.h>
|
||||
#include <llvm-c/DebugInfo.h>
|
||||
#if LLVM_VERSION_MAJOR >= 17
|
||||
#include <llvm-c/Transforms/PassBuilder.h>
|
||||
#else
|
||||
#include <llvm-c/Transforms/AggressiveInstCombine.h>
|
||||
#include <llvm-c/Transforms/InstCombine.h>
|
||||
#include <llvm-c/Transforms/IPO.h>
|
||||
#include <llvm-c/Transforms/PassManagerBuilder.h>
|
||||
#include <llvm-c/Transforms/Scalar.h>
|
||||
#include <llvm-c/Transforms/Utils.h>
|
||||
#include <llvm-c/Transforms/Vectorize.h>
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR < 14
|
||||
#error "LLVM Version 14 is the minimum required"
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR > 14 || (LLVM_VERSION_MAJOR == 14 && LLVM_VERSION_MINOR >= 0 && LLVM_VERSION_PATCH > 0)
|
||||
#define ODIN_LLVM_MINIMUM_VERSION_14 1
|
||||
#else
|
||||
#define ODIN_LLVM_MINIMUM_VERSION_14 0
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR == 15 || LLVM_VERSION_MAJOR == 16
|
||||
#error "LLVM versions 15 and 16 are not supported"
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 17
|
||||
#define LB_USE_NEW_PASS_SYSTEM 1
|
||||
#else
|
||||
#define LB_USE_NEW_PASS_SYSTEM 0
|
||||
#endif
|
||||
|
||||
#if LLVM_VERSION_MAJOR >= 19
|
||||
#define LLVMDIBuilderInsertDeclareAtEnd(...) LLVMDIBuilderInsertDeclareRecordAtEnd(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
gb_internal bool lb_use_new_pass_system(void) {
|
||||
return LB_USE_NEW_PASS_SYSTEM;
|
||||
}
|
||||
|
||||
struct lbProcedure;
|
||||
|
||||
struct lbValue {
|
||||
@@ -408,13 +380,6 @@ struct lbProcedure {
|
||||
#define ABI_PKG_NAME_SEPARATOR "."
|
||||
#endif
|
||||
|
||||
|
||||
#if !ODIN_LLVM_MINIMUM_VERSION_14
|
||||
#define LLVMConstGEP2(Ty__, ConstantVal__, ConstantIndices__, NumIndices__) LLVMConstGEP(ConstantVal__, ConstantIndices__, NumIndices__)
|
||||
#define LLVMConstInBoundsGEP2(Ty__, ConstantVal__, ConstantIndices__, NumIndices__) LLVMConstInBoundsGEP(ConstantVal__, ConstantIndices__, NumIndices__)
|
||||
#define LLVMBuildPtrDiff2(Builder__, Ty__, LHS__, RHS__, Name__) LLVMBuildPtrDiff(Builder__, LHS__, RHS__, Name__)
|
||||
#endif
|
||||
|
||||
gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c);
|
||||
|
||||
gb_internal String lb_mangle_name(Entity *e);
|
||||
@@ -641,11 +606,7 @@ gb_internal lbValue lb_emit_source_code_location_as_global_ptr(lbProcedure *p, S
|
||||
gb_internal LLVMMetadataRef lb_debug_location_from_token_pos(lbProcedure *p, TokenPos pos);
|
||||
|
||||
gb_internal LLVMTypeRef llvm_array_type(LLVMTypeRef ElementType, uint64_t ElementCount) {
|
||||
#if LB_USE_NEW_PASS_SYSTEM
|
||||
return LLVMArrayType2(ElementType, ElementCount);
|
||||
#else
|
||||
return LLVMArrayType(ElementType, cast(unsigned)ElementCount);
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal lbValue lb_emit_struct_iv(lbProcedure *p, lbValue agg, lbValue field, i32 index);
|
||||
|
||||
@@ -109,46 +109,7 @@ gb_internal LLVMValueRef llvm_const_cast(lbModule *m, LLVMValueRef val, LLVMType
|
||||
return LLVMConstPointerCast(val, dst);
|
||||
}
|
||||
case LLVMStructTypeKind: {
|
||||
GB_ASSERT_MSG(lb_sizeof(dst) == lb_sizeof(src), "dst:%s vs src:%s (dst:%lld vs src:%lld)", LLVMPrintTypeToString(dst), LLVMPrintTypeToString(src),
|
||||
cast(long long)lb_sizeof(dst),
|
||||
cast(long long)lb_sizeof(src));
|
||||
|
||||
unsigned src_n = LLVMCountStructElementTypes(src);
|
||||
unsigned dst_n = LLVMCountStructElementTypes(dst);
|
||||
if (src_n != dst_n) goto failure;
|
||||
|
||||
if (LLVM_VERSION_MAJOR > 14) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
LLVMValueRef *field_vals = temporary_alloc_array<LLVMValueRef>(dst_n);
|
||||
for (unsigned i = 0; i < dst_n; i++) {
|
||||
LLVMValueRef field_val = llvm_const_extract_value(m, val, i);
|
||||
if (field_val == nullptr) goto failure;
|
||||
|
||||
LLVMTypeRef dst_elem_ty = LLVMStructGetTypeAtIndex(dst, i);
|
||||
LLVMTypeRef src_elem_ty = LLVMTypeOf(field_val);
|
||||
|
||||
if (lb_sizeof(dst_elem_ty) != lb_sizeof(src_elem_ty)) {
|
||||
goto failure;
|
||||
}
|
||||
|
||||
GB_ASSERT_MSG(lb_sizeof(dst_elem_ty) == lb_sizeof(src_elem_ty), "dst:%s vs src:%s (dst:%lld vs src:%lld) to %s from %s", LLVMPrintTypeToString(dst_elem_ty), LLVMPrintTypeToString(src_elem_ty),
|
||||
cast(long long)lb_sizeof(dst_elem_ty),
|
||||
cast(long long)lb_sizeof(src_elem_ty),
|
||||
LLVMPrintTypeToString(dst),
|
||||
LLVMPrintTypeToString(src)
|
||||
);
|
||||
|
||||
field_vals[i] = llvm_const_cast(m, field_val, dst_elem_ty, failure_);
|
||||
if (failure_ && *failure_) goto failure;
|
||||
}
|
||||
|
||||
if (!LLVMIsLiteralStruct(dst)) {
|
||||
return LLVMConstNamedStruct(dst, field_vals, dst_n);
|
||||
} else {
|
||||
return LLVMConstStructInContext(m->ctx, field_vals, dst_n, LLVMIsPackedStruct(dst));
|
||||
}
|
||||
goto failure;
|
||||
}
|
||||
case LLVMArrayTypeKind: {
|
||||
goto failure;
|
||||
@@ -621,104 +582,6 @@ gb_internal bool lb_is_nested_possibly_constant(Type *ft, Selection const &sel,
|
||||
return lb_is_elem_const(elem, ft);
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_MAJOR == 14
|
||||
LLVMValueRef llvm_const_pad_to_size(lbModule *m, LLVMValueRef val, LLVMTypeRef dst_ty) {
|
||||
LLVMContextRef ctx = m->ctx;
|
||||
LLVMTargetDataRef td = LLVMGetModuleDataLayout(m->mod);
|
||||
LLVMTypeRef src_ty = LLVMTypeOf(val);
|
||||
unsigned src_bits = (unsigned)LLVMSizeOfTypeInBits(td, src_ty);
|
||||
unsigned dst_bits = (unsigned)LLVMSizeOfTypeInBits(td, dst_ty);
|
||||
|
||||
LLVMValueRef as_int = nullptr;
|
||||
LLVMTypeKind src_kind = LLVMGetTypeKind(src_ty);
|
||||
|
||||
if (src_kind == LLVMIntegerTypeKind ||
|
||||
src_kind == LLVMFloatTypeKind ||
|
||||
src_kind == LLVMDoubleTypeKind ||
|
||||
src_kind == LLVMPointerTypeKind ||
|
||||
src_kind == LLVMVectorTypeKind) {
|
||||
LLVMTypeRef src_int_ty = LLVMIntTypeInContext(ctx, src_bits);
|
||||
as_int = LLVMConstBitCast(val, src_int_ty);
|
||||
|
||||
} else if (src_kind == LLVMArrayTypeKind) {
|
||||
unsigned elem_count = LLVMGetArrayLength(src_ty);
|
||||
LLVMTypeRef elem_ty = LLVMGetElementType(src_ty);
|
||||
unsigned elem_bits = (unsigned)LLVMSizeOfTypeInBits(td, elem_ty);
|
||||
LLVMTypeRef src_int_ty = LLVMIntTypeInContext(ctx, src_bits);
|
||||
as_int = LLVMConstInt(src_int_ty, 0, false);
|
||||
|
||||
for (unsigned i = 0; i < elem_count; i++) {
|
||||
LLVMValueRef elem = llvm_const_extract_value(m, val, i);
|
||||
LLVMTypeRef elem_int_ty = LLVMIntTypeInContext(ctx, elem_bits);
|
||||
LLVMValueRef elem_int = llvm_const_pad_to_size(m, elem, elem_int_ty);
|
||||
LLVMValueRef shifted = LLVMConstShl(LLVMConstZExt(elem_int, src_int_ty), LLVMConstInt(src_int_ty, i * elem_bits, false));
|
||||
as_int = LLVMConstOr(as_int, shifted);
|
||||
}
|
||||
} else if (src_kind == LLVMStructTypeKind) {
|
||||
unsigned field_count = LLVMCountStructElementTypes(src_ty);
|
||||
LLVMTypeRef src_int_ty = LLVMIntTypeInContext(ctx, src_bits);
|
||||
as_int = LLVMConstInt(src_int_ty, 0, false);
|
||||
|
||||
for (unsigned i = 0; i < field_count; i++) {
|
||||
LLVMTypeRef field_ty = LLVMStructGetTypeAtIndex(src_ty, i);
|
||||
unsigned field_bits = (unsigned)LLVMSizeOfTypeInBits(td, field_ty);
|
||||
LLVMValueRef field = llvm_const_extract_value(m, val, i);
|
||||
|
||||
LLVMTypeRef field_int_ty = LLVMIntTypeInContext(ctx, field_bits);
|
||||
LLVMValueRef field_int = llvm_const_pad_to_size(m, field, field_int_ty);
|
||||
|
||||
uint64_t field_offset_bytes = LLVMOffsetOfElement(td, src_ty, i);
|
||||
uint64_t field_offset_bits = field_offset_bytes * 8;
|
||||
|
||||
LLVMValueRef shifted = LLVMConstShl(LLVMConstZExt(field_int, src_int_ty), LLVMConstInt(src_int_ty, field_offset_bits, false));
|
||||
as_int = LLVMConstOr(as_int, shifted);
|
||||
}
|
||||
} else {
|
||||
gb_printf_err("unsupported const_pad source type: %s\n", LLVMPrintTypeToString(src_ty));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (src_bits != dst_bits) {
|
||||
LLVMTypeRef dst_int_ty = LLVMIntTypeInContext(ctx, dst_bits);
|
||||
if (src_bits < dst_bits) {
|
||||
as_int = LLVMConstZExt(as_int, dst_int_ty);
|
||||
} else {
|
||||
as_int = LLVMConstTrunc(as_int, dst_int_ty);
|
||||
}
|
||||
}
|
||||
|
||||
LLVMTypeKind dst_kind = LLVMGetTypeKind(dst_ty);
|
||||
|
||||
if (dst_kind == LLVMIntegerTypeKind ||
|
||||
dst_kind == LLVMFloatTypeKind ||
|
||||
dst_kind == LLVMDoubleTypeKind ||
|
||||
dst_kind == LLVMPointerTypeKind ||
|
||||
dst_kind == LLVMVectorTypeKind) {
|
||||
return LLVMConstBitCast(as_int, dst_ty);
|
||||
|
||||
} else if (dst_kind == LLVMArrayTypeKind) {
|
||||
unsigned elem_count = LLVMGetArrayLength(dst_ty);
|
||||
LLVMTypeRef elem_ty = LLVMGetElementType(dst_ty);
|
||||
unsigned elem_bits = (unsigned)LLVMSizeOfTypeInBits(td, elem_ty);
|
||||
|
||||
LLVMValueRef *elems = temporary_alloc_array<LLVMValueRef>(elem_count);
|
||||
LLVMTypeRef as_int_ty = LLVMTypeOf(as_int);
|
||||
|
||||
for (unsigned i = 0; i < elem_count; i++) {
|
||||
LLVMValueRef shifted = LLVMConstLShr(as_int, LLVMConstInt(as_int_ty, i * elem_bits, false));
|
||||
LLVMTypeRef elem_int_ty = LLVMIntTypeInContext(ctx, elem_bits);
|
||||
LLVMValueRef trunc = LLVMConstTrunc(shifted, elem_int_ty);
|
||||
elems[i] = llvm_const_pad_to_size(m, trunc, elem_ty);
|
||||
}
|
||||
|
||||
return LLVMConstArray(elem_ty, elems, elem_count);
|
||||
}
|
||||
|
||||
gb_printf_err("unsupported const_pad destination type: %s\n", LLVMPrintTypeToString(dst_ty));
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
gb_internal void lb_const_array_spread(lbModule *m, lbConstContext cc, Type *array, ExactValue value, lbValue *res, Type *value_type) {
|
||||
GB_ASSERT(array->kind == Type_Array);
|
||||
|
||||
@@ -1053,16 +916,11 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, Ty
|
||||
LLVMValueRef values[4] = {};
|
||||
unsigned value_count = 0;
|
||||
|
||||
#if LLVM_VERSION_MAJOR == 14
|
||||
LLVMTypeRef block_type = lb_type_internal_union_block_type(m, bt);
|
||||
values[value_count++] = llvm_const_pad_to_size(m, cv.value, block_type);
|
||||
#else
|
||||
values[value_count++] = cv.value;
|
||||
if (block_size != type_size_of(variant_type)) {
|
||||
LLVMTypeRef padding_type = lb_type_padding_filler(m, block_size - type_size_of(variant_type), 1);
|
||||
values[value_count++] = LLVMConstNull(padding_type);
|
||||
}
|
||||
#endif
|
||||
|
||||
Type *tag_type = union_tag_type(bt);
|
||||
LLVMTypeRef llvm_tag_type = lb_type(m, tag_type);
|
||||
|
||||
@@ -166,10 +166,6 @@ gb_internal bool lb_init_generator(lbGenerator *gen, Checker *c) {
|
||||
String init_fullpath = c->parser->init_fullpath;
|
||||
linker_data_init(gen, &c->info, init_fullpath);
|
||||
|
||||
#if defined(GB_SYSTEM_OSX) && (LLVM_VERSION_MAJOR < 14)
|
||||
linker_enable_system_library_linking(gen);
|
||||
#endif
|
||||
|
||||
gen->info = &c->info;
|
||||
|
||||
map_init(&gen->modules, gen->info->packages.count*2);
|
||||
|
||||
@@ -32,11 +32,6 @@
|
||||
**************************************************************************/
|
||||
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level);
|
||||
gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level);
|
||||
gb_internal void lb_populate_module_pass_manager(LLVMTargetMachineRef target_machine, LLVMPassManagerRef mpm, i32 optimization_level);
|
||||
gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level);
|
||||
|
||||
// gb_internal LLVMBool lb_must_preserve_predicate_callback(LLVMValueRef value, void *user_data) {
|
||||
// lbModule *m = cast(lbModule *)user_data;
|
||||
// if (m == nullptr) {
|
||||
@@ -48,221 +43,6 @@ gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPas
|
||||
// return LLVMIsAAllocaInst(value) != nullptr;
|
||||
// }
|
||||
|
||||
gb_internal bool lb_opt_ignore(i32 optimization_level) {
|
||||
return optimization_level < 0;
|
||||
}
|
||||
|
||||
gb_internal void lb_basic_populate_function_pass_manager(LLVMPassManagerRef fpm, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (false && optimization_level <= 0 && build_context.ODIN_DEBUG) {
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
} else {
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
if (!build_context.ODIN_DEBUG) {
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager(lbModule *m, LLVMPassManagerRef fpm, bool ignore_memcpy_pass, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (ignore_memcpy_pass) {
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
} else if (optimization_level <= 0) {
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderPopulateFunctionPassManager(pmb, fpm);
|
||||
#else
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
|
||||
LLVMAddSCCPPass(fpm);
|
||||
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddUnifyFunctionExitNodesPass(fpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
LLVMAddLowerExpectIntrinsicPass(fpm);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_populate_function_pass_manager_specific(lbModule *m, LLVMPassManagerRef fpm, i32 optimization_level) {
|
||||
if (lb_opt_ignore(optimization_level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
if (optimization_level <= 0) {
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
lb_basic_populate_function_pass_manager(fpm, optimization_level);
|
||||
return;
|
||||
}
|
||||
|
||||
#if 1
|
||||
LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderSetSizeLevel(pmb, optimization_level);
|
||||
LLVMPassManagerBuilderPopulateFunctionPassManager(pmb, fpm);
|
||||
#else
|
||||
LLVMAddMemCpyOptPass(fpm);
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
|
||||
LLVMAddMergedLoadStoreMotionPass(fpm);
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
|
||||
LLVMAddSCCPPass(fpm);
|
||||
|
||||
LLVMAddPromoteMemoryToRegisterPass(fpm);
|
||||
LLVMAddUnifyFunctionExitNodesPass(fpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(fpm);
|
||||
LLVMAddEarlyCSEPass(fpm);
|
||||
LLVMAddLowerExpectIntrinsicPass(fpm);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
gb_internal void lb_add_function_simplifcation_passes(LLVMPassManagerRef mpm, i32 optimization_level) {
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddJumpThreadingPass(mpm);
|
||||
|
||||
LLVMAddSimplifyLibCallsPass(mpm);
|
||||
|
||||
LLVMAddTailCallEliminationPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
LLVMAddReassociatePass(mpm);
|
||||
|
||||
LLVMAddLoopRotatePass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
LLVMAddLoopUnswitchPass(mpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
LLVMAddLoopIdiomPass(mpm);
|
||||
LLVMAddLoopDeletionPass(mpm);
|
||||
|
||||
LLVMAddMergedLoadStoreMotionPass(mpm);
|
||||
|
||||
LLVMAddMemCpyOptPass(mpm);
|
||||
LLVMAddSCCPPass(mpm);
|
||||
|
||||
LLVMAddBitTrackingDCEPass(mpm);
|
||||
|
||||
LLVMAddJumpThreadingPass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
|
||||
LLVMAddLoopRerollPass(mpm);
|
||||
LLVMAddAggressiveDCEPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
gb_internal 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
|
||||
if (optimization_level <= 0 && build_context.ODIN_DEBUG) {
|
||||
return;
|
||||
}
|
||||
#if !LB_USE_NEW_PASS_SYSTEM
|
||||
LLVMAddAlwaysInlinerPass(mpm);
|
||||
LLVMAddStripDeadPrototypesPass(mpm);
|
||||
LLVMAddAnalysisPasses(target_machine, mpm);
|
||||
LLVMAddPruneEHPass(mpm);
|
||||
if (optimization_level <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
// NOTE(bill, 2021-03-29: use this causes invalid code generation)
|
||||
// LLVMPassManagerBuilderRef pmb = LLVMPassManagerBuilderCreate();
|
||||
// LLVMPassManagerBuilderSetOptLevel(pmb, optimization_level);
|
||||
// LLVMPassManagerBuilderPopulateModulePassManager(pmb, mpm);
|
||||
// LLVMPassManagerBuilderPopulateLTOPassManager(pmb, mpm, false, true);
|
||||
// return;
|
||||
}
|
||||
|
||||
|
||||
LLVMAddIPSCCPPass(mpm);
|
||||
LLVMAddCalledValuePropagationPass(mpm);
|
||||
|
||||
LLVMAddGlobalOptimizerPass(mpm);
|
||||
LLVMAddDeadArgEliminationPass(mpm);
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddPruneEHPass(mpm);
|
||||
if (optimization_level < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
LLVMAddFunctionInliningPass(mpm);
|
||||
|
||||
|
||||
lb_add_function_simplifcation_passes(mpm, optimization_level);
|
||||
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
LLVMAddGlobalOptimizerPass(mpm);
|
||||
|
||||
|
||||
LLVMAddLoopRotatePass(mpm);
|
||||
|
||||
LLVMAddLoopVectorizePass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
LLVMAddEarlyCSEPass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
LLVMAddLoopUnswitchPass(mpm);
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
}
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
|
||||
LLVMAddSLPVectorizePass(mpm);
|
||||
LLVMAddLICMPass(mpm);
|
||||
|
||||
LLVMAddAlignmentFromAssumptionsPass(mpm);
|
||||
|
||||
LLVMAddStripDeadPrototypesPass(mpm);
|
||||
|
||||
if (optimization_level >= 2) {
|
||||
LLVMAddGlobalDCEPass(mpm);
|
||||
LLVMAddConstantMergePass(mpm);
|
||||
}
|
||||
|
||||
LLVMAddCFGSimplificationPass(mpm);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
IMPORTANT NOTE(bill, 2021-11-06): Custom Passes
|
||||
|
||||
|
||||
@@ -968,8 +968,7 @@ gb_internal lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue
|
||||
for (unsigned i = 0; i < param_count; i++) {
|
||||
LLVMTypeRef param_type = param_types[i];
|
||||
LLVMTypeRef arg_type = LLVMTypeOf(args[i]);
|
||||
if (LB_USE_NEW_PASS_SYSTEM &&
|
||||
arg_type != param_type) {
|
||||
if (arg_type != param_type) {
|
||||
LLVMTypeKind arg_kind = LLVMGetTypeKind(arg_type);
|
||||
LLVMTypeKind param_kind = LLVMGetTypeKind(param_type);
|
||||
if (arg_kind == param_kind) {
|
||||
|
||||
14
src/main.cpp
14
src/main.cpp
@@ -875,7 +875,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
} else if (value.value_string == "speed") {
|
||||
build_context.custom_optimization_level = true;
|
||||
build_context.optimization_level = 2;
|
||||
} else if (value.value_string == "aggressive" && LB_USE_NEW_PASS_SYSTEM) {
|
||||
} else if (value.value_string == "aggressive") {
|
||||
build_context.custom_optimization_level = true;
|
||||
build_context.optimization_level = 3;
|
||||
} else {
|
||||
@@ -884,9 +884,7 @@ gb_internal bool parse_build_flags(Array<String> args) {
|
||||
gb_printf_err("\tminimal\n");
|
||||
gb_printf_err("\tsize\n");
|
||||
gb_printf_err("\tspeed\n");
|
||||
if (LB_USE_NEW_PASS_SYSTEM) {
|
||||
gb_printf_err("\taggressive\n");
|
||||
}
|
||||
gb_printf_err("\taggressive\n");
|
||||
gb_printf_err("\tnone (useful for -debug builds)\n");
|
||||
bad_flags = true;
|
||||
}
|
||||
@@ -3043,9 +3041,7 @@ gb_internal int print_show_help(String const arg0, String command, String option
|
||||
print_usage_line(3, "-o:minimal");
|
||||
print_usage_line(3, "-o:size");
|
||||
print_usage_line(3, "-o:speed");
|
||||
if (LB_USE_NEW_PASS_SYSTEM) {
|
||||
print_usage_line(3, "-o:aggressive (use this with caution)");
|
||||
}
|
||||
print_usage_line(2, "The default is -o:minimal. If -debug is set, the default is -o:none.");
|
||||
}
|
||||
|
||||
@@ -4221,12 +4217,6 @@ int main(int arg_count, char const **arg_ptr) {
|
||||
gb_printf_err("missing required target feature: \"%.*s\", enable it by setting a different -microarch or explicitly adding it through -target-features\n", LIT(disabled));
|
||||
gb_exit(1);
|
||||
}
|
||||
|
||||
// NOTE(laytan): some weird errors on LLVM 14 that LLVM 17 fixes.
|
||||
if (LLVM_VERSION_MAJOR < 17) {
|
||||
gb_printf_err("Invalid LLVM version %s, RISC-V targets require at least LLVM 17\n", LLVM_VERSION_STRING);
|
||||
gb_exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (build_context.show_debug_messages) {
|
||||
|
||||
Reference in New Issue
Block a user