3 * Copyright (c) 2019 Collabora LTD
5 * Author: Gert Wollny <gert.wollny@collabora.com>
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:
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
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.
27 #include "sfn_instruction_cf.h"
28 #include "sfn_liverange.h"
32 CFInstruction::CFInstruction(instr_type type
):Instruction(type
)
37 IfElseInstruction::IfElseInstruction(instr_type type
):
43 IfInstruction::IfInstruction(AluInstruction
*pred
):
44 IfElseInstruction(cond_if
),
47 PValue
*v
= m_pred
->psrc(0);
48 add_remappable_src_value(v
);
51 void IfInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
56 bool IfInstruction::is_equal_to(const Instruction
& lhs
) const
58 assert(lhs
.type() == cond_if
);
59 const IfInstruction
& l
= static_cast<const IfInstruction
&>(lhs
);
60 return *l
.m_pred
== *m_pred
;
63 void IfInstruction::do_print(std::ostream
& os
) const
65 os
<< "PRED = " << *m_pred
<< "\n";
69 ElseInstruction::ElseInstruction(IfInstruction
*jump_src
):
70 IfElseInstruction(cond_else
),
75 void ElseInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
81 bool ElseInstruction::is_equal_to(const Instruction
& lhs
) const
83 if (lhs
.type() != cond_else
)
85 auto& l
= static_cast<const ElseInstruction
&>(lhs
);
86 return (*m_jump_src
== *l
.m_jump_src
);
89 void ElseInstruction::do_print(std::ostream
& os
) const
94 IfElseEndInstruction::IfElseEndInstruction():
95 IfElseInstruction(cond_endif
)
99 void IfElseEndInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
104 bool IfElseEndInstruction::is_equal_to(const Instruction
& lhs
) const
106 if (lhs
.type() != cond_endif
)
111 void IfElseEndInstruction::do_print(std::ostream
& os
) const
116 LoopBeginInstruction::LoopBeginInstruction():
117 CFInstruction(loop_begin
)
121 void LoopBeginInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
123 eval
.scope_loop_begin();
126 bool LoopBeginInstruction::is_equal_to(const Instruction
& lhs
) const
128 assert(lhs
.type() == loop_begin
);
132 void LoopBeginInstruction::do_print(std::ostream
& os
) const
137 LoopEndInstruction::LoopEndInstruction(LoopBeginInstruction
*start
):
138 CFInstruction (loop_end
),
143 void LoopEndInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
145 eval
.scope_loop_end();
148 bool LoopEndInstruction::is_equal_to(const Instruction
& lhs
) const
150 assert(lhs
.type() == loop_end
);
151 const auto& other
= static_cast<const LoopEndInstruction
&>(lhs
);
152 return *m_start
== *other
.m_start
;
155 void LoopEndInstruction::do_print(std::ostream
& os
) const
160 LoopBreakInstruction::LoopBreakInstruction():
161 CFInstruction (loop_break
)
165 void LoopBreakInstruction::do_evalue_liveness(LiverangeEvaluator
& eval
) const
167 eval
.scope_loop_break();
170 bool LoopBreakInstruction::is_equal_to(UNUSED
const Instruction
& lhs
) const
175 void LoopBreakInstruction::do_print(std::ostream
& os
) const
180 LoopContInstruction::LoopContInstruction():
181 CFInstruction (loop_continue
)
185 bool LoopContInstruction::is_equal_to(UNUSED
const Instruction
& lhs
) const
189 void LoopContInstruction::do_print(std::ostream
& os
) const