• 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 "sfn_debug.h"
28 
29 #include "util/u_debug.h"
30 
31 namespace r600 {
32 
stderr_streambuf()33 stderr_streambuf::stderr_streambuf() {}
34 
35 int
sync()36 stderr_streambuf::sync()
37 {
38    fflush(stderr);
39    return 0;
40 }
41 
42 int
overflow(int c)43 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    {"warn" ,    SfnLog::warn,        "Print warnings"                       },
69    DEBUG_NAMED_VALUE_END
70 };
71 
72 SfnLog sfn_log;
73 
74 std::streamsize
xsputn(const char * s,std::streamsize n)75 stderr_streambuf::xsputn(const char *s, std::streamsize n)
76 {
77    std::streamsize i = n;
78    while (i--)
79       fputc(*s++, stderr);
80    return n;
81 }
82 
SfnLog()83 SfnLog::SfnLog():
84     m_active_log_flags(0),
85     m_log_mask(0),
86     m_buf(),
87     m_output(&m_buf)
88 {
89    m_log_mask = debug_get_flags_option("R600_NIR_DEBUG", sfn_debug_options, 0);
90    m_log_mask ^= err;
91 }
92 
93 SfnLog&
operator <<(SfnLog::LogFlag const l)94 SfnLog::operator<<(SfnLog::LogFlag const l)
95 {
96    m_active_log_flags = l;
97    return *this;
98 }
99 
100 SfnLog&
operator <<(UNUSED std::ostream & (* f)(std::ostream &))101 SfnLog::operator<<(UNUSED std::ostream& (*f)(std::ostream&))
102 {
103    if (m_active_log_flags & m_log_mask)
104       m_output << f;
105    return *this;
106 }
107 
108 SfnLog&
operator <<(nir_shader & sh)109 SfnLog::operator<<(nir_shader& sh)
110 {
111    if (m_active_log_flags & m_log_mask)
112       nir_print_shader(&sh, stderr);
113    return *this;
114 }
115 
116 SfnLog&
operator <<(nir_instr & instr)117 SfnLog::operator<<(nir_instr& instr)
118 {
119    if (m_active_log_flags & m_log_mask)
120       nir_print_instr(&instr, stderr);
121    return *this;
122 }
123 
SfnTrace(SfnLog::LogFlag flag,const char * msg)124 SfnTrace::SfnTrace(SfnLog::LogFlag flag, const char *msg):
125     m_flag(flag),
126     m_msg(msg)
127 {
128    sfn_log << m_flag << std::string( 2 * m_indention++, ' ') << "BEGIN: " << m_msg << "\n";
129 }
130 
~SfnTrace()131 SfnTrace::~SfnTrace()
132 {
133    assert(m_indention > 0);
134    sfn_log << m_flag << std::string( 2 * m_indention--, ' ') << "END:   " << m_msg << "\n";
135 }
136 
137 int SfnTrace::m_indention = 0;
138 
139 } // namespace r600
140