summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-reachability.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-04-14 08:12:14 -0700
committerGitHub <noreply@github.com>2023-04-14 23:12:14 +0800
commit168c58389e9155312a8cef88d986a4ceee5a511e (patch)
tree1f1cda0335e8ecc6f25af2e94f369214198050d0 /source/slang/slang-ir-reachability.cpp
parent4c9c8a7a4d9b97fec6041a562638fbea521533ed (diff)
Diagnose on using uninitialized `out` param. (#2803)
* Diagnose on using uninitialized `out` param. * Hack to allow `out Vertices<T>`. * Fix. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-reachability.cpp')
-rw-r--r--source/slang/slang-ir-reachability.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/source/slang/slang-ir-reachability.cpp b/source/slang/slang-ir-reachability.cpp
new file mode 100644
index 000000000..9d36b9450
--- /dev/null
+++ b/source/slang/slang-ir-reachability.cpp
@@ -0,0 +1,39 @@
+#include "slang-ir-reachability.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.
+
+bool ReachabilityContext::computeReachability(IRBlock* block1, IRBlock* block2)
+{
+ workList.clear();
+ reachableBlocks.Clear();
+ workList.add(block1);
+ for (Index i = 0; i < workList.getCount(); i++)
+ {
+ auto src = workList[i];
+ for (auto successor : src->getSuccessors())
+ {
+ if (successor == block2)
+ return true;
+ if (reachableBlocks.Add(successor))
+ workList.add(successor);
+ }
+ }
+ return false;
+}
+
+bool ReachabilityContext::isBlockReachable(IRBlock* from, IRBlock* to)
+{
+ BlockPair pair;
+ pair.first = from;
+ pair.second = to;
+ bool result = false;
+ if (reachabilityResults.TryGetValue(pair, result))
+ return result;
+ result = computeReachability(from, to);
+ reachabilityResults[pair] = result;
+ return result;
+}
+}