From 1b40fe56725eeefe9c601461278376b697d4d35a Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 23 Nov 2022 17:50:02 -0800 Subject: Make differentiable data-flow pass recognize interface methods. (#2530) * Make differentiable data-flow pass recognize interface methods. * Make existing test to work with `[TreatAsDifferentiable]`. Co-authored-by: Yong He --- source/slang/slang-ir-check-differentiability.cpp | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-check-differentiability.cpp') diff --git a/source/slang/slang-ir-check-differentiability.cpp b/source/slang/slang-ir-check-differentiability.cpp index f4f61d7e9..83351d07b 100644 --- a/source/slang/slang-ir-check-differentiability.cpp +++ b/source/slang/slang-ir-check-differentiability.cpp @@ -97,6 +97,39 @@ public: if (differentiableFunctions.Contains(func)) return true; + if (func->findDecoration()) + return true; + + if (auto lookupInterfaceMethod = as(func)) + { + auto wit = lookupInterfaceMethod->getWitnessTable(); + if (!wit) + return false; + auto witType = as(wit->getDataType()); + if (!witType) + return false; + auto interfaceType = witType->getConformanceType(); + if (!interfaceType) + return false; + if (interfaceType->findDecoration()) + return true; + if (sharedContext.differentiableInterfaceType && interfaceType == sharedContext.differentiableInterfaceType) + return true; + auto dictDecor = interfaceType->findDecoration(); + if (!dictDecor) + return false; + for (auto child : dictDecor->getChildren()) + { + if (auto entry = as(child)) + { + if (entry->getOperand(0) == lookupInterfaceMethod->getRequirementKey()) + { + return true; + } + } + } + } + for (; func; func = func->parent) { if (as(func)) @@ -222,7 +255,7 @@ public: case kIROp_FloatLit: return true; case kIROp_Call: - return inst->findDecoration() || isDifferentiableFunc(as(inst)->getCallee()); + return inst->findDecoration() || isDifferentiableFunc(as(inst)->getCallee()); case kIROp_Load: // We don't have more knowledge on whether diff is available at the destination address. // Just assume it is producing diff. -- cgit v1.2.3