From 17e3b88b541ed7f45d575f0f9caaa808cd0a6619 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 1 Jun 2022 17:37:07 -0700 Subject: New language feature: basic error handling. (#2253) * New language feature: basic error handling. * Fix. * Fix `tryCall` encoding according to code review. Co-authored-by: Yong He --- source/slang/slang-ir-deduplicate.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source/slang/slang-ir-deduplicate.cpp') diff --git a/source/slang/slang-ir-deduplicate.cpp b/source/slang/slang-ir-deduplicate.cpp index f2c199af6..8aef7736c 100644 --- a/source/slang/slang-ir-deduplicate.cpp +++ b/source/slang/slang-ir-deduplicate.cpp @@ -76,4 +76,37 @@ namespace Slang for (auto inst : instToRemove) inst->removeAndDeallocate(); } + + void SharedIRBuilder::replaceGlobalInst(IRInst* oldInst, IRInst* newInst) + { + List uses; + for (auto use = oldInst->firstUse; use; use = use->nextUse) + { + uses.add(use); + } + + bool shouldUpdateGlobalNumberedCache = false; + for (auto use : uses) + { + use->set(newInst); + // depending on the type of the user inst, we may need to rebuild and update the global + // numbering cache. + if (isGloballyNumberedInst(use->getUser())) + { + shouldUpdateGlobalNumberedCache = true; + } + } + oldInst->removeAndDeallocate(); + if (shouldUpdateGlobalNumberedCache) + { + deduplicateAndRebuildGlobalNumberingMap(); + } + } + + bool SharedIRBuilder::isGloballyNumberedInst(IRInst* inst) + { + if (!inst->getParent() || inst->getParent()->getOp() != kIROp_Module) + return false; + return m_globalValueNumberingMap.ContainsKey(IRInstKey{inst}); + } } -- cgit v1.2.3