diff options
| author | Pankaj Mistry <63069047+pmistryNV@users.noreply.github.com> | 2024-01-24 13:55:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-24 13:55:19 -0800 |
| commit | dd57306d951dbcaf6471659fcd1d2c37738f36d0 (patch) | |
| tree | ce67cd68ce243028947c76e53db314929a1889f2 /source/slang/slang-ir-util.cpp | |
| parent | 70f6ae4e0427890bf5674e9cca307356125c5c10 (diff) | |
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
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
| -rw-r--r-- | source/slang/slang-ir-util.cpp | 59 |
1 files changed, 45 insertions, 14 deletions
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<IRDecoration>(param) || as<IRParam, IRDynamicCastBehavior::NoUnwrap>(param)) - { - param->insertAtEnd(dest); - } - else - { - break; - } - param = nextInst; - } + SLANG_RELEASE_ASSERT(inst); + + if (const auto block = as<IRBlock>(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<IRDecoration>(param) || as<IRParam, IRDynamicCastBehavior::NoUnwrap>(param)) + { + param->insertAtEnd(dest); + } + else + { + break; + } + param = nextInst; + } +} + List<IRBlock*> collectBlocksInRegion( IRDominatorTree* dom, IRLoop* loop, @@ -1338,6 +1351,23 @@ List<IRBlock*> collectBlocksInRegion(IRGlobalValueWithCode* func, IRLoop* loopIn return collectBlocksInRegion(dom, loopInst, &hasMultiLevelBreaks); } +IRBlock* getBlock(IRInst* inst) +{ + if (!inst) + return nullptr; + + while (inst) + { + if (auto block = as<IRBlock>(inst)) + return block; + inst = inst->getParent(); + } + return nullptr; +} + +/// +/// End of IRBlock utility methods +/// IRVarLayout* findVarLayout(IRInst* value) { if (auto layoutDecoration = value->findDecoration<IRLayoutDecoration>()) @@ -1549,4 +1579,5 @@ IRType* dropNormAttributes(IRType* const t) return t; } + } |
