From 2e1c15f36b42374455228e37885bdb221f302050 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 2 Nov 2022 12:12:18 -0700 Subject: Rework differential conformance dictionary checking. (#2483) * Rework differential conformance dictionary checking. * Revert space changes. Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 122 +++++----------------------------------------- 1 file changed, 12 insertions(+), 110 deletions(-) (limited to 'source/slang/slang-ir.cpp') 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( - 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(parent)) - break; - - // Inserting into a basic block inside of - // a generic? That is okay too. - if (auto block = as(parent)) - { - if (as(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( - this, - kIROp_DifferentiableTypeDictionaryItem, - nullptr, - 2, - args); + IRInst* args[2] = {irType, conformanceWitness}; + item = createInstWithTrailingArgs( + 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(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() { -- cgit v1.2.3