OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 | 6 |
7 #include "src/compiler/code-generator-impl.h" | 7 #include "src/compiler/code-generator-impl.h" |
8 #include "src/compiler/gap-resolver.h" | 8 #include "src/compiler/gap-resolver.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 Constant constant = ToConstant(operand); | 41 Constant constant = ToConstant(operand); |
42 if (constant.type() == Constant::kFloat64) { | 42 if (constant.type() == Constant::kFloat64) { |
43 DCHECK_EQ(0, bit_cast<int64_t>(constant.ToFloat64())); | 43 DCHECK_EQ(0, bit_cast<int64_t>(constant.ToFloat64())); |
44 return Immediate(0); | 44 return Immediate(0); |
45 } | 45 } |
46 return Immediate(constant.ToInt32()); | 46 return Immediate(constant.ToInt32()); |
47 } | 47 } |
48 | 48 |
49 Operand ToOperand(InstructionOperand* op, int extra = 0) { | 49 Operand ToOperand(InstructionOperand* op, int extra = 0) { |
50 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot()); | 50 DCHECK(op->IsStackSlot() || op->IsDoubleStackSlot()); |
51 FrameOffset offset = | 51 // The linkage computes where all spill slots are located. |
52 linkage()->GetFrameOffset(AllocatedOperand::cast(op)->index(), frame()); | 52 FrameOffset offset = linkage()->GetFrameOffset( |
53 return Operand(offset.from_stack_pointer() ? rsp : rbp, | 53 AllocatedOperand::cast(op)->index(), frame(), extra); |
54 offset.offset() + extra); | 54 return Operand(offset.from_stack_pointer() ? rsp : rbp, offset.offset()); |
55 } | 55 } |
56 | 56 |
57 static size_t NextOffset(size_t* offset) { | 57 static size_t NextOffset(size_t* offset) { |
58 size_t i = *offset; | 58 size_t i = *offset; |
59 (*offset)++; | 59 (*offset)++; |
60 return i; | 60 return i; |
61 } | 61 } |
62 | 62 |
63 static ScaleFactor ScaleFor(AddressingMode one, AddressingMode mode) { | 63 static ScaleFactor ScaleFor(AddressingMode one, AddressingMode mode) { |
64 STATIC_ASSERT(0 == static_cast<int>(times_1)); | 64 STATIC_ASSERT(0 == static_cast<int>(times_1)); |
(...skipping 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 break; | 1212 break; |
1213 case kX64Inc32: | 1213 case kX64Inc32: |
1214 __ incl(i.OutputRegister()); | 1214 __ incl(i.OutputRegister()); |
1215 break; | 1215 break; |
1216 case kX64Push: | 1216 case kX64Push: |
1217 if (HasImmediateInput(instr, 0)) { | 1217 if (HasImmediateInput(instr, 0)) { |
1218 __ pushq(i.InputImmediate(0)); | 1218 __ pushq(i.InputImmediate(0)); |
1219 } else { | 1219 } else { |
1220 if (instr->InputAt(0)->IsRegister()) { | 1220 if (instr->InputAt(0)->IsRegister()) { |
1221 __ pushq(i.InputRegister(0)); | 1221 __ pushq(i.InputRegister(0)); |
1222 } else if (instr->InputAt(0)->IsDoubleRegister()) { | |
1223 // TODO(titzer): use another machine instruction? | |
1224 __ subq(rsp, Immediate(kDoubleSize)); | |
1225 __ movsd(Operand(rsp, 0), i.InputDoubleRegister(0)); | |
1226 } else { | 1222 } else { |
1227 __ pushq(i.InputOperand(0)); | 1223 __ pushq(i.InputOperand(0)); |
1228 } | 1224 } |
1229 } | 1225 } |
1230 break; | 1226 break; |
1231 case kX64Poke: { | 1227 case kX64Poke: { |
1232 int const slot = MiscField::decode(instr->opcode()); | 1228 int const slot = MiscField::decode(instr->opcode()); |
1233 if (HasImmediateInput(instr, 0)) { | 1229 if (HasImmediateInput(instr, 0)) { |
1234 __ movq(Operand(rsp, slot * kPointerSize), i.InputImmediate(0)); | 1230 __ movq(Operand(rsp, slot * kPointerSize), i.InputImmediate(0)); |
1235 } else { | 1231 } else { |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1551 __ addp(rsp, Immediate(stack_size)); | 1547 __ addp(rsp, Immediate(stack_size)); |
1552 } | 1548 } |
1553 const RegList saves = descriptor->CalleeSavedRegisters(); | 1549 const RegList saves = descriptor->CalleeSavedRegisters(); |
1554 if (saves != 0) { | 1550 if (saves != 0) { |
1555 for (int i = 0; i < Register::kNumRegisters; i++) { | 1551 for (int i = 0; i < Register::kNumRegisters; i++) { |
1556 if (!((1 << i) & saves)) continue; | 1552 if (!((1 << i) & saves)) continue; |
1557 __ popq(Register::from_code(i)); | 1553 __ popq(Register::from_code(i)); |
1558 } | 1554 } |
1559 } | 1555 } |
1560 __ popq(rbp); // Pop caller's frame pointer. | 1556 __ popq(rbp); // Pop caller's frame pointer. |
| 1557 __ ret(0); |
1561 } else { | 1558 } else { |
1562 // No saved registers. | 1559 // No saved registers. |
1563 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 1560 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. |
1564 __ popq(rbp); // Pop caller's frame pointer. | 1561 __ popq(rbp); // Pop caller's frame pointer. |
| 1562 __ ret(0); |
1565 } | 1563 } |
1566 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { | 1564 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { |
1567 // Canonicalize JSFunction return sites for now. | 1565 // Canonicalize JSFunction return sites for now. |
1568 if (return_label_.is_bound()) { | 1566 if (return_label_.is_bound()) { |
1569 __ jmp(&return_label_); | 1567 __ jmp(&return_label_); |
1570 return; | |
1571 } else { | 1568 } else { |
1572 __ bind(&return_label_); | 1569 __ bind(&return_label_); |
1573 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. | 1570 __ movq(rsp, rbp); // Move stack pointer back to frame pointer. |
1574 __ popq(rbp); // Pop caller's frame pointer. | 1571 __ popq(rbp); // Pop caller's frame pointer. |
| 1572 int pop_count = static_cast<int>(descriptor->StackParameterCount()); |
| 1573 if (pop_count == 0) { |
| 1574 __ Ret(); |
| 1575 } else { |
| 1576 __ Ret(pop_count * kPointerSize, rbx); |
| 1577 } |
1575 } | 1578 } |
| 1579 } else { |
| 1580 __ Ret(); |
1576 } | 1581 } |
1577 size_t pop_size = descriptor->StackParameterCount() * kPointerSize; | |
1578 // Might need rcx for scratch if pop_size is too big. | |
1579 DCHECK_EQ(0, descriptor->CalleeSavedRegisters() & rcx.bit()); | |
1580 __ Ret(static_cast<int>(pop_size), rcx); | |
1581 } | 1582 } |
1582 | 1583 |
1583 | 1584 |
1584 void CodeGenerator::AssembleMove(InstructionOperand* source, | 1585 void CodeGenerator::AssembleMove(InstructionOperand* source, |
1585 InstructionOperand* destination) { | 1586 InstructionOperand* destination) { |
1586 X64OperandConverter g(this, NULL); | 1587 X64OperandConverter g(this, NULL); |
1587 // Dispatch on the source and destination operand kinds. Not all | 1588 // Dispatch on the source and destination operand kinds. Not all |
1588 // combinations are possible. | 1589 // combinations are possible. |
1589 if (source->IsRegister()) { | 1590 if (source->IsRegister()) { |
1590 DCHECK(destination->IsRegister() || destination->IsStackSlot()); | 1591 DCHECK(destination->IsRegister() || destination->IsStackSlot()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 __ Nop(padding_size); | 1769 __ Nop(padding_size); |
1769 } | 1770 } |
1770 } | 1771 } |
1771 } | 1772 } |
1772 | 1773 |
1773 #undef __ | 1774 #undef __ |
1774 | 1775 |
1775 } // namespace internal | 1776 } // namespace internal |
1776 } // namespace compiler | 1777 } // namespace compiler |
1777 } // namespace v8 | 1778 } // namespace v8 |
OLD | NEW |