CIRCT 22.0.0git
Loading...
Searching...
No Matches
Debug.h
Go to the documentation of this file.
1//===- Debug.h - Debug Utilities --------------------------------*- 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// Utilities related to generating run-time debug information.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_SUPPORT_DEBUG_H
14#define CIRCT_SUPPORT_DEBUG_H
15
16#include "mlir/Pass/Pass.h"
17#include "llvm/ADT/Twine.h"
18#include "llvm/Support/Debug.h"
19
20namespace circt {
21
22/// Write a "header"-like string to the debug stream with a certain width. This
23/// produces output like the following:
24///
25/// ===- Hello World --------------------===
26///
27/// This is commonly used for generating a header in debug information. The
28/// format is modeled after LLVM/MLIR/CIRCT source file headers.
29llvm::raw_ostream &debugHeader(const llvm::Twine &str, unsigned width = 80);
30
31/// Write a boilerplate header for a pass to the debug stream. This generates
32/// output like the following if the pass's name is "FooPass":
33///
34/// ===- Running FooPass -----------------===
35///
36/// This is commonly used to generate a header in debug when a pass starts
37/// running.
38llvm::raw_ostream &debugPassHeader(const mlir::Pass *pass, unsigned width = 80);
39
40/// Write a boilerplate footer to the debug stream to indicate that a pass has
41/// ended. This produces text like the following:
42///
43/// ===-----------------------------------===
44llvm::raw_ostream &debugFooter(unsigned width = 80);
45
46#ifndef NDEBUG
47/// RAII helper for creating a pass header and footer automatically. The heaer
48/// is printed on construction and the footer on destruction.
50
51public:
52 ScopedDebugPassLogger(const mlir::Pass *pass, unsigned width = 80)
53 : pass(pass), width(width) {
54 if (::llvm::DebugFlag &&
55 ::llvm::isCurrentDebugType(pass->getArgument().data(), 1))
56 debugPassHeader(pass, width) << "\n";
57 }
58
60 if (::llvm::DebugFlag &&
61 ::llvm::isCurrentDebugType(pass->getArgument().data(), 1))
62 debugFooter(width) << "\n";
63 }
64
65private:
66 const mlir::Pass *pass;
67 unsigned width;
68};
69
70#define CIRCT_DEBUG_SCOPED_PASS_LOGGER(PASS) \
71 ScopedDebugPassLogger _scopedDebugPassLogger(PASS)
72#else
73#define CIRCT_DEBUG_SCOPED_PASS_LOGGER(PASS) \
74 do { \
75 } while (0)
76#endif
77
78} // namespace circt
79
80#endif // CIRCT_SUPPORT_DEBUG_H
RAII helper for creating a pass header and footer automatically.
Definition Debug.h:49
ScopedDebugPassLogger(const mlir::Pass *pass, unsigned width=80)
Definition Debug.h:52
const mlir::Pass * pass
Definition Debug.h:66
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
llvm::raw_ostream & debugHeader(const llvm::Twine &str, unsigned width=80)
Write a "header"-like string to the debug stream with a certain width.
Definition Debug.cpp:17
llvm::raw_ostream & debugPassHeader(const mlir::Pass *pass, unsigned width=80)
Write a boilerplate header for a pass to the debug stream.
Definition Debug.cpp:31
llvm::raw_ostream & debugFooter(unsigned width=80)
Write a boilerplate footer to the debug stream to indicate that a pass has ended.
Definition Debug.cpp:36