1 // 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 
9 namespace v8 {
10 namespace internal {
11 namespace compiler {
12 
Frame(int fixed_frame_size_in_slots)13 Frame::Frame(int fixed_frame_size_in_slots)
14     : fixed_slot_count_(fixed_frame_size_in_slots),
15       frame_slot_count_(fixed_frame_size_in_slots),
16       spill_slot_count_(0),
17       return_slot_count_(0),
18       allocated_registers_(nullptr),
19       allocated_double_registers_(nullptr) {}
20 
AlignFrame(int alignment)21 int Frame::AlignFrame(int alignment) {
22   int alignment_slots = alignment / kSystemPointerSize;
23   // We have to align return slots separately, because they are claimed
24   // separately on the stack.
25   int return_delta =
26       alignment_slots - (return_slot_count_ & (alignment_slots - 1));
27   if (return_delta != alignment_slots) {
28     frame_slot_count_ += return_delta;
29   }
30   int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
31   if (delta != alignment_slots) {
32     frame_slot_count_ += delta;
33     if (spill_slot_count_ != 0) {
34       spill_slot_count_ += delta;
35     }
36   }
37   return delta;
38 }
39 
MarkHasFrame(bool state)40 void FrameAccessState::MarkHasFrame(bool state) {
41   has_frame_ = state;
42   SetFrameAccessToDefault();
43 }
44 
SetFrameAccessToDefault()45 void FrameAccessState::SetFrameAccessToDefault() {
46   if (has_frame() && !FLAG_turbo_sp_frame_access) {
47     SetFrameAccessToFP();
48   } else {
49     SetFrameAccessToSP();
50   }
51 }
52 
53 
GetFrameOffset(int spill_slot) const54 FrameOffset FrameAccessState::GetFrameOffset(int spill_slot) const {
55   const int frame_offset = FrameSlotToFPOffset(spill_slot);
56   if (access_frame_with_fp()) {
57     return FrameOffset::FromFramePointer(frame_offset);
58   } else {
59     // No frame. Retrieve all parameters relative to stack pointer.
60     int sp_offset = frame_offset + GetSPToFPOffset();
61     return FrameOffset::FromStackPointer(sp_offset);
62   }
63 }
64 
65 
66 }  // namespace compiler
67 }  // namespace internal
68 }  // namespace v8
69