Repository: shader-slang/slang
File: source/slang/slang-ir-cleanup-void.cpp (C++)

Code before:
                    inst = newCall;
                }
            }
            break;
        case kIROp_Func:
            {
                // Remove void parameters.
                // To keep the ArgIndex operand of the IRDebugVars
                // corresponding to the function parameters correct, we build a
                // map to update the IRDebugVar argument indices later.
                List<IRParam*> paramsToRemove;
                List<Index> argIndexRemap; // Indexed by old ArgIndex, with value of new ArgIndex
                auto func = as<IRFunc>(inst);
                Index nextKeptArgIndex = 0;
                for (auto param : func->getParams())
                {
                    if (param->getDataType()->getOp() == kIROp_VoidType)
                    {
                        paramsToRemove.add(param);
                        argIndexRemap.add(-1); // We can remove the IRDebugVar
                    }
                    else
                    {
                        argIndexRemap.add(nextKeptArgIndex);
                        nextKeptArgIndex++;
                    }
                }
                IRBuilder builder(module);
                builder.setInsertBefore(func);
                for (auto param : paramsToRemove)
                {
                    auto voidVal = builder.getVoidValue();
                    param->replaceUsesWith(voidVal);
                    param->removeAndDeallocate();
                }

                if (paramsToRemove.getCount() != 0)
                {
                    m_debugVarRemappedArgIndices.add(func, argIndexRemap);
                }
            }
            break;
        case kIROp_DebugValue:
            {
                // Remove void values.
                if (auto debugValue = as<IRDebugValue>(inst))
                {
                    if (auto valueType = debugValue->getValue()->getDataType())
                    {
                        if (valueType->getOp() == kIROp_VoidType)
                        {

Review comment (suggestion):
Feel free to ignore this comment because my suggestion is just for cosmetic.
I think it would be easier to read if it is written as following:
```
bool needToRemove = (param->getDataType()->getOp() == kIROp_VoidType);
argIndexRemap.add( needToRemove ? -1 : nextKeptArgIndex);

if (needToRemove)
{
  paramsToRemove.add(param);
}
else
{
  nextKeptArgIndex++;
}
```

Code after:
                    inst = newCall;
                }
            }
            break;
        case kIROp_Func:
            {
                // Remove void parameters.
                // To keep the ArgIndex operand of the IRDebugVars
                // corresponding to the function parameters correct, we build a
                // map to update the IRDebugVar argument indices later.
                List<IRParam*> paramsToRemove;
                auto func = as<IRFunc>(inst);
                List<Index> argIndexRemap; // Indexed by old ArgIndex, with value of new ArgIndex
                argIndexRemap.reserve(func->getParamCount());
                Index nextKeptArgIndex = 0;
                for (auto param : func->getParams())
                {
                    bool needToRemove = (param->getDataType()->getOp() == kIROp_VoidType);
                    argIndexRemap.add(needToRemove ? -1 : nextKeptArgIndex);

                    if (needToRemove)
                    {
                        paramsToRemove.add(param);
                    }
                    else
                    {
                        nextKeptArgIndex++;
                    }
                }
                IRBuilder builder(module);
                builder.setInsertBefore(func);
                for (auto param : paramsToRemove)
                {
                    auto voidVal = builder.getVoidValue();
                    param->replaceUsesWith(voidVal);
                    param->removeAndDeallocate();
                }

                if (paramsToRemove.getCount() != 0)
                {
                    m_debugVarRemappedArgIndices.add(func, argIndexRemap);
                }
            }
            break;
        case kIROp_DebugValue:
            {
                // Remove void values.
                if (auto debugValue = as<IRDebugValue>(inst))
                {
                    if (auto valueType = debugValue->getValue()->getDataType())
                    {