Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1284)

Side by Side Diff: src/interpreter/bytecode-array-builder.h

Issue 1651133002: [interpreter] Move temporary register allocator into own file. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Incorporate review comments from rmcilroy. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/identity-map.cc ('k') | src/interpreter/bytecode-array-builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bytecode-register-allocator.h"
9 #include "src/interpreter/bytecodes.h" 10 #include "src/interpreter/bytecodes.h"
10 #include "src/interpreter/constant-array-builder.h" 11 #include "src/interpreter/constant-array-builder.h"
11 #include "src/interpreter/handler-table-builder.h" 12 #include "src/interpreter/handler-table-builder.h"
12 #include "src/interpreter/register-translator.h" 13 #include "src/interpreter/register-translator.h"
13 #include "src/zone-containers.h" 14 #include "src/zone-containers.h"
14 15
15 namespace v8 { 16 namespace v8 {
16 namespace internal { 17 namespace internal {
17 18
18 class Isolate; 19 class Isolate;
19 20
20 namespace interpreter { 21 namespace interpreter {
21 22
22 class BytecodeLabel; 23 class BytecodeLabel;
23 class Register; 24 class Register;
24 25
25 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan 26 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan
26 // when rest parameters implementation has settled down. 27 // when rest parameters implementation has settled down.
27 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; 28 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments };
28 29
29 class BytecodeArrayBuilder final : private RegisterMover { 30 class BytecodeArrayBuilder final : public ZoneObject, private RegisterMover {
30 public: 31 public:
31 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); 32 BytecodeArrayBuilder(Isolate* isolate, Zone* zone, int parameter_count,
33 int context_count, int locals_count);
32 ~BytecodeArrayBuilder(); 34 ~BytecodeArrayBuilder();
33 35
34 Handle<BytecodeArray> ToBytecodeArray(); 36 Handle<BytecodeArray> ToBytecodeArray();
35 37
36 // Set the number of parameters expected by function. 38 // Get the number of parameters expected by function.
37 void set_parameter_count(int number_of_params);
38 int parameter_count() const { 39 int parameter_count() const {
39 DCHECK_GE(parameter_count_, 0); 40 DCHECK_GE(parameter_count_, 0);
40 return parameter_count_; 41 return parameter_count_;
41 } 42 }
42 43
43 // Set the number of locals required for bytecode array. 44 // Get the number of locals required for bytecode array.
44 void set_locals_count(int number_of_locals);
45 int locals_count() const { 45 int locals_count() const {
46 DCHECK_GE(local_register_count_, 0); 46 DCHECK_GE(local_register_count_, 0);
47 return local_register_count_; 47 return local_register_count_;
48 } 48 }
49 49
50 // Set number of contexts required for bytecode array. 50 // Get number of contexts required for bytecode array.
51 void set_context_count(int number_of_contexts);
52 int context_count() const { 51 int context_count() const {
53 DCHECK_GE(context_register_count_, 0); 52 DCHECK_GE(context_register_count_, 0);
54 return context_register_count_; 53 return context_register_count_;
55 } 54 }
56 55
57 Register first_context_register() const; 56 Register first_context_register() const;
58 Register last_context_register() const; 57 Register last_context_register() const;
59 58
60 // Returns the number of fixed (non-temporary) registers. 59 // Returns the number of fixed (non-temporary) registers.
61 int fixed_register_count() const { return context_count() + locals_count(); } 60 int fixed_register_count() const { return context_count() + locals_count(); }
62 61
63 // Returns the number of fixed and temporary registers. 62 // Returns the number of fixed and temporary registers.
64 int fixed_and_temporary_register_count() const { 63 int fixed_and_temporary_register_count() const {
65 return fixed_register_count() + temporary_register_count_; 64 return fixed_register_count() + temporary_register_count();
65 }
66
67 int temporary_register_count() const {
68 return temporary_register_allocator()->allocation_count();
66 } 69 }
67 70
68 // Returns the number of registers used for translating wide 71 // Returns the number of registers used for translating wide
69 // register operands into byte sized register operands. 72 // register operands into byte sized register operands.
70 int translation_register_count() const { 73 int translation_register_count() const {
71 return RegisterTranslator::RegisterCountAdjustment( 74 return RegisterTranslator::RegisterCountAdjustment(
72 fixed_and_temporary_register_count(), parameter_count()); 75 fixed_and_temporary_register_count(), parameter_count());
73 } 76 }
74 77
75 Register Parameter(int parameter_index) const; 78 Register Parameter(int parameter_index) const;
76 79
77 // Return true if the register |reg| represents a parameter or a 80 // Return true if the register |reg| represents a parameter or a
78 // local. 81 // local.
79 bool RegisterIsParameterOrLocal(Register reg) const; 82 bool RegisterIsParameterOrLocal(Register reg) const;
80 83
81 // Return true if the register |reg| represents a temporary register. 84 // Returns true if the register |reg| is a live temporary register.
82 bool RegisterIsTemporary(Register reg) const; 85 bool TemporaryRegisterIsLive(Register reg) const;
83 86
84 // Constant loads to accumulator. 87 // Constant loads to accumulator.
85 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); 88 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value);
86 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); 89 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object);
87 BytecodeArrayBuilder& LoadUndefined(); 90 BytecodeArrayBuilder& LoadUndefined();
88 BytecodeArrayBuilder& LoadNull(); 91 BytecodeArrayBuilder& LoadNull();
89 BytecodeArrayBuilder& LoadTheHole(); 92 BytecodeArrayBuilder& LoadTheHole();
90 BytecodeArrayBuilder& LoadTrue(); 93 BytecodeArrayBuilder& LoadTrue();
91 BytecodeArrayBuilder& LoadFalse(); 94 BytecodeArrayBuilder& LoadFalse();
92 BytecodeArrayBuilder& LoadBooleanConstant(bool value); 95 BytecodeArrayBuilder& LoadBooleanConstant(bool value);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 BytecodeArrayBuilder& MarkHandler(int handler_id, bool will_catch); 247 BytecodeArrayBuilder& MarkHandler(int handler_id, bool will_catch);
245 BytecodeArrayBuilder& MarkTryBegin(int handler_id, Register context); 248 BytecodeArrayBuilder& MarkTryBegin(int handler_id, Register context);
246 BytecodeArrayBuilder& MarkTryEnd(int handler_id); 249 BytecodeArrayBuilder& MarkTryEnd(int handler_id);
247 250
248 // Creates a new handler table entry and returns a {hander_id} identifying the 251 // Creates a new handler table entry and returns a {hander_id} identifying the
249 // entry, so that it can be referenced by above exception handling support. 252 // entry, so that it can be referenced by above exception handling support.
250 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); } 253 int NewHandlerEntry() { return handler_table_builder()->NewHandlerEntry(); }
251 254
252 // Accessors 255 // Accessors
253 Zone* zone() const { return zone_; } 256 Zone* zone() const { return zone_; }
257 TemporaryRegisterAllocator* temporary_register_allocator() {
258 return &temporary_allocator_;
259 }
260 const TemporaryRegisterAllocator* temporary_register_allocator() const {
261 return &temporary_allocator_;
262 }
254 263
255 private: 264 private:
256 class PreviousBytecodeHelper; 265 class PreviousBytecodeHelper;
257 friend class BytecodeRegisterAllocator; 266 friend class BytecodeRegisterAllocator;
258 267
259 static Bytecode BytecodeForBinaryOperation(Token::Value op); 268 static Bytecode BytecodeForBinaryOperation(Token::Value op);
260 static Bytecode BytecodeForCountOperation(Token::Value op); 269 static Bytecode BytecodeForCountOperation(Token::Value op);
261 static Bytecode BytecodeForCompareOperation(Token::Value op); 270 static Bytecode BytecodeForCompareOperation(Token::Value op);
262 static Bytecode BytecodeForWideOperands(Bytecode bytecode); 271 static Bytecode BytecodeForWideOperands(Bytecode bytecode);
263 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); 272 static Bytecode BytecodeForLoadIC(LanguageMode language_mode);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 void EnsureReturn(); 320 void EnsureReturn();
312 321
313 bool OperandIsValid(Bytecode bytecode, int operand_index, 322 bool OperandIsValid(Bytecode bytecode, int operand_index,
314 uint32_t operand_value) const; 323 uint32_t operand_value) const;
315 bool RegisterIsValid(Register reg, OperandType reg_type) const; 324 bool RegisterIsValid(Register reg, OperandType reg_type) const;
316 325
317 bool LastBytecodeInSameBlock() const; 326 bool LastBytecodeInSameBlock() const;
318 bool NeedToBooleanCast(); 327 bool NeedToBooleanCast();
319 bool IsRegisterInAccumulator(Register reg); 328 bool IsRegisterInAccumulator(Register reg);
320 329
321 // Temporary register management.
322 void ForgeTemporaryRegister();
323 int BorrowTemporaryRegister();
324 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index);
325 void ReturnTemporaryRegister(int reg_index);
326 int PrepareForConsecutiveTemporaryRegisters(size_t count);
327 void BorrowConsecutiveTemporaryRegister(int reg_index);
328 bool TemporaryRegisterIsLive(Register reg) const;
329
330 Register first_temporary_register() const;
331 Register last_temporary_register() const;
332
333 // Gets a constant pool entry for the |object|. 330 // Gets a constant pool entry for the |object|.
334 size_t GetConstantPoolEntry(Handle<Object> object); 331 size_t GetConstantPoolEntry(Handle<Object> object);
335 332
336 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } 333 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; }
337 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } 334 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; }
338 Isolate* isolate() const { return isolate_; } 335 Isolate* isolate() const { return isolate_; }
339 ConstantArrayBuilder* constant_array_builder() { 336 ConstantArrayBuilder* constant_array_builder() {
340 return &constant_array_builder_; 337 return &constant_array_builder_;
341 } 338 }
342 const ConstantArrayBuilder* constant_array_builder() const { 339 const ConstantArrayBuilder* constant_array_builder() const {
(...skipping 10 matching lines...) Expand all
353 bool bytecode_generated_; 350 bool bytecode_generated_;
354 ConstantArrayBuilder constant_array_builder_; 351 ConstantArrayBuilder constant_array_builder_;
355 HandlerTableBuilder handler_table_builder_; 352 HandlerTableBuilder handler_table_builder_;
356 size_t last_block_end_; 353 size_t last_block_end_;
357 size_t last_bytecode_start_; 354 size_t last_bytecode_start_;
358 bool exit_seen_in_block_; 355 bool exit_seen_in_block_;
359 int unbound_jumps_; 356 int unbound_jumps_;
360 int parameter_count_; 357 int parameter_count_;
361 int local_register_count_; 358 int local_register_count_;
362 int context_register_count_; 359 int context_register_count_;
363 int temporary_register_count_; 360 TemporaryRegisterAllocator temporary_allocator_;
364 ZoneSet<int> free_temporaries_;
365 RegisterTranslator register_translator_; 361 RegisterTranslator register_translator_;
366 362
367 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); 363 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder);
368 }; 364 };
369 365
370 366
371 // A label representing a branch target in a bytecode array. When a 367 // A label representing a branch target in a bytecode array. When a
372 // label is bound, it represents a known position in the bytecode 368 // label is bound, it represents a known position in the bytecode
373 // array. For labels that are forward references there can be at most 369 // array. For labels that are forward references there can be at most
374 // one reference whilst it is unbound. 370 // one reference whilst it is unbound.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 size_t offset_; 402 size_t offset_;
407 403
408 friend class BytecodeArrayBuilder; 404 friend class BytecodeArrayBuilder;
409 }; 405 };
410 406
411 } // namespace interpreter 407 } // namespace interpreter
412 } // namespace internal 408 } // namespace internal
413 } // namespace v8 409 } // namespace v8
414 410
415 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 411 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
OLDNEW
« no previous file with comments | « src/identity-map.cc ('k') | src/interpreter/bytecode-array-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698