blob: e0284c8ab4c6cfc01fb1cef625784e0641fe5720 [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
Ben Murdochc5610432016-08-08 18:44:38 +010015Frame::Frame(int fixed_frame_size_in_slots)
Ben Murdochda12d292016-06-02 14:46:10 +010016 : frame_slot_count_(fixed_frame_size_in_slots),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017 spill_slot_count_(0),
18 allocated_registers_(nullptr),
19 allocated_double_registers_(nullptr) {}
20
Ben Murdochda12d292016-06-02 14:46:10 +010021int Frame::AlignFrame(int alignment) {
Ben Murdochda12d292016-06-02 14:46:10 +010022 int alignment_slots = alignment / kPointerSize;
23 int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
24 if (delta != alignment_slots) {
25 frame_slot_count_ += delta;
26 if (spill_slot_count_ != 0) {
27 spill_slot_count_ += delta;
28 }
29 }
30 return delta;
31}
32
33void FrameAccessState::MarkHasFrame(bool state) {
34 has_frame_ = state;
35 SetFrameAccessToDefault();
36}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000037
38void FrameAccessState::SetFrameAccessToDefault() {
Ben Murdochda12d292016-06-02 14:46:10 +010039 if (has_frame() && !FLAG_turbo_sp_frame_access) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000040 SetFrameAccessToFP();
41 } else {
42 SetFrameAccessToSP();
43 }
44}
45
46
47FrameOffset FrameAccessState::GetFrameOffset(int spill_slot) const {
Ben Murdochda12d292016-06-02 14:46:10 +010048 const int frame_offset = FrameSlotToFPOffset(spill_slot);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 if (access_frame_with_fp()) {
Ben Murdochda12d292016-06-02 14:46:10 +010050 return FrameOffset::FromFramePointer(frame_offset);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051 } else {
52 // No frame. Retrieve all parameters relative to stack pointer.
Ben Murdochda12d292016-06-02 14:46:10 +010053 int sp_offset = frame_offset + GetSPToFPOffset();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054 return FrameOffset::FromStackPointer(sp_offset);
55 }
56}
57
58
59} // namespace compiler
60} // namespace internal
61} // namespace v8