diff options
| author | Yong He <yonghe@outlook.com> | 2022-11-02 12:12:18 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-02 12:12:18 -0700 |
| commit | 2e1c15f36b42374455228e37885bdb221f302050 (patch) | |
| tree | 57ab722b87e1ef327860e4293bad9edc53bba965 /source/slang/slang-ir.cpp | |
| parent | fb29bd32cc3404455ff92916a91c517823f486dd (diff) | |
Rework differential conformance dictionary checking. (#2483)
* Rework differential conformance dictionary checking.
* Revert space changes.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 122 |
1 files changed, 12 insertions, 110 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 382f7be5e..083ef98c5 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3546,133 +3546,35 @@ namespace Slang value->insertAtEnd(parent); } } - - IRInst* IRBuilder::emitDifferentiableTypeDictionary() - { - auto inst = createInst<IRInst>( - this, - kIROp_DifferentiableTypeDictionary, - nullptr); - - addGlobalValue(this, inst); - return inst; - } - - IRInst* IRBuilder::findOrEmitDifferentiableTypeDictionary() + IRInst* IRBuilder::addDifferentiableTypeDictionaryDecoration(IRInst* target) { - auto currentLoc = this->getInsertLoc(); - auto currentInst = currentLoc.getInst(); - - if (auto diffTypeDictionary = findDifferentiableTypeDictionary(currentInst)) - return diffTypeDictionary; - - return emitDifferentiableTypeDictionary(); + return addDecoration(target, kIROp_DifferentiableTypeDictionaryDecoration); } - IRInst* IRBuilder::findDifferentiableTypeDictionary(IRInst* parent) - { - //auto parent = inst->getParent(); - while (parent) - { - // Inserting into the top level of a module? - // That is fine, and we can stop searching. - if (as<IRModuleInst>(parent)) - break; - - // Inserting into a basic block inside of - // a generic? That is okay too. - if (auto block = as<IRBlock>(parent)) - { - if (as<IRGeneric>(block->parent)) - break; - } - - // Otherwise, move up the chain. - parent = parent->parent; - } - - for (auto child = parent->getFirstChild(); child; child = child->getNextInst()) - { - if (child->getOp() == kIROp_DifferentiableTypeDictionary) - return child; - } - - return nullptr; - } - - IRInst* IRBuilder::addDifferentiableTypeEntry(IRInst* irType, IRInst* conformanceWitness) + IRInst* IRBuilder::addDifferentiableTypeEntry(IRInst* dictDecoration, IRInst* irType, IRInst* conformanceWitness) { auto oldLoc = this->getInsertLoc(); IRDifferentiableTypeDictionaryItem* item = nullptr; - if (auto diffTypeDictionary = findOrEmitDifferentiableTypeDictionary()) - { - this->setInsertInto(diffTypeDictionary); + this->setInsertInto(dictDecoration); - IRInst* args[2] = {irType, conformanceWitness}; - item = createInstWithTrailingArgs<IRDifferentiableTypeDictionaryItem>( - this, - kIROp_DifferentiableTypeDictionaryItem, - nullptr, - 2, - args); + IRInst* args[2] = {irType, conformanceWitness}; + item = createInstWithTrailingArgs<IRDifferentiableTypeDictionaryItem>( + this, + kIROp_DifferentiableTypeDictionaryItem, + nullptr, + 2, + args); - addInst(item); - } + addInst(item); this->setInsertLoc(oldLoc); return item; } - IRInst* IRBuilder::findDifferentiableTypeEntry(IRInst* irType, IRInst* scope) - { - IRInst* foundResult = nullptr; - for (auto child = scope->getFirstChild(); child; child = child->getNextInst()) - { - if (child->getOp() == kIROp_DifferentiableTypeDictionary) - { - for (auto entry = child->getFirstChild(); entry; entry = entry->getNextInst()) - { - IRInst* entryType = entry->getOperand(0); - IRInst* entryConformanceWitness = entry->getOperand(1); - - if (irType == entryType) - { - foundResult = entryConformanceWitness; - // If the found witness table is not a trivial one (i.e. DifferentialBottom:IDifferential), - // return immediately. Otherwise, continue the search to see if we can find a better one. - if (auto witness = as<IRWitnessTable>(foundResult)) - { - if (witness->getConcreteType()->getOp() != kIROp_DifferentialBottomType) - return foundResult; - } - } - } - } - } - - return foundResult; - } - - IRInst* IRBuilder::findDifferentiableTypeEntry(IRInst* irType) - { - auto instScope = this->getInsertLoc().getInst(); - - while (instScope) - { - if (auto witness = findDifferentiableTypeEntry(irType, instScope)) - { - return witness; - } - instScope = instScope->getParent(); - } - - return nullptr; - } - IRFunc* IRBuilder::createFunc() { |
