LLZK
3.0.0
An open-source IR for Zero Knowledge (ZK) circuits
Toggle main menu visibility
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
20
template
<
typename
MatchType,
typename
R>
inline
static
bool
walkContains(R &root) {
21
return
root.walk([](MatchType) {
return
mlir::WalkResult::interrupt(); }).wasInterrupted();
22
}
23
28
template
<
typename
MatchType,
typename
R>
29
inline
static
bool
walkContains(R &root, llvm::function_ref<
bool
(MatchType)> pred) {
30
return
root
31
.walk([&pred](MatchType t) {
32
return
pred(t) ? mlir::WalkResult::interrupt() :
mlir
::WalkResult::advance();
33
}).wasInterrupted();
34
}
35
37
template
<
typename
MatchType,
typename
R>
38
inline
static
llvm::SmallVector<MatchType> walkCollect(R &root) {
39
llvm::SmallVector<MatchType> collected;
40
root.walk([&collected](MatchType op) { collected.push_back(op); });
41
return
collected;
42
}
43
46
template
<
typename
MatchType,
typename
R>
47
inline
static
llvm::SmallVector<MatchType>
48
walkCollect(R &root, llvm::function_ref<
bool
(MatchType)> pred) {
49
llvm::SmallVector<MatchType> collected;
50
root.walk([&collected, &pred](MatchType op) {
51
if
(pred(op)) {
52
collected.push_back(op);
53
}
54
});
55
return
collected;
56
}
57
60
template
<
typename
MatchType,
typename
R,
typename
Map>
61
inline
static
auto
walkCollectMapped(R &root, Map &&map) {
62
using
MappedType = std::invoke_result_t<Map &, MatchType &>;
63
64
llvm::SmallVector<MappedType> collected;
65
root.walk([&collected, &map](MatchType op) { collected.push_back(map(op)); });
66
return
collected;
67
}
mlir
Definition
ValueModel.h:30
include
llzk
Util
Walk.h
Generated by
1.17.0
Copyright 2025 Veridise Inc. under the Apache License v2.0. Copyright 2026 Project LLZK under the Apache License v2.0.