[asm.js] Remove some dead AsmType subclasses.
R=clemensh@chromium.org Change-Id: I5bdb91d2e82105bb301c2b97abfb1b074b710a64 Reviewed-on: https://chromium-review.googlesource.com/632680 Reviewed-by: Clemens Hammacher <clemensh@chromium.org> Commit-Queue: Michael Starzinger <mstarzinger@chromium.org> Cr-Commit-Position: refs/heads/master@{#47597}
This commit is contained in:
parent
49e3bfd572
commit
77c7ef6750
@ -234,21 +234,6 @@ AsmType* AsmType::MinMaxType(Zone* zone, AsmType* dest, AsmType* src) {
|
||||
return reinterpret_cast<AsmType*>(MinMax);
|
||||
}
|
||||
|
||||
bool AsmFFIType::CanBeInvokedWith(AsmType* return_type,
|
||||
const ZoneVector<AsmType*>& args) {
|
||||
if (return_type->IsExactly(AsmType::Float())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t ii = 0; ii < args.size(); ++ii) {
|
||||
if (!args[ii]->IsA(AsmType::Extern())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AsmFunctionType::IsA(AsmType* other) {
|
||||
auto* that = other->AsFunctionType();
|
||||
if (that == nullptr) {
|
||||
@ -319,36 +304,6 @@ void AsmOverloadedFunctionType::AddOverload(AsmType* overload) {
|
||||
overloads_.push_back(overload);
|
||||
}
|
||||
|
||||
AsmFunctionTableType::AsmFunctionTableType(size_t length, AsmType* signature)
|
||||
: length_(length), signature_(signature) {
|
||||
DCHECK(signature_ != nullptr);
|
||||
DCHECK(signature_->AsFunctionType() != nullptr);
|
||||
}
|
||||
|
||||
namespace {
|
||||
// ToString is used for reporting function tables' names. It converts its
|
||||
// argument to uint32_t because asm.js integers are 32-bits, thus effectively
|
||||
// limiting the max function table's length.
|
||||
std::string ToString(size_t s) {
|
||||
auto u32 = static_cast<uint32_t>(s);
|
||||
// 16 bytes is more than enough to represent a 32-bit integer as a base 10
|
||||
// string.
|
||||
char digits[16];
|
||||
int length = base::OS::SNPrintF(digits, arraysize(digits), "%" PRIu32, u32);
|
||||
DCHECK_NE(length, -1);
|
||||
return std::string(digits, length);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::string AsmFunctionTableType::Name() {
|
||||
return "(" + signature_->Name() + ")[" + ToString(length_) + "]";
|
||||
}
|
||||
|
||||
bool AsmFunctionTableType::CanBeInvokedWith(AsmType* return_type,
|
||||
const ZoneVector<AsmType*>& args) {
|
||||
return signature_->AsCallableType()->CanBeInvokedWith(return_type, args);
|
||||
}
|
||||
|
||||
} // namespace wasm
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -18,10 +18,8 @@ namespace internal {
|
||||
namespace wasm {
|
||||
|
||||
class AsmType;
|
||||
class AsmFFIType;
|
||||
class AsmFunctionType;
|
||||
class AsmOverloadedFunctionType;
|
||||
class AsmFunctionTableType;
|
||||
|
||||
// List of V(CamelName, string_name, number, parent_types)
|
||||
#define FOR_EACH_ASM_VALUE_TYPE_LIST(V) \
|
||||
@ -58,9 +56,7 @@ class AsmFunctionTableType;
|
||||
// List of V(CamelName)
|
||||
#define FOR_EACH_ASM_CALLABLE_TYPE_LIST(V) \
|
||||
V(FunctionType) \
|
||||
V(FFIType) \
|
||||
V(OverloadedFunctionType) \
|
||||
V(FunctionTableType)
|
||||
V(OverloadedFunctionType)
|
||||
|
||||
class AsmValueType {
|
||||
public:
|
||||
@ -176,45 +172,6 @@ class V8_EXPORT_PRIVATE AsmOverloadedFunctionType final
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(AsmOverloadedFunctionType);
|
||||
};
|
||||
|
||||
class V8_EXPORT_PRIVATE AsmFFIType final : public AsmCallableType {
|
||||
public:
|
||||
AsmFFIType* AsFFIType() override { return this; }
|
||||
|
||||
std::string Name() override { return "Function"; }
|
||||
bool CanBeInvokedWith(AsmType* return_type,
|
||||
const ZoneVector<AsmType*>& args) override;
|
||||
|
||||
private:
|
||||
friend AsmType;
|
||||
|
||||
AsmFFIType() = default;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AsmFFIType);
|
||||
};
|
||||
|
||||
class V8_EXPORT_PRIVATE AsmFunctionTableType : public AsmCallableType {
|
||||
public:
|
||||
AsmFunctionTableType* AsFunctionTableType() override { return this; }
|
||||
|
||||
std::string Name() override;
|
||||
|
||||
bool CanBeInvokedWith(AsmType* return_type,
|
||||
const ZoneVector<AsmType*>& args) override;
|
||||
|
||||
size_t length() const { return length_; }
|
||||
AsmType* signature() { return signature_; }
|
||||
|
||||
private:
|
||||
friend class AsmType;
|
||||
|
||||
AsmFunctionTableType(size_t length, AsmType* signature);
|
||||
|
||||
size_t length_;
|
||||
AsmType* signature_;
|
||||
|
||||
DISALLOW_IMPLICIT_CONSTRUCTORS(AsmFunctionTableType);
|
||||
};
|
||||
|
||||
class V8_EXPORT_PRIVATE AsmType {
|
||||
public:
|
||||
#define DEFINE_CONSTRUCTOR(CamelName, string_name, number, parent_types) \
|
||||
@ -256,19 +213,6 @@ class V8_EXPORT_PRIVATE AsmType {
|
||||
// The (variadic) type for min and max.
|
||||
static AsmType* MinMaxType(Zone* zone, AsmType* dest, AsmType* src);
|
||||
|
||||
// The type for foreign functions.
|
||||
static AsmType* FFIType(Zone* zone) {
|
||||
auto* f = new (zone) AsmFFIType();
|
||||
return reinterpret_cast<AsmType*>(f);
|
||||
}
|
||||
|
||||
// The type for function tables.
|
||||
static AsmType* FunctionTableType(Zone* zone, size_t length,
|
||||
AsmType* signature) {
|
||||
auto* f = new (zone) AsmFunctionTableType(length, signature);
|
||||
return reinterpret_cast<AsmType*>(f);
|
||||
}
|
||||
|
||||
std::string Name();
|
||||
// IsExactly returns true if this is the exact same type as that. For
|
||||
// non-value types (e.g., callables), this returns this == that.
|
||||
@ -278,56 +222,6 @@ class V8_EXPORT_PRIVATE AsmType {
|
||||
// returns this == that.
|
||||
bool IsA(AsmType* that);
|
||||
|
||||
// Types allowed in return statements. void is the type for returns without
|
||||
// an expression.
|
||||
bool IsReturnType() {
|
||||
return this == AsmType::Void() || this == AsmType::Double() ||
|
||||
this == AsmType::Signed() || this == AsmType::Float();
|
||||
}
|
||||
|
||||
// Converts this to the corresponding valid argument type.
|
||||
AsmType* ToReturnType() {
|
||||
if (this->IsA(AsmType::Signed())) {
|
||||
return AsmType::Signed();
|
||||
}
|
||||
if (this->IsA(AsmType::Double())) {
|
||||
return AsmType::Double();
|
||||
}
|
||||
if (this->IsA(AsmType::Float())) {
|
||||
return AsmType::Float();
|
||||
}
|
||||
if (this->IsA(AsmType::Void())) {
|
||||
return AsmType::Void();
|
||||
}
|
||||
return AsmType::None();
|
||||
}
|
||||
|
||||
// Types allowed to be parameters in asm functions.
|
||||
bool IsParameterType() {
|
||||
return this == AsmType::Double() || this == AsmType::Int() ||
|
||||
this == AsmType::Float();
|
||||
}
|
||||
|
||||
// Converts this to the corresponding valid argument type.
|
||||
AsmType* ToParameterType() {
|
||||
if (this->IsA(AsmType::Int())) {
|
||||
return AsmType::Int();
|
||||
}
|
||||
if (this->IsA(AsmType::Double())) {
|
||||
return AsmType::Double();
|
||||
}
|
||||
if (this->IsA(AsmType::Float())) {
|
||||
return AsmType::Float();
|
||||
}
|
||||
return AsmType::None();
|
||||
}
|
||||
|
||||
// Types allowed to be compared using the comparison operators.
|
||||
bool IsComparableType() {
|
||||
return this == AsmType::Double() || this == AsmType::Signed() ||
|
||||
this == AsmType::Unsigned() || this == AsmType::Float();
|
||||
}
|
||||
|
||||
// The following methods are meant to be used for inspecting the traits of
|
||||
// element types for the heap view types.
|
||||
enum : int32_t { kNotHeapType = -1 };
|
||||
|
@ -232,12 +232,6 @@ TEST_F(AsmTypeTest, Names) {
|
||||
StrEq("(floatish, floatish...) -> float"));
|
||||
EXPECT_THAT(Type::MinMaxType(zone(), Type::Double(), Type::DoubleQ())->Name(),
|
||||
StrEq("(double?, double?...) -> double"));
|
||||
|
||||
EXPECT_THAT(Type::FFIType(zone())->Name(), StrEq("Function"));
|
||||
|
||||
auto* ft =
|
||||
Type::FunctionTableType(zone(), 15, Function(Type::Double)(Type::Int));
|
||||
EXPECT_THAT(ft->Name(), StrEq("((int) -> double)[15]"));
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, IsExactly) {
|
||||
@ -252,8 +246,6 @@ TEST_F(AsmTypeTest, IsExactly) {
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
@ -288,8 +280,6 @@ TEST_F(AsmTypeTest, IsA) {
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
@ -425,188 +415,6 @@ TEST_F(AsmTypeTest, CanBeInvokedWith) {
|
||||
i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
|
||||
EXPECT_FALSE(i2f->AsCallableType()->CanBeInvokedWith(
|
||||
i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
|
||||
|
||||
auto* ffi = Type::FFIType(zone());
|
||||
AsmType* (*kReturnTypes[])() = {
|
||||
Type::Void, Type::Double, Type::Signed,
|
||||
};
|
||||
AsmType* (*kParameterTypes[])() = {
|
||||
Type::Double, Type::Signed, Type::FixNum,
|
||||
};
|
||||
for (size_t ii = 0; ii < arraysize(kReturnTypes); ++ii) {
|
||||
for (size_t jj = 0; jj < arraysize(kParameterTypes); ++jj) {
|
||||
auto* f = Function(kReturnTypes[ii])(kParameterTypes[jj]);
|
||||
EXPECT_TRUE(ffi->AsCallableType()->CanBeInvokedWith(
|
||||
f->AsFunctionType()->ReturnType(), f->AsFunctionType()->Arguments()))
|
||||
<< kReturnTypes[ii]()->Name();
|
||||
|
||||
// Call with non-parameter type type should fail.
|
||||
f = Function(kReturnTypes[ii])(kParameterTypes[jj], Type::Int);
|
||||
EXPECT_FALSE(ffi->AsCallableType()->CanBeInvokedWith(
|
||||
f->AsFunctionType()->ReturnType(), f->AsFunctionType()->Arguments()))
|
||||
<< kReturnTypes[ii]()->Name();
|
||||
}
|
||||
}
|
||||
|
||||
auto* ft0 = Type::FunctionTableType(zone(), 10, fi2d);
|
||||
EXPECT_TRUE(ft0->AsCallableType()->CanBeInvokedWith(
|
||||
fi2d->AsFunctionType()->ReturnType(),
|
||||
fi2d->AsFunctionType()->Arguments()));
|
||||
EXPECT_FALSE(ft0->AsCallableType()->CanBeInvokedWith(
|
||||
i2d->AsFunctionType()->ReturnType(), i2d->AsFunctionType()->Arguments()));
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, ToReturnType) {
|
||||
std::unordered_map<AsmType*, AsmType*> kToReturnType = {
|
||||
{Type::Signed(), Type::Signed()}, {Type::FixNum(), Type::Signed()},
|
||||
{Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
|
||||
{Type::Void(), Type::Void()},
|
||||
};
|
||||
|
||||
Type* test_types[] = {
|
||||
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
|
||||
FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
|
||||
#undef CREATE
|
||||
Function(Type::Int)(Type::Double),
|
||||
Function(Type::Int)(Type::DoubleQ),
|
||||
Overload(Function(Type::Int)(Type::Double)),
|
||||
Function(Type::Int)(Type::Int, Type::Int),
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
auto* return_type = Type::None();
|
||||
auto to_return_type_iter = kToReturnType.find(test_types[ii]);
|
||||
if (to_return_type_iter != kToReturnType.end()) {
|
||||
return_type = to_return_type_iter->second;
|
||||
}
|
||||
EXPECT_EQ(return_type, test_types[ii]->ToReturnType())
|
||||
<< return_type->Name() << " != " << test_types[ii]->ToReturnType();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, IsReturnType) {
|
||||
Type* test_types[] = {
|
||||
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
|
||||
FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
|
||||
#undef CREATE
|
||||
Function(Type::Int)(Type::Double),
|
||||
Function(Type::Int)(Type::DoubleQ),
|
||||
Overload(Function(Type::Int)(Type::Double)),
|
||||
Function(Type::Int)(Type::Int, Type::Int),
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
std::unordered_set<Type*> return_types{
|
||||
Type::Double(), Type::Signed(), Type::Float(), Type::Void(),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
const bool IsReturnType = return_types.count(test_types[ii]);
|
||||
EXPECT_EQ(IsReturnType, test_types[ii]->IsReturnType())
|
||||
<< test_types[ii]->Name()
|
||||
<< (IsReturnType ? " is not a return type" : " is a return type");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, ToParameterType) {
|
||||
std::unordered_map<AsmType*, AsmType*> kToParameterType = {
|
||||
{Type::Int(), Type::Int()}, {Type::Signed(), Type::Int()},
|
||||
{Type::Unsigned(), Type::Int()}, {Type::FixNum(), Type::Int()},
|
||||
{Type::Double(), Type::Double()}, {Type::Float(), Type::Float()},
|
||||
};
|
||||
|
||||
Type* test_types[] = {
|
||||
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
|
||||
FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
|
||||
#undef CREATE
|
||||
Function(Type::Int)(Type::Double),
|
||||
Function(Type::Int)(Type::DoubleQ),
|
||||
Overload(Function(Type::Int)(Type::Double)),
|
||||
Function(Type::Int)(Type::Int, Type::Int),
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
auto* parameter_type = Type::None();
|
||||
auto to_parameter_type_iter = kToParameterType.find(test_types[ii]);
|
||||
if (to_parameter_type_iter != kToParameterType.end()) {
|
||||
parameter_type = to_parameter_type_iter->second;
|
||||
}
|
||||
EXPECT_EQ(parameter_type, test_types[ii]->ToParameterType())
|
||||
<< parameter_type->Name()
|
||||
<< " != " << test_types[ii]->ToParameterType();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, IsParameterType) {
|
||||
Type* test_types[] = {
|
||||
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
|
||||
FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
|
||||
#undef CREATE
|
||||
Function(Type::Int)(Type::Double),
|
||||
Function(Type::Int)(Type::DoubleQ),
|
||||
Overload(Function(Type::Int)(Type::Double)),
|
||||
Function(Type::Int)(Type::Int, Type::Int),
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
std::unordered_set<Type*> parameter_types{
|
||||
Type::Double(), Type::Int(), Type::Float(),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
const bool IsParameterType = parameter_types.count(test_types[ii]);
|
||||
EXPECT_EQ(IsParameterType, test_types[ii]->IsParameterType())
|
||||
<< test_types[ii]->Name()
|
||||
<< (IsParameterType ? " is not a parameter type"
|
||||
: " is a parameter type");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, IsComparableType) {
|
||||
Type* test_types[] = {
|
||||
#define CREATE(CamelName, string_name, number, parent_types) Type::CamelName(),
|
||||
FOR_EACH_ASM_VALUE_TYPE_LIST(CREATE)
|
||||
#undef CREATE
|
||||
Function(Type::Int)(Type::Double),
|
||||
Function(Type::Int)(Type::DoubleQ),
|
||||
Overload(Function(Type::Int)(Type::Double)),
|
||||
Function(Type::Int)(Type::Int, Type::Int),
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
std::unordered_set<Type*> comparable_types{
|
||||
Type::Double(), Type::Signed(), Type::Unsigned(), Type::Float(),
|
||||
};
|
||||
|
||||
for (size_t ii = 0; ii < arraysize(test_types); ++ii) {
|
||||
const bool IsComparableType = comparable_types.count(test_types[ii]);
|
||||
EXPECT_EQ(IsComparableType, test_types[ii]->IsComparableType())
|
||||
<< test_types[ii]->Name()
|
||||
<< (IsComparableType ? " is not a comparable type"
|
||||
: " is a comparable type");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(AsmTypeTest, ElementSizeInBytes) {
|
||||
@ -621,8 +429,6 @@ TEST_F(AsmTypeTest, ElementSizeInBytes) {
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
auto ElementSizeInBytesForType = [](Type* type) -> int32_t {
|
||||
@ -660,8 +466,6 @@ TEST_F(AsmTypeTest, LoadType) {
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
auto LoadTypeForType = [](Type* type) -> Type* {
|
||||
@ -699,8 +503,6 @@ TEST_F(AsmTypeTest, StoreType) {
|
||||
Type::MinMaxType(zone(), Type::Signed(), Type::Int()),
|
||||
Function(Type::Int)(Type::Float),
|
||||
Type::FroundType(zone()),
|
||||
Type::FFIType(zone()),
|
||||
Type::FunctionTableType(zone(), 10, Function(Type::Void)()),
|
||||
};
|
||||
|
||||
auto StoreTypeForType = [](Type* type) -> Type* {
|
||||
|
Loading…
Reference in New Issue
Block a user