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

Fixed NVVM generation for void functions and out parameters. #1147

Merged
merged 1 commit into from
Jan 12, 2024
Merged
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
25 changes: 19 additions & 6 deletions Src/ILGPU/Backends/PTX/PTXLibDeviceNvvm.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021-2023 ILGPU Project
// Copyright (c) 2021-2024 ILGPU Project
// www.ilgpu.net
//
// File: PTXLibDeviceNvvm.tt/PTXLibDeviceNvvm.cs
Expand Down Expand Up @@ -110,7 +110,7 @@ void WriteLibDeviceFunctionNvvm(LibDeviceFunction func)
for (int i = 0; i < func.Parameters.Length; i++)
{
var param = func.Parameters[i];
WriteNvvmType(param.Type);
WriteNvvmType(param.Type, param.Flags);
Write($" %{param.Name}");
if (i < func.Parameters.Length - 1)
Write(",");
Expand All @@ -128,7 +128,7 @@ void WriteLibDeviceFunctionNvvm(LibDeviceFunction func)
for (int i = 0; i < func.Parameters.Length; i++)
{
var param = func.Parameters[i];
WriteNvvmType(param.Type);
WriteNvvmType(param.Type, param.Flags);
Write($" %{param.Name}");
if (i < func.Parameters.Length - 1)
Write(",");
Expand All @@ -139,15 +139,18 @@ void WriteLibDeviceFunctionNvvm(LibDeviceFunction func)
WriteLine("entry:");

PushIndent();
Write("%call = call ");
if (func.ReturnType == "void")
Write("call ");
else
Write("%call = call ");
WriteNvvmType(func.ReturnType);
Write(" @");
Write(func.Name);
Write("(");
for (int i = 0; i < func.Parameters.Length; i++)
{
var param = func.Parameters[i];
WriteNvvmType(param.Type);
WriteNvvmType(param.Type, param.Flags);
Write($" %{param.Name}");
if (i < func.Parameters.Length - 1)
Write(",");
Expand All @@ -157,7 +160,10 @@ void WriteLibDeviceFunctionNvvm(LibDeviceFunction func)
WriteLine();
Write("ret ");
WriteNvvmType(func.ReturnType);
WriteLine(" %call");
if (func.ReturnType == "void")
WriteLine();
else
WriteLine(" %call");
PopIndent();
WriteLine("}\";");
WriteLine();
Expand All @@ -180,4 +186,11 @@ void WriteNvvmType(string type)
Write(type);
}

void WriteNvvmType(string type, string flags)
{
WriteNvvmType(type);
if (flags == "Out")
Write("*");
}

#>
Loading