frame.cc 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "src/compiler/frame.h"

#include "src/compiler/linkage.h"

namespace v8 {
namespace internal {
namespace compiler {

13
Frame::Frame(int fixed_frame_size_in_slots)
14
    : fixed_slot_count_(fixed_frame_size_in_slots),
15
      allocated_registers_(nullptr),
16 17 18
      allocated_double_registers_(nullptr) {
  slot_allocator_.AllocateUnaligned(fixed_frame_size_in_slots);
}
19

20
void Frame::AlignFrame(int alignment) {
21 22
#if DEBUG
  spill_slots_finished_ = true;
23
  frame_aligned_ = true;
24 25 26 27
#endif
  // In the calculations below we assume that alignment is a power of 2.
  DCHECK(base::bits::IsPowerOfTwo(alignment));
  int alignment_in_slots = AlignedSlotAllocator::NumSlotsForWidth(alignment);
28

29 30
  // We have to align return slots separately, because they are claimed
  // separately on the stack.
31 32 33 34
  const int mask = alignment_in_slots - 1;
  int return_delta = alignment_in_slots - (return_slot_count_ & mask);
  if (return_delta != alignment_in_slots) {
    return_slot_count_ += return_delta;
35
  }
36 37 38
  int delta = alignment_in_slots - (slot_allocator_.Size() & mask);
  if (delta != alignment_in_slots) {
    slot_allocator_.Align(alignment_in_slots);
39 40 41 42 43
    if (spill_slot_count_ != 0) {
      spill_slot_count_ += delta;
    }
  }
}
44

45 46 47 48 49
void FrameAccessState::MarkHasFrame(bool state) {
  has_frame_ = state;
  SetFrameAccessToDefault();
}

50
void FrameAccessState::SetFrameAccessToDefault() {
51
  if (has_frame() && !FLAG_turbo_sp_frame_access) {
52 53 54 55 56 57 58 59
    SetFrameAccessToFP();
  } else {
    SetFrameAccessToSP();
  }
}


FrameOffset 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 64
  } else {
    // No frame. Retrieve all parameters relative to stack pointer.
65
    int sp_offset = frame_offset + GetSPToFPOffset();
66 67 68 69 70
    return FrameOffset::FromStackPointer(sp_offset);
  }
}


71 72 73
}  // namespace compiler
}  // namespace internal
}  // namespace v8