Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LLVM 20 #15412

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/llvm/enums.cr
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ module LLVM
Pointer
Vector
Metadata
X86_MMX
X86_MMX # deleted in LLVM 20
Token
ScalableVector
BFloat
X86_AMX
TargetExt
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/llvm/ext/llvm-versions.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0
20.1 19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0
8 changes: 7 additions & 1 deletion src/llvm/function_collection.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ struct LLVM::FunctionCollection
end

def []?(name)
func = LibLLVM.get_named_function(@mod, name)
func =
{% if LibLLVM::IS_LT_200 %}
LibLLVM.get_named_function(@mod, name)
{% else %}
LibLLVM.get_named_function_with_length(@mod, name, name.bytesize)
{% end %}

func ? Function.new(func) : nil
end

Expand Down
8 changes: 7 additions & 1 deletion src/llvm/global_collection.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ struct LLVM::GlobalCollection
end

def []?(name)
global = LibLLVM.get_named_global(@mod, name)
global =
{% if LibLLVM::IS_LT_200 %}
LibLLVM.get_named_global(@mod, name)
{% else %}
LibLLVM.get_named_global_with_length(@mod, name, name.bytesize)
{% end %}

global ? Value.new(global) : nil
end

Expand Down
1 change: 1 addition & 0 deletions src/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
IS_LT_170 = {{compare_versions(LibLLVM::VERSION, "17.0.0") < 0}}
IS_LT_180 = {{compare_versions(LibLLVM::VERSION, "18.0.0") < 0}}
IS_LT_190 = {{compare_versions(LibLLVM::VERSION, "19.0.0") < 0}}
IS_LT_200 = {{compare_versions(LibLLVM::VERSION, "20.0.0") < 0}}
end
{% end %}

Expand Down
12 changes: 10 additions & 2 deletions src/llvm/lib_llvm/core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ lib LibLLVM
fun get_module_context = LLVMGetModuleContext(m : ModuleRef) : ContextRef

fun add_function = LLVMAddFunction(m : ModuleRef, name : Char*, function_ty : TypeRef) : ValueRef
fun get_named_function = LLVMGetNamedFunction(m : ModuleRef, name : Char*) : ValueRef
{% if LibLLVM::IS_LT_200 %}
fun get_named_function = LLVMGetNamedFunction(m : ModuleRef, name : Char*) : ValueRef
{% else %}
fun get_named_function_with_length = LLVMGetNamedFunctionWithLength(m : ModuleRef, name : Char*, length : SizeT) : ValueRef
{% end %}
fun get_first_function = LLVMGetFirstFunction(m : ModuleRef) : ValueRef
fun get_next_function = LLVMGetNextFunction(fn : ValueRef) : ValueRef

Expand Down Expand Up @@ -144,7 +148,11 @@ lib LibLLVM
fun set_alignment = LLVMSetAlignment(v : ValueRef, bytes : UInt)

fun add_global = LLVMAddGlobal(m : ModuleRef, ty : TypeRef, name : Char*) : ValueRef
fun get_named_global = LLVMGetNamedGlobal(m : ModuleRef, name : Char*) : ValueRef
{% if LibLLVM::IS_LT_200 %}
fun get_named_global = LLVMGetNamedGlobal(m : ModuleRef, name : Char*) : ValueRef
{% else %}
fun get_named_global_with_length = LLVMGetNamedGlobalWithLength(m : ModuleRef, name : Char*, length : SizeT) : ValueRef
{% end %}
fun get_initializer = LLVMGetInitializer(global_var : ValueRef) : ValueRef
fun set_initializer = LLVMSetInitializer(global_var : ValueRef, constant_val : ValueRef)
fun is_thread_local = LLVMIsThreadLocal(global_var : ValueRef) : Bool
Expand Down