type-cache.h 6.28 KB
Newer Older
1 2 3 4
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef V8_COMPILER_TYPE_CACHE_H_
#define V8_COMPILER_TYPE_CACHE_H_
7

8
#include "src/compiler/types.h"
9
#include "src/date.h"
10 11 12

namespace v8 {
namespace internal {
13
namespace compiler {
14

15
class TypeCache final {
16 17
 private:
  // This has to be first for the initialization magic to work.
18
  AccountingAllocator allocator;
19 20 21
  Zone zone_;

 public:
22 23
  static TypeCache const& Get();

24
  TypeCache() : zone_(&allocator, ZONE_NAME) {}
25

26 27
  Type* const kInt8 = CreateRange<int8_t>();
  Type* const kUint8 = CreateRange<uint8_t>();
28
  Type* const kUint8Clamped = kUint8;
29 30
  Type* const kUint8OrMinusZeroOrNaN =
      Type::Union(kUint8, Type::MinusZeroOrNaN(), zone());
31 32 33 34 35 36 37
  Type* const kInt16 = CreateRange<int16_t>();
  Type* const kUint16 = CreateRange<uint16_t>();
  Type* const kInt32 = Type::Signed32();
  Type* const kUint32 = Type::Unsigned32();
  Type* const kFloat32 = Type::Number();
  Type* const kFloat64 = Type::Number();

38 39
  Type* const kHoleySmi =
      Type::Union(Type::SignedSmall(), Type::Hole(), zone());
40

41 42
  Type* const kSingletonZero = CreateRange(0.0, 0.0);
  Type* const kSingletonOne = CreateRange(1.0, 1.0);
43
  Type* const kSingletonTen = CreateRange(10.0, 10.0);
44
  Type* const kSingletonMinusOne = CreateRange(-1.0, -1.0);
45 46 47 48
  Type* const kZeroOrUndefined =
      Type::Union(kSingletonZero, Type::Undefined(), zone());
  Type* const kTenOrUndefined =
      Type::Union(kSingletonTen, Type::Undefined(), zone());
49
  Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0);
50 51 52
  Type* const kMinusOneToOneOrMinusZeroOrNaN = Type::Union(
      Type::Union(CreateRange(-1.0, 1.0), Type::MinusZero(), zone()),
      Type::NaN(), zone());
53
  Type* const kZeroOrOne = CreateRange(0.0, 1.0);
54
  Type* const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone());
55
  Type* const kZeroToThirtyOne = CreateRange(0.0, 31.0);
56
  Type* const kZeroToThirtyTwo = CreateRange(0.0, 32.0);
57 58 59
  Type* const kZeroish =
      Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
  Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
60 61 62 63
  Type* const kIntegerOrMinusZero =
      Type::Union(kInteger, Type::MinusZero(), zone());
  Type* const kIntegerOrMinusZeroOrNaN =
      Type::Union(kIntegerOrMinusZero, Type::NaN(), zone());
64 65 66
  Type* const kPositiveInteger = CreateRange(0.0, V8_INFINITY);
  Type* const kPositiveIntegerOrMinusZero =
      Type::Union(kPositiveInteger, Type::MinusZero(), zone());
67 68
  Type* const kPositiveIntegerOrNaN =
      Type::Union(kPositiveInteger, Type::NaN(), zone());
69 70
  Type* const kPositiveIntegerOrMinusZeroOrNaN =
      Type::Union(kPositiveIntegerOrMinusZero, Type::NaN(), zone());
71

72 73 74
  Type* const kAdditiveSafeInteger =
      CreateRange(-4503599627370496.0, 4503599627370496.0);
  Type* const kSafeInteger = CreateRange(-kMaxSafeInteger, kMaxSafeInteger);
75 76 77 78
  Type* const kAdditiveSafeIntegerOrMinusZero =
      Type::Union(kAdditiveSafeInteger, Type::MinusZero(), zone());
  Type* const kSafeIntegerOrMinusZero =
      Type::Union(kSafeInteger, Type::MinusZero(), zone());
79
  Type* const kPositiveSafeInteger = CreateRange(0.0, kMaxSafeInteger);
80

81 82
  // The FixedArray::length property always containts a smi in the range
  // [0, FixedArray::kMaxLength].
83
  Type* const kFixedArrayLengthType = CreateRange(0.0, FixedArray::kMaxLength);
84 85 86

  // The FixedDoubleArray::length property always containts a smi in the range
  // [0, FixedDoubleArray::kMaxLength].
87 88
  Type* const kFixedDoubleArrayLengthType =
      CreateRange(0.0, FixedDoubleArray::kMaxLength);
89 90 91

  // The JSArray::length property always contains a tagged number in the range
  // [0, kMaxUInt32].
92
  Type* const kJSArrayLengthType = Type::Unsigned32();
93

94 95
  // The JSTyped::length property always contains a tagged number in the range
  // [0, kMaxSmiValue].
96
  Type* const kJSTypedArrayLengthType = Type::UnsignedSmall();
97

98 99
  // The String::length property always contains a smi in the range
  // [0, String::kMaxLength].
100
  Type* const kStringLengthType = CreateRange(0.0, String::kMaxLength);
101

102 103 104 105 106
  // A time value always contains a tagged number in the range
  // [-kMaxTimeInMs, kMaxTimeInMs].
  Type* const kTimeValueType =
      CreateRange(-DateCache::kMaxTimeInMs, DateCache::kMaxTimeInMs);

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  // The JSDate::day property always contains a tagged number in the range
  // [1, 31] or NaN.
  Type* const kJSDateDayType =
      Type::Union(CreateRange(1, 31.0), Type::NaN(), zone());

  // The JSDate::hour property always contains a tagged number in the range
  // [0, 23] or NaN.
  Type* const kJSDateHourType =
      Type::Union(CreateRange(0, 23.0), Type::NaN(), zone());

  // The JSDate::minute property always contains a tagged number in the range
  // [0, 59] or NaN.
  Type* const kJSDateMinuteType =
      Type::Union(CreateRange(0, 59.0), Type::NaN(), zone());

  // The JSDate::month property always contains a tagged number in the range
  // [0, 11] or NaN.
  Type* const kJSDateMonthType =
      Type::Union(CreateRange(0, 11.0), Type::NaN(), zone());

  // The JSDate::second property always contains a tagged number in the range
  // [0, 59] or NaN.
  Type* const kJSDateSecondType = kJSDateMinuteType;

  // The JSDate::value property always contains a tagged number in the range
132
  // [-kMaxTimeInMs, kMaxTimeInMs] or NaN.
133 134
  Type* const kJSDateValueType =
      Type::Union(kTimeValueType, Type::NaN(), zone());
135

136 137 138 139 140 141 142 143 144 145
  // The JSDate::weekday property always contains a tagged number in the range
  // [0, 6] or NaN.
  Type* const kJSDateWeekdayType =
      Type::Union(CreateRange(0, 6.0), Type::NaN(), zone());

  // The JSDate::year property always contains a tagged number in the signed
  // small range or NaN.
  Type* const kJSDateYearType =
      Type::Union(Type::SignedSmall(), Type::NaN(), zone());

146 147 148 149
  // The valid number of arguments for JavaScript functions.
  Type* const kArgumentsLengthType =
      Type::Range(0.0, Code::kMaxArguments, zone());

150 151 152 153 154 155 156 157 158 159 160 161 162 163
 private:
  template <typename T>
  Type* CreateRange() {
    return CreateRange(std::numeric_limits<T>::min(),
                       std::numeric_limits<T>::max());
  }

  Type* CreateRange(double min, double max) {
    return Type::Range(min, max, zone());
  }

  Zone* zone() { return &zone_; }
};

164
}  // namespace compiler
165 166 167
}  // namespace internal
}  // namespace v8

168
#endif  // V8_COMPILER_TYPE_CACHE_H_