diff options
| author | venkataram-nv <vedavamadath@nvidia.com> | 2024-07-31 11:51:09 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-31 11:51:09 -0700 |
| commit | 93a3ba812dd33b10f166f9172bd781e84d938e21 (patch) | |
| tree | fd5175d41a5b16f6de97ba37dd00267219ec3e4d /source/slang/slang-ir-reachability.cpp | |
| parent | 134f8ccc930a8da28808c2e288344c21c67a577e (diff) | |
Warnings target switch intrinsic asm (#4727)
* Proper warning generation for target switches and intrinsic asm
* Relaxing terminators
* Fix compiler warnings
* Rectified target switch reachability check
* Simplify target switch reachability check
* Refactoring variable names
* Using getBlocks
* Moving ad hoc special case to diagnostics source
* Using the LINE directive for testing
* Simplifying reliance on target switches
* Skipping IR generation for empty target switches
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir-reachability.cpp')
| -rw-r--r-- | source/slang/slang-ir-reachability.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/source/slang/slang-ir-reachability.cpp b/source/slang/slang-ir-reachability.cpp index 1a4aa271b..5a9d732ca 100644 --- a/source/slang/slang-ir-reachability.cpp +++ b/source/slang/slang-ir-reachability.cpp @@ -1,19 +1,20 @@ #include "slang-ir-reachability.h" +#include "slang-ir-insts.h" +#include "slang-ir-util.h" namespace Slang { -// Computes whether block1 can reach block2. -// A block is considered not reachable from itself unless there is a backedge in the CFG. - + // Computes whether block1 can reach block2. + // A block is considered not reachable from itself unless there is a backedge in the CFG. ReachabilityContext::ReachabilityContext(IRGlobalValueWithCode* code) { int id = 0; for (auto block : code->getBlocks()) { - mapBlockToId[block] = id; - id++; + mapBlockToId[block] = id++; allBlocks.add(block); } + sourceBlocks.setCount(allBlocks.getCount()); for (auto &srcBlock : sourceBlocks) srcBlock.resizeAndClear(allBlocks.getCount()); @@ -23,6 +24,7 @@ namespace Slang List<IRBlock*> workList; List<IRBlock*> pendingWorkList; + workList.add(allBlocks[0]); while (workList.getCount()) { @@ -52,17 +54,37 @@ namespace Slang } workList.swapWith(pendingWorkList); } + } + + bool ReachabilityContext::isInstReachable(IRInst* from, IRInst* to) + { + // If inst1 and inst2 are in the same block, + // we test if inst2 appears after inst1. + if (getBlock(from) == getBlock(to)) + { + for (auto inst = from->getNextInst(); inst; inst = inst->getNextInst()) + { + if (inst == to) + return true; + } + } + return isBlockReachable(getBlock(from), getBlock(to)); } bool ReachabilityContext::isBlockReachable(IRBlock* from, IRBlock* to) { - if (!from) return false; - if (!to) return false; + if (!from) + return false; + + if (!to) + return false; + int* fromId = mapBlockToId.tryGetValue(from); int* toId = mapBlockToId.tryGetValue(to); if (!fromId || !toId) return true; + return sourceBlocks[*toId].contains(*fromId); } } |
