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_COMPILER_INTERPRETER_ASSEMBLER_H_ | 5 #ifndef V8_INTERPRETER_INTERPRETER_ASSEMBLER_H_ |
6 #define V8_COMPILER_INTERPRETER_ASSEMBLER_H_ | 6 #define V8_INTERPRETER_INTERPRETER_ASSEMBLER_H_ |
7 | 7 |
8 // Clients of this interface shouldn't depend on lots of compiler internals. | |
9 // Do not include anything from src/compiler here! | |
10 #include "src/allocation.h" | 8 #include "src/allocation.h" |
11 #include "src/base/smart-pointers.h" | 9 #include "src/base/smart-pointers.h" |
12 #include "src/builtins.h" | 10 #include "src/builtins.h" |
| 11 #include "src/compiler/code-stub-assembler.h" |
13 #include "src/frames.h" | 12 #include "src/frames.h" |
14 #include "src/interpreter/bytecodes.h" | 13 #include "src/interpreter/bytecodes.h" |
15 #include "src/runtime/runtime.h" | 14 #include "src/runtime/runtime.h" |
16 | 15 |
17 namespace v8 { | 16 namespace v8 { |
18 namespace internal { | 17 namespace internal { |
| 18 namespace interpreter { |
19 | 19 |
20 class CallInterfaceDescriptor; | 20 class InterpreterAssembler : public compiler::CodeStubAssembler { |
21 class Isolate; | |
22 class Zone; | |
23 | |
24 namespace compiler { | |
25 | |
26 class CallDescriptor; | |
27 class Graph; | |
28 class Node; | |
29 class Operator; | |
30 class RawMachineAssembler; | |
31 class Schedule; | |
32 | |
33 class InterpreterAssembler { | |
34 public: | 21 public: |
35 InterpreterAssembler(Isolate* isolate, Zone* zone, | 22 InterpreterAssembler(Isolate* isolate, Zone* zone, Bytecode bytecode); |
36 interpreter::Bytecode bytecode); | |
37 virtual ~InterpreterAssembler(); | 23 virtual ~InterpreterAssembler(); |
38 | 24 |
39 Handle<Code> GenerateCode(); | |
40 | |
41 // Returns the count immediate for bytecode operand |operand_index| in the | 25 // Returns the count immediate for bytecode operand |operand_index| in the |
42 // current bytecode. | 26 // current bytecode. |
43 Node* BytecodeOperandCount(int operand_index); | 27 compiler::Node* BytecodeOperandCount(int operand_index); |
44 // Returns the index immediate for bytecode operand |operand_index| in the | 28 // Returns the index immediate for bytecode operand |operand_index| in the |
45 // current bytecode. | 29 // current bytecode. |
46 Node* BytecodeOperandIdx(int operand_index); | 30 compiler::Node* BytecodeOperandIdx(int operand_index); |
47 // Returns the Imm8 immediate for bytecode operand |operand_index| in the | 31 // Returns the Imm8 immediate for bytecode operand |operand_index| in the |
48 // current bytecode. | 32 // current bytecode. |
49 Node* BytecodeOperandImm(int operand_index); | 33 compiler::Node* BytecodeOperandImm(int operand_index); |
50 // Returns the register index for bytecode operand |operand_index| in the | 34 // Returns the register index for bytecode operand |operand_index| in the |
51 // current bytecode. | 35 // current bytecode. |
52 Node* BytecodeOperandReg(int operand_index); | 36 compiler::Node* BytecodeOperandReg(int operand_index); |
53 | 37 |
54 // Accumulator. | 38 // Accumulator. |
55 Node* GetAccumulator(); | 39 compiler::Node* GetAccumulator(); |
56 void SetAccumulator(Node* value); | 40 void SetAccumulator(compiler::Node* value); |
57 | 41 |
58 // Context. | 42 // Context. |
59 Node* GetContext(); | 43 compiler::Node* GetContext(); |
60 void SetContext(Node* value); | 44 void SetContext(compiler::Node* value); |
61 | 45 |
62 // Loads from and stores to the interpreter register file. | 46 // Loads from and stores to the interpreter register file. |
63 Node* LoadRegister(int offset); | 47 compiler::Node* LoadRegister(int offset); |
64 Node* LoadRegister(interpreter::Register reg); | 48 compiler::Node* LoadRegister(Register reg); |
65 Node* LoadRegister(Node* reg_index); | 49 compiler::Node* LoadRegister(compiler::Node* reg_index); |
66 Node* StoreRegister(Node* value, int offset); | 50 compiler::Node* StoreRegister(compiler::Node* value, int offset); |
67 Node* StoreRegister(Node* value, interpreter::Register reg); | 51 compiler::Node* StoreRegister(compiler::Node* value, Register reg); |
68 Node* StoreRegister(Node* value, Node* reg_index); | 52 compiler::Node* StoreRegister(compiler::Node* value, |
| 53 compiler::Node* reg_index); |
69 | 54 |
70 // Returns the next consecutive register. | 55 // Returns the next consecutive register. |
71 Node* NextRegister(Node* reg_index); | 56 compiler::Node* NextRegister(compiler::Node* reg_index); |
72 | 57 |
73 // Returns the location in memory of the register |reg_index| in the | 58 // Returns the location in memory of the register |reg_index| in the |
74 // interpreter register file. | 59 // interpreter register file. |
75 Node* RegisterLocation(Node* reg_index); | 60 compiler::Node* RegisterLocation(compiler::Node* reg_index); |
76 | |
77 // Constants. | |
78 Node* Int32Constant(int value); | |
79 Node* IntPtrConstant(intptr_t value); | |
80 Node* NumberConstant(double value); | |
81 Node* HeapConstant(Handle<HeapObject> object); | |
82 Node* BooleanConstant(bool value); | |
83 | |
84 // Tag and untag Smi values. | |
85 Node* SmiTag(Node* value); | |
86 Node* SmiUntag(Node* value); | |
87 | |
88 // Basic arithmetic operations. | |
89 Node* IntPtrAdd(Node* a, Node* b); | |
90 Node* IntPtrSub(Node* a, Node* b); | |
91 Node* Int32Sub(Node* a, Node* b); | |
92 Node* WordShl(Node* value, int shift); | |
93 | 61 |
94 // Load constant at |index| in the constant pool. | 62 // Load constant at |index| in the constant pool. |
95 Node* LoadConstantPoolEntry(Node* index); | 63 compiler::Node* LoadConstantPoolEntry(compiler::Node* index); |
96 | 64 |
97 // Load an element from a fixed array on the heap. | 65 // Load an element from a fixed array on the heap. |
98 Node* LoadFixedArrayElement(Node* fixed_array, int index); | 66 compiler::Node* LoadFixedArrayElement(compiler::Node* fixed_array, int index); |
99 | 67 |
100 // Load a field from an object on the heap. | 68 // Load a field from an object on the heap. |
101 Node* LoadObjectField(Node* object, int offset); | 69 compiler::Node* LoadObjectField(compiler::Node* object, int offset); |
102 | 70 |
103 // Load |slot_index| from |context|. | 71 // Load |slot_index| from |context|. |
104 Node* LoadContextSlot(Node* context, int slot_index); | 72 compiler::Node* LoadContextSlot(compiler::Node* context, int slot_index); |
105 Node* LoadContextSlot(Node* context, Node* slot_index); | 73 compiler::Node* LoadContextSlot(compiler::Node* context, |
| 74 compiler::Node* slot_index); |
106 // Stores |value| into |slot_index| of |context|. | 75 // Stores |value| into |slot_index| of |context|. |
107 Node* StoreContextSlot(Node* context, Node* slot_index, Node* value); | 76 compiler::Node* StoreContextSlot(compiler::Node* context, |
| 77 compiler::Node* slot_index, |
| 78 compiler::Node* value); |
108 | 79 |
109 // Load the TypeFeedbackVector for the current function. | 80 // Load the TypeFeedbackVector for the current function. |
110 Node* LoadTypeFeedbackVector(); | 81 compiler::Node* LoadTypeFeedbackVector(); |
111 | 82 |
112 // Project the output value at index |index| | 83 // Call JSFunction or Callable |function| with |arg_count| |
113 Node* Projection(int index, Node* node); | 84 // arguments (not including receiver) and the first argument |
| 85 // located at |first_arg|. |
| 86 compiler::Node* CallJS(compiler::Node* function, compiler::Node* context, |
| 87 compiler::Node* first_arg, compiler::Node* arg_count); |
114 | 88 |
115 // Call constructor |constructor| with |arg_count| arguments (not | 89 // Call constructor |constructor| with |arg_count| arguments (not |
116 // including receiver) and the first argument located at | 90 // including receiver) and the first argument located at |
117 // |first_arg|. The |new_target| is the same as the | 91 // |first_arg|. The |new_target| is the same as the |
118 // |constructor| for the new keyword, but differs for the super | 92 // |constructor| for the new keyword, but differs for the super |
119 // keyword. | 93 // keyword. |
120 Node* CallConstruct(Node* new_target, Node* constructor, Node* first_arg, | 94 compiler::Node* CallConstruct(compiler::Node* constructor, |
121 Node* arg_count); | 95 compiler::Node* context, |
| 96 compiler::Node* new_target, |
| 97 compiler::Node* first_arg, |
| 98 compiler::Node* arg_count); |
122 | 99 |
123 // Call JSFunction or Callable |function| with |arg_count| | 100 // Call runtime function with |arg_count| arguments and the first argument |
124 // arguments (not including receiver) and the first argument | |
125 // located at |first_arg|. | 101 // located at |first_arg|. |
126 Node* CallJS(Node* function, Node* first_arg, Node* arg_count); | 102 compiler::Node* CallRuntimeN(compiler::Node* function_id, |
127 | 103 compiler::Node* context, |
128 // Call an IC code stub. | 104 compiler::Node* first_arg, |
129 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node* arg1, | 105 compiler::Node* arg_count, int return_size = 1); |
130 Node* arg2, Node* arg3); | |
131 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node* arg1, | |
132 Node* arg2, Node* arg3, Node* arg4); | |
133 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node* arg1, | |
134 Node* arg2, Node* arg3, Node* arg4, Node* arg5); | |
135 | |
136 // Call runtime function. | |
137 Node* CallRuntime(Node* function_id, Node* first_arg, Node* arg_count, | |
138 int return_size = 1); | |
139 Node* CallRuntime(Runtime::FunctionId function_id); | |
140 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1); | |
141 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2); | |
142 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2, | |
143 Node* arg3); | |
144 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2, | |
145 Node* arg3, Node* arg4); | |
146 | 106 |
147 // Jump relative to the current bytecode by |jump_offset|. | 107 // Jump relative to the current bytecode by |jump_offset|. |
148 void Jump(Node* jump_offset); | 108 void Jump(compiler::Node* jump_offset); |
149 | 109 |
150 // Jump relative to the current bytecode by |jump_offset| if the | 110 // Jump relative to the current bytecode by |jump_offset| if the |
151 // |condition| is true. Helper function for JumpIfWordEqual and | 111 // |condition| is true. Helper function for JumpIfWordEqual and |
152 // JumpIfWordNotEqual. | 112 // JumpIfWordNotEqual. |
153 void JumpConditional(Node* condition, Node* jump_offset); | 113 void JumpConditional(compiler::Node* condition, compiler::Node* jump_offset); |
154 | 114 |
155 // Jump relative to the current bytecode by |jump_offset| if the | 115 // Jump relative to the current bytecode by |jump_offset| if the |
156 // word values |lhs| and |rhs| are equal. | 116 // word values |lhs| and |rhs| are equal. |
157 void JumpIfWordEqual(Node* lhs, Node* rhs, Node* jump_offset); | 117 void JumpIfWordEqual(compiler::Node* lhs, compiler::Node* rhs, |
| 118 compiler::Node* jump_offset); |
158 | 119 |
159 // Jump relative to the current bytecode by |jump_offset| if the | 120 // Jump relative to the current bytecode by |jump_offset| if the |
160 // word values |lhs| and |rhs| are not equal. | 121 // word values |lhs| and |rhs| are not equal. |
161 void JumpIfWordNotEqual(Node* lhs, Node* rhs, Node* jump_offset); | 122 void JumpIfWordNotEqual(compiler::Node* lhs, compiler::Node* rhs, |
| 123 compiler::Node* jump_offset); |
162 | 124 |
163 // Perform a stack guard check. | 125 // Perform a stack guard check. |
164 void StackCheck(); | 126 void StackCheck(); |
165 | 127 |
166 // Returns from the function. | 128 // Returns from the function. |
167 void Return(); | 129 void InterpreterReturn(); |
168 | 130 |
169 // Dispatch to the bytecode. | 131 // Dispatch to the bytecode. |
170 void Dispatch(); | 132 void Dispatch(); |
171 | 133 |
172 // Abort with the given bailout reason. | 134 // Abort with the given bailout reason. |
173 void Abort(BailoutReason bailout_reason); | 135 void Abort(BailoutReason bailout_reason); |
174 | 136 |
175 protected: | 137 protected: |
176 static bool TargetSupportsUnalignedAccess(); | 138 static bool TargetSupportsUnalignedAccess(); |
177 | 139 |
178 // Protected helpers (for testing) which delegate to RawMachineAssembler. | |
179 CallDescriptor* call_descriptor() const; | |
180 Graph* graph(); | |
181 | |
182 private: | 140 private: |
183 // Returns a raw pointer to start of the register file on the stack. | 141 // Returns a raw pointer to start of the register file on the stack. |
184 Node* RegisterFileRawPointer(); | 142 compiler::Node* RegisterFileRawPointer(); |
185 // Returns a tagged pointer to the current function's BytecodeArray object. | 143 // Returns a tagged pointer to the current function's BytecodeArray object. |
186 Node* BytecodeArrayTaggedPointer(); | 144 compiler::Node* BytecodeArrayTaggedPointer(); |
187 // Returns the offset from the BytecodeArrayPointer of the current bytecode. | 145 // Returns the offset from the BytecodeArrayPointer of the current bytecode. |
188 Node* BytecodeOffset(); | 146 compiler::Node* BytecodeOffset(); |
189 // Returns a raw pointer to first entry in the interpreter dispatch table. | 147 // Returns a raw pointer to first entry in the interpreter dispatch table. |
190 Node* DispatchTableRawPointer(); | 148 compiler::Node* DispatchTableRawPointer(); |
191 | 149 |
192 // Saves and restores interpreter bytecode offset to the interpreter stack | 150 // Saves and restores interpreter bytecode offset to the interpreter stack |
193 // frame when performing a call. | 151 // frame when performing a call. |
194 void CallPrologue(); | 152 void CallPrologue() override; |
| 153 void CallEpilogue() override; |
195 | 154 |
196 // Traces the current bytecode by calling |function_id|. | 155 // Traces the current bytecode by calling |function_id|. |
197 void TraceBytecode(Runtime::FunctionId function_id); | 156 void TraceBytecode(Runtime::FunctionId function_id); |
198 | 157 |
199 // Returns the offset of register |index| relative to RegisterFilePointer(). | 158 // Returns the offset of register |index| relative to RegisterFilePointer(). |
200 Node* RegisterFrameOffset(Node* index); | 159 compiler::Node* RegisterFrameOffset(compiler::Node* index); |
201 | 160 |
202 Node* SmiShiftBitsConstant(); | 161 compiler::Node* BytecodeOperand(int operand_index); |
203 Node* BytecodeOperand(int operand_index); | 162 compiler::Node* BytecodeOperandSignExtended(int operand_index); |
204 Node* BytecodeOperandSignExtended(int operand_index); | 163 compiler::Node* BytecodeOperandShort(int operand_index); |
205 Node* BytecodeOperandShort(int operand_index); | 164 compiler::Node* BytecodeOperandShortSignExtended(int operand_index); |
206 Node* BytecodeOperandShortSignExtended(int operand_index); | |
207 | |
208 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args); | |
209 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node** args); | |
210 | 165 |
211 // Returns BytecodeOffset() advanced by delta bytecodes. Note: this does not | 166 // Returns BytecodeOffset() advanced by delta bytecodes. Note: this does not |
212 // update BytecodeOffset() itself. | 167 // update BytecodeOffset() itself. |
213 Node* Advance(int delta); | 168 compiler::Node* Advance(int delta); |
214 Node* Advance(Node* delta); | 169 compiler::Node* Advance(compiler::Node* delta); |
215 | 170 |
216 // Starts next instruction dispatch at |new_bytecode_offset|. | 171 // Starts next instruction dispatch at |new_bytecode_offset|. |
217 void DispatchTo(Node* new_bytecode_offset); | 172 void DispatchTo(compiler::Node* new_bytecode_offset); |
218 | 173 |
219 // Abort operations for debug code. | 174 // Abort operations for debug code. |
220 void AbortIfWordNotEqual(Node* lhs, Node* rhs, BailoutReason bailout_reason); | 175 void AbortIfWordNotEqual(compiler::Node* lhs, compiler::Node* rhs, |
| 176 BailoutReason bailout_reason); |
221 | 177 |
222 // Private helpers which delegate to RawMachineAssembler. | 178 Bytecode bytecode_; |
223 Isolate* isolate(); | 179 compiler::Node* accumulator_; |
224 Zone* zone(); | 180 compiler::Node* context_; |
225 | 181 |
226 interpreter::Bytecode bytecode_; | 182 bool disable_stack_check_across_call_; |
227 base::SmartPointer<RawMachineAssembler> raw_assembler_; | 183 compiler::Node* stack_pointer_before_call_; |
228 | |
229 Node* accumulator_; | |
230 Node* context_; | |
231 | |
232 bool code_generated_; | |
233 | 184 |
234 DISALLOW_COPY_AND_ASSIGN(InterpreterAssembler); | 185 DISALLOW_COPY_AND_ASSIGN(InterpreterAssembler); |
235 }; | 186 }; |
236 | 187 |
237 } // namespace compiler | 188 } // namespace interpreter |
238 } // namespace internal | 189 } // namespace internal |
239 } // namespace v8 | 190 } // namespace v8 |
240 | 191 |
241 #endif // V8_COMPILER_INTERPRETER_ASSEMBLER_H_ | 192 #endif // V8_INTERPRETER_INTERPRETER_ASSEMBLER_H_ |
OLD | NEW |