Skip to content

Commit

Permalink
Apply sugestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Oct 4, 2023
1 parent 06eb228 commit 78f50e3
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/allocfunc.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# List of methods to location of arg which is the mi/function, then start of args
const generic_method_offsets = Dict{String, Tuple{Int,Int}}(("jl_f__apply_latest" => (2,3), "ijl_f__apply_latest" => (2,3), "jl_f__call_latest" => (2,3), "ijl_f__call_latest" => (2,3), "jl_f_invoke" => (2,3), "jl_invoke" => (1,3), "jl_apply_generic" => (1,2), "ijl_f_invoke" => (2,3), "ijl_invoke" => (1,3), "ijl_apply_generic" => (1,2)))
const generic_method_offsets = Dict{String,Tuple{Int,Int}}(("jl_f__apply_latest" => (2, 3), "ijl_f__apply_latest" => (2, 3), "jl_f__call_latest" => (2, 3), "ijl_f__call_latest" => (2, 3), "jl_f_invoke" => (2, 3), "jl_invoke" => (1, 3), "jl_apply_generic" => (1, 2), "ijl_f_invoke" => (2, 3), "ijl_invoke" => (1, 3), "ijl_apply_generic" => (1, 2)))


const known_nonalloc_funcs = (
"jl_egal__unboxed", "ijl_egal__unboxed",
"jl_lock_value", "ijl_lock_value",
"jl_unlock_value", "ijl_unlock_value",
"jl_get_nth_field_noalloc", "ijl_get_nth_field_noalloc",
"jl_load_and_lookup","ijl_load_and_lookup",
"jl_lazy_load_and_lookup","ijl_lazy_load_and_lookup",
"jl_box_bool","ijl_box_bool",
"jl_box_int8","ijl_box_int8",
"jl_box_uint8","ijl_box_uint8",
"jl_load_and_lookup", "ijl_load_and_lookup",
"jl_lazy_load_and_lookup", "ijl_lazy_load_and_lookup",
"jl_box_bool", "ijl_box_bool",
"jl_box_int8", "ijl_box_int8",
"jl_box_uint8", "ijl_box_uint8",
r"(ijl|jl)_unbox.*"
)

function is_alloc_function(name)
maybe_alloc = occursin(r"(ijl_|jl_).*", name)
if maybe_alloc
any(x->contains(name, x), known_nonalloc_funcs) && return false
any(x -> contains(name, x), known_nonalloc_funcs) && return false
return true
end
return false
Expand Down Expand Up @@ -93,18 +93,16 @@ function rename_ir!(job, inst::LLVM.CallInst)
if occursin("bitcast", string(dest))
fn_got = LLVM.Value(LLVM.LLVM.API.LLVMGetOperand(fptr, 0))
fname = name(fn_got)
if startswith(fname, "jlplt_")
if startswith(fname, "jlplt_") && endswith(fname, "_got")
fname = fname[7:end]
fname = replace(fname, r"_\d+_got$" => "")
mod = LLVM.parent(LLVM.parent(LLVM.parent(inst)))
lfn = LLVM.API.LLVMGetNamedFunction(mod, fname)
if lfn == C_NULL
lfn = LLVM.API.LLVMAddFunction(mod, Symbol(fname), LLVM.API.LLVMGetCalledFunctionType(inst))
end
LLVM.API.LLVMSetOperand(inst, LLVM.API.LLVMGetNumOperands(inst) - 1, lfn)
end
mod = LLVM.parent(LLVM.parent(LLVM.parent(inst)))
lfn = LLVM.API.LLVMGetNamedFunction(mod, fname)
if lfn == C_NULL
lfn = LLVM.API.LLVMAddFunction(mod, Symbol(fname), LLVM.API.LLVMGetCalledFunctionType(inst))
else
lfn = LLVM.API.LLVMConstBitCast(lfn, LLVM.PointerType(LLVM.FunctionType(LLVM.API.LLVMGetCalledFunctionType(inst))))
end
LLVM.API.LLVMSetOperand(inst, LLVM.API.LLVMGetNumOperands(inst)-1, lfn)
end
end

Expand All @@ -130,10 +128,8 @@ function rename_ir!(job, inst::LLVM.CallInst)
lfn = LLVM.API.LLVMGetNamedFunction(mod, fn_str)
if lfn == C_NULL
lfn = LLVM.API.LLVMAddFunction(mod, fn, LLVM.API.LLVMGetCalledFunctionType(inst))
else
lfn = LLVM.API.LLVMConstBitCast(lfn, LLVM.PointerType(LLVM.FunctionType(LLVM.API.LLVMGetCalledFunctionType(inst))))
end
LLVM.API.LLVMSetOperand(inst, LLVM.API.LLVMGetNumOperands(inst)-1, lfn)
LLVM.API.LLVMSetOperand(inst, LLVM.API.LLVMGetNumOperands(inst) - 1, lfn)
end
end
end
Expand Down

0 comments on commit 78f50e3

Please sign in to comment.