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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
|
/* -*- mesa-c++ -*-
*
* Copyright (c) 2018-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 "sfn_value_gpr.h"
#include "sfn_valuepool.h"
#include "sfn_debug.h"
#include "sfn_liverange.h"
namespace r600 {
using std::vector;
using std::array;
GPRValue::GPRValue(uint32_t sel, uint32_t chan, int base_offset):
Value(Value::gpr, chan),
m_sel(sel),
m_base_offset(base_offset),
m_input(false)
{
}
GPRValue::GPRValue(uint32_t sel, uint32_t chan):
Value(Value::gpr, chan),
m_sel(sel),
m_base_offset(0),
m_input(false)
{
}
uint32_t GPRValue::sel() const
{
return m_sel;
}
void GPRValue::do_print(std::ostream& os) const
{
os << 'R';
os << m_sel;
os << '.' << component_names[chan()];
}
bool GPRValue::is_equal_to(const Value& other) const
{
assert(other.type() == Value::Type::gpr);
const auto& rhs = static_cast<const GPRValue&>(other);
return (sel() == rhs.sel() &&
chan() == rhs.chan());
}
void GPRValue::do_print(std::ostream& os, UNUSED const PrintFlags& flags) const
{
os << 'R';
os << m_sel;
os << '.' << component_names[chan()];
}
GPRVector::GPRVector(const GPRVector& orig):
Value(gpr_vector),
m_elms(orig.m_elms),
m_valid(orig.m_valid)
{
}
GPRVector::GPRVector(std::array<PValue,4> elms):
Value(gpr_vector),
m_elms(elms),
m_valid(false)
{
for (unsigned i = 0; i < 4; ++i)
if (!m_elms[i] || (m_elms[i]->type() != Value::gpr)) {
assert(0 && "GPR vector not valid because element missing or nit a GPR");
return;
}
unsigned sel = m_elms[0]->sel();
for (unsigned i = 1; i < 4; ++i)
if (m_elms[i]->sel() != sel) {
assert(0 && "GPR vector not valid because sel is not equal for all elements");
return;
}
m_valid = true;
}
GPRVector::GPRVector(uint32_t sel, std::array<uint32_t,4> swizzle):
Value (gpr_vector),
m_valid(true)
{
for (int i = 0; i < 4; ++i)
m_elms[i] = PValue(new GPRValue(sel, swizzle[i]));
}
GPRVector::GPRVector(const GPRVector& orig, const std::array<uint8_t,4>& swizzle)
{
for (int i = 0; i < 4; ++i)
m_elms[i] = orig.reg_i(swizzle[i]);
m_valid = orig.m_valid;
}
void GPRVector::validate() const
{
assert(m_elms[0]);
uint32_t sel = m_elms[0]->sel();
if (sel >= 124)
return;
for (unsigned i = 1; i < 4; ++i) {
assert(m_elms[i]);
if (sel != m_elms[i]->sel())
return;
}
m_valid = true;
}
uint32_t GPRVector::sel() const
{
validate();
assert(m_valid);
return m_elms[0] ? m_elms[0]->sel() : 999;
}
void GPRVector::set_reg_i(int i, PValue reg)
{
m_elms[i] = reg;
}
void GPRVector::pin_to_channel(int i)
{
auto& v = static_cast<GPRValue&>(*m_elms[i]);
v.pin_to_channel();
}
void GPRVector::do_print(std::ostream& os) const
{
os << "R" << sel() << ".";
for (int i = 0; i < 4; ++i)
os << (m_elms[i] ? component_names[m_elms[i]->chan() < 8 ? m_elms[i]->chan() : 8] : '?');
}
void GPRVector::swizzle(const Swizzle& swz)
{
Values v(m_elms);
for (uint32_t i = 0; i < 4; ++i)
if (i != swz[i]) {
assert(swz[i] < 4);
m_elms[i] = v[swz[i]];
}
}
bool GPRVector::is_equal_to(const Value& other) const
{
if (other.type() != gpr_vector) {
std::cerr << "t";
return false;
}
const GPRVector& o = static_cast<const GPRVector&>(other);
for (int i = 0; i < 4; ++i) {
if (*m_elms[i] != *o.m_elms[i]) {
std::cerr << "elm" << i;
return false;
}
}
return true;
}
GPRArrayValue::GPRArrayValue(PValue value, PValue addr, GPRArray *array):
Value(gpr_array_value, value->chan()),
m_value(value),
m_addr(addr),
m_array(array)
{
}
GPRArrayValue::GPRArrayValue(PValue value, GPRArray *array):
Value(gpr_array_value, value->chan()),
m_value(value),
m_array(array)
{
}
static const char *swz_char = "xyzw01_";
void GPRArrayValue::do_print(std::ostream& os) const
{
assert(m_array);
os << "R" << m_value->sel();
if (m_addr) {
os << "[" << *m_addr << "] ";
}
os << swz_char[m_value->chan()];
os << "(" << *m_array << ")";
}
bool GPRArrayValue::is_equal_to(const Value& other) const
{
const GPRArrayValue& v = static_cast<const GPRArrayValue&>(other);
return *m_value == *v.m_value &&
*m_array == *v.m_array;
}
void GPRArrayValue::record_read(LiverangeEvaluator& ev) const
{
if (m_addr) {
ev.record_read(*m_addr);
unsigned chan = m_value->chan();
assert(m_array);
m_array->record_read(ev, chan);
} else
ev.record_read(*m_value);
}
void GPRArrayValue::record_write(LiverangeEvaluator& ev) const
{
if (m_addr) {
ev.record_read(*m_addr);
unsigned chan = m_value->chan();
assert(m_array);
m_array->record_write(ev, chan);
} else
ev.record_write(*m_value);
}
void GPRArrayValue::reset_value(PValue new_value)
{
m_value = new_value;
}
void GPRArrayValue::reset_addr(PValue new_addr)
{
m_addr = new_addr;
}
GPRArray::GPRArray(int base, int size, int mask, int frac):
Value (gpr_vector),
m_base_index(base),
m_component_mask(mask),
m_frac(frac)
{
m_values.resize(size);
for (int i = 0; i < size; ++i) {
for (int j = 0; j < 4; ++j) {
if (mask & (1 << j))
m_values[i].set_reg_i(j, PValue(new GPRValue(base + i, j)));
}
}
}
uint32_t GPRArray::sel() const
{
return m_base_index;
}
static const char *compchar = "xyzw";
void GPRArray::do_print(std::ostream& os) const
{
os << "ARRAY[R" << sel() << "..R" << sel() + m_values.size() - 1 << "].";
for (int j = 0; j < 4; ++j) {
if (m_component_mask & (1 << j))
os << compchar[j];
}
}
bool GPRArray::is_equal_to(const Value& other) const
{
const GPRArray& o = static_cast<const GPRArray&>(other);
return o.sel() == sel() &&
o.m_values.size() == m_values.size() &&
o.m_component_mask == m_component_mask;
}
uint32_t GPRArrayValue::sel() const
{
return m_value->sel();
}
PValue GPRArray::get_indirect(unsigned index, PValue indirect, unsigned component)
{
assert(index < m_values.size());
assert(m_component_mask & (1 << (component + m_frac)));
sfn_log << SfnLog::reg << "Create indirect register from " << *this;
PValue v = m_values[index].reg_i(component + m_frac);
assert(v);
sfn_log << SfnLog::reg << " -> " << *v;
if (indirect) {
sfn_log << SfnLog::reg << "[" << *indirect << "]";
switch (indirect->type()) {
case Value::literal: {
const LiteralValue& lv = static_cast<const LiteralValue&>(*indirect);
v = m_values[lv.value()].reg_i(component + m_frac);
break;
}
case Value::gpr: {
v = PValue(new GPRArrayValue(v, indirect, this));
sfn_log << SfnLog::reg << "(" << *v << ")";
break;
}
default:
assert(0 && !"Indirect addressing must be literal value or GPR");
}
}
sfn_log << SfnLog::reg <<" -> " << *v << "\n";
return v;
}
void GPRArray::record_read(LiverangeEvaluator& ev, int chan) const
{
for (auto& v: m_values)
ev.record_read(*v.reg_i(chan), true);
}
void GPRArray::record_write(LiverangeEvaluator& ev, int chan) const
{
for (auto& v: m_values)
ev.record_write(*v.reg_i(chan), true);
}
void GPRArray::collect_registers(ValueMap& output) const
{
for (auto& v: m_values) {
for (int i = 0; i < 4; ++i) {
auto vv = v.reg_i(i);
if (vv)
output.insert(vv);
}
}
}
}
|