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

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

Issue 810403003: [turbofan] remove checks for virtual register overflow (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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 | « no previous file | src/compiler/instruction.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_INSTRUCTION_H_ 5 #ifndef V8_COMPILER_INSTRUCTION_H_
6 #define V8_COMPILER_INSTRUCTION_H_ 6 #define V8_COMPILER_INSTRUCTION_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <map> 10 #include <map>
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 value_ = KindField::encode(kind); 66 value_ = KindField::encode(kind);
67 value_ |= bit_cast<unsigned>(index << KindField::kSize); 67 value_ |= bit_cast<unsigned>(index << KindField::kSize);
68 DCHECK(this->index() == index); 68 DCHECK(this->index() == index);
69 } 69 }
70 70
71 // Calls SetUpCache()/TearDownCache() for each subclass. 71 // Calls SetUpCache()/TearDownCache() for each subclass.
72 static void SetUpCaches(); 72 static void SetUpCaches();
73 static void TearDownCaches(); 73 static void TearDownCaches();
74 74
75 protected: 75 protected:
76 typedef BitField64<Kind, 0, 3> KindField; 76 typedef BitField<Kind, 0, 3> KindField;
77 77
78 uint64_t value_; 78 uint32_t value_;
79 }; 79 };
80 80
81 typedef ZoneVector<InstructionOperand*> InstructionOperandVector; 81 typedef ZoneVector<InstructionOperand*> InstructionOperandVector;
82 82
83 struct PrintableInstructionOperand { 83 struct PrintableInstructionOperand {
84 const RegisterConfiguration* register_configuration_; 84 const RegisterConfiguration* register_configuration_;
85 const InstructionOperand* op_; 85 const InstructionOperand* op_;
86 }; 86 };
87 87
88 std::ostream& operator<<(std::ostream& os, 88 std::ostream& operator<<(std::ostream& os,
(...skipping 19 matching lines...) Expand all
108 // to some other operand used inside instruction (i.e. temporary or 108 // to some other operand used inside instruction (i.e. temporary or
109 // output). 109 // output).
110 USED_AT_START, 110 USED_AT_START,
111 111
112 // USED_AT_END operand is treated as live until the end of 112 // USED_AT_END operand is treated as live until the end of
113 // instruction. This means that register allocator will not reuse it's 113 // instruction. This means that register allocator will not reuse it's
114 // register for any other operand inside instruction. 114 // register for any other operand inside instruction.
115 USED_AT_END 115 USED_AT_END
116 }; 116 };
117 117
118 static const int kInvalidVirtualRegister = -1;
119
118 explicit UnallocatedOperand(ExtendedPolicy policy) 120 explicit UnallocatedOperand(ExtendedPolicy policy)
119 : InstructionOperand(UNALLOCATED, 0) { 121 : InstructionOperand(UNALLOCATED, 0),
120 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); 122 virtual_register_(kInvalidVirtualRegister) {
121 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); 123 value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
122 value_ |= ExtendedPolicyField::encode(policy); 124 value_ |= ExtendedPolicyField::encode(policy);
123 value_ |= LifetimeField::encode(USED_AT_END); 125 value_ |= LifetimeField::encode(USED_AT_END);
124 } 126 }
125 127
126 UnallocatedOperand(BasicPolicy policy, int index) 128 UnallocatedOperand(BasicPolicy policy, int index)
127 : InstructionOperand(UNALLOCATED, 0) { 129 : InstructionOperand(UNALLOCATED, 0),
130 virtual_register_(kInvalidVirtualRegister) {
128 DCHECK(policy == FIXED_SLOT); 131 DCHECK(policy == FIXED_SLOT);
129 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister);
130 value_ |= BasicPolicyField::encode(policy); 132 value_ |= BasicPolicyField::encode(policy);
131 value_ |= static_cast<int64_t>(index) << FixedSlotIndexField::kShift; 133 value_ |= static_cast<int32_t>(index) << FixedSlotIndexField::kShift;
132 DCHECK(this->fixed_slot_index() == index); 134 DCHECK(this->fixed_slot_index() == index);
133 } 135 }
134 136
135 UnallocatedOperand(ExtendedPolicy policy, int index) 137 UnallocatedOperand(ExtendedPolicy policy, int index)
136 : InstructionOperand(UNALLOCATED, 0) { 138 : InstructionOperand(UNALLOCATED, 0),
139 virtual_register_(kInvalidVirtualRegister) {
137 DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER); 140 DCHECK(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER);
138 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister);
139 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); 141 value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
140 value_ |= ExtendedPolicyField::encode(policy); 142 value_ |= ExtendedPolicyField::encode(policy);
141 value_ |= LifetimeField::encode(USED_AT_END); 143 value_ |= LifetimeField::encode(USED_AT_END);
142 value_ |= FixedRegisterField::encode(index); 144 value_ |= FixedRegisterField::encode(index);
143 } 145 }
144 146
145 UnallocatedOperand(ExtendedPolicy policy, Lifetime lifetime) 147 UnallocatedOperand(ExtendedPolicy policy, Lifetime lifetime)
146 : InstructionOperand(UNALLOCATED, 0) { 148 : InstructionOperand(UNALLOCATED, 0),
147 value_ |= VirtualRegisterField::encode(kInvalidVirtualRegister); 149 virtual_register_(kInvalidVirtualRegister) {
148 value_ |= BasicPolicyField::encode(EXTENDED_POLICY); 150 value_ |= BasicPolicyField::encode(EXTENDED_POLICY);
149 value_ |= ExtendedPolicyField::encode(policy); 151 value_ |= ExtendedPolicyField::encode(policy);
150 value_ |= LifetimeField::encode(lifetime); 152 value_ |= LifetimeField::encode(lifetime);
151 } 153 }
152 154
153 UnallocatedOperand* CopyUnconstrained(Zone* zone) { 155 UnallocatedOperand* CopyUnconstrained(Zone* zone) {
154 UnallocatedOperand* result = new (zone) UnallocatedOperand(ANY); 156 UnallocatedOperand* result = new (zone) UnallocatedOperand(ANY);
155 result->set_virtual_register(virtual_register()); 157 result->set_virtual_register(virtual_register());
156 return result; 158 return result;
157 } 159 }
158 160
159 static const UnallocatedOperand* cast(const InstructionOperand* op) { 161 static const UnallocatedOperand* cast(const InstructionOperand* op) {
160 DCHECK(op->IsUnallocated()); 162 DCHECK(op->IsUnallocated());
161 return static_cast<const UnallocatedOperand*>(op); 163 return static_cast<const UnallocatedOperand*>(op);
162 } 164 }
163 165
164 static UnallocatedOperand* cast(InstructionOperand* op) { 166 static UnallocatedOperand* cast(InstructionOperand* op) {
165 DCHECK(op->IsUnallocated()); 167 DCHECK(op->IsUnallocated());
166 return static_cast<UnallocatedOperand*>(op); 168 return static_cast<UnallocatedOperand*>(op);
167 } 169 }
168 170
169 // The encoding used for UnallocatedOperand operands depends on the policy 171 // The encoding used for UnallocatedOperand operands depends on the policy
170 // that is 172 // that is
171 // stored within the operand. The FIXED_SLOT policy uses a compact encoding 173 // stored within the operand. The FIXED_SLOT policy uses a compact encoding
172 // because it accommodates a larger pay-load. 174 // because it accommodates a larger pay-load.
173 // 175 //
174 // For FIXED_SLOT policy: 176 // For FIXED_SLOT policy:
175 // +------------------------------------------+ 177 // +-----------------------------+
176 // | slot_index | vreg | 0 | 001 | 178 // | slot_index | 0 | 001 |
177 // +------------------------------------------+ 179 // +-----------------------------+
178 // 180 //
179 // For all other (extended) policies: 181 // For all other (extended) policies:
180 // +------------------------------------------+ 182 // +----------------------------------+
181 // | reg_index | L | PPP | vreg | 1 | 001 | L ... Lifetime 183 // | reg_index | L | PPP | 1 | 001 | L ... Lifetime
182 // +------------------------------------------+ P ... Policy 184 // +----------------------------------+ P ... Policy
183 // 185 //
184 // The slot index is a signed value which requires us to decode it manually 186 // The slot index is a signed value which requires us to decode it manually
185 // instead of using the BitField64 utility class. 187 // instead of using the BitField utility class.
186 188
187 // The superclass has a KindField. 189 // The superclass has a KindField.
188 STATIC_ASSERT(KindField::kSize == 3); 190 STATIC_ASSERT(KindField::kSize == 3);
189 191
190 // BitFields for all unallocated operands. 192 // BitFields for all unallocated operands.
191 class BasicPolicyField : public BitField64<BasicPolicy, 3, 1> {}; 193 class BasicPolicyField : public BitField<BasicPolicy, 3, 1> {};
192 class VirtualRegisterField : public BitField64<unsigned, 4, 30> {};
193 194
194 // BitFields specific to BasicPolicy::FIXED_SLOT. 195 // BitFields specific to BasicPolicy::FIXED_SLOT.
195 class FixedSlotIndexField : public BitField64<int, 34, 30> {}; 196 class FixedSlotIndexField : public BitField<int, 4, 28> {};
196 197
197 // BitFields specific to BasicPolicy::EXTENDED_POLICY. 198 // BitFields specific to BasicPolicy::EXTENDED_POLICY.
198 class ExtendedPolicyField : public BitField64<ExtendedPolicy, 34, 3> {}; 199 class ExtendedPolicyField : public BitField<ExtendedPolicy, 4, 3> {};
199 class LifetimeField : public BitField64<Lifetime, 37, 1> {}; 200 class LifetimeField : public BitField<Lifetime, 7, 1> {};
200 class FixedRegisterField : public BitField64<int, 38, 6> {}; 201 class FixedRegisterField : public BitField<int, 8, 6> {};
201 202
202 static const int kInvalidVirtualRegister = VirtualRegisterField::kMax;
203 static const int kMaxVirtualRegisters = VirtualRegisterField::kMax;
204 static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize; 203 static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize;
205 static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1; 204 static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1;
206 static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1)); 205 static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1));
207 206
208 // Predicates for the operand policy. 207 // Predicates for the operand policy.
209 bool HasAnyPolicy() const { 208 bool HasAnyPolicy() const {
210 return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY; 209 return basic_policy() == EXTENDED_POLICY && extended_policy() == ANY;
211 } 210 }
212 bool HasFixedPolicy() const { 211 bool HasFixedPolicy() const {
213 return basic_policy() == FIXED_SLOT || 212 return basic_policy() == FIXED_SLOT ||
(...skipping 23 matching lines...) Expand all
237 236
238 // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy. 237 // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy.
239 ExtendedPolicy extended_policy() const { 238 ExtendedPolicy extended_policy() const {
240 DCHECK(basic_policy() == EXTENDED_POLICY); 239 DCHECK(basic_policy() == EXTENDED_POLICY);
241 return ExtendedPolicyField::decode(value_); 240 return ExtendedPolicyField::decode(value_);
242 } 241 }
243 242
244 // [fixed_slot_index]: Only for FIXED_SLOT. 243 // [fixed_slot_index]: Only for FIXED_SLOT.
245 int fixed_slot_index() const { 244 int fixed_slot_index() const {
246 DCHECK(HasFixedSlotPolicy()); 245 DCHECK(HasFixedSlotPolicy());
247 return static_cast<int>(bit_cast<int64_t>(value_) >> 246 return static_cast<int>(bit_cast<int32_t>(value_) >>
248 FixedSlotIndexField::kShift); 247 FixedSlotIndexField::kShift);
249 } 248 }
250 249
251 // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER. 250 // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER.
252 int fixed_register_index() const { 251 int fixed_register_index() const {
253 DCHECK(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy()); 252 DCHECK(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy());
254 return FixedRegisterField::decode(value_); 253 return FixedRegisterField::decode(value_);
255 } 254 }
256 255
257 // [virtual_register]: The virtual register ID for this operand. 256 // [virtual_register]: The virtual register ID for this operand.
258 int virtual_register() const { return VirtualRegisterField::decode(value_); } 257 int32_t virtual_register() const { return virtual_register_; }
259 void set_virtual_register(unsigned id) { 258 void set_virtual_register(int32_t id) { virtual_register_ = id; }
260 value_ = VirtualRegisterField::update(value_, id);
261 }
262 259
263 // [lifetime]: Only for non-FIXED_SLOT. 260 // [lifetime]: Only for non-FIXED_SLOT.
264 bool IsUsedAtStart() const { 261 bool IsUsedAtStart() const {
265 DCHECK(basic_policy() == EXTENDED_POLICY); 262 DCHECK(basic_policy() == EXTENDED_POLICY);
266 return LifetimeField::decode(value_) == USED_AT_START; 263 return LifetimeField::decode(value_) == USED_AT_START;
267 } 264 }
265
266 private:
267 // TODO(dcarney): this should really be unsigned.
268 int32_t virtual_register_;
268 }; 269 };
269 270
270 271
271 class MoveOperands FINAL { 272 class MoveOperands FINAL {
272 public: 273 public:
273 MoveOperands(InstructionOperand* source, InstructionOperand* destination) 274 MoveOperands(InstructionOperand* source, InstructionOperand* destination)
274 : source_(source), destination_(destination) {} 275 : source_(source), destination_(destination) {}
275 276
276 InstructionOperand* source() const { return source_; } 277 InstructionOperand* source() const { return source_; }
277 void set_source(InstructionOperand* operand) { source_ = operand; } 278 void set_source(InstructionOperand* operand) { source_ = operand; }
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 // TODO(titzer): s/IsDouble/IsFloat64/ 941 // TODO(titzer): s/IsDouble/IsFloat64/
941 class InstructionSequence FINAL : public ZoneObject { 942 class InstructionSequence FINAL : public ZoneObject {
942 public: 943 public:
943 static InstructionBlocks* InstructionBlocksFor(Zone* zone, 944 static InstructionBlocks* InstructionBlocksFor(Zone* zone,
944 const Schedule* schedule); 945 const Schedule* schedule);
945 // Puts the deferred blocks last. 946 // Puts the deferred blocks last.
946 static void ComputeAssemblyOrder(InstructionBlocks* blocks); 947 static void ComputeAssemblyOrder(InstructionBlocks* blocks);
947 948
948 InstructionSequence(Zone* zone, InstructionBlocks* instruction_blocks); 949 InstructionSequence(Zone* zone, InstructionBlocks* instruction_blocks);
949 950
950 int NextVirtualRegister() { return next_virtual_register_++; } 951 int NextVirtualRegister();
951 int VirtualRegisterCount() const { return next_virtual_register_; } 952 int VirtualRegisterCount() const { return next_virtual_register_; }
952 953
953 const InstructionBlocks& instruction_blocks() const { 954 const InstructionBlocks& instruction_blocks() const {
954 return *instruction_blocks_; 955 return *instruction_blocks_;
955 } 956 }
956 957
957 int InstructionBlockCount() const { 958 int InstructionBlockCount() const {
958 return static_cast<int>(instruction_blocks_->size()); 959 return static_cast<int>(instruction_blocks_->size());
959 } 960 }
960 961
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1088
1088 1089
1089 std::ostream& operator<<(std::ostream& os, 1090 std::ostream& operator<<(std::ostream& os,
1090 const PrintableInstructionSequence& code); 1091 const PrintableInstructionSequence& code);
1091 1092
1092 } // namespace compiler 1093 } // namespace compiler
1093 } // namespace internal 1094 } // namespace internal
1094 } // namespace v8 1095 } // namespace v8
1095 1096
1096 #endif // V8_COMPILER_INSTRUCTION_H_ 1097 #endif // V8_COMPILER_INSTRUCTION_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/instruction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698