LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
GraphUtil.h
Go to the documentation of this file.
1//===-- GraphUtil.h ---------------------------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#pragma once
11
12#include <llvm/ADT/GraphTraits.h>
13#include <llvm/ADT/SCCIterator.h>
14
15namespace llzk {
16
17template <typename GraphT> inline bool hasCycle(const GraphT &G) {
18 for (llvm::scc_iterator<GraphT> I = llvm::scc_begin(G), E = llvm::scc_end(G); I != E; ++I) {
19 const std::vector<typename llvm::GraphTraits<GraphT>::NodeRef> &SCC = *I;
20 if (SCC.size() > 1) {
21 return true;
22 }
23 // Detect self-loop
24 auto *N = SCC.front();
25 for (auto *child : llvm::children<GraphT>(N)) {
26 if (child == N) {
27 return true;
28 }
29 }
30 }
31 return false;
32}
33
34} // namespace llzk
bool hasCycle(const GraphT &G)
Definition GraphUtil.h:17