Spliting out TyperCache into ZoneTypeCache to share with AsmTyper.

The zone type cache would be handy inside the asm.js typer.
Pulling it out into a seperate inlinable header to allow sharing.

BUG=https://code.google.com/p/v8/issues/detail?id=4203
TEST=None
R=andreas@chromium.org,titzer@chromium.org
LOG=N

Review URL: https://codereview.chromium.org/1307093006

Cr-Commit-Position: refs/heads/master@{#30398}
This commit is contained in:
bradnelson 2015-08-26 14:40:52 -07:00 committed by Commit bot
parent 972bd61586
commit e2b3edbf31
5 changed files with 106 additions and 86 deletions

View File

@ -1238,6 +1238,7 @@ source_set("v8_base") {
"src/version.h",
"src/vm-state-inl.h",
"src/vm-state.h",
"src/zone-type-cache.h",
"src/zone.cc",
"src/zone.h",
"src/zone-allocator.h",

View File

@ -13,96 +13,15 @@
#include "src/compiler/node.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/simplified-operator.h"
#include "src/zone-type-cache.h"
namespace v8 {
namespace internal {
namespace compiler {
class TyperCache final {
private:
// This has to be first for the initialization magic to work.
Zone zone_;
public:
TyperCache() = default;
Type* const kInt8 =
CreateNative(CreateRange<int8_t>(), Type::UntaggedSigned8());
Type* const kUint8 =
CreateNative(CreateRange<uint8_t>(), Type::UntaggedUnsigned8());
Type* const kUint8Clamped = kUint8;
Type* const kInt16 =
CreateNative(CreateRange<int16_t>(), Type::UntaggedSigned16());
Type* const kUint16 =
CreateNative(CreateRange<uint16_t>(), Type::UntaggedUnsigned16());
Type* const kInt32 = CreateNative(Type::Signed32(), Type::UntaggedSigned32());
Type* const kUint32 =
CreateNative(Type::Unsigned32(), Type::UntaggedUnsigned32());
Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32());
Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64());
Type* const kSingletonZero = CreateRange(0.0, 0.0);
Type* const kSingletonOne = CreateRange(1.0, 1.0);
Type* const kZeroOrOne = CreateRange(0.0, 1.0);
Type* const kZeroish =
Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone());
Type* const kWeakintFunc1 = Type::Function(kWeakint, Type::Number(), zone());
Type* const kRandomFunc0 = Type::Function(Type::OrderedNumber(), zone());
Type* const kAnyFunc0 = Type::Function(Type::Any(), zone());
Type* const kAnyFunc1 = Type::Function(Type::Any(), Type::Any(), zone());
Type* const kAnyFunc2 =
Type::Function(Type::Any(), Type::Any(), Type::Any(), zone());
Type* const kAnyFunc3 = Type::Function(Type::Any(), Type::Any(), Type::Any(),
Type::Any(), zone());
Type* const kNumberFunc0 = Type::Function(Type::Number(), zone());
Type* const kNumberFunc1 =
Type::Function(Type::Number(), Type::Number(), zone());
Type* const kNumberFunc2 =
Type::Function(Type::Number(), Type::Number(), Type::Number(), zone());
Type* const kImulFunc = Type::Function(Type::Signed32(), Type::Integral32(),
Type::Integral32(), zone());
Type* const kClz32Func =
Type::Function(CreateRange(0, 32), Type::Number(), zone());
#define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \
Type* const k##TypeName##Array = CreateArray(k##TypeName);
TYPED_ARRAYS(TYPED_ARRAY)
#undef TYPED_ARRAY
private:
Type* CreateArray(Type* element) { return Type::Array(element, zone()); }
Type* CreateArrayFunction(Type* array) {
Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone());
Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone());
Type* arg3 = arg2;
return Type::Function(array, arg1, arg2, arg3, zone());
}
Type* CreateNative(Type* semantic, Type* representation) {
return Type::Intersect(semantic, representation, zone());
}
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_; }
};
namespace {
base::LazyInstance<TyperCache>::type kCache = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<ZoneTypeCache>::type kCache = LAZY_INSTANCE_INITIALIZER;
} // namespace

View File

@ -10,10 +10,11 @@
namespace v8 {
namespace internal {
namespace compiler {
// Forward declarations.
class TyperCache;
class ZoneTypeCache;
namespace compiler {
class Typer {
@ -39,7 +40,7 @@ class Typer {
Graph* const graph_;
Type::FunctionType* function_type_;
Decorator* decorator_;
TyperCache const& cache_;
ZoneTypeCache const& cache_;
Type* singleton_false_;
Type* singleton_true_;

98
src/zone-type-cache.h Normal file
View File

@ -0,0 +1,98 @@
// 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.
#ifndef V8_ZONE_TYPE_CACHE_H_
#define V8_ZONE_TYPE_CACHE_H_
#include "src/types.h"
namespace v8 {
namespace internal {
class ZoneTypeCache final {
private:
// This has to be first for the initialization magic to work.
Zone zone_;
public:
ZoneTypeCache() = default;
Type* const kInt8 =
CreateNative(CreateRange<int8_t>(), Type::UntaggedSigned8());
Type* const kUint8 =
CreateNative(CreateRange<uint8_t>(), Type::UntaggedUnsigned8());
Type* const kUint8Clamped = kUint8;
Type* const kInt16 =
CreateNative(CreateRange<int16_t>(), Type::UntaggedSigned16());
Type* const kUint16 =
CreateNative(CreateRange<uint16_t>(), Type::UntaggedUnsigned16());
Type* const kInt32 = CreateNative(Type::Signed32(), Type::UntaggedSigned32());
Type* const kUint32 =
CreateNative(Type::Unsigned32(), Type::UntaggedUnsigned32());
Type* const kFloat32 = CreateNative(Type::Number(), Type::UntaggedFloat32());
Type* const kFloat64 = CreateNative(Type::Number(), Type::UntaggedFloat64());
Type* const kSingletonZero = CreateRange(0.0, 0.0);
Type* const kSingletonOne = CreateRange(1.0, 1.0);
Type* const kZeroOrOne = CreateRange(0.0, 1.0);
Type* const kZeroish =
Type::Union(kSingletonZero, Type::MinusZeroOrNaN(), zone());
Type* const kInteger = CreateRange(-V8_INFINITY, V8_INFINITY);
Type* const kWeakint = Type::Union(kInteger, Type::MinusZeroOrNaN(), zone());
Type* const kWeakintFunc1 = Type::Function(kWeakint, Type::Number(), zone());
Type* const kRandomFunc0 = Type::Function(Type::OrderedNumber(), zone());
Type* const kAnyFunc0 = Type::Function(Type::Any(), zone());
Type* const kAnyFunc1 = Type::Function(Type::Any(), Type::Any(), zone());
Type* const kAnyFunc2 =
Type::Function(Type::Any(), Type::Any(), Type::Any(), zone());
Type* const kAnyFunc3 = Type::Function(Type::Any(), Type::Any(), Type::Any(),
Type::Any(), zone());
Type* const kNumberFunc0 = Type::Function(Type::Number(), zone());
Type* const kNumberFunc1 =
Type::Function(Type::Number(), Type::Number(), zone());
Type* const kNumberFunc2 =
Type::Function(Type::Number(), Type::Number(), Type::Number(), zone());
Type* const kImulFunc = Type::Function(Type::Signed32(), Type::Integral32(),
Type::Integral32(), zone());
Type* const kClz32Func =
Type::Function(CreateRange(0, 32), Type::Number(), zone());
#define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \
Type* const k##TypeName##Array = CreateArray(k##TypeName);
TYPED_ARRAYS(TYPED_ARRAY)
#undef TYPED_ARRAY
private:
Type* CreateArray(Type* element) { return Type::Array(element, zone()); }
Type* CreateArrayFunction(Type* array) {
Type* arg1 = Type::Union(Type::Unsigned32(), Type::Object(), zone());
Type* arg2 = Type::Union(Type::Unsigned32(), Type::Undefined(), zone());
Type* arg3 = arg2;
return Type::Function(array, arg1, arg2, arg3, zone());
}
Type* CreateNative(Type* semantic, Type* representation) {
return Type::Intersect(semantic, representation, zone());
}
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_; }
};
} // namespace internal
} // namespace v8
#endif // V8_ZONE_TYPE_CACHE_H_

View File

@ -999,6 +999,7 @@
'../../src/version.h',
'../../src/vm-state-inl.h',
'../../src/vm-state.h',
'../../src/zone-type-cache.h',
'../../src/zone.cc',
'../../src/zone.h',
'../../src/zone-allocator.h',