summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-10-21 15:51:18 -0700
committerGitHub <noreply@github.com>2021-10-21 15:51:18 -0700
commit9304c2d04c9bfbae33cc328d404b24aba375aa4f (patch)
tree88473d2ca0b03341f84bca17b359ae45c4becfaa /source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
parent66e319e34b99eff0a8d27be524ab4a831437ac1b (diff)
Diagnostic for no type conformance + bug fix. (#1985)
* Diagnostic for no type conformance + bug fix. * Fixes. * Fix. * Include heterogeneous example only with --enable-experimental-projects premake flag Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: jsmall-nvidia <jsmall@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp')
-rw-r--r--source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp46
1 files changed, 16 insertions, 30 deletions
diff --git a/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp b/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
index 059531107..e2d321ed4 100644
--- a/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
+++ b/source/slang/slang-ir-specialize-dynamic-associatedtype-lookup.cpp
@@ -157,44 +157,30 @@ struct AssociatedTypeLookupSpecializationContext
{
if (inst->getRTTIOperand()->getDataType()->getOp() == kIROp_WitnessTableIDType)
{
+ // If the operand is a witness table id, just return the operand.
inst->replaceUsesWith(inst->getRTTIOperand());
inst->removeAndDeallocate();
}
- }
-
- template<typename TFunc>
- void workOnModule(const TFunc& func)
- {
- SharedIRBuilder* sharedBuilder = &sharedContext->sharedBuilderStorage;
- sharedBuilder->module = sharedContext->module;
- sharedBuilder->session = sharedContext->module->session;
-
- sharedContext->addToWorkList(sharedContext->module->getModuleInst());
-
- while (sharedContext->workList.getCount() != 0)
+ else if (inst->getRTTIOperand()->getDataType()->getOp() == kIROp_VectorType)
{
- IRInst* inst = sharedContext->workList.getLast();
-
- sharedContext->workList.removeLast();
- sharedContext->workListSet.Remove(inst);
-
- func(inst);
- if (inst->getOp() == kIROp_lookup_interface_method)
- {
- processLookupInterfaceMethodInst(cast<IRLookupWitnessMethod>(inst));
- }
-
- for (auto child = inst->getLastChild(); child; child = child->getPrevInst())
- {
- sharedContext->addToWorkList(child);
- }
+ // If the operand is a witness table, it is already replaced with a uint2
+ // at this point, where the first element in the uint2 is the id of the
+ // witneess table.
+ auto vectorType = inst->getRTTIOperand()->getDataType();
+ IRBuilder builder;
+ builder.sharedBuilder = &sharedContext->sharedBuilderStorage;
+ builder.setInsertBefore(inst);
+ UInt index = 0;
+ auto id = builder.emitSwizzle(as<IRVectorType>(vectorType)->getElementType(), inst->getRTTIOperand(), 1, &index);
+ inst->replaceUsesWith(id);
+ inst->removeAndDeallocate();
}
}
void processModule()
{
// Replace all `lookup_interface_method():IRWitnessTable` with call to specialized functions.
- workOnModule([this](IRInst* inst)
+ workOnModule(sharedContext, [this](IRInst* inst)
{
if (inst->getOp() == kIROp_lookup_interface_method)
{
@@ -203,7 +189,7 @@ struct AssociatedTypeLookupSpecializationContext
});
// Replace all direct uses of IRWitnessTables with its sequential ID.
- workOnModule([this](IRInst* inst)
+ workOnModule(sharedContext, [this](IRInst* inst)
{
if (inst->getOp() == kIROp_WitnessTable)
{
@@ -252,7 +238,7 @@ struct AssociatedTypeLookupSpecializationContext
}
// `GetSequentialID(WitnessTableIDOperand)` becomes just `WitnessTableIDOperand`.
- workOnModule([this](IRInst* inst)
+ workOnModule(sharedContext, [this](IRInst* inst)
{
if (inst->getOp() == kIROp_GetSequentialID)
{