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_FRAME_STATES_H_ | 5 #ifndef V8_COMPILER_FRAME_STATES_H_ |
6 #define V8_COMPILER_FRAME_STATES_H_ | 6 #define V8_COMPILER_FRAME_STATES_H_ |
7 | 7 |
8 #include "src/compiler/machine-type.h" | |
8 #include "src/handles.h" | 9 #include "src/handles.h" |
9 #include "src/utils.h" | 10 #include "src/utils.h" |
11 #include "src/zone-containers.h" | |
10 | 12 |
11 namespace v8 { | 13 namespace v8 { |
12 namespace internal { | 14 namespace internal { |
13 | 15 |
14 // Forward declarations. | 16 // Forward declarations. |
15 class SharedFunctionInfo; | 17 class SharedFunctionInfo; |
18 class Translation; | |
16 | 19 |
17 namespace compiler { | 20 namespace compiler { |
18 | 21 |
22 // Forward declarations. | |
23 class OperandGenerator; | |
24 class CodeGenerator; | |
25 class Node; | |
26 class Instruction; | |
27 class InstructionOperand; | |
28 typedef ZoneVector<InstructionOperand> InstructionOperandVector; | |
29 | |
19 // Flag that describes how to combine the current environment with | 30 // Flag that describes how to combine the current environment with |
20 // the output of a node to obtain a framestate for lazy bailout. | 31 // the output of a node to obtain a framestate for lazy bailout. |
21 class OutputFrameStateCombine { | 32 class OutputFrameStateCombine { |
22 public: | 33 public: |
23 enum Kind { | 34 enum Kind { |
24 kPushOutput, // Push the output on the expression stack. | 35 kPushOutput, // Push the output on the expression stack. |
25 kPokeAt // Poke at the given environment location, | 36 kPokeAt // Poke at the given environment location, |
26 // counting from the top of the stack. | 37 // counting from the top of the stack. |
27 }; | 38 }; |
28 | 39 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 std::ostream& operator<<(std::ostream&, FrameStateInfo const&); | 168 std::ostream& operator<<(std::ostream&, FrameStateInfo const&); |
158 | 169 |
159 static const int kFrameStateParametersInput = 0; | 170 static const int kFrameStateParametersInput = 0; |
160 static const int kFrameStateLocalsInput = 1; | 171 static const int kFrameStateLocalsInput = 1; |
161 static const int kFrameStateStackInput = 2; | 172 static const int kFrameStateStackInput = 2; |
162 static const int kFrameStateContextInput = 3; | 173 static const int kFrameStateContextInput = 3; |
163 static const int kFrameStateFunctionInput = 4; | 174 static const int kFrameStateFunctionInput = 4; |
164 static const int kFrameStateOuterStateInput = 5; | 175 static const int kFrameStateOuterStateInput = 5; |
165 static const int kFrameStateInputCount = kFrameStateOuterStateInput + 1; | 176 static const int kFrameStateInputCount = kFrameStateOuterStateInput + 1; |
166 | 177 |
178 | |
179 enum class FrameStateInputKind { kAny, kStackSlot }; | |
180 | |
181 | |
182 class StateObjectCache { | |
183 public: | |
184 explicit StateObjectCache(Zone* zone) : objects_(zone) {} | |
185 static const size_t kNotCached = std::numeric_limits<std::size_t>::max(); | |
186 | |
187 size_t GetObjectId(Node* node) { | |
188 for (size_t i = 0; i < objects_.size(); ++i) { | |
189 if (objects_[i] == node) { | |
190 return i; | |
191 } | |
192 } | |
193 return kNotCached; | |
194 } | |
195 | |
196 size_t InsertObject(Node* node) { | |
197 size_t id = objects_.size(); | |
198 objects_.push_back(node); | |
199 return id; | |
200 } | |
201 | |
202 private: | |
203 ZoneVector<Node*> objects_; | |
204 }; | |
205 | |
206 | |
207 // Forward Declaration. | |
208 class FrameStateDescriptor; | |
209 | |
210 | |
211 class StateValueDescriptor { | |
212 public: | |
213 static const size_t kNoId = std::numeric_limits<std::size_t>::max(); | |
214 | |
215 StateValueDescriptor(Zone* zone, MachineType type, size_t id = kNoId) | |
216 : type_(type), id_(id), fields_(zone) {} | |
217 | |
218 size_t AddOperand(InstructionOperandVector* inputs, OperandGenerator* g, | |
Jarin
2015/12/02 12:24:34
It is unfortunate that frame state needs to know a
sigurds
2015/12/02 16:35:13
Done.
| |
219 StateObjectCache* cache, Node* input, MachineType type, | |
220 FrameStateInputKind kind, Zone* zone); | |
221 | |
222 size_t Translate(CodeGenerator* gen, Translation* translation, | |
223 Instruction* instr, size_t frame_state_offset); | |
224 size_t TranslateOperand(size_t index, CodeGenerator* gen, | |
225 Translation* translation, Instruction* instr, | |
226 size_t frame_state_offset); | |
227 | |
228 size_t size() { return fields_.size(); } | |
229 | |
230 int IsRecursive() { return fields_.size() > 0; } | |
231 int IsDuplicate() { return fields_.size() == 0 && id_ != kNoId; } | |
Jarin
2015/12/02 12:24:34
I am wondering whether it would not be more readab
sigurds
2015/12/02 16:35:13
Great idea, thanks.
| |
232 | |
233 MachineType GetOperandType(size_t index) const { | |
234 return fields_[index].type_; | |
235 } | |
236 | |
237 | |
238 private: | |
239 MachineType type_; | |
240 size_t id_; | |
241 ZoneVector<StateValueDescriptor> fields_; | |
242 }; | |
243 | |
244 | |
245 class FrameStateDescriptor : public ZoneObject { | |
246 public: | |
247 FrameStateDescriptor(Zone* zone, FrameStateType type, BailoutId bailout_id, | |
248 OutputFrameStateCombine state_combine, | |
249 size_t parameters_count, size_t locals_count, | |
250 size_t stack_count, | |
251 MaybeHandle<SharedFunctionInfo> shared_info, | |
252 FrameStateDescriptor* outer_state = nullptr); | |
253 | |
254 FrameStateType type() const { return type_; } | |
255 BailoutId bailout_id() const { return bailout_id_; } | |
256 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } | |
257 size_t parameters_count() const { return parameters_count_; } | |
258 size_t locals_count() const { return locals_count_; } | |
259 size_t stack_count() const { return stack_count_; } | |
260 MaybeHandle<SharedFunctionInfo> shared_info() const { return shared_info_; } | |
261 FrameStateDescriptor* outer_state() const { return outer_state_; } | |
262 bool HasContext() const { | |
263 return type_ == FrameStateType::kJavaScriptFunction; | |
264 } | |
265 | |
266 size_t AddInputs(Node* state, OperandGenerator* g, StateObjectCache* cache, | |
267 InstructionOperandVector* inputs, FrameStateInputKind kind, | |
268 Zone* zone); | |
269 void TranslateOperands(CodeGenerator* gen, Instruction* instr, | |
270 size_t frame_state_offset, | |
271 OutputFrameStateCombine combine, | |
272 Translation* translation); | |
273 | |
274 size_t GetSize(OutputFrameStateCombine combine = | |
275 OutputFrameStateCombine::Ignore()) const; | |
276 size_t GetTotalSize() const; | |
277 size_t GetFrameCount() const; | |
278 size_t GetJSFrameCount() const; | |
279 | |
280 MachineType GetType(size_t index) const { | |
281 return values_.GetOperandType(index); | |
282 } | |
283 StateValueDescriptor* GetStateValueDescriptor() { return &values_; } | |
284 | |
285 private: | |
286 FrameStateType type_; | |
287 BailoutId bailout_id_; | |
288 OutputFrameStateCombine frame_state_combine_; | |
289 size_t parameters_count_; | |
290 size_t locals_count_; | |
291 size_t stack_count_; | |
292 StateValueDescriptor values_; | |
293 MaybeHandle<SharedFunctionInfo> const shared_info_; | |
294 FrameStateDescriptor* outer_state_; | |
295 }; | |
296 | |
297 | |
167 } // namespace compiler | 298 } // namespace compiler |
168 } // namespace internal | 299 } // namespace internal |
169 } // namespace v8 | 300 } // namespace v8 |
170 | 301 |
171 #endif // V8_COMPILER_FRAME_STATES_H_ | 302 #endif // V8_COMPILER_FRAME_STATES_H_ |
OLD | NEW |