From 15a11aedd588fed658507a31140049bf563b0b3d Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Mon, 11 Dec 2023 20:14:01 +0800 Subject: [PATCH] LLVM 18 dev C APIs --- src/llvm/builder.cr | 10 +++++----- src/llvm/lib_llvm.cr | 2 ++ src/llvm/lib_llvm/core.cr | 10 ++++++++++ src/llvm/lib_llvm_ext.cr | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/llvm/builder.cr b/src/llvm/builder.cr index a6aab1d8872e..741f9ee8eb5c 100644 --- a/src/llvm/builder.cr +++ b/src/llvm/builder.cr @@ -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 = "") @@ -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) @@ -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) @@ -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 = "") @@ -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) diff --git a/src/llvm/lib_llvm.cr b/src/llvm/lib_llvm.cr index 3acff22ef324..a4c55f2473a4 100644 --- a/src/llvm/lib_llvm.cr +++ b/src/llvm/lib_llvm.cr @@ -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")}} @@ -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 %} diff --git a/src/llvm/lib_llvm/core.cr b/src/llvm/lib_llvm/core.cr index a0cfb708d515..5c7d7d519267 100644 --- a/src/llvm/lib_llvm/core.cr +++ b/src/llvm/lib_llvm/core.cr @@ -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 @@ -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 @@ -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 diff --git a/src/llvm/lib_llvm_ext.cr b/src/llvm/lib_llvm_ext.cr index 5a45e1e2218e..5730d81d8c4c 100644 --- a/src/llvm/lib_llvm_ext.cr +++ b/src/llvm/lib_llvm_ext.cr @@ -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