Skip to content

Commit

Permalink
LLVM 18 dev C APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Dec 11, 2023
1 parent 60fedcf commit 15a11ae
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/llvm/builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LLVM::Builder
bundle_ref = bundle.to_unsafe
bundles = bundle_ref ? pointerof(bundle_ref) : Pointer(Void).null.as(LibLLVM::OperandBundleRef*)
num_bundles = bundle_ref ? 1 : 0
Value.new LibLLVMExt.build_call_with_operand_bundles(self, func.function_type, func, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, bundles, num_bundles, name)
Value.new {{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.build_call_with_operand_bundles(self, func.function_type, func, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, bundles, num_bundles, name)
end

def call(type : LLVM::Type, func : LLVM::Function, args : Array(LLVM::Value), name : String = "")
Expand All @@ -108,7 +108,7 @@ class LLVM::Builder
bundle_ref = bundle.to_unsafe
bundles = bundle_ref ? pointerof(bundle_ref) : Pointer(Void).null.as(LibLLVM::OperandBundleRef*)
num_bundles = bundle_ref ? 1 : 0
Value.new LibLLVMExt.build_call_with_operand_bundles(self, type, func, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, bundles, num_bundles, name)
Value.new {{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.build_call_with_operand_bundles(self, type, func, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, bundles, num_bundles, name)
end

def call(type : LLVM::Type, func : LLVM::Function, args : Array(LLVM::Value), bundle : LLVM::OperandBundleDef)
Expand Down Expand Up @@ -285,7 +285,7 @@ class LLVM::Builder
end

def build_operand_bundle_def(name, values : Array(LLVM::Value))
LLVM::OperandBundleDef.new LibLLVMExt.create_operand_bundle(name, name.bytesize, values.to_unsafe.as(LibLLVM::ValueRef*), values.size)
LLVM::OperandBundleDef.new {{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.create_operand_bundle(name, name.bytesize, values.to_unsafe.as(LibLLVM::ValueRef*), values.size)
end

def build_catch_ret(pad, basic_block)
Expand All @@ -299,7 +299,7 @@ class LLVM::Builder
bundle_ref = bundle.to_unsafe
bundles = bundle_ref ? pointerof(bundle_ref) : Pointer(Void).null.as(LibLLVM::OperandBundleRef*)
num_bundles = bundle_ref ? 1 : 0
Value.new LibLLVMExt.build_invoke_with_operand_bundles(self, fn.function_type, fn, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, a_then, a_catch, bundles, num_bundles, name)
Value.new {{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.build_invoke_with_operand_bundles(self, fn.function_type, fn, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, a_then, a_catch, bundles, num_bundles, name)
end

def invoke(type : LLVM::Type, fn : LLVM::Function, args : Array(LLVM::Value), a_then, a_catch, *, name = "")
Expand All @@ -316,7 +316,7 @@ class LLVM::Builder
bundle_ref = bundle.to_unsafe
bundles = bundle_ref ? pointerof(bundle_ref) : Pointer(Void).null.as(LibLLVM::OperandBundleRef*)
num_bundles = bundle_ref ? 1 : 0
Value.new LibLLVMExt.build_invoke_with_operand_bundles(self, type, fn, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, a_then, a_catch, bundles, num_bundles, name)
Value.new {{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.build_invoke_with_operand_bundles(self, type, fn, (args.to_unsafe.as(LibLLVM::ValueRef*)), args.size, a_then, a_catch, bundles, num_bundles, name)
end

def switch(value, otherwise, cases)
Expand Down
2 changes: 2 additions & 0 deletions src/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end

{% begin %}
lib LibLLVM
IS_180 = {{LibLLVM::VERSION.starts_with?("18.0")}}
IS_170 = {{LibLLVM::VERSION.starts_with?("17.0")}}
IS_160 = {{LibLLVM::VERSION.starts_with?("16.0")}}
IS_150 = {{LibLLVM::VERSION.starts_with?("15.0")}}
Expand All @@ -40,6 +41,7 @@ end
IS_LT_150 = {{compare_versions(LibLLVM::VERSION, "15.0.0") < 0}}
IS_LT_160 = {{compare_versions(LibLLVM::VERSION, "16.0.0") < 0}}
IS_LT_170 = {{compare_versions(LibLLVM::VERSION, "17.0.0") < 0}}
IS_LT_180 = {{compare_versions(LibLLVM::VERSION, "18.0.0") < 0}}
end
{% end %}

Expand Down
10 changes: 10 additions & 0 deletions src/llvm/lib_llvm/core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ lib LibLLVM
fun md_string_in_context = LLVMMDStringInContext(c : ContextRef, str : Char*, s_len : UInt) : ValueRef
fun md_node_in_context = LLVMMDNodeInContext(c : ContextRef, vals : ValueRef*, count : UInt) : ValueRef

{% unless LibLLVM::IS_LT_180 %}
fun create_operand_bundle = LLVMCreateOperandBundle(tag : Char*, tag_len : SizeT, args : ValueRef*, num_args : UInt) : OperandBundleRef
{% end %}

fun get_basic_block_name = LLVMGetBasicBlockName(bb : BasicBlockRef) : Char*
fun get_first_basic_block = LLVMGetFirstBasicBlock(fn : ValueRef) : BasicBlockRef
fun get_next_basic_block = LLVMGetNextBasicBlock(bb : BasicBlockRef) : BasicBlockRef
Expand Down Expand Up @@ -197,6 +201,9 @@ lib LibLLVM
fun build_cond = LLVMBuildCondBr(BuilderRef, if : ValueRef, then : BasicBlockRef, else : BasicBlockRef) : ValueRef
fun build_switch = LLVMBuildSwitch(BuilderRef, v : ValueRef, else : BasicBlockRef, num_cases : UInt) : ValueRef
fun build_invoke2 = LLVMBuildInvoke2(BuilderRef, ty : TypeRef, fn : ValueRef, args : ValueRef*, num_args : UInt, then : BasicBlockRef, catch : BasicBlockRef, name : Char*) : ValueRef
{% unless LibLLVM::IS_LT_180 %}
fun build_invoke_with_operand_bundles = LLVMBuildInvokeWithOperandBundles(BuilderRef, ty : TypeRef, fn : ValueRef, args : ValueRef*, num_args : UInt, then : BasicBlockRef, catch : BasicBlockRef, bundles : OperandBundleRef*, num_bundles : UInt, name : Char*) : ValueRef
{% end %}
fun build_unreachable = LLVMBuildUnreachable(BuilderRef) : ValueRef

fun build_landing_pad = LLVMBuildLandingPad(b : BuilderRef, ty : TypeRef, pers_fn : ValueRef, num_clauses : UInt, name : Char*) : ValueRef
Expand Down Expand Up @@ -260,6 +267,9 @@ lib LibLLVM

fun build_phi = LLVMBuildPhi(BuilderRef, ty : TypeRef, name : Char*) : ValueRef
fun build_call2 = LLVMBuildCall2(BuilderRef, TypeRef, fn : ValueRef, args : ValueRef*, num_args : UInt, name : Char*) : ValueRef
{% unless LibLLVM::IS_LT_180 %}
fun build_call_with_operand_bundles = LLVMBuildCallWithOperandBundles(BuilderRef, TypeRef, fn : ValueRef, args : ValueRef*, num_args : UInt, bundles : OperandBundleRef*, num_bundles : UInt, name : Char*) : ValueRef
{% end %}
fun build_select = LLVMBuildSelect(BuilderRef, if : ValueRef, then : ValueRef, else : ValueRef, name : Char*) : ValueRef
fun build_va_arg = LLVMBuildVAArg(BuilderRef, list : ValueRef, ty : TypeRef, name : Char*) : ValueRef
fun build_extract_value = LLVMBuildExtractValue(BuilderRef, agg_val : ValueRef, index : UInt, name : Char*) : ValueRef
Expand Down
2 changes: 1 addition & 1 deletion src/llvm/lib_llvm_ext.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ lib LibLLVMExt

fun build_invoke_with_operand_bundles = LLVMExtBuildInvokeWithOperandBundles(LibLLVM::BuilderRef, ty : LibLLVM::TypeRef, fn : LibLLVM::ValueRef,
args : LibLLVM::ValueRef*, num_args : UInt,
then : LibLLVM::BasicBlockRef, catch : LibLLVM::BasicBlockRef,
then : LibLLVM::BasicBlockRef, catch : LibLLVM::BasicBlockRef,
bundles : LibLLVM::OperandBundleRef*, num_bundles : UInt,
name : Char*) : LibLLVM::ValueRef

Expand Down

0 comments on commit 15a11ae

Please sign in to comment.