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

Side by Side Diff: src/interpreter/bytecode-register-allocator.h

Issue 1997653002: [interpreter] Bytecode register optimizer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Grammar. Created 4 years, 7 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
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_REGISTER_ALLOCATOR_H_ 5 #ifndef V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
6 #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ 6 #define V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
7 7
8 #include "src/interpreter/bytecodes.h" 8 #include "src/interpreter/bytecodes.h"
9 #include "src/zone-containers.h" 9 #include "src/zone-containers.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 namespace interpreter { 13 namespace interpreter {
14 14
15 class BytecodeArrayBuilder; 15 class BytecodeArrayBuilder;
16 class Register; 16 class Register;
17 17
18 class TemporaryRegisterObserver;
rmcilroy 2016/05/26 10:24:52 nit - move into block above
oth 2016/05/26 21:26:50 Done.
19
18 class TemporaryRegisterAllocator final { 20 class TemporaryRegisterAllocator final {
19 public: 21 public:
20 TemporaryRegisterAllocator(Zone* zone, int start_index); 22 TemporaryRegisterAllocator(Zone* zone, int start_index);
21 23
22 // Borrow a temporary register. 24 // Borrow a temporary register.
23 int BorrowTemporaryRegister(); 25 int BorrowTemporaryRegister();
24 26
25 // Borrow a temporary register from the register range outside of 27 // Borrow a temporary register from the register range outside of
26 // |start_index| to |end_index|. 28 // |start_index| to |end_index|.
27 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); 29 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index);
(...skipping 19 matching lines...) Expand all
47 49
48 // Returns the last register in the range of temporary registers. 50 // Returns the last register in the range of temporary registers.
49 Register last_temporary_register() const; 51 Register last_temporary_register() const;
50 52
51 // Returns the start index of temporary register allocations. 53 // Returns the start index of temporary register allocations.
52 int allocation_base() const { return allocation_base_; } 54 int allocation_base() const { return allocation_base_; }
53 55
54 // Returns the number of temporary register allocations made. 56 // Returns the number of temporary register allocations made.
55 int allocation_count() const { return allocation_count_; } 57 int allocation_count() const { return allocation_count_; }
56 58
59 // Sets an observer for temporary register events.
60 void set_observer(TemporaryRegisterObserver* observer);
61
57 private: 62 private:
58 // Allocate a temporary register. 63 // Allocate a temporary register.
59 int AllocateTemporaryRegister(); 64 int AllocateTemporaryRegister();
60 65
61 ZoneSet<int> free_temporaries_; 66 ZoneSet<int> free_temporaries_;
62 int allocation_base_; 67 int allocation_base_;
63 int allocation_count_; 68 int allocation_count_;
69 TemporaryRegisterObserver* observer_;
64 70
65 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterAllocator); 71 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterAllocator);
66 }; 72 };
67 73
74 class TemporaryRegisterObserver {
75 public:
76 virtual ~TemporaryRegisterObserver() {}
77 virtual void TemporaryRegisterFreeEvent(Register reg) = 0;
78 };
79
68 // A class that allows the instantiator to allocate temporary registers that are 80 // A class that allows the instantiator to allocate temporary registers that are
69 // cleaned up when scope is closed. 81 // cleaned up when scope is closed.
70 class BytecodeRegisterAllocator final { 82 class BytecodeRegisterAllocator final {
71 public: 83 public:
72 explicit BytecodeRegisterAllocator(Zone* zone, 84 explicit BytecodeRegisterAllocator(Zone* zone,
73 TemporaryRegisterAllocator* allocator); 85 TemporaryRegisterAllocator* allocator);
74 ~BytecodeRegisterAllocator(); 86 ~BytecodeRegisterAllocator();
75 Register NewRegister(); 87 Register NewRegister();
76 88
77 // Ensure |count| consecutive allocations are available. 89 // Ensure |count| consecutive allocations are available.
(...skipping 19 matching lines...) Expand all
97 109
98 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator); 110 DISALLOW_COPY_AND_ASSIGN(BytecodeRegisterAllocator);
99 }; 111 };
100 112
101 } // namespace interpreter 113 } // namespace interpreter
102 } // namespace internal 114 } // namespace internal
103 } // namespace v8 115 } // namespace v8
104 116
105 117
106 #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_ 118 #endif // V8_INTERPRETER_BYTECODE_REGISTER_ALLOCATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698