LLVM 14 removal cleanup

This commit is contained in:
Jeroen van Rijn
2026-06-30 21:12:42 +02:00
parent eb03ed0bbb
commit 40b28a2ded
4 changed files with 9 additions and 178 deletions

View File

@@ -3,6 +3,7 @@ set -eu
SUPPORTED_LLVM_VERSIONS="22 21 20 19 18 17"
SUGGESTED_LLVM_VERSION="22"
MINIMUM_LLVM_VERSION="17"
: ${CPPFLAGS=}
: ${CXXFLAGS=}
@@ -94,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 17 ]; then
error "Invalid LLVM version $LLVM_VERSION: must be 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

View File

@@ -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,37 +15,11 @@
#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)
// These two are always available since we're on >= 17
#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__)

View File

@@ -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);

View File

@@ -4219,12 +4219,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) {