blob: 3d93e1528f503037b5dd54941e9caf97a91a00c4 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/compiler/frame.h"
6
7#include "src/compiler/linkage.h"
8#include "src/compiler/register-allocator.h"
9#include "src/macro-assembler.h"
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15Frame::Frame(int fixed_frame_size_in_slots, const CallDescriptor* descriptor)
Ben Murdochda12d292016-06-02 14:46:10 +010016 : frame_slot_count_(fixed_frame_size_in_slots),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017 callee_saved_slot_count_(0),
18 spill_slot_count_(0),
19 allocated_registers_(nullptr),
20 allocated_double_registers_(nullptr) {}
21
Ben Murdochda12d292016-06-02 14:46:10 +010022int Frame::AlignFrame(int alignment) {
23 DCHECK_EQ(0, callee_saved_slot_count_);
24 int alignment_slots = alignment / kPointerSize;
25 int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
26 if (delta != alignment_slots) {
27 frame_slot_count_ += delta;
28 if (spill_slot_count_ != 0) {
29 spill_slot_count_ += delta;
30 }
31 }
32 return delta;
33}
34
35void FrameAccessState::MarkHasFrame(bool state) {
36 has_frame_ = state;
37 SetFrameAccessToDefault();
38}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000039
40void FrameAccessState::SetFrameAccessToDefault() {
Ben Murdochda12d292016-06-02 14:46:10 +010041 if (has_frame() && !FLAG_turbo_sp_frame_access) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000042 SetFrameAccessToFP();
43 } else {
44 SetFrameAccessToSP();
45 }
46}
47
48
49FrameOffset FrameAccessState::GetFrameOffset(int spill_slot) const {
Ben Murdochda12d292016-06-02 14:46:10 +010050 const int frame_offset = FrameSlotToFPOffset(spill_slot);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051 if (access_frame_with_fp()) {
Ben Murdochda12d292016-06-02 14:46:10 +010052 return FrameOffset::FromFramePointer(frame_offset);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053 } else {
54 // No frame. Retrieve all parameters relative to stack pointer.
Ben Murdochda12d292016-06-02 14:46:10 +010055 int sp_offset = frame_offset + GetSPToFPOffset();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056 return FrameOffset::FromStackPointer(sp_offset);
57 }
58}
59
60
61} // namespace compiler
62} // namespace internal
63} // namespace v8