From 499b0253c224e68ceed6e5b6b1ee9cd7d65aad0f Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 30 Jan 2023 19:24:09 -0800 Subject: Make ArrayExpressionType a DeclRefType and define its autodiff extension in stdlib. (#2615) * Allow array parameters in forward diff. * Use type canonicalization instead of coersion. * Reimplement array type. * Fix. * Update test case. --------- Co-authored-by: Yong He --- source/slang/slang-lower-to-ir.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'source/slang/slang-lower-to-ir.cpp') diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 605ac62db..149f5f6b9 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -1443,11 +1443,6 @@ struct ValLoweringVisitor : ValVisitorbaseType); - if (type->arrayLength) + auto elementType = lowerType(context, type->getElementType()); + if (!type->isUnsized()) { - auto elementCount = lowerSimpleVal(context, type->arrayLength); + auto elementCount = lowerSimpleVal(context, type->getElementCount()); return getBuilder()->getArrayType( elementType, elementCount); @@ -3390,18 +3385,10 @@ struct ExprLoweringVisitorBase : ExprVisitor } else if (auto arrayType = as(type)) { - UInt elementCount = (UInt) getIntVal(arrayType->arrayLength); - - auto irDefaultElement = getSimpleVal(context, getDefaultVal(arrayType->baseType)); - - List args; - for(UInt ee = 0; ee < elementCount; ++ee) - { - args.add(irDefaultElement); - } + auto irDefaultElement = getSimpleVal(context, getDefaultVal(arrayType->getElementType())); return LoweredValInfo::simple( - getBuilder()->emitMakeArray(irType, args.getCount(), args.getBuffer())); + getBuilder()->emitMakeArrayFromElement(irType, irDefaultElement)); } else if (auto declRefType = as(type)) { @@ -3470,7 +3457,7 @@ struct ExprLoweringVisitorBase : ExprVisitor // fill in the appropriate field of the result if (auto arrayType = as(type)) { - UInt elementCount = (UInt) getIntVal(arrayType->arrayLength); + UInt elementCount = (UInt) getIntVal(arrayType->getElementCount()); for (UInt ee = 0; ee < argCount; ++ee) { @@ -3480,7 +3467,7 @@ struct ExprLoweringVisitorBase : ExprVisitor } if(elementCount > argCount) { - auto irDefaultValue = getSimpleVal(context, getDefaultVal(arrayType->baseType)); + auto irDefaultValue = getSimpleVal(context, getDefaultVal(arrayType->getElementType())); for(UInt ee = argCount; ee < elementCount; ++ee) { args.add(irDefaultValue); -- cgit v1.2.3