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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 break; | 62 break; |
59 case FrameStateType::kArgumentsAdaptor: | 63 case FrameStateType::kArgumentsAdaptor: |
60 os << "ARGUMENTS_ADAPTOR"; | 64 os << "ARGUMENTS_ADAPTOR"; |
61 break; | 65 break; |
62 case FrameStateType::kTailCallerFunction: | 66 case FrameStateType::kTailCallerFunction: |
63 os << "TAIL_CALLER_FRAME"; | 67 os << "TAIL_CALLER_FRAME"; |
64 break; | 68 break; |
65 case FrameStateType::kConstructStub: | 69 case FrameStateType::kConstructStub: |
66 os << "CONSTRUCT_STUB"; | 70 os << "CONSTRUCT_STUB"; |
67 break; | 71 break; |
| 72 case FrameStateType::kBuiltinContinuation: |
| 73 os << "BUILTIN_CONTINUATION_FRAME"; |
| 74 break; |
68 case FrameStateType::kGetterStub: | 75 case FrameStateType::kGetterStub: |
69 os << "GETTER_STUB"; | 76 os << "GETTER_STUB"; |
70 break; | 77 break; |
71 case FrameStateType::kSetterStub: | 78 case FrameStateType::kSetterStub: |
72 os << "SETTER_STUB"; | 79 os << "SETTER_STUB"; |
73 break; | 80 break; |
74 } | 81 } |
75 return os; | 82 return os; |
76 } | 83 } |
77 | 84 |
78 | 85 |
79 std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) { | 86 std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) { |
80 os << info.type() << ", " << info.bailout_id() << ", " | 87 os << info.type() << ", " << info.bailout_id() << ", " |
81 << info.state_combine(); | 88 << info.state_combine(); |
82 Handle<SharedFunctionInfo> shared_info; | 89 Handle<SharedFunctionInfo> shared_info; |
83 if (info.shared_info().ToHandle(&shared_info)) { | 90 if (info.shared_info().ToHandle(&shared_info)) { |
84 os << ", " << Brief(*shared_info); | 91 os << ", " << Brief(*shared_info); |
85 } | 92 } |
86 return os; | 93 return os; |
87 } | 94 } |
88 | 95 |
| 96 namespace { |
| 97 std::pair<Node*, Node*> CreateBuiltinContinuationFrameStateCommon( |
| 98 JSGraph* js_graph, Builtins::Name name, Node** parameters, |
| 99 int parameter_count, Node* effect, Node* control, Node* outer_frame_state, |
| 100 CheckpointMode mode, Handle<SharedFunctionInfo> shared) { |
| 101 Isolate* isolate = js_graph->isolate(); |
| 102 Graph* graph = js_graph->graph(); |
| 103 CommonOperatorBuilder* common = js_graph->common(); |
| 104 |
| 105 BailoutId bailout_id = Builtins::GetContinuationBailoutId(name); |
| 106 Callable callable = Builtins::CallableFor(isolate, name); |
| 107 |
| 108 const Operator* op_param = |
| 109 common->StateValues(parameter_count, SparseInputMask::Dense()); |
| 110 Node* params_node = graph->NewNode(op_param, parameter_count, parameters); |
| 111 |
| 112 const FrameStateFunctionInfo* state_info = |
| 113 common->CreateFrameStateFunctionInfo(FrameStateType::kBuiltinContinuation, |
| 114 parameter_count, 0, shared); |
| 115 const Operator* op = common->FrameState( |
| 116 bailout_id, OutputFrameStateCombine::Ignore(), state_info); |
| 117 const Operator* op0 = common->StateValues(0, SparseInputMask::Dense()); |
| 118 Node* node0 = graph->NewNode(op0); |
| 119 |
| 120 Node* frame_state = graph->NewNode( |
| 121 op, params_node, node0, node0, js_graph->UndefinedConstant(), |
| 122 js_graph->UndefinedConstant(), outer_frame_state); |
| 123 |
| 124 return std::make_pair( |
| 125 frame_state, |
| 126 mode == CREATE_CHECKPOINT |
| 127 ? graph->NewNode(common->Checkpoint(), frame_state, effect, control) |
| 128 : effect); |
| 129 } |
| 130 |
| 131 } // namespace |
| 132 |
| 133 std::pair<Node*, Node*> CreateStubBuiltinContinuationFrameState( |
| 134 JSGraph* js_graph, Builtins::Name name, Node* context, Node** parameters, |
| 135 int parameter_count, Node* effect, Node* control, Node* outer_frame_state, |
| 136 CheckpointMode mode) { |
| 137 Isolate* isolate = js_graph->isolate(); |
| 138 Callable callable = Builtins::CallableFor(isolate, name); |
| 139 CallInterfaceDescriptor descriptor = callable.descriptor(); |
| 140 |
| 141 std::vector<Node*> actual_parameters; |
| 142 if (descriptor.GetRegisterParameterCount() == 0) { |
| 143 actual_parameters.push_back(context); |
| 144 } |
| 145 for (int i = 0; i < parameter_count; ++i) { |
| 146 actual_parameters.push_back(parameters[i]); |
| 147 if (i == descriptor.GetRegisterParameterCount() - 1) { |
| 148 actual_parameters.push_back(context); |
| 149 } |
| 150 } |
| 151 |
| 152 return CreateBuiltinContinuationFrameStateCommon( |
| 153 js_graph, name, &actual_parameters[0], |
| 154 static_cast<int>(actual_parameters.size()), effect, control, |
| 155 outer_frame_state, mode, Handle<SharedFunctionInfo>()); |
| 156 } |
| 157 |
| 158 std::pair<Node*, Node*> CreateJavaScriptBuiltinContinuationFrameState( |
| 159 JSGraph* js_graph, Handle<SharedFunctionInfo> shared, Builtins::Name name, |
| 160 Node* target, Node* context, Node** stack_parameters, |
| 161 int stack_parameter_count, Node* effect, Node* control, |
| 162 Node* outer_frame_state, CheckpointMode mode) { |
| 163 Isolate* isolate = js_graph->isolate(); |
| 164 Callable callable = Builtins::CallableFor(isolate, name); |
| 165 |
| 166 // Lazy deopt points where the frame state is assocated with a call get an |
| 167 // additional parameter for the return result from the call that's added by |
| 168 // the deoptimizer and not explicitly specified in the frame state. Check that |
| 169 // there is not a mismatch between the number of frame state parameters and |
| 170 // the stack parameters required by the builtin taking this into account. |
| 171 DCHECK_EQ( |
| 172 Builtins::GetStackParameterCount(isolate, name) + 1, // add receiver |
| 173 stack_parameter_count + (mode == CREATE_CHECKPOINT ? 0 : 1)); |
| 174 |
| 175 std::vector<Node*> actual_parameters; |
| 176 // target |
| 177 actual_parameters.push_back(target); |
| 178 // new target |
| 179 actual_parameters.push_back(js_graph->UndefinedConstant()); |
| 180 // argc, remove receiver and add in return value for lazy deopts from calls |
| 181 actual_parameters.push_back(js_graph->Constant( |
| 182 stack_parameter_count - (mode == CREATE_CHECKPOINT ? 1 : 0))); |
| 183 // context |
| 184 actual_parameters.push_back(context); |
| 185 |
| 186 for (int i = 0; i < stack_parameter_count; ++i) { |
| 187 actual_parameters.push_back(stack_parameters[i]); |
| 188 } |
| 189 |
| 190 return CreateBuiltinContinuationFrameStateCommon( |
| 191 js_graph, name, &actual_parameters[0], |
| 192 static_cast<int>(actual_parameters.size()), effect, control, |
| 193 outer_frame_state, mode, shared); |
| 194 } |
| 195 |
89 } // namespace compiler | 196 } // namespace compiler |
90 } // namespace internal | 197 } // namespace internal |
91 } // namespace v8 | 198 } // namespace v8 |
OLD | NEW |