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

Remove GCN lower_throw_extra! pass #74

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
60 changes: 0 additions & 60 deletions src/gcn.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,68 +42,8 @@ function process_kernel!(job::CompilerJob{GCNCompilerTarget}, mod::LLVM.Module,
end

function add_lowering_passes!(job::CompilerJob{GCNCompilerTarget}, pm::LLVM.PassManager)
add!(pm, ModulePass("LowerThrowExtra", lower_throw_extra!))
add!(pm, FunctionPass("FixAllocaAddrspace", fix_alloca_addrspace!))
end

function lower_throw_extra!(mod::LLVM.Module)
job = current_job::CompilerJob
ctx = context(mod)
changed = false
@timeit_debug to "lower throw (extra)" begin

throw_functions = [
r"julia_bounds_error.*",
r"julia_throw_boundserror.*",
r"julia_error_if_canonical_getindex.*",
r"julia_error_if_canonical_setindex.*",
r"julia___subarray_throw_boundserror.*",
]


for f in functions(mod)
f_name = LLVM.name(f)
for fn in throw_functions
if occursin(fn, f_name)
for use in uses(f)
call = user(use)::LLVM.CallInst

# replace the throw with a trap
let builder = Builder(ctx)
position!(builder, call)
emit_exception!(builder, f_name, call)
dispose(builder)
end

# remove the call
call_args = collect(operands(call))[1:end-1] # last arg is function itself
unsafe_delete!(LLVM.parent(call), call)

# HACK: kill the exceptions' unused arguments
for arg in call_args
# peek through casts
if isa(arg, LLVM.AddrSpaceCastInst)
cast = arg
arg = first(operands(cast))
isempty(uses(cast)) && unsafe_delete!(LLVM.parent(cast), cast)
end

if isa(arg, LLVM.Instruction) && isempty(uses(arg))
unsafe_delete!(LLVM.parent(arg), arg)
end
end

changed = true
end

@compiler_assert isempty(uses(f)) job
end
end
end

end
return changed
end
function fix_alloca_addrspace!(fn::LLVM.Function)
changed = false
alloca_as = 5
Expand Down