From a3ba22b51c371d5a20d61aa4e35233ba4f4f68db Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 27 Feb 2023 15:18:07 -0800 Subject: Detect and deduplicate read-only resource access. (#2680) * Detect and deduplicate read-only resource access. * Fix tests. * Fix tests. --------- Co-authored-by: Yong He --- source/slang/slang-ir-util.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/slang/slang-ir-util.cpp') diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index 339521f41..13920b011 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -157,6 +157,7 @@ IRInst* maybeSpecializeWithGeneric(IRBuilder& builder, IRInst* genericToSpecaili return genericToSpecailize; } +// Returns true if is not possible to produce side-effect from a value of `dataType`. bool isValueType(IRInst* dataType) { dataType = getResolvedInstForDecorations(unwrapAttributedType(dataType)); @@ -179,6 +180,15 @@ bool isValueType(IRInst* dataType) case kIROp_FuncType: return true; default: + // Read-only resource handles are considered as Value type. + if (auto resType = as(dataType)) + return (resType->getAccess() == SLANG_RESOURCE_ACCESS_READ); + else if (as(dataType)) + return true; + else if (as(dataType)) + return true; + else if (as(dataType)) + return true; return false; } } -- cgit v1.2.3