1//===- DumpNotifications.h - Test notifications -----------------*- C++ -*-===//
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#ifndef MLIR_TEST_LIB_IR_DUMPNOTIFICATIONS_H
10#define MLIR_TEST_LIB_IR_DUMPNOTIFICATIONS_H
11
12#include "mlir/IR/PatternMatch.h"
13#include "llvm/Support/raw_ostream.h"
14
15namespace mlir {
16struct DumpNotifications : public RewriterBase::Listener {
17 void notifyBlockInserted(Block *block, Region *previous,
18 Region::iterator previousIt) override {
19 llvm::outs() << "notifyBlockInserted";
20 if (block->getParentOp()) {
21 llvm::outs() << " into " << block->getParentOp()->getName() << ": ";
22 } else {
23 llvm::outs() << " into unknown op: ";
24 }
25 if (previous == nullptr) {
26 llvm::outs() << "was unlinked\n";
27 } else {
28 llvm::outs() << "was linked\n";
29 }
30 }
31 void notifyOperationInserted(Operation *op,
32 OpBuilder::InsertPoint previous) override {
33 llvm::outs() << "notifyOperationInserted: " << op->getName();
34 if (!previous.isSet()) {
35 llvm::outs() << ", was unlinked\n";
36 } else {
37 if (!previous.getPoint().getNodePtr()) {
38 llvm::outs() << ", was linked, exact position unknown\n";
39 } else if (previous.getPoint() == previous.getBlock()->end()) {
40 llvm::outs() << ", was last in block\n";
41 } else {
42 llvm::outs() << ", previous = " << previous.getPoint()->getName()
43 << "\n";
44 }
45 }
46 }
47 void notifyBlockErased(Block *block) override {
48 llvm::outs() << "notifyBlockErased\n";
49 }
50 void notifyOperationErased(Operation *op) override {
51 llvm::outs() << "notifyOperationErased: " << op->getName() << "\n";
52 }
53 void notifyOperationModified(Operation *op) override {
54 llvm::outs() << "notifyOperationModified: " << op->getName() << "\n";
55 }
56 void notifyOperationReplaced(Operation *op, ValueRange values) override {
57 llvm::outs() << "notifyOperationReplaced: " << op->getName() << "\n";
58 }
59};
60} // namespace mlir
61
62#endif // MLIR_TEST_LIB_IR_DUMPNOTIFICATIONS_H
63