blob: 2850a8c1a152e74f287bbf60129bf71e2109a9b5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
// Copyright 2014 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.
#ifndef V8_COMPILER_FRAME_H_
#define V8_COMPILER_FRAME_H_
#include "src/bit-vector.h"
namespace v8 {
namespace internal {
namespace compiler {
// Collects the spill slot requirements and the allocated general and double
// registers for a compiled function. Frames are usually populated by the
// register allocator and are used by Linkage to generate code for the prologue
// and epilogue to compiled code.
class Frame : public ZoneObject {
public:
Frame()
: register_save_area_size_(0),
spill_slot_count_(0),
osr_stack_slot_count_(0),
allocated_registers_(NULL),
allocated_double_registers_(NULL) {}
inline int GetSpillSlotCount() { return spill_slot_count_; }
void SetAllocatedRegisters(BitVector* regs) {
DCHECK(allocated_registers_ == NULL);
allocated_registers_ = regs;
}
void SetAllocatedDoubleRegisters(BitVector* regs) {
DCHECK(allocated_double_registers_ == NULL);
allocated_double_registers_ = regs;
}
bool DidAllocateDoubleRegisters() {
return !allocated_double_registers_->IsEmpty();
}
void SetRegisterSaveAreaSize(int size) {
DCHECK(IsAligned(size, kPointerSize));
register_save_area_size_ = size;
}
int GetRegisterSaveAreaSize() { return register_save_area_size_; }
// OSR stack slots, including locals and expression stack slots.
void SetOsrStackSlotCount(int slots) {
DCHECK(slots >= 0);
osr_stack_slot_count_ = slots;
}
int GetOsrStackSlotCount() { return osr_stack_slot_count_; }
int AllocateSpillSlot(int width) {
DCHECK(width == 4 || width == 8);
// Skip one slot if necessary.
if (width > kPointerSize) {
DCHECK(width == kPointerSize * 2);
spill_slot_count_++;
spill_slot_count_ |= 1;
}
return spill_slot_count_++;
}
void ReserveSpillSlots(size_t slot_count) {
DCHECK_EQ(0, spill_slot_count_); // can only reserve before allocation.
spill_slot_count_ = static_cast<int>(slot_count);
}
private:
int register_save_area_size_;
int spill_slot_count_;
int osr_stack_slot_count_;
BitVector* allocated_registers_;
BitVector* allocated_double_registers_;
DISALLOW_COPY_AND_ASSIGN(Frame);
};
// Represents an offset from either the stack pointer or frame pointer.
class FrameOffset {
public:
inline bool from_stack_pointer() { return (offset_ & 1) == kFromSp; }
inline bool from_frame_pointer() { return (offset_ & 1) == kFromFp; }
inline int offset() { return offset_ & ~1; }
inline static FrameOffset FromStackPointer(int offset) {
DCHECK((offset & 1) == 0);
return FrameOffset(offset | kFromSp);
}
inline static FrameOffset FromFramePointer(int offset) {
DCHECK((offset & 1) == 0);
return FrameOffset(offset | kFromFp);
}
private:
explicit FrameOffset(int offset) : offset_(offset) {}
int offset_; // Encodes SP or FP in the low order bit.
static const int kFromSp = 1;
static const int kFromFp = 0;
};
}
}
} // namespace v8::internal::compiler
#endif // V8_COMPILER_FRAME_H_
|