MLIR 22.0.0git
TagBreakpointManager.h
Go to the documentation of this file.
1//===- TagBreakpointManager.h - Simple breakpoint Support -------*- 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_DEBUG_BREAKPOINTMANAGERS_TAGBREAKPOINTMANAGER_H
10#define MLIR_DEBUG_BREAKPOINTMANAGERS_TAGBREAKPOINTMANAGER_H
11
14#include "mlir/IR/Action.h"
15#include "llvm/ADT/MapVector.h"
16
17namespace mlir {
18namespace tracing {
19
20/// Simple breakpoint matching an action "tag".
21class TagBreakpoint : public BreakpointBase<TagBreakpoint> {
22public:
23 TagBreakpoint(StringRef tag) : tag(tag) {}
24
25 void print(raw_ostream &os) const override { os << "Tag: `" << tag << '`'; }
26
27private:
28 /// A tag to associate the TagBreakpoint with.
29 std::string tag;
30
31 /// Allow access to `tag`.
33};
34
35/// This is a manager to store a collection of breakpoints that trigger
36/// on tags.
38 : public BreakpointManagerBase<TagBreakpointManager> {
39public:
40 Breakpoint *match(const Action &action) const override {
41 auto it = breakpoints.find(action.getTag());
42 if (it != breakpoints.end() && it->second->isEnabled())
43 return it->second.get();
44 return {};
45 }
46
47 /// Add a breakpoint to the manager for the given tag and return it.
48 /// If a breakpoint already exists for the given tag, return the existing
49 /// instance.
50 TagBreakpoint *addBreakpoint(StringRef tag) {
51 auto result = breakpoints.try_emplace(tag);
52 auto &it = result.first;
53 if (result.second)
54 it->second = std::make_unique<TagBreakpoint>(tag.str());
55 return it->second.get();
56 }
57
58private:
59 llvm::StringMap<std::unique_ptr<TagBreakpoint>> breakpoints;
60};
61
62} // namespace tracing
63} // namespace mlir
64
65#endif // MLIR_DEBUG_BREAKPOINTMANAGERS_TAGBREAKPOINTMANAGER_H
An action is a specific action that is to be taken by the compiler, that can be toggled and controlle...
Definition Action.h:38
virtual StringRef getTag() const =0
Return a string "tag" which intends to uniquely identify this type of action.
This abstract class represents a breakpoint.
This is a manager to store a collection of breakpoints that trigger on tags.
TagBreakpoint * addBreakpoint(StringRef tag)
Add a breakpoint to the manager for the given tag and return it.
Breakpoint * match(const Action &action) const override
Try to match a Breakpoint to a given Action.
Simple breakpoint matching an action "tag".
void print(raw_ostream &os) const override
friend class TagBreakpointManager
Allow access to tag.
Include the generated interface declarations.