LCOV - code coverage report
Current view: top level - src/compiler - type-cache.h (source / functions) Hit Total Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2019-04-19 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/js-array-buffer.h"
      12             : #include "src/objects/string.h"
      13             : 
      14             : namespace v8 {
      15             : namespace internal {
      16             : namespace compiler {
      17             : 
      18             : class V8_EXPORT_PRIVATE TypeCache final {
      19             :  private:
      20             :   // This has to be first for the initialization magic to work.
      21             :   AccountingAllocator allocator;
      22             :   Zone zone_;
      23             : 
      24             :  public:
      25             :   static TypeCache const* Get();
      26             : 
      27      552928 :   TypeCache() : zone_(&allocator, ZONE_NAME) {}
      28             : 
      29             :   Type const kInt8 = CreateRange<int8_t>();
      30             :   Type const kUint8 = CreateRange<uint8_t>();
      31             :   Type const kUint8Clamped = kUint8;
      32             :   Type const kUint8OrMinusZeroOrNaN =
      33             :       Type::Union(kUint8, Type::MinusZeroOrNaN(), zone());
      34             :   Type const kInt16 = CreateRange<int16_t>();
      35             :   Type const kUint16 = CreateRange<uint16_t>();
      36             :   Type const kInt32 = Type::Signed32();
      37             :   Type const kUint32 = Type::Unsigned32();
      38             :   Type const kInt64 = CreateRange<int64_t>();
      39             :   Type const kUint64 = CreateRange<uint64_t>();
      40             :   Type const kFloat32 = Type::Number();
      41             :   Type const kFloat64 = Type::Number();
      42             :   Type const kBigInt64 = Type::BigInt();
      43             :   Type const kBigUint64 = Type::BigInt();
      44             : 
      45             :   Type const kHoleySmi = Type::Union(Type::SignedSmall(), Type::Hole(), zone());
      46             : 
      47             :   Type const kSingletonZero = CreateRange(0.0, 0.0);
      48             :   Type const kSingletonOne = CreateRange(1.0, 1.0);
      49             :   Type const kSingletonTen = CreateRange(10.0, 10.0);
      50             :   Type const kSingletonMinusOne = CreateRange(-1.0, -1.0);
      51             :   Type const kZeroOrMinusZero =
      52             :       Type::Union(kSingletonZero, Type::MinusZero(), zone());
      53             :   Type const kZeroOrUndefined =
      54             :       Type::Union(kSingletonZero, Type::Undefined(), zone());
      55             :   Type const kTenOrUndefined =
      56             :       Type::Union(kSingletonTen, Type::Undefined(), zone());
      57             :   Type const kMinusOneOrZero = CreateRange(-1.0, 0.0);
      58             :   Type const kMinusOneToOneOrMinusZeroOrNaN = Type::Union(
      59             :       Type::Union(CreateRange(-1.0, 1.0), Type::MinusZero(), zone()),
      60       14944 :       Type::NaN(), zone());
      61             :   Type const kZeroOrOne = CreateRange(0.0, 1.0);
      62             :   Type const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone());
      63             :   Type const kZeroToThirtyOne = CreateRange(0.0, 31.0);
      64             :   Type const kZeroToThirtyTwo = CreateRange(0.0, 32.0);
      65             :   Type const kZeroish =
      66             :       Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
      67             :   Type const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
      68             :   Type const kIntegerOrMinusZero =
      69             :       Type::Union(kInteger, Type::MinusZero(), zone());
      70             :   Type const kIntegerOrMinusZeroOrNaN =
      71             :       Type::Union(kIntegerOrMinusZero, Type::NaN(), zone());
      72             :   Type const kPositiveInteger = CreateRange(0.0, V8_INFINITY);
      73             :   Type const kPositiveIntegerOrMinusZero =
      74             :       Type::Union(kPositiveInteger, Type::MinusZero(), zone());
      75             :   Type const kPositiveIntegerOrNaN =
      76             :       Type::Union(kPositiveInteger, Type::NaN(), zone());
      77             :   Type const kPositiveIntegerOrMinusZeroOrNaN =
      78             :       Type::Union(kPositiveIntegerOrMinusZero, Type::NaN(), zone());
      79             : 
      80             :   Type const kAdditiveSafeInteger =
      81             :       CreateRange(-4503599627370496.0, 4503599627370496.0);
      82             :   Type const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger);
      83             :   Type const kAdditiveSafeIntegerOrMinusZero =
      84             :       Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone());
      85             :   Type const kSafeIntegerOrMinusZero =
      86             :       Type::Union(kSafeInteger, Type::MinusZero(), zone());
      87             :   Type const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger);
      88             : 
      89             :   // The FixedArray::length property always containts a smi in the range
      90             :   // [0, FixedArray::kMaxLength].
      91             :   Type const kFixedArrayLengthType = CreateRange(0.0, FixedArray::kMaxLength);
      92             : 
      93             :   // The FixedDoubleArray::length property always containts a smi in the range
      94             :   // [0, FixedDoubleArray::kMaxLength].
      95             :   Type const kFixedDoubleArrayLengthType =
      96             :       CreateRange(0.0, FixedDoubleArray::kMaxLength);
      97             : 
      98             :   // The JSArray::length property always contains a tagged number in the range
      99             :   // [0, kMaxUInt32].
     100             :   Type const kJSArrayLengthType = Type::Unsigned32();
     101             : 
     102             :   // The JSArrayBuffer::byte_length property is limited to safe integer range
     103             :   // per specification, but on 32-bit architectures is implemented as uint32_t
     104             :   // field, so it's in the [0, kMaxUInt32] range in that case.
     105             :   Type const kJSArrayBufferByteLengthType =
     106             :       CreateRange(0.0, JSArrayBuffer::kMaxByteLength);
     107             : 
     108             :   // The type for the JSArrayBufferView::byte_length property is the same as
     109             :   // JSArrayBuffer::byte_length above.
     110             :   Type const kJSArrayBufferViewByteLengthType = kJSArrayBufferByteLengthType;
     111             : 
     112             :   // The type for the JSArrayBufferView::byte_offset property is the same as
     113             :   // JSArrayBuffer::byte_length above.
     114             :   Type const kJSArrayBufferViewByteOffsetType = kJSArrayBufferByteLengthType;
     115             : 
     116             :   // The JSTypedArray::length property always contains a tagged number in the
     117             :   // range [0, kMaxSmiValue].
     118             :   Type const kJSTypedArrayLengthType = Type::UnsignedSmall();
     119             : 
     120             :   // The String::length property always contains a smi in the range
     121             :   // [0, String::kMaxLength].
     122             :   Type const kStringLengthType = CreateRange(0.0, String::kMaxLength);
     123             : 
     124             :   // A time value always contains a tagged number in the range
     125             :   // [-kMaxTimeInMs, kMaxTimeInMs].
     126             :   Type const kTimeValueType =
     127             :       CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs);
     128             : 
     129             :   // The JSDate::day property always contains a tagged number in the range
     130             :   // [1, 31] or NaN.
     131             :   Type const kJSDateDayType =
     132             :       Type::Union(CreateRange(1, 31.0), Type::NaN(), zone());
     133             : 
     134             :   // The JSDate::hour property always contains a tagged number in the range
     135             :   // [0, 23] or NaN.
     136             :   Type const kJSDateHourType =
     137             :       Type::Union(CreateRange(0, 23.0), Type::NaN(), zone());
     138             : 
     139             :   // The JSDate::minute property always contains a tagged number in the range
     140             :   // [0, 59] or NaN.
     141             :   Type const kJSDateMinuteType =
     142             :       Type::Union(CreateRange(0, 59.0), Type::NaN(), zone());
     143             : 
     144             :   // The JSDate::month property always contains a tagged number in the range
     145             :   // [0, 11] or NaN.
     146             :   Type const kJSDateMonthType =
     147             :       Type::Union(CreateRange(0, 11.0), Type::NaN(), zone());
     148             : 
     149             :   // The JSDate::second property always contains a tagged number in the range
     150             :   // [0, 59] or NaN.
     151             :   Type const kJSDateSecondType = kJSDateMinuteType;
     152             : 
     153             :   // The JSDate::value property always contains a tagged number in the range
     154             :   // [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
     155             :   Type const kJSDateValueType =
     156             :       Type::Union(kTimeValueType, Type::NaN(), zone());
     157             : 
     158             :   // The JSDate::weekday property always contains a tagged number in the range
     159             :   // [0, 6] or NaN.
     160             :   Type const kJSDateWeekdayType =
     161             :       Type::Union(CreateRange(0, 6.0), Type::NaN(), zone());
     162             : 
     163             :   // The JSDate::year property always contains a tagged number in the signed
     164             :   // small range or NaN.
     165             :   Type const kJSDateYearType =
     166             :       Type::Union(Type::SignedSmall(), Type::NaN(), zone());
     167             : 
     168             :   // The valid number of arguments for JavaScript functions. We can never
     169             :   // materialize more than the max size of a fixed array, because we require a
     170             :   // fixed array in spread/apply calls.
     171             :   Type const kArgumentsLengthType = CreateRange(0.0, FixedArray::kMaxLength);
     172             : 
     173             :   // The JSArrayIterator::kind property always contains an integer in the
     174             :   // range [0, 2], representing the possible IterationKinds.
     175             :   Type const kJSArrayIteratorKindType = CreateRange(0.0, 2.0);
     176             : 
     177             :  private:
     178             :   template <typename T>
     179             :   Type CreateRange() {
     180             :     return CreateRange(std::numeric_limits<T>::min(),
     181             :                        std::numeric_limits<T>::max());
     182             :   }
     183             : 
     184             :   Type CreateRange(double min, double max) {
     185      478208 :     return Type::Range(min, max, zone());
     186             :   }
     187             : 
     188             :   Zone* zone() { return &zone_; }
     189             : };
     190             : 
     191             : }  // namespace compiler
     192             : }  // namespace internal
     193             : }  // namespace v8
     194             : 
     195             : #endif  // V8_COMPILER_TYPE_CACHE_H_

Generated by: LCOV version 1.10