MLIR  19.0.0git
CLOptionsSetup.h
Go to the documentation of this file.
1 //===- CLOptionsSetup.h - Helpers to setup debug CL options -----*- 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_CLOPTIONSSETUP_H
10 #define MLIR_DEBUG_CLOPTIONSSETUP_H
11 
14 #include "llvm/ADT/StringRef.h"
15 
16 #include <memory>
17 
18 namespace mlir {
19 class MLIRContext;
20 namespace tracing {
21 class BreakpointManager;
22 
23 class DebugConfig {
24 public:
25  /// Register the options as global LLVM command line options.
26  static void registerCLOptions();
27 
28  /// Create a new config with the default set from the CL options.
30 
31  ///
32  /// Options.
33  ///
34 
35  /// Enable the Debugger action hook: it makes a debugger (like gdb or lldb)
36  /// able to intercept MLIR Actions.
37  void enableDebuggerActionHook(bool enabled = true) {
39  }
40 
41  /// Return true if the debugger action hook is enabled.
44  }
45 
46  /// Set the filename to use for logging actions, use "-" for stdout.
47  DebugConfig &logActionsTo(StringRef filename) {
48  logActionsToFlag = filename;
49  return *this;
50  }
51  /// Get the filename to use for logging actions.
52  StringRef getLogActionsTo() const { return logActionsToFlag; }
53 
54  /// Get the filename to use for profiling actions.
55  StringRef getProfileActionsTo() const { return profileActionsToFlag; }
56 
57  /// Set a location breakpoint manager to filter out action logging based on
58  /// the attached IR location in the Action context. Ownership stays with the
59  /// caller.
61  logActionLocationFilter.push_back(breakpointManager);
62  }
63 
64  /// Get the location breakpoint managers to use to filter out action logging.
67  }
68 
69 protected:
70  /// Enable the Debugger action hook: a debugger (like gdb or lldb) can
71  /// intercept MLIR Actions.
73 
74  /// Log action execution to the given file (or "-" for stdout)
75  std::string logActionsToFlag;
76 
77  /// Profile action execution to the given file (or "-" for stdout)
78  std::string profileActionsToFlag;
79 
80  /// Location Breakpoints to filter the action logging.
81  std::vector<tracing::BreakpointManager *> logActionLocationFilter;
82 };
83 
84 /// This is a RAII class that installs the debug handlers on the context
85 /// based on the provided configuration.
87 public:
88  InstallDebugHandler(MLIRContext &context, const DebugConfig &config);
90 
91 private:
92  class Impl;
93  std::unique_ptr<Impl> impl;
94 };
95 
96 } // namespace tracing
97 } // namespace mlir
98 
99 #endif // MLIR_DEBUG_CLOPTIONSSETUP_H
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
A breakpoint manager is responsible for managing a set of breakpoints and matching them to a given ac...
bool enableDebuggerActionHookFlag
Enable the Debugger action hook: a debugger (like gdb or lldb) can intercept MLIR Actions.
std::string logActionsToFlag
Log action execution to the given file (or "-" for stdout)
std::string profileActionsToFlag
Profile action execution to the given file (or "-" for stdout)
static DebugConfig createFromCLOptions()
Create a new config with the default set from the CL options.
StringRef getLogActionsTo() const
Get the filename to use for logging actions.
StringRef getProfileActionsTo() const
Get the filename to use for profiling actions.
void addLogActionLocFilter(tracing::BreakpointManager *breakpointManager)
Set a location breakpoint manager to filter out action logging based on the attached IR location in t...
static void registerCLOptions()
Register the options as global LLVM command line options.
bool isDebuggerActionHookEnabled() const
Return true if the debugger action hook is enabled.
DebugConfig & logActionsTo(StringRef filename)
Set the filename to use for logging actions, use "-" for stdout.
ArrayRef< tracing::BreakpointManager * > getLogActionsLocFilters() const
Get the location breakpoint managers to use to filter out action logging.
std::vector< tracing::BreakpointManager * > logActionLocationFilter
Location Breakpoints to filter the action logging.
void enableDebuggerActionHook(bool enabled=true)
Options.
This is a RAII class that installs the debug handlers on the context based on the provided configurat...
InstallDebugHandler(MLIRContext &context, const DebugConfig &config)
Include the generated interface declarations.