Skip to content

Commit

Permalink
Address review comments, make visited a set
Browse files Browse the repository at this point in the history
  • Loading branch information
prithayan committed Aug 17, 2023
1 parent 61dcb9d commit 4012431
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/Dialect/FIRRTL/Transforms/CheckCombLoops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class DiscoverLoops {
});
}

std::string getName(FieldRef v) { return getFieldName(v).first; };
static std::string getName(FieldRef v) { return getFieldName(v).first; };

unsigned getOrAddNode(Value v) {
auto iter = valToFieldRefs.find(v);
Expand Down Expand Up @@ -451,17 +451,17 @@ class DiscoverLoops {
SmallVector<bool> onStack(numNodes, false);
SmallVector<unsigned> dfsStack;

auto hasCycle = [&](unsigned rootNode, SmallVector<bool> &visited,
auto hasCycle = [&](unsigned rootNode, DenseSet<unsigned> &visited,
bool recordPortPaths = false) {
if (visited[rootNode])
if (visited.contains(rootNode))
return success();
dfsStack.push_back(rootNode);

while (!dfsStack.empty()) {
auto currentNode = dfsStack.back();

if (!visited[currentNode]) {
visited[currentNode] = true;
if (!visited.contains(currentNode)) {
visited.insert(currentNode);
onStack[currentNode] = true;
LLVM_DEBUG(llvm::dbgs()
<< "\n visiting :"
Expand All @@ -485,7 +485,7 @@ class DiscoverLoops {
}

for (auto neighbor : graph[currentNode].second) {
if (!visited[neighbor]) {
if (!visited.contains(neighbor)) {
dfsStack.push_back(neighbor);
} else if (onStack[neighbor]) {
// Cycle found !!
Expand All @@ -511,15 +511,15 @@ class DiscoverLoops {
return success();
};

SmallVector<bool> visited(numNodes, false);
DenseSet<unsigned> visited;
for (unsigned node = 0; node < graph.size(); ++node) {
bool isPort = false;
if (auto arg =
dyn_cast<BlockArgument>(reachingDefGraph[node].first.getValue()))
if (module.getPortDirection(arg.getArgNumber()) == Direction::Out) {
// For output ports, reset the visited. Required to revisit the entire
// graph, to discover all the paths that exist from any input port.
std::fill_n(visited.begin(), numNodes, false);
visited.clear();
isPort = true;
}

Expand Down

0 comments on commit 4012431

Please sign in to comment.