summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-cleanup-void.cpp
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-04-02 12:34:58 -0500
committerGitHub <noreply@github.com>2025-04-02 10:34:58 -0700
commitc1f69ca1e29811919dbd2f08a6e2dd498b80aab2 (patch)
tree7e41262b8bd04ebd38d388cf84ba45553db44d4d /source/slang/slang-ir-cleanup-void.cpp
parente44479c88806a711f6d5f821a4acff030f9a558b (diff)
Metal remove void field (#6725)
* Reapply "Eliminate empty struct on metal target (#6603)" (#6711) This reverts commit bc9dc6557fc0cc3a4c0c2ff27e636940e361cf5d. * Remove argument in make_struct call corresponding to void field This is a follow-up of #6543, where we leave the VoidType field as it in make_struct call during legalization pass. So during cleaning_void IR pass, when we remove "VoidType" from struct, we will have to also clean up the argument corresponding to the "VoidType" field.
Diffstat (limited to 'source/slang/slang-ir-cleanup-void.cpp')
-rw-r--r--source/slang/slang-ir-cleanup-void.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/slang-ir-cleanup-void.cpp b/source/slang/slang-ir-cleanup-void.cpp
index 3a776fc4f..84532d0ec 100644
--- a/source/slang/slang-ir-cleanup-void.cpp
+++ b/source/slang/slang-ir-cleanup-void.cpp
@@ -122,6 +122,8 @@ struct CleanUpVoidContext
case kIROp_StructType:
{
List<IRInst*> toRemove;
+ UInt fieldCount = 0;
+ ShortList<UInt> voidFieldIndex;
for (auto child : inst->getChildren())
{
if (auto field = as<IRStructField>(child))
@@ -129,11 +131,33 @@ struct CleanUpVoidContext
if (field->getFieldType()->getOp() == kIROp_VoidType)
{
toRemove.add(field);
+ voidFieldIndex.add(fieldCount);
}
}
+ fieldCount++;
}
for (auto ii : toRemove)
ii->removeAndDeallocate();
+
+ // Once we remove the void fields in the struct, we also need update the make_struct
+ // call sites to remove the arguments corresponding to the void fields.
+ if (inst->hasUses() && voidFieldIndex.getCount())
+ {
+ UInt currentFieldCount = fieldCount - toRemove.getCount();
+ for (auto use = inst->firstUse; use; use = use->nextUse)
+ {
+ if (auto makeStructInst = as<IRMakeStruct>(use->user))
+ {
+ if (makeStructInst->getOperandCount() != currentFieldCount)
+ {
+ for (Int i = 0; i < voidFieldIndex.getCount(); i++)
+ {
+ makeStructInst->removeOperand(voidFieldIndex[i]);
+ }
+ }
+ }
+ }
+ }
}
break;
default: