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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "src/ast.h" | 10 #include "src/ast.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 namespace interpreter { | 21 namespace interpreter { |
22 | 22 |
23 class BytecodeLabel; | 23 class BytecodeLabel; |
24 class Register; | 24 class Register; |
25 | 25 |
26 class BytecodeArrayBuilder { | 26 class BytecodeArrayBuilder { |
27 public: | 27 public: |
28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 28 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
29 Handle<BytecodeArray> ToBytecodeArray(); | 29 Handle<BytecodeArray> ToBytecodeArray(); |
30 | 30 |
31 // Set number of parameters expected by function. | 31 // Set the number of parameters expected by function. |
32 void set_parameter_count(int number_of_params); | 32 void set_parameter_count(int number_of_params); |
33 int parameter_count() const { | 33 int parameter_count() const { |
34 DCHECK_GE(parameter_count_, 0); | 34 DCHECK_GE(parameter_count_, 0); |
35 return parameter_count_; | 35 return parameter_count_; |
36 } | 36 } |
37 | 37 |
38 // Set number of locals required for bytecode array. | 38 // Set the number of locals required for bytecode array. |
39 void set_locals_count(int number_of_locals); | 39 void set_locals_count(int number_of_locals); |
40 int locals_count() const { | 40 int locals_count() const { |
41 DCHECK_GE(local_register_count_, 0); | 41 DCHECK_GE(local_register_count_, 0); |
42 return local_register_count_; | 42 return local_register_count_; |
43 } | 43 } |
44 | 44 |
45 // Set number of contexts required for bytecode array. | 45 // Set number of contexts required for bytecode array. |
46 void set_context_count(int number_of_contexts); | 46 void set_context_count(int number_of_contexts); |
47 int context_count() const { | 47 int context_count() const { |
48 DCHECK_GE(context_register_count_, 0); | 48 DCHECK_GE(context_register_count_, 0); |
49 return context_register_count_; | 49 return context_register_count_; |
50 } | 50 } |
51 | 51 |
52 Register first_context_register() const; | 52 Register first_context_register() const; |
53 Register last_context_register() const; | 53 Register last_context_register() const; |
54 | 54 |
55 // Returns the number of fixed (non-temporary) registers. | 55 // Returns the number of fixed (non-temporary) registers. |
56 int fixed_register_count() const { return context_count() + locals_count(); } | 56 int fixed_register_count() const { return context_count() + locals_count(); } |
57 | 57 |
58 Register Parameter(int parameter_index) const; | 58 Register Parameter(int parameter_index) const; |
59 | 59 |
60 // Constant loads to the accumulator. | 60 // Return true if the register |reg| represents a parameter or a |
61 // local. | |
62 bool RegisterIsParameterOrLocal(Register reg) const; | |
63 | |
64 // Return true if the register |reg| represents a temporary register. | |
65 bool RegisterIsTemporary(Register reg) const; | |
66 | |
67 // Constant loads to accumulator. | |
61 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); | 68 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); |
62 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); | 69 BytecodeArrayBuilder& LoadLiteral(Handle<Object> object); |
63 BytecodeArrayBuilder& LoadUndefined(); | 70 BytecodeArrayBuilder& LoadUndefined(); |
64 BytecodeArrayBuilder& LoadNull(); | 71 BytecodeArrayBuilder& LoadNull(); |
65 BytecodeArrayBuilder& LoadTheHole(); | 72 BytecodeArrayBuilder& LoadTheHole(); |
66 BytecodeArrayBuilder& LoadTrue(); | 73 BytecodeArrayBuilder& LoadTrue(); |
67 BytecodeArrayBuilder& LoadFalse(); | 74 BytecodeArrayBuilder& LoadFalse(); |
68 | 75 |
69 // Global loads to accumulator and stores from the accumulator. | 76 // Global loads to the accumulator and stores from the accumulator. |
70 BytecodeArrayBuilder& LoadGlobal(int slot_index); | 77 BytecodeArrayBuilder& LoadGlobal(int slot_index); |
71 BytecodeArrayBuilder& StoreGlobal(int slot_index, LanguageMode language_mode); | 78 BytecodeArrayBuilder& StoreGlobal(int slot_index, LanguageMode language_mode); |
72 | 79 |
73 // Load the object at |slot_index| in |context| into the accumulator. | 80 // Load the object at |slot_index| in |context| into the accumulator. |
74 BytecodeArrayBuilder& LoadContextSlot(Register context, int slot_index); | 81 BytecodeArrayBuilder& LoadContextSlot(Register context, int slot_index); |
75 | 82 |
76 // Stores the object in the accumulator into |slot_index| of |context|. | 83 // Stores the object in the accumulator into |slot_index| of |context|. |
77 BytecodeArrayBuilder& StoreContextSlot(Register context, int slot_index); | 84 BytecodeArrayBuilder& StoreContextSlot(Register context, int slot_index); |
78 | 85 |
79 // Register-accumulator transfers. | 86 // Register-accumulator transfers. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 Strength strength); | 140 Strength strength); |
134 | 141 |
135 // Unary Operators. | 142 // Unary Operators. |
136 BytecodeArrayBuilder& LogicalNot(); | 143 BytecodeArrayBuilder& LogicalNot(); |
137 BytecodeArrayBuilder& TypeOf(); | 144 BytecodeArrayBuilder& TypeOf(); |
138 | 145 |
139 // Tests. | 146 // Tests. |
140 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, | 147 BytecodeArrayBuilder& CompareOperation(Token::Value op, Register reg, |
141 Strength strength); | 148 Strength strength); |
142 | 149 |
143 // Casts | 150 // Casts. |
144 BytecodeArrayBuilder& CastAccumulatorToBoolean(); | 151 BytecodeArrayBuilder& CastAccumulatorToBoolean(); |
145 BytecodeArrayBuilder& CastAccumulatorToName(); | 152 BytecodeArrayBuilder& CastAccumulatorToName(); |
146 | 153 |
147 // Flow Control. | 154 // Flow Control. |
148 BytecodeArrayBuilder& Bind(BytecodeLabel* label); | 155 BytecodeArrayBuilder& Bind(BytecodeLabel* label); |
149 BytecodeArrayBuilder& Bind(const BytecodeLabel& target, BytecodeLabel* label); | 156 BytecodeArrayBuilder& Bind(const BytecodeLabel& target, BytecodeLabel* label); |
150 | 157 |
151 BytecodeArrayBuilder& Jump(BytecodeLabel* label); | 158 BytecodeArrayBuilder& Jump(BytecodeLabel* label); |
152 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); | 159 BytecodeArrayBuilder& JumpIfTrue(BytecodeLabel* label); |
153 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); | 160 BytecodeArrayBuilder& JumpIfFalse(BytecodeLabel* label); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
198 ZoneVector<uint8_t>::iterator jump_location); | 205 ZoneVector<uint8_t>::iterator jump_location); |
199 | 206 |
200 void EnsureReturn(); | 207 void EnsureReturn(); |
201 | 208 |
202 bool OperandIsValid(Bytecode bytecode, int operand_index, | 209 bool OperandIsValid(Bytecode bytecode, int operand_index, |
203 uint32_t operand_value) const; | 210 uint32_t operand_value) const; |
204 bool LastBytecodeInSameBlock() const; | 211 bool LastBytecodeInSameBlock() const; |
205 | 212 |
206 size_t GetConstantPoolEntry(Handle<Object> object); | 213 size_t GetConstantPoolEntry(Handle<Object> object); |
207 | 214 |
208 // Scope helpers used by TemporaryRegisterScope | |
209 int BorrowTemporaryRegister(); | 215 int BorrowTemporaryRegister(); |
210 void ReturnTemporaryRegister(int reg_index); | 216 void ReturnTemporaryRegister(int reg_index); |
217 int PrepareForConsecutiveTemporaryRegisters(size_t count); | |
218 void BorrowConsecutiveTemporaryRegister(int reg_index); | |
219 bool TemporaryRegisterIsLive(Register reg) const; | |
220 | |
221 Register first_temporary_register() const; | |
222 Register last_temporary_register() const; | |
211 | 223 |
212 Isolate* isolate_; | 224 Isolate* isolate_; |
213 Zone* zone_; | 225 Zone* zone_; |
214 ZoneVector<uint8_t> bytecodes_; | 226 ZoneVector<uint8_t> bytecodes_; |
215 bool bytecode_generated_; | 227 bool bytecode_generated_; |
216 size_t last_block_end_; | 228 size_t last_block_end_; |
217 size_t last_bytecode_start_; | 229 size_t last_bytecode_start_; |
218 bool return_seen_in_block_; | 230 bool return_seen_in_block_; |
219 | 231 |
220 IdentityMap<size_t> constants_map_; | 232 IdentityMap<size_t> constants_map_; |
221 ZoneVector<Handle<Object>> constants_; | 233 ZoneVector<Handle<Object>> constants_; |
222 | 234 |
223 int parameter_count_; | 235 int parameter_count_; |
224 int local_register_count_; | 236 int local_register_count_; |
225 int context_register_count_; | 237 int context_register_count_; |
226 int temporary_register_count_; | 238 int temporary_register_count_; |
227 int temporary_register_next_; | 239 |
240 ZoneSet<int> free_temporaries_; | |
228 | 241 |
229 friend class TemporaryRegisterScope; | 242 friend class TemporaryRegisterScope; |
230 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); | 243 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
231 }; | 244 }; |
232 | 245 |
233 | 246 |
234 // A label representing a branch target in a bytecode array. When a | 247 // A label representing a branch target in a bytecode array. When a |
235 // label is bound, it represents a known position in the bytecode | 248 // label is bound, it represents a known position in the bytecode |
236 // array. For labels that are forward references there can be at most | 249 // array. For labels that are forward references there can be at most |
237 // one reference whilst it is unbound. | 250 // one reference whilst it is unbound. |
238 class BytecodeLabel final { | 251 class BytecodeLabel final { |
239 public: | 252 public: |
240 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} | 253 BytecodeLabel() : bound_(false), offset_(kInvalidOffset) {} |
(...skipping 29 matching lines...) Expand all Loading... | |
270 | 283 |
271 | 284 |
272 // A stack-allocated class than allows the instantiator to allocate | 285 // A stack-allocated class than allows the instantiator to allocate |
273 // temporary registers that are cleaned up when scope is closed. | 286 // temporary registers that are cleaned up when scope is closed. |
274 class TemporaryRegisterScope { | 287 class TemporaryRegisterScope { |
275 public: | 288 public: |
276 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); | 289 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); |
277 ~TemporaryRegisterScope(); | 290 ~TemporaryRegisterScope(); |
278 Register NewRegister(); | 291 Register NewRegister(); |
279 | 292 |
293 | |
rmcilroy
2015/10/20 16:39:20
nit - remove extra newline
oth
2015/10/20 20:58:42
Done.
| |
294 void PrepareForConsecutiveAllocations(size_t count); | |
295 Register NextConsecutiveRegister(); | |
296 | |
280 private: | 297 private: |
281 void* operator new(size_t size); | 298 void* operator new(size_t size); |
282 void operator delete(void* p); | 299 void operator delete(void* p); |
283 | 300 |
284 BytecodeArrayBuilder* builder_; | 301 BytecodeArrayBuilder* builder_; |
285 int count_; | 302 const TemporaryRegisterScope* outer_; |
286 int last_register_index_; | 303 ZoneVector<int> allocated_; |
304 int next_consecutive_register_; | |
305 int next_consecutive_count_; | |
287 | 306 |
288 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 307 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
289 }; | 308 }; |
290 | 309 |
291 | 310 |
292 } // namespace interpreter | 311 } // namespace interpreter |
293 } // namespace internal | 312 } // namespace internal |
294 } // namespace v8 | 313 } // namespace v8 |
295 | 314 |
296 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 315 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |