summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2022-11-21 10:29:57 -0500
committerGitHub <noreply@github.com>2022-11-21 10:29:57 -0500
commit545de51298ddda52ac51ded03ad489c98bdda397 (patch)
treedef78374f743d2c722fbde45eba60951a6f5c8f9 /source/slang/slang-ir.cpp
parentd58e08f8237a1888ceaad53402d534679ea83b1a (diff)
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
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp49
1 files changed, 41 insertions, 8 deletions
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<IRDifferentialPairType>(type));
+ SLANG_RELEASE_ASSERT(as<IRDifferentialPairType>(type)->getValueType() != nullptr);
+
IRInst* args[] = {primal, differential};
auto inst = createInstWithTrailingArgs<IRMakeDifferentialPair>(
this, kIROp_MakeDifferentialPair, type, 2, args);
@@ -3160,6 +3163,18 @@ namespace Slang
UInt argCount,
IRInst* const* args)
{
+ auto innerReturnVal = findInnerMostGenericReturnVal(as<IRGeneric>(genericVal));
+
+ if (as<IRWitnessTable>(innerReturnVal))
+ {
+ return findOrEmitHoistableInst(
+ type,
+ kIROp_Specialize,
+ genericVal,
+ argCount,
+ args);
+ }
+
auto inst = createInstWithTrailingArgs<IRSpecialize>(
this,
kIROp_Specialize,
@@ -3186,15 +3201,13 @@ namespace Slang
//
SLANG_ASSERT(witnessTableVal->getOp() != kIROp_StructKey);
- auto inst = createInst<IRLookupWitnessMethod>(
- 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<IRDifferentialPairType>(diffPair->getDataType())->getValueType();
@@ -3477,6 +3499,17 @@ namespace Slang
&diffPair);
}
+ IRInst* IRBuilder::emitDifferentialPairAddressPrimal(IRInst* diffPair)
+ {
+ auto valueType = as<IRDifferentialPairType>(
+ as<IRPtrTypeBase>(diffPair->getDataType())->getValueType())->getValueType();
+ return emitIntrinsicInst(
+ this->getPtrType(kIROp_PtrType, valueType),
+ kIROp_DifferentialPairGetPrimal,
+ 1,
+ &diffPair);
+ }
+
IRInst* IRBuilder::emitMakeMatrix(
IRType* type,
UInt argCount,