Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Debug.h
Go to the documentation of this file.
1#ifndef HALIDE_DEBUG_H
2#define HALIDE_DEBUG_H
3
4/** \file
5 * Defines functions for debug logging during code generation.
6 */
7
8#include <cstdlib>
9#include <iostream>
10#include <string>
11
12 namespace Halide {
13
14 struct Expr;
15 struct Type;
16// Forward declare some things from IRPrinter, which we can't include yet.
17std::ostream &operator<<(std::ostream &stream, const Expr &);
18std::ostream &operator<<(std::ostream &stream, const Type &);
19
20 class Module;
21std::ostream &operator<<(std::ostream &stream, const Module &);
22
23 struct Target;
24/** Emit a halide Target in a human readable form */
25std::ostream &operator<<(std::ostream &stream, const Target &);
26
27 namespace Internal {
28
29 struct Stmt;
30std::ostream &operator<<(std::ostream &stream, const Stmt &);
31
32 struct LoweredFunc;
33std::ostream &operator<<(std::ostream &, const LoweredFunc &);
34
35 bool debug_is_active_impl(int verbosity, const char *file, const char *function, int line);
36#define debug_is_active(n) (::Halide::Internal::debug_is_active_impl((n), __FILE__, __FUNCTION__, __LINE__))
37
38/** For optional debugging during codegen, use the debug macro as
39 * follows:
40 *
41 * \code
42 * debug(verbosity) << "The expression is " << expr << "\n";
43 * \endcode
44 *
45 * verbosity of 0 always prints, 1 should print after every major
46 * stage, 2 should be used for more detail, and 3 should be used for
47 * tracing everything that occurs. The verbosity with which to print
48 * is determined by the value of the environment variable
49 * HL_DEBUG_CODEGEN
50 */
51// clang-format off
52#define debug(n) \
53 /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
54 if (debug_is_active((n))) std::cerr
55// clang-format on
56
57/** Allow easily printing the contents of containers, or std::vector-like containers,
58 * in debug output. Used like so:
59 * std::vector<Type> arg_types;
60 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
61 * Which results in output like "arg_types: { uint8x8, uint8x8 }" on one line. */
62 template<typename T>
63 struct PrintSpan {
64 const T &span;
65 PrintSpan(const T &span)
66 : span(span) {
67 }
68};
69// Class template argument deduction (CTAD) guide to prevent warnings.
70 template<typename T>
71 PrintSpan(const T &) -> PrintSpan<T>;
72
73 template<typename StreamT, typename T>
74 inline StreamT &operator<<(StreamT &stream, const PrintSpan<T> &wrapper) {
75 stream << "{ ";
76 const char *sep = "";
77 for (const auto &e : wrapper.span) {
78 stream << sep << e;
79 sep = ", ";
80 }
81 stream << " }";
82 return stream;
83}
84
85/** Allow easily printing the contents of spans, or std::vector-like spans,
86 * in debug output. Used like so:
87 * std::vector<Type> arg_types;
88 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
89 * Which results in output like:
90 * arg_types:
91 * {
92 * uint8x8,
93 * uint8x8,
94 * }
95 * Indentation uses a tab character. */
96 template<typename T>
97 struct PrintSpanLn {
98 const T &span;
99 PrintSpanLn(const T &span)
100 : span(span) {
101 }
102};
103// Class template argument deduction (CTAD) guide to prevent warnings.
104 template<typename T>
105 PrintSpanLn(const T &) -> PrintSpanLn<T>;
106
107 template<typename StreamT, typename T>
108 inline StreamT &operator<<(StreamT &stream, const PrintSpanLn<T> &wrapper) {
109 stream << "\n{\n";
110 for (const auto &e : wrapper.span) {
111 stream << "\t" << e << ",\n";
112 }
113 stream << "}\n";
114 return stream;
115}
116
117} // namespace Internal
118} // namespace Halide
119
120#endif
Halide::Module
A halide module.
Definition Module.h:142
Halide::Internal::SyntheticParamType::Type
@ Type
Halide::Internal::operator<<
ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::debug_is_active_impl
bool debug_is_active_impl(int verbosity, const char *file, const char *function, int line)
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::operator<<
std::ostream & operator<<(std::ostream &stream, const Expr &)
Emit an expression on an output stream (such as std::cout) in human-readable form.
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Internal::LoweredFunc
Definition of a lowered function.
Definition Module.h:101
Halide::Internal::PrintSpan
Allow easily printing the contents of containers, or std::vector-like containers, in debug output.
Definition Debug.h:63
Halide::Internal::PrintSpan::PrintSpan
PrintSpan(const T &span)
Definition Debug.h:65
Halide::Internal::PrintSpan::span
const T & span
Definition Debug.h:64
Halide::Internal::PrintSpanLn
Allow easily printing the contents of spans, or std::vector-like spans, in debug output.
Definition Debug.h:97
Halide::Internal::PrintSpanLn::PrintSpanLn
PrintSpanLn(const T &span)
Definition Debug.h:99
Halide::Internal::PrintSpanLn::span
const T & span
Definition Debug.h:98
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition Expr.h:427
Halide::Target
A struct representing a target machine and os to generate code for.
Definition Target.h:19
Halide::Type
Types in the halide type system.
Definition Type.h:283