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

Allow caller of classify_argument to specify that the first arg is sret #272

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions src/irgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ end
GHOST # not passed
end

function classify_arguments(@nospecialize(job::CompilerJob), codegen_ft::LLVM.FunctionType)
function classify_arguments(@nospecialize(job::CompilerJob), codegen_ft::LLVM.FunctionType, has_sret=false)
source_sig = Base.signature_type(job.source.f, job.source.tt)::Type
source_types = [source_sig.parameters...]

codegen_types = parameters(codegen_ft)

args = []
codegen_i = 1
codegen_i = 1 + has_sret
for (source_i, source_typ) in enumerate(source_types)
if isghosttype(source_typ) || Core.Compiler.isconstType(source_typ)
push!(args, (cc=GHOST, typ=source_typ))
Expand Down
18 changes: 18 additions & 0 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,22 @@ end

############################################################################################

@testset "classify_arguments" begin
f_sret(x) = (x, x)
job, _ = native_job(f_sret, Tuple{Float64})
_, meta = GPUCompiler.compile(:llvm, job)
ft = LLVM.eltype(LLVM.llvmtype(meta.entry))

sret = EnumAttribute("sret"; ctx=context(ft))
attrs = collect(parameter_attributes(meta.entry, 1))
has_sret = any(attr->kind(attr)==kind(sret), attrs)

@test has_sret

classification = GPUCompiler.classify_arguments(job, ft, has_sret)
@test length(classification) == 2
@test classification[1].typ == typeof(f_sret)
@test classification[2].typ == Float64
end

end