summaryrefslogtreecommitdiffstats
path: root/source/slang
diff options
context:
space:
mode:
authorPankaj Mistry <63069047+pmistryNV@users.noreply.github.com>2024-01-24 13:55:19 -0800
committerGitHub <noreply@github.com>2024-01-24 13:55:19 -0800
commitdd57306d951dbcaf6471659fcd1d2c37738f36d0 (patch)
treece67cd68ce243028947c76e53db314929a1889f2 /source/slang
parent70f6ae4e0427890bf5674e9cca307356125c5c10 (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')
-rw-r--r--source/slang/slang-ir-autodiff.cpp21
-rw-r--r--source/slang/slang-ir-autodiff.h4
-rw-r--r--source/slang/slang-ir-util.cpp59
-rw-r--r--source/slang/slang-ir-util.h12
-rw-r--r--source/slang/slang-ir-validate.cpp9
5 files changed, 58 insertions, 47 deletions
diff --git a/source/slang/slang-ir-autodiff.cpp b/source/slang/slang-ir-autodiff.cpp
index 9acb6756e..2605dd028 100644
--- a/source/slang/slang-ir-autodiff.cpp
+++ b/source/slang/slang-ir-autodiff.cpp
@@ -2109,27 +2109,6 @@ bool finalizeAutoDiffPass(TargetRequest* target, IRModule* module)
return modified;
}
-IRBlock* getBlock(IRInst* inst)
-{
- if (!inst)
- return nullptr;
-
- if (auto block = as<IRBlock>(inst))
- return block;
-
- return getBlock(inst->getParent());
-}
-
-IRInst* getInstInBlock(IRInst* inst)
-{
- SLANG_RELEASE_ASSERT(inst);
-
- if (const auto block = as<IRBlock>(inst->getParent()))
- return inst;
-
- return getInstInBlock(inst->getParent());
-}
-
UIndex addPhiOutputArg(IRBuilder* builder, IRBlock* block, IRInst*& inoutTerminatorInst, IRInst* arg)
{
SLANG_RELEASE_ASSERT(as<IRUnconditionalBranch>(block->getTerminator()));
diff --git a/source/slang/slang-ir-autodiff.h b/source/slang/slang-ir-autodiff.h
index 0f688c84f..a3e8c8de7 100644
--- a/source/slang/slang-ir-autodiff.h
+++ b/source/slang/slang-ir-autodiff.h
@@ -394,10 +394,6 @@ inline bool isRelevantDifferentialPair(IRType* type)
return false;
}
-IRBlock* getBlock(IRInst* inst);
-
-IRInst* getInstInBlock(IRInst* inst);
-
UIndex addPhiOutputArg(IRBuilder* builder, IRBlock* block, IRInst*& inoutTerminatorInst, IRInst* arg);
IRUse* findUniqueStoredVal(IRVar* var);
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;
}
+
}
diff --git a/source/slang/slang-ir-util.h b/source/slang/slang-ir-util.h
index 096b008d9..c76898aa2 100644
--- a/source/slang/slang-ir-util.h
+++ b/source/slang/slang-ir-util.h
@@ -217,7 +217,7 @@ IRInst* findWitnessTableEntry(IRWitnessTable* table, IRInst* key);
IRInst* getVulkanPayloadLocation(IRInst* payloadGlobalVar);
-void moveParams(IRBlock* dest, IRBlock* src);
+IRInst* getInstInBlock(IRInst* inst);
void removePhiArgs(IRInst* phiParam);
@@ -233,6 +233,10 @@ IRPtrTypeBase* isMutablePointerType(IRInst* inst);
void initializeScratchData(IRInst* inst);
void resetScratchDataBit(IRInst* inst, int bitIndex);
+///
+/// IRBlock related common helper methods
+///
+void moveParams(IRBlock* dest, IRBlock* src);
List<IRBlock*> collectBlocksInRegion(
IRDominatorTree* dom,
@@ -265,6 +269,12 @@ List<IRBlock*> collectBlocksInRegion(IRGlobalValueWithCode* func, IRLoop* loopI
HashSet<IRBlock*> getParentBreakBlockSet(IRDominatorTree* dom, IRBlock* block);
+IRBlock* getBlock(IRInst* inst);
+
+///
+/// End of IRBlock utility methods
+///
+
IRVarLayout* findVarLayout(IRInst* value);
UnownedStringSlice getBuiltinFuncName(IRInst* callee);
diff --git a/source/slang/slang-ir-validate.cpp b/source/slang/slang-ir-validate.cpp
index af793bb54..5caa8a66e 100644
--- a/source/slang/slang-ir-validate.cpp
+++ b/source/slang/slang-ir-validate.cpp
@@ -4,6 +4,7 @@
#include "slang-ir.h"
#include "slang-ir-insts.h"
#include "slang-ir-dominators.h"
+#include "slang-ir-util.h"
namespace Slang
{
@@ -144,13 +145,7 @@ namespace Slang
auto operandParent = operandValue->getParent();
- auto instParentBlock = as<IRBlock>(instParent);
- if (!instParentBlock && as<IRDecoration>(inst))
- {
- instParent = instParent->getParent();
- instParentBlock = as<IRBlock>(instParent);
- }
-
+ auto instParentBlock = getBlock(inst);
if (instParentBlock)
{
if (auto operandParentBlock = as<IRBlock>(operandParent))