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-emit-c-like.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/slang/slang-emit-c-like.cpp') diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 7840dc450..a31c16505 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -1344,6 +1344,30 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst) } } + // If this is a call to a ResourceType's member function, don't fold for readability. + if (auto call = as(inst)) + { + auto callee = getResolvedInstForDecorations(call->getCallee()); + if (callee->findDecoration()) + { + auto funcType = as(callee->getDataType()); + if (funcType) + { + if (funcType->getParamCount() > 0) + { + auto firstParamType = funcType->getParamType(0); + if (as(firstParamType)) + return false; + if (as(firstParamType)) + return false; + if (as(firstParamType)) + return false; + if (as(firstParamType)) + return false; + } + } + } + } // We'd like to figure out if it is safe to fold our instruction into `user` // First, let's make sure they are in the same block/parent: -- cgit v1.2.3