OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 | 184 |
185 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ | 185 #define DECLARE_CONCRETE_INSTRUCTION(type, mnemonic) \ |
186 virtual LInstruction* CompileToLithium(LChunkBuilder* builder); \ | 186 virtual LInstruction* CompileToLithium(LChunkBuilder* builder); \ |
187 virtual const char* Mnemonic() const { return mnemonic; } \ | 187 virtual const char* Mnemonic() const { return mnemonic; } \ |
188 DECLARE_INSTRUCTION(type) | 188 DECLARE_INSTRUCTION(type) |
189 | 189 |
190 | 190 |
191 class Range: public ZoneObject { | 191 class Range: public ZoneObject { |
192 public: | 192 public: |
193 Range() : lower_(kMinInt), | 193 Range() |
194 upper_(kMaxInt), | 194 : lower_(kMinInt), |
195 next_(NULL), | 195 upper_(kMaxInt), |
196 can_be_minus_zero_(false) { } | 196 next_(NULL), |
| 197 can_be_minus_zero_(false) { } |
197 | 198 |
198 Range(int32_t lower, int32_t upper) | 199 Range(int32_t lower, int32_t upper) |
199 : lower_(lower), upper_(upper), next_(NULL), can_be_minus_zero_(false) { } | 200 : lower_(lower), |
| 201 upper_(upper), |
| 202 next_(NULL), |
| 203 can_be_minus_zero_(false) { } |
200 | 204 |
| 205 int32_t upper() const { return upper_; } |
| 206 int32_t lower() const { return lower_; } |
| 207 Range* next() const { return next_; } |
| 208 Range* CopyClearLower() const { return new Range(kMinInt, upper_); } |
| 209 Range* CopyClearUpper() const { return new Range(lower_, kMaxInt); } |
| 210 Range* Copy() const { return new Range(lower_, upper_); } |
| 211 int32_t Mask() const; |
| 212 void set_can_be_minus_zero(bool b) { can_be_minus_zero_ = b; } |
| 213 bool CanBeMinusZero() const { return CanBeZero() && can_be_minus_zero_; } |
| 214 bool CanBeZero() const { return upper_ >= 0 && lower_ <= 0; } |
| 215 bool CanBeNegative() const { return lower_ < 0; } |
| 216 bool Includes(int value) const { return lower_ <= value && upper_ >= value; } |
| 217 bool IsMostGeneric() const { return lower_ == kMinInt && upper_ == kMaxInt; } |
201 bool IsInSmiRange() const { | 218 bool IsInSmiRange() const { |
202 return lower_ >= Smi::kMinValue && upper_ <= Smi::kMaxValue; | 219 return lower_ >= Smi::kMinValue && upper_ <= Smi::kMaxValue; |
203 } | 220 } |
204 void KeepOrder(); | 221 void KeepOrder(); |
205 void Verify() const; | 222 void Verify() const; |
206 int32_t upper() const { return upper_; } | |
207 int32_t lower() const { return lower_; } | |
208 Range* next() const { return next_; } | |
209 Range* CopyClearLower() const { return new Range(kMinInt, upper_); } | |
210 Range* CopyClearUpper() const { return new Range(lower_, kMaxInt); } | |
211 void ClearLower() { lower_ = kMinInt; } | |
212 void ClearUpper() { upper_ = kMaxInt; } | |
213 Range* Copy() const { return new Range(lower_, upper_); } | |
214 bool IsMostGeneric() const { return lower_ == kMinInt && upper_ == kMaxInt; } | |
215 int32_t Mask() const; | |
216 void set_can_be_minus_zero(bool b) { can_be_minus_zero_ = b; } | |
217 bool CanBeMinusZero() const { return CanBeZero() && can_be_minus_zero_; } | |
218 bool CanBeZero() const { return upper_ >= 0 && lower_ <= 0; } | |
219 bool CanBeNegative() const { return lower_ < 0; } | |
220 bool Includes(int value) const { | |
221 return lower_ <= value && upper_ >= value; | |
222 } | |
223 | |
224 void Sar(int32_t value) { | |
225 int32_t bits = value & 0x1F; | |
226 lower_ = lower_ >> bits; | |
227 upper_ = upper_ >> bits; | |
228 set_can_be_minus_zero(false); | |
229 } | |
230 | |
231 void Shl(int32_t value) { | |
232 int32_t bits = value & 0x1F; | |
233 int old_lower = lower_; | |
234 int old_upper = upper_; | |
235 lower_ = lower_ << bits; | |
236 upper_ = upper_ << bits; | |
237 if (old_lower != lower_ >> bits || old_upper != upper_ >> bits) { | |
238 upper_ = kMaxInt; | |
239 lower_ = kMinInt; | |
240 } | |
241 set_can_be_minus_zero(false); | |
242 } | |
243 | |
244 // Adds a constant to the lower and upper bound of the range. | |
245 void AddConstant(int32_t value); | |
246 | 223 |
247 void StackUpon(Range* other) { | 224 void StackUpon(Range* other) { |
248 Intersect(other); | 225 Intersect(other); |
249 next_ = other; | 226 next_ = other; |
250 } | 227 } |
251 | 228 |
252 void Intersect(Range* other) { | 229 void Intersect(Range* other); |
253 upper_ = Min(upper_, other->upper_); | 230 void Union(Range* other); |
254 lower_ = Max(lower_, other->lower_); | |
255 bool b = CanBeMinusZero() && other->CanBeMinusZero(); | |
256 set_can_be_minus_zero(b); | |
257 } | |
258 | 231 |
259 void Union(Range* other) { | 232 void AddConstant(int32_t value); |
260 upper_ = Max(upper_, other->upper_); | 233 void Sar(int32_t value); |
261 lower_ = Min(lower_, other->lower_); | 234 void Shl(int32_t value); |
262 bool b = CanBeMinusZero() || other->CanBeMinusZero(); | |
263 set_can_be_minus_zero(b); | |
264 } | |
265 | |
266 // Compute a new result range and return true, if the operation | |
267 // can overflow. | |
268 bool AddAndCheckOverflow(Range* other); | 235 bool AddAndCheckOverflow(Range* other); |
269 bool SubAndCheckOverflow(Range* other); | 236 bool SubAndCheckOverflow(Range* other); |
270 bool MulAndCheckOverflow(Range* other); | 237 bool MulAndCheckOverflow(Range* other); |
271 | 238 |
272 private: | 239 private: |
273 int32_t lower_; | 240 int32_t lower_; |
274 int32_t upper_; | 241 int32_t upper_; |
275 Range* next_; | 242 Range* next_; |
276 bool can_be_minus_zero_; | 243 bool can_be_minus_zero_; |
277 }; | 244 }; |
(...skipping 3201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3479 HValue* object() { return left(); } | 3446 HValue* object() { return left(); } |
3480 HValue* key() { return right(); } | 3447 HValue* key() { return right(); } |
3481 }; | 3448 }; |
3482 | 3449 |
3483 #undef DECLARE_INSTRUCTION | 3450 #undef DECLARE_INSTRUCTION |
3484 #undef DECLARE_CONCRETE_INSTRUCTION | 3451 #undef DECLARE_CONCRETE_INSTRUCTION |
3485 | 3452 |
3486 } } // namespace v8::internal | 3453 } } // namespace v8::internal |
3487 | 3454 |
3488 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 3455 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
OLD | NEW |