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
52#define debug(n) \
53 /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
54 if (debug_is_active((n))) std::cerr
55
56/** Allow easily printing the contents of containers, or std::vector-like containers,
57 * in debug output. Used like so:
58 * std::vector<Type> arg_types;
59 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
60 * Which results in output like "arg_types: { uint8x8, uint8x8 }" on one line. */
61 template<typename T>
62 struct PrintSpan {
63 const T &span;
64 PrintSpan(const T &span)
65 : span(span) {
66 }
67};
68// Class template argument deduction (CTAD) guide to prevent warnings.
69 template<typename T>
70 PrintSpan(const T &) -> PrintSpan<T>;
71
72 template<typename StreamT, typename T>
73 inline StreamT &operator<<(StreamT &stream, const PrintSpan<T> &wrapper) {
74 stream << "{ ";
75 const char *sep = "";
76 for (const auto &e : wrapper.span) {
77 stream << sep << e;
78 sep = ", ";
79 }
80 stream << " }";
81 return stream;
82}
83
84/** Allow easily printing the contents of spans, or std::vector-like spans,
85 * in debug output. Used like so:
86 * std::vector<Type> arg_types;
87 * debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
88 * Which results in output like:
89 * arg_types:
90 * {
91 * uint8x8,
92 * uint8x8,
93 * }
94 * Indentation uses a tab character. */
95 template<typename T>
96 struct PrintSpanLn {
97 const T &span;
98 PrintSpanLn(const T &span)
99 : span(span) {
100 }
101};
102// Class template argument deduction (CTAD) guide to prevent warnings.
103 template<typename T>
104 PrintSpanLn(const T &) -> PrintSpanLn<T>;
105
106 template<typename StreamT, typename T>
107 inline StreamT &operator<<(StreamT &stream, const PrintSpanLn<T> &wrapper) {
108 stream << "\n{\n";
109 for (const auto &e : wrapper.span) {
110 stream << "\t" << e << ",\n";
111 }
112 stream << "}\n";
113 return stream;
114}
115
116} // namespace Internal
117} // namespace Halide
118
119#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:62
Halide::Internal::PrintSpan::PrintSpan
PrintSpan(const T &span)
Definition Debug.h:64
Halide::Internal::PrintSpan::span
const T & span
Definition Debug.h:63
Halide::Internal::PrintSpanLn
Allow easily printing the contents of spans, or std::vector-like spans, in debug output.
Definition Debug.h:96
Halide::Internal::PrintSpanLn::PrintSpanLn
PrintSpanLn(const T &span)
Definition Debug.h:98
Halide::Internal::PrintSpanLn::span
const T & span
Definition Debug.h:97
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:281