Skip to content

Commit

Permalink
Fixed NVVM generation for void functions void or with out parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ committed Apr 19, 2024
1 parent 0f73696 commit 1b145be
Showing 1 changed file with 19 additions and 6 deletions.
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("*");
}

#>

0 comments on commit 1b145be

Please sign in to comment.