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

Side by Side Diff: src/compiler/typer.cc

Issue 2116753002: [builtins] Unify most of the remaining Math builtins. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2102223005
Patch Set: Created 4 years, 5 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
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 #include "src/compiler/typer.h" 5 #include "src/compiler/typer.h"
6 6
7 #include "src/base/flags.h" 7 #include "src/base/flags.h"
8 #include "src/bootstrapper.h" 8 #include "src/bootstrapper.h"
9 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
10 #include "src/compiler/common-operator.h" 10 #include "src/compiler/common-operator.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 static Type* ToInteger(Type*, Typer*); 251 static Type* ToInteger(Type*, Typer*);
252 static Type* ToLength(Type*, Typer*); 252 static Type* ToLength(Type*, Typer*);
253 static Type* ToName(Type*, Typer*); 253 static Type* ToName(Type*, Typer*);
254 static Type* ToNumber(Type*, Typer*); 254 static Type* ToNumber(Type*, Typer*);
255 static Type* ToObject(Type*, Typer*); 255 static Type* ToObject(Type*, Typer*);
256 static Type* ToString(Type*, Typer*); 256 static Type* ToString(Type*, Typer*);
257 static Type* NumberAbs(Type*, Typer*); 257 static Type* NumberAbs(Type*, Typer*);
258 static Type* NumberCeil(Type*, Typer*); 258 static Type* NumberCeil(Type*, Typer*);
259 static Type* NumberFloor(Type*, Typer*); 259 static Type* NumberFloor(Type*, Typer*);
260 static Type* NumberRound(Type*, Typer*); 260 static Type* NumberRound(Type*, Typer*);
261 static Type* NumberSign(Type*, Typer*);
261 static Type* NumberTrunc(Type*, Typer*); 262 static Type* NumberTrunc(Type*, Typer*);
262 static Type* NumberToInt32(Type*, Typer*); 263 static Type* NumberToInt32(Type*, Typer*);
263 static Type* NumberToUint32(Type*, Typer*); 264 static Type* NumberToUint32(Type*, Typer*);
264 265
265 static Type* ObjectIsCallable(Type*, Typer*); 266 static Type* ObjectIsCallable(Type*, Typer*);
266 static Type* ObjectIsNumber(Type*, Typer*); 267 static Type* ObjectIsNumber(Type*, Typer*);
267 static Type* ObjectIsReceiver(Type*, Typer*); 268 static Type* ObjectIsReceiver(Type*, Typer*);
268 static Type* ObjectIsSmi(Type*, Typer*); 269 static Type* ObjectIsSmi(Type*, Typer*);
269 static Type* ObjectIsString(Type*, Typer*); 270 static Type* ObjectIsString(Type*, Typer*);
270 static Type* ObjectIsUndetectable(Type*, Typer*); 271 static Type* ObjectIsUndetectable(Type*, Typer*);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 537
537 // static 538 // static
538 Type* Typer::Visitor::NumberRound(Type* type, Typer* t) { 539 Type* Typer::Visitor::NumberRound(Type* type, Typer* t) {
539 DCHECK(type->Is(Type::Number())); 540 DCHECK(type->Is(Type::Number()));
540 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; 541 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type;
541 // TODO(bmeurer): We could infer a more precise type here. 542 // TODO(bmeurer): We could infer a more precise type here.
542 return t->cache_.kIntegerOrMinusZeroOrNaN; 543 return t->cache_.kIntegerOrMinusZeroOrNaN;
543 } 544 }
544 545
545 // static 546 // static
547 Type* Typer::Visitor::NumberSign(Type* type, Typer* t) {
548 DCHECK(type->Is(Type::Number()));
549 if (type->Is(t->cache_.kZeroish)) return type;
550 bool maybe_minuszero = type->Maybe(Type::MinusZero());
551 bool maybe_nan = type->Maybe(Type::NaN());
552 type = Type::Intersect(type, Type::PlainNumber(), t->zone());
553 if (type->Max() < 0.0) {
554 type = t->cache_.kSingletonMinusOne;
555 } else if (type->Max() <= 0.0) {
556 type = t->cache_.kMinusOneOrZero;
557 } else if (type->Min() > 0.0) {
558 type = t->cache_.kSingletonOne;
559 } else if (type->Min() >= 0.0) {
560 type = t->cache_.kZeroOrOne;
561 } else {
562 type = Type::Range(-1.0, 1.0, t->zone());
563 }
564 if (maybe_minuszero) {
565 type = Type::Union(type, Type::MinusZero(), t->zone());
566 }
567 if (maybe_nan) {
568 type = Type::Union(type, Type::NaN(), t->zone());
569 }
570 return type;
571 }
572
573 // static
546 Type* Typer::Visitor::NumberTrunc(Type* type, Typer* t) { 574 Type* Typer::Visitor::NumberTrunc(Type* type, Typer* t) {
547 DCHECK(type->Is(Type::Number())); 575 DCHECK(type->Is(Type::Number()));
548 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type; 576 if (type->Is(t->cache_.kIntegerOrMinusZeroOrNaN)) return type;
549 // TODO(bmeurer): We could infer a more precise type here. 577 // TODO(bmeurer): We could infer a more precise type here.
550 return t->cache_.kIntegerOrMinusZeroOrNaN; 578 return t->cache_.kIntegerOrMinusZeroOrNaN;
551 } 579 }
552 580
553 Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) { 581 Type* Typer::Visitor::NumberToInt32(Type* type, Typer* t) {
554 if (type->Is(Type::Signed32())) return type; 582 if (type->Is(Type::Signed32())) return type;
555 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero; 583 if (type->Is(t->cache_.kZeroish)) return t->cache_.kSingletonZero;
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
1377 // Unary math functions. 1405 // Unary math functions.
1378 case kMathAbs: 1406 case kMathAbs:
1379 case kMathExp: 1407 case kMathExp:
1380 return Type::Union(Type::PlainNumber(), Type::NaN(), t->zone()); 1408 return Type::Union(Type::PlainNumber(), Type::NaN(), t->zone());
1381 case kMathLog: 1409 case kMathLog:
1382 case kMathSqrt: 1410 case kMathSqrt:
1383 case kMathCos: 1411 case kMathCos:
1384 case kMathSin: 1412 case kMathSin:
1385 case kMathTan: 1413 case kMathTan:
1386 case kMathAcos: 1414 case kMathAcos:
1415 case kMathAcosh:
1387 case kMathAsin: 1416 case kMathAsin:
1417 case kMathAsinh:
1388 case kMathAtan: 1418 case kMathAtan:
1419 case kMathAtanh:
1389 case kMathFround: 1420 case kMathFround:
1421 case kMathSign:
1390 return Type::Number(); 1422 return Type::Number();
1391 // Binary math functions. 1423 // Binary math functions.
1392 case kMathAtan2: 1424 case kMathAtan2:
1393 case kMathPow: 1425 case kMathPow:
1394 case kMathMax: 1426 case kMathMax:
1395 case kMathMin: 1427 case kMathMin:
1396 return Type::Number(); 1428 return Type::Number();
1397 case kMathImul: 1429 case kMathImul:
1398 return Type::Signed32(); 1430 return Type::Signed32();
1399 case kMathClz32: 1431 case kMathClz32:
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 Type* Typer::Visitor::TypeNumberCeil(Node* node) { 1665 Type* Typer::Visitor::TypeNumberCeil(Node* node) {
1634 return TypeUnaryOp(node, NumberCeil); 1666 return TypeUnaryOp(node, NumberCeil);
1635 } 1667 }
1636 1668
1637 Type* Typer::Visitor::TypeNumberFloor(Node* node) { 1669 Type* Typer::Visitor::TypeNumberFloor(Node* node) {
1638 return TypeUnaryOp(node, NumberFloor); 1670 return TypeUnaryOp(node, NumberFloor);
1639 } 1671 }
1640 1672
1641 Type* Typer::Visitor::TypeNumberFround(Node* node) { return Type::Number(); } 1673 Type* Typer::Visitor::TypeNumberFround(Node* node) { return Type::Number(); }
1642 1674
1675 Type* Typer::Visitor::TypeNumberSign(Node* node) {
1676 return TypeUnaryOp(node, NumberSign);
1677 }
1678
1679 Type* Typer::Visitor::TypeNumberAcos(Node* node) { return Type::Number(); }
1680
1681 Type* Typer::Visitor::TypeNumberAcosh(Node* node) { return Type::Number(); }
1682
1683 Type* Typer::Visitor::TypeNumberAsin(Node* node) { return Type::Number(); }
1684
1685 Type* Typer::Visitor::TypeNumberAsinh(Node* node) { return Type::Number(); }
1686
1643 Type* Typer::Visitor::TypeNumberAtan(Node* node) { return Type::Number(); } 1687 Type* Typer::Visitor::TypeNumberAtan(Node* node) { return Type::Number(); }
1644 1688
1689 Type* Typer::Visitor::TypeNumberAtanh(Node* node) { return Type::Number(); }
1690
1645 Type* Typer::Visitor::TypeNumberAtan2(Node* node) { return Type::Number(); } 1691 Type* Typer::Visitor::TypeNumberAtan2(Node* node) { return Type::Number(); }
1646 1692
1647 Type* Typer::Visitor::TypeNumberAtanh(Node* node) { return Type::Number(); }
1648
1649 Type* Typer::Visitor::TypeNumberCos(Node* node) { return Type::Number(); } 1693 Type* Typer::Visitor::TypeNumberCos(Node* node) { return Type::Number(); }
1650 1694
1651 Type* Typer::Visitor::TypeNumberCosh(Node* node) { return Type::Number(); } 1695 Type* Typer::Visitor::TypeNumberCosh(Node* node) { return Type::Number(); }
1652 1696
1653 Type* Typer::Visitor::TypeNumberExp(Node* node) { 1697 Type* Typer::Visitor::TypeNumberExp(Node* node) {
1654 return Type::Union(Type::PlainNumber(), Type::NaN(), zone()); 1698 return Type::Union(Type::PlainNumber(), Type::NaN(), zone());
1655 } 1699 }
1656 1700
1657 // TODO(mvstanton): Is this type sufficient, or should it look like Exp()? 1701 // TODO(mvstanton): Is this type sufficient, or should it look like Exp()?
1658 Type* Typer::Visitor::TypeNumberExpm1(Node* node) { return Type::Number(); } 1702 Type* Typer::Visitor::TypeNumberExpm1(Node* node) { return Type::Number(); }
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
2317 2361
2318 2362
2319 Type* Typer::Visitor::TypeFloat64Min(Node* node) { return Type::Number(); } 2363 Type* Typer::Visitor::TypeFloat64Min(Node* node) { return Type::Number(); }
2320 2364
2321 2365
2322 Type* Typer::Visitor::TypeFloat64Abs(Node* node) { 2366 Type* Typer::Visitor::TypeFloat64Abs(Node* node) {
2323 // TODO(turbofan): We should be able to infer a better type here. 2367 // TODO(turbofan): We should be able to infer a better type here.
2324 return Type::Number(); 2368 return Type::Number();
2325 } 2369 }
2326 2370
2371 Type* Typer::Visitor::TypeFloat64Acos(Node* node) { return Type::Number(); }
2372
2373 Type* Typer::Visitor::TypeFloat64Acosh(Node* node) { return Type::Number(); }
2374
2375 Type* Typer::Visitor::TypeFloat64Asin(Node* node) { return Type::Number(); }
2376
2377 Type* Typer::Visitor::TypeFloat64Asinh(Node* node) { return Type::Number(); }
2378
2327 Type* Typer::Visitor::TypeFloat64Atan(Node* node) { return Type::Number(); } 2379 Type* Typer::Visitor::TypeFloat64Atan(Node* node) { return Type::Number(); }
2328 2380
2381 Type* Typer::Visitor::TypeFloat64Atanh(Node* node) { return Type::Number(); }
2382
2329 Type* Typer::Visitor::TypeFloat64Atan2(Node* node) { return Type::Number(); } 2383 Type* Typer::Visitor::TypeFloat64Atan2(Node* node) { return Type::Number(); }
2330 2384
2331 Type* Typer::Visitor::TypeFloat64Atanh(Node* node) { return Type::Number(); }
2332
2333 Type* Typer::Visitor::TypeFloat64Cbrt(Node* node) { return Type::Number(); } 2385 Type* Typer::Visitor::TypeFloat64Cbrt(Node* node) { return Type::Number(); }
2334 2386
2335 Type* Typer::Visitor::TypeFloat64Cos(Node* node) { return Type::Number(); } 2387 Type* Typer::Visitor::TypeFloat64Cos(Node* node) { return Type::Number(); }
2336 2388
2337 Type* Typer::Visitor::TypeFloat64Cosh(Node* node) { return Type::Number(); } 2389 Type* Typer::Visitor::TypeFloat64Cosh(Node* node) { return Type::Number(); }
2338 2390
2339 Type* Typer::Visitor::TypeFloat64Exp(Node* node) { return Type::Number(); } 2391 Type* Typer::Visitor::TypeFloat64Exp(Node* node) { return Type::Number(); }
2340 2392
2341 Type* Typer::Visitor::TypeFloat64Expm1(Node* node) { return Type::Number(); } 2393 Type* Typer::Visitor::TypeFloat64Expm1(Node* node) { return Type::Number(); }
2342 2394
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2518 } 2570 }
2519 if (Type::IsInteger(*value)) { 2571 if (Type::IsInteger(*value)) {
2520 return Type::Range(value->Number(), value->Number(), zone()); 2572 return Type::Range(value->Number(), value->Number(), zone());
2521 } 2573 }
2522 return Type::Constant(value, zone()); 2574 return Type::Constant(value, zone());
2523 } 2575 }
2524 2576
2525 } // namespace compiler 2577 } // namespace compiler
2526 } // namespace internal 2578 } // namespace internal
2527 } // namespace v8 2579 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698