From dd57306d951dbcaf6471659fcd1d2c37738f36d0 Mon Sep 17 00:00:00 2001 From: Pankaj Mistry <63069047+pmistryNV@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:55:19 -0800 Subject: IRSPIRVAsmOperandInst instructions may not have IRBlock as the immediate parent. Previously special case was added to handle IRDecoration similarly. Replace this with a common method getBlock that traverses the parent chain till it gets to the Block (#3486) Fixes bug #3432 --- source/slang/slang-ir-util.cpp | 59 ++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) (limited to 'source/slang/slang-ir-util.cpp') diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp index b4a7b6b99..d859f86a6 100644 --- a/source/slang/slang-ir-util.cpp +++ b/source/slang/slang-ir-util.cpp @@ -1020,21 +1020,14 @@ IRInst* getVulkanPayloadLocation(IRInst* payloadGlobalVar) return location; } -void moveParams(IRBlock* dest, IRBlock* src) +IRInst* getInstInBlock(IRInst* inst) { - for (auto param = src->getFirstChild(); param;) - { - auto nextInst = param->getNextInst(); - if (as(param) || as(param)) - { - param->insertAtEnd(dest); - } - else - { - break; - } - param = nextInst; - } + SLANG_RELEASE_ASSERT(inst); + + if (const auto block = as(inst->getParent())) + return inst; + + return getInstInBlock(inst->getParent()); } void removePhiArgs(IRInst* phiParam) @@ -1216,6 +1209,26 @@ void resetScratchDataBit(IRInst* inst, int bitIndex) } } +/// +/// IRBlock related common helper methods +/// +void moveParams(IRBlock* dest, IRBlock* src) +{ + for (auto param = src->getFirstChild(); param;) + { + auto nextInst = param->getNextInst(); + if (as(param) || as(param)) + { + param->insertAtEnd(dest); + } + else + { + break; + } + param = nextInst; + } +} + List collectBlocksInRegion( IRDominatorTree* dom, IRLoop* loop, @@ -1338,6 +1351,23 @@ List collectBlocksInRegion(IRGlobalValueWithCode* func, IRLoop* loopIn return collectBlocksInRegion(dom, loopInst, &hasMultiLevelBreaks); } +IRBlock* getBlock(IRInst* inst) +{ + if (!inst) + return nullptr; + + while (inst) + { + if (auto block = as(inst)) + return block; + inst = inst->getParent(); + } + return nullptr; +} + +/// +/// End of IRBlock utility methods +/// IRVarLayout* findVarLayout(IRInst* value) { if (auto layoutDecoration = value->findDecoration()) @@ -1549,4 +1579,5 @@ IRType* dropNormAttributes(IRType* const t) return t; } + } -- cgit v1.2.3