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 | 10 |
10 namespace v8 { | 11 namespace v8 { |
11 namespace internal { | 12 namespace internal { |
12 namespace compiler { | 13 namespace compiler { |
13 | 14 |
14 // Collects the spill slot requirements and the allocated general and double | 15 // Collects the spill slot and other frame slot requirements for a compiled |
15 // registers for a compiled function. Frames are usually populated by the | 16 // function. Frames are usually populated by the register allocator and are used |
16 // register allocator and are used by Linkage to generate code for the prologue | 17 // by Linkage to generate code for the prologue and epilogue to compiled code. |
17 // and epilogue to compiled code. | 18 // |
19 // Frames are divided up into three regions. The first is the fixed header, | |
20 // which always has a constant size and can be predicted before code generation | |
21 // begins depending on the type of code being generated. The second is the | |
22 // region for spill slots, which is immediately below the fixed header and grows | |
23 // as the register allocator needs to spill to the stack and asks the frame for | |
24 // more space. The third region, which contains the callee-saved registers must | |
25 // be reserved after register allocation, since its size can only be precisely | |
26 // determined after register allocation once the number of used callee-saved | |
27 // register is certain. | |
28 // | |
29 // Every pointer in a frame has a slot id. On 32-bit platforms, doubles consume | |
30 // two slots. | |
31 // | |
32 // Stack slot indices >= 0 access the callee stack with slot 0 corresponding to | |
33 // the callee's saved return address and 1 corresponding to the saved frame | |
34 // pointer. Some frames have additional information stored in the fixed header, | |
35 // for example JSFunctions store the function context and marker in the fixed | |
36 // header, with slot index 2 corresponding to the current function context and 3 | |
37 // corresponding to the frame marker/JSFunction. The frame region immediately | |
38 // below the fixed header contains spill slots starting a 4 for JsFunctions. The | |
39 // callee-saved frame region below that starts at 4+spilled_slot_count. Callee | |
40 // stack slots corresponding to parameters are accessible through negative slot | |
41 // ids. | |
42 // | |
43 // Every slot of a caller or callee frame is accessible by the register | |
44 // allocator and gab resolver with a SpillSlotOperand containing its | |
Benedikt Meurer
2015/08/16 07:04:35
Nit: gap resolver
danno
2015/08/18 13:23:10
Done
| |
45 // corresponding slot id. | |
46 // | |
47 // Below an example JSFunction Frame with slot ids, frame regions and contents: | |
48 // | |
49 // slot JS frame | |
50 // +-----------------+---------------------------- | |
51 // -n-1 | parameter 0 | ^ | |
52 // |- - - - - - - - -| | | |
53 // -n | | Caller | |
54 // ... | ... | frame slots | |
55 // -2 | parameter n-1 | (slot < 0) | |
56 // |- - - - - - - - -| | | |
57 // -1 | parameter n | v | |
58 // -----+-----------------+---------------------------- | |
59 // 0 | return addr | ^ ^ | |
60 // |- - - - - - - - -| | | | |
61 // 1 | saved frame ptr | Fixed | | |
62 // |- - - - - - - - -| Header <-- frame ptr | | |
63 // 2 | JSFunction | | | | |
Benedikt Meurer
2015/08/16 07:04:35
Nit: Context
danno
2015/08/18 13:23:10
Done
| |
64 // |- - - - - - - - -| | | | |
65 // 3 | Marker | v | | |
Benedikt Meurer
2015/08/16 07:04:35
Nit: JSFunction/Marker
danno
2015/08/18 13:23:10
Done
| |
66 // +-----------------+---- | | |
67 // 4 | spill 1 | ^ Callee | |
68 // |- - - - - - - - -| | frame slots | |
69 // ... | ... | Spill slots (slot >= 0) | |
70 // |- - - - - - - - -| | | | |
71 // m+4 | spill m | v | | |
72 // +-----------------+---- | | |
73 // m+5 | callee-saved 1 | ^ | | |
74 // |- - - - - - - - -| | | | |
75 // | ... | Callee-saved | | |
76 // |- - - - - - - - -| | | | |
77 // m+r+4 | callee-saved r | v v | |
78 // -----+-----------------+----- <-- stack ptr --------- | |
79 // | |
18 class Frame : public ZoneObject { | 80 class Frame : public ZoneObject { |
19 public: | 81 public: |
20 Frame() | 82 explicit Frame(int fixed_frame_size_in_slots); |
21 : register_save_area_size_(0), | |
22 spill_slot_count_(0), | |
23 osr_stack_slot_count_(0), | |
24 allocated_registers_(NULL), | |
25 allocated_double_registers_(NULL), | |
26 pc_on_stack_(true) {} | |
27 | 83 |
28 inline int GetSpillSlotCount() { return spill_slot_count_; } | 84 static const int kFixedSlotCount = |
titzer
2015/08/17 10:58:42
I think this is dead now?
danno
2015/08/18 13:23:10
No, it's not. It is used to initialize the Frame w
titzer
2015/08/18 13:30:04
In that case recommend moving it to the usage site
| |
85 (kPCOnStackSize + kFPOnStackSize) / kPointerSize; | |
86 static const int kJSFixedSlotCount = | |
87 StandardFrameConstants::kFixedFrameSize / kPointerSize; | |
88 | |
89 inline int GetTotalFrameSlotCount() { return frame_slot_count_; } | |
90 | |
91 inline int GetSavedCalleeRegisterSlotCount() { | |
92 return spilled_callee_register_slot_count_; | |
93 } | |
94 inline int GetSpillSlotCount() { return stack_slot_count_; } | |
95 | |
96 inline void SetElidedFrameSizeInSlots(int slots) { | |
97 DCHECK_EQ(0, spilled_callee_register_slot_count_); | |
98 DCHECK_EQ(0, stack_slot_count_); | |
99 frame_slot_count_ = slots; | |
100 } | |
29 | 101 |
30 void SetAllocatedRegisters(BitVector* regs) { | 102 void SetAllocatedRegisters(BitVector* regs) { |
31 DCHECK(allocated_registers_ == NULL); | 103 DCHECK(allocated_registers_ == NULL); |
32 allocated_registers_ = regs; | 104 allocated_registers_ = regs; |
33 } | 105 } |
34 | 106 |
35 void SetAllocatedDoubleRegisters(BitVector* regs) { | 107 void SetAllocatedDoubleRegisters(BitVector* regs) { |
36 DCHECK(allocated_double_registers_ == NULL); | 108 DCHECK(allocated_double_registers_ == NULL); |
37 allocated_double_registers_ = regs; | 109 allocated_double_registers_ = regs; |
38 } | 110 } |
39 | 111 |
40 bool DidAllocateDoubleRegisters() { | 112 bool DidAllocateDoubleRegisters() { |
41 return !allocated_double_registers_->IsEmpty(); | 113 return !allocated_double_registers_->IsEmpty(); |
42 } | 114 } |
43 | 115 |
44 void SetRegisterSaveAreaSize(int size) { | 116 int AlignSavedCalleeRegisterSlots() { |
45 DCHECK(IsAligned(size, kPointerSize)); | 117 DCHECK_EQ(0, spilled_callee_register_slot_count_); |
46 register_save_area_size_ = size; | 118 int frame_slot_count_before = frame_slot_count_; |
119 frame_slot_count_ = RoundUp(frame_slot_count_, 2); | |
120 return frame_slot_count_before - frame_slot_count_; | |
47 } | 121 } |
48 | 122 |
49 int GetRegisterSaveAreaSize() { return register_save_area_size_; } | 123 void AllocateSavedCalleeRegisterSlots(int count) { |
50 | 124 ++frame_slot_count_ += count; |
51 // OSR stack slots, including locals and expression stack slots. | 125 ++spilled_callee_register_slot_count_ += count; |
Jarin
2015/08/16 09:28:59
How about 'frame_slot_count_ += count + 1;'? I am
Benedikt Meurer
2015/08/16 09:31:34
Oh indeed. Missed this one. Should really be
fram
danno
2015/08/18 13:23:10
Fixed.
| |
52 void SetOsrStackSlotCount(int slots) { | |
53 DCHECK(slots >= 0); | |
54 osr_stack_slot_count_ = slots; | |
55 } | 126 } |
56 | 127 |
57 int GetOsrStackSlotCount() { return osr_stack_slot_count_; } | 128 int AllocateSpillSlot(int width) { |
129 DCHECK_EQ(0, spilled_callee_register_slot_count_); | |
130 int frame_slot_count_before = frame_slot_count_; | |
131 int slot = AllocateAlignedFrameSlot(width); | |
132 stack_slot_count_ += (frame_slot_count_ - frame_slot_count_before); | |
133 return slot; | |
134 } | |
58 | 135 |
59 int AllocateSpillSlot(int width) { | 136 int ReserveSpillSlots(size_t slot_count) { |
137 DCHECK_EQ(0, spilled_callee_register_slot_count_); | |
138 DCHECK_EQ(0, stack_slot_count_); | |
139 stack_slot_count_ += static_cast<int>(slot_count); | |
140 frame_slot_count_ += static_cast<int>(slot_count); | |
141 return frame_slot_count_ - 1; | |
142 } | |
143 | |
144 private: | |
145 int AllocateAlignedFrameSlot(int width) { | |
60 DCHECK(width == 4 || width == 8); | 146 DCHECK(width == 4 || width == 8); |
61 // Skip one slot if necessary. | 147 // Skip one slot if necessary. |
62 if (width > kPointerSize) { | 148 if (width > kPointerSize) { |
63 DCHECK(width == kPointerSize * 2); | 149 DCHECK(width == kPointerSize * 2); |
64 spill_slot_count_++; | 150 frame_slot_count_++; |
65 spill_slot_count_ |= 1; | 151 frame_slot_count_ |= 1; |
66 } | 152 } |
67 return spill_slot_count_++; | 153 return frame_slot_count_++; |
68 } | 154 } |
69 | 155 |
70 void ReserveSpillSlots(size_t slot_count) { | |
71 DCHECK_EQ(0, spill_slot_count_); // can only reserve before allocation. | |
72 spill_slot_count_ = static_cast<int>(slot_count); | |
73 } | |
74 | |
75 void SetPCOnStack(bool val) { pc_on_stack_ = val; } | |
76 | |
77 int PCOnStackSize() { return pc_on_stack_ ? kRegisterSize : 0; } | |
78 | |
79 private: | 156 private: |
80 int register_save_area_size_; | 157 int frame_slot_count_; |
81 int spill_slot_count_; | 158 int spilled_callee_register_slot_count_; |
82 int osr_stack_slot_count_; | 159 int stack_slot_count_; |
83 BitVector* allocated_registers_; | 160 BitVector* allocated_registers_; |
84 BitVector* allocated_double_registers_; | 161 BitVector* allocated_double_registers_; |
85 bool pc_on_stack_; | |
86 | 162 |
87 DISALLOW_COPY_AND_ASSIGN(Frame); | 163 DISALLOW_COPY_AND_ASSIGN(Frame); |
88 }; | 164 }; |
89 | 165 |
90 | 166 |
91 // Represents an offset from either the stack pointer or frame pointer. | 167 // Represents an offset from either the stack pointer or frame pointer. |
92 class FrameOffset { | 168 class FrameOffset { |
93 public: | 169 public: |
94 inline bool from_stack_pointer() { return (offset_ & 1) == kFromSp; } | 170 inline bool from_stack_pointer() { return (offset_ & 1) == kFromSp; } |
95 inline bool from_frame_pointer() { return (offset_ & 1) == kFromFp; } | 171 inline bool from_frame_pointer() { return (offset_ & 1) == kFromFp; } |
(...skipping 15 matching lines...) Expand all Loading... | |
111 int offset_; // Encodes SP or FP in the low order bit. | 187 int offset_; // Encodes SP or FP in the low order bit. |
112 | 188 |
113 static const int kFromSp = 1; | 189 static const int kFromSp = 1; |
114 static const int kFromFp = 0; | 190 static const int kFromFp = 0; |
115 }; | 191 }; |
116 } | 192 } |
117 } | 193 } |
118 } // namespace v8::internal::compiler | 194 } // namespace v8::internal::compiler |
119 | 195 |
120 #endif // V8_COMPILER_FRAME_H_ | 196 #endif // V8_COMPILER_FRAME_H_ |
OLD | NEW |