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

Side by Side Diff: src/interpreter/interpreter-assembler.h

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

Powered by Google App Engine
This is Rietveld 408576698