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 #include "src/base/flags.h" | 5 #include "src/base/flags.h" |
6 #include "src/bootstrapper.h" | 6 #include "src/bootstrapper.h" |
7 #include "src/compiler/graph-reducer.h" | 7 #include "src/compiler/graph-reducer.h" |
8 #include "src/compiler/js-operator.h" | 8 #include "src/compiler/js-operator.h" |
9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 static Type* ToNumber(Type*, Typer*); | 343 static Type* ToNumber(Type*, Typer*); |
344 static Type* ToString(Type*, Typer*); | 344 static Type* ToString(Type*, Typer*); |
345 static Type* NumberToInt32(Type*, Typer*); | 345 static Type* NumberToInt32(Type*, Typer*); |
346 static Type* NumberToUint32(Type*, Typer*); | 346 static Type* NumberToUint32(Type*, Typer*); |
347 | 347 |
348 static Type* JSAddRanger(Type::RangeType*, Type::RangeType*, Typer*); | 348 static Type* JSAddRanger(Type::RangeType*, Type::RangeType*, Typer*); |
349 static Type* JSSubtractRanger(Type::RangeType*, Type::RangeType*, Typer*); | 349 static Type* JSSubtractRanger(Type::RangeType*, Type::RangeType*, Typer*); |
350 static Type* JSMultiplyRanger(Type::RangeType*, Type::RangeType*, Typer*); | 350 static Type* JSMultiplyRanger(Type::RangeType*, Type::RangeType*, Typer*); |
351 static Type* JSDivideRanger(Type::RangeType*, Type::RangeType*, Typer*); | 351 static Type* JSDivideRanger(Type::RangeType*, Type::RangeType*, Typer*); |
352 static Type* JSModulusRanger(Type::RangeType*, Type::RangeType*, Typer*); | 352 static Type* JSModulusRanger(Type::RangeType*, Type::RangeType*, Typer*); |
| 353 static Type* JSExponentiateRanger(Type::RangeType*, Type::RangeType*, Typer*); |
353 | 354 |
354 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); | 355 static ComparisonOutcome JSCompareTyper(Type*, Type*, Typer*); |
355 | 356 |
356 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); | 357 #define DECLARE_METHOD(x) static Type* x##Typer(Type*, Type*, Typer*); |
357 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) | 358 JS_SIMPLE_BINOP_LIST(DECLARE_METHOD) |
358 #undef DECLARE_METHOD | 359 #undef DECLARE_METHOD |
359 | 360 |
360 static Type* JSUnaryNotTyper(Type*, Typer*); | 361 static Type* JSUnaryNotTyper(Type*, Typer*); |
361 static Type* JSLoadPropertyTyper(Type*, Type*, Typer*); | 362 static Type* JSLoadPropertyTyper(Type*, Type*, Typer*); |
362 static Type* JSCallFunctionTyper(Type*, Typer*); | 363 static Type* JSCallFunctionTyper(Type*, Typer*); |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 | 1217 |
1217 lhs = Rangify(lhs, t); | 1218 lhs = Rangify(lhs, t); |
1218 rhs = Rangify(rhs, t); | 1219 rhs = Rangify(rhs, t); |
1219 if (lhs->IsRange() && rhs->IsRange()) { | 1220 if (lhs->IsRange() && rhs->IsRange()) { |
1220 return JSModulusRanger(lhs->AsRange(), rhs->AsRange(), t); | 1221 return JSModulusRanger(lhs->AsRange(), rhs->AsRange(), t); |
1221 } | 1222 } |
1222 return Type::OrderedNumber(); | 1223 return Type::OrderedNumber(); |
1223 } | 1224 } |
1224 | 1225 |
1225 | 1226 |
| 1227 Type* Typer::Visitor::JSExponentiateRanger(Type::RangeType* lhs, |
| 1228 Type::RangeType* rhs, Typer* t) { |
| 1229 double lmin = lhs->Min(); |
| 1230 double lmax = lhs->Max(); |
| 1231 double rmin = rhs->Min(); |
| 1232 double rmax = rhs->Max(); |
| 1233 |
| 1234 if (lmin > 0.0) { |
| 1235 // +x ** -y : epsilon...1 |
| 1236 if (rmax < 0.0) return Type::Range(0.0, 1.0, t->zone()); |
| 1237 |
| 1238 // +x ** +y : epsilon...infinity |
| 1239 if (rmin > 0.0) return Type::Range(0.0, +V8_INFINITY, t->zone()); |
| 1240 } else if (lmax < 0.0) { |
| 1241 // -x ** -y : -1.0...1.0 |
| 1242 if (rmax < 0.0) return Type::Range(-1.0, 1.0, t->zone()); |
| 1243 } |
| 1244 |
| 1245 // pow(lmin, rmax) does not limit range by much. |
| 1246 return Type::Number(); |
| 1247 } |
| 1248 |
| 1249 |
| 1250 Type* Typer::Visitor::JSExponentiateTyper(Type* lhs, Type* rhs, Typer* t) { |
| 1251 lhs = ToNumber(lhs, t); |
| 1252 rhs = ToNumber(rhs, t); |
| 1253 |
| 1254 // x ** NaN|undefined : NaN |
| 1255 if (rhs->Is(Type::NaN())) return Type::NaN(); |
| 1256 |
| 1257 // x ** 0|false|null : 1 |
| 1258 if (rhs->Is(t->singleton_zero)) return t->singleton_one; |
| 1259 |
| 1260 // NaN ** x [~0] : NaN |
| 1261 if (lhs->Is(Type::NaN())) return Type::NaN(); |
| 1262 |
| 1263 // 0|false|null ** x [~0] : 0 |
| 1264 if (lhs->Is(t->singleton_zero)) return t->singleton_zero; |
| 1265 |
| 1266 lhs = Rangify(lhs, t); |
| 1267 rhs = Rangify(rhs, t); |
| 1268 if (lhs->IsRange() && rhs->IsRange()) { |
| 1269 return JSExponentiateRanger(lhs->AsRange(), rhs->AsRange(), t); |
| 1270 } |
| 1271 return Type::Number(); |
| 1272 } |
| 1273 |
| 1274 |
1226 // JS unary operators. | 1275 // JS unary operators. |
1227 | 1276 |
1228 | 1277 |
1229 Type* Typer::Visitor::JSUnaryNotTyper(Type* type, Typer* t) { | 1278 Type* Typer::Visitor::JSUnaryNotTyper(Type* type, Typer* t) { |
1230 return Invert(ToBoolean(type, t), t); | 1279 return Invert(ToBoolean(type, t), t); |
1231 } | 1280 } |
1232 | 1281 |
1233 | 1282 |
1234 Bounds Typer::Visitor::TypeJSUnaryNot(Node* node) { | 1283 Bounds Typer::Visitor::TypeJSUnaryNot(Node* node) { |
1235 return TypeUnaryOp(node, JSUnaryNotTyper); | 1284 return TypeUnaryOp(node, JSUnaryNotTyper); |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2184 TYPED_ARRAYS(TYPED_ARRAY_CASE) | 2233 TYPED_ARRAYS(TYPED_ARRAY_CASE) |
2185 #undef TYPED_ARRAY_CASE | 2234 #undef TYPED_ARRAY_CASE |
2186 } | 2235 } |
2187 } | 2236 } |
2188 return Type::Constant(value, zone()); | 2237 return Type::Constant(value, zone()); |
2189 } | 2238 } |
2190 | 2239 |
2191 } // namespace compiler | 2240 } // namespace compiler |
2192 } // namespace internal | 2241 } // namespace internal |
2193 } // namespace v8 | 2242 } // namespace v8 |
OLD | NEW |