From 1093218d6f0e114eb9fa52d60ca525bf9dd9f98a Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 20 Oct 2022 14:22:00 -0400 Subject: Modified the new type system to support generic differentiable types … (#2413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Modified the new type system to support generic differentiable types and added support for differentiating overloaded functions. * Changed a few asserts to release asserts to avoid unreferenced variable errors * Fixed a naming issue with TypeWitnessBreadcumb::Flavor::Decl * Added logic to avoid tracking differentiable types if the module does not use auto-diff or define differentiable types. * Moved the auto-diff passes to after the specialization step, added a more complex generics test * Added a generics stress test and fixed AST-side logic. IR side needs some more work * Added differential getter and setter logic, fixed multiple issues with DifferentiableTypeDictionary, added support for loops and conditions * Changed differential getters to use pointer types, added getter type checking * Fixed some bugs related to diff type registration and differential getters * Removed some superfluous code * Removed some more unused code. * Fixed an issue with witness substitution * Minor fix Co-authored-by: Yong He --- source/slang/slang-ir-link.cpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-ir-link.cpp') diff --git a/source/slang/slang-ir-link.cpp b/source/slang/slang-ir-link.cpp index a5130e8b6..56688abae 100644 --- a/source/slang/slang-ir-link.cpp +++ b/source/slang/slang-ir-link.cpp @@ -238,6 +238,7 @@ IRInst* IRSpecContext::maybeCloneValue(IRInst* originalValue) case kIROp_WitnessTable: case kIROp_InterfaceType: case kIROp_TaggedUnionType: + case kIROp_DifferentiableTypeDictionary: return cloneGlobalValue(this, originalValue); case kIROp_BoolLit: @@ -592,6 +593,24 @@ IRWitnessTable* cloneWitnessTableImpl( return clonedTable; } +IRInst* cloneDifferentiableTypeDictionary( + IRSpecContextBase* context, + IRBuilder* builder, + IRInst* originalDict, + IROriginalValuesForClone const& originalValues, + IRInst* dstDict = nullptr, + bool registerValue = true) +{ + IRInst* clonedDict = dstDict; + if (!clonedDict) + { + clonedDict = builder->emitDifferentiableTypeDictionary(); + } + cloneSimpleGlobalValueImpl(context, originalDict, originalValues, clonedDict, registerValue); + return clonedDict; +} + + IRWitnessTable* cloneWitnessTableWithoutRegistering( IRSpecContextBase* context, IRBuilder* builder, @@ -1118,6 +1137,9 @@ IRInst* cloneInst( case kIROp_GlobalGenericParam: return cloneGlobalGenericParamImpl(context, builder, cast(originalInst), originalValues); + + case kIROp_DifferentiableTypeDictionary: + return cloneDifferentiableTypeDictionary(context, builder, originalInst, originalValues); default: break; @@ -1504,11 +1526,14 @@ LinkedIR linkIR( { for (auto inst : irModule->getGlobalInsts()) { - auto bindInst = as(inst); - if (!bindInst) - continue; - - cloneValue(context, bindInst); + if (auto bindInst = as(inst)) + { + cloneValue(context, bindInst); + } + else if (inst->getOp() == kIROp_DifferentiableTypeDictionary) + { + cloneValue(context, inst); + } } } -- cgit v1.2.3