summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-09-14 10:28:22 -0700
committerGitHub <noreply@github.com>2020-09-14 10:28:22 -0700
commit2e3688af574738650c2753680ce9f417fb22e5e7 (patch)
treed99d049a98540336f2d803545d94d91fb200cc8e /source
parent54616718b07b2256271a88b4fc862c6acdb23773 (diff)
Dynamic dispatch bug fixes. (#1541)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-emit-cpp.cpp4
-rw-r--r--source/slang/slang-emit-cpp.h2
-rw-r--r--source/slang/slang-ir-any-value-marshalling.cpp11
-rw-r--r--source/slang/slang-ir-deduplicate.cpp10
4 files changed, 19 insertions, 8 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index 63cac961f..3c6a25135 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -1724,6 +1724,10 @@ void CPPSourceEmitter::emitRTTIObject(IRRTTIObject* rttiObject)
void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition(
IRInterfaceType* interfaceType)
{
+ if (m_interfaceTypesEmitted.Contains(interfaceType))
+ return;
+ m_interfaceTypesEmitted.Add(interfaceType);
+
m_writer->emit("struct ");
emitSimpleType(interfaceType);
m_writer->emit("\n{\n");
diff --git a/source/slang/slang-emit-cpp.h b/source/slang/slang-emit-cpp.h
index e12493b5a..3b7acd953 100644
--- a/source/slang/slang-emit-cpp.h
+++ b/source/slang/slang-emit-cpp.h
@@ -137,6 +137,8 @@ protected:
HashSet<const HLSLIntrinsic*> m_intrinsicEmitted;
+ HashSet<IRInterfaceType*> m_interfaceTypesEmitted;
+
StringSlicePool m_slicePool;
SemanticUsedFlags m_semanticUsedFlags;
diff --git a/source/slang/slang-ir-any-value-marshalling.cpp b/source/slang/slang-ir-any-value-marshalling.cpp
index f732ffbe7..0a988da1d 100644
--- a/source/slang/slang-ir-any-value-marshalling.cpp
+++ b/source/slang/slang-ir-any-value-marshalling.cpp
@@ -126,13 +126,14 @@ namespace Slang
auto vectorType = static_cast<IRVectorType*>(dataType);
auto elementType = vectorType->getElementType();
auto elementCount = getIntVal(vectorType->getElementCount());
+ auto elementPtrType = builder->getPtrType(elementType);
for (IRIntegerValue i = 0; i < elementCount; i++)
{
- auto elementVal = builder->emitElementExtract(
- elementType,
+ auto elementAddr = builder->emitElementAddress(
+ elementPtrType,
concreteTypedVar,
builder->getIntValue(builder->getIntType(), i));
- emitMarshallingCode(builder, context, elementVal);
+ emitMarshallingCode(builder, context, elementAddr);
}
break;
}
@@ -469,6 +470,10 @@ namespace Slang
if (auto anyValueType = as<IRAnyValueType>(inst))
processAnyValueType(anyValueType);
}
+ // Because we replaced all `AnyValueType` uses, some old type definitions (e.g. PtrType(AnyValueType))
+ // will become duplicates with new types we introduced (e.g. PtrType(AnyValueStruct)), and therefore
+ // invalidates our `globalValueNumberingMap` hash map. We need to rebuild it.
+ sharedContext->sharedBuilderStorage.deduplicateAndRebuildGlobalNumberingMap();
}
};
diff --git a/source/slang/slang-ir-deduplicate.cpp b/source/slang/slang-ir-deduplicate.cpp
index 83090e5ff..bbcb8cf03 100644
--- a/source/slang/slang-ir-deduplicate.cpp
+++ b/source/slang/slang-ir-deduplicate.cpp
@@ -17,6 +17,7 @@ namespace Slang
IRInst* addConstantValue(IRConstant* value)
{
IRConstantKey key = { value };
+ value->setFullType((IRType*)addValue(value->getFullType()));
if (auto newValue = builder->constantMap.TryGetValue(key))
return *newValue;
builder->constantMap[key] = value;
@@ -34,15 +35,14 @@ namespace Slang
break;
}
- IRInstKey key = { value };
- if (auto newValue = builder->globalValueNumberingMap.TryGetValue(key))
- return *newValue;
-
for (UInt i = 0; i < value->getOperandCount(); i++)
{
value->setOperand(i, addValue(value->getOperand(i)));
}
value->setFullType((IRType*)addValue(value->getFullType()));
+ IRInstKey key = { value };
+ if (auto newValue = builder->globalValueNumberingMap.TryGetValue(key))
+ return *newValue;
builder->globalValueNumberingMap[key] = value;
return value;
}
@@ -53,6 +53,7 @@ namespace Slang
context.builder = this;
bool changed = true;
constantMap.Clear();
+ globalValueNumberingMap.Clear();
for (auto inst : module->getGlobalInsts())
{
if (auto constVal = as<IRConstant>(inst))
@@ -60,7 +61,6 @@ namespace Slang
context.addConstantValue(constVal);
}
}
- globalValueNumberingMap.Clear();
List<IRInst*> instToRemove;
for (auto inst : module->getGlobalInsts())
{