summaryrefslogtreecommitdiff
path: root/source/slang/slang-lower-to-ir.cpp
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2022-10-26 22:21:29 -0400
committerGitHub <noreply@github.com>2022-10-26 19:21:29 -0700
commitf7f0dcadd3b2aca4c0bcd03a96e11c617cf69fc2 (patch)
tree574dff2bcb8c5a3de9e74d18346a424c82d62a7a /source/slang/slang-lower-to-ir.cpp
parent939be44ca23476e622dfb24a592383fe2a1da61f (diff)
Adding a differentiable standard library (#2465)
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
-rw-r--r--source/slang/slang-lower-to-ir.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp
index 1e58a456e..ff66caa90 100644
--- a/source/slang/slang-lower-to-ir.cpp
+++ b/source/slang/slang-lower-to-ir.cpp
@@ -8204,12 +8204,28 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
getBuilder()->addDecoration(irFunc, kIROp_ForceInlineDecoration);
}
+ // Register the value now, to avoid any possible infinite recursion when lowering CustomJVPAttribute
+ setGlobalValue(context, decl, LoweredValInfo::simple(findOuterMostGeneric(irFunc)));
+
if (auto attr = decl->findModifier<CustomJVPAttribute>())
{
- auto loweredVal = lowerLValueExpr(this->context, attr->funcDeclRef);
+ // TODO(Sai): HACK.. we need to emit a decl-ref to handle this modifier correctly.
+ // If we don't move the cursor to the parent, we sometimes emit supporting
+ // insts into the function body, which shouldn't happen.
+ //
+ subContext->irBuilder->setInsertInto(irFunc->getParent());
+
+ auto diffFuncType = getFuncType(subContext->astBuilder, attr->funcDeclRef->declRef.as<CallableDecl>());
+ auto irDiffFuncType = lowerType(subContext, diffFuncType);
+
+ auto loweredVal = emitDeclRef(subContext, attr->funcDeclRef->declRef, irDiffFuncType);
+
SLANG_ASSERT(loweredVal.flavor == LoweredValInfo::Flavor::Simple);
- IRFunc* jvpFunc = as<IRFunc>(loweredVal.val);
+ IRInst* jvpFunc = loweredVal.val;
getBuilder()->addDecoration(irFunc, kIROp_JVPDerivativeReferenceDecoration, jvpFunc);
+
+ // Reset cursor.
+ subContext->irBuilder->setInsertInto(irFunc);
}
// For convenience, ensure that any additional global