From 93a3ba812dd33b10f166f9172bd781e84d938e21 Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Wed, 31 Jul 2024 11:51:09 -0700 Subject: 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 --- source/slang/slang-ir-reachability.cpp | 36 +++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) (limited to 'source/slang/slang-ir-reachability.cpp') 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 workList; List 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); } } -- cgit v1.2.3