Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/interpreter/bytecode-array-builder.h" | 7 #include "src/interpreter/bytecode-array-builder.h" |
| 8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
| 9 #include "src/interpreter/bytecode-label.h" | 9 #include "src/interpreter/bytecode-label.h" |
| 10 #include "src/interpreter/bytecode-register-allocator.h" | 10 #include "src/interpreter/bytecode-register-allocator.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 // Emit argument creation operations. | 36 // Emit argument creation operations. |
| 37 builder.CreateArguments(CreateArgumentsType::kMappedArguments) | 37 builder.CreateArguments(CreateArgumentsType::kMappedArguments) |
| 38 .CreateArguments(CreateArgumentsType::kUnmappedArguments) | 38 .CreateArguments(CreateArgumentsType::kUnmappedArguments) |
| 39 .CreateArguments(CreateArgumentsType::kRestParameter); | 39 .CreateArguments(CreateArgumentsType::kRestParameter); |
| 40 | 40 |
| 41 // Emit constant loads. | 41 // Emit constant loads. |
| 42 builder.LoadLiteral(Smi::FromInt(0)) | 42 builder.LoadLiteral(Smi::FromInt(0)) |
| 43 .StoreAccumulatorInRegister(reg) | 43 .StoreAccumulatorInRegister(reg) |
| 44 .LoadLiteral(Smi::FromInt(8)) | 44 .LoadLiteral(Smi::FromInt(8)) |
| 45 .CompareOperation(Token::Value::NE, reg) // Prevent peephole optimization | |
| 46 // LdaSmi, Star -> LdrSmi. | |
| 45 .StoreAccumulatorInRegister(reg) | 47 .StoreAccumulatorInRegister(reg) |
| 46 .LoadLiteral(Smi::FromInt(10000000)) | 48 .LoadLiteral(Smi::FromInt(10000000)) |
| 47 .StoreAccumulatorInRegister(reg) | 49 .StoreAccumulatorInRegister(reg) |
| 48 .LoadLiteral(factory->NewStringFromStaticChars("A constant")) | 50 .LoadLiteral(factory->NewStringFromStaticChars("A constant")) |
| 49 .StoreAccumulatorInRegister(reg) | 51 .StoreAccumulatorInRegister(reg) |
| 50 .LoadUndefined() | 52 .LoadUndefined() |
| 51 .Debugger() // Prevent peephole optimization LdaNull, Star -> LdrNull. | 53 .Debugger() // Prevent peephole optimization LdaNull, Star -> LdrNull. |
| 52 .LoadNull() | 54 .LoadNull() |
| 53 .StoreAccumulatorInRegister(reg) | 55 .StoreAccumulatorInRegister(reg) |
| 54 .LoadTheHole() | 56 .LoadTheHole() |
| 55 .StoreAccumulatorInRegister(reg) | 57 .StoreAccumulatorInRegister(reg) |
| 56 .LoadTrue() | 58 .LoadTrue() |
| 57 .StoreAccumulatorInRegister(reg) | 59 .StoreAccumulatorInRegister(reg) |
| 58 .LoadFalse() | 60 .LoadFalse() |
| 59 .StoreAccumulatorInRegister(wide); | 61 .StoreAccumulatorInRegister(wide); |
| 60 | 62 |
| 61 // Emit Ldar and Star taking care to foil the register optimizer. | 63 // Emit Ldar and Star taking care to foil the register optimizer. |
| 62 builder.StackCheck(0) | 64 builder.StackCheck(0) |
| 63 .LoadAccumulatorWithRegister(other) | 65 .LoadAccumulatorWithRegister(other) |
| 64 .BinaryOperation(Token::ADD, reg) | 66 .BinaryOperation(Token::ADD, reg) |
| 65 .StoreAccumulatorInRegister(reg) | 67 .StoreAccumulatorInRegister(reg) |
| 66 .LoadNull(); | 68 .LoadNull(); |
| 67 | 69 |
| 70 // Force emission of AddSmi. | |
|
rmcilroy
2016/07/04 12:35:32
nit - maybe just group these all together since th
oth
2016/07/04 14:56:24
Done.
| |
| 71 builder.LoadLiteral(Smi::FromInt(1)).BinaryOperation(Token::Value::ADD, reg); | |
| 72 | |
| 73 // Force emission of SubSmi. | |
| 74 builder.LoadLiteral(Smi::FromInt(1)).BinaryOperation(Token::Value::SUB, reg); | |
| 75 | |
| 68 // Emit register-register transfer. | 76 // Emit register-register transfer. |
| 69 builder.MoveRegister(reg, other); | 77 builder.MoveRegister(reg, other); |
| 70 builder.MoveRegister(reg, wide); | 78 builder.MoveRegister(reg, wide); |
| 71 | 79 |
| 72 // Emit global load / store operations. | 80 // Emit global load / store operations. |
| 73 Handle<String> name = factory->NewStringFromStaticChars("var_name"); | 81 Handle<String> name = factory->NewStringFromStaticChars("var_name"); |
| 74 builder.LoadGlobal(1, TypeofMode::NOT_INSIDE_TYPEOF) | 82 builder.LoadGlobal(1, TypeofMode::NOT_INSIDE_TYPEOF) |
| 75 .LoadGlobal(1, TypeofMode::INSIDE_TYPEOF) | 83 .LoadGlobal(1, TypeofMode::INSIDE_TYPEOF) |
| 76 .StoreGlobal(name, 1, LanguageMode::SLOPPY) | 84 .StoreGlobal(name, 1, LanguageMode::SLOPPY) |
| 77 .StoreGlobal(name, 1, LanguageMode::STRICT); | 85 .StoreGlobal(name, 1, LanguageMode::STRICT); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 .BinaryOperation(Token::Value::SUB, reg) | 132 .BinaryOperation(Token::Value::SUB, reg) |
| 125 .BinaryOperation(Token::Value::MUL, reg) | 133 .BinaryOperation(Token::Value::MUL, reg) |
| 126 .BinaryOperation(Token::Value::DIV, reg) | 134 .BinaryOperation(Token::Value::DIV, reg) |
| 127 .BinaryOperation(Token::Value::MOD, reg); | 135 .BinaryOperation(Token::Value::MOD, reg); |
| 128 | 136 |
| 129 // Emit bitwise operator invocations | 137 // Emit bitwise operator invocations |
| 130 builder.BinaryOperation(Token::Value::BIT_OR, reg) | 138 builder.BinaryOperation(Token::Value::BIT_OR, reg) |
| 131 .BinaryOperation(Token::Value::BIT_XOR, reg) | 139 .BinaryOperation(Token::Value::BIT_XOR, reg) |
| 132 .BinaryOperation(Token::Value::BIT_AND, reg); | 140 .BinaryOperation(Token::Value::BIT_AND, reg); |
| 133 | 141 |
| 142 // Emit bitwise AND with smi operand. | |
| 143 builder.LoadLiteral(Smi::FromInt(8)) | |
| 144 .BinaryOperation(Token::Value::BIT_AND, reg); | |
| 145 | |
| 146 // Emit bitwise OR with smi operand. | |
| 147 builder.LoadLiteral(Smi::FromInt(8)) | |
| 148 .BinaryOperation(Token::Value::BIT_OR, reg); | |
| 149 | |
| 134 // Emit shift operator invocations | 150 // Emit shift operator invocations |
| 135 builder.BinaryOperation(Token::Value::SHL, reg) | 151 builder.BinaryOperation(Token::Value::SHL, reg) |
| 136 .BinaryOperation(Token::Value::SAR, reg) | 152 .BinaryOperation(Token::Value::SAR, reg) |
| 137 .BinaryOperation(Token::Value::SHR, reg); | 153 .BinaryOperation(Token::Value::SHR, reg); |
| 138 | 154 |
| 155 // Emit shift left with smi operand. | |
| 156 builder.LoadLiteral(Smi::FromInt(8)).BinaryOperation(Token::Value::SHL, reg); | |
| 157 | |
| 158 // Emit shift right with smi operand. | |
| 159 builder.LoadLiteral(Smi::FromInt(8)).BinaryOperation(Token::Value::SAR, reg); | |
| 160 | |
| 139 // Emit count operatior invocations | 161 // Emit count operatior invocations |
| 140 builder.CountOperation(Token::Value::ADD).CountOperation(Token::Value::SUB); | 162 builder.CountOperation(Token::Value::ADD).CountOperation(Token::Value::SUB); |
| 141 | 163 |
| 142 // Emit unary operator invocations. | 164 // Emit unary operator invocations. |
| 143 builder | 165 builder |
| 144 .LogicalNot() // ToBooleanLogicalNot | 166 .LogicalNot() // ToBooleanLogicalNot |
| 145 .LogicalNot() // non-ToBoolean LogicalNot | 167 .LogicalNot() // non-ToBoolean LogicalNot |
| 146 .TypeOf(); | 168 .TypeOf(); |
| 147 | 169 |
| 148 // Emit delete | 170 // Emit delete |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 for (size_t i = 0; i < arraysize(end); i++) { | 375 for (size_t i = 0; i < arraysize(end); i++) { |
| 354 builder.Bind(&end[i]); | 376 builder.Bind(&end[i]); |
| 355 } | 377 } |
| 356 builder.Return(); | 378 builder.Return(); |
| 357 | 379 |
| 358 // Generate BytecodeArray. | 380 // Generate BytecodeArray. |
| 359 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); | 381 Handle<BytecodeArray> the_array = builder.ToBytecodeArray(); |
| 360 CHECK_EQ(the_array->frame_size(), | 382 CHECK_EQ(the_array->frame_size(), |
| 361 builder.fixed_and_temporary_register_count() * kPointerSize); | 383 builder.fixed_and_temporary_register_count() * kPointerSize); |
| 362 | 384 |
| 385 the_array->Print(); | |
|
rmcilroy
2016/07/04 12:35:32
leftover debugging?
oth
2016/07/04 14:56:24
Yep, done. :-)
| |
| 386 | |
| 363 // Build scorecard of bytecodes encountered in the BytecodeArray. | 387 // Build scorecard of bytecodes encountered in the BytecodeArray. |
| 364 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); | 388 std::vector<int> scorecard(Bytecodes::ToByte(Bytecode::kLast) + 1); |
| 365 | 389 |
| 366 Bytecode final_bytecode = Bytecode::kLdaZero; | 390 Bytecode final_bytecode = Bytecode::kLdaZero; |
| 367 int i = 0; | 391 int i = 0; |
| 368 while (i < the_array->length()) { | 392 while (i < the_array->length()) { |
| 369 uint8_t code = the_array->get(i); | 393 uint8_t code = the_array->get(i); |
| 370 scorecard[code] += 1; | 394 scorecard[code] += 1; |
| 371 final_bytecode = Bytecodes::FromByte(code); | 395 final_bytecode = Bytecodes::FromByte(code); |
| 372 OperandScale operand_scale = OperandScale::kSingle; | 396 OperandScale operand_scale = OperandScale::kSingle; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 392 scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; | 416 scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; |
| 393 scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; | 417 scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; |
| 394 scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; | 418 scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; |
| 395 scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; | 419 scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; |
| 396 scorecard[Bytecodes::ToByte(Bytecode::kLogicalNot)] = 1; | 420 scorecard[Bytecodes::ToByte(Bytecode::kLogicalNot)] = 1; |
| 397 scorecard[Bytecodes::ToByte(Bytecode::kJump)] = 1; | 421 scorecard[Bytecodes::ToByte(Bytecode::kJump)] = 1; |
| 398 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrue)] = 1; | 422 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrue)] = 1; |
| 399 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalse)] = 1; | 423 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalse)] = 1; |
| 400 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrueConstant)] = 1; | 424 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrueConstant)] = 1; |
| 401 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalseConstant)] = 1; | 425 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalseConstant)] = 1; |
| 426 scorecard[Bytecodes::ToByte(Bytecode::kAddSmi)] = 1; | |
| 427 scorecard[Bytecodes::ToByte(Bytecode::kSubSmi)] = 1; | |
| 428 scorecard[Bytecodes::ToByte(Bytecode::kBitwiseAndSmi)] = 1; | |
| 429 scorecard[Bytecodes::ToByte(Bytecode::kBitwiseOrSmi)] = 1; | |
| 430 scorecard[Bytecodes::ToByte(Bytecode::kShiftLeftSmi)] = 1; | |
| 431 scorecard[Bytecodes::ToByte(Bytecode::kShiftRightSmi)] = 1; | |
| 402 } | 432 } |
| 403 | 433 |
| 404 // Check return occurs at the end and only once in the BytecodeArray. | 434 // Check return occurs at the end and only once in the BytecodeArray. |
| 405 CHECK_EQ(final_bytecode, Bytecode::kReturn); | 435 CHECK_EQ(final_bytecode, Bytecode::kReturn); |
| 406 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); | 436 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); |
| 407 | 437 |
| 408 #define CHECK_BYTECODE_PRESENT(Name, ...) \ | 438 #define CHECK_BYTECODE_PRESENT(Name, ...) \ |
| 409 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ | 439 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ |
| 410 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ | 440 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ |
| 411 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ | 441 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 817 iterator.Advance(); | 847 iterator.Advance(); |
| 818 } | 848 } |
| 819 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 849 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
| 820 iterator.Advance(); | 850 iterator.Advance(); |
| 821 CHECK(iterator.done()); | 851 CHECK(iterator.done()); |
| 822 } | 852 } |
| 823 | 853 |
| 824 } // namespace interpreter | 854 } // namespace interpreter |
| 825 } // namespace internal | 855 } // namespace internal |
| 826 } // namespace v8 | 856 } // namespace v8 |
| OLD | NEW |