Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: src/compiler/frame.h

Issue 1460183002: [turbofan] Add general support for sp-based frame access (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Last comment addressed Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/code-generator-impl.h ('k') | src/compiler/frame.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
20 // code. Frame objects must be considered immutable once they've been
21 // instantiated and the basic information about the frame has been collected
22 // into them. Mutable state associated with the frame is stored separately in
23 // FrameAccessState.
18 // 24 //
19 // Frames are divided up into four regions. 25 // Frames are divided up into three regions.
20 // - The first is the fixed header, which always has a constant size and can be 26 // - 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 27 // predicted before code generation begins depending on the type of code being
22 // generated. 28 // generated.
23 // - The second is the region for spill slots, which is immediately below the 29 // - 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 30 // fixed header and grows as the register allocator needs to spill to the
25 // stack and asks the frame for more space. 31 // stack and asks the frame for more space.
26 // - The third region, which contains the callee-saved registers must be 32 // - The third region, which contains the callee-saved registers must be
27 // reserved after register allocation, since its size can only be precisely 33 // reserved after register allocation, since its size can only be precisely
28 // determined after register allocation once the number of used callee-saved 34 // determined after register allocation once the number of used callee-saved
29 // register is certain. 35 // 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 // 36 //
33 // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume 37 // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume
34 // two slots. 38 // two slots.
35 // 39 //
36 // Stack slot indices >= 0 access the callee stack with slot 0 corresponding to 40 // 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 41 // 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, 42 // pointer. Some frames have additional information stored in the fixed header,
39 // for example JSFunctions store the function context and marker in the fixed 43 // 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 44 // header, with slot index 2 corresponding to the current function context and 3
41 // corresponding to the frame marker/JSFunction. The frame region immediately 45 // corresponding to the frame marker/JSFunction. The frame region immediately
(...skipping 29 matching lines...) Expand all
71 // 4 | spill 1 | ^ Callee 75 // 4 | spill 1 | ^ Callee
72 // |- - - - - - - - -| | frame slots 76 // |- - - - - - - - -| | frame slots
73 // ... | ... | Spill slots (slot >= 0) 77 // ... | ... | Spill slots (slot >= 0)
74 // |- - - - - - - - -| | | 78 // |- - - - - - - - -| | |
75 // m+4 | spill m | v | 79 // m+4 | spill m | v |
76 // +-----------------+---- | 80 // +-----------------+---- |
77 // m+5 | callee-saved 1 | ^ | 81 // m+5 | callee-saved 1 | ^ |
78 // |- - - - - - - - -| | | 82 // |- - - - - - - - -| | |
79 // | ... | Callee-saved | 83 // | ... | Callee-saved |
80 // |- - - - - - - - -| | | 84 // |- - - - - - - - -| | |
81 // m+r+4 | callee-saved r | v | 85 // 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 ------------- 86 // -----+-----------------+----- <-- stack ptr -------------
89 // 87 //
90 class Frame : public ZoneObject { 88 class Frame : public ZoneObject {
91 public: 89 public:
92 explicit Frame(int fixed_frame_size_in_slots); 90 explicit Frame(int fixed_frame_size_in_slots,
91 const CallDescriptor* descriptor);
92
93 static int FPOffsetToSlot(int frame_offset) {
94 return StandardFrameConstants::kFixedSlotCountAboveFp - 1 -
95 frame_offset / kPointerSize;
96 }
97
98 static int SlotToFPOffset(int slot) {
99 return (StandardFrameConstants::kFixedSlotCountAboveFp - 1 - slot) *
100 kPointerSize;
101 }
102
103 inline bool needs_frame() const { return needs_frame_; }
104 inline void MarkNeedsFrame() { needs_frame_ = true; }
93 105
94 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; } 106 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; }
95 107
96 inline int GetSpToFpSlotCount() const { 108 inline int GetSpToFpSlotCount() const {
97 return GetTotalFrameSlotCount() - 109 return GetTotalFrameSlotCount() -
98 StandardFrameConstants::kFixedSlotCountAboveFp; 110 StandardFrameConstants::kFixedSlotCountAboveFp;
99 } 111 }
100 inline int GetOutgoingParameterSlotCount() const {
101 return outgoing_parameter_slot_count_;
102 }
103 inline int GetSavedCalleeRegisterSlotCount() const { 112 inline int GetSavedCalleeRegisterSlotCount() const {
104 return callee_saved_slot_count_; 113 return callee_saved_slot_count_;
105 } 114 }
106 inline int GetSpillSlotCount() const { return spill_slot_count_; } 115 inline int GetSpillSlotCount() const { return spill_slot_count_; }
107 116
108 inline void SetElidedFrameSizeInSlots(int slots) { 117 inline void SetElidedFrameSizeInSlots(int slots) {
109 DCHECK_EQ(0, callee_saved_slot_count_); 118 DCHECK_EQ(0, callee_saved_slot_count_);
110 DCHECK_EQ(0, spill_slot_count_); 119 DCHECK_EQ(0, spill_slot_count_);
111 frame_slot_count_ = slots; 120 frame_slot_count_ = slots;
112 } 121 }
113 122
114 void SetAllocatedRegisters(BitVector* regs) { 123 void SetAllocatedRegisters(BitVector* regs) {
115 DCHECK(allocated_registers_ == NULL); 124 DCHECK(allocated_registers_ == NULL);
116 allocated_registers_ = regs; 125 allocated_registers_ = regs;
117 } 126 }
118 127
119 void SetAllocatedDoubleRegisters(BitVector* regs) { 128 void SetAllocatedDoubleRegisters(BitVector* regs) {
120 DCHECK(allocated_double_registers_ == NULL); 129 DCHECK(allocated_double_registers_ == NULL);
121 allocated_double_registers_ = regs; 130 allocated_double_registers_ = regs;
122 } 131 }
123 132
124 bool DidAllocateDoubleRegisters() const { 133 bool DidAllocateDoubleRegisters() const {
125 return !allocated_double_registers_->IsEmpty(); 134 return !allocated_double_registers_->IsEmpty();
126 } 135 }
127 136
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() { 137 int AlignSavedCalleeRegisterSlots() {
139 DCHECK_EQ(0, callee_saved_slot_count_); 138 DCHECK_EQ(0, callee_saved_slot_count_);
139 needs_frame_ = true;
140 int delta = frame_slot_count_ & 1; 140 int delta = frame_slot_count_ & 1;
141 frame_slot_count_ += delta; 141 frame_slot_count_ += delta;
142 return delta; 142 return delta;
143 } 143 }
144 144
145 void AllocateSavedCalleeRegisterSlots(int count) { 145 void AllocateSavedCalleeRegisterSlots(int count) {
146 DCHECK_EQ(0, outgoing_parameter_slot_count_); 146 needs_frame_ = true;
147 frame_slot_count_ += count; 147 frame_slot_count_ += count;
148 callee_saved_slot_count_ += count; 148 callee_saved_slot_count_ += count;
149 } 149 }
150 150
151 int AllocateSpillSlot(int width) { 151 int AllocateSpillSlot(int width) {
152 DCHECK_EQ(0, outgoing_parameter_slot_count_);
153 DCHECK_EQ(0, callee_saved_slot_count_); 152 DCHECK_EQ(0, callee_saved_slot_count_);
153 needs_frame_ = true;
154 int frame_slot_count_before = frame_slot_count_; 154 int frame_slot_count_before = frame_slot_count_;
155 int slot = AllocateAlignedFrameSlot(width); 155 int slot = AllocateAlignedFrameSlot(width);
156 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before); 156 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before);
157 return slot; 157 return slot;
158 } 158 }
159 159
160 int ReserveSpillSlots(size_t slot_count) { 160 int ReserveSpillSlots(size_t slot_count) {
161 DCHECK_EQ(0, outgoing_parameter_slot_count_);
162 DCHECK_EQ(0, callee_saved_slot_count_); 161 DCHECK_EQ(0, callee_saved_slot_count_);
163 DCHECK_EQ(0, spill_slot_count_); 162 DCHECK_EQ(0, spill_slot_count_);
163 needs_frame_ = true;
164 spill_slot_count_ += static_cast<int>(slot_count); 164 spill_slot_count_ += static_cast<int>(slot_count);
165 frame_slot_count_ += static_cast<int>(slot_count); 165 frame_slot_count_ += static_cast<int>(slot_count);
166 return frame_slot_count_ - 1; 166 return frame_slot_count_ - 1;
167 } 167 }
168 168
169 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount; 169 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount;
170 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount; 170 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount;
171 171
172 private: 172 private:
173 int AllocateAlignedFrameSlot(int width) { 173 int AllocateAlignedFrameSlot(int width) {
174 DCHECK(width == 4 || width == 8); 174 DCHECK(width == 4 || width == 8);
175 // Skip one slot if necessary. 175 // Skip one slot if necessary.
176 if (width > kPointerSize) { 176 if (width > kPointerSize) {
177 DCHECK(width == kPointerSize * 2); 177 DCHECK(width == kPointerSize * 2);
178 frame_slot_count_++; 178 frame_slot_count_++;
179 frame_slot_count_ |= 1; 179 frame_slot_count_ |= 1;
180 } 180 }
181 return frame_slot_count_++; 181 return frame_slot_count_++;
182 } 182 }
183 183
184 private: 184 private:
185 bool needs_frame_;
185 int frame_slot_count_; 186 int frame_slot_count_;
186 int outgoing_parameter_slot_count_;
187 int callee_saved_slot_count_; 187 int callee_saved_slot_count_;
188 int spill_slot_count_; 188 int spill_slot_count_;
189 BitVector* allocated_registers_; 189 BitVector* allocated_registers_;
190 BitVector* allocated_double_registers_; 190 BitVector* allocated_double_registers_;
191 191
192 DISALLOW_COPY_AND_ASSIGN(Frame); 192 DISALLOW_COPY_AND_ASSIGN(Frame);
193 }; 193 };
194 194
195 195
196 // Represents an offset from either the stack pointer or frame pointer. 196 // Represents an offset from either the stack pointer or frame pointer.
(...skipping 14 matching lines...) Expand all
211 } 211 }
212 212
213 private: 213 private:
214 explicit FrameOffset(int offset) : offset_(offset) {} 214 explicit FrameOffset(int offset) : offset_(offset) {}
215 215
216 int offset_; // Encodes SP or FP in the low order bit. 216 int offset_; // Encodes SP or FP in the low order bit.
217 217
218 static const int kFromSp = 1; 218 static const int kFromSp = 1;
219 static const int kFromFp = 0; 219 static const int kFromFp = 0;
220 }; 220 };
221
222 // Encapsulates the mutable state maintained during code generation about the
223 // current function's frame.
224 class FrameAccessState : public ZoneObject {
225 public:
226 explicit FrameAccessState(Frame* const frame)
227 : frame_(frame), access_frame_with_fp_(false), sp_delta_(0) {
228 SetFrameAccessToDefault();
229 }
230
231 Frame* const frame() const { return frame_; }
232
233 int sp_delta() const { return sp_delta_; }
234 void ClearSPDelta() { sp_delta_ = 0; }
235 void IncreaseSPDelta(int amount) { sp_delta_ += amount; }
236
237 bool access_frame_with_fp() const { return access_frame_with_fp_; }
238 void SetFrameAccessToDefault();
239 void SetFrameAccessToFP() { access_frame_with_fp_ = true; }
240 void SetFrameAccessToSP() { access_frame_with_fp_ = false; }
241
242 // Get the frame offset for a given spill slot. The location depends on the
243 // calling convention and the specific frame layout, and may thus be
244 // architecture-specific. Negative spill slots indicate arguments on the
245 // caller's frame.
246 FrameOffset GetFrameOffset(int spill_slot) const;
247
248 private:
249 Frame* const frame_;
250 bool access_frame_with_fp_;
251 int sp_delta_;
252 };
221 } // namespace compiler 253 } // namespace compiler
222 } // namespace internal 254 } // namespace internal
223 } // namespace v8 255 } // namespace v8
224 256
225 #endif // V8_COMPILER_FRAME_H_ 257 #endif // V8_COMPILER_FRAME_H_
OLDNEW
« no previous file with comments | « src/compiler/code-generator-impl.h ('k') | src/compiler/frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698