| 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 // RegisterMover interface methods. |
| 285 void MoveRegisterUntranslated(Register from, Register to) override; |
| 286 bool RegisterOperandIsMovable(Bytecode bytecode, int operand_index) override; |
| 268 | 287 |
| 269 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 288 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
| 270 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); | 289 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
| 271 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | 290 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
| 272 | 291 |
| 273 Register MapRegister(Register reg); | |
| 274 Register MapRegisters(Register reg, Register args_base, int args_length = 1); | |
| 275 | |
| 276 template <size_t N> | 292 template <size_t N> |
| 277 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); | 293 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); |
| 278 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 294 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 279 uint32_t operand2, uint32_t operand3); | 295 uint32_t operand2, uint32_t operand3); |
| 280 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 296 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
| 281 uint32_t operand2); | 297 uint32_t operand2); |
| 282 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 298 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
| 283 void Output(Bytecode bytecode, uint32_t operand0); | 299 void Output(Bytecode bytecode, uint32_t operand0); |
| 284 void Output(Bytecode bytecode); | 300 void Output(Bytecode bytecode); |
| 285 | 301 |
| 286 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 302 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
| 287 BytecodeLabel* label); | 303 BytecodeLabel* label); |
| 288 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 304 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
| 289 const ZoneVector<uint8_t>::iterator& jump_location); | 305 const ZoneVector<uint8_t>::iterator& jump_location); |
| 290 void PatchIndirectJumpWith8BitOperand( | 306 void PatchIndirectJumpWith8BitOperand( |
| 291 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 307 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 292 void PatchIndirectJumpWith16BitOperand( | 308 void PatchIndirectJumpWith16BitOperand( |
| 293 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 309 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
| 294 | 310 |
| 295 void LeaveBasicBlock(); | 311 void LeaveBasicBlock(); |
| 296 void EnsureReturn(); | 312 void EnsureReturn(); |
| 297 | 313 |
| 298 bool OperandIsValid(Bytecode bytecode, int operand_index, | 314 bool OperandIsValid(Bytecode bytecode, int operand_index, |
| 299 uint32_t operand_value) const; | 315 uint32_t operand_value) const; |
| 300 bool LastBytecodeInSameBlock() const; | |
| 301 bool RegisterIsValid(Register reg, OperandType reg_type) const; | 316 bool RegisterIsValid(Register reg, OperandType reg_type) const; |
| 302 | 317 |
| 318 bool LastBytecodeInSameBlock() const; |
| 303 bool NeedToBooleanCast(); | 319 bool NeedToBooleanCast(); |
| 304 bool IsRegisterInAccumulator(Register reg); | 320 bool IsRegisterInAccumulator(Register reg); |
| 305 | 321 |
| 306 // Temporary register management. | 322 // Temporary register management. |
| 323 void ForgeTemporaryRegister(); |
| 307 int BorrowTemporaryRegister(); | 324 int BorrowTemporaryRegister(); |
| 308 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 325 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
| 309 void ReturnTemporaryRegister(int reg_index); | 326 void ReturnTemporaryRegister(int reg_index); |
| 310 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 327 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
| 311 void BorrowConsecutiveTemporaryRegister(int reg_index); | 328 void BorrowConsecutiveTemporaryRegister(int reg_index); |
| 312 bool TemporaryRegisterIsLive(Register reg) const; | 329 bool TemporaryRegisterIsLive(Register reg) const; |
| 313 | 330 |
| 314 Register first_temporary_register() const; | 331 Register first_temporary_register() const; |
| 315 Register last_temporary_register() const; | 332 Register last_temporary_register() const; |
| 316 | 333 |
| 317 // Gets a constant pool entry for the |object|. | 334 // Gets a constant pool entry for the |object|. |
| 318 size_t GetConstantPoolEntry(Handle<Object> object); | 335 size_t GetConstantPoolEntry(Handle<Object> object); |
| 319 | 336 |
| 320 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 337 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
| 321 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 338 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
| 322 Isolate* isolate() const { return isolate_; } | 339 Isolate* isolate() const { return isolate_; } |
| 323 ConstantArrayBuilder* constant_array_builder() { | 340 ConstantArrayBuilder* constant_array_builder() { |
| 324 return &constant_array_builder_; | 341 return &constant_array_builder_; |
| 325 } | 342 } |
| 326 const ConstantArrayBuilder* constant_array_builder() const { | 343 const ConstantArrayBuilder* constant_array_builder() const { |
| 327 return &constant_array_builder_; | 344 return &constant_array_builder_; |
| 328 } | 345 } |
| 329 HandlerTableBuilder* handler_table_builder() { | 346 HandlerTableBuilder* handler_table_builder() { |
| 330 return &handler_table_builder_; | 347 return &handler_table_builder_; |
| 331 } | 348 } |
| 349 RegisterTranslator* register_translator() { return ®ister_translator_; } |
| 332 | 350 |
| 333 Isolate* isolate_; | 351 Isolate* isolate_; |
| 334 Zone* zone_; | 352 Zone* zone_; |
| 335 ZoneVector<uint8_t> bytecodes_; | 353 ZoneVector<uint8_t> bytecodes_; |
| 336 bool bytecode_generated_; | 354 bool bytecode_generated_; |
| 337 ConstantArrayBuilder constant_array_builder_; | 355 ConstantArrayBuilder constant_array_builder_; |
| 338 HandlerTableBuilder handler_table_builder_; | 356 HandlerTableBuilder handler_table_builder_; |
| 339 size_t last_block_end_; | 357 size_t last_block_end_; |
| 340 size_t last_bytecode_start_; | 358 size_t last_bytecode_start_; |
| 341 bool exit_seen_in_block_; | 359 bool exit_seen_in_block_; |
| 342 int unbound_jumps_; | 360 int unbound_jumps_; |
| 343 | |
| 344 int parameter_count_; | 361 int parameter_count_; |
| 345 int local_register_count_; | 362 int local_register_count_; |
| 346 int context_register_count_; | 363 int context_register_count_; |
| 347 int temporary_register_count_; | 364 int temporary_register_count_; |
| 348 ZoneSet<int> free_temporaries_; | 365 ZoneSet<int> free_temporaries_; |
| 366 RegisterTranslator register_translator_; |
| 349 | 367 |
| 350 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 368 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
| 351 }; | 369 }; |
| 352 | 370 |
| 353 | 371 |
| 354 // A label representing a branch target in a bytecode array. When a | 372 // A label representing a branch target in a bytecode array. When a |
| 355 // label is bound, it represents a known position in the bytecode | 373 // label is bound, it represents a known position in the bytecode |
| 356 // array. For labels that are forward references there can be at most | 374 // array. For labels that are forward references there can be at most |
| 357 // one reference whilst it is unbound. | 375 // one reference whilst it is unbound. |
| 358 class BytecodeLabel final { | 376 class BytecodeLabel final { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 389 size_t offset_; | 407 size_t offset_; |
| 390 | 408 |
| 391 friend class BytecodeArrayBuilder; | 409 friend class BytecodeArrayBuilder; |
| 392 }; | 410 }; |
| 393 | 411 |
| 394 } // namespace interpreter | 412 } // namespace interpreter |
| 395 } // namespace internal | 413 } // namespace internal |
| 396 } // namespace v8 | 414 } // namespace v8 |
| 397 | 415 |
| 398 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 416 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
| OLD | NEW |