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_instruction_cf.h"
28 #include "sfn_liverange.h"
29 
30 namespace  r600 {
31 
CFInstruction(instr_type type)32 CFInstruction::CFInstruction(instr_type type):Instruction(type)
33 {
34 
35 }
36 
IfElseInstruction(instr_type type)37 IfElseInstruction::IfElseInstruction(instr_type type):
38    CFInstruction (type)
39 {
40 
41 }
42 
IfInstruction(AluInstruction * pred)43 IfInstruction::IfInstruction(AluInstruction *pred):
44    IfElseInstruction(cond_if),
45    m_pred(pred)
46 {
47    PValue *v = m_pred->psrc(0);
48    add_remappable_src_value(v);
49 }
50 
do_evalue_liveness(LiverangeEvaluator & eval) const51 void IfInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
52 {
53    eval.scope_if();
54 }
55 
is_equal_to(const Instruction & lhs) const56 bool IfInstruction::is_equal_to(const Instruction& lhs) const
57 {
58    assert(lhs.type() == cond_if);
59    const IfInstruction& l = static_cast<const IfInstruction&>(lhs);
60    return *l.m_pred == *m_pred;
61 }
62 
do_print(std::ostream & os) const63 void IfInstruction::do_print(std::ostream& os) const
64 {
65    os << "PRED = " << *m_pred << "\n";
66    os << "IF (PRED)";
67 }
68 
ElseInstruction(IfInstruction * jump_src)69 ElseInstruction::ElseInstruction(IfInstruction *jump_src):
70    IfElseInstruction(cond_else),
71    m_jump_src(jump_src)
72 {
73 }
74 
do_evalue_liveness(LiverangeEvaluator & eval) const75 void ElseInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
76 {
77    eval.scope_else();
78 }
79 
80 
is_equal_to(const Instruction & lhs) const81 bool ElseInstruction::is_equal_to(const Instruction& lhs) const
82 {
83    if (lhs.type() != cond_else)
84       return false;
85    auto& l = static_cast<const ElseInstruction&>(lhs);
86    return (*m_jump_src == *l.m_jump_src);
87 }
88 
do_print(std::ostream & os) const89 void ElseInstruction::do_print(std::ostream& os) const
90 {
91    os << "ELSE";
92 }
93 
IfElseEndInstruction()94 IfElseEndInstruction::IfElseEndInstruction():
95    IfElseInstruction(cond_endif)
96 {
97 }
98 
do_evalue_liveness(LiverangeEvaluator & eval) const99 void IfElseEndInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
100 {
101    eval.scope_endif();
102 }
103 
is_equal_to(const Instruction & lhs) const104 bool IfElseEndInstruction::is_equal_to(const Instruction& lhs) const
105 {
106    if (lhs.type() != cond_endif)
107       return false;
108    return true;
109 }
110 
do_print(std::ostream & os) const111 void IfElseEndInstruction::do_print(std::ostream& os) const
112 {
113    os << "ENDIF";
114 }
115 
LoopBeginInstruction()116 LoopBeginInstruction::LoopBeginInstruction():
117    CFInstruction(loop_begin)
118 {
119 }
120 
do_evalue_liveness(LiverangeEvaluator & eval) const121 void LoopBeginInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
122 {
123    eval.scope_loop_begin();
124 }
125 
is_equal_to(const Instruction & lhs) const126 bool LoopBeginInstruction::is_equal_to(const Instruction& lhs) const
127 {
128    assert(lhs.type() == loop_begin);
129    return true;
130 }
131 
do_print(std::ostream & os) const132 void LoopBeginInstruction::do_print(std::ostream& os) const
133 {
134    os << "BGNLOOP";
135 }
136 
LoopEndInstruction(LoopBeginInstruction * start)137 LoopEndInstruction::LoopEndInstruction(LoopBeginInstruction *start):
138    CFInstruction (loop_end),
139    m_start(start)
140 {
141 }
142 
do_evalue_liveness(LiverangeEvaluator & eval) const143 void LoopEndInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
144 {
145    eval.scope_loop_end();
146 }
147 
is_equal_to(const Instruction & lhs) const148 bool LoopEndInstruction::is_equal_to(const Instruction& lhs) const
149 {
150    assert(lhs.type() == loop_end);
151    const auto& other = static_cast<const LoopEndInstruction&>(lhs);
152    return *m_start == *other.m_start;
153 }
154 
do_print(std::ostream & os) const155 void LoopEndInstruction::do_print(std::ostream& os) const
156 {
157    os << "ENDLOOP";
158 }
159 
LoopBreakInstruction()160 LoopBreakInstruction::LoopBreakInstruction():
161    CFInstruction (loop_break)
162 {
163 }
164 
do_evalue_liveness(LiverangeEvaluator & eval) const165 void LoopBreakInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
166 {
167    eval.scope_loop_break();
168 }
169 
is_equal_to(UNUSED const Instruction & lhs) const170 bool LoopBreakInstruction::is_equal_to(UNUSED const Instruction& lhs) const
171 {
172    return true;
173 }
174 
do_print(std::ostream & os) const175 void LoopBreakInstruction::do_print(std::ostream& os) const
176 {
177    os << "BREAK";
178 }
179 
LoopContInstruction()180 LoopContInstruction::LoopContInstruction():
181    CFInstruction (loop_continue)
182 {
183 }
184 
is_equal_to(UNUSED const Instruction & lhs) const185 bool LoopContInstruction::is_equal_to(UNUSED const Instruction& lhs) const
186 {
187    return true;
188 }
do_print(std::ostream & os) const189 void LoopContInstruction::do_print(std::ostream& os) const
190 {
191    os << "CONTINUE";
192 }
193 
194 }
195