summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-lower-generics.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-lower-generics.cpp')
-rw-r--r--source/slang/slang-ir-lower-generics.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/source/slang/slang-ir-lower-generics.cpp b/source/slang/slang-ir-lower-generics.cpp
index a7c0f51e6..f535b97d2 100644
--- a/source/slang/slang-ir-lower-generics.cpp
+++ b/source/slang/slang-ir-lower-generics.cpp
@@ -176,6 +176,30 @@ namespace Slang
});
}
+ void stripWrapExistential(IRModule* module)
+ {
+ auto& workList = *module->getContainerPool().getList<IRInst>();
+ workList.add(module->getModuleInst());
+ for (Index i = 0; i < workList.getCount(); i++)
+ {
+ auto inst = workList[i];
+ switch (inst->getOp())
+ {
+ case kIROp_WrapExistential:
+ {
+ auto operand = inst->getOperand(0);
+ inst->replaceUsesWith(operand);
+ inst->removeAndDeallocate();
+ }
+ break;
+ default:
+ for (auto child : inst->getChildren())
+ workList.add(child);
+ break;
+ }
+ }
+ }
+
void lowerGenerics(
TargetRequest* targetReq,
IRModule* module,
@@ -234,5 +258,11 @@ namespace Slang
generateAnyValueMarshallingFunctions(&sharedContext);
if (sink->getErrorCount() != 0)
return;
+
+ // At this point, we should no longer need to care any `WrapExistential` insts,
+ // although they could still exist in the IR in order to call generic stdlib functions,
+ // e.g. RWStucturedBuffer.Load(WrapExistential(sbuffer, type), index).
+ // We should remove them now.
+ stripWrapExistential(module);
}
} // namespace Slang