| 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/interpreter/constant-array-builder.h" | 10 #include "src/interpreter/constant-array-builder.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 Flush(); | 127 Flush(); |
| 128 CHECK_EQ(write_count(), 2); | 128 CHECK_EQ(write_count(), 2); |
| 129 CHECK_EQ(add, last_written()); | 129 CHECK_EQ(add, last_written()); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Tests covering BytecodePeepholeOptimizer::UpdateCurrentBytecode(). | 132 // Tests covering BytecodePeepholeOptimizer::UpdateCurrentBytecode(). |
| 133 | 133 |
| 134 TEST_F(BytecodePeepholeOptimizerTest, KeepJumpIfToBooleanTrue) { | 134 TEST_F(BytecodePeepholeOptimizerTest, KeepJumpIfToBooleanTrue) { |
| 135 BytecodeNode first(Bytecode::kLdaNull); | 135 BytecodeNode first(Bytecode::kLdaNull); |
| 136 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); | 136 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); |
| 137 BytecodeLabel label; | |
| 138 optimizer()->Write(&first); | 137 optimizer()->Write(&first); |
| 139 CHECK_EQ(write_count(), 0); | 138 CHECK_EQ(write_count(), 0); |
| 140 optimizer()->WriteJump(&second, &label); | 139 optimizer()->Write(&second); |
| 140 CHECK_EQ(write_count(), 1); |
| 141 CHECK_EQ(last_written(), first); |
| 142 Flush(); |
| 141 CHECK_EQ(write_count(), 2); | 143 CHECK_EQ(write_count(), 2); |
| 142 CHECK_EQ(last_written(), second); | 144 CHECK_EQ(last_written(), second); |
| 143 } | 145 } |
| 144 | 146 |
| 145 TEST_F(BytecodePeepholeOptimizerTest, ElideJumpIfToBooleanTrue) { | 147 TEST_F(BytecodePeepholeOptimizerTest, ElideJumpIfToBooleanTrue) { |
| 146 BytecodeNode first(Bytecode::kLdaTrue); | 148 BytecodeNode first(Bytecode::kLdaTrue); |
| 147 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); | 149 BytecodeNode second(Bytecode::kJumpIfToBooleanTrue, 3); |
| 148 BytecodeLabel label; | |
| 149 optimizer()->Write(&first); | 150 optimizer()->Write(&first); |
| 150 CHECK_EQ(write_count(), 0); | 151 CHECK_EQ(write_count(), 0); |
| 151 optimizer()->WriteJump(&second, &label); | 152 optimizer()->Write(&second); |
| 153 CHECK_EQ(write_count(), 1); |
| 154 CHECK_EQ(last_written(), first); |
| 155 Flush(); |
| 152 CHECK_EQ(write_count(), 2); | 156 CHECK_EQ(write_count(), 2); |
| 153 CHECK_EQ(last_written(), second); | 157 CHECK_EQ(last_written().bytecode(), Bytecode::kJumpIfTrue); |
| 158 CHECK_EQ(last_written().operand(0), second.operand(0)); |
| 154 } | 159 } |
| 155 | 160 |
| 156 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) { | 161 TEST_F(BytecodePeepholeOptimizerTest, KeepToBooleanLogicalNot) { |
| 157 BytecodeNode first(Bytecode::kLdaNull); | 162 BytecodeNode first(Bytecode::kLdaNull); |
| 158 BytecodeNode second(Bytecode::kToBooleanLogicalNot); | 163 BytecodeNode second(Bytecode::kToBooleanLogicalNot); |
| 159 optimizer()->Write(&first); | 164 optimizer()->Write(&first); |
| 160 CHECK_EQ(write_count(), 0); | 165 CHECK_EQ(write_count(), 0); |
| 161 optimizer()->Write(&second); | 166 optimizer()->Write(&second); |
| 162 CHECK_EQ(write_count(), 1); | 167 CHECK_EQ(write_count(), 1); |
| 163 CHECK_EQ(last_written(), first); | 168 CHECK_EQ(last_written(), first); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 192 Flush(); | 197 Flush(); |
| 193 CHECK_EQ(write_count(), 2); | 198 CHECK_EQ(write_count(), 2); |
| 194 CHECK_EQ(last_written(), second); | 199 CHECK_EQ(last_written(), second); |
| 195 } | 200 } |
| 196 | 201 |
| 197 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRx) { | 202 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRx) { |
| 198 BytecodeLabel label; | 203 BytecodeLabel label; |
| 199 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); | 204 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); |
| 200 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); | 205 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); |
| 201 optimizer()->Write(&first); | 206 optimizer()->Write(&first); |
| 207 CHECK_EQ(write_count(), 0); |
| 202 optimizer()->Write(&second); | 208 optimizer()->Write(&second); |
| 203 CHECK_EQ(write_count(), 0); | 209 CHECK_EQ(write_count(), 1); |
| 210 CHECK_EQ(last_written(), first); |
| 204 Flush(); | 211 Flush(); |
| 205 CHECK_EQ(write_count(), 1); | 212 CHECK_EQ(write_count(), 1); |
| 206 CHECK_EQ(last_written(), first); | |
| 207 } | 213 } |
| 208 | 214 |
| 209 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRxStatement) { | 215 TEST_F(BytecodePeepholeOptimizerTest, StarRxLdarRxStatement) { |
| 210 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); | 216 BytecodeNode first(Bytecode::kStar, Register(0).ToOperand()); |
| 211 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); | 217 BytecodeNode second(Bytecode::kLdar, Register(0).ToOperand()); |
| 212 second.source_info().MakeStatementPosition(0); | 218 second.source_info().MakeStatementPosition(0); |
| 213 optimizer()->Write(&first); | 219 optimizer()->Write(&first); |
| 214 CHECK_EQ(write_count(), 0); | 220 CHECK_EQ(write_count(), 0); |
| 215 optimizer()->Write(&second); | 221 optimizer()->Write(&second); |
| 216 CHECK_EQ(write_count(), 1); | 222 CHECK_EQ(write_count(), 1); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 CHECK_EQ(last_written(), first); | 255 CHECK_EQ(last_written(), first); |
| 250 Flush(); | 256 Flush(); |
| 251 CHECK_EQ(write_count(), 2); | 257 CHECK_EQ(write_count(), 2); |
| 252 CHECK_EQ(last_written(), second); | 258 CHECK_EQ(last_written(), second); |
| 253 } | 259 } |
| 254 | 260 |
| 255 TEST_F(BytecodePeepholeOptimizerTest, ToNameToName) { | 261 TEST_F(BytecodePeepholeOptimizerTest, ToNameToName) { |
| 256 BytecodeNode first(Bytecode::kToName); | 262 BytecodeNode first(Bytecode::kToName); |
| 257 BytecodeNode second(Bytecode::kToName); | 263 BytecodeNode second(Bytecode::kToName); |
| 258 optimizer()->Write(&first); | 264 optimizer()->Write(&first); |
| 265 CHECK_EQ(write_count(), 0); |
| 259 optimizer()->Write(&second); | 266 optimizer()->Write(&second); |
| 260 CHECK_EQ(write_count(), 0); | 267 CHECK_EQ(write_count(), 1); |
| 268 CHECK_EQ(last_written(), first); |
| 261 Flush(); | 269 Flush(); |
| 262 CHECK_EQ(last_written(), first); | |
| 263 CHECK_EQ(write_count(), 1); | 270 CHECK_EQ(write_count(), 1); |
| 264 } | 271 } |
| 265 | 272 |
| 266 TEST_F(BytecodePeepholeOptimizerTest, TypeOfToName) { | 273 TEST_F(BytecodePeepholeOptimizerTest, TypeOfToName) { |
| 267 BytecodeNode first(Bytecode::kTypeOf); | 274 BytecodeNode first(Bytecode::kTypeOf); |
| 268 BytecodeNode second(Bytecode::kToName); | 275 BytecodeNode second(Bytecode::kToName); |
| 269 optimizer()->Write(&first); | 276 optimizer()->Write(&first); |
| 277 CHECK_EQ(write_count(), 0); |
| 270 optimizer()->Write(&second); | 278 optimizer()->Write(&second); |
| 271 CHECK_EQ(write_count(), 0); | 279 CHECK_EQ(write_count(), 1); |
| 280 CHECK_EQ(last_written(), first); |
| 272 Flush(); | 281 Flush(); |
| 273 CHECK_EQ(write_count(), 1); | 282 CHECK_EQ(write_count(), 1); |
| 274 CHECK_EQ(last_written(), first); | |
| 275 } | 283 } |
| 276 | 284 |
| 277 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantStringToName) { | 285 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantStringToName) { |
| 278 Handle<Object> word = | 286 Handle<Object> word = |
| 279 isolate()->factory()->NewStringFromStaticChars("optimizing"); | 287 isolate()->factory()->NewStringFromStaticChars("optimizing"); |
| 280 size_t index = constant_array()->Insert(word); | 288 size_t index = constant_array()->Insert(word); |
| 281 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); | 289 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); |
| 282 BytecodeNode second(Bytecode::kToName); | 290 BytecodeNode second(Bytecode::kToName); |
| 283 optimizer()->Write(&first); | 291 optimizer()->Write(&first); |
| 292 CHECK_EQ(write_count(), 0); |
| 284 optimizer()->Write(&second); | 293 optimizer()->Write(&second); |
| 285 CHECK_EQ(write_count(), 0); | 294 CHECK_EQ(write_count(), 1); |
| 295 CHECK_EQ(last_written(), first); |
| 286 Flush(); | 296 Flush(); |
| 287 CHECK_EQ(write_count(), 1); | 297 CHECK_EQ(write_count(), 1); |
| 288 CHECK_EQ(last_written(), first); | |
| 289 } | 298 } |
| 290 | 299 |
| 291 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantNumberToName) { | 300 TEST_F(BytecodePeepholeOptimizerTest, LdaConstantNumberToName) { |
| 292 Handle<Object> word = isolate()->factory()->NewNumber(0.380); | 301 Handle<Object> word = isolate()->factory()->NewNumber(0.380); |
| 293 size_t index = constant_array()->Insert(word); | 302 size_t index = constant_array()->Insert(word); |
| 294 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); | 303 BytecodeNode first(Bytecode::kLdaConstant, static_cast<uint32_t>(index)); |
| 295 BytecodeNode second(Bytecode::kToName); | 304 BytecodeNode second(Bytecode::kToName); |
| 296 optimizer()->Write(&first); | 305 optimizer()->Write(&first); |
| 297 CHECK_EQ(write_count(), 0); | 306 CHECK_EQ(write_count(), 0); |
| 298 optimizer()->Write(&second); | 307 optimizer()->Write(&second); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 CHECK_EQ(last_written().operand_count(), 2); | 568 CHECK_EQ(last_written().operand_count(), 2); |
| 560 CHECK_EQ(last_written().operand(0), 0); | 569 CHECK_EQ(last_written().operand(0), 0); |
| 561 CHECK_EQ(last_written().operand(1), reg_operand); | 570 CHECK_EQ(last_written().operand(1), reg_operand); |
| 562 Reset(); | 571 Reset(); |
| 563 } | 572 } |
| 564 } | 573 } |
| 565 | 574 |
| 566 } // namespace interpreter | 575 } // namespace interpreter |
| 567 } // namespace internal | 576 } // namespace internal |
| 568 } // namespace v8 | 577 } // namespace v8 |
| OLD | NEW |