1 /* -*- mesa-c++ -*-
2 * Copyright 2019 Collabora LTD
3 * Author: Gert Wollny <[email protected]>
4 * SPDX-License-Identifier: MIT
5 */
6
7 #include "sfn_debug.h"
8
9 #include "util/u_debug.h"
10
11 namespace r600 {
12
stderr_streambuf()13 stderr_streambuf::stderr_streambuf() {}
14
15 int
sync()16 stderr_streambuf::sync()
17 {
18 fflush(stderr);
19 return 0;
20 }
21
22 int
overflow(int c)23 stderr_streambuf::overflow(int c)
24 {
25 fputc(c, stderr);
26 return 0;
27 }
28
29 static const struct debug_named_value sfn_debug_options[] = {
30 {"instr", SfnLog::instr, "Log all consumed nir instructions" },
31 {"ir", SfnLog::r600ir, "Log created R600 IR" },
32 {"cc", SfnLog::cc, "Log R600 IR to assembly code creation"},
33 {"noerr", SfnLog::err, "Don't log shader conversion errors" },
34 {"si", SfnLog::shader_info, "Log shader info (non-zero values)" },
35 {"ts", SfnLog::test_shader, "Log shaders in tests" },
36 {"reg", SfnLog::reg, "Log register allocation and lookup" },
37 {"io", SfnLog::io, "Log shader in and output" },
38 {"ass", SfnLog::assembly, "Log IR to assembly conversion" },
39 {"flow", SfnLog::flow, "Log Flow instructions" },
40 {"merge", SfnLog::merge, "Log register merge operations" },
41 {"nomerge", SfnLog::nomerge, "Skip register merge step" },
42 {"tex", SfnLog::tex, "Log texture ops" },
43 {"trans", SfnLog::trans, "Log generic translation messages" },
44 {"schedule", SfnLog::schedule, "Log scheduling" },
45 {"opt", SfnLog::opt, "Log optimization" },
46 {"steps", SfnLog::steps, "Log shaders at transformation steps" },
47 {"noopt", SfnLog::noopt, "Don't run backend optimizations" },
48 {"warn" , SfnLog::warn, "Print warnings" },
49 DEBUG_NAMED_VALUE_END
50 };
51
52 SfnLog sfn_log;
53
54 std::streamsize
xsputn(const char * s,std::streamsize n)55 stderr_streambuf::xsputn(const char *s, std::streamsize n)
56 {
57 std::streamsize i = n;
58 while (i--)
59 fputc(*s++, stderr);
60 return n;
61 }
62
SfnLog()63 SfnLog::SfnLog():
64 m_active_log_flags(0),
65 m_log_mask(0),
66 m_buf(),
67 m_output(&m_buf)
68 {
69 m_log_mask = debug_get_flags_option("R600_NIR_DEBUG", sfn_debug_options, 0);
70 m_log_mask ^= err;
71 }
72
73 SfnLog&
operator <<(SfnLog::LogFlag const l)74 SfnLog::operator<<(SfnLog::LogFlag const l)
75 {
76 m_active_log_flags = l;
77 return *this;
78 }
79
80 SfnLog&
operator <<(UNUSED std::ostream & (* f)(std::ostream &))81 SfnLog::operator<<(UNUSED std::ostream& (*f)(std::ostream&))
82 {
83 if (m_active_log_flags & m_log_mask)
84 m_output << f;
85 return *this;
86 }
87
88 SfnLog&
operator <<(nir_shader & sh)89 SfnLog::operator<<(nir_shader& sh)
90 {
91 if (m_active_log_flags & m_log_mask)
92 nir_print_shader(&sh, stderr);
93 return *this;
94 }
95
96 SfnLog&
operator <<(nir_instr & instr)97 SfnLog::operator<<(nir_instr& instr)
98 {
99 if (m_active_log_flags & m_log_mask)
100 nir_print_instr(&instr, stderr);
101 return *this;
102 }
103
SfnTrace(SfnLog::LogFlag flag,const char * msg)104 SfnTrace::SfnTrace(SfnLog::LogFlag flag, const char *msg):
105 m_flag(flag),
106 m_msg(msg)
107 {
108 sfn_log << m_flag << std::string( 2 * m_indention++, ' ') << "BEGIN: " << m_msg << "\n";
109 }
110
~SfnTrace()111 SfnTrace::~SfnTrace()
112 {
113 assert(m_indention > 0);
114 sfn_log << m_flag << std::string( 2 * m_indention--, ' ') << "END: " << m_msg << "\n";
115 }
116
117 int SfnTrace::m_indention = 0;
118
119 } // namespace r600
120