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> | |
9 | |
10 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
11 #include "src/identity-map.h" | |
12 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
13 #include "src/zone.h" | 10 #include "src/interpreter/constant-array-builder.h" |
14 #include "src/zone-containers.h" | 11 #include "src/zone-containers.h" |
15 | 12 |
16 namespace v8 { | 13 namespace v8 { |
17 namespace internal { | 14 namespace internal { |
18 | 15 |
19 class Isolate; | 16 class Isolate; |
20 | 17 |
21 namespace interpreter { | 18 namespace interpreter { |
22 | 19 |
23 class BytecodeLabel; | 20 class BytecodeLabel; |
| 21 class ConstantArrayBuilder; |
24 class Register; | 22 class Register; |
25 | 23 |
26 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan | 24 // TODO(rmcilroy): Unify this with CreateArgumentsParameters::Type in Turbofan |
27 // when rest parameters implementation has settled down. | 25 // when rest parameters implementation has settled down. |
28 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; | 26 enum class CreateArgumentsType { kMappedArguments, kUnmappedArguments }; |
29 | 27 |
30 class BytecodeArrayBuilder final { | 28 class BytecodeArrayBuilder final { |
31 public: | 29 public: |
32 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); | 30 BytecodeArrayBuilder(Isolate* isolate, Zone* zone); |
33 ~BytecodeArrayBuilder(); | 31 ~BytecodeArrayBuilder(); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Register cache_array, Register index); | 219 Register cache_array, Register index); |
222 BytecodeArrayBuilder& ForInStep(Register index); | 220 BytecodeArrayBuilder& ForInStep(Register index); |
223 | 221 |
224 // Accessors | 222 // Accessors |
225 Zone* zone() const { return zone_; } | 223 Zone* zone() const { return zone_; } |
226 | 224 |
227 private: | 225 private: |
228 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } | 226 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; } |
229 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } | 227 const ZoneVector<uint8_t>* bytecodes() const { return &bytecodes_; } |
230 Isolate* isolate() const { return isolate_; } | 228 Isolate* isolate() const { return isolate_; } |
| 229 ConstantArrayBuilder* constant_array_builder() { |
| 230 return &constant_array_builder_; |
| 231 } |
| 232 const ConstantArrayBuilder* constant_array_builder() const { |
| 233 return &constant_array_builder_; |
| 234 } |
231 | 235 |
232 static Bytecode BytecodeForBinaryOperation(Token::Value op); | 236 static Bytecode BytecodeForBinaryOperation(Token::Value op); |
233 static Bytecode BytecodeForCountOperation(Token::Value op); | 237 static Bytecode BytecodeForCountOperation(Token::Value op); |
234 static Bytecode BytecodeForCompareOperation(Token::Value op); | 238 static Bytecode BytecodeForCompareOperation(Token::Value op); |
235 static Bytecode BytecodeForWideOperands(Bytecode bytecode); | 239 static Bytecode BytecodeForWideOperands(Bytecode bytecode); |
236 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); | 240 static Bytecode BytecodeForLoadIC(LanguageMode language_mode); |
237 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); | 241 static Bytecode BytecodeForKeyedLoadIC(LanguageMode language_mode); |
238 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); | 242 static Bytecode BytecodeForStoreIC(LanguageMode language_mode); |
239 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); | 243 static Bytecode BytecodeForKeyedStoreIC(LanguageMode language_mode); |
240 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, | 244 static Bytecode BytecodeForLoadGlobal(LanguageMode language_mode, |
241 TypeofMode typeof_mode); | 245 TypeofMode typeof_mode); |
242 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); | 246 static Bytecode BytecodeForStoreGlobal(LanguageMode language_mode); |
243 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); | 247 static Bytecode BytecodeForStoreLookupSlot(LanguageMode language_mode); |
244 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); | 248 static Bytecode BytecodeForCreateArguments(CreateArgumentsType type); |
245 static Bytecode BytecodeForDelete(LanguageMode language_mode); | 249 static Bytecode BytecodeForDelete(LanguageMode language_mode); |
246 | 250 |
247 static bool FitsInIdx8Operand(int value); | 251 static bool FitsInIdx8Operand(int value); |
248 static bool FitsInIdx8Operand(size_t value); | 252 static bool FitsInIdx8Operand(size_t value); |
249 static bool FitsInImm8Operand(int value); | 253 static bool FitsInImm8Operand(int value); |
250 static bool FitsInIdx16Operand(int value); | 254 static bool FitsInIdx16Operand(int value); |
251 static bool FitsInIdx16Operand(size_t value); | 255 static bool FitsInIdx16Operand(size_t value); |
252 | 256 |
253 static Bytecode GetJumpWithConstantOperand(Bytecode jump_with_smi8_operand); | 257 static Bytecode GetJumpWithConstantOperand(Bytecode jump_smi8_operand); |
254 static Bytecode GetJumpWithToBoolean(Bytecode jump); | 258 static Bytecode GetJumpWithConstantWideOperand(Bytecode jump_smi8_operand); |
| 259 static Bytecode GetJumpWithToBoolean(Bytecode jump_smi8_operand); |
255 | 260 |
256 template <size_t N> | 261 template <size_t N> |
257 INLINE(void Output(Bytecode bytecode, uint32_t(&oprands)[N])); | 262 INLINE(void Output(Bytecode bytecode, uint32_t(&oprands)[N])); |
258 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 263 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
259 uint32_t operand2, uint32_t operand3); | 264 uint32_t operand2, uint32_t operand3); |
260 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, | 265 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1, |
261 uint32_t operand2); | 266 uint32_t operand2); |
262 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); | 267 void Output(Bytecode bytecode, uint32_t operand0, uint32_t operand1); |
263 void Output(Bytecode bytecode, uint32_t operand0); | 268 void Output(Bytecode bytecode, uint32_t operand0); |
264 void Output(Bytecode bytecode); | 269 void Output(Bytecode bytecode); |
265 | 270 |
266 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, | 271 BytecodeArrayBuilder& OutputJump(Bytecode jump_bytecode, |
267 BytecodeLabel* label); | 272 BytecodeLabel* label); |
268 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, | 273 void PatchJump(const ZoneVector<uint8_t>::iterator& jump_target, |
269 ZoneVector<uint8_t>::iterator jump_location); | 274 const ZoneVector<uint8_t>::iterator& jump_location); |
| 275 void PatchIndirectJumpWith8BitOperand( |
| 276 const ZoneVector<uint8_t>::iterator& jump_target, |
| 277 const ZoneVector<uint8_t>::iterator& jump_location); |
| 278 void PatchIndirectJumpWith16BitOperand( |
| 279 const ZoneVector<uint8_t>::iterator& jump_target, |
| 280 const ZoneVector<uint8_t>::iterator& jump_location); |
270 | 281 |
271 void LeaveBasicBlock(); | 282 void LeaveBasicBlock(); |
272 void EnsureReturn(); | 283 void EnsureReturn(); |
273 | 284 |
274 bool OperandIsValid(Bytecode bytecode, int operand_index, | 285 bool OperandIsValid(Bytecode bytecode, int operand_index, |
275 uint32_t operand_value) const; | 286 uint32_t operand_value) const; |
276 bool LastBytecodeInSameBlock() const; | 287 bool LastBytecodeInSameBlock() const; |
277 | 288 |
278 bool NeedToBooleanCast(); | 289 bool NeedToBooleanCast(); |
279 bool IsRegisterInAccumulator(Register reg); | 290 bool IsRegisterInAccumulator(Register reg); |
280 | 291 |
| 292 // Temporary register management. |
281 int BorrowTemporaryRegister(); | 293 int BorrowTemporaryRegister(); |
282 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); | 294 int BorrowTemporaryRegisterNotInRange(int start_index, int end_index); |
283 int AllocateAndBorrowTemporaryRegister(); | 295 int AllocateAndBorrowTemporaryRegister(); |
284 void ReturnTemporaryRegister(int reg_index); | 296 void ReturnTemporaryRegister(int reg_index); |
285 int PrepareForConsecutiveTemporaryRegisters(size_t count); | 297 int PrepareForConsecutiveTemporaryRegisters(size_t count); |
286 void BorrowConsecutiveTemporaryRegister(int reg_index); | 298 void BorrowConsecutiveTemporaryRegister(int reg_index); |
287 bool TemporaryRegisterIsLive(Register reg) const; | 299 bool TemporaryRegisterIsLive(Register reg) const; |
288 | 300 |
289 Register first_temporary_register() const; | 301 Register first_temporary_register() const; |
290 Register last_temporary_register() const; | 302 Register last_temporary_register() const; |
291 | 303 |
292 // Gets a constant pool entry for the |object|. | 304 // Gets a constant pool entry for the |object|. |
293 size_t GetConstantPoolEntry(Handle<Object> object); | 305 size_t GetConstantPoolEntry(Handle<Object> object); |
294 | 306 |
295 Isolate* isolate_; | 307 Isolate* isolate_; |
296 Zone* zone_; | 308 Zone* zone_; |
297 ZoneVector<uint8_t> bytecodes_; | 309 ZoneVector<uint8_t> bytecodes_; |
298 bool bytecode_generated_; | 310 bool bytecode_generated_; |
| 311 ConstantArrayBuilder constant_array_builder_; |
299 size_t last_block_end_; | 312 size_t last_block_end_; |
300 size_t last_bytecode_start_; | 313 size_t last_bytecode_start_; |
301 bool exit_seen_in_block_; | 314 bool exit_seen_in_block_; |
302 int unbound_jumps_; | 315 int unbound_jumps_; |
303 | 316 |
304 IdentityMap<size_t> constants_map_; | |
305 ZoneVector<Handle<Object>> constants_; | |
306 | |
307 int parameter_count_; | 317 int parameter_count_; |
308 int local_register_count_; | 318 int local_register_count_; |
309 int context_register_count_; | 319 int context_register_count_; |
310 int temporary_register_count_; | 320 int temporary_register_count_; |
311 | |
312 ZoneSet<int> free_temporaries_; | 321 ZoneSet<int> free_temporaries_; |
313 | 322 |
314 class PreviousBytecodeHelper; | 323 class PreviousBytecodeHelper; |
315 friend class TemporaryRegisterScope; | 324 friend class TemporaryRegisterScope; |
316 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); | 325 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayBuilder); |
317 }; | 326 }; |
318 | 327 |
319 | 328 |
320 // A label representing a branch target in a bytecode array. When a | 329 // A label representing a branch target in a bytecode array. When a |
321 // label is bound, it represents a known position in the bytecode | 330 // label is bound, it represents a known position in the bytecode |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 397 |
389 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); | 398 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); |
390 }; | 399 }; |
391 | 400 |
392 | 401 |
393 } // namespace interpreter | 402 } // namespace interpreter |
394 } // namespace internal | 403 } // namespace internal |
395 } // namespace v8 | 404 } // namespace v8 |
396 | 405 |
397 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ | 406 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ |
OLD | NEW |