Halide 16.0.0
Halide compiler and libraries
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
35/** For optional debugging during codegen, use the debug class as
36 * follows:
37 *
38 \code
39 debug(verbosity) << "The expression is " << expr << "\n";
40 \endcode
41 *
42 * verbosity of 0 always prints, 1 should print after every major
43 * stage, 2 should be used for more detail, and 3 should be used for
44 * tracing everything that occurs. The verbosity with which to print
45 * is determined by the value of the environment variable
46 * HL_DEBUG_CODEGEN
47 */
48
49class debug {
50 const bool logging;
51
52public:
53 debug(int verbosity)
54 : logging(verbosity <= debug_level()) {
55 }
56
57 template<typename T>
58 debug &operator<<(T &&x) {
59 if (logging) {
60 std::cerr << std::forward<T>(x);
61 }
62 return *this;
63 }
64
65 static int debug_level();
66};
67
68} // namespace Internal
69} // namespace Halide
70
71#endif
For optional debugging during codegen, use the debug class as follows:
Definition: Debug.h:49
debug & operator<<(T &&x)
Definition: Debug.h:58
static int debug_level()
debug(int verbosity)
Definition: Debug.h:53
A halide module.
Definition: Module.h:138
std::ostream & operator<<(std::ostream &stream, const Stmt &)
Emit a halide statement on an output stream (such as std::cout) in a human-readable form.
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.
A fragment of Halide syntax.
Definition: Expr.h:257
Definition of a lowered function.
Definition: Module.h:97
A reference-counted handle to a statement node.
Definition: Expr.h:418
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:276