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/compiler/osr.h" |
10 #include "src/scopes.h" | 11 #include "src/scopes.h" |
11 #include "src/x87/assembler-x87.h" | 12 #include "src/x87/assembler-x87.h" |
12 #include "src/x87/frames-x87.h" | 13 #include "src/x87/frames-x87.h" |
13 #include "src/x87/macro-assembler-x87.h" | 14 #include "src/x87/macro-assembler-x87.h" |
14 | 15 |
15 namespace v8 { | 16 namespace v8 { |
16 namespace internal { | 17 namespace internal { |
17 namespace compiler { | 18 namespace compiler { |
18 | 19 |
19 #define __ masm()-> | 20 #define __ masm()-> |
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1501 // | FP | RET | args | caller frame | | 1502 // | FP | RET | args | caller frame | |
1502 // ^ esp,ebp | 1503 // ^ esp,ebp |
1503 | 1504 |
1504 // --{ pop ebp }---------------------------------------------------------------- | 1505 // --{ pop ebp }---------------------------------------------------------------- |
1505 // | RET | args | caller frame | | 1506 // | RET | args | caller frame | |
1506 // ^ esp ^ ebp | 1507 // ^ esp ^ ebp |
1507 | 1508 |
1508 | 1509 |
1509 void CodeGenerator::AssemblePrologue() { | 1510 void CodeGenerator::AssemblePrologue() { |
1510 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1511 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1511 int stack_slots = frame()->GetSpillSlotCount(); | |
1512 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 1512 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
1513 // Assemble a prologue similar the to cdecl calling convention. | 1513 // Assemble a prologue similar the to cdecl calling convention. |
1514 __ push(ebp); | 1514 __ push(ebp); |
1515 __ mov(ebp, esp); | 1515 __ mov(ebp, esp); |
1516 const RegList saves = descriptor->CalleeSavedRegisters(); | |
1517 if (saves != 0) { // Save callee-saved registers. | |
1518 int register_save_area_size = 0; | |
1519 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { | |
1520 if (!((1 << i) & saves)) continue; | |
1521 __ push(Register::from_code(i)); | |
1522 register_save_area_size += kPointerSize; | |
1523 } | |
1524 frame()->SetRegisterSaveAreaSize(register_save_area_size); | |
1525 } | |
1526 } else if (descriptor->IsJSFunctionCall()) { | 1516 } else if (descriptor->IsJSFunctionCall()) { |
1527 // TODO(turbofan): this prologue is redundant with OSR, but needed for | 1517 // TODO(turbofan): this prologue is redundant with OSR, but needed for |
1528 // code aging. | 1518 // code aging. |
1529 CompilationInfo* info = this->info(); | 1519 CompilationInfo* info = this->info(); |
1530 __ Prologue(info->IsCodePreAgingActive()); | 1520 __ Prologue(info->IsCodePreAgingActive()); |
1531 frame()->SetRegisterSaveAreaSize( | |
1532 StandardFrameConstants::kFixedFrameSizeFromFp); | |
1533 } else if (needs_frame_) { | 1521 } else if (needs_frame_) { |
1534 __ StubPrologue(); | 1522 __ StubPrologue(); |
1535 frame()->SetRegisterSaveAreaSize( | 1523 } else { |
1536 StandardFrameConstants::kFixedFrameSizeFromFp); | 1524 frame()->SetElidedFrameSizeInSlots(kPCOnStackSize / kPointerSize); |
1537 } | 1525 } |
1538 | 1526 |
| 1527 int stack_shrink_slots = frame()->GetSpillSlotCount(); |
1539 if (info()->is_osr()) { | 1528 if (info()->is_osr()) { |
1540 // TurboFan OSR-compiled functions cannot be entered directly. | 1529 // TurboFan OSR-compiled functions cannot be entered directly. |
1541 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 1530 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
1542 | 1531 |
1543 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 1532 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
1544 // frame is still on the stack. Optimized code uses OSR values directly from | 1533 // frame is still on the stack. Optimized code uses OSR values directly from |
1545 // the unoptimized frame. Thus, all that needs to be done is to allocate the | 1534 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
1546 // remaining stack slots. | 1535 // remaining stack slots. |
1547 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 1536 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
1548 osr_pc_offset_ = __ pc_offset(); | 1537 osr_pc_offset_ = __ pc_offset(); |
1549 // TODO(titzer): cannot address target function == local #-1 | 1538 // TODO(titzer): cannot address target function == local #-1 |
1550 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); | 1539 __ mov(edi, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
1551 DCHECK(stack_slots >= frame()->GetOsrStackSlotCount()); | 1540 stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); |
1552 stack_slots -= frame()->GetOsrStackSlotCount(); | |
1553 } | 1541 } |
1554 | 1542 |
1555 if (stack_slots > 0) { | 1543 const RegList saves = descriptor->CalleeSavedRegisters(); |
1556 // Allocate the stack slots used by this frame. | 1544 if (stack_shrink_slots > 0) { |
1557 __ sub(esp, Immediate(stack_slots * kPointerSize)); | 1545 __ sub(esp, Immediate(stack_shrink_slots * kPointerSize)); |
| 1546 } |
| 1547 |
| 1548 if (saves != 0) { // Save callee-saved registers. |
| 1549 DCHECK(!info()->is_osr()); |
| 1550 int pushed = 0; |
| 1551 for (int i = Register::kNumRegisters - 1; i >= 0; i--) { |
| 1552 if (!((1 << i) & saves)) continue; |
| 1553 __ push(Register::from_code(i)); |
| 1554 ++pushed; |
| 1555 } |
| 1556 frame()->AllocateSavedCalleeRegisterSlots(pushed); |
1558 } | 1557 } |
1559 | 1558 |
1560 // Initailize FPU state. | 1559 // Initailize FPU state. |
1561 __ fninit(); | 1560 __ fninit(); |
1562 __ fld1(); | 1561 __ fld1(); |
1563 } | 1562 } |
1564 | 1563 |
1565 | 1564 |
1566 void CodeGenerator::AssembleReturn() { | 1565 void CodeGenerator::AssembleReturn() { |
1567 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1566 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1568 int stack_slots = frame()->GetSpillSlotCount(); | 1567 |
1569 int pop_count = static_cast<int>(descriptor->StackParameterCount()); | 1568 int pop_count = static_cast<int>(descriptor->StackParameterCount()); |
| 1569 const RegList saves = descriptor->CalleeSavedRegisters(); |
| 1570 // Restore registers. |
| 1571 if (saves != 0) { |
| 1572 for (int i = 0; i < Register::kNumRegisters; i++) { |
| 1573 if (!((1 << i) & saves)) continue; |
| 1574 __ pop(Register::from_code(i)); |
| 1575 } |
| 1576 } |
| 1577 |
1570 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 1578 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
1571 const RegList saves = descriptor->CalleeSavedRegisters(); | 1579 __ mov(esp, ebp); // Move stack pointer back to frame pointer. |
1572 if (frame()->GetRegisterSaveAreaSize() > 0) { | 1580 __ pop(ebp); // Pop caller's frame pointer. |
1573 // Remove this frame's spill slots first. | |
1574 if (stack_slots > 0) { | |
1575 __ add(esp, Immediate(stack_slots * kPointerSize)); | |
1576 } | |
1577 // Restore registers. | |
1578 if (saves != 0) { | |
1579 for (int i = 0; i < Register::kNumRegisters; i++) { | |
1580 if (!((1 << i) & saves)) continue; | |
1581 __ pop(Register::from_code(i)); | |
1582 } | |
1583 } | |
1584 __ pop(ebp); // Pop caller's frame pointer. | |
1585 } else { | |
1586 // No saved registers. | |
1587 __ mov(esp, ebp); // Move stack pointer back to frame pointer. | |
1588 __ pop(ebp); // Pop caller's frame pointer. | |
1589 } | |
1590 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { | 1581 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { |
1591 // Canonicalize JSFunction return sites for now. | 1582 // Canonicalize JSFunction return sites for now. |
1592 if (return_label_.is_bound()) { | 1583 if (return_label_.is_bound()) { |
1593 __ jmp(&return_label_); | 1584 __ jmp(&return_label_); |
1594 return; | 1585 return; |
1595 } else { | 1586 } else { |
1596 __ bind(&return_label_); | 1587 __ bind(&return_label_); |
1597 __ mov(esp, ebp); // Move stack pointer back to frame pointer. | 1588 __ mov(esp, ebp); // Move stack pointer back to frame pointer. |
1598 __ pop(ebp); // Pop caller's frame pointer. | 1589 __ pop(ebp); // Pop caller's frame pointer. |
1599 } | 1590 } |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1835 __ Nop(padding_size); | 1826 __ Nop(padding_size); |
1836 } | 1827 } |
1837 } | 1828 } |
1838 } | 1829 } |
1839 | 1830 |
1840 #undef __ | 1831 #undef __ |
1841 | 1832 |
1842 } // namespace compiler | 1833 } // namespace compiler |
1843 } // namespace internal | 1834 } // namespace internal |
1844 } // namespace v8 | 1835 } // namespace v8 |
OLD | NEW |