aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/r600/sfn/sfn_debug.cpp
blob: a766ff63f2b4342bef829020138590327160b142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* -*- mesa-c++  -*-
 *
 * Copyright (c) 2019 Collabora LTD
 *
 * Author: Gert Wollny <gert.wollny@collabora.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#include "util/u_debug.h"
#include "sfn_debug.h"

namespace r600 {

class stderr_streambuf : public std::streambuf
{
public:
   stderr_streambuf();
protected:
   int sync();
   int overflow(int c);
   std::streamsize xsputn ( const char *s, std::streamsize n );
};

stderr_streambuf::stderr_streambuf()
{

}

int stderr_streambuf::sync()
{
   fflush(stderr);
   return 0;
}

int stderr_streambuf::overflow(int c)
{
   fputc(c, stderr);
   return 0;
}

static const struct debug_named_value sfn_debug_options[] = {
   {"instr", SfnLog::instr, "Log all consumed nir instructions"},
   {"ir", SfnLog::r600ir, "Log created R600 IR"},
   {"cc", SfnLog::cc, "Log R600 IR to assembly code creation"},
   {"noerr", SfnLog::err, "Don't log shader conversion errors"},
   {"si", SfnLog::shader_info, "Log shader info (non-zero values)"},
   {"ts", SfnLog::test_shader, "Log shaders in tests"},
   {"reg", SfnLog::reg, "Log register allocation and lookup"},
   {"io", SfnLog::io, "Log shader in and output"},
   {"ass", SfnLog::assembly, "Log IR to assembly conversion"},
   {"flow", SfnLog::flow, "Log Flow instructions"},
   {"merge", SfnLog::merge, "Log register merge operations"},
   {"nomerge", SfnLog::nomerge, "Skup egister merge step"},
   {"tex", SfnLog::tex, "Log texture ops"},
   {"trans", SfnLog::trans, "Log generic translation messages"},
   DEBUG_NAMED_VALUE_END
};

SfnLog sfn_log;

std::streamsize stderr_streambuf::xsputn ( const char *s, std::streamsize n )
{
   std::streamsize i = n;
   while (i--)
      fputc(*s++, stderr);
   return n;
}

SfnLog::SfnLog():
   m_active_log_flags(0),
   m_log_mask(0),
   m_output(new stderr_streambuf())
{
   m_log_mask = debug_get_flags_option("R600_NIR_DEBUG", sfn_debug_options, 0);
   m_log_mask ^= err;
}

SfnLog& SfnLog::operator << (SfnLog::LogFlag const l)
{
   m_active_log_flags = l;
   return *this;
}

SfnLog& SfnLog::operator << (UNUSED std::ostream & (*f)(std::ostream&))
{
   if (m_active_log_flags & m_log_mask)
      m_output << f;
   return *this;
}

SfnLog& SfnLog::operator << (nir_shader& sh)
{
   if (m_active_log_flags & m_log_mask)
      nir_print_shader(&sh, stderr);
   return *this;
}

SfnLog& SfnLog::operator << (nir_instr &instr)
{
   if (m_active_log_flags & m_log_mask)
      nir_print_instr(&instr, stderr);
   return *this;
}

SfnTrace::SfnTrace(SfnLog::LogFlag flag, const char *msg):
   m_flag(flag),
   m_msg(msg)
{
   sfn_log << m_flag << std::string(" ", 2 * m_indention++)
           << "BEGIN: " << m_msg << "\n";
}

SfnTrace::~SfnTrace()
{
   sfn_log << m_flag << std::string(" ", 2 * m_indention--)
           << "END:   " << m_msg << "\n";
}

int SfnTrace::m_indention = 0;

}