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

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

Issue 1283313003: [interpreter]: Update BytecodeArrayBuilder register handling. (Closed) Base URL: ssh://rmcilroy.lon.corp.google.com///usr/local/google/code/v8_full/v8@master
Patch Set: Fix define in OperandTypeToString Created 5 years, 4 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 | « no previous file | src/interpreter/bytecode-array-builder.cc » ('j') | src/interpreter/bytecodes.h » ('J')
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 <vector> 8 #include <vector>
9 9
10 #include "src/ast.h" 10 #include "src/ast.h"
11 #include "src/interpreter/bytecodes.h" 11 #include "src/interpreter/bytecodes.h"
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 class Isolate; 16 class Isolate;
17 17
18 namespace interpreter { 18 namespace interpreter {
19 19
20 class Register;
21
20 class BytecodeArrayBuilder { 22 class BytecodeArrayBuilder {
21 public: 23 public:
22 explicit BytecodeArrayBuilder(Isolate* isolate); 24 explicit BytecodeArrayBuilder(Isolate* isolate);
23 Handle<BytecodeArray> ToBytecodeArray(); 25 Handle<BytecodeArray> ToBytecodeArray();
24 26
25 // Set number of locals required for bytecode array. 27 // Set number of locals required for bytecode array.
26 void set_locals_count(int number_of_locals); 28 void set_locals_count(int number_of_locals);
27 int locals_count() const; 29 int locals_count() const;
28 30
29 // Constant loads to accumulator 31 // Constant loads to accumulator.
30 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value); 32 BytecodeArrayBuilder& LoadLiteral(v8::internal::Smi* value);
31 BytecodeArrayBuilder& LoadUndefined(); 33 BytecodeArrayBuilder& LoadUndefined();
32 BytecodeArrayBuilder& LoadNull(); 34 BytecodeArrayBuilder& LoadNull();
33 BytecodeArrayBuilder& LoadTheHole(); 35 BytecodeArrayBuilder& LoadTheHole();
34 BytecodeArrayBuilder& LoadTrue(); 36 BytecodeArrayBuilder& LoadTrue();
35 BytecodeArrayBuilder& LoadFalse(); 37 BytecodeArrayBuilder& LoadFalse();
36 38
37 // Register-accumulator transfers 39 // Register-accumulator transfers.
38 BytecodeArrayBuilder& LoadAccumulatorWithRegister(int reg); 40 BytecodeArrayBuilder& LoadAccumulatorWithRegister(Register reg);
39 BytecodeArrayBuilder& StoreAccumulatorInRegister(int reg); 41 BytecodeArrayBuilder& StoreAccumulatorInRegister(Register reg);
40 42
41 // Operators 43 // Operators.
42 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, int reg); 44 BytecodeArrayBuilder& BinaryOperation(Token::Value binop, Register reg);
43 45
44 // Flow Control 46 // Flow Control.
45 BytecodeArrayBuilder& Return(); 47 BytecodeArrayBuilder& Return();
46 48
47 private: 49 private:
48 static Bytecode BytecodeForBinaryOperation(Token::Value op); 50 static Bytecode BytecodeForBinaryOperation(Token::Value op);
49 51
50 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2); 52 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1, uint8_t r2);
51 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1); 53 void Output(Bytecode bytecode, uint8_t r0, uint8_t r1);
52 void Output(Bytecode bytecode, uint8_t r0); 54 void Output(Bytecode bytecode, uint8_t r0);
53 void Output(Bytecode bytecode); 55 void Output(Bytecode bytecode);
54 56
55 bool OperandIsValid(Bytecode bytecode, int operand_index, 57 bool OperandIsValid(Bytecode bytecode, int operand_index,
56 uint8_t operand_value) const; 58 uint8_t operand_value) const;
57 59
58 int BorrowTemporaryRegister(); 60 int BorrowTemporaryRegister();
59 void ReturnTemporaryRegister(int reg); 61 void ReturnTemporaryRegister(int reg_index);
60 62
61 Isolate* isolate_; 63 Isolate* isolate_;
62 std::vector<uint8_t> bytecodes_; 64 std::vector<uint8_t> bytecodes_;
63 bool bytecode_generated_; 65 bool bytecode_generated_;
64 66
65 int local_register_count_; 67 int local_register_count_;
66 int temporary_register_count_; 68 int temporary_register_count_;
67 int temporary_register_next_; 69 int temporary_register_next_;
68 70
69 friend class TemporaryRegisterScope; 71 friend class TemporaryRegisterScope;
70 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder); 72 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArrayBuilder);
71 }; 73 };
72 74
75 // An interpreter register which is located in the function's regsiter file
76 // in its stack-frame.
77 class Register {
78 public:
79 static const int kMaxRegisterIndex = 128;
80
81 explicit Register(int index) : index_(index) {
82 DCHECK_LE(index_, kMaxRegisterIndex);
oth 2015/08/13 10:29:55 Probably worth having a lower bounds DCHECK too.
rmcilroy 2015/08/13 10:44:22 Done.
83 }
84
85 int index() { return index_; }
86 uint8_t ToOperand() { return static_cast<uint8_t>(-index_); }
87 static Register FromOperand(uint8_t operand) { return Register(-operand); }
88
89 private:
90 void* operator new(size_t size);
91 void operator delete(void* p);
92
93 int index_;
94 };
95
73 // A stack-allocated class than allows the instantiator to allocate 96 // A stack-allocated class than allows the instantiator to allocate
74 // temporary registers that are cleaned up when scope is closed. 97 // temporary registers that are cleaned up when scope is closed.
75 class TemporaryRegisterScope { 98 class TemporaryRegisterScope {
76 public: 99 public:
77 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder); 100 explicit TemporaryRegisterScope(BytecodeArrayBuilder* builder);
78 ~TemporaryRegisterScope(); 101 ~TemporaryRegisterScope();
79 int NewRegister(); 102 Register NewRegister();
80 103
81 private: 104 private:
82 void* operator new(size_t size); 105 void* operator new(size_t size);
83 void operator delete(void* p); 106 void operator delete(void* p);
84 107
85 BytecodeArrayBuilder* builder_; 108 BytecodeArrayBuilder* builder_;
86 int count_; 109 int count_;
87 int register_; 110 int last_register_index_;
88 111
89 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope); 112 DISALLOW_COPY_AND_ASSIGN(TemporaryRegisterScope);
90 }; 113 };
91 114
92 115
93 } // namespace interpreter 116 } // namespace interpreter
94 } // namespace internal 117 } // namespace internal
95 } // namespace v8 118 } // namespace v8
96 119
97 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_ 120 #endif // V8_INTERPRETER_BYTECODE_ARRAY_BUILDER_H_
OLDNEW
« no previous file with comments | « no previous file | src/interpreter/bytecode-array-builder.cc » ('j') | src/interpreter/bytecodes.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698