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/node-properties.h" |
9 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
10 #include "src/compiler/scheduler.h" | 10 #include "src/compiler/scheduler.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void RawMachineAssembler::Goto(RawMachineLabel* label) { | 56 void RawMachineAssembler::Goto(RawMachineLabel* label) { |
57 DCHECK(current_block_ != schedule()->end()); | 57 DCHECK(current_block_ != schedule()->end()); |
58 schedule()->AddGoto(CurrentBlock(), Use(label)); | 58 schedule()->AddGoto(CurrentBlock(), Use(label)); |
59 current_block_ = nullptr; | 59 current_block_ = nullptr; |
60 } | 60 } |
61 | 61 |
62 | 62 |
63 void RawMachineAssembler::Branch(Node* condition, RawMachineLabel* true_val, | 63 void RawMachineAssembler::Branch(Node* condition, RawMachineLabel* true_val, |
64 RawMachineLabel* false_val) { | 64 RawMachineLabel* false_val) { |
65 DCHECK(current_block_ != schedule()->end()); | 65 DCHECK(current_block_ != schedule()->end()); |
66 Node* branch = AddNode(common()->Branch(), condition); | 66 Node* branch = MakeNode(common()->Branch(), 1, &condition); |
67 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val)); | 67 schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val)); |
68 current_block_ = nullptr; | 68 current_block_ = nullptr; |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 void RawMachineAssembler::Switch(Node* index, RawMachineLabel* default_label, | 72 void RawMachineAssembler::Switch(Node* index, RawMachineLabel* default_label, |
73 int32_t* case_values, | 73 int32_t* case_values, |
74 RawMachineLabel** case_labels, | 74 RawMachineLabel** case_labels, |
75 size_t case_count) { | 75 size_t case_count) { |
76 DCHECK_NE(schedule()->end(), current_block_); | 76 DCHECK_NE(schedule()->end(), current_block_); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 | 259 |
260 Node* nodes[] = {centry, arg1, arg2, ref, arity, context}; | 260 Node* nodes[] = {centry, arg1, arg2, ref, arity, context}; |
261 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); | 261 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
262 | 262 |
263 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); | 263 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
264 schedule()->AddTailCall(CurrentBlock(), tail_call); | 264 schedule()->AddTailCall(CurrentBlock(), tail_call); |
265 current_block_ = nullptr; | 265 current_block_ = nullptr; |
266 return tail_call; | 266 return tail_call; |
267 } | 267 } |
268 | 268 |
| 269 Node* RawMachineAssembler::TailCallRuntime3(Runtime::FunctionId function, |
| 270 Node* arg1, Node* arg2, Node* arg3, |
| 271 Node* context) { |
| 272 const int kArity = 3; |
| 273 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 274 zone(), function, kArity, Operator::kNoProperties, |
| 275 CallDescriptor::kSupportsTailCalls); |
| 276 int return_count = static_cast<int>(desc->ReturnCount()); |
| 277 |
| 278 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); |
| 279 Node* ref = AddNode( |
| 280 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 281 Node* arity = Int32Constant(kArity); |
| 282 |
| 283 Node* nodes[] = {centry, arg1, arg2, arg3, ref, arity, context}; |
| 284 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
| 285 |
| 286 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
| 287 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 288 current_block_ = nullptr; |
| 289 return tail_call; |
| 290 } |
| 291 |
| 292 Node* RawMachineAssembler::TailCallRuntime4(Runtime::FunctionId function, |
| 293 Node* arg1, Node* arg2, Node* arg3, |
| 294 Node* arg4, Node* context) { |
| 295 const int kArity = 4; |
| 296 CallDescriptor* desc = Linkage::GetRuntimeCallDescriptor( |
| 297 zone(), function, kArity, Operator::kNoProperties, |
| 298 CallDescriptor::kSupportsTailCalls); |
| 299 int return_count = static_cast<int>(desc->ReturnCount()); |
| 300 |
| 301 Node* centry = HeapConstant(CEntryStub(isolate(), return_count).GetCode()); |
| 302 Node* ref = AddNode( |
| 303 common()->ExternalConstant(ExternalReference(function, isolate()))); |
| 304 Node* arity = Int32Constant(kArity); |
| 305 |
| 306 Node* nodes[] = {centry, arg1, arg2, arg3, arg4, ref, arity, context}; |
| 307 Node* tail_call = MakeNode(common()->TailCall(desc), arraysize(nodes), nodes); |
| 308 |
| 309 NodeProperties::MergeControlToEnd(graph(), common(), tail_call); |
| 310 schedule()->AddTailCall(CurrentBlock(), tail_call); |
| 311 current_block_ = nullptr; |
| 312 return tail_call; |
| 313 } |
269 | 314 |
270 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, | 315 Node* RawMachineAssembler::CallCFunction0(MachineType return_type, |
271 Node* function) { | 316 Node* function) { |
272 MachineSignature::Builder builder(zone(), 1, 0); | 317 MachineSignature::Builder builder(zone(), 1, 0); |
273 builder.AddReturn(return_type); | 318 builder.AddReturn(return_type); |
274 const CallDescriptor* descriptor = | 319 const CallDescriptor* descriptor = |
275 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); | 320 Linkage::GetSimplifiedCDescriptor(zone(), builder.Build()); |
276 | 321 |
277 return AddNode(common()->Call(descriptor), function); | 322 return AddNode(common()->Call(descriptor), function); |
278 } | 323 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock(); | 392 if (label->block_ == nullptr) label->block_ = schedule()->NewBasicBlock(); |
348 return label->block_; | 393 return label->block_; |
349 } | 394 } |
350 | 395 |
351 | 396 |
352 BasicBlock* RawMachineAssembler::CurrentBlock() { | 397 BasicBlock* RawMachineAssembler::CurrentBlock() { |
353 DCHECK(current_block_); | 398 DCHECK(current_block_); |
354 return current_block_; | 399 return current_block_; |
355 } | 400 } |
356 | 401 |
| 402 Node* RawMachineAssembler::Phi(MachineRepresentation rep, int input_count, |
| 403 Node* const* inputs) { |
| 404 Node** buffer = new (zone()->New(sizeof(Node*) * (input_count + 1))) |
| 405 Node*[input_count + 1]; |
| 406 std::copy(inputs, inputs + input_count, buffer); |
| 407 buffer[input_count] = graph()->start(); |
| 408 return AddNode(common()->Phi(rep, input_count), input_count + 1, buffer); |
| 409 } |
| 410 |
| 411 void RawMachineAssembler::AppendPhiInput(Node* phi, Node* new_input) { |
| 412 const Operator* op = phi->op(); |
| 413 const Operator* new_op = common()->ResizeMergeOrPhi(op, phi->InputCount()); |
| 414 phi->InsertInput(zone(), phi->InputCount() - 1, new_input); |
| 415 NodeProperties::ChangeOp(phi, new_op); |
| 416 } |
357 | 417 |
358 Node* RawMachineAssembler::AddNode(const Operator* op, int input_count, | 418 Node* RawMachineAssembler::AddNode(const Operator* op, int input_count, |
359 Node** inputs) { | 419 Node* const* inputs) { |
360 DCHECK_NOT_NULL(schedule_); | 420 DCHECK_NOT_NULL(schedule_); |
361 DCHECK_NOT_NULL(current_block_); | 421 DCHECK_NOT_NULL(current_block_); |
362 Node* node = MakeNode(op, input_count, inputs); | 422 Node* node = MakeNode(op, input_count, inputs); |
363 schedule()->AddNode(CurrentBlock(), node); | 423 schedule()->AddNode(CurrentBlock(), node); |
364 return node; | 424 return node; |
365 } | 425 } |
366 | 426 |
367 | |
368 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count, | 427 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count, |
369 Node** inputs) { | 428 Node* const* inputs) { |
370 // The raw machine assembler nodes do not have effect and control inputs, | 429 // The raw machine assembler nodes do not have effect and control inputs, |
371 // so we disable checking input counts here. | 430 // so we disable checking input counts here. |
372 return graph()->NewNodeUnchecked(op, input_count, inputs); | 431 return graph()->NewNodeUnchecked(op, input_count, inputs); |
373 } | 432 } |
374 | 433 |
375 | 434 |
376 RawMachineLabel::RawMachineLabel() | 435 RawMachineLabel::RawMachineLabel() |
377 : block_(nullptr), used_(false), bound_(false) {} | 436 : block_(nullptr), used_(false), bound_(false) {} |
378 | 437 |
379 | 438 |
380 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } | 439 RawMachineLabel::~RawMachineLabel() { DCHECK(bound_ || !used_); } |
381 | 440 |
382 } // namespace compiler | 441 } // namespace compiler |
383 } // namespace internal | 442 } // namespace internal |
384 } // namespace v8 | 443 } // namespace v8 |
OLD | NEW |