From 545de51298ddda52ac51ded03ad489c98bdda397 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 21 Nov 2022 10:29:57 -0500 Subject: WIP: Fixed inout struct and added testing for calls to non-differentiable functions (#2505) * Added non-differentiable call test * Extended testing for nondifferentiable calls * Fixed subtle issue with extensions on generic types not applying the correct substitutions, leading to unspecialized generics at the emit stage * More fixes. inout struct params now work fine * Update inout-struct-parameters-jvp.slang * Update slang-ir.cpp * Fixed hoisting lookup_interface_method * Fixed non-diff call return value * Fixed issue with phi nodes * Fixed problem with IRSpecialize preventing hoisitng of DifferentialPairType * Fixed non-diff call test to conform to the new 'no_diff' system --- source/slang/slang-ir.cpp | 49 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index de86a6a52..c12872320 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3147,6 +3147,9 @@ namespace Slang IRInst* IRBuilder::emitMakeDifferentialPair(IRType* type, IRInst* primal, IRInst* differential) { + SLANG_RELEASE_ASSERT(as(type)); + SLANG_RELEASE_ASSERT(as(type)->getValueType() != nullptr); + IRInst* args[] = {primal, differential}; auto inst = createInstWithTrailingArgs( this, kIROp_MakeDifferentialPair, type, 2, args); @@ -3160,6 +3163,18 @@ namespace Slang UInt argCount, IRInst* const* args) { + auto innerReturnVal = findInnerMostGenericReturnVal(as(genericVal)); + + if (as(innerReturnVal)) + { + return findOrEmitHoistableInst( + type, + kIROp_Specialize, + genericVal, + argCount, + args); + } + auto inst = createInstWithTrailingArgs( this, kIROp_Specialize, @@ -3186,15 +3201,13 @@ namespace Slang // SLANG_ASSERT(witnessTableVal->getOp() != kIROp_StructKey); - auto inst = createInst( - this, - kIROp_lookup_interface_method, - type, - witnessTableVal, - interfaceMethodVal); + IRInst* args[] = {witnessTableVal, interfaceMethodVal}; - addInst(inst); - return inst; + return findOrEmitHoistableInst( + type, + kIROp_lookup_interface_method, + 2, + args); } IRInst* IRBuilder::emitGetSequentialIDInst(IRInst* rttiObj) @@ -3467,6 +3480,15 @@ namespace Slang &diffPair); } + IRInst* IRBuilder::emitDifferentialPairAddressDifferential(IRType* diffType, IRInst* diffPair) + { + return emitIntrinsicInst( + diffType, + kIROp_DifferentialPairGetDifferential, + 1, + &diffPair); + } + IRInst* IRBuilder::emitDifferentialPairGetPrimal(IRInst* diffPair) { auto valueType = as(diffPair->getDataType())->getValueType(); @@ -3477,6 +3499,17 @@ namespace Slang &diffPair); } + IRInst* IRBuilder::emitDifferentialPairAddressPrimal(IRInst* diffPair) + { + auto valueType = as( + as(diffPair->getDataType())->getValueType())->getValueType(); + return emitIntrinsicInst( + this->getPtrType(kIROp_PtrType, valueType), + kIROp_DifferentialPairGetPrimal, + 1, + &diffPair); + } + IRInst* IRBuilder::emitMakeMatrix( IRType* type, UInt argCount, -- cgit v1.2.3