Skip to content

Commit

Permalink
Add names to object emission (#1789)
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmoses committed Sep 4, 2024
1 parent cdc790d commit 8dde034
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ declare_allocobj!(mod) = get_function!(mod, "julia.gc_alloc_obj") do
LLVM.FunctionType(T_prjlvalue, [T_ppjlvalue, T_size_t, T_prjlvalue])
end
end
function emit_allocobj!(B, tag::LLVM.Value, Size::LLVM.Value, needs_workaround::Bool)
function emit_allocobj!(B, tag::LLVM.Value, Size::LLVM.Value, needs_workaround::Bool, name::String="")
curent_bb = position(B)
fn = LLVM.parent(curent_bb)
mod = LLVM.parent(fn)
Expand Down Expand Up @@ -792,12 +792,12 @@ function emit_allocobj!(B, tag::LLVM.Value, Size::LLVM.Value, needs_workaround::
alloc_obj, alty = declare_allocobj!(mod)

@static if VERSION < v"1.8.0"
return call!(B, alty, alloc_obj, [ptls, Size, tag])
return call!(B, alty, alloc_obj, [ptls, Size, tag], name)
else
return call!(B, alty, alloc_obj, [ct, Size, tag])
return call!(B, alty, alloc_obj, [ct, Size, tag], name)
end
end
function emit_allocobj!(B, T::DataType)
function emit_allocobj!(B, T::DataType, name::String="")
curent_bb = position(B)
fn = LLVM.parent(curent_bb)
mod = LLVM.parent(fn)
Expand All @@ -811,7 +811,7 @@ function emit_allocobj!(B, T::DataType)

T_size_t = convert(LLVM.LLVMType, UInt)
Size = LLVM.ConstantInt(T_size_t, sizeof(T))
emit_allocobj!(B, tag, Size, #=needs_workaround=#false)
emit_allocobj!(B, tag, Size, #=needs_workaround=#false, name)
end
declare_pointerfromobjref!(mod) = get_function!(mod, "julia.pointer_from_objref") do
T_jlvalue = LLVM.StructType(LLVMType[])
Expand Down Expand Up @@ -4499,7 +4499,7 @@ function create_abi_wrapper(enzymefn::LLVM.Function, TT, rettype, actualRetType,
convty = convert(LLVMType, T′; allow_boxed=true)

if (T <: MixedDuplicated || T <: BatchMixedDuplicated) && !isboxed # && (isa(llty, LLVM.ArrayType) || isa(llty, LLVM.StructType))
al0 = al = emit_allocobj!(builder, Base.RefValue{T′})
al0 = al = emit_allocobj!(builder, Base.RefValue{T′}, "mixedparameter")
al = bitcast!(builder, al, LLVM.PointerType(llty, addrspace(value_type(al))))
store!(builder, params[i], al)
emit_writebarrier!(builder, get_julia_inner_types(builder, al0, params[i]))
Expand Down Expand Up @@ -4649,7 +4649,7 @@ function create_abi_wrapper(enzymefn::LLVM.Function, TT, rettype, actualRetType,
ival = UndefValue(LLVM.LLVMType(API.EnzymeGetShadowType(width, T_prjlvalue)))
for idx in 1:width
pv = (width == 1) ? eval : extract_value!(builder, eval, idx-1)
al0 = al = emit_allocobj!(builder, Base.RefValue{eltype(rettype)})
al0 = al = emit_allocobj!(builder, Base.RefValue{eltype(rettype)}, "batchmixedret")
llty = value_type(pv)
al = bitcast!(builder, al, LLVM.PointerType(llty, addrspace(value_type(al))))
store!(builder, pv, al)
Expand Down Expand Up @@ -5236,9 +5236,10 @@ function lower_convention(functy::Type, mod::LLVM.Module, entry_f::LLVM.Function
if arg.arg_i in loweredArgs
push!(nops, load!(builder, convert(LLVMType, arg.typ), parm))
elseif arg.arg_i in raisedArgs
obj = emit_allocobj!(builder, arg.typ)
obj = emit_allocobj!(builder, arg.typ, "raisedArg")
bc = bitcast!(builder, obj, LLVM.PointerType(value_type(parm), addrspace(value_type(obj))))
store!(builder, parm, bc)
emit_writebarrier!(builder, get_julia_inner_types(builder, obj, parm))
addr = addrspacecast!(builder, bc, LLVM.PointerType(value_type(parm), Derived))
push!(nops, addr)
else
Expand Down Expand Up @@ -5374,7 +5375,7 @@ function lower_convention(functy::Type, mod::LLVM.Module, entry_f::LLVM.Function
ret!(builder, fill_val)
else
nobj = if sretPtr !== nothing
obj = emit_allocobj!(builder, jlrettype)
obj = emit_allocobj!(builder, jlrettype, "boxunion")
llty = convert(LLVMType, jlrettype)
ld = load!(builder, llty, bitcast!(builder, sretPtr, LLVM.PointerType(llty, addrspace(value_type(sretPtr)))))
store!(builder, ld, bitcast!(builder, obj, LLVM.PointerType(llty, addrspace(value_type(obj)))))
Expand Down

2 comments on commit 8dde034

@wsmoses
Copy link
Member Author

@wsmoses wsmoses commented on 8dde034 Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/114495

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.36 -m "<description of version>" 8dde0343d7b4fdc92ecf4fe4fafd7e7df7cf1427
git push origin v0.12.36

Please sign in to comment.