MLIR  20.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 
13 #include "llvm/ADT/StringRef.h"
14 
15 #include <memory>
16 
17 namespace mlir {
18 class MLIRContext;
19 namespace tracing {
20 class BreakpointManager;
21 
22 class DebugConfig {
23 public:
24  /// Register the options as global LLVM command line options.
25  static void registerCLOptions();
26 
27  /// Create a new config with the default set from the CL options.
29 
30  ///
31  /// Options.
32  ///
33 
34  /// Enable the Debugger action hook: it makes a debugger (like gdb or lldb)
35  /// able to intercept MLIR Actions.
36  void enableDebuggerActionHook(bool enabled = true) {
38  }
39 
40  /// Return true if the debugger action hook is enabled.
43  }
44 
45  /// Set the filename to use for logging actions, use "-" for stdout.
46  DebugConfig &logActionsTo(StringRef filename) {
47  logActionsToFlag = filename;
48  return *this;
49  }
50  /// Get the filename to use for logging actions.
51  StringRef getLogActionsTo() const { return logActionsToFlag; }
52 
53  /// Get the filename to use for profiling actions.
54  StringRef getProfileActionsTo() const { return profileActionsToFlag; }
55 
56  /// Set a location breakpoint manager to filter out action logging based on
57  /// the attached IR location in the Action context. Ownership stays with the
58  /// caller.
60  logActionLocationFilter.push_back(breakpointManager);
61  }
62 
63  /// Get the location breakpoint managers to use to filter out action logging.
66  }
67 
68 protected:
69  /// Enable the Debugger action hook: a debugger (like gdb or lldb) can
70  /// intercept MLIR Actions.
72 
73  /// Log action execution to the given file (or "-" for stdout)
74  std::string logActionsToFlag;
75 
76  /// Profile action execution to the given file (or "-" for stdout)
77  std::string profileActionsToFlag;
78 
79  /// Location Breakpoints to filter the action logging.
80  std::vector<tracing::BreakpointManager *> logActionLocationFilter;
81 };
82 
83 /// This is a RAII class that installs the debug handlers on the context
84 /// based on the provided configuration.
86 public:
89 
90 private:
91  class Impl;
92  std::unique_ptr<Impl> impl;
93 };
94 
95 } // namespace tracing
96 } // namespace mlir
97 
98 #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.
const FrozenRewritePatternSet GreedyRewriteConfig config