Halide 20.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
12namespace Halide {
13
14struct Expr;
15struct 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
20class Module;
21std::ostream &operator<<(std::ostream &stream, const Module &);
22
23struct Target;
24/** Emit a halide Target in a human readable form */
25std::ostream &operator<<(std::ostream &stream, const Target &);
26
27namespace Internal {
28
29struct Stmt;
30std::ostream &operator<<(std::ostream &stream, const Stmt &);
31
32struct LoweredFunc;
33std::ostream &operator<<(std::ostream &, const LoweredFunc &);
34
35bool 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#define debug(n) \
52 /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
53 (!debug_is_active((n))) ? (void)0 : ::Halide::Internal::Voidifier() & std::cerr
54
55/** Allow easily printing the contents of containers, or std::vector-like containers,
56 * in debug output. Used like so:
57 * std::vector<Type> arg_types;
58 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
59 * Which results in output like "arg_types: { uint8x8, uint8x8 }" on one line. */
60template<typename T>
61struct PrintSpan {
62 const T &span;
63 PrintSpan(const T &span)
64 : span(span) {
65 }
66};
67// Class template argument deduction (CTAD) guide to prevent warnings.
68template<typename T>
69PrintSpan(const T &) -> PrintSpan<T>;
70
71template<typename StreamT, typename T>
72inline StreamT &operator<<(StreamT &stream, const PrintSpan<T> &wrapper) {
73 stream << "{ ";
74 const char *sep = "";
75 for (const auto &e : wrapper.span) {
76 stream << sep << e;
77 sep = ", ";
78 }
79 stream << " }";
80 return stream;
81}
82
83/** Allow easily printing the contents of spans, or std::vector-like spans,
84 * in debug output. Used like so:
85 * std::vector<Type> arg_types;
86 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
87 * Which results in output like:
88 * arg_types:
89 * {
90 * uint8x8,
91 * uint8x8,
92 * }
93 * Indentation uses a tab character. */
94template<typename T>
96 const T &span;
97 PrintSpanLn(const T &span)
98 : span(span) {
99 }
100};
101// Class template argument deduction (CTAD) guide to prevent warnings.
102template<typename T>
104
105template<typename StreamT, typename T>
107 stream << "\n{\n";
108 for (const auto &e : wrapper.span) {
109 stream << "\t" << e << ",\n";
110 }
111 stream << "}\n";
112 return stream;
113}
114
115} // namespace Internal
116} // namespace Halide
117
118#endif
A halide module.
Definition Module.h:142
ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b)
bool debug_is_active_impl(int verbosity, const char *file, const char *function, int line)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
std::ostream & operator<<(std::ostream &stream, const Expr &)
Emit an expression on an output stream (such as std::cout) in human-readable form.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
A fragment of Halide syntax.
Definition Expr.h:258
Definition of a lowered function.
Definition Module.h:101
Allow easily printing the contents of containers, or std::vector-like containers, in debug output.
Definition Debug.h:61
PrintSpan(const T &span)
Definition Debug.h:63
Allow easily printing the contents of spans, or std::vector-like spans, in debug output.
Definition Debug.h:95
PrintSpanLn(const T &span)
Definition Debug.h:97
A reference-counted handle to a statement node.
Definition Expr.h:427
A struct representing a target machine and os to generate code for.
Definition Target.h:19
Types in the halide type system.
Definition Type.h:283