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

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

Issue 1843143002: [turbofan] CodeGenerator: Frame setup refactoring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months 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
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // |- - - - - - - - -| | | 75 // |- - - - - - - - -| | |
76 // m+r+3 | callee-saved r | v v 76 // m+r+3 | callee-saved r | v v
77 // -----+-----------------+----- <-- stack ptr ------------- 77 // -----+-----------------+----- <-- stack ptr -------------
78 // 78 //
79 class Frame : public ZoneObject { 79 class Frame : public ZoneObject {
80 public: 80 public:
81 explicit Frame(int fixed_frame_size_in_slots); 81 explicit Frame(int fixed_frame_size_in_slots);
82 82
83 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; } 83 inline int GetTotalFrameSlotCount() const { return frame_slot_count_; }
84 84
85 inline int GetSavedCalleeRegisterSlotCount() const {
86 return callee_saved_slot_count_;
87 }
88 inline int GetSpillSlotCount() const { return spill_slot_count_; } 85 inline int GetSpillSlotCount() const { return spill_slot_count_; }
89 86
90 void SetAllocatedRegisters(BitVector* regs) { 87 void SetAllocatedRegisters(BitVector* regs) {
91 DCHECK(allocated_registers_ == nullptr); 88 DCHECK(allocated_registers_ == nullptr);
92 allocated_registers_ = regs; 89 allocated_registers_ = regs;
93 } 90 }
94 91
95 void SetAllocatedDoubleRegisters(BitVector* regs) { 92 void SetAllocatedDoubleRegisters(BitVector* regs) {
96 DCHECK(allocated_double_registers_ == nullptr); 93 DCHECK(allocated_double_registers_ == nullptr);
97 allocated_double_registers_ = regs; 94 allocated_double_registers_ = regs;
98 } 95 }
99 96
100 bool DidAllocateDoubleRegisters() const { 97 bool DidAllocateDoubleRegisters() const {
101 return !allocated_double_registers_->IsEmpty(); 98 return !allocated_double_registers_->IsEmpty();
102 } 99 }
103 100
104 int AlignSavedCalleeRegisterSlots(int alignment = kDoubleSize) { 101 void AlignSavedCalleeRegisterSlots(int alignment = kDoubleSize) {
105 DCHECK_EQ(0, callee_saved_slot_count_);
106 int alignment_slots = alignment / kPointerSize; 102 int alignment_slots = alignment / kPointerSize;
107 int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1)); 103 int delta = alignment_slots - (frame_slot_count_ & (alignment_slots - 1));
108 if (delta != alignment_slots) { 104 if (delta != alignment_slots) {
109 frame_slot_count_ += delta; 105 frame_slot_count_ += delta;
110 } 106 }
111 return delta; 107 spill_slot_count_ += delta;
Mircea Trofin 2016/04/16 04:25:10 Note to reviewers: I am not very happy with this.
Mircea Trofin 2016/04/16 15:25:43 FWIW, I see we do the same in AlignFrame. Still, i
112 } 108 }
113 109
114 void AllocateSavedCalleeRegisterSlots(int count) { 110 void AllocateSavedCalleeRegisterSlots(int count) {
115 frame_slot_count_ += count; 111 frame_slot_count_ += count;
116 callee_saved_slot_count_ += count;
117 } 112 }
118 113
119 int AllocateSpillSlot(int width) { 114 int AllocateSpillSlot(int width) {
120 DCHECK_EQ(0, callee_saved_slot_count_);
121 int frame_slot_count_before = frame_slot_count_; 115 int frame_slot_count_before = frame_slot_count_;
122 int slot = AllocateAlignedFrameSlot(width); 116 int slot = AllocateAlignedFrameSlot(width);
123 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before); 117 spill_slot_count_ += (frame_slot_count_ - frame_slot_count_before);
124 return slot; 118 return slot;
125 } 119 }
126 120
127 int AlignFrame(int alignment = kDoubleSize); 121 int AlignFrame(int alignment = kDoubleSize);
128 122
129 int ReserveSpillSlots(size_t slot_count) { 123 int ReserveSpillSlots(size_t slot_count) {
130 DCHECK_EQ(0, callee_saved_slot_count_);
131 DCHECK_EQ(0, spill_slot_count_); 124 DCHECK_EQ(0, spill_slot_count_);
132 spill_slot_count_ += static_cast<int>(slot_count); 125 spill_slot_count_ += static_cast<int>(slot_count);
133 frame_slot_count_ += static_cast<int>(slot_count); 126 frame_slot_count_ += static_cast<int>(slot_count);
134 return frame_slot_count_ - 1; 127 return frame_slot_count_ - 1;
135 } 128 }
136 129
137 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount; 130 static const int kContextSlot = 2 + StandardFrameConstants::kCPSlotCount;
138 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount; 131 static const int kJSFunctionSlot = 3 + StandardFrameConstants::kCPSlotCount;
139 132
140 private: 133 private:
141 int AllocateAlignedFrameSlot(int width) { 134 int AllocateAlignedFrameSlot(int width) {
142 DCHECK(width == 4 || width == 8); 135 DCHECK(width == 4 || width == 8);
143 // Skip one slot if necessary. 136 // Skip one slot if necessary.
144 if (width > kPointerSize) { 137 if (width > kPointerSize) {
145 DCHECK(width == kPointerSize * 2); 138 DCHECK(width == kPointerSize * 2);
146 frame_slot_count_++; 139 frame_slot_count_++;
147 frame_slot_count_ |= 1; 140 frame_slot_count_ |= 1;
148 } 141 }
149 return frame_slot_count_++; 142 return frame_slot_count_++;
150 } 143 }
151 144
152 private: 145 private:
153 int frame_slot_count_; 146 int frame_slot_count_;
154 int callee_saved_slot_count_;
155 int spill_slot_count_; 147 int spill_slot_count_;
156 BitVector* allocated_registers_; 148 BitVector* allocated_registers_;
157 BitVector* allocated_double_registers_; 149 BitVector* allocated_double_registers_;
158 150
159 DISALLOW_COPY_AND_ASSIGN(Frame); 151 DISALLOW_COPY_AND_ASSIGN(Frame);
160 }; 152 };
161 153
162 154
163 // Represents an offset from either the stack pointer or frame pointer. 155 // Represents an offset from either the stack pointer or frame pointer.
164 class FrameOffset { 156 class FrameOffset {
(...skipping 18 matching lines...) Expand all
183 int offset_; // Encodes SP or FP in the low order bit. 175 int offset_; // Encodes SP or FP in the low order bit.
184 176
185 static const int kFromSp = 1; 177 static const int kFromSp = 1;
186 static const int kFromFp = 0; 178 static const int kFromFp = 0;
187 }; 179 };
188 180
189 // Encapsulates the mutable state maintained during code generation about the 181 // Encapsulates the mutable state maintained during code generation about the
190 // current function's frame. 182 // current function's frame.
191 class FrameAccessState : public ZoneObject { 183 class FrameAccessState : public ZoneObject {
192 public: 184 public:
193 explicit FrameAccessState(Frame* const frame) 185 explicit FrameAccessState(const Frame* const frame)
194 : frame_(frame), 186 : frame_(frame),
195 access_frame_with_fp_(false), 187 access_frame_with_fp_(false),
196 sp_delta_(0), 188 sp_delta_(0),
197 has_frame_(false) {} 189 has_frame_(false) {}
198 190
199 Frame* frame() const { return frame_; } 191 const Frame* frame() const { return frame_; }
200 void MarkHasFrame(bool state); 192 void MarkHasFrame(bool state);
201 193
202 int sp_delta() const { return sp_delta_; } 194 int sp_delta() const { return sp_delta_; }
203 void ClearSPDelta() { sp_delta_ = 0; } 195 void ClearSPDelta() { sp_delta_ = 0; }
204 void IncreaseSPDelta(int amount) { sp_delta_ += amount; } 196 void IncreaseSPDelta(int amount) { sp_delta_ += amount; }
205 197
206 bool access_frame_with_fp() const { return access_frame_with_fp_; } 198 bool access_frame_with_fp() const { return access_frame_with_fp_; }
207 199
208 // Regardless of how we access slots on the stack - using sp or fp - do we 200 // Regardless of how we access slots on the stack - using sp or fp - do we
209 // have a frame, at the current stage in code generation. 201 // have a frame, at the current stage in code generation.
(...skipping 11 matching lines...) Expand all
221 } 213 }
222 int GetSPToFPOffset() const { return GetSPToFPSlotCount() * kPointerSize; } 214 int GetSPToFPOffset() const { return GetSPToFPSlotCount() * kPointerSize; }
223 215
224 // Get the frame offset for a given spill slot. The location depends on the 216 // Get the frame offset for a given spill slot. The location depends on the
225 // calling convention and the specific frame layout, and may thus be 217 // calling convention and the specific frame layout, and may thus be
226 // architecture-specific. Negative spill slots indicate arguments on the 218 // architecture-specific. Negative spill slots indicate arguments on the
227 // caller's frame. 219 // caller's frame.
228 FrameOffset GetFrameOffset(int spill_slot) const; 220 FrameOffset GetFrameOffset(int spill_slot) const;
229 221
230 private: 222 private:
231 Frame* const frame_; 223 const Frame* const frame_;
232 bool access_frame_with_fp_; 224 bool access_frame_with_fp_;
233 int sp_delta_; 225 int sp_delta_;
234 bool has_frame_; 226 bool has_frame_;
235 }; 227 };
236 } // namespace compiler 228 } // namespace compiler
237 } // namespace internal 229 } // namespace internal
238 } // namespace v8 230 } // namespace v8
239 231
240 #endif // V8_COMPILER_FRAME_H_ 232 #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