Commit 81a1530e authored by mtrofin's avatar mtrofin Committed by Commit bot

[turbofan] CodeGenerator: Frame setup refactoring

Before frame elision, we finalized the frame shape when assembling the
prologue, which is also when we prepared the frame (saving sp, etc).

The frame finalization only needs to happen once, and happens to be
actually a set of idempotent operations. With frame elision, the logic for
frame finalization was happening every time we constructed the frame.
Albeit idempotent operations, the code would become hard to maintain.

This change separates frame shape finalization from frame
construction. When constructing the CodeGenerator, we finalize the
frame. Subsequent access is to a const Frame*.

Also renamed AssemblePrologue to AssembleConstructFrame, as
suggested in the frame elision CR.

Separating frame setup gave the opportunity to do away with
architecture-independent frame aligning (which is something just arm64
cares about), and also with stack pointer setup (also arm64). Both of
these happen now at frame finalization on arm64.

BUG=

Review URL: https://codereview.chromium.org/1843143002

Cr-Commit-Position: refs/heads/master@{#35642}
parent b94e9d88
...@@ -399,8 +399,6 @@ void CodeGenerator::AssembleDeconstructFrame() { ...@@ -399,8 +399,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ LeaveFrame(StackFrame::MANUAL); __ LeaveFrame(StackFrame::MANUAL);
} }
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
...@@ -1346,8 +1344,34 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1346,8 +1344,34 @@ void CodeGenerator::AssembleDeoptimizerCall(
__ CheckConstPool(false, false); __ CheckConstPool(false, false);
} }
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
if (saves_fp != 0) {
frame->AlignSavedCalleeRegisterSlots();
}
if (saves_fp != 0) {
// Save callee-saved FP registers.
STATIC_ASSERT(DwVfpRegister::kMaxNumRegisters == 32);
uint32_t last = base::bits::CountLeadingZeros32(saves_fp) - 1;
uint32_t first = base::bits::CountTrailingZeros32(saves_fp);
DCHECK_EQ((last - first + 1), base::bits::CountPopulation32(saves_fp));
frame->AllocateSavedCalleeRegisterSlots((last - first + 1) *
(kDoubleSize / kPointerSize));
}
const RegList saves = FLAG_enable_embedded_constant_pool
? (descriptor->CalleeSavedRegisters() & ~pp.bit())
: descriptor->CalleeSavedRegisters();
if (saves != 0) {
// Save callee-saved registers.
frame->AllocateSavedCalleeRegisterSlots(
base::bits::CountPopulation32(saves));
}
}
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
...@@ -1366,7 +1390,8 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1366,7 +1390,8 @@ void CodeGenerator::AssemblePrologue() {
} }
} }
int stack_shrink_slots = frame()->GetSpillSlotCount(); int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1377,15 +1402,12 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1377,15 +1402,12 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
} }
const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
if (saves_fp != 0) { if (shrink_slots > 0) {
stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); __ sub(sp, sp, Operand(shrink_slots * kPointerSize));
}
if (stack_shrink_slots > 0) {
__ sub(sp, sp, Operand(stack_shrink_slots * kPointerSize));
} }
if (saves_fp != 0) { if (saves_fp != 0) {
...@@ -1396,8 +1418,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1396,8 +1418,6 @@ void CodeGenerator::AssemblePrologue() {
DCHECK_EQ((last - first + 1), base::bits::CountPopulation32(saves_fp)); DCHECK_EQ((last - first + 1), base::bits::CountPopulation32(saves_fp));
__ vstm(db_w, sp, DwVfpRegister::from_code(first), __ vstm(db_w, sp, DwVfpRegister::from_code(first),
DwVfpRegister::from_code(last)); DwVfpRegister::from_code(last));
frame()->AllocateSavedCalleeRegisterSlots((last - first + 1) *
(kDoubleSize / kPointerSize));
} }
const RegList saves = FLAG_enable_embedded_constant_pool const RegList saves = FLAG_enable_embedded_constant_pool
? (descriptor->CalleeSavedRegisters() & ~pp.bit()) ? (descriptor->CalleeSavedRegisters() & ~pp.bit())
...@@ -1405,8 +1425,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1405,8 +1425,6 @@ void CodeGenerator::AssemblePrologue() {
if (saves != 0) { if (saves != 0) {
// Save callee-saved registers. // Save callee-saved registers.
__ stm(db_w, sp, saves); __ stm(db_w, sp, saves);
frame()->AllocateSavedCalleeRegisterSlots(
base::bits::CountPopulation32(saves));
} }
} }
......
...@@ -1539,22 +1539,40 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1539,22 +1539,40 @@ void CodeGenerator::AssembleDeoptimizerCall(
__ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
} }
void CodeGenerator::AssembleSetupStackPointer() { void CodeGenerator::FinishFrame(Frame* frame) {
const CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); frame->AlignFrame(16);
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (descriptor->UseNativeStack() || descriptor->IsCFunctionCall()) { if (descriptor->UseNativeStack() || descriptor->IsCFunctionCall()) {
__ SetStackPointer(csp); __ SetStackPointer(csp);
} else { } else {
__ SetStackPointer(jssp); __ SetStackPointer(jssp);
} }
// Save FP registers.
CPURegList saves_fp = CPURegList(CPURegister::kFPRegister, kDRegSizeInBits,
descriptor->CalleeSavedFPRegisters());
int saved_count = saves_fp.Count();
if (saved_count != 0) {
DCHECK(saves_fp.list() == CPURegList::GetCalleeSavedFP().list());
frame->AllocateSavedCalleeRegisterSlots(saved_count *
(kDoubleSize / kPointerSize));
}
CPURegList saves = CPURegList(CPURegister::kRegister, kXRegSizeInBits,
descriptor->CalleeSavedRegisters());
saved_count = saves.Count();
if (saved_count != 0) {
frame->AllocateSavedCalleeRegisterSlots(saved_count);
}
} }
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (descriptor->UseNativeStack()) { if (descriptor->UseNativeStack()) {
__ AssertCspAligned(); __ AssertCspAligned();
} }
int stack_shrink_slots = frame()->GetSpillSlotCount();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsJSFunctionCall()) { if (descriptor->IsJSFunctionCall()) {
DCHECK(!descriptor->UseNativeStack()); DCHECK(!descriptor->UseNativeStack());
...@@ -1563,7 +1581,7 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1563,7 +1581,7 @@ void CodeGenerator::AssemblePrologue() {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
__ Push(lr, fp); __ Push(lr, fp);
__ Mov(fp, masm_.StackPointer()); __ Mov(fp, masm_.StackPointer());
__ Claim(stack_shrink_slots); __ Claim(frame()->GetSpillSlotCount());
} else { } else {
__ StubPrologue(info()->GetOutputStackFrameType(), __ StubPrologue(info()->GetOutputStackFrameType(),
frame()->GetTotalFrameSlotCount()); frame()->GetTotalFrameSlotCount());
...@@ -1571,6 +1589,8 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1571,6 +1589,8 @@ void CodeGenerator::AssemblePrologue() {
} }
} }
int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1581,11 +1601,11 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1581,11 +1601,11 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
} }
if (descriptor->IsJSFunctionCall()) { if (descriptor->IsJSFunctionCall()) {
__ Claim(stack_shrink_slots); __ Claim(shrink_slots);
} }
// Save FP registers. // Save FP registers.
...@@ -1595,8 +1615,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1595,8 +1615,6 @@ void CodeGenerator::AssemblePrologue() {
if (saved_count != 0) { if (saved_count != 0) {
DCHECK(saves_fp.list() == CPURegList::GetCalleeSavedFP().list()); DCHECK(saves_fp.list() == CPURegList::GetCalleeSavedFP().list());
__ PushCPURegList(saves_fp); __ PushCPURegList(saves_fp);
frame()->AllocateSavedCalleeRegisterSlots(saved_count *
(kDoubleSize / kPointerSize));
} }
// Save registers. // Save registers.
// TODO(palfia): TF save list is not in sync with // TODO(palfia): TF save list is not in sync with
...@@ -1607,7 +1625,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1607,7 +1625,6 @@ void CodeGenerator::AssemblePrologue() {
saved_count = saves.Count(); saved_count = saves.Count();
if (saved_count != 0) { if (saved_count != 0) {
__ PushCPURegList(saves); __ PushCPURegList(saves);
frame()->AllocateSavedCalleeRegisterSlots(saved_count);
} }
} }
......
...@@ -127,7 +127,7 @@ class InstructionOperandConverter { ...@@ -127,7 +127,7 @@ class InstructionOperandConverter {
return ToConstant(op).ToHeapObject(); return ToConstant(op).ToHeapObject();
} }
Frame* frame() const { return gen_->frame(); } const Frame* frame() const { return gen_->frame(); }
FrameAccessState* frame_access_state() const { FrameAccessState* frame_access_state() const {
return gen_->frame_access_state(); return gen_->frame_access_state();
} }
...@@ -163,7 +163,7 @@ class OutOfLineCode : public ZoneObject { ...@@ -163,7 +163,7 @@ class OutOfLineCode : public ZoneObject {
Label* entry() { return &entry_; } Label* entry() { return &entry_; }
Label* exit() { return &exit_; } Label* exit() { return &exit_; }
Frame* frame() const { return frame_; } const Frame* frame() const { return frame_; }
Isolate* isolate() const { return masm()->isolate(); } Isolate* isolate() const { return masm()->isolate(); }
MacroAssembler* masm() const { return masm_; } MacroAssembler* masm() const { return masm_; }
OutOfLineCode* next() const { return next_; } OutOfLineCode* next() const { return next_; }
...@@ -171,7 +171,7 @@ class OutOfLineCode : public ZoneObject { ...@@ -171,7 +171,7 @@ class OutOfLineCode : public ZoneObject {
private: private:
Label entry_; Label entry_;
Label exit_; Label exit_;
Frame* const frame_; const Frame* const frame_;
MacroAssembler* const masm_; MacroAssembler* const masm_;
OutOfLineCode* const next_; OutOfLineCode* const next_;
}; };
......
...@@ -33,7 +33,7 @@ class CodeGenerator::JumpTable final : public ZoneObject { ...@@ -33,7 +33,7 @@ class CodeGenerator::JumpTable final : public ZoneObject {
CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
InstructionSequence* code, CompilationInfo* info) InstructionSequence* code, CompilationInfo* info)
: frame_access_state_(new (code->zone()) FrameAccessState(frame)), : frame_access_state_(nullptr),
linkage_(linkage), linkage_(linkage),
code_(code), code_(code),
info_(info), info_(info),
...@@ -56,6 +56,12 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, ...@@ -56,6 +56,12 @@ CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage,
for (int i = 0; i < code->InstructionBlockCount(); ++i) { for (int i = 0; i < code->InstructionBlockCount(); ++i) {
new (&labels_[i]) Label; new (&labels_[i]) Label;
} }
CreateFrameAccessState(frame);
}
void CodeGenerator::CreateFrameAccessState(Frame* frame) {
FinishFrame(frame);
frame_access_state_ = new (code()->zone()) FrameAccessState(frame);
} }
Handle<Code> CodeGenerator::GenerateCode() { Handle<Code> CodeGenerator::GenerateCode() {
...@@ -96,9 +102,6 @@ Handle<Code> CodeGenerator::GenerateCode() { ...@@ -96,9 +102,6 @@ Handle<Code> CodeGenerator::GenerateCode() {
} }
} }
// Finish the Frame
frame()->AlignFrame(kFrameAlignmentInBytes);
AssembleSetupStackPointer();
// Assemble all non-deferred blocks, followed by deferred ones. // Assemble all non-deferred blocks, followed by deferred ones.
for (int deferred = 0; deferred < 2; ++deferred) { for (int deferred = 0; deferred < 2; ++deferred) {
for (const InstructionBlock* block : code()->instruction_blocks()) { for (const InstructionBlock* block : code()->instruction_blocks()) {
...@@ -143,7 +146,7 @@ Handle<Code> CodeGenerator::GenerateCode() { ...@@ -143,7 +146,7 @@ Handle<Code> CodeGenerator::GenerateCode() {
masm()->bind(GetLabel(current_block_)); masm()->bind(GetLabel(current_block_));
if (block->must_construct_frame()) { if (block->must_construct_frame()) {
AssemblePrologue(); AssembleConstructFrame();
// We need to setup the root register after we assemble the prologue, to // We need to setup the root register after we assemble the prologue, to
// avoid clobbering callee saved registers in case of C linkage and // avoid clobbering callee saved registers in case of C linkage and
// using the roots. // using the roots.
......
...@@ -54,7 +54,7 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -54,7 +54,7 @@ class CodeGenerator final : public GapResolver::Assembler {
InstructionSequence* code() const { return code_; } InstructionSequence* code() const { return code_; }
FrameAccessState* frame_access_state() const { return frame_access_state_; } FrameAccessState* frame_access_state() const { return frame_access_state_; }
Frame* frame() const { return frame_access_state_->frame(); } const Frame* frame() const { return frame_access_state_->frame(); }
Isolate* isolate() const { return info_->isolate(); } Isolate* isolate() const { return info_->isolate(); }
Linkage* linkage() const { return linkage_; } Linkage* linkage() const { return linkage_; }
...@@ -67,6 +67,12 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -67,6 +67,12 @@ class CodeGenerator final : public GapResolver::Assembler {
Zone* zone() const { return code()->zone(); } Zone* zone() const { return code()->zone(); }
CompilationInfo* info() const { return info_; } CompilationInfo* info() const { return info_; }
// Create the FrameAccessState object. The Frame is immutable from here on.
void CreateFrameAccessState(Frame* frame);
// Architecture - specific frame finalization.
void FinishFrame(Frame* frame);
// Checks if {block} will appear directly after {current_block_} when // Checks if {block} will appear directly after {current_block_} when
// assembling code, in which case, a fall-through can be used. // assembling code, in which case, a fall-through can be used.
bool IsNextInAssemblyOrder(RpoNumber block) const; bool IsNextInAssemblyOrder(RpoNumber block) const;
...@@ -108,9 +114,7 @@ class CodeGenerator final : public GapResolver::Assembler { ...@@ -108,9 +114,7 @@ class CodeGenerator final : public GapResolver::Assembler {
// Generates an architecture-specific, descriptor-specific prologue // Generates an architecture-specific, descriptor-specific prologue
// to set up a stack frame. // to set up a stack frame.
void AssemblePrologue(); void AssembleConstructFrame();
void AssembleSetupStackPointer();
// Generates an architecture-specific, descriptor-specific return sequence // Generates an architecture-specific, descriptor-specific return sequence
// to tear down a stack frame. // to tear down a stack frame.
......
...@@ -14,13 +14,11 @@ namespace compiler { ...@@ -14,13 +14,11 @@ namespace compiler {
Frame::Frame(int fixed_frame_size_in_slots) Frame::Frame(int fixed_frame_size_in_slots)
: frame_slot_count_(fixed_frame_size_in_slots), : frame_slot_count_(fixed_frame_size_in_slots),
callee_saved_slot_count_(0),
spill_slot_count_(0), spill_slot_count_(0),
allocated_registers_(nullptr), allocated_registers_(nullptr),
allocated_double_registers_(nullptr) {} allocated_double_registers_(nullptr) {}
int Frame::AlignFrame(int alignment) { int Frame::AlignFrame(int alignment) {
DCHECK_EQ(0, callee_saved_slot_count_);
int alignment_slots = alignment / kPointerSize; int alignment_slots = alignment / kPointerSize;
int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1)); int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
if (delta != alignment_slots) { if (delta != alignment_slots) {
......
...@@ -82,9 +82,6 @@ class Frame : public ZoneObject { ...@@ -82,9 +82,6 @@ class Frame : public ZoneObject {
inline int GetTotalFrameSlotCount() const { return frame_slot_count_; } inline int GetTotalFrameSlotCount() const { return frame_slot_count_; }
inline int GetSavedCalleeRegisterSlotCount() const {
return callee_saved_slot_count_;
}
inline int GetSpillSlotCount() const { return spill_slot_count_; } inline int GetSpillSlotCount() const { return spill_slot_count_; }
void SetAllocatedRegisters(BitVector* regs) { void SetAllocatedRegisters(BitVector* regs) {
...@@ -101,23 +98,20 @@ class Frame : public ZoneObject { ...@@ -101,23 +98,20 @@ class Frame : public ZoneObject {
return !allocated_double_registers_->IsEmpty(); return !allocated_double_registers_->IsEmpty();
} }
int AlignSavedCalleeRegisterSlots(int alignment = kDoubleSize) { void AlignSavedCalleeRegisterSlots(int alignment = kDoubleSize) {
DCHECK_EQ(0, callee_saved_slot_count_);
int alignment_slots = alignment / kPointerSize; int alignment_slots = alignment / kPointerSize;
int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1)); int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
if (delta != alignment_slots) { if (delta != alignment_slots) {
frame_slot_count_ += delta; frame_slot_count_ += delta;
} }
return delta; spill_slot_count_ += delta;
} }
void AllocateSavedCalleeRegisterSlots(int count) { void AllocateSavedCalleeRegisterSlots(int count) {
frame_slot_count_ += count; frame_slot_count_ += count;
callee_saved_slot_count_ += count;
} }
int AllocateSpillSlot(int width) { int AllocateSpillSlot(int width) {
DCHECK_EQ(0, callee_saved_slot_count_);
int frame_slot_count_before = frame_slot_count_; int frame_slot_count_before = frame_slot_count_;
int slot = AllocateAlignedFrameSlot(width); int slot = AllocateAlignedFrameSlot(width);
spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before); spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before);
...@@ -127,7 +121,6 @@ class Frame : public ZoneObject { ...@@ -127,7 +121,6 @@ class Frame : public ZoneObject {
int AlignFrame(int alignment = kDoubleSize); int AlignFrame(int alignment = kDoubleSize);
int ReserveSpillSlots(size_t slot_count) { int ReserveSpillSlots(size_t slot_count) {
DCHECK_EQ(0, callee_saved_slot_count_);
DCHECK_EQ(0, spill_slot_count_); DCHECK_EQ(0, spill_slot_count_);
spill_slot_count_ += static_cast<int>(slot_count); spill_slot_count_ += static_cast<int>(slot_count);
frame_slot_count_ += static_cast<int>(slot_count); frame_slot_count_ += static_cast<int>(slot_count);
...@@ -151,7 +144,6 @@ class Frame : public ZoneObject { ...@@ -151,7 +144,6 @@ class Frame : public ZoneObject {
private: private:
int frame_slot_count_; int frame_slot_count_;
int callee_saved_slot_count_;
int spill_slot_count_; int spill_slot_count_;
BitVector* allocated_registers_; BitVector* allocated_registers_;
BitVector* allocated_double_registers_; BitVector* allocated_double_registers_;
...@@ -190,13 +182,13 @@ class FrameOffset { ...@@ -190,13 +182,13 @@ class FrameOffset {
// current function's frame. // current function's frame.
class FrameAccessState : public ZoneObject { class FrameAccessState : public ZoneObject {
public: public:
explicit FrameAccessState(Frame* const frame) explicit FrameAccessState(const Frame* const frame)
: frame_(frame), : frame_(frame),
access_frame_with_fp_(false), access_frame_with_fp_(false),
sp_delta_(0), sp_delta_(0),
has_frame_(false) {} has_frame_(false) {}
Frame* frame() const { return frame_; } const Frame* frame() const { return frame_; }
void MarkHasFrame(bool state); void MarkHasFrame(bool state);
int sp_delta() const { return sp_delta_; } int sp_delta() const { return sp_delta_; }
...@@ -228,7 +220,7 @@ class FrameAccessState : public ZoneObject { ...@@ -228,7 +220,7 @@ class FrameAccessState : public ZoneObject {
FrameOffset GetFrameOffset(int spill_slot) const; FrameOffset GetFrameOffset(int spill_slot) const;
private: private:
Frame* const frame_; const Frame* const frame_;
bool access_frame_with_fp_; bool access_frame_with_fp_;
int sp_delta_; int sp_delta_;
bool has_frame_; bool has_frame_;
......
...@@ -367,8 +367,6 @@ void CodeGenerator::AssembleDeconstructFrame() { ...@@ -367,8 +367,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ pop(ebp); __ pop(ebp);
} }
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
...@@ -1642,8 +1640,21 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1642,8 +1640,21 @@ void CodeGenerator::AssembleDeoptimizerCall(
// | RET | args | caller frame | // | RET | args | caller frame |
// ^ esp ^ ebp // ^ esp ^ ebp
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { // Save callee-saved registers.
DCHECK(!info()->is_osr());
int pushed = 0;
for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (!((1 << i) & saves)) continue;
++pushed;
}
frame->AllocateSavedCalleeRegisterSlots(pushed);
}
}
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
...@@ -1655,7 +1666,9 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1655,7 +1666,9 @@ void CodeGenerator::AssemblePrologue() {
__ StubPrologue(info()->GetOutputStackFrameType()); __ StubPrologue(info()->GetOutputStackFrameType());
} }
} }
int stack_shrink_slots = frame()->GetSpillSlotCount();
int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1666,12 +1679,12 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1666,12 +1679,12 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
} }
const RegList saves = descriptor->CalleeSavedRegisters(); const RegList saves = descriptor->CalleeSavedRegisters();
if (stack_shrink_slots > 0) { if (shrink_slots > 0) {
__ sub(esp, Immediate(stack_shrink_slots * kPointerSize)); __ sub(esp, Immediate(shrink_slots * kPointerSize));
} }
if (saves != 0) { // Save callee-saved registers. if (saves != 0) { // Save callee-saved registers.
...@@ -1682,7 +1695,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1682,7 +1695,6 @@ void CodeGenerator::AssemblePrologue() {
__ push(Register::from_code(i)); __ push(Register::from_code(i));
++pushed; ++pushed;
} }
frame()->AllocateSavedCalleeRegisterSlots(pushed);
} }
} }
......
...@@ -483,8 +483,6 @@ void CodeGenerator::AssembleDeconstructFrame() { ...@@ -483,8 +483,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ Pop(ra, fp); __ Pop(ra, fp);
} }
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
...@@ -1648,10 +1646,31 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1648,10 +1646,31 @@ void CodeGenerator::AssembleDeoptimizerCall(
__ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
} }
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
void CodeGenerator::AssemblePrologue() { const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) {
frame->AlignSavedCalleeRegisterSlots();
}
if (saves_fpu != 0) {
int count = base::bits::CountPopulation32(saves_fpu);
DCHECK(kNumCalleeSavedFPU == count);
frame->AllocateSavedCalleeRegisterSlots(count *
(kDoubleSize / kPointerSize));
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) {
int count = base::bits::CountPopulation32(saves);
DCHECK(kNumCalleeSaved == count + 1);
frame->AllocateSavedCalleeRegisterSlots(count);
}
}
void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
int stack_shrink_slots = frame()->GetSpillSlotCount();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
__ Push(ra, fp); __ Push(ra, fp);
...@@ -1663,6 +1682,8 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1663,6 +1682,8 @@ void CodeGenerator::AssemblePrologue() {
} }
} }
int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1673,35 +1694,24 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1673,35 +1694,24 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
} }
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) { if (shrink_slots > 0) {
stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); __ Subu(sp, sp, Operand(shrink_slots * kPointerSize));
}
if (stack_shrink_slots > 0) {
__ Subu(sp, sp, Operand(stack_shrink_slots * kPointerSize));
} }
// Save callee-saved FPU registers. // Save callee-saved FPU registers.
if (saves_fpu != 0) { if (saves_fpu != 0) {
__ MultiPushFPU(saves_fpu); __ MultiPushFPU(saves_fpu);
int count = base::bits::CountPopulation32(saves_fpu);
DCHECK(kNumCalleeSavedFPU == count);
frame()->AllocateSavedCalleeRegisterSlots(count *
(kDoubleSize / kPointerSize));
} }
const RegList saves = descriptor->CalleeSavedRegisters(); const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { if (saves != 0) {
// Save callee-saved registers. // Save callee-saved registers.
__ MultiPush(saves); __ MultiPush(saves);
// kNumCalleeSaved includes the fp register, but the fp register DCHECK(kNumCalleeSaved == base::bits::CountPopulation32(saves) + 1);
// is saved separately in TF.
int count = base::bits::CountPopulation32(saves);
DCHECK(kNumCalleeSaved == count + 1);
frame()->AllocateSavedCalleeRegisterSlots(count);
} }
} }
......
...@@ -495,8 +495,6 @@ void CodeGenerator::AssembleDeconstructFrame() { ...@@ -495,8 +495,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ Pop(ra, fp); __ Pop(ra, fp);
} }
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
...@@ -1915,8 +1913,26 @@ void CodeGenerator::AssembleDeoptimizerCall( ...@@ -1915,8 +1913,26 @@ void CodeGenerator::AssembleDeoptimizerCall(
__ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY);
} }
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) {
int count = base::bits::CountPopulation32(saves_fpu);
DCHECK(kNumCalleeSavedFPU == count);
frame->AllocateSavedCalleeRegisterSlots(count *
(kDoubleSize / kPointerSize));
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) {
int count = base::bits::CountPopulation32(saves);
DCHECK(kNumCalleeSaved == count + 1);
frame->AllocateSavedCalleeRegisterSlots(count);
}
}
void CodeGenerator::AssemblePrologue() { void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
...@@ -1929,7 +1945,8 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1929,7 +1945,8 @@ void CodeGenerator::AssemblePrologue() {
} }
} }
int stack_shrink_slots = frame()->GetSpillSlotCount(); int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1940,32 +1957,25 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1940,32 +1957,25 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots();
} }
if (stack_shrink_slots > 0) { if (shrink_slots > 0) {
__ Dsubu(sp, sp, Operand(stack_shrink_slots * kPointerSize)); __ Dsubu(sp, sp, Operand(shrink_slots * kPointerSize));
} }
const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); const RegList saves_fpu = descriptor->CalleeSavedFPRegisters();
if (saves_fpu != 0) { if (saves_fpu != 0) {
// Save callee-saved FPU registers. // Save callee-saved FPU registers.
__ MultiPushFPU(saves_fpu); __ MultiPushFPU(saves_fpu);
int count = base::bits::CountPopulation32(saves_fpu); DCHECK(kNumCalleeSavedFPU == base::bits::CountPopulation32(saves_fpu));
DCHECK(kNumCalleeSavedFPU == count);
frame()->AllocateSavedCalleeRegisterSlots(count *
(kDoubleSize / kPointerSize));
} }
const RegList saves = descriptor->CalleeSavedRegisters(); const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { if (saves != 0) {
// Save callee-saved registers. // Save callee-saved registers.
__ MultiPush(saves); __ MultiPush(saves);
// kNumCalleeSaved includes the fp register, but the fp register DCHECK(kNumCalleeSaved == base::bits::CountPopulation32(saves) + 1);
// is saved separately in TF.
int count = base::bits::CountPopulation32(saves);
DCHECK(kNumCalleeSaved == count + 1);
frame()->AllocateSavedCalleeRegisterSlots(count);
} }
} }
......
...@@ -607,8 +607,6 @@ void CodeGenerator::AssembleDeconstructFrame() { ...@@ -607,8 +607,6 @@ void CodeGenerator::AssembleDeconstructFrame() {
__ popq(rbp); __ popq(rbp);
} }
void CodeGenerator::AssembleSetupStackPointer() {}
void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) { void CodeGenerator::AssembleDeconstructActivationRecord(int stack_param_delta) {
int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta); int sp_slot_delta = TailCallFrameStackSlotDelta(stack_param_delta);
if (sp_slot_delta > 0) { if (sp_slot_delta > 0) {
...@@ -1952,8 +1950,31 @@ static const int kQuadWordSize = 16; ...@@ -1952,8 +1950,31 @@ static const int kQuadWordSize = 16;
} // namespace } // namespace
void CodeGenerator::FinishFrame(Frame* frame) {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
void CodeGenerator::AssemblePrologue() { const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
if (saves_fp != 0) {
frame->AlignSavedCalleeRegisterSlots();
if (saves_fp != 0) { // Save callee-saved XMM registers.
const uint32_t saves_fp_count = base::bits::CountPopulation32(saves_fp);
frame->AllocateSavedCalleeRegisterSlots(saves_fp_count *
(kQuadWordSize / kPointerSize));
}
}
const RegList saves = descriptor->CalleeSavedRegisters();
if (saves != 0) { // Save callee-saved registers.
int count = 0;
for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (((1 << i) & saves)) {
++count;
}
}
frame->AllocateSavedCalleeRegisterSlots(count);
}
}
void CodeGenerator::AssembleConstructFrame() {
CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
if (frame_access_state()->has_frame()) { if (frame_access_state()->has_frame()) {
if (descriptor->IsCFunctionCall()) { if (descriptor->IsCFunctionCall()) {
...@@ -1965,7 +1986,8 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1965,7 +1986,8 @@ void CodeGenerator::AssemblePrologue() {
__ StubPrologue(info()->GetOutputStackFrameType()); __ StubPrologue(info()->GetOutputStackFrameType());
} }
} }
int stack_shrink_slots = frame()->GetSpillSlotCount(); int shrink_slots = frame()->GetSpillSlotCount();
if (info()->is_osr()) { if (info()->is_osr()) {
// TurboFan OSR-compiled functions cannot be entered directly. // TurboFan OSR-compiled functions cannot be entered directly.
__ Abort(kShouldNotDirectlyEnterOsrFunction); __ Abort(kShouldNotDirectlyEnterOsrFunction);
...@@ -1976,16 +1998,12 @@ void CodeGenerator::AssemblePrologue() { ...@@ -1976,16 +1998,12 @@ void CodeGenerator::AssemblePrologue() {
// remaining stack slots. // remaining stack slots.
if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --");
osr_pc_offset_ = __ pc_offset(); osr_pc_offset_ = __ pc_offset();
stack_shrink_slots -= shrink_slots -= static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots());
static_cast<int>(OsrHelper(info()).UnoptimizedFrameSlots());
} }
const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); const RegList saves_fp = descriptor->CalleeSavedFPRegisters();
if (saves_fp != 0) { if (shrink_slots > 0) {
stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); __ subq(rsp, Immediate(shrink_slots * kPointerSize));
}
if (stack_shrink_slots > 0) {
__ subq(rsp, Immediate(stack_shrink_slots * kPointerSize));
} }
if (saves_fp != 0) { // Save callee-saved XMM registers. if (saves_fp != 0) { // Save callee-saved XMM registers.
...@@ -2001,8 +2019,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -2001,8 +2019,6 @@ void CodeGenerator::AssemblePrologue() {
XMMRegister::from_code(i)); XMMRegister::from_code(i));
slot_idx++; slot_idx++;
} }
frame()->AllocateSavedCalleeRegisterSlots(saves_fp_count *
(kQuadWordSize / kPointerSize));
} }
const RegList saves = descriptor->CalleeSavedRegisters(); const RegList saves = descriptor->CalleeSavedRegisters();
...@@ -2010,7 +2026,6 @@ void CodeGenerator::AssemblePrologue() { ...@@ -2010,7 +2026,6 @@ void CodeGenerator::AssemblePrologue() {
for (int i = Register::kNumRegisters - 1; i >= 0; i--) { for (int i = Register::kNumRegisters - 1; i >= 0; i--) {
if (!((1 << i) & saves)) continue; if (!((1 << i) & saves)) continue;
__ pushq(Register::from_code(i)); __ pushq(Register::from_code(i));
frame()->AllocateSavedCalleeRegisterSlots(1);
} }
} }
} }
......
...@@ -124,11 +124,6 @@ const int kFloatSize = sizeof(float); // NOLINT ...@@ -124,11 +124,6 @@ const int kFloatSize = sizeof(float); // NOLINT
const int kDoubleSize = sizeof(double); // NOLINT const int kDoubleSize = sizeof(double); // NOLINT
const int kIntptrSize = sizeof(intptr_t); // NOLINT const int kIntptrSize = sizeof(intptr_t); // NOLINT
const int kPointerSize = sizeof(void*); // NOLINT const int kPointerSize = sizeof(void*); // NOLINT
#if V8_TARGET_ARCH_ARM64
const int kFrameAlignmentInBytes = 2 * kPointerSize;
#else
const int kFrameAlignmentInBytes = kPointerSize;
#endif
#if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT #if V8_TARGET_ARCH_X64 && V8_TARGET_ARCH_32_BIT
const int kRegisterSize = kPointerSize + kPointerSize; const int kRegisterSize = kPointerSize + kPointerSize;
#else #else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment