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