summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-08-14 12:56:43 -0700
committerGitHub <noreply@github.com>2020-08-14 12:56:43 -0700
commit0640a10ab85f8be3c3c925cb70711560265e6548 (patch)
treed1ec2068c5ffe6845eabcd425504014ab0bed1a0
parentb37a7770d9781515f70047665d12680a5838406d (diff)
Fix tuple type lowering (#1499)
Co-authored-by: Tim Foley <tfoleyNV@users.noreply.github.com>
-rw-r--r--source/slang/slang-ir-deduplicate.cpp3
-rw-r--r--source/slang/slang-ir-lower-tuple-types.cpp26
2 files changed, 9 insertions, 20 deletions
diff --git a/source/slang/slang-ir-deduplicate.cpp b/source/slang/slang-ir-deduplicate.cpp
index 81bb2371e..83090e5ff 100644
--- a/source/slang/slang-ir-deduplicate.cpp
+++ b/source/slang/slang-ir-deduplicate.cpp
@@ -24,10 +24,11 @@ namespace Slang
}
IRInst* addTypeValue(IRInst* value)
{
- // Do not deduplicate struct types.
+ // Do not deduplicate struct or interface types.
switch (value->op)
{
case kIROp_StructType:
+ case kIROp_InterfaceType:
return value;
default:
break;
diff --git a/source/slang/slang-ir-lower-tuple-types.cpp b/source/slang/slang-ir-lower-tuple-types.cpp
index 814f92283..cadf77253 100644
--- a/source/slang/slang-ir-lower-tuple-types.cpp
+++ b/source/slang/slang-ir-lower-tuple-types.cpp
@@ -33,14 +33,6 @@ namespace Slang
return type;
}
- void appendTypeName(StringBuilder& sb, IRInst* inst)
- {
- if (auto name = inst->findDecoration<IRNameHintDecoration>())
- {
- sb << name->getName();
- }
- }
-
LoweredTupleInfo* getLoweredTupleType(IRBuilder* builder, IRInst* type)
{
if (auto loweredInfo = loweredTuples.TryGetValue(type))
@@ -57,13 +49,12 @@ namespace Slang
info->tupleType = (IRType*)type;
auto structType = builder->createStructType();
info->structType = structType;
- StringBuilder nameSb, fieldNameSb;
- nameSb << "Tuple";
+ builder->addNameHintDecoration(structType, UnownedStringSlice("Tuple"));
+
+ StringBuilder fieldNameSb;
for (UInt i = 0; i < type->getOperandCount(); i++)
{
auto elementType = maybeLowerTupleType(builder, (IRType*)(type->getOperand(i)));
- nameSb << "_";
- appendTypeName(nameSb, elementType);
auto key = builder->createStructKey();
fieldNameSb.Clear();
fieldNameSb << "value" << i;
@@ -71,7 +62,6 @@ namespace Slang
auto field = builder->createStructField(structType, key, (IRType*)elementType);
info->fields.add(field);
}
- builder->addNameHintDecoration(structType, nameSb.getUnownedSlice());
mapLoweredStructToTupleInfo[structType] = info;
loweredTuples[type] = info;
return info.Ptr();
@@ -101,16 +91,14 @@ namespace Slang
builder->setInsertBefore(inst);
auto info = getLoweredTupleType(builder, inst->getDataType());
- auto var = builder->emitVar(info->structType);
+ List<IRInst*> operands;
for (Index i = 0; i < info->fields.getCount(); i++)
{
SLANG_ASSERT(i < (Index)inst->getOperandCount());
- auto ptrType = builder->getPtrType(info->fields[i]->getFieldType());
- auto addr = builder->emitFieldAddress(ptrType, var, info->fields[i]->getKey());
- builder->emitStore(addr, inst->getOperand((UInt)i));
+ operands.add(inst->getOperand(i));
}
- auto load = builder->emitLoad(var);
- inst->replaceUsesWith(load);
+ auto makeStruct = builder->emitMakeStruct(info->structType, operands);
+ inst->replaceUsesWith(makeStruct);
inst->removeAndDeallocate();
}