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