From b325474c4aba52cca7e0bcd4eae02d23ca4ab9a3 Mon Sep 17 00:00:00 2001 From: kaizhangNV <149626564+kaizhangNV@users.noreply.github.com> Date: Thu, 15 May 2025 11:59:15 -0500 Subject: Implement spec const for generic parameter (#7121) Close #6840. This PR add supports to use specialize constant in generic parameter, and that parameter can also be used as array size, e.g. following code should work: ``` struct MyStruct { float buffer[N]; } MyStruct s; ``` - Loose the restriction from Link-Time to SpecializationConstant when extract generic argument - Tweak the logic of how we decide whether a inst is hoistable. Besides checking existing hoistable flag of each IRInst, when we detect a IRInst's type is SpecConstRateType, we will treat that inst hoistable. Because IRInst in global scope can be deduplicated, and every SpecConstRateType inst should be in the global scope or IRGeneric scope (which will be at global scope after specialization). - Remove the SpecConstIntVal to IRInst map in IR lowering logic, because we already have way to deduplicate the global scope IR. --- source/slang/slang-ir-clone.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source/slang/slang-ir-clone.cpp') diff --git a/source/slang/slang-ir-clone.cpp b/source/slang/slang-ir-clone.cpp index 5bb1c1210..1a020ec26 100644 --- a/source/slang/slang-ir-clone.cpp +++ b/source/slang/slang-ir-clone.cpp @@ -93,6 +93,9 @@ IRInst* cloneInstAndOperands(IRCloneEnv* env, IRBuilder* builder, IRInst* oldIns auto newOperand = findCloneForOperand(env, oldOperand); newOperands[ii] = newOperand; + + if (isArithmeticInst(oldInst)) + newType = maybeAddRateType(builder, newOperand->getFullType(), newType); } // Finally we create the inst with the updated operands. -- cgit v1.2.3