1 #include "sfn_instruction_lds.h"
2 
3 namespace r600 {
4 
do_print(std::ostream & os) const5 void LDSReadInstruction::do_print(std::ostream& os) const
6 {
7    os << "LDS Read  [";
8    for (auto& v : m_dest_value)
9       os << *v << " ";
10    os << "], ";
11    for (auto& a : m_address)
12       os << *a << " ";
13 }
14 
LDSReadInstruction(std::vector<PValue> & address,std::vector<PValue> & value)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 
replace_values(const ValueSet & candidates,PValue new_value)28 void LDSReadInstruction::replace_values(const ValueSet& candidates, PValue new_value)
29 {
30    for (auto& c : candidates) {
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 
is_equal_to(const Instruction & lhs) const43 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 
LDSAtomicInstruction(PValue & dest,PValue & src0,PValue src1,PValue & address,unsigned op)50 LDSAtomicInstruction::LDSAtomicInstruction(PValue& dest, PValue& src0, PValue src1, PValue& address, unsigned op):
51    Instruction(lds_atomic),
52    m_address(address),
53    m_dest_value(dest),
54    m_src0_value(src0),
55    m_src1_value(src1),
56    m_opcode(op)
57 {
58    add_remappable_src_value(&m_src0_value);
59    add_remappable_src_value(&m_src1_value);
60    add_remappable_src_value(&m_address);
61    add_remappable_dst_value(&m_dest_value);
62 }
63 
LDSAtomicInstruction(PValue & dest,PValue & src0,PValue & address,unsigned op)64 LDSAtomicInstruction::LDSAtomicInstruction(PValue& dest, PValue& src0, PValue& address, unsigned op):
65    LDSAtomicInstruction(dest, src0, PValue(), address, op)
66 {
67 
68 }
69 
70 
do_print(std::ostream & os) const71 void LDSAtomicInstruction::do_print(std::ostream& os) const
72 {
73    os << "LDS " << m_opcode << " " << *m_dest_value << " ";
74    os << "[" << *m_address << "] " << *m_src0_value;
75    if (m_src1_value)
76       os << ", " << *m_src1_value;
77 }
78 
is_equal_to(const Instruction & lhs) const79 bool LDSAtomicInstruction::is_equal_to(const Instruction& lhs) const
80 {
81    auto& other = static_cast<const LDSAtomicInstruction&>(lhs);
82 
83    return m_opcode == other.m_opcode &&
84          *m_dest_value == *other.m_dest_value &&
85          *m_src0_value == *other.m_src0_value &&
86          *m_address == *other.m_address &&
87          ((m_src1_value && other.m_src1_value && (*m_src1_value == *other.m_src1_value)) ||
88           (!m_src1_value && !other.m_src1_value));
89 }
90 
LDSWriteInstruction(PValue address,unsigned idx_offset,PValue value0)91 LDSWriteInstruction::LDSWriteInstruction(PValue address, unsigned idx_offset, PValue value0):
92    LDSWriteInstruction::LDSWriteInstruction(address, idx_offset, value0, PValue())
93 
94 {
95 }
96 
LDSWriteInstruction(PValue address,unsigned idx_offset,PValue value0,PValue value1)97 LDSWriteInstruction::LDSWriteInstruction(PValue address, unsigned idx_offset, PValue value0, PValue value1):
98    Instruction(lds_write),
99    m_address(address),
100    m_value0(value0),
101    m_value1(value1),
102    m_idx_offset(idx_offset)
103 {
104    add_remappable_src_value(&m_address);
105    add_remappable_src_value(&m_value0);
106    if (m_value1)
107       add_remappable_src_value(&m_value1);
108 }
109 
110 
do_print(std::ostream & os) const111 void LDSWriteInstruction::do_print(std::ostream& os) const
112 {
113    os << "LDS Write" << num_components()
114       << " " << address() << ", " << value0();
115    if (num_components() > 1)
116       os << ", " << value1();
117 }
118 
replace_values(const ValueSet & candidates,PValue new_value)119 void LDSWriteInstruction::replace_values(const ValueSet& candidates, PValue new_value)
120 {
121    for (auto c: candidates) {
122       if (*c == *m_address)
123          m_address = new_value;
124 
125       if (*c == *m_value0)
126          m_value0 = new_value;
127 
128       if (*c == *m_value1)
129          m_value1 = new_value;
130    }
131 }
132 
is_equal_to(const Instruction & lhs) const133 bool LDSWriteInstruction::is_equal_to(const Instruction& lhs) const
134 {
135    auto& other = static_cast<const LDSWriteInstruction&>(lhs);
136 
137    if (m_value1) {
138       if (!other.m_value1)
139          return false;
140       if (*m_value1 != *other.m_value1)
141          return false;
142    } else {
143       if (other.m_value1)
144          return false;
145    }
146 
147    return (m_value0 != other.m_value0 &&
148            *m_address != *other.m_address);
149 }
150 
151 } // namespace r600
152