LCOV - code coverage report
Current view: top level - src/compiler - type-cache.h (source / functions) Hit Total Coverage
Test: app.info Lines: 22 22 100.0 %
Date: 2017-10-20 Functions: 1 1 100.0 %

          Line data    Source code
       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
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_COMPILER_TYPE_CACHE_H_
       6             : #define V8_COMPILER_TYPE_CACHE_H_
       7             : 
       8             : #include "src/compiler/types.h"
       9             : #include "src/date.h"
      10             : #include "src/objects/code.h"
      11             : #include "src/objects/string.h"
      12             : 
      13             : namespace v8 {
      14             : namespace internal {
      15             : namespace compiler {
      16             : 
      17             : class TypeCache final {
      18             :  private:
      19             :   // This has to be first for the initialization magic to work.
      20             :   AccountingAllocator allocator;
      21             :   Zone zone_;
      22             : 
      23             :  public:
      24             :   static TypeCache const& Get();
      25             : 
      26      623340 :   TypeCache() : zone_(&allocator, ZONE_NAME) {}
      27             : 
      28             :   Type* const kInt8 = CreateRange<int8_t>();
      29             :   Type* const kUint8 = CreateRange<uint8_t>();
      30             :   Type* const kUint8Clamped = kUint8;
      31             :   Type* const kUint8OrMinusZeroOrNaN =
      32       13852 :       Type::Union(kUint8, Type::MinusZeroOrNaN(), zone());
      33             :   Type* const kInt16 = CreateRange<int16_t>();
      34             :   Type* const kUint16 = CreateRange<uint16_t>();
      35             :   Type* const kInt32 = Type::Signed32();
      36             :   Type* const kUint32 = Type::Unsigned32();
      37             :   Type* const kFloat32 = Type::Number();
      38             :   Type* const kFloat64 = Type::Number();
      39             : 
      40             :   Type* const kHoleySmi =
      41       13852 :       Type::Union(Type::SignedSmall(), Type::Hole(), zone());
      42             : 
      43             :   Type* const kSingletonZero = CreateRange(0.0, 0.0);
      44             :   Type* const kSingletonOne = CreateRange(1.0, 1.0);
      45             :   Type* const kSingletonTen = CreateRange(10.0, 10.0);
      46             :   Type* const kSingletonMinusOne = CreateRange(-1.0, -1.0);
      47             :   Type* const kZeroOrUndefined =
      48       13852 :       Type::Union(kSingletonZero, Type::Undefined(), zone());
      49             :   Type* const kTenOrUndefined =
      50       13852 :       Type::Union(kSingletonTen, Type::Undefined(), zone());
      51             :   Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0);
      52             :   Type* const kMinusOneToOneOrMinusZeroOrNaN = Type::Union(
      53             :       Type::Union(CreateRange(-1.0, 1.0), Type::MinusZero(), zone()),
      54       13852 :       Type::NaN(), zone());
      55             :   Type* const kZeroOrOne = CreateRange(0.0, 1.0);
      56       13852 :   Type* const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone());
      57             :   Type* const kZeroToThirtyOne = CreateRange(0.0, 31.0);
      58             :   Type* const kZeroToThirtyTwo = CreateRange(0.0, 32.0);
      59             :   Type* const kZeroish =
      60       13852 :       Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
      61             :   Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
      62             :   Type* const kIntegerOrMinusZero =
      63       13852 :       Type::Union(kInteger, Type::MinusZero(), zone());
      64             :   Type* const kIntegerOrMinusZeroOrNaN =
      65       13852 :       Type::Union(kIntegerOrMinusZero, Type::NaN(), zone());
      66             :   Type* const kPositiveInteger = CreateRange(0.0, V8_INFINITY);
      67             :   Type* const kPositiveIntegerOrMinusZero =
      68       13852 :       Type::Union(kPositiveInteger, Type::MinusZero(), zone());
      69             :   Type* const kPositiveIntegerOrNaN =
      70       13852 :       Type::Union(kPositiveInteger, Type::NaN(), zone());
      71             :   Type* const kPositiveIntegerOrMinusZeroOrNaN =
      72       13852 :       Type::Union(kPositiveIntegerOrMinusZero, Type::NaN(), zone());
      73             : 
      74             :   Type* const kAdditiveSafeInteger =
      75             :       CreateRange(-4503599627370496.0, 4503599627370496.0);
      76             :   Type* const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger);
      77             :   Type* const kAdditiveSafeIntegerOrMinusZero =
      78       13852 :       Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone());
      79             :   Type* const kSafeIntegerOrMinusZero =
      80       13852 :       Type::Union(kSafeInteger, Type::MinusZero(), zone());
      81             :   Type* const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger);
      82             : 
      83             :   // The FixedArray::length property always containts a smi in the range
      84             :   // [0, FixedArray::kMaxLength].
      85             :   Type* const kFixedArrayLengthType = CreateRange(0.0, FixedArray::kMaxLength);
      86             : 
      87             :   // The FixedDoubleArray::length property always containts a smi in the range
      88             :   // [0, FixedDoubleArray::kMaxLength].
      89             :   Type* const kFixedDoubleArrayLengthType =
      90             :       CreateRange(0.0, FixedDoubleArray::kMaxLength);
      91             : 
      92             :   // The JSArray::length property always contains a tagged number in the range
      93             :   // [0, kMaxUInt32].
      94             :   Type* const kJSArrayLengthType = Type::Unsigned32();
      95             : 
      96             :   // The JSTyped::length property always contains a tagged number in the range
      97             :   // [0, kMaxSmiValue].
      98             :   Type* const kJSTypedArrayLengthType = Type::UnsignedSmall();
      99             : 
     100             :   // The String::length property always contains a smi in the range
     101             :   // [0, String::kMaxLength].
     102             :   Type* const kStringLengthType = CreateRange(0.0, String::kMaxLength);
     103             : 
     104             :   // A time value always contains a tagged number in the range
     105             :   // [-kMaxTimeInMs, kMaxTimeInMs].
     106             :   Type* const kTimeValueType =
     107             :       CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs);
     108             : 
     109             :   // The JSDate::day property always contains a tagged number in the range
     110             :   // [1, 31] or NaN.
     111             :   Type* const kJSDateDayType =
     112       13852 :       Type::Union(CreateRange(1, 31.0), Type::NaN(), zone());
     113             : 
     114             :   // The JSDate::hour property always contains a tagged number in the range
     115             :   // [0, 23] or NaN.
     116             :   Type* const kJSDateHourType =
     117       13852 :       Type::Union(CreateRange(0, 23.0), Type::NaN(), zone());
     118             : 
     119             :   // The JSDate::minute property always contains a tagged number in the range
     120             :   // [0, 59] or NaN.
     121             :   Type* const kJSDateMinuteType =
     122       13852 :       Type::Union(CreateRange(0, 59.0), Type::NaN(), zone());
     123             : 
     124             :   // The JSDate::month property always contains a tagged number in the range
     125             :   // [0, 11] or NaN.
     126             :   Type* const kJSDateMonthType =
     127       13852 :       Type::Union(CreateRange(0, 11.0), Type::NaN(), zone());
     128             : 
     129             :   // The JSDate::second property always contains a tagged number in the range
     130             :   // [0, 59] or NaN.
     131             :   Type* const kJSDateSecondType = kJSDateMinuteType;
     132             : 
     133             :   // The JSDate::value property always contains a tagged number in the range
     134             :   // [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
     135             :   Type* const kJSDateValueType =
     136       13852 :       Type::Union(kTimeValueType, Type::NaN(), zone());
     137             : 
     138             :   // The JSDate::weekday property always contains a tagged number in the range
     139             :   // [0, 6] or NaN.
     140             :   Type* const kJSDateWeekdayType =
     141       13852 :       Type::Union(CreateRange(0, 6.0), Type::NaN(), zone());
     142             : 
     143             :   // The JSDate::year property always contains a tagged number in the signed
     144             :   // small range or NaN.
     145             :   Type* const kJSDateYearType =
     146       13852 :       Type::Union(Type::SignedSmall(), Type::NaN(), zone());
     147             : 
     148             :   // The valid number of arguments for JavaScript functions.
     149             :   Type* const kArgumentsLengthType =
     150             :       Type::Range(0.0, Code::kMaxArguments, zone());
     151             : 
     152             :  private:
     153             :   template <typename T>
     154             :   Type* CreateRange() {
     155             :     return CreateRange(std::numeric_limits<T>::min(),
     156             :                        std::numeric_limits<T>::max());
     157             :   }
     158             : 
     159             :   Type* CreateRange(double min, double max) {
     160             :     return Type::Range(min, max, zone());
     161             :   }
     162             : 
     163             :   Zone* zone() { return &zone_; }
     164             : };
     165             : 
     166             : }  // namespace compiler
     167             : }  // namespace internal
     168             : }  // namespace v8
     169             : 
     170             : #endif  // V8_COMPILER_TYPE_CACHE_H_

Generated by: LCOV version 1.10