Loading...
Searching...
No Matches
Debug.h
Go to the documentation of this file.
#ifndef HALIDE_DEBUG_H
#define HALIDE_DEBUG_H
/** \file
* Defines functions for debug logging during code generation.
*/
#include <cstdlib>
#include <iostream>
#include <string>
namespace Halide {
struct Expr;
struct Type;
// Forward declare some things from IRPrinter, which we can't include yet.
std::ostream &operator<<(std::ostream &stream, const Expr &);
std::ostream &operator<<(std::ostream &stream, const Type &);
class Module;
std::ostream &operator<<(std::ostream &stream, const Module &);
struct Target;
/** Emit a halide Target in a human readable form */
std::ostream &operator<<(std::ostream &stream, const Target &);
namespace Internal {
struct Stmt;
std::ostream &operator<<(std::ostream &stream, const Stmt &);
struct LoweredFunc;
std::ostream &operator<<(std::ostream &, const LoweredFunc &);
bool debug_is_active_impl(int verbosity, const char *file, const char *function, int line);
#define debug_is_active(n) (::Halide::Internal::debug_is_active_impl((n), __FILE__, __FUNCTION__, __LINE__))
/** For optional debugging during codegen, use the debug macro as
* follows:
*
* \code
* debug(verbosity) << "The expression is " << expr << "\n";
* \endcode
*
* verbosity of 0 always prints, 1 should print after every major
* stage, 2 should be used for more detail, and 3 should be used for
* tracing everything that occurs. The verbosity with which to print
* is determined by the value of the environment variable
* HL_DEBUG_CODEGEN
*/
// clang-format off
#define debug(n) \
/* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \
if (debug_is_active((n))) std::cerr
// clang-format on
/** Allow easily printing the contents of containers, or std::vector-like containers,
* in debug output. Used like so:
* std::vector<Type> arg_types;
* debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
* Which results in output like "arg_types: { uint8x8, uint8x8 }" on one line. */
template<typename T>
struct PrintSpan {
const T &span;
PrintSpan(const T &span)
: span(span) {
}
};
// Class template argument deduction (CTAD) guide to prevent warnings.
template<typename T>
PrintSpan(const T &) -> PrintSpan<T>;
template<typename StreamT, typename T>
inline StreamT &operator<<(StreamT &stream, const PrintSpan<T> &wrapper) {
stream << "{ ";
const char *sep = "";
for (const auto &e : wrapper.span) {
stream << sep << e;
sep = ", ";
}
stream << " }";
return stream;
}
/** Allow easily printing the contents of spans, or std::vector-like spans,
* in debug output. Used like so:
* std::vector<Type> arg_types;
* debug(4) << "arg_types: " << PrintSpan(arg_types) << "\n";
* Which results in output like:
* arg_types:
* {
* uint8x8,
* uint8x8,
* }
* Indentation uses a tab character. */
template<typename T>
struct PrintSpanLn {
const T &span;
PrintSpanLn(const T &span)
: span(span) {
}
};
// Class template argument deduction (CTAD) guide to prevent warnings.
template<typename T>
PrintSpanLn(const T &) -> PrintSpanLn<T>;
template<typename StreamT, typename T>
inline StreamT &operator<<(StreamT &stream, const PrintSpanLn<T> &wrapper) {
stream << "\n{\n";
for (const auto &e : wrapper.span) {
stream << "\t" << e << ",\n";
}
stream << "}\n";
return stream;
}
} // namespace Internal
} // namespace Halide
#endif
Halide::Module
A halide module.
Definition Module.h:142
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::PrintSpanLn
PrintSpanLn(const T &) -> PrintSpanLn< T >
Halide::Internal::operator<<
ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::PrintSpan
PrintSpan(const T &) -> PrintSpan< T >
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::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::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