Coverage Report

Created: 2020-06-26 05:44

/home/arjun/llvm-project/mlir/lib/IR/Visitors.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Visitors.cpp - MLIR Visitor Utilities ------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "mlir/IR/Visitors.h"
10
#include "mlir/IR/Operation.h"
11
12
using namespace mlir;
13
14
/// Walk all of the operations nested under and including the given operations.
15
void detail::walkOperations(Operation *op,
16
0
                            function_ref<void(Operation *op)> callback) {
17
0
  // TODO(b/140235992) This walk should be iterative over the operations.
18
0
  for (auto &region : op->getRegions())
19
0
    for (auto &block : region)
20
0
      // Early increment here in the case where the operation is erased.
21
0
      for (auto &nestedOp : llvm::make_early_inc_range(block))
22
0
        walkOperations(&nestedOp, callback);
23
0
24
0
  callback(op);
25
0
}
26
27
/// Walk all of the operations nested under and including the given operations.
28
/// This methods walks operations until an interrupt signal is received.
29
WalkResult
30
detail::walkOperations(Operation *op,
31
0
                       function_ref<WalkResult(Operation *op)> callback) {
32
0
  // TODO(b/140235992) This walk should be iterative over the operations.
33
0
  for (auto &region : op->getRegions()) {
34
0
    for (auto &block : region) {
35
0
      // Early increment here in the case where the operation is erased.
36
0
      for (auto &nestedOp : llvm::make_early_inc_range(block))
37
0
        if (walkOperations(&nestedOp, callback).wasInterrupted())
38
0
          return WalkResult::interrupt();
39
0
    }
40
0
  }
41
0
  return callback(op);
42
0
}