| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 6 #define V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| 7 | 7 |
| 8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
| 9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
| 10 #include "src/interpreter/constant-array-builder.h" | 10 #include "src/interpreter/constant-array-builder.h" |
| 11 #include "src/interpreter/handler-table-builder.h" | 11 #include "src/interpreter/handler-table-builder.h" |
| 12 #include "src/interpreter/register-translator.h" |
| 12 #include "src/zone-containers.h" | 13 #include "src/zone-containers.h" |
| 13 | 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 | 17 |
| 17 class Isolate; | 18 class Isolate; |
| 18 | 19 |
| 19 namespace interpreter { | 20 namespace interpreter { |
| 20 | 21 |
| 21 class BytecodeLabel; | 22 class BytecodeLabel; |
| 22 class Register; | 23 class Register; |
| 23 | 24 |
| 24 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan | 25 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan |
| 25 // when rest parameters implementation has settled down. | 26 // when rest parameters implementation has settled down. |
| 26 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; | 27 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; |
| 27 | 28 |
| 28 class BytecodeArrayBuilder final { | 29 class BytecodeArrayBuilder final : private RegisterMover { |
| 29 public: | 30 public: |
| 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 31 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
| 31 ~BytecodeArrayBuilder(); | 32 ~BytecodeArrayBuilder(); |
| 32 | 33 |
| 33 Handle<BytecodeArray> ToBytecodeArray(); | 34 Handle<BytecodeArray> ToBytecodeArray(); |
| 34 | 35 |
| 35 // Set the number of parameters expected by function. | 36 // Set the number of parameters expected by function. |
| 36 void set_parameter_count(int number_of_params); | 37 void set_parameter_count(int number_of_params); |
| 37 int parameter_count() const { | 38 int parameter_count() const { |
| 38 DCHECK_GE(parameter_count_, 0); | 39 DCHECK_GE(parameter_count_, 0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 DCHECK_GE(context_register_count_, 0); | 53 DCHECK_GE(context_register_count_, 0); |
| 53 return context_register_count_; | 54 return context_register_count_; |
| 54 } | 55 } |
| 55 | 56 |
| 56 Register first_context_register() const; | 57 Register first_context_register() const; |
| 57 Register last_context_register() const; | 58 Register last_context_register() const; |
| 58 | 59 |
| 59 // Returns the number of fixed (non-temporary) registers. | 60 // Returns the number of fixed (non-temporary) registers. |
| 60 int fixed_register_count() const { return context_count() + locals_count(); } | 61 int fixed_register_count() const { return context_count() + locals_count(); } |
| 61 | 62 |
| 63 // Returns the number of fixed and temporary registers. |
| 64 int fixed_and_temporary_register_count() const { |
| 65 return fixed_register_count() + temporary_register_count_; |
| 66 } |
| 67 |
| 68 // Returns the number of registers used for translating wide |
| 69 // register operands into byte sized register operands. |
| 70 int translation_register_count() const { |
| 71 return RegisterTranslator::RegisterCountAdjustment( |
| 72 fixed_and_temporary_register_count(), parameter_count()); |
| 73 } |
| 74 |
| 62 Register Parameter(int parameter_index) const; | 75 Register Parameter(int parameter_index) const; |
| 63 | 76 |
| 64 // Return true if the register |reg| represents a parameter or a | 77 // Return true if the register |reg| represents a parameter or a |
| 65 // local. | 78 // local. |
| 66 bool RegisterIsParameterOrLocal(Register reg) const; | 79 bool RegisterIsParameterOrLocal(Register reg) const; |
| 67 | 80 |
| 68 // Return true if the register |reg| represents a temporary register. | 81 // Return true if the register |reg| represents a temporary register. |
| 69 bool RegisterIsTemporary(Register reg) const; | 82 bool RegisterIsTemporary(Register reg) const; |
| 70 | 83 |
| 71 // Constant loads to accumulator. | 84 // Constant loads to accumulator. |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 270 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
| 258 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 271 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
| 259 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 272 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
| 260 | 273 |
| 261 static bool FitsInIdx8Operand(int value); | 274 static bool FitsInIdx8Operand(int value); |
| 262 static bool FitsInIdx8Operand(size_t value); | 275 static bool FitsInIdx8Operand(size_t value); |
| 263 static bool FitsInImm8Operand(int value); | 276 static bool FitsInImm8Operand(int value); |
| 264 static bool FitsInIdx16Operand(int value); | 277 static bool FitsInIdx16Operand(int value); |
| 265 static bool FitsInIdx16Operand(size_t value); | 278 static bool FitsInIdx16Operand(size_t value); |
| 266 static bool FitsInReg8Operand(Register value); | 279 static bool FitsInReg8Operand(Register value); |
| 280 static bool FitsInReg8OperandUntranslated(Register value); |
| 267 static bool FitsInReg16Operand(Register value); | 281 static bool FitsInReg16Operand(Register value); |
| 282 static bool FitsInReg16OperandUntranslated(Register value); |
| 283 |
| 284 void MoveRegisterUntranslated(Register from, Register to) override; |
| 268 | 285 |
| 269 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 286 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
| 270 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); | 287 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
| 271 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | 288 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
| 272 | 289 |
| 273 Register MapRegister(Register reg); | |
| 274 Register MapRegisters(Register reg, Register args_base, int args_length = 1); | |
| 275 | |
| 276 template <size_t N> | 290 template <size_t N> |
| 277 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); | 291 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); |
| 278 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 292 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 279 uint32_t operand2, uint32_t operand3); | 293 uint32_t operand2, uint32_t operand3); |
| 280 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 294 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 281 uint32_t operand2); | 295 uint32_t operand2); |
| 282 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 296 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
| 283 void Output(Bytecode bytecode, uint32_t operand0); | 297 void Output(Bytecode bytecode, uint32_t operand0); |
| 284 void Output(Bytecode bytecode); | 298 void Output(Bytecode bytecode); |
| 285 | 299 |
| 286 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 300 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
| 287 BytecodeLabel* label); | 301 BytecodeLabel* label); |
| 288 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 302 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
| 289 const ZoneVector<uint8_t>::iterator& jump_location); | 303 const ZoneVector<uint8_t>::iterator& jump_location); |
| 290 void PatchIndirectJumpWith8BitOperand( | 304 void PatchIndirectJumpWith8BitOperand( |
| 291 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 305 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 292 void PatchIndirectJumpWith16BitOperand( | 306 void PatchIndirectJumpWith16BitOperand( |
| 293 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 307 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 294 | 308 |
| 295 void LeaveBasicBlock(); | 309 void LeaveBasicBlock(); |
| 296 void EnsureReturn(); | 310 void EnsureReturn(); |
| 297 | 311 |
| 298 bool OperandIsValid(Bytecode bytecode, int operand_index, | 312 bool OperandIsValid(Bytecode bytecode, int operand_index, |
| 299 uint32_t operand_value) const; | 313 uint32_t operand_value) const; |
| 300 bool LastBytecodeInSameBlock() const; | |
| 301 bool RegisterIsValid(Register reg, OperandType reg_type) const; | 314 bool RegisterIsValid(Register reg, OperandType reg_type) const; |
| 302 | 315 |
| 316 bool LastBytecodeInSameBlock() const; |
| 303 bool NeedToBooleanCast(); | 317 bool NeedToBooleanCast(); |
| 304 bool IsRegisterInAccumulator(Register reg); | 318 bool IsRegisterInAccumulator(Register reg); |
| 305 | 319 |
| 306 // Temporary register management. | 320 // Temporary register management. |
| 321 void ForgeTemporaryRegister(); |
| 307 int BorrowTemporaryRegister(); | 322 int BorrowTemporaryRegister(); |
| 308 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 323 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
| 309 void ReturnTemporaryRegister(int reg_index); | 324 void ReturnTemporaryRegister(int reg_index); |
| 310 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 325 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
| 311 void BorrowConsecutiveTemporaryRegister(int reg_index); | 326 void BorrowConsecutiveTemporaryRegister(int reg_index); |
| 312 bool TemporaryRegisterIsLive(Register reg) const; | 327 bool TemporaryRegisterIsLive(Register reg) const; |
| 313 | 328 |
| 314 Register first_temporary_register() const; | 329 Register first_temporary_register() const; |
| 315 Register last_temporary_register() const; | 330 Register last_temporary_register() const; |
| 316 | 331 |
| 317 // Gets a constant pool entry for the |object|. | 332 // Gets a constant pool entry for the |object|. |
| 318 size_t GetConstantPoolEntry(Handle<Object> object); | 333 size_t GetConstantPoolEntry(Handle<Object> object); |
| 319 | 334 |
| 320 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 335 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
| 321 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 336 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
| 322 Isolate* isolate() const { return isolate_; } | 337 Isolate* isolate() const { return isolate_; } |
| 323 ConstantArrayBuilder* constant_array_builder() { | 338 ConstantArrayBuilder* constant_array_builder() { |
| 324 return &constant_array_builder_; | 339 return &constant_array_builder_; |
| 325 } | 340 } |
| 326 const ConstantArrayBuilder* constant_array_builder() const { | 341 const ConstantArrayBuilder* constant_array_builder() const { |
| 327 return &constant_array_builder_; | 342 return &constant_array_builder_; |
| 328 } | 343 } |
| 329 HandlerTableBuilder* handler_table_builder() { | 344 HandlerTableBuilder* handler_table_builder() { |
| 330 return &handler_table_builder_; | 345 return &handler_table_builder_; |
| 331 } | 346 } |
| 347 RegisterTranslator* register_translator() { return ®ister_translator_; } |
| 332 | 348 |
| 333 Isolate* isolate_; | 349 Isolate* isolate_; |
| 334 Zone* zone_; | 350 Zone* zone_; |
| 335 ZoneVector<uint8_t> bytecodes_; | 351 ZoneVector<uint8_t> bytecodes_; |
| 336 bool bytecode_generated_; | 352 bool bytecode_generated_; |
| 337 ConstantArrayBuilder constant_array_builder_; | 353 ConstantArrayBuilder constant_array_builder_; |
| 338 HandlerTableBuilder handler_table_builder_; | 354 HandlerTableBuilder handler_table_builder_; |
| 339 size_t last_block_end_; | 355 size_t last_block_end_; |
| 340 size_t last_bytecode_start_; | 356 size_t last_bytecode_start_; |
| 341 bool exit_seen_in_block_; | 357 bool exit_seen_in_block_; |
| 342 int unbound_jumps_; | 358 int unbound_jumps_; |
| 343 | |
| 344 int parameter_count_; | 359 int parameter_count_; |
| 345 int local_register_count_; | 360 int local_register_count_; |
| 346 int context_register_count_; | 361 int context_register_count_; |
| 347 int temporary_register_count_; | 362 int temporary_register_count_; |
| 348 ZoneSet<int> free_temporaries_; | 363 ZoneSet<int> free_temporaries_; |
| 364 RegisterTranslator register_translator_; |
| 349 | 365 |
| 350 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 366 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 351 }; | 367 }; |
| 352 | 368 |
| 353 | 369 |
| 354 // A label representing a branch target in a bytecode array. When a | 370 // A label representing a branch target in a bytecode array. When a |
| 355 // label is bound, it represents a known position in the bytecode | 371 // label is bound, it represents a known position in the bytecode |
| 356 // array. For labels that are forward references there can be at most | 372 // array. For labels that are forward references there can be at most |
| 357 // one reference whilst it is unbound. | 373 // one reference whilst it is unbound. |
| 358 class BytecodeLabel final { | 374 class BytecodeLabel final { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 389 size_t offset_; | 405 size_t offset_; |
| 390 | 406 |
| 391 friend class BytecodeArrayBuilder; | 407 friend class BytecodeArrayBuilder; |
| 392 }; | 408 }; |
| 393 | 409 |
| 394 } // namespace interpreter | 410 } // namespace interpreter |
| 395 } // namespace internal | 411 } // namespace internal |
| 396 } // namespace v8 | 412 } // namespace v8 |
| 397 | 413 |
| 398 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 414 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |