Halide
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.
17 std::ostream &operator<<(std::ostream &stream, const Expr &);
18 std::ostream &operator<<(std::ostream &stream, const Type &);
19 
20 class Module;
21 std::ostream &operator<<(std::ostream &stream, const Module &);
22 
23 struct Target;
24 /** Emit a halide Target in a human readable form */
25 std::ostream &operator<<(std::ostream &stream, const Target &);
26 
27 namespace Internal {
28 
29 struct Stmt;
30 std::ostream &operator<<(std::ostream &stream, const Stmt &);
31 
32 struct LoweredFunc;
33 std::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 
49 class debug {
50  const bool logging;
51 
52 public:
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
Halide::Internal::operator<<
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.
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::Internal::debug::operator<<
debug & operator<<(T &&x)
Definition: Debug.h:58
Halide::Internal::debug::debug_level
static int debug_level()
Halide::Internal::debug
For optional debugging during codegen, use the debug class as follows:
Definition: Debug.h:49
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::Internal::SyntheticParamType::Type
@ Type
Halide::Internal::debug::debug
debug(int verbosity)
Definition: Debug.h:53