• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_FRAME_STATES_H_
6 #define V8_COMPILER_FRAME_STATES_H_
7 
8 #include "src/builtins/builtins.h"
9 #include "src/compiler/node.h"
10 #include "src/handles/handles.h"
11 #include "src/objects/shared-function-info.h"
12 #include "src/utils/utils.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 namespace compiler {
18 
19 class JSGraph;
20 class Node;
21 class SharedFunctionInfoRef;
22 
23 // Flag that describes how to combine the current environment with
24 // the output of a node to obtain a framestate for lazy bailout.
25 class OutputFrameStateCombine {
26  public:
27   static const size_t kInvalidIndex = SIZE_MAX;
28 
Ignore()29   static OutputFrameStateCombine Ignore() {
30     return OutputFrameStateCombine(kInvalidIndex);
31   }
PokeAt(size_t index)32   static OutputFrameStateCombine PokeAt(size_t index) {
33     return OutputFrameStateCombine(index);
34   }
35 
GetOffsetToPokeAt()36   size_t GetOffsetToPokeAt() const {
37     DCHECK_NE(parameter_, kInvalidIndex);
38     return parameter_;
39   }
40 
IsOutputIgnored()41   bool IsOutputIgnored() const { return parameter_ == kInvalidIndex; }
42 
ConsumedOutputCount()43   size_t ConsumedOutputCount() const { return IsOutputIgnored() ? 0 : 1; }
44 
45   bool operator==(OutputFrameStateCombine const& other) const {
46     return parameter_ == other.parameter_;
47   }
48   bool operator!=(OutputFrameStateCombine const& other) const {
49     return !(*this == other);
50   }
51 
52   friend size_t hash_value(OutputFrameStateCombine const&);
53   friend std::ostream& operator<<(std::ostream&,
54                                   OutputFrameStateCombine const&);
55 
56  private:
OutputFrameStateCombine(size_t parameter)57   explicit OutputFrameStateCombine(size_t parameter) : parameter_(parameter) {}
58 
59   size_t const parameter_;
60 };
61 
62 
63 // The type of stack frame that a FrameState node represents.
64 enum class FrameStateType {
65   kInterpretedFunction,            // Represents an InterpretedFrame.
66   kArgumentsAdaptor,               // Represents an ArgumentsAdaptorFrame.
67   kConstructStub,                  // Represents a ConstructStubFrame.
68   kBuiltinContinuation,            // Represents a continuation to a stub.
69   kJavaScriptBuiltinContinuation,  // Represents a continuation to a JavaScipt
70                                    // builtin.
71   kJavaScriptBuiltinContinuationWithCatch  // Represents a continuation to a
72                                            // JavaScipt builtin with a catch
73                                            // handler.
74 };
75 
76 class FrameStateFunctionInfo {
77  public:
FrameStateFunctionInfo(FrameStateType type,int parameter_count,int local_count,Handle<SharedFunctionInfo> shared_info)78   FrameStateFunctionInfo(FrameStateType type, int parameter_count,
79                          int local_count,
80                          Handle<SharedFunctionInfo> shared_info)
81       : type_(type),
82         parameter_count_(parameter_count),
83         local_count_(local_count),
84         shared_info_(shared_info) {}
85 
local_count()86   int local_count() const { return local_count_; }
parameter_count()87   int parameter_count() const { return parameter_count_; }
shared_info()88   Handle<SharedFunctionInfo> shared_info() const { return shared_info_; }
type()89   FrameStateType type() const { return type_; }
90 
IsJSFunctionType(FrameStateType type)91   static bool IsJSFunctionType(FrameStateType type) {
92     return type == FrameStateType::kInterpretedFunction ||
93            type == FrameStateType::kJavaScriptBuiltinContinuation ||
94            type == FrameStateType::kJavaScriptBuiltinContinuationWithCatch;
95   }
96 
97  private:
98   FrameStateType const type_;
99   int const parameter_count_;
100   int const local_count_;
101   Handle<SharedFunctionInfo> const shared_info_;
102 };
103 
104 
105 class FrameStateInfo final {
106  public:
FrameStateInfo(BailoutId bailout_id,OutputFrameStateCombine state_combine,const FrameStateFunctionInfo * info)107   FrameStateInfo(BailoutId bailout_id, OutputFrameStateCombine state_combine,
108                  const FrameStateFunctionInfo* info)
109       : bailout_id_(bailout_id),
110         frame_state_combine_(state_combine),
111         info_(info) {}
112 
type()113   FrameStateType type() const {
114     return info_ == nullptr ? FrameStateType::kInterpretedFunction
115                             : info_->type();
116   }
bailout_id()117   BailoutId bailout_id() const { return bailout_id_; }
state_combine()118   OutputFrameStateCombine state_combine() const { return frame_state_combine_; }
shared_info()119   MaybeHandle<SharedFunctionInfo> shared_info() const {
120     return info_ == nullptr ? MaybeHandle<SharedFunctionInfo>()
121                             : info_->shared_info();
122   }
parameter_count()123   int parameter_count() const {
124     return info_ == nullptr ? 0 : info_->parameter_count();
125   }
local_count()126   int local_count() const {
127     return info_ == nullptr ? 0 : info_->local_count();
128   }
function_info()129   const FrameStateFunctionInfo* function_info() const { return info_; }
130 
131  private:
132   BailoutId const bailout_id_;
133   OutputFrameStateCombine const frame_state_combine_;
134   const FrameStateFunctionInfo* const info_;
135 };
136 
137 bool operator==(FrameStateInfo const&, FrameStateInfo const&);
138 bool operator!=(FrameStateInfo const&, FrameStateInfo const&);
139 
140 size_t hash_value(FrameStateInfo const&);
141 
142 std::ostream& operator<<(std::ostream&, FrameStateInfo const&);
143 
144 static constexpr int kFrameStateParametersInput = 0;
145 static constexpr int kFrameStateLocalsInput = 1;
146 static constexpr int kFrameStateStackInput = 2;
147 static constexpr int kFrameStateContextInput = 3;
148 static constexpr int kFrameStateFunctionInput = 4;
149 static constexpr int kFrameStateOuterStateInput = 5;
150 static constexpr int kFrameStateInputCount = kFrameStateOuterStateInput + 1;
151 
152 enum class ContinuationFrameStateMode { EAGER, LAZY, LAZY_WITH_CATCH };
153 
154 FrameState CreateStubBuiltinContinuationFrameState(
155     JSGraph* graph, Builtins::Name name, Node* context, Node* const* parameters,
156     int parameter_count, Node* outer_frame_state,
157     ContinuationFrameStateMode mode);
158 
159 FrameState CreateJavaScriptBuiltinContinuationFrameState(
160     JSGraph* graph, const SharedFunctionInfoRef& shared, Builtins::Name name,
161     Node* target, Node* context, Node* const* stack_parameters,
162     int stack_parameter_count, Node* outer_frame_state,
163     ContinuationFrameStateMode mode);
164 
165 FrameState CreateGenericLazyDeoptContinuationFrameState(
166     JSGraph* graph, const SharedFunctionInfoRef& shared, Node* target,
167     Node* context, Node* receiver, Node* outer_frame_state);
168 
169 }  // namespace compiler
170 }  // namespace internal
171 }  // namespace v8
172 
173 #endif  // V8_COMPILER_FRAME_STATES_H_
174