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 #include "src/compiler/frame-states.h" | 5 #include "src/compiler/frame-states.h" |
6 | 6 |
7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
| 8 #include "src/callable.h" |
| 9 #include "src/compiler/graph.h" |
| 10 #include "src/compiler/js-graph.h" |
| 11 #include "src/compiler/node.h" |
8 #include "src/handles-inl.h" | 12 #include "src/handles-inl.h" |
9 #include "src/objects-inl.h" | 13 #include "src/objects-inl.h" |
10 | 14 |
11 namespace v8 { | 15 namespace v8 { |
12 namespace internal { | 16 namespace internal { |
13 namespace compiler { | 17 namespace compiler { |
14 | 18 |
15 size_t hash_value(OutputFrameStateCombine const& sc) { | 19 size_t hash_value(OutputFrameStateCombine const& sc) { |
16 return base::hash_combine(sc.kind_, sc.parameter_); | 20 return base::hash_combine(sc.kind_, sc.parameter_); |
17 } | 21 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 break; | 61 break; |
58 case FrameStateType::kArgumentsAdaptor: | 62 case FrameStateType::kArgumentsAdaptor: |
59 os << "ARGUMENTS_ADAPTOR"; | 63 os << "ARGUMENTS_ADAPTOR"; |
60 break; | 64 break; |
61 case FrameStateType::kTailCallerFunction: | 65 case FrameStateType::kTailCallerFunction: |
62 os << "TAIL_CALLER_FRAME"; | 66 os << "TAIL_CALLER_FRAME"; |
63 break; | 67 break; |
64 case FrameStateType::kConstructStub: | 68 case FrameStateType::kConstructStub: |
65 os << "CONSTRUCT_STUB"; | 69 os << "CONSTRUCT_STUB"; |
66 break; | 70 break; |
| 71 case FrameStateType::kBuiltinContinuation: |
| 72 os << "BUILTIN_CONTINUATION_FRAME"; |
| 73 break; |
| 74 case FrameStateType::kJavaScriptBuiltinContinuation: |
| 75 os << "JAVA_SCRIPT_BUILTIN_CONTINUATION_FRAME"; |
| 76 break; |
67 case FrameStateType::kGetterStub: | 77 case FrameStateType::kGetterStub: |
68 os << "GETTER_STUB"; | 78 os << "GETTER_STUB"; |
69 break; | 79 break; |
70 case FrameStateType::kSetterStub: | 80 case FrameStateType::kSetterStub: |
71 os << "SETTER_STUB"; | 81 os << "SETTER_STUB"; |
72 break; | 82 break; |
73 } | 83 } |
74 return os; | 84 return os; |
75 } | 85 } |
76 | 86 |
77 | 87 |
78 std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) { | 88 std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) { |
79 os << info.type() << ", " << info.bailout_id() << ", " | 89 os << info.type() << ", " << info.bailout_id() << ", " |
80 << info.state_combine(); | 90 << info.state_combine(); |
81 Handle<SharedFunctionInfo> shared_info; | 91 Handle<SharedFunctionInfo> shared_info; |
82 if (info.shared_info().ToHandle(&shared_info)) { | 92 if (info.shared_info().ToHandle(&shared_info)) { |
83 os << ", " << Brief(*shared_info); | 93 os << ", " << Brief(*shared_info); |
84 } | 94 } |
85 return os; | 95 return os; |
86 } | 96 } |
87 | 97 |
| 98 namespace { |
| 99 Node* CreateBuiltinContinuationFrameStateCommon( |
| 100 JSGraph* js_graph, Builtins::Name name, Node* context, Node** parameters, |
| 101 int parameter_count, Node* outer_frame_state, Handle<JSFunction> function) { |
| 102 Isolate* isolate = js_graph->isolate(); |
| 103 Graph* graph = js_graph->graph(); |
| 104 CommonOperatorBuilder* common = js_graph->common(); |
| 105 |
| 106 BailoutId bailout_id = Builtins::GetContinuationBailoutId(name); |
| 107 Callable callable = Builtins::CallableFor(isolate, name); |
| 108 |
| 109 const Operator* op_param = |
| 110 common->StateValues(parameter_count, SparseInputMask::Dense()); |
| 111 Node* params_node = graph->NewNode(op_param, parameter_count, parameters); |
| 112 |
| 113 FrameStateType frame_type = |
| 114 function.is_null() ? FrameStateType::kBuiltinContinuation |
| 115 : FrameStateType::kJavaScriptBuiltinContinuation; |
| 116 Handle<SharedFunctionInfo> shared( |
| 117 Handle<SharedFunctionInfo>(function->shared())); |
| 118 const FrameStateFunctionInfo* state_info = |
| 119 common->CreateFrameStateFunctionInfo(frame_type, parameter_count, 0, |
| 120 shared); |
| 121 const Operator* op = common->FrameState( |
| 122 bailout_id, OutputFrameStateCombine::Ignore(), state_info); |
| 123 |
| 124 Node* function_node = function.is_null() ? js_graph->UndefinedConstant() |
| 125 : js_graph->HeapConstant(function); |
| 126 |
| 127 Node* frame_state = graph->NewNode( |
| 128 op, params_node, js_graph->EmptyStateValues(), |
| 129 js_graph->EmptyStateValues(), context, function_node, outer_frame_state); |
| 130 |
| 131 return frame_state; |
| 132 } |
| 133 } // namespace |
| 134 |
| 135 Node* CreateStubBuiltinContinuationFrameState(JSGraph* js_graph, |
| 136 Builtins::Name name, |
| 137 Node* context, Node** parameters, |
| 138 int parameter_count, |
| 139 Node* outer_frame_state, |
| 140 ContinuationFrameStateMode mode) { |
| 141 Isolate* isolate = js_graph->isolate(); |
| 142 Callable callable = Builtins::CallableFor(isolate, name); |
| 143 CallInterfaceDescriptor descriptor = callable.descriptor(); |
| 144 |
| 145 std::vector<Node*> actual_parameters; |
| 146 // Stack parameters first |
| 147 for (int i = 0; i < descriptor.GetStackParameterCount(); ++i) { |
| 148 actual_parameters.push_back( |
| 149 parameters[descriptor.GetRegisterParameterCount() + i]); |
| 150 } |
| 151 // Register parameters follow, context will be added by instruction selector |
| 152 // during FrameState translation. |
| 153 for (int i = 0; i < descriptor.GetRegisterParameterCount(); ++i) { |
| 154 actual_parameters.push_back(parameters[i]); |
| 155 } |
| 156 |
| 157 return CreateBuiltinContinuationFrameStateCommon( |
| 158 js_graph, name, context, &actual_parameters[0], |
| 159 static_cast<int>(actual_parameters.size()), outer_frame_state, |
| 160 Handle<JSFunction>()); |
| 161 } |
| 162 |
| 163 Node* CreateJavaScriptBuiltinContinuationFrameState( |
| 164 JSGraph* js_graph, Handle<JSFunction> function, Builtins::Name name, |
| 165 Node* target, Node* context, Node** stack_parameters, |
| 166 int stack_parameter_count, Node* outer_frame_state, |
| 167 ContinuationFrameStateMode mode) { |
| 168 Isolate* isolate = js_graph->isolate(); |
| 169 Callable callable = Builtins::CallableFor(isolate, name); |
| 170 |
| 171 // Lazy deopt points where the frame state is assocated with a call get an |
| 172 // additional parameter for the return result from the call that's added by |
| 173 // the deoptimizer and not explicitly specified in the frame state. Check that |
| 174 // there is not a mismatch between the number of frame state parameters and |
| 175 // the stack parameters required by the builtin taking this into account. |
| 176 DCHECK_EQ( |
| 177 Builtins::GetStackParameterCount(isolate, name) + 1, // add receiver |
| 178 stack_parameter_count + |
| 179 (mode == ContinuationFrameStateMode::EAGER ? 0 : 1)); |
| 180 |
| 181 Node* argc = |
| 182 js_graph->Constant(stack_parameter_count - |
| 183 (mode == ContinuationFrameStateMode::EAGER ? 1 : 0)); |
| 184 |
| 185 // Stack parameters first. They must be first because the receiver is expected |
| 186 // to be the second value in the translation when creating stack crawls |
| 187 // (e.g. Error.stack) of optimized JavaScript frames. |
| 188 std::vector<Node*> actual_parameters; |
| 189 for (int i = 0; i < stack_parameter_count; ++i) { |
| 190 actual_parameters.push_back(stack_parameters[i]); |
| 191 } |
| 192 |
| 193 // Register parameters follow stack paraemters. The context will be added by |
| 194 // instruction selector during FrameState translation. |
| 195 actual_parameters.push_back(target); |
| 196 actual_parameters.push_back(js_graph->UndefinedConstant()); |
| 197 actual_parameters.push_back(argc); |
| 198 |
| 199 return CreateBuiltinContinuationFrameStateCommon( |
| 200 js_graph, name, context, &actual_parameters[0], |
| 201 static_cast<int>(actual_parameters.size()), outer_frame_state, function); |
| 202 } |
| 203 |
88 } // namespace compiler | 204 } // namespace compiler |
89 } // namespace internal | 205 } // namespace internal |
90 } // namespace v8 | 206 } // namespace v8 |
OLD | NEW |