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 used for translating wide register operands | |
rmcilroy
2016/01/22 17:50:56
/s/of used/of registers used
| |
69 // into byte sized register operands.. | |
rmcilroy
2016/01/22 17:50:56
remove extra full-stop.
| |
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 | 246 |
234 // Creates a new handler table entry and returns a {hander_id} identifying the | 247 // Creates a new handler table entry and returns a {hander_id} identifying the |
235 // entry, so that it can be referenced by above exception handling support. | 248 // entry, so that it can be referenced by above exception handling support. |
236 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } | 249 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } |
237 | 250 |
238 // Accessors | 251 // Accessors |
239 Zone* zone() const { return zone_; } | 252 Zone* zone() const { return zone_; } |
240 | 253 |
241 private: | 254 private: |
242 class PreviousBytecodeHelper; | 255 class PreviousBytecodeHelper; |
256 class RegisterTranslationScope; | |
243 friend class BytecodeRegisterAllocator; | 257 friend class BytecodeRegisterAllocator; |
244 | 258 |
245 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 259 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
246 static Bytecode BytecodeForCountOperation(Token::Value op); | 260 static Bytecode BytecodeForCountOperation(Token::Value op); |
247 static Bytecode BytecodeForCompareOperation(Token::Value op); | 261 static Bytecode BytecodeForCompareOperation(Token::Value op); |
248 static Bytecode BytecodeForWideOperands(Bytecode bytecode); | 262 static Bytecode BytecodeForWideOperands(Bytecode bytecode); |
249 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); | 263 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); |
250 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); | 264 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); |
251 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 265 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
252 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 266 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
253 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, | 267 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, |
254 TypeofMode typeof_mode); | 268 TypeofMode typeof_mode); |
255 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 269 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
256 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 270 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
257 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 271 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
258 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 272 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
259 | 273 |
260 static bool FitsInIdx8Operand(int value); | 274 static bool FitsInIdx8Operand(int value); |
261 static bool FitsInIdx8Operand(size_t value); | 275 static bool FitsInIdx8Operand(size_t value); |
262 static bool FitsInImm8Operand(int value); | 276 static bool FitsInImm8Operand(int value); |
263 static bool FitsInIdx16Operand(int value); | 277 static bool FitsInIdx16Operand(int value); |
264 static bool FitsInIdx16Operand(size_t value); | 278 static bool FitsInIdx16Operand(size_t value); |
265 static bool FitsInReg8Operand(Register value); | 279 static bool FitsInReg8Operand(Register value); |
280 static bool FitsInReg8OperandUntranslated(Register value); | |
266 static bool FitsInReg16Operand(Register value); | 281 static bool FitsInReg16Operand(Register value); |
282 static bool FitsInReg16OperandUntranslated(Register value); | |
283 | |
284 bool MoveRegisterUntranslated(Register from, Register to) override; | |
267 | 285 |
268 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); | 286 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
269 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); | 287 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
270 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); | 288 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
271 | 289 |
272 Register MapRegister(Register reg); | |
273 Register MapRegisters(Register reg, Register args_base, int args_length = 1); | |
274 | |
275 template <size_t N> | 290 template <size_t N> |
276 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); | 291 INLINE(void Output(Bytecode bytecode, uint32_t(&operands)[N])); |
277 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 292 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
278 uint32_t operand2, uint32_t operand3); | 293 uint32_t operand2, uint32_t operand3); |
279 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 294 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
280 uint32_t operand2); | 295 uint32_t operand2); |
281 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 296 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
282 void Output(Bytecode bytecode, uint32_t operand0); | 297 void Output(Bytecode bytecode, uint32_t operand0); |
283 void Output(Bytecode bytecode); | 298 void Output(Bytecode bytecode); |
284 | 299 |
285 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 300 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
286 BytecodeLabel* label); | 301 BytecodeLabel* label); |
287 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 302 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
288 const ZoneVector<uint8_t>::iterator& jump_location); | 303 const ZoneVector<uint8_t>::iterator& jump_location); |
289 void PatchIndirectJumpWith8BitOperand( | 304 void PatchIndirectJumpWith8BitOperand( |
290 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 305 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
291 void PatchIndirectJumpWith16BitOperand( | 306 void PatchIndirectJumpWith16BitOperand( |
292 const ZoneVector<uint8_t>::iterator& jump_location, int delta); | 307 const ZoneVector<uint8_t>::iterator& jump_location, int delta); |
293 | 308 |
294 void LeaveBasicBlock(); | 309 void LeaveBasicBlock(); |
295 void EnsureReturn(); | 310 void EnsureReturn(); |
296 | 311 |
297 bool OperandIsValid(Bytecode bytecode, int operand_index, | 312 bool OperandIsValid(Bytecode bytecode, int operand_index, |
298 uint32_t operand_value) const; | 313 uint32_t operand_value) const; |
299 bool LastBytecodeInSameBlock() const; | |
300 bool RegisterIsValid(Register reg, OperandType reg_type) const; | 314 bool RegisterIsValid(Register reg, OperandType reg_type) const; |
301 | 315 |
316 bool LastBytecodeInSameBlock() const; | |
302 bool NeedToBooleanCast(); | 317 bool NeedToBooleanCast(); |
303 bool IsRegisterInAccumulator(Register reg); | 318 bool IsRegisterInAccumulator(Register reg); |
304 | 319 |
305 // Temporary register management. | 320 // Temporary register management. |
321 void ForgeTemporaryRegister(); | |
306 int BorrowTemporaryRegister(); | 322 int BorrowTemporaryRegister(); |
307 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 323 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
308 void ReturnTemporaryRegister(int reg_index); | 324 void ReturnTemporaryRegister(int reg_index); |
309 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 325 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
310 void BorrowConsecutiveTemporaryRegister(int reg_index); | 326 void BorrowConsecutiveTemporaryRegister(int reg_index); |
311 bool TemporaryRegisterIsLive(Register reg) const; | 327 bool TemporaryRegisterIsLive(Register reg) const; |
312 | 328 |
313 Register first_temporary_register() const; | 329 Register first_temporary_register() const; |
314 Register last_temporary_register() const; | 330 Register last_temporary_register() const; |
315 | 331 |
316 // Gets a constant pool entry for the |object|. | 332 // Gets a constant pool entry for the |object|. |
317 size_t GetConstantPoolEntry(Handle<Object> object); | 333 size_t GetConstantPoolEntry(Handle<Object> object); |
318 | 334 |
319 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 335 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
320 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 336 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
321 Isolate* isolate() const { return isolate_; } | 337 Isolate* isolate() const { return isolate_; } |
322 ConstantArrayBuilder* constant_array_builder() { | 338 ConstantArrayBuilder* constant_array_builder() { |
323 return &constant_array_builder_; | 339 return &constant_array_builder_; |
324 } | 340 } |
325 const ConstantArrayBuilder* constant_array_builder() const { | 341 const ConstantArrayBuilder* constant_array_builder() const { |
326 return &constant_array_builder_; | 342 return &constant_array_builder_; |
327 } | 343 } |
328 HandlerTableBuilder* handler_table_builder() { | 344 HandlerTableBuilder* handler_table_builder() { |
329 return &handler_table_builder_; | 345 return &handler_table_builder_; |
330 } | 346 } |
347 RegisterTranslator* register_translator() { return ®ister_translator_; } | |
348 void set_register_translation_scope(RegisterTranslationScope* scope) { | |
349 register_translation_scope_ = scope; | |
350 } | |
351 RegisterTranslationScope* register_translation_scope() const { | |
352 return register_translation_scope_; | |
353 } | |
331 | 354 |
332 Isolate* isolate_; | 355 Isolate* isolate_; |
333 Zone* zone_; | 356 Zone* zone_; |
334 ZoneVector<uint8_t> bytecodes_; | 357 ZoneVector<uint8_t> bytecodes_; |
335 bool bytecode_generated_; | 358 bool bytecode_generated_; |
336 ConstantArrayBuilder constant_array_builder_; | 359 ConstantArrayBuilder constant_array_builder_; |
337 HandlerTableBuilder handler_table_builder_; | 360 HandlerTableBuilder handler_table_builder_; |
338 size_t last_block_end_; | 361 size_t last_block_end_; |
339 size_t last_bytecode_start_; | 362 size_t last_bytecode_start_; |
340 bool exit_seen_in_block_; | 363 bool exit_seen_in_block_; |
341 int unbound_jumps_; | 364 int unbound_jumps_; |
342 | |
343 int parameter_count_; | 365 int parameter_count_; |
344 int local_register_count_; | 366 int local_register_count_; |
345 int context_register_count_; | 367 int context_register_count_; |
346 int temporary_register_count_; | 368 int temporary_register_count_; |
347 ZoneSet<int> free_temporaries_; | 369 ZoneSet<int> free_temporaries_; |
370 RegisterTranslator register_translator_; | |
371 RegisterTranslationScope* register_translation_scope_; | |
348 | 372 |
349 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 373 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
350 }; | 374 }; |
351 | 375 |
352 | 376 |
353 // A label representing a branch target in a bytecode array. When a | 377 // A label representing a branch target in a bytecode array. When a |
354 // label is bound, it represents a known position in the bytecode | 378 // label is bound, it represents a known position in the bytecode |
355 // array. For labels that are forward references there can be at most | 379 // array. For labels that are forward references there can be at most |
356 // one reference whilst it is unbound. | 380 // one reference whilst it is unbound. |
357 class BytecodeLabel final { | 381 class BytecodeLabel final { |
(...skipping 30 matching lines...) Expand all Loading... | |
388 size_t offset_; | 412 size_t offset_; |
389 | 413 |
390 friend class BytecodeArrayBuilder; | 414 friend class BytecodeArrayBuilder; |
391 }; | 415 }; |
392 | 416 |
393 } // namespace interpreter | 417 } // namespace interpreter |
394 } // namespace internal | 418 } // namespace internal |
395 } // namespace v8 | 419 } // namespace v8 |
396 | 420 |
397 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 421 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |