LLZK 2.1.1
An open-source IR for Zero Knowledge (ZK) circuits
Loading...
Searching...
No Matches
Walk.h
Go to the documentation of this file.
1//===-- Walk.h --------------------------------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2026 Project LLZK
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#pragma once
11
12#include <mlir/IR/Visitors.h>
13
14#include <llvm/ADT/STLFunctionalExtras.h>
15#include <llvm/ADT/SmallVector.h>
16
21template <typename MatchType, typename R>
22inline static bool walkContainsMatch(R &root, llvm::function_ref<bool(MatchType)> pred) {
23 return root
24 .walk([&pred](MatchType t) {
25 return pred(t) ? mlir::WalkResult::interrupt() : mlir::WalkResult::advance();
26 }).wasInterrupted();
27}
28
32template <typename MatchType, typename R> inline static bool walkContains(R &root) {
33 return root.walk([](MatchType t) { return mlir::WalkResult::interrupt(); }).wasInterrupted();
34}
35
38template <typename MatchType, typename R>
39inline static llvm::SmallVector<MatchType> walkCollect(R &root) {
40 llvm::SmallVector<MatchType> collected;
41 root.walk([&collected](MatchType op) { collected.push_back(op); });
42 return collected;
43}