• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mesa-c++  -*-
2  *
3  * Copyright (c) 2019 Collabora LTD
4  *
5  * Author: Gert Wollny <gert.wollny@collabora.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * on the rights to use, copy, modify, merge, publish, distribute, sub
11  * license, and/or sell copies of the Software, and to permit persons to whom
12  * the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 
27 #include "util/u_debug.h"
28 #include "sfn_debug.h"
29 
30 namespace r600 {
31 
stderr_streambuf()32 stderr_streambuf::stderr_streambuf()
33 {
34 
35 }
36 
sync()37 int stderr_streambuf::sync()
38 {
39    fflush(stderr);
40    return 0;
41 }
42 
overflow(int c)43 int stderr_streambuf::overflow(int c)
44 {
45    fputc(c, stderr);
46    return 0;
47 }
48 
49 static const struct debug_named_value sfn_debug_options[] = {
50    {"instr", SfnLog::instr, "Log all consumed nir instructions"},
51    {"ir", SfnLog::r600ir, "Log created R600 IR"},
52    {"cc", SfnLog::cc, "Log R600 IR to assembly code creation"},
53    {"noerr", SfnLog::err, "Don't log shader conversion errors"},
54    {"si", SfnLog::shader_info, "Log shader info (non-zero values)"},
55    {"ts", SfnLog::test_shader, "Log shaders in tests"},
56    {"reg", SfnLog::reg, "Log register allocation and lookup"},
57    {"io", SfnLog::io, "Log shader in and output"},
58    {"ass", SfnLog::assembly, "Log IR to assembly conversion"},
59    {"flow", SfnLog::flow, "Log Flow instructions"},
60    {"merge", SfnLog::merge, "Log register merge operations"},
61    {"nomerge", SfnLog::nomerge, "Skip register merge step"},
62    {"tex", SfnLog::tex, "Log texture ops"},
63    {"trans", SfnLog::trans, "Log generic translation messages"},
64    {"schedule", SfnLog::schedule, "Log scheduling"},
65    {"opt", SfnLog::opt, "Log optimization"},
66    {"steps", SfnLog::steps, "Log shaders at transformation steps"},
67    {"noopt", SfnLog::noopt, "Don't run backend optimizations"},
68    DEBUG_NAMED_VALUE_END
69 };
70 
71 SfnLog sfn_log;
72 
xsputn(const char * s,std::streamsize n)73 std::streamsize stderr_streambuf::xsputn ( const char *s, std::streamsize n )
74 {
75    std::streamsize i = n;
76    while (i--)
77       fputc(*s++, stderr);
78    return n;
79 }
80 
SfnLog()81 SfnLog::SfnLog():
82    m_active_log_flags(0),
83    m_log_mask(0),
84    m_buf(),
85    m_output(&m_buf)
86 {
87    m_log_mask = debug_get_flags_option("R600_NIR_DEBUG", sfn_debug_options, 0);
88    m_log_mask ^= err;
89 }
90 
operator <<(SfnLog::LogFlag const l)91 SfnLog& SfnLog::operator << (SfnLog::LogFlag const l)
92 {
93    m_active_log_flags = l;
94    return *this;
95 }
96 
operator <<(UNUSED std::ostream & (* f)(std::ostream &))97 SfnLog& SfnLog::operator << (UNUSED std::ostream & (*f)(std::ostream&))
98 {
99    if (m_active_log_flags & m_log_mask)
100       m_output << f;
101    return *this;
102 }
103 
operator <<(nir_shader & sh)104 SfnLog& SfnLog::operator << (nir_shader& sh)
105 {
106    if (m_active_log_flags & m_log_mask)
107       nir_print_shader(&sh, stderr);
108    return *this;
109 }
110 
operator <<(nir_instr & instr)111 SfnLog& SfnLog::operator << (nir_instr &instr)
112 {
113    if (m_active_log_flags & m_log_mask)
114       nir_print_instr(&instr, stderr);
115    return *this;
116 }
117 
SfnTrace(SfnLog::LogFlag flag,const char * msg)118 SfnTrace::SfnTrace(SfnLog::LogFlag flag, const char *msg):
119    m_flag(flag),
120    m_msg(msg)
121 {
122    sfn_log << m_flag << std::string(" ", 2 * m_indention++)
123            << "BEGIN: " << m_msg << "\n";
124 }
125 
~SfnTrace()126 SfnTrace::~SfnTrace()
127 {
128    sfn_log << m_flag << std::string(" ", 2 * m_indention--)
129            << "END:   " << m_msg << "\n";
130 }
131 
132 int SfnTrace::m_indention = 0;
133 
134 }
135