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

Add LLVM::OperandBundleDef#dispose #14095

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
6 changes: 5 additions & 1 deletion src/compiler/crystal/codegen/crystal_llvm_builder.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ module Crystal
funclet = LLVM::OperandBundleDef.null
end

call @printf, [global_string_pointer(format)] + args, bundle: funclet
begin
call @printf, [global_string_pointer(format)] + args, bundle: funclet
ensure
funclet.dispose
end
end

def position_at_end(block)
Expand Down
12 changes: 10 additions & 2 deletions src/compiler/crystal/codegen/llvm_builder_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ module Crystal
funclet = LLVM::OperandBundleDef.null
end

builder.call(func.type, func.func, args, bundle: funclet, name: name)
begin
builder.call(func.type, func.func, args, bundle: funclet, name: name)
ensure
funclet.dispose
end
end

def invoke(func : LLVMTypedFunction, args : Array(LLVM::Value), a_then, a_catch, name : String = "")
Expand All @@ -138,7 +142,11 @@ module Crystal
funclet = LLVM::OperandBundleDef.null
end

builder.invoke(func.type, func.func, args, a_then, a_catch, bundle: funclet, name: name)
begin
builder.invoke(func.type, func.func, args, a_then, a_catch, bundle: funclet, name: name)
ensure
funclet.dispose
end
end

delegate ptr2int, int2ptr, and, or, not, bit_cast,
Expand Down
4 changes: 4 additions & 0 deletions src/llvm/ext/llvm_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ LLVMOperandBundleRef LLVMExtCreateOperandBundle(const char *Tag, size_t TagLen,
makeArrayRef(unwrap(Args), NumArgs)));
}

void LLVMExtDisposeOperandBundle(LLVMOperandBundleRef Bundle) {
delete unwrap(Bundle);
}

LLVMValueRef
LLVMExtBuildCallWithOperandBundles(LLVMBuilderRef B, LLVMTypeRef Ty,
LLVMValueRef Fn, LLVMValueRef *Args,
Expand Down
1 change: 1 addition & 0 deletions src/llvm/lib_llvm/core.cr
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ lib LibLLVM

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

fun get_basic_block_name = LLVMGetBasicBlockName(bb : BasicBlockRef) : Char*
Expand Down
2 changes: 2 additions & 0 deletions src/llvm/lib_llvm_ext.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ lib LibLLVMExt
args : LibLLVM::ValueRef*,
num_args : UInt) : LibLLVM::OperandBundleRef

fun dispose_operand_bundle = LLVMExtDisposeOperandBundle(bundle : LibLLVM::OperandBundleRef)

fun build_call_with_operand_bundles = LLVMExtBuildCallWithOperandBundles(LibLLVM::BuilderRef, LibLLVM::TypeRef, fn : LibLLVM::ValueRef,
args : LibLLVM::ValueRef*, num_args : UInt,
bundles : LibLLVM::OperandBundleRef*, num_bundles : UInt,
Expand Down
4 changes: 4 additions & 0 deletions src/llvm/operand_bundle_def.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ struct LLVM::OperandBundleDef
def to_unsafe
@unwrap
end

def dispose
{{ LibLLVM::IS_LT_180 ? LibLLVMExt : LibLLVM }}.dispose_operand_bundle(@unwrap) if @unwrap
end
end