Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Side by Side Diff: src/compiler/ppc/instruction-selector-ppc.cc

Issue 1114193003: PPC: [turbofan] Fix tail call optimization. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/base/adapters.h" 5 #include "src/base/adapters.h"
6 #include "src/compiler/instruction-selector-impl.h" 6 #include "src/compiler/instruction-selector-impl.h"
7 #include "src/compiler/node-matchers.h" 7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties.h" 8 #include "src/compiler/node-properties.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 VisitFloat64Compare(this, node, &cont); 1427 VisitFloat64Compare(this, node, &cont);
1428 } 1428 }
1429 1429
1430 1430
1431 void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { 1431 void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) {
1432 FlagsContinuation cont(kUnsignedLessThanOrEqual, node); 1432 FlagsContinuation cont(kUnsignedLessThanOrEqual, node);
1433 VisitFloat64Compare(this, node, &cont); 1433 VisitFloat64Compare(this, node, &cont);
1434 } 1434 }
1435 1435
1436 1436
1437 void InstructionSelector::VisitCall(Node* node, BasicBlock* handler, 1437 void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
1438 CallMode call_mode) {
1439 PPCOperandGenerator g(this); 1438 PPCOperandGenerator g(this);
1440 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node); 1439 const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node);
1441 1440
1442 FrameStateDescriptor* frame_state_descriptor = NULL; 1441 FrameStateDescriptor* frame_state_descriptor = nullptr;
1443 if (descriptor->NeedsFrameState()) { 1442 if (descriptor->NeedsFrameState()) {
1444 frame_state_descriptor = 1443 frame_state_descriptor =
1445 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount())); 1444 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount()));
1446 } 1445 }
1447 1446
1448 CallBuffer buffer(zone(), descriptor, frame_state_descriptor); 1447 CallBuffer buffer(zone(), descriptor, frame_state_descriptor);
1449 1448
1450 // Compute InstructionOperands for inputs and outputs. 1449 // Compute InstructionOperands for inputs and outputs.
1451 // TODO(turbofan): on PPC it's probably better to use the code object in a 1450 // TODO(turbofan): on PPC it's probably better to use the code object in a
1452 // register if there are multiple uses of it. Improve constant pool and the 1451 // register if there are multiple uses of it. Improve constant pool and the
1453 // heuristics in the register allocator for where to emit constants. 1452 // heuristics in the register allocator for where to emit constants.
1454 InitializeCallBuffer(node, &buffer, true, false); 1453 InitializeCallBuffer(node, &buffer, true, false);
1455 1454
1456 // Push any stack arguments. 1455 // Push any stack arguments.
1457 // TODO(mbrandy): reverse order and use push only for first 1456 // TODO(mbrandy): reverse order and use push only for first
1458 for (Node* node : base::Reversed(buffer.pushed_nodes)) { 1457 for (Node* node : base::Reversed(buffer.pushed_nodes)) {
1459 Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node)); 1458 Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node));
1460 } 1459 }
1461 1460
1462 // Pass label of exception handler block. 1461 // Pass label of exception handler block.
1463 CallDescriptor::Flags flags = descriptor->flags(); 1462 CallDescriptor::Flags flags = descriptor->flags();
1464 if (handler != nullptr) { 1463 if (handler) {
1465 flags |= CallDescriptor::kHasExceptionHandler; 1464 flags |= CallDescriptor::kHasExceptionHandler;
1466 buffer.instruction_args.push_back(g.Label(handler)); 1465 buffer.instruction_args.push_back(g.Label(handler));
1467 } 1466 }
1468 1467
1469 // Select the appropriate opcode based on the call type. 1468 // Select the appropriate opcode based on the call type.
1470 bool is_tail_call = call_mode == TAIL_CALL;
1471 InstructionCode opcode; 1469 InstructionCode opcode;
1472 switch (descriptor->kind()) { 1470 switch (descriptor->kind()) {
1473 case CallDescriptor::kCallCodeObject: { 1471 case CallDescriptor::kCallCodeObject: {
1474 opcode = is_tail_call ? kArchTailCallCodeObject : kArchCallCodeObject; 1472 opcode = kArchCallCodeObject;
1475 break; 1473 break;
1476 } 1474 }
1477 case CallDescriptor::kCallJSFunction: 1475 case CallDescriptor::kCallJSFunction:
1478 opcode = is_tail_call ? kArchTailCallJSFunction : kArchCallJSFunction; 1476 opcode = kArchCallJSFunction;
1479 break; 1477 break;
1480 default: 1478 default:
1481 UNREACHABLE(); 1479 UNREACHABLE();
1482 return; 1480 return;
1483 } 1481 }
1484 opcode |= MiscField::encode(flags); 1482 opcode |= MiscField::encode(flags);
1485 1483
1486 // Emit the call instruction. 1484 // Emit the call instruction.
1487 size_t size = is_tail_call ? 0 : buffer.outputs.size(); 1485 size_t const output_count = buffer.outputs.size();
1488 InstructionOperand* first_output = 1486 auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
1489 size > 0 ? &buffer.outputs.front() : nullptr; 1487 Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
1490 Instruction* call_instr = 1488 &buffer.instruction_args.front())->MarkAsCall();
1491 Emit(opcode, size, first_output, buffer.instruction_args.size(),
1492 &buffer.instruction_args.front());
1493 call_instr->MarkAsCall();
1494 } 1489 }
1495 1490
1496 1491
1492 void InstructionSelector::VisitTailCall(Node* node) {
1493 PPCOperandGenerator g(this);
1494 CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node);
1495 DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls);
1496 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite);
1497 DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall);
1498
1499 // TODO(turbofan): Relax restriction for stack parameters.
1500 if (descriptor->UsesOnlyRegisters() &&
1501 descriptor->HasSameReturnLocationsAs(
1502 linkage()->GetIncomingDescriptor())) {
1503 CallBuffer buffer(zone(), descriptor, nullptr);
1504
1505 // Compute InstructionOperands for inputs and outputs.
1506 // TODO(turbofan): on PPC it's probably better to use the code object in a
1507 // register if there are multiple uses of it. Improve constant pool and the
1508 // heuristics in the register allocator for where to emit constants.
1509 InitializeCallBuffer(node, &buffer, true, false);
1510
1511 DCHECK_EQ(0u, buffer.pushed_nodes.size());
1512
1513 // Select the appropriate opcode based on the call type.
1514 InstructionCode opcode;
1515 switch (descriptor->kind()) {
1516 case CallDescriptor::kCallCodeObject:
1517 opcode = kArchTailCallCodeObject;
1518 break;
1519 case CallDescriptor::kCallJSFunction:
1520 opcode = kArchTailCallJSFunction;
1521 break;
1522 default:
1523 UNREACHABLE();
1524 return;
1525 }
1526 opcode |= MiscField::encode(descriptor->flags());
1527
1528 // Emit the tailcall instruction.
1529 Emit(opcode, 0, nullptr, buffer.instruction_args.size(),
1530 &buffer.instruction_args.front());
1531 } else {
1532 FrameStateDescriptor* frame_state_descriptor = nullptr;
1533 if (descriptor->NeedsFrameState()) {
1534 frame_state_descriptor =
1535 GetFrameStateDescriptor(node->InputAt(descriptor->InputCount()));
1536 }
1537
1538 CallBuffer buffer(zone(), descriptor, frame_state_descriptor);
1539
1540 // Compute InstructionOperands for inputs and outputs.
1541 // TODO(turbofan): on PPC it's probably better to use the code object in a
1542 // register if there are multiple uses of it. Improve constant pool and the
1543 // heuristics in the register allocator for where to emit constants.
1544 InitializeCallBuffer(node, &buffer, true, false);
1545
1546 // Push any stack arguments.
1547 for (Node* node : base::Reversed(buffer.pushed_nodes)) {
1548 Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node));
1549 }
1550
1551 // Select the appropriate opcode based on the call type.
1552 InstructionCode opcode;
1553 switch (descriptor->kind()) {
1554 case CallDescriptor::kCallCodeObject: {
1555 opcode = kArchCallCodeObject;
1556 break;
1557 }
1558 case CallDescriptor::kCallJSFunction:
1559 opcode = kArchCallJSFunction;
1560 break;
1561 default:
1562 UNREACHABLE();
1563 return;
1564 }
1565 opcode |= MiscField::encode(descriptor->flags());
1566
1567 // Emit the call instruction.
1568 size_t const output_count = buffer.outputs.size();
1569 auto* outputs = output_count ? &buffer.outputs.front() : nullptr;
1570 Emit(opcode, output_count, outputs, buffer.instruction_args.size(),
1571 &buffer.instruction_args.front())->MarkAsCall();
1572 Emit(kArchRet, 0, nullptr, output_count, outputs);
1573 }
1574 }
1575
1576
1497 void InstructionSelector::VisitFloat64ExtractLowWord32(Node* node) { 1577 void InstructionSelector::VisitFloat64ExtractLowWord32(Node* node) {
1498 PPCOperandGenerator g(this); 1578 PPCOperandGenerator g(this);
1499 Emit(kPPC_DoubleExtractLowWord32, g.DefineAsRegister(node), 1579 Emit(kPPC_DoubleExtractLowWord32, g.DefineAsRegister(node),
1500 g.UseRegister(node->InputAt(0))); 1580 g.UseRegister(node->InputAt(0)));
1501 } 1581 }
1502 1582
1503 1583
1504 void InstructionSelector::VisitFloat64ExtractHighWord32(Node* node) { 1584 void InstructionSelector::VisitFloat64ExtractHighWord32(Node* node) {
1505 PPCOperandGenerator g(this); 1585 PPCOperandGenerator g(this);
1506 Emit(kPPC_DoubleExtractHighWord32, g.DefineAsRegister(node), 1586 Emit(kPPC_DoubleExtractHighWord32, g.DefineAsRegister(node),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 MachineOperatorBuilder::kFloat64Min | 1631 MachineOperatorBuilder::kFloat64Min |
1552 MachineOperatorBuilder::kFloat64RoundDown | 1632 MachineOperatorBuilder::kFloat64RoundDown |
1553 MachineOperatorBuilder::kFloat64RoundTruncate | 1633 MachineOperatorBuilder::kFloat64RoundTruncate |
1554 MachineOperatorBuilder::kFloat64RoundTiesAway; 1634 MachineOperatorBuilder::kFloat64RoundTiesAway;
1555 // We omit kWord32ShiftIsSafe as s[rl]w use 0x3f as a mask rather than 0x1f. 1635 // We omit kWord32ShiftIsSafe as s[rl]w use 0x3f as a mask rather than 0x1f.
1556 } 1636 }
1557 1637
1558 } // namespace compiler 1638 } // namespace compiler
1559 } // namespace internal 1639 } // namespace internal
1560 } // namespace v8 1640 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698