2020-01-20 11:14:37 +08:00
|
|
|
//===- Visitors.cpp - MLIR Visitor Utilities ------------------------------===//
|
2019-08-30 04:04:22 +08:00
|
|
|
//
|
2020-01-26 11:58:30 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
2019-12-24 01:35:36 +08:00
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2019-08-30 04:04:22 +08:00
|
|
|
//
|
2019-12-24 01:35:36 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2019-08-30 04:04:22 +08:00
|
|
|
|
|
|
|
#include "mlir/IR/Visitors.h"
|
|
|
|
#include "mlir/IR/Operation.h"
|
|
|
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
|
|
|
/// Walk all of the operations nested under and including the given operations.
|
|
|
|
void detail::walkOperations(Operation *op,
|
|
|
|
function_ref<void(Operation *op)> callback) {
|
|
|
|
// TODO(b/140235992) This walk should be iterative over the operations.
|
|
|
|
for (auto ®ion : op->getRegions())
|
|
|
|
for (auto &block : region)
|
|
|
|
// Early increment here in the case where the operation is erased.
|
|
|
|
for (auto &nestedOp : llvm::make_early_inc_range(block))
|
|
|
|
walkOperations(&nestedOp, callback);
|
|
|
|
|
|
|
|
callback(op);
|
|
|
|
}
|
2019-08-31 03:47:24 +08:00
|
|
|
|
|
|
|
/// Walk all of the operations nested under and including the given operations.
|
|
|
|
/// This methods walks operations until an interrupt signal is received.
|
|
|
|
WalkResult
|
|
|
|
detail::walkOperations(Operation *op,
|
|
|
|
function_ref<WalkResult(Operation *op)> callback) {
|
|
|
|
// TODO(b/140235992) This walk should be iterative over the operations.
|
|
|
|
for (auto ®ion : op->getRegions()) {
|
|
|
|
for (auto &block : region) {
|
|
|
|
// Early increment here in the case where the operation is erased.
|
|
|
|
for (auto &nestedOp : llvm::make_early_inc_range(block))
|
|
|
|
if (walkOperations(&nestedOp, callback).wasInterrupted())
|
|
|
|
return WalkResult::interrupt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return callback(op);
|
|
|
|
}
|