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 9namespace v8 { 10namespace internal { 11namespace compiler { 12 13Frame::Frame(int fixed_frame_size_in_slots) 14 : fixed_slot_count_(fixed_frame_size_in_slots), 15 allocated_registers_(nullptr), 16 allocated_double_registers_(nullptr) { 17 slot_allocator_.AllocateUnaligned(fixed_frame_size_in_slots); 18} 19 20void Frame::AlignFrame(int alignment) { 21#if DEBUG 22 spill_slots_finished_ = true; 23 frame_aligned_ = true; 24#endif 25 // In the calculations below we assume that alignment is a power of 2. 26 DCHECK(base::bits::IsPowerOfTwo(alignment)); 27 int alignment_in_slots = AlignedSlotAllocator::NumSlotsForWidth(alignment); 28 29 // We have to align return slots separately, because they are claimed 30 // separately on the stack. 31 const int mask = alignment_in_slots - 1; 32 int return_delta = alignment_in_slots - (return_slot_count_ & mask); 33 if (return_delta != alignment_in_slots) { 34 return_slot_count_ += return_delta; 35 } 36 int delta = alignment_in_slots - (slot_allocator_.Size() & mask); 37 if (delta != alignment_in_slots) { 38 slot_allocator_.Align(alignment_in_slots); 39 if (spill_slot_count_ != 0) { 40 spill_slot_count_ += delta; 41 } 42 } 43} 44 45void FrameAccessState::MarkHasFrame(bool state) { 46 has_frame_ = state; 47 SetFrameAccessToDefault(); 48} 49 50void FrameAccessState::SetFrameAccessToDefault() { 51 if (has_frame() && !FLAG_turbo_sp_frame_access) { 52 SetFrameAccessToFP(); 53 } else { 54 SetFrameAccessToSP(); 55 } 56} 57 58 59FrameOffset FrameAccessState::GetFrameOffset(int spill_slot) const { 60 const int frame_offset = FrameSlotToFPOffset(spill_slot); 61 if (access_frame_with_fp()) { 62 return FrameOffset::FromFramePointer(frame_offset); 63 } else { 64 // No frame. Retrieve all parameters relative to stack pointer. 65 int sp_offset = frame_offset + GetSPToFPOffset(); 66 return FrameOffset::FromStackPointer(sp_offset); 67 } 68} 69 70 71} // namespace compiler 72} // namespace internal 73} // namespace v8 74