1 // Copyright 2014 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.
5 #ifndef V8_COMPILER_FRAME_H_
6 #define V8_COMPILER_FRAME_H_
10 #include "src/bit-vector.h"
16 // Collects the spill slot requirements and the allocated general and double
17 // registers for a compiled function. Frames are usually populated by the
18 // register allocator and are used by Linkage to generate code for the prologue
19 // and epilogue to compiled code.
23 : register_save_area_size_(0),
25 double_spill_slot_count_(0),
26 allocated_registers_(NULL),
27 allocated_double_registers_(NULL) {}
29 inline int GetSpillSlotCount() { return spill_slot_count_; }
30 inline int GetDoubleSpillSlotCount() { return double_spill_slot_count_; }
32 void SetAllocatedRegisters(BitVector* regs) {
33 DCHECK(allocated_registers_ == NULL);
34 allocated_registers_ = regs;
37 void SetAllocatedDoubleRegisters(BitVector* regs) {
38 DCHECK(allocated_double_registers_ == NULL);
39 allocated_double_registers_ = regs;
42 bool DidAllocateDoubleRegisters() {
43 return !allocated_double_registers_->IsEmpty();
46 void SetRegisterSaveAreaSize(int size) {
47 DCHECK(IsAligned(size, kPointerSize));
48 register_save_area_size_ = size;
51 int GetRegisterSaveAreaSize() { return register_save_area_size_; }
53 int AllocateSpillSlot(bool is_double) {
54 // If 32-bit, skip one if the new slot is a double.
56 if (kDoubleSize > kPointerSize) {
57 DCHECK(kDoubleSize == kPointerSize * 2);
59 spill_slot_count_ |= 1;
61 double_spill_slot_count_++;
63 return spill_slot_count_++;
67 int register_save_area_size_;
68 int spill_slot_count_;
69 int double_spill_slot_count_;
70 BitVector* allocated_registers_;
71 BitVector* allocated_double_registers_;
75 // Represents an offset from either the stack pointer or frame pointer.
78 inline bool from_stack_pointer() { return (offset_ & 1) == kFromSp; }
79 inline bool from_frame_pointer() { return (offset_ & 1) == kFromFp; }
80 inline int offset() { return offset_ & ~1; }
82 inline static FrameOffset FromStackPointer(int offset) {
83 DCHECK((offset & 1) == 0);
84 return FrameOffset(offset | kFromSp);
87 inline static FrameOffset FromFramePointer(int offset) {
88 DCHECK((offset & 1) == 0);
89 return FrameOffset(offset | kFromFp);
93 explicit FrameOffset(int offset) : offset_(offset) {}
95 int offset_; // Encodes SP or FP in the low order bit.
97 static const int kFromSp = 1;
98 static const int kFromFp = 0;
102 } // namespace v8::internal::compiler
104 #endif // V8_COMPILER_FRAME_H_