OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/factory.h" | 7 #include "src/factory.h" |
8 #include "src/interpreter/bytecode-label.h" | 8 #include "src/interpreter/bytecode-label.h" |
9 #include "src/interpreter/bytecode-peephole-optimizer.h" | 9 #include "src/interpreter/bytecode-peephole-optimizer.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 optimizer()->Write(&nop); | 121 optimizer()->Write(&nop); |
122 BytecodeSourceInfo source_info_expression(3, false); | 122 BytecodeSourceInfo source_info_expression(3, false); |
123 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1, | 123 BytecodeNode add(Bytecode::kAdd, Register(0).ToOperand(), 1, |
124 source_info_expression); | 124 source_info_expression); |
125 optimizer()->Write(&add); | 125 optimizer()->Write(&add); |
126 Flush(); | 126 Flush(); |
127 CHECK_EQ(write_count(), 2); | 127 CHECK_EQ(write_count(), 2); |
128 CHECK_EQ(add, last_written()); | 128 CHECK_EQ(add, last_written()); |
129 } | 129 } |
130 | 130 |
131 // Tests covering BytecodePeepholeOptimizer::UpdateCurrentBytecode(). | |
132 | |
133 TEST_F(BytecodePeepholeOptimizerTest, KeepJumpIfToBooleanTrue) { | |
134 BytecodeNode first(Bytecode::kLdaNull); | |
135 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); | |
136 BytecodeLabel label; | |
137 optimizer()->Write(&first); | |
138 CHECK_EQ(write_count(), 0); | |
139 optimizer()->WriteJump(&second, &label); | |
140 CHECK_EQ(write_count(), 2); | |
141 CHECK_EQ(last_written(), second); | |
142 } | |
143 | |
144 TEST_F(BytecodePeepholeOptimizerTest, ElideJumpIfToBooleanTrue) { | |
145 BytecodeNode first(Bytecode::kLdaTrue); | |
146 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); | |
147 BytecodeLabel label; | |
148 optimizer()->Write(&first); | |
149 CHECK_EQ(write_count(), 0); | |
150 optimizer()->WriteJump(&second, &label); | |
151 CHECK_EQ(write_count(), 2); | |
152 CHECK_EQ(last_written(), second); | |
153 } | |
154 | |
155 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) { | |
156 BytecodeNode first(Bytecode::kLdaNull); | |
157 BytecodeNode second(Bytecode::kToBooleanLogicalNot); | |
158 optimizer()->Write(&first); | |
159 CHECK_EQ(write_count(), 0); | |
160 optimizer()->Write(&second); | |
161 CHECK_EQ(write_count(), 1); | |
162 CHECK_EQ(last_written(), first); | |
163 Flush(); | |
164 CHECK_EQ(write_count(), 2); | |
165 CHECK_EQ(last_written(), second); | |
166 } | |
167 | |
168 TEST_F(BytecodePeepholeOptimizerTest, ElideToBooleanLogicalNot) { | |
169 BytecodeNode first(Bytecode::kLdaTrue); | |
170 BytecodeNode second(Bytecode::kToBooleanLogicalNot); | |
171 optimizer()->Write(&first); | |
172 CHECK_EQ(write_count(), 0); | |
173 optimizer()->Write(&second); | |
174 CHECK_EQ(write_count(), 1); | |
175 CHECK_EQ(last_written(), first); | |
176 Flush(); | |
177 CHECK_EQ(write_count(), 2); | |
178 CHECK_EQ(last_written().bytecode(), Bytecode::kLogicalNot); | |
179 } | |
180 | |
181 // Tests covering BytecodePeepholeOptimizer::CanElideCurrent(). | 131 // Tests covering BytecodePeepholeOptimizer::CanElideCurrent(). |
182 | 132 |
183 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRy) { | 133 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRy) { |
184 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); | 134 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); |
185 BytecodeNode second(Bytecode::kLdar, Register(1).ToOperand()); | 135 BytecodeNode second(Bytecode::kLdar, Register(1).ToOperand()); |
186 optimizer()->Write(&first); | 136 optimizer()->Write(&first); |
187 CHECK_EQ(write_count(), 0); | 137 CHECK_EQ(write_count(), 0); |
188 optimizer()->Write(&second); | 138 optimizer()->Write(&second); |
189 CHECK_EQ(write_count(), 1); | 139 CHECK_EQ(write_count(), 1); |
190 CHECK_EQ(last_written(), first); | 140 CHECK_EQ(last_written(), first); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 CHECK_EQ(last_written().operand(0), 0u); | 350 CHECK_EQ(last_written().operand(0), 0u); |
401 CHECK_EQ(last_written().operand(1), reg_operand); | 351 CHECK_EQ(last_written().operand(1), reg_operand); |
402 CHECK_EQ(last_written().operand(2), idx_operand); | 352 CHECK_EQ(last_written().operand(2), idx_operand); |
403 Reset(); | 353 Reset(); |
404 } | 354 } |
405 } | 355 } |
406 | 356 |
407 } // namespace interpreter | 357 } // namespace interpreter |
408 } // namespace internal | 358 } // namespace internal |
409 } // namespace v8 | 359 } // namespace v8 |
OLD | NEW |