1//===- ActionLogging.h - Logging Actions *- 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_TRACING_OBSERVERS_ACTIONLOGGING_H
10#define MLIR_TRACING_OBSERVERS_ACTIONLOGGING_H
11
12#include "mlir/Debug/BreakpointManager.h"
13#include "mlir/Debug/ExecutionContext.h"
14#include "mlir/IR/Action.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/Support/raw_ostream.h"
17
18namespace mlir {
19namespace tracing {
20
21/// This class defines an observer that print Actions before and after execution
22/// on the provided stream.
23struct ActionLogger : public ExecutionContext::Observer {
24 ActionLogger(raw_ostream &os, bool printActions = true,
25 bool printBreakpoints = true, bool printIRUnits = true)
26 : os(os), printActions(printActions), printBreakpoints(printBreakpoints),
27 printIRUnits(printIRUnits) {}
28
29 void beforeExecute(const ActionActiveStack *action, Breakpoint *breakpoint,
30 bool willExecute) override;
31 void afterExecute(const ActionActiveStack *action) override;
32
33 /// If one of multiple breakpoint managers are set, only actions that are
34 /// matching a breakpoint will be logged.
35 void addBreakpointManager(const BreakpointManager *manager) {
36 breakpointManagers.push_back(x: manager);
37 }
38
39private:
40 /// Check if we should log this action or not.
41 bool shouldLog(const ActionActiveStack *action);
42
43 raw_ostream &os;
44 bool printActions;
45 bool printBreakpoints;
46 bool printIRUnits;
47 std::vector<const BreakpointManager *> breakpointManagers;
48};
49
50} // namespace tracing
51} // namespace mlir
52
53#endif // MLIR_TRACING_OBSERVERS_ACTIONLOGGING_H
54

source code of mlir/include/mlir/Debug/Observers/ActionLogging.h