r600/sfn: Add IR instruction to fetch the TESS parameters
[mesa.git] / src / gallium / drivers / r600 / sfn / sfn_instruction_lds.cpp
1 #include "sfn_instruction_lds.h"
2
3 namespace r600 {
4
5 void LDSReadInstruction::do_print(std::ostream& os) const
6 {
7 os << "LDS Read [";
8 for (unsigned i = 0; i < m_address.size(); ++i)
9 os << *m_dest_value[i] << " ";
10 os << "], ";
11 for (unsigned i = 0; i < m_address.size(); ++i)
12 os << *m_address[i] << " ";
13 }
14
15 LDSReadInstruction::LDSReadInstruction(std::vector<PValue>& address, std::vector<PValue>& value):
16 Instruction(lds_read),
17 m_address(address),
18 m_dest_value(value)
19 {
20 assert(address.size() == value.size());
21
22 for (unsigned i = 0; i < address.size(); ++i) {
23 add_remappable_src_value(&m_address[i]);
24 add_remappable_dst_value(&m_dest_value[i]);
25 }
26 }
27
28 void LDSReadInstruction::replace_values(const ValueSet& candiates, PValue new_value)
29 {
30 for (auto& c : candiates) {
31 for (auto& d: m_dest_value) {
32 if (*c == *d)
33 d = new_value;
34 }
35
36 for (auto& a: m_address) {
37 if (*c == *a)
38 a = new_value;
39 }
40 }
41 }
42
43 bool LDSReadInstruction::is_equal_to(const Instruction& lhs) const
44 {
45 auto& other = static_cast<const LDSReadInstruction&>(lhs);
46 return m_address == other.m_address &&
47 m_dest_value == other.m_dest_value;
48 }
49
50 LDSWriteInstruction::LDSWriteInstruction(PValue address, unsigned idx_offset, PValue value0):
51 LDSWriteInstruction::LDSWriteInstruction(address, idx_offset, value0, PValue())
52
53 {
54 }
55
56 LDSWriteInstruction::LDSWriteInstruction(PValue address, unsigned idx_offset, PValue value0, PValue value1):
57 Instruction(lds_write),
58 m_address(address),
59 m_value0(value0),
60 m_value1(value1),
61 m_idx_offset(idx_offset)
62 {
63 add_remappable_src_value(&m_address);
64 add_remappable_src_value(&m_value0);
65 if (m_value1)
66 add_remappable_src_value(&m_value1);
67 }
68
69
70 void LDSWriteInstruction::do_print(std::ostream& os) const
71 {
72 os << "LDS Write" << num_components()
73 << " " << address() << ", " << value0();
74 if (num_components() > 1)
75 os << ", " << value1();
76 }
77
78 void LDSWriteInstruction::replace_values(const ValueSet& candiates, PValue new_value)
79 {
80 for (auto c: candiates) {
81 if (*c == *m_address)
82 m_address = new_value;
83
84 if (*c == *m_value0)
85 m_value0 = new_value;
86
87 if (*c == *m_value1)
88 m_value1 = new_value;
89 }
90 }
91
92 bool LDSWriteInstruction::is_equal_to(const Instruction& lhs) const
93 {
94 auto& other = static_cast<const LDSWriteInstruction&>(lhs);
95
96 if (m_value1) {
97 if (!other.m_value1)
98 return false;
99 if (*m_value1 != *other.m_value1)
100 return false;
101 } else {
102 if (other.m_value1)
103 return false;
104 }
105
106 return (m_value0 != other.m_value0 &&
107 *m_address != *other.m_address);
108 }
109
110 } // namespace r600