diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-16 12:17:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-16 12:17:49 -0800 |
| commit | 801aa3b44254341018a1acbe754f2ce3b0900e2a (patch) | |
| tree | b3066778522edb99bf64c0ac80c91b0b4cb788f8 /source/slang/slang-lower-to-ir.cpp | |
| parent | 09d8e048d2264d89886cda8e87e8a452d4f913c1 (diff) | |
Clean up type checking of higher order expressions. (#2519)
* Clean up type checking of higher order expressions.
* Replace `goto` with `break` to pacify clang.
* Fix.
* Fixes.
* Fix more tests.
* Fix lowerWitnessTable parameter error.
* Exclude attributes from ast printing.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-lower-to-ir.cpp')
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index dc0af4f96..4c3f4d646 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -19,7 +19,6 @@ #include "slang-ir-string-hash.h" #include "slang-ir-clone.h" #include "slang-ir-lower-error-handling.h" - #include "slang-mangle.h" #include "slang-type-layout.h" #include "slang-visitor.h" @@ -6040,11 +6039,11 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> IRGenContext* subContext, WitnessTable* astWitnessTable, IRWitnessTable* irWitnessTable, - Dictionary<WitnessTable*, IRWitnessTable*> mapASTToIRWitnessTable) + Dictionary<WitnessTable*, IRWitnessTable*> &mapASTToIRWitnessTable) { auto subBuilder = subContext->irBuilder; - for(auto entry : astWitnessTable->requirementList) + for(auto entry : astWitnessTable->requirementDictionary) { auto requiredMemberDecl = entry.Key; auto satisfyingWitness = entry.Value; @@ -8273,6 +8272,16 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> // Reset cursor. subContext->irBuilder->setInsertInto(irFunc); } + + // For convenience, ensure that any additional global + // values that were emitted while outputting the function + // body appear before the function itself in the list + // of global values. + irFunc->moveToEnd(); + + // If this function is defined inside an interface, add a reference to the IRFunc from + // the interface's type definition. + auto finalVal = finishOuterGenerics(subBuilder, irFunc, outerGeneric); if (auto attr = decl->findModifier<ForwardDerivativeOfAttribute>()) { @@ -8281,7 +8290,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> NestedContext originalContextFunc(this); auto originalSubBuilder = originalContextFunc.getBuilder(); auto originalSubContext = originalContextFunc.getContext(); - + if (auto outterGeneric = getOuterGeneric(irFunc)) + originalSubBuilder->setInsertBefore(outterGeneric); + else + originalSubBuilder->setInsertBefore(irFunc); auto originalFuncDecl = as<FunctionDeclBase>(originalDeclRefExpr->declRef.getDecl()); SLANG_RELEASE_ASSERT(originalFuncDecl); @@ -8294,27 +8306,10 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo> auto derivativeFuncVal = lowerRValueExpr(originalSubContext, attr->backDeclRef); originalSubBuilder->addForwardDerivativeDecoration(originalFuncVal, derivativeFuncVal.val); } - - subContext->irBuilder->setInsertInto(irFunc->getParent()); - auto loweredVal = lowerRValueExpr(subContext, attr->funcExpr); - - SLANG_ASSERT(loweredVal.flavor == LoweredValInfo::Flavor::Simple); - IRInst* originalFunc = loweredVal.val; - getBuilder()->addDecoration(irFunc, kIROp_ForwardDerivativeDecoration, originalFunc); - + getBuilder()->addForwardDifferentiableDecoration(irFunc); subContext->irBuilder->setInsertInto(irFunc); + finalVal->moveToEnd(); } - - // For convenience, ensure that any additional global - // values that were emitted while outputting the function - // body appear before the function itself in the list - // of global values. - irFunc->moveToEnd(); - - // If this function is defined inside an interface, add a reference to the IRFunc from - // the interface's type definition. - auto finalVal = finishOuterGenerics(subBuilder, irFunc, outerGeneric); - return LoweredValInfo::simple(finalVal); } |
