summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-legalize-types.cpp44
1 files changed, 35 insertions, 9 deletions
diff --git a/source/slang/slang-legalize-types.cpp b/source/slang/slang-legalize-types.cpp
index 3568e4d0e..49bce39f3 100644
--- a/source/slang/slang-legalize-types.cpp
+++ b/source/slang/slang-legalize-types.cpp
@@ -246,7 +246,8 @@ struct TupleTypeBuilder
IRStructKey* fieldKey,
LegalType legalFieldType,
LegalType legalLeafType,
- bool isSpecial)
+ bool isSpecial,
+ IRType* originalFieldType)
{
LegalType ordinaryType;
LegalType specialType;
@@ -292,7 +293,8 @@ struct TupleTypeBuilder
fieldKey,
legalFieldType,
legalLeafType.getImplicitDeref()->valueType,
- isSpecial);
+ isSpecial,
+ originalFieldType);
return;
}
break;
@@ -356,6 +358,14 @@ struct TupleTypeBuilder
if(ot.flavor == LegalType::Flavor::simple)
{
+ // If the field type is changed after legalization
+ // (e.g. the field has empty struct type), we want
+ // to propagate this change through the enclosing
+ // struct type, forcing a new type to be created for
+ // the enclosing struct.
+ if (ot.getSimple() != originalFieldType)
+ anyComplex = true;
+
ordinaryElement.type = ot.getSimple();
}
else
@@ -394,7 +404,9 @@ struct TupleTypeBuilder
field->getKey(),
legalFieldType,
legalFieldType,
- isSpecialField);
+ isSpecialField,
+ fieldType);
+
}
LegalType getResult()
@@ -485,13 +497,13 @@ struct TupleTypeBuilder
ordinaryType = LegalType::simple((IRType*) ordinaryStructType);
}
+ if (!anySpecial)
+ return ordinaryType;
+
LegalType specialType;
- if (anySpecial)
- {
- RefPtr<TuplePseudoType> specialTuple = new TuplePseudoType();
- specialTuple->elements = specialElements;
- specialType = LegalType::tuple(specialTuple);
- }
+ RefPtr<TuplePseudoType> specialTuple = new TuplePseudoType();
+ specialTuple->elements = specialElements;
+ specialType = LegalType::tuple(specialTuple);
RefPtr<PairInfo> pairInfo;
if (anyOrdinary && anySpecial)
@@ -1189,6 +1201,11 @@ LegalType legalizeTypeImpl(
//
auto legalConcreteType = legalizeType(context, pseudoPtrType->getValueType());
+ // If element type hasn't change, return original type.
+ if (legalConcreteType.flavor == LegalType::Flavor::simple &&
+ legalConcreteType.getSimple() == pseudoPtrType->getValueType())
+ return LegalType::simple(pseudoPtrType);
+
// TODO: If/when we change our generation of pseudo-pointers
// so that use-site code emits a "pseudo-load" then we may
// need to change the logic here so that we return
@@ -1204,6 +1221,10 @@ LegalType legalizeTypeImpl(
else if (auto ptrType = as<IRPtrTypeBase>(type))
{
auto legalValueType = legalizeType(context, ptrType->getValueType());
+ // If element type hasn't change, return original type.
+ if (legalValueType.flavor == LegalType::Flavor::simple &&
+ legalValueType.getSimple() == ptrType->getValueType())
+ return LegalType::simple(ptrType);
return createLegalPtrType(context, ptrType->op, legalValueType);
}
else if(auto structType = as<IRStructType>(type))
@@ -1283,6 +1304,11 @@ LegalType legalizeTypeImpl(
context,
arrayType->getElementType());
+ // If element type hasn't change, return original type.
+ if (legalElementType.flavor == LegalType::Flavor::simple &&
+ legalElementType.getSimple() == arrayType->getElementType())
+ return LegalType::simple(arrayType);
+
ArrayLegalTypeWrapper wrapper;
wrapper.arrayType = arrayType;