frame.cc 1.91 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 15
    : fixed_slot_count_(fixed_frame_size_in_slots),
      frame_slot_count_(fixed_frame_size_in_slots),
16
      spill_slot_count_(0),
17
      return_slot_count_(0),
18 19
      allocated_registers_(nullptr),
      allocated_double_registers_(nullptr) {}
20

21
int Frame::AlignFrame(int alignment) {
22
  int alignment_slots = alignment / kSystemPointerSize;
23 24 25 26 27 28 29
  // We have to align return slots separately, because they are claimed
  // separately on the stack.
  int return_delta =
      alignment_slots - (return_slot_count_ & (alignment_slots - 1));
  if (return_delta != alignment_slots) {
    frame_slot_count_ += return_delta;
  }
30 31 32 33 34 35 36 37 38
  int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
  if (delta != alignment_slots) {
    frame_slot_count_ += delta;
    if (spill_slot_count_ != 0) {
      spill_slot_count_ += delta;
    }
  }
  return delta;
}
39

40 41 42 43 44
void FrameAccessState::MarkHasFrame(bool state) {
  has_frame_ = state;
  SetFrameAccessToDefault();
}

45
void FrameAccessState::SetFrameAccessToDefault() {
46
  if (has_frame() && !FLAG_turbo_sp_frame_access) {
47 48 49 50 51 52 53 54
    SetFrameAccessToFP();
  } else {
    SetFrameAccessToSP();
  }
}


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 59
  } else {
    // No frame. Retrieve all parameters relative to stack pointer.
60
    int sp_offset = frame_offset + GetSPToFPOffset();
61 62 63 64 65
    return FrameOffset::FromStackPointer(sp_offset);
  }
}


66 67 68
}  // namespace compiler
}  // namespace internal
}  // namespace v8