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