blob: 1a3cab3862c458fd1ec2a03666a9808f52742a02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;
}
}
|