From 79d106fac18f5792fcac448a0b037aa834fa6042 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Fri, 14 May 2021 17:32:52 -0400 Subject: Fix for KernelContext threading issue for C++ targets (#1843) * #include an absolute path didn't work - because paths were taken to always be relative. * Fix for issue where threading KernelContext was not working on C++ test when there were multiple invocations. * Improve test for context threading. --- source/slang/slang-ir-explicit-global-context.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/slang/slang-ir-explicit-global-context.cpp b/source/slang/slang-ir-explicit-global-context.cpp index ea7d0fb2a..6ab0d68f2 100644 --- a/source/slang/slang-ir-explicit-global-context.cpp +++ b/source/slang/slang-ir-explicit-global-context.cpp @@ -467,7 +467,7 @@ struct IntroduceExplicitGlobalContextPass addKernelContextNameHint(contextParam); contextParam->insertBefore(firstBlock->getFirstOrdinaryInst()); - // The new parameter can be registerd as the context value + // The new parameter can be registered as the context value // to be used for `func` right away. // // Note: we register the value *before* modifying locations @@ -482,8 +482,12 @@ struct IntroduceExplicitGlobalContextPass // TODO: There is an issue here if `func` might be called // dynamically, through something like a witness table. // - List uses; - for( auto use = func->firstUse; use; use = use->nextUse ) + // We collect all the uses first which are in calls. + // NOTE! That we collect all calls and then process (and don't iterate + // using the linked list), because when a replacement is made the func usage + // linked list will no longer hold all of the use sites. + List callUses; + for (auto use = func->firstUse; use; use = use->nextUse) { // We will only fix up calls to `func`, and ignore // other operations that might refer to it. @@ -495,9 +499,15 @@ struct IntroduceExplicitGlobalContextPass // to a higher-order function. // auto call = as(use->getUser()); - if(!call) - continue; + if (call) + { + callUses.add(call); + } + } + // Fix up all of the call uses + for( auto call : callUses) + { // We are going to construct a new call to `func` // that has all of the arguments of the original call... // -- cgit v1.2.3