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