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() |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 // Emit bitwise operator invocations | 131 // Emit bitwise operator invocations |
130 builder.BinaryOperation(Token::Value::BIT_OR, reg) | 132 builder.BinaryOperation(Token::Value::BIT_OR, reg) |
131 .BinaryOperation(Token::Value::BIT_XOR, reg) | 133 .BinaryOperation(Token::Value::BIT_XOR, reg) |
132 .BinaryOperation(Token::Value::BIT_AND, reg); | 134 .BinaryOperation(Token::Value::BIT_AND, reg); |
133 | 135 |
134 // Emit shift operator invocations | 136 // Emit shift operator invocations |
135 builder.BinaryOperation(Token::Value::SHL, reg) | 137 builder.BinaryOperation(Token::Value::SHL, reg) |
136 .BinaryOperation(Token::Value::SAR, reg) | 138 .BinaryOperation(Token::Value::SAR, reg) |
137 .BinaryOperation(Token::Value::SHR, reg); | 139 .BinaryOperation(Token::Value::SHR, reg); |
138 | 140 |
| 141 // Emit peephole optimizations of LdaSmi followed by binary operation. |
| 142 builder.LoadLiteral(Smi::FromInt(1)) |
| 143 .BinaryOperation(Token::Value::ADD, reg) |
| 144 .LoadLiteral(Smi::FromInt(2)) |
| 145 .BinaryOperation(Token::Value::SUB, reg) |
| 146 .LoadLiteral(Smi::FromInt(3)) |
| 147 .BinaryOperation(Token::Value::BIT_AND, reg) |
| 148 .LoadLiteral(Smi::FromInt(4)) |
| 149 .BinaryOperation(Token::Value::BIT_OR, reg) |
| 150 .LoadLiteral(Smi::FromInt(5)) |
| 151 .BinaryOperation(Token::Value::SHL, reg) |
| 152 .LoadLiteral(Smi::FromInt(6)) |
| 153 .BinaryOperation(Token::Value::SAR, reg); |
| 154 |
139 // Emit count operatior invocations | 155 // Emit count operatior invocations |
140 builder.CountOperation(Token::Value::ADD).CountOperation(Token::Value::SUB); | 156 builder.CountOperation(Token::Value::ADD).CountOperation(Token::Value::SUB); |
141 | 157 |
142 // Emit unary operator invocations. | 158 // Emit unary operator invocations. |
143 builder | 159 builder |
144 .LogicalNot() // ToBooleanLogicalNot | 160 .LogicalNot() // ToBooleanLogicalNot |
145 .LogicalNot() // non-ToBoolean LogicalNot | 161 .LogicalNot() // non-ToBoolean LogicalNot |
146 .TypeOf(); | 162 .TypeOf(); |
147 | 163 |
148 // Emit delete | 164 // Emit delete |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; | 408 scorecard[Bytecodes::ToByte(Bytecode::kLdrKeyedProperty)] = 1; |
393 scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; | 409 scorecard[Bytecodes::ToByte(Bytecode::kLdrGlobal)] = 1; |
394 scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; | 410 scorecard[Bytecodes::ToByte(Bytecode::kLdrContextSlot)] = 1; |
395 scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; | 411 scorecard[Bytecodes::ToByte(Bytecode::kLdrUndefined)] = 1; |
396 scorecard[Bytecodes::ToByte(Bytecode::kLogicalNot)] = 1; | 412 scorecard[Bytecodes::ToByte(Bytecode::kLogicalNot)] = 1; |
397 scorecard[Bytecodes::ToByte(Bytecode::kJump)] = 1; | 413 scorecard[Bytecodes::ToByte(Bytecode::kJump)] = 1; |
398 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrue)] = 1; | 414 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrue)] = 1; |
399 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalse)] = 1; | 415 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalse)] = 1; |
400 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrueConstant)] = 1; | 416 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfTrueConstant)] = 1; |
401 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalseConstant)] = 1; | 417 scorecard[Bytecodes::ToByte(Bytecode::kJumpIfFalseConstant)] = 1; |
| 418 scorecard[Bytecodes::ToByte(Bytecode::kAddSmi)] = 1; |
| 419 scorecard[Bytecodes::ToByte(Bytecode::kSubSmi)] = 1; |
| 420 scorecard[Bytecodes::ToByte(Bytecode::kBitwiseAndSmi)] = 1; |
| 421 scorecard[Bytecodes::ToByte(Bytecode::kBitwiseOrSmi)] = 1; |
| 422 scorecard[Bytecodes::ToByte(Bytecode::kShiftLeftSmi)] = 1; |
| 423 scorecard[Bytecodes::ToByte(Bytecode::kShiftRightSmi)] = 1; |
402 } | 424 } |
403 | 425 |
404 // Check return occurs at the end and only once in the BytecodeArray. | 426 // Check return occurs at the end and only once in the BytecodeArray. |
405 CHECK_EQ(final_bytecode, Bytecode::kReturn); | 427 CHECK_EQ(final_bytecode, Bytecode::kReturn); |
406 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); | 428 CHECK_EQ(scorecard[Bytecodes::ToByte(final_bytecode)], 1); |
407 | 429 |
408 #define CHECK_BYTECODE_PRESENT(Name, ...) \ | 430 #define CHECK_BYTECODE_PRESENT(Name, ...) \ |
409 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ | 431 /* Check Bytecode is marked in scorecard, unless it's a debug break */ \ |
410 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ | 432 if (!Bytecodes::IsDebugBreak(Bytecode::k##Name)) { \ |
411 CHECK_GE(scorecard[Bytecodes::ToByte(Bytecode::k##Name)], 1); \ | 433 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(); | 839 iterator.Advance(); |
818 } | 840 } |
819 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); | 841 CHECK_EQ(iterator.current_bytecode(), Bytecode::kReturn); |
820 iterator.Advance(); | 842 iterator.Advance(); |
821 CHECK(iterator.done()); | 843 CHECK(iterator.done()); |
822 } | 844 } |
823 | 845 |
824 } // namespace interpreter | 846 } // namespace interpreter |
825 } // namespace internal | 847 } // namespace internal |
826 } // namespace v8 | 848 } // namespace v8 |
OLD | NEW |