• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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    pred->set_cf_type(cf_alu_push_before);
50 }
51 
do_evalue_liveness(LiverangeEvaluator & eval) const52 void IfInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
53 {
54    eval.scope_if();
55 }
56 
is_equal_to(const Instruction & lhs) const57 bool IfInstruction::is_equal_to(const Instruction& lhs) const
58 {
59    assert(lhs.type() == cond_if);
60    const IfInstruction& l = static_cast<const IfInstruction&>(lhs);
61    return *l.m_pred == *m_pred;
62 }
63 
do_print(std::ostream & os) const64 void IfInstruction::do_print(std::ostream& os) const
65 {
66    os << "PRED = " << *m_pred << "\n";
67    os << "IF (PRED)";
68 }
69 
ElseInstruction(IfInstruction * jump_src)70 ElseInstruction::ElseInstruction(IfInstruction *jump_src):
71    IfElseInstruction(cond_else),
72    m_jump_src(jump_src)
73 {
74 }
75 
do_evalue_liveness(LiverangeEvaluator & eval) const76 void ElseInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
77 {
78    eval.scope_else();
79 }
80 
81 
is_equal_to(const Instruction & lhs) const82 bool ElseInstruction::is_equal_to(const Instruction& lhs) const
83 {
84    if (lhs.type() != cond_else)
85       return false;
86    auto& l = static_cast<const ElseInstruction&>(lhs);
87    return (*m_jump_src == *l.m_jump_src);
88 }
89 
do_print(std::ostream & os) const90 void ElseInstruction::do_print(std::ostream& os) const
91 {
92    os << "ELSE";
93 }
94 
IfElseEndInstruction()95 IfElseEndInstruction::IfElseEndInstruction():
96    IfElseInstruction(cond_endif)
97 {
98 }
99 
do_evalue_liveness(LiverangeEvaluator & eval) const100 void IfElseEndInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
101 {
102    eval.scope_endif();
103 }
104 
is_equal_to(const Instruction & lhs) const105 bool IfElseEndInstruction::is_equal_to(const Instruction& lhs) const
106 {
107    if (lhs.type() != cond_endif)
108       return false;
109    return true;
110 }
111 
do_print(std::ostream & os) const112 void IfElseEndInstruction::do_print(std::ostream& os) const
113 {
114    os << "ENDIF";
115 }
116 
LoopBeginInstruction()117 LoopBeginInstruction::LoopBeginInstruction():
118    CFInstruction(loop_begin)
119 {
120 }
121 
do_evalue_liveness(LiverangeEvaluator & eval) const122 void LoopBeginInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
123 {
124    eval.scope_loop_begin();
125 }
126 
is_equal_to(const Instruction & lhs) const127 bool LoopBeginInstruction::is_equal_to(const Instruction& lhs) const
128 {
129    assert(lhs.type() == loop_begin);
130    return true;
131 }
132 
do_print(std::ostream & os) const133 void LoopBeginInstruction::do_print(std::ostream& os) const
134 {
135    os << "BGNLOOP";
136 }
137 
LoopEndInstruction(LoopBeginInstruction * start)138 LoopEndInstruction::LoopEndInstruction(LoopBeginInstruction *start):
139    CFInstruction (loop_end),
140    m_start(start)
141 {
142 }
143 
do_evalue_liveness(LiverangeEvaluator & eval) const144 void LoopEndInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
145 {
146    eval.scope_loop_end();
147 }
148 
is_equal_to(const Instruction & lhs) const149 bool LoopEndInstruction::is_equal_to(const Instruction& lhs) const
150 {
151    assert(lhs.type() == loop_end);
152    const auto& other = static_cast<const LoopEndInstruction&>(lhs);
153    return *m_start == *other.m_start;
154 }
155 
do_print(std::ostream & os) const156 void LoopEndInstruction::do_print(std::ostream& os) const
157 {
158    os << "ENDLOOP";
159 }
160 
LoopBreakInstruction()161 LoopBreakInstruction::LoopBreakInstruction():
162    CFInstruction (loop_break)
163 {
164 }
165 
do_evalue_liveness(LiverangeEvaluator & eval) const166 void LoopBreakInstruction::do_evalue_liveness(LiverangeEvaluator& eval) const
167 {
168    eval.scope_loop_break();
169 }
170 
is_equal_to(UNUSED const Instruction & lhs) const171 bool LoopBreakInstruction::is_equal_to(UNUSED const Instruction& lhs) const
172 {
173    return true;
174 }
175 
do_print(std::ostream & os) const176 void LoopBreakInstruction::do_print(std::ostream& os) const
177 {
178    os << "BREAK";
179 }
180 
LoopContInstruction()181 LoopContInstruction::LoopContInstruction():
182    CFInstruction (loop_continue)
183 {
184 }
185 
is_equal_to(UNUSED const Instruction & lhs) const186 bool LoopContInstruction::is_equal_to(UNUSED const Instruction& lhs) const
187 {
188    return true;
189 }
do_print(std::ostream & os) const190 void LoopContInstruction::do_print(std::ostream& os) const
191 {
192    os << "CONTINUE";
193 }
194 
195 }
196