tint/sem: Treat abstract-numerics as scalars.
This tracks the WGSL spec and reduces tint complexity. Change-Id: I240a87fc7bb7f51d9e0ff180af4911cd00a33758 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97581 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
6fe1f515d4
commit
ea84b9b072
|
@ -68,19 +68,15 @@ bool Type::IsConstructible() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_scalar() const {
|
bool Type::is_scalar() const {
|
||||||
return IsAnyOf<F16, F32, U32, I32, Bool>();
|
return IsAnyOf<F16, F32, U32, I32, AbstractNumeric, Bool>();
|
||||||
}
|
|
||||||
|
|
||||||
bool Type::is_abstract_or_scalar() const {
|
|
||||||
return IsAnyOf<F16, F32, U32, I32, Bool, AbstractNumeric>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_numeric_scalar() const {
|
bool Type::is_numeric_scalar() const {
|
||||||
return IsAnyOf<F16, F32, U32, I32>();
|
return IsAnyOf<F16, F32, U32, I32, AbstractNumeric>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_float_scalar() const {
|
bool Type::is_float_scalar() const {
|
||||||
return IsAnyOf<F16, F32>();
|
return IsAnyOf<F16, F32, AbstractNumeric>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_float_matrix() const {
|
bool Type::is_float_matrix() const {
|
||||||
|
@ -117,7 +113,7 @@ bool Type::is_unsigned_integer_scalar() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_signed_integer_vector() const {
|
bool Type::is_signed_integer_vector() const {
|
||||||
return Is([](const Vector* v) { return v->type()->Is<I32>(); });
|
return Is([](const Vector* v) { return v->type()->IsAnyOf<I32>(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_unsigned_integer_vector() const {
|
bool Type::is_unsigned_integer_vector() const {
|
||||||
|
@ -136,10 +132,6 @@ bool Type::is_integer_scalar_or_vector() const {
|
||||||
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
return is_unsigned_scalar_or_vector() || is_signed_scalar_or_vector();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_abstract_scalar_vector() const {
|
|
||||||
return Is([](const Vector* v) { return v->type()->Is<sem::AbstractNumeric>(); });
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Type::is_abstract_integer_vector() const {
|
bool Type::is_abstract_integer_vector() const {
|
||||||
return Is([](const Vector* v) { return v->type()->Is<sem::AbstractInt>(); });
|
return Is([](const Vector* v) { return v->type()->Is<sem::AbstractInt>(); });
|
||||||
}
|
}
|
||||||
|
@ -148,10 +140,6 @@ bool Type::is_abstract_float_vector() const {
|
||||||
return Is([](const Vector* v) { return v->type()->Is<sem::AbstractFloat>(); });
|
return Is([](const Vector* v) { return v->type()->Is<sem::AbstractFloat>(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Type::is_abstract_scalar_or_vector() const {
|
|
||||||
return Is<sem::AbstractNumeric>() || is_abstract_scalar_vector();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Type::is_abstract_integer_scalar_or_vector() const {
|
bool Type::is_abstract_integer_scalar_or_vector() const {
|
||||||
return Is<sem::AbstractInt>() || is_abstract_integer_vector();
|
return Is<sem::AbstractInt>() || is_abstract_integer_vector();
|
||||||
}
|
}
|
||||||
|
@ -228,7 +216,7 @@ uint32_t Type::ConversionRank(const Type* from, const Type* to) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Type* Type::ElementOf(const Type* ty, uint32_t* count /* = nullptr */) {
|
const Type* Type::ElementOf(const Type* ty, uint32_t* count /* = nullptr */) {
|
||||||
if (ty->is_abstract_or_scalar()) {
|
if (ty->is_scalar()) {
|
||||||
if (count) {
|
if (count) {
|
||||||
*count = 1;
|
*count = 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,8 +71,6 @@ class Type : public Castable<Type, Node> {
|
||||||
|
|
||||||
/// @returns true if this type is a scalar
|
/// @returns true if this type is a scalar
|
||||||
bool is_scalar() const;
|
bool is_scalar() const;
|
||||||
/// @returns true if this type is a scalar or an abstract numeric
|
|
||||||
bool is_abstract_or_scalar() const;
|
|
||||||
/// @returns true if this type is a numeric scalar
|
/// @returns true if this type is a numeric scalar
|
||||||
bool is_numeric_scalar() const;
|
bool is_numeric_scalar() const;
|
||||||
/// @returns true if this type is a float scalar
|
/// @returns true if this type is a float scalar
|
||||||
|
@ -103,14 +101,10 @@ class Type : public Castable<Type, Node> {
|
||||||
bool is_signed_scalar_or_vector() const;
|
bool is_signed_scalar_or_vector() const;
|
||||||
/// @returns true if this type is an integer scalar or vector
|
/// @returns true if this type is an integer scalar or vector
|
||||||
bool is_integer_scalar_or_vector() const;
|
bool is_integer_scalar_or_vector() const;
|
||||||
/// @returns true if this type is an abstract scalar vector
|
|
||||||
bool is_abstract_scalar_vector() const;
|
|
||||||
/// @returns true if this type is an abstract integer vector
|
/// @returns true if this type is an abstract integer vector
|
||||||
bool is_abstract_integer_vector() const;
|
bool is_abstract_integer_vector() const;
|
||||||
/// @returns true if this type is an abstract float vector
|
/// @returns true if this type is an abstract float vector
|
||||||
bool is_abstract_float_vector() const;
|
bool is_abstract_float_vector() const;
|
||||||
/// @returns true if this type is an abstract scalar or vector
|
|
||||||
bool is_abstract_scalar_or_vector() const;
|
|
||||||
/// @returns true if this type is an abstract integer scalar or vector
|
/// @returns true if this type is an abstract integer scalar or vector
|
||||||
bool is_abstract_integer_scalar_or_vector() const;
|
bool is_abstract_integer_scalar_or_vector() const;
|
||||||
/// @returns true if this type is an abstract float scalar or vector
|
/// @returns true if this type is an abstract float scalar or vector
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#include "src/tint/program_builder.h"
|
#include "src/tint/program_builder.h"
|
||||||
|
#include "src/tint/sem/abstract_numeric.h"
|
||||||
#include "src/tint/sem/call.h"
|
#include "src/tint/sem/call.h"
|
||||||
#include "src/tint/sem/expression.h"
|
#include "src/tint/sem/expression.h"
|
||||||
#include "src/tint/sem/type_constructor.h"
|
#include "src/tint/sem/type_constructor.h"
|
||||||
|
@ -54,7 +55,6 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
|
||||||
if (!ty_ctor) {
|
if (!ty_ctor) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
// Check if this is a matrix constructor with scalar arguments.
|
|
||||||
auto* mat_type = call->Type()->As<sem::Matrix>();
|
auto* mat_type = call->Type()->As<sem::Matrix>();
|
||||||
if (!mat_type) {
|
if (!mat_type) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -64,7 +64,15 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
|
||||||
if (args.IsEmpty()) {
|
if (args.IsEmpty()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!args[0]->Type()->UnwrapRef()->is_scalar()) {
|
|
||||||
|
// If the argument type is a matrix, then this is an identity / conversion constructor.
|
||||||
|
// If the argument type is a vector, then we're already column vectors.
|
||||||
|
// If the argument type is abstract, then we're const-expression and there's no need to
|
||||||
|
// adjust this, as it'll be constant folded by the backend.
|
||||||
|
if (args[0]
|
||||||
|
->Type()
|
||||||
|
->UnwrapRef()
|
||||||
|
->IsAnyOf<sem::Matrix, sem::Vector, sem::AbstractNumeric>()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue