summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkaizhangNV <149626564+kaizhangNV@users.noreply.github.com>2025-04-09 16:24:17 -0500
committerGitHub <noreply@github.com>2025-04-09 14:24:17 -0700
commitfd09feaaa19c1ae3441dd687bced1b12ff7c768e (patch)
treee6f30188ffef052e8930b5ebf3131973355bb8ce
parent87c96bcfa89905d237dc0452f255ebf61307c441 (diff)
void field rework (#6739)
* void field rework * move void cleanup pass earlier
-rw-r--r--source/slang/slang-emit.cpp3
-rw-r--r--source/slang/slang-ir-cleanup-void.cpp24
-rw-r--r--source/slang/slang-ir-legalize-types.cpp2
-rw-r--r--source/slang/slang-ir-peephole.cpp6
4 files changed, 10 insertions, 25 deletions
diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp
index 4eb4719f0..9cfa7dcae 100644
--- a/source/slang/slang-emit.cpp
+++ b/source/slang/slang-emit.cpp
@@ -1716,6 +1716,8 @@ Result linkAndOptimizeIR(
//
eliminateDeadCode(irModule, deadCodeEliminationOptions);
+ cleanUpVoidType(irModule);
+
if (isKhronosTarget(targetRequest))
{
// As a fallback, if the above specialization steps failed to remove resource type
@@ -1728,7 +1730,6 @@ Result linkAndOptimizeIR(
#endif
validateIRModuleIfEnabled(codeGenContext, irModule);
- cleanUpVoidType(irModule);
// Lower the `getRegisterIndex` and `getRegisterSpace` intrinsics.
//
diff --git a/source/slang/slang-ir-cleanup-void.cpp b/source/slang/slang-ir-cleanup-void.cpp
index 84532d0ec..3a776fc4f 100644
--- a/source/slang/slang-ir-cleanup-void.cpp
+++ b/source/slang/slang-ir-cleanup-void.cpp
@@ -122,8 +122,6 @@ 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))
@@ -131,33 +129,11 @@ 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:
diff --git a/source/slang/slang-ir-legalize-types.cpp b/source/slang/slang-ir-legalize-types.cpp
index 837193abc..af29d1998 100644
--- a/source/slang/slang-ir-legalize-types.cpp
+++ b/source/slang/slang-ir-legalize-types.cpp
@@ -1962,6 +1962,8 @@ static LegalVal coerceToLegalType(IRTypeLegalizationContext* context, LegalType
ShortList<IRInst*> fields;
for (auto field : structType->getFields())
{
+ if (as<IRVoidType>(field->getFieldType()))
+ continue;
auto fieldVal = coerceToLegalType(
context,
LegalType::simple(field->getFieldType()),
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp
index e29fdf975..28e98fdb6 100644
--- a/source/slang/slang-ir-peephole.cpp
+++ b/source/slang/slang-ir-peephole.cpp
@@ -402,6 +402,12 @@ struct PeepholeContext : InstPassBase
Index i = 0;
for (auto sfield : structType->getFields())
{
+ // skip the void field
+ if (as<IRVoidType>(sfield->getFieldType()))
+ {
+ continue;
+ }
+
if (sfield->getKey() == field)
{
fieldIndex = i;