llvm-project/mlir/lib/Debug/Observers/ActionLogging.cpp
Mehdi Amini f406adf134 Add capture of "IRUnits" as context for an MLIR Action
IRUnit is defined as:

  using IRUnit = PointerUnion<Operation *, Region *, Block *, Value>;

The tracing::Action is extended to take an ArrayRef<IRUnit> as context to
describe an Action. It is demonstrated in the "ActionLogging" observer.

Reviewed By: rriddle, Mogball

Differential Revision: https://reviews.llvm.org/D144814
2023-03-20 13:40:55 +01:00

63 lines
1.8 KiB
C++

//===- ActionLogging.cpp - Logging Actions *- C++ -*-========================//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "mlir/Debug/Observers/ActionLogging.h"
#include "mlir/IR/Action.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
using namespace mlir::tracing;
//===----------------------------------------------------------------------===//
// ActionLogger
//===----------------------------------------------------------------------===//
void ActionLogger::beforeExecute(const ActionActiveStack *action,
Breakpoint *breakpoint, bool willExecute) {
SmallVector<char> name;
llvm::get_thread_name(name);
if (name.empty()) {
llvm::raw_svector_ostream os(name);
os << llvm::get_threadid();
}
os << "[thread " << name << "] ";
if (willExecute)
os << "begins ";
else
os << "skipping ";
if (printBreakpoints) {
if (breakpoint)
os << "(on breakpoint: " << *breakpoint << ") ";
else
os << "(no breakpoint) ";
}
os << "Action ";
if (printActions)
action->getAction().print(os);
else
os << action->getAction().getTag();
if (printIRUnits) {
os << " (";
interleaveComma(action->getAction().getContextIRUnits(), os);
os << ")";
}
os << "`\n";
}
void ActionLogger::afterExecute(const ActionActiveStack *action) {
SmallVector<char> name;
llvm::get_thread_name(name);
if (name.empty()) {
llvm::raw_svector_ostream os(name);
os << llvm::get_threadid();
}
os << "[thread " << name << "] completed `" << action->getAction().getTag()
<< "`\n";
}