OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_FRAME_H_ | 5 #ifndef V8_COMPILER_FRAME_H_ |
6 #define V8_COMPILER_FRAME_H_ | 6 #define V8_COMPILER_FRAME_H_ |
7 | 7 |
8 #include "src/bit-vector.h" | 8 #include "src/bit-vector.h" |
9 #include "src/frames.h" | 9 #include "src/frames.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
| 15 class CallDescriptor; |
| 16 |
15 // Collects the spill slot and other frame slot requirements for a compiled | 17 // Collects the spill slot and other frame slot requirements for a compiled |
16 // function. Frames are usually populated by the register allocator and are used | 18 // function. Frames are usually populated by the register allocator and are used |
17 // by Linkage to generate code for the prologue and epilogue to compiled code. | 19 // by Linkage to generate code for the prologue and epilogue to compiled code. |
18 // | 20 // |
19 // Frames are divided up into four regions. | 21 // Frames are divided up into three regions. |
20 // - The first is the fixed header, which always has a constant size and can be | 22 // - The first is the fixed header, which always has a constant size and can be |
21 // predicted before code generation begins depending on the type of code being | 23 // predicted before code generation begins depending on the type of code being |
22 // generated. | 24 // generated. |
23 // - The second is the region for spill slots, which is immediately below the | 25 // - The second is the region for spill slots, which is immediately below the |
24 // fixed header and grows as the register allocator needs to spill to the | 26 // fixed header and grows as the register allocator needs to spill to the |
25 // stack and asks the frame for more space. | 27 // stack and asks the frame for more space. |
26 // - The third region, which contains the callee-saved registers must be | 28 // - The third region, which contains the callee-saved registers must be |
27 // reserved after register allocation, since its size can only be precisely | 29 // reserved after register allocation, since its size can only be precisely |
28 // determined after register allocation once the number of used callee-saved | 30 // determined after register allocation once the number of used callee-saved |
29 // register is certain. | 31 // register is certain. |
30 // - The fourth region is used to pass arguments to other functions. It should | |
31 // be empty except when a call is being prepared. | |
32 // | 32 // |
33 // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume | 33 // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume |
34 // two slots. | 34 // two slots. |
35 // | 35 // |
36 // Stack slot indices >= 0 access the callee stack with slot 0 corresponding to | 36 // Stack slot indices >= 0 access the callee stack with slot 0 corresponding to |
37 // the callee's saved return address and 1 corresponding to the saved frame | 37 // the callee's saved return address and 1 corresponding to the saved frame |
38 // pointer. Some frames have additional information stored in the fixed header, | 38 // pointer. Some frames have additional information stored in the fixed header, |
39 // for example JSFunctions store the function context and marker in the fixed | 39 // for example JSFunctions store the function context and marker in the fixed |
40 // header, with slot index 2 corresponding to the current function context and 3 | 40 // header, with slot index 2 corresponding to the current function context and 3 |
41 // corresponding to the frame marker/JSFunction. The frame region immediately | 41 // corresponding to the frame marker/JSFunction. The frame region immediately |
(...skipping 29 matching lines...) Expand all Loading... |
71 // 4 | spill 1 | ^ Callee | 71 // 4 | spill 1 | ^ Callee |
72 // |- - - - - - - - -| | frame slots | 72 // |- - - - - - - - -| | frame slots |
73 // ... | ... | Spill slots (slot >= 0) | 73 // ... | ... | Spill slots (slot >= 0) |
74 // |- - - - - - - - -| | | | 74 // |- - - - - - - - -| | | |
75 // m+4 | spill m | v | | 75 // m+4 | spill m | v | |
76 // +-----------------+---- | | 76 // +-----------------+---- | |
77 // m+5 | callee-saved 1 | ^ | | 77 // m+5 | callee-saved 1 | ^ | |
78 // |- - - - - - - - -| | | | 78 // |- - - - - - - - -| | | |
79 // | ... | Callee-saved | | 79 // | ... | Callee-saved | |
80 // |- - - - - - - - -| | | | 80 // |- - - - - - - - -| | | |
81 // m+r+4 | callee-saved r | v | | 81 // m+r+4 | callee-saved r | v v |
82 // +-----------------+---- | | |
83 // | parameter 0 | ^ | | |
84 // |- - - - - - - - -| | | | |
85 // | ... | Outgoing parameters | | |
86 // |- - - - - - - - -| | (for function calls) | | |
87 // | parameter p | v v | |
88 // -----+-----------------+----- <-- stack ptr ------------- | 82 // -----+-----------------+----- <-- stack ptr ------------- |
89 // | 83 // |
90 class Frame : public ZoneObject { | 84 class Frame : public ZoneObject { |
91 public: | 85 public: |
92 explicit Frame(int fixed_frame_size_in_slots); | 86 explicit Frame(int fixed_frame_size_in_slots, |
| 87 const CallDescriptor* descriptor); |
| 88 |
| 89 static int FPOffsetToSlot(int frame_offset) { |
| 90 return StandardFrameConstants::kFixedSlotCountAboveFp - 1 - |
| 91 frame_offset / kPointerSize; |
| 92 } |
| 93 |
| 94 static int SlotToFPOffset(int slot) { |
| 95 return (StandardFrameConstants::kFixedSlotCountAboveFp - 1 - slot) * |
| 96 kPointerSize; |
| 97 } |
| 98 |
| 99 inline bool needs_frame() const { return needs_frame_; } |
| 100 inline void MarkNeedsFrame() { needs_frame_ = true; } |
93 | 101 |
94 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; } | 102 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; } |
95 | 103 |
96 inline int GetSpToFpSlotCount() const { | 104 inline int GetSpToFpSlotCount() const { |
97 return GetTotalFrameSlotCount() - | 105 return GetTotalFrameSlotCount() - |
98 StandardFrameConstants::kFixedSlotCountAboveFp; | 106 StandardFrameConstants::kFixedSlotCountAboveFp; |
99 } | 107 } |
100 inline int GetOutgoingParameterSlotCount() const { | |
101 return outgoing_parameter_slot_count_; | |
102 } | |
103 inline int GetSavedCalleeRegisterSlotCount() const { | 108 inline int GetSavedCalleeRegisterSlotCount() const { |
104 return callee_saved_slot_count_; | 109 return callee_saved_slot_count_; |
105 } | 110 } |
106 inline int GetSpillSlotCount() const { return spill_slot_count_; } | 111 inline int GetSpillSlotCount() const { return spill_slot_count_; } |
107 | 112 |
108 inline void SetElidedFrameSizeInSlots(int slots) { | 113 inline void SetElidedFrameSizeInSlots(int slots) { |
109 DCHECK_EQ(0, callee_saved_slot_count_); | 114 DCHECK_EQ(0, callee_saved_slot_count_); |
110 DCHECK_EQ(0, spill_slot_count_); | 115 DCHECK_EQ(0, spill_slot_count_); |
111 frame_slot_count_ = slots; | 116 frame_slot_count_ = slots; |
112 } | 117 } |
113 | 118 |
114 void SetAllocatedRegisters(BitVector* regs) { | 119 void SetAllocatedRegisters(BitVector* regs) { |
115 DCHECK(allocated_registers_ == NULL); | 120 DCHECK(allocated_registers_ == NULL); |
116 allocated_registers_ = regs; | 121 allocated_registers_ = regs; |
117 } | 122 } |
118 | 123 |
119 void SetAllocatedDoubleRegisters(BitVector* regs) { | 124 void SetAllocatedDoubleRegisters(BitVector* regs) { |
120 DCHECK(allocated_double_registers_ == NULL); | 125 DCHECK(allocated_double_registers_ == NULL); |
121 allocated_double_registers_ = regs; | 126 allocated_double_registers_ = regs; |
122 } | 127 } |
123 | 128 |
124 bool DidAllocateDoubleRegisters() const { | 129 bool DidAllocateDoubleRegisters() const { |
125 return !allocated_double_registers_->IsEmpty(); | 130 return !allocated_double_registers_->IsEmpty(); |
126 } | 131 } |
127 | 132 |
128 void AllocateOutgoingParameterSlots(int count) { | |
129 outgoing_parameter_slot_count_ += count; | |
130 frame_slot_count_ += count; | |
131 } | |
132 | |
133 void ClearOutgoingParameterSlots() { | |
134 frame_slot_count_ -= outgoing_parameter_slot_count_; | |
135 outgoing_parameter_slot_count_ = 0; | |
136 } | |
137 | |
138 int AlignSavedCalleeRegisterSlots() { | 133 int AlignSavedCalleeRegisterSlots() { |
139 DCHECK_EQ(0, callee_saved_slot_count_); | 134 DCHECK_EQ(0, callee_saved_slot_count_); |
| 135 needs_frame_ = true; |
140 int delta = frame_slot_count_ & 1; | 136 int delta = frame_slot_count_ & 1; |
141 frame_slot_count_ += delta; | 137 frame_slot_count_ += delta; |
142 return delta; | 138 return delta; |
143 } | 139 } |
144 | 140 |
145 void AllocateSavedCalleeRegisterSlots(int count) { | 141 void AllocateSavedCalleeRegisterSlots(int count) { |
146 DCHECK_EQ(0, outgoing_parameter_slot_count_); | 142 needs_frame_ = true; |
147 frame_slot_count_ += count; | 143 frame_slot_count_ += count; |
148 callee_saved_slot_count_ += count; | 144 callee_saved_slot_count_ += count; |
149 } | 145 } |
150 | 146 |
151 int AllocateSpillSlot(int width) { | 147 int AllocateSpillSlot(int width) { |
152 DCHECK_EQ(0, outgoing_parameter_slot_count_); | |
153 DCHECK_EQ(0, callee_saved_slot_count_); | 148 DCHECK_EQ(0, callee_saved_slot_count_); |
| 149 needs_frame_ = true; |
154 int frame_slot_count_before = frame_slot_count_; | 150 int frame_slot_count_before = frame_slot_count_; |
155 int slot = AllocateAlignedFrameSlot(width); | 151 int slot = AllocateAlignedFrameSlot(width); |
156 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before); | 152 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before); |
157 return slot; | 153 return slot; |
158 } | 154 } |
159 | 155 |
160 int ReserveSpillSlots(size_t slot_count) { | 156 int ReserveSpillSlots(size_t slot_count) { |
161 DCHECK_EQ(0, outgoing_parameter_slot_count_); | |
162 DCHECK_EQ(0, callee_saved_slot_count_); | 157 DCHECK_EQ(0, callee_saved_slot_count_); |
163 DCHECK_EQ(0, spill_slot_count_); | 158 DCHECK_EQ(0, spill_slot_count_); |
| 159 needs_frame_ = true; |
164 spill_slot_count_ += static_cast<int>(slot_count); | 160 spill_slot_count_ += static_cast<int>(slot_count); |
165 frame_slot_count_ += static_cast<int>(slot_count); | 161 frame_slot_count_ += static_cast<int>(slot_count); |
166 return frame_slot_count_ - 1; | 162 return frame_slot_count_ - 1; |
167 } | 163 } |
168 | 164 |
169 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount; | 165 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount; |
170 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount; | 166 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount; |
171 | 167 |
172 private: | 168 private: |
173 int AllocateAlignedFrameSlot(int width) { | 169 int AllocateAlignedFrameSlot(int width) { |
174 DCHECK(width == 4 || width == 8); | 170 DCHECK(width == 4 || width == 8); |
175 // Skip one slot if necessary. | 171 // Skip one slot if necessary. |
176 if (width > kPointerSize) { | 172 if (width > kPointerSize) { |
177 DCHECK(width == kPointerSize * 2); | 173 DCHECK(width == kPointerSize * 2); |
178 frame_slot_count_++; | 174 frame_slot_count_++; |
179 frame_slot_count_ |= 1; | 175 frame_slot_count_ |= 1; |
180 } | 176 } |
181 return frame_slot_count_++; | 177 return frame_slot_count_++; |
182 } | 178 } |
183 | 179 |
184 private: | 180 private: |
| 181 bool needs_frame_; |
185 int frame_slot_count_; | 182 int frame_slot_count_; |
186 int outgoing_parameter_slot_count_; | |
187 int callee_saved_slot_count_; | 183 int callee_saved_slot_count_; |
188 int spill_slot_count_; | 184 int spill_slot_count_; |
189 BitVector* allocated_registers_; | 185 BitVector* allocated_registers_; |
190 BitVector* allocated_double_registers_; | 186 BitVector* allocated_double_registers_; |
191 | 187 |
192 DISALLOW_COPY_AND_ASSIGN(Frame); | 188 DISALLOW_COPY_AND_ASSIGN(Frame); |
193 }; | 189 }; |
194 | 190 |
195 | 191 |
196 // Represents an offset from either the stack pointer or frame pointer. | 192 // Represents an offset from either the stack pointer or frame pointer. |
(...skipping 19 matching lines...) Expand all Loading... |
216 int offset_; // Encodes SP or FP in the low order bit. | 212 int offset_; // Encodes SP or FP in the low order bit. |
217 | 213 |
218 static const int kFromSp = 1; | 214 static const int kFromSp = 1; |
219 static const int kFromFp = 0; | 215 static const int kFromFp = 0; |
220 }; | 216 }; |
221 } // namespace compiler | 217 } // namespace compiler |
222 } // namespace internal | 218 } // namespace internal |
223 } // namespace v8 | 219 } // namespace v8 |
224 | 220 |
225 #endif // V8_COMPILER_FRAME_H_ | 221 #endif // V8_COMPILER_FRAME_H_ |
OLD | NEW |