OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/raw-machine-assembler.h" | 5 #include "src/compiler/raw-machine-assembler.h" |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/compiler/node-properties.h" |
8 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
9 #include "src/compiler/scheduler.h" | 10 #include "src/compiler/scheduler.h" |
10 | 11 |
11 namespace v8 { | 12 namespace v8 { |
12 namespace internal { | 13 namespace internal { |
13 namespace compiler { | 14 namespace compiler { |
14 | 15 |
15 RawMachineAssembler::RawMachineAssembler(Isolate* isolate, Graph* graph, | 16 RawMachineAssembler::RawMachineAssembler(Isolate* isolate, Graph* graph, |
16 CallDescriptor* call_descriptor, | 17 CallDescriptor* call_descriptor, |
17 MachineType word, | 18 MachineType word, |
18 MachineOperatorBuilder::Flags flags) | 19 MachineOperatorBuilder::Flags flags) |
19 : isolate_(isolate), | 20 : isolate_(isolate), |
20 graph_(graph), | 21 graph_(graph), |
21 schedule_(new (zone()) Schedule(zone())), | 22 schedule_(new (zone()) Schedule(zone())), |
22 machine_(zone(), word, flags), | 23 machine_(zone(), word, flags), |
23 common_(zone()), | 24 common_(zone()), |
24 call_descriptor_(call_descriptor), | 25 call_descriptor_(call_descriptor), |
25 parameters_(parameter_count(), zone()), | 26 parameters_(parameter_count(), zone()), |
26 current_block_(schedule()->start()) { | 27 current_block_(schedule()->start()) { |
27 int param_count = static_cast<int>(parameter_count()); | 28 int param_count = static_cast<int>(parameter_count()); |
28 // Add an extra input for the JSFunction parameter to the start node. | 29 // Add an extra input for the JSFunction parameter to the start node. |
29 graph->SetStart(graph->NewNode(common_.Start(param_count + 1))); | 30 graph->SetStart(graph->NewNode(common_.Start(param_count + 1))); |
30 for (size_t i = 0; i < parameter_count(); ++i) { | 31 for (size_t i = 0; i < parameter_count(); ++i) { |
31 parameters_[i] = | 32 parameters_[i] = |
32 AddNode(common()->Parameter(static_cast<int>(i)), graph->start()); | 33 AddNode(common()->Parameter(static_cast<int>(i)), graph->start()); |
33 } | 34 } |
| 35 graph->SetEnd(graph->NewNode(common_.End(0))); |
34 } | 36 } |
35 | 37 |
36 | 38 |
37 Schedule* RawMachineAssembler::Export() { | 39 Schedule* RawMachineAssembler::Export() { |
38 // Compute the correct codegen order. | 40 // Compute the correct codegen order. |
39 DCHECK(schedule_->rpo_order()->empty()); | 41 DCHECK(schedule_->rpo_order()->empty()); |
40 Scheduler::ComputeSpecialRPO(zone(), schedule_); | 42 Scheduler::ComputeSpecialRPO(zone(), schedule_); |
41 // Invalidate RawMachineAssembler. | 43 // Invalidate RawMachineAssembler. |
42 Schedule* schedule = schedule_; | 44 Schedule* schedule = schedule_; |
43 schedule_ = nullptr; | 45 schedule_ = nullptr; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 int input_count = param_count + 3; | 207 int input_count = param_count + 3; |
206 Node** buffer = zone()->NewArray<Node*>(input_count); | 208 Node** buffer = zone()->NewArray<Node*>(input_count); |
207 int index = 0; | 209 int index = 0; |
208 buffer[index++] = function; | 210 buffer[index++] = function; |
209 for (int i = 0; i < param_count; i++) { | 211 for (int i = 0; i < param_count; i++) { |
210 buffer[index++] = args[i]; | 212 buffer[index++] = args[i]; |
211 } | 213 } |
212 buffer[index++] = graph()->start(); | 214 buffer[index++] = graph()->start(); |
213 buffer[index++] = graph()->start(); | 215 buffer[index++] = graph()->start(); |
214 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); | 216 Node* tail_call = MakeNode(common()->TailCall(desc), input_count, buffer); |
| 217 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
215 schedule()->AddTailCall(CurrentBlock(), tail_call); | 218 schedule()->AddTailCall(CurrentBlock(), tail_call); |
216 current_block_ = nullptr; | 219 current_block_ = nullptr; |
217 return tail_call; | 220 return tail_call; |
218 } | 221 } |
219 | 222 |
220 | 223 |
221 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, | 224 Node* RawMachineAssembler::TailCallRuntime1(Runtime::FunctionId function, |
222 Node* arg1, Node* context) { | 225 Node* arg1, Node* context) { |
223 const int kArity = 1; | 226 const int kArity = 1; |
224 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 227 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
225 zone(), function, kArity, Operator::kNoProperties, | 228 zone(), function, kArity, Operator::kNoProperties, |
226 CallDescriptor::kSupportsTailCalls); | 229 CallDescriptor::kSupportsTailCalls); |
227 | 230 |
228 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 231 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
229 Node* ref = AddNode( | 232 Node* ref = AddNode( |
230 common()->ExternalConstant(ExternalReference(function, isolate()))); | 233 common()->ExternalConstant(ExternalReference(function, isolate()))); |
231 Node* arity = Int32Constant(kArity); | 234 Node* arity = Int32Constant(kArity); |
232 | 235 |
233 Node* nodes[] = {centry, arg1, ref, arity, context, graph()->start(), | 236 Node* nodes[] = {centry, arg1, ref, arity, context, graph()->start(), |
234 graph()->start()}; | 237 graph()->start()}; |
235 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | 238 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
236 | 239 |
| 240 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
237 schedule()->AddTailCall(CurrentBlock(), tail_call); | 241 schedule()->AddTailCall(CurrentBlock(), tail_call); |
238 current_block_ = nullptr; | 242 current_block_ = nullptr; |
239 return tail_call; | 243 return tail_call; |
240 } | 244 } |
241 | 245 |
242 | 246 |
243 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, | 247 Node* RawMachineAssembler::TailCallRuntime2(Runtime::FunctionId function, |
244 Node* arg1, Node* arg2, | 248 Node* arg1, Node* arg2, |
245 Node* context) { | 249 Node* context) { |
246 const int kArity = 2; | 250 const int kArity = 2; |
247 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( | 251 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
248 zone(), function, kArity, Operator::kNoProperties, | 252 zone(), function, kArity, Operator::kNoProperties, |
249 CallDescriptor::kSupportsTailCalls); | 253 CallDescriptor::kSupportsTailCalls); |
250 | 254 |
251 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); | 255 Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode()); |
252 Node* ref = AddNode( | 256 Node* ref = AddNode( |
253 common()->ExternalConstant(ExternalReference(function, isolate()))); | 257 common()->ExternalConstant(ExternalReference(function, isolate()))); |
254 Node* arity = Int32Constant(kArity); | 258 Node* arity = Int32Constant(kArity); |
255 | 259 |
256 Node* nodes[] = { | 260 Node* nodes[] = { |
257 centry, arg1, arg2, ref, arity, context, graph()->start(), | 261 centry, arg1, arg2, ref, arity, context, graph()->start(), |
258 graph()->start()}; | 262 graph()->start()}; |
259 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | 263 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
260 | 264 |
| 265 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
261 schedule()->AddTailCall(CurrentBlock(), tail_call); | 266 schedule()->AddTailCall(CurrentBlock(), tail_call); |
262 current_block_ = nullptr; | 267 current_block_ = nullptr; |
263 return tail_call; | 268 return tail_call; |
264 } | 269 } |
265 | 270 |
266 | 271 |
267 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 272 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
268 Node* function) { | 273 Node* function) { |
269 MachineSignature::Builder builder(zone(), 1, 0); | 274 MachineSignature::Builder builder(zone(), 1, 0); |
270 builder.AddReturn(return_type); | 275 builder.AddReturn(return_type); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 390 |
386 RawMachineLabel::RawMachineLabel() | 391 RawMachineLabel::RawMachineLabel() |
387 : block_(NULL), used_(false), bound_(false) {} | 392 : block_(NULL), used_(false), bound_(false) {} |
388 | 393 |
389 | 394 |
390 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } | 395 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } |
391 | 396 |
392 } // namespace compiler | 397 } // namespace compiler |
393 } // namespace internal | 398 } // namespace internal |
394 } // namespace v8 | 399 } // namespace v8 |
OLD | NEW |