Skip to content

Commit

Permalink
Support LLVM 20 (#15412)
Browse files Browse the repository at this point in the history
Tested using version `20.1.0~++20250202013302+1eb7f4e6b461-1~exp1~20250202013426.11` from the official Apt repository, a few days beyond the RC1 release.

Since Crystal has never used the MMX register type during LLVM IR generation, no major changes are needed.
  • Loading branch information
HertzDevil authored Feb 5, 2025
1 parent 1fafbb2 commit 1c03dfa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
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

0 comments on commit 1c03dfa

Please sign in to comment.