Update internals to initializer instead of constructor.

This CL catches up the internals (along with a few error messages) to
say `initializer` instead of `constructor.

Bug: tint:1600
Change-Id: I8e56572c310d77da1130380bdd32b334f27c8e46
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/106462
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
dan sinclair
2022-10-20 13:38:28 +00:00
committed by Dawn LUCI CQ
parent 56ce1a2155
commit 6e77b47ed9
155 changed files with 6593 additions and 6593 deletions

View File

@@ -139,7 +139,7 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) co
const ast::Type* inner_ty = CreateASTTypeFor(ctx, ty);
auto* new_var =
ctx.dst->Var(ctx.Clone(var->source), ctx.Clone(var->symbol), inner_ty,
var->declared_address_space, ac, ctx.Clone(var->constructor),
var->declared_address_space, ac, ctx.Clone(var->initializer),
ctx.Clone(var->attributes));
ctx.Replace(var, new_var);
}

View File

@@ -161,17 +161,17 @@ void ClampFragDepth::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
auto fn_sym = b.Symbols().New("clamp_frag_depth_" +
sym.NameFor(return_ty->As<ast::TypeName>()->name));
utils::Vector<const ast::Expression*, 8u> constructor_args;
utils::Vector<const ast::Expression*, 8u> initializer_args;
for (auto* member : struct_ty->members) {
const ast::Expression* arg = b.MemberAccessor("s", ctx.Clone(member->symbol));
if (ContainsFragDepth(member->attributes)) {
arg = b.Call(base_fn_sym, arg);
}
constructor_args.Push(arg);
initializer_args.Push(arg);
}
utils::Vector params{b.Param("s", ctx.Clone(return_ty))};
utils::Vector body{
b.Return(b.Construct(ctx.Clone(return_ty), std::move(constructor_args))),
b.Return(b.Construct(ctx.Clone(return_ty), std::move(initializer_args))),
};
b.Func(fn_sym, params, ctx.Clone(return_ty), body);
return fn_sym;

View File

@@ -832,7 +832,7 @@ void DecomposeMemoryAccess::Run(CloneContext& ctx, const DataMap&, DataMap&) con
//
// Inner-most expression nodes are guaranteed to be visited first because AST
// nodes are fully immutable and require their children to be constructed
// first so their pointer can be passed to the parent's constructor.
// first so their pointer can be passed to the parent's initializer.
for (auto* node : ctx.src->ASTNodes().Objects()) {
if (auto* ident = node->As<ast::IdentifierExpression>()) {
// X

View File

@@ -22,7 +22,7 @@
#include "src/tint/sem/call.h"
#include "src/tint/sem/expression.h"
#include "src/tint/sem/member_accessor_expression.h"
#include "src/tint/sem/type_constructor.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/transform/simplify_pointers.h"
#include "src/tint/utils/hash.h"
#include "src/tint/utils/map.h"
@@ -107,9 +107,9 @@ void DecomposeStridedArray::Run(CloneContext& ctx, const DataMap&, DataMap&) con
return nullptr;
});
// Find all array type constructor expressions for array types that have had
// their element changed to a single field structure. These constructors are
// adjusted to wrap each of the arguments with an additional constructor for
// Find all array type initializer expressions for array types that have had
// their element changed to a single field structure. These initializers are
// adjusted to wrap each of the arguments with an additional initializer for
// the new element structure type.
// Example:
// `@stride(32) array<i32, 3>(1, 2, 3)`
@@ -118,9 +118,9 @@ void DecomposeStridedArray::Run(CloneContext& ctx, const DataMap&, DataMap&) con
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::Expression* {
if (!expr->args.IsEmpty()) {
if (auto* call = sem.Get(expr)->UnwrapMaterialize()->As<sem::Call>()) {
if (auto* ctor = call->Target()->As<sem::TypeConstructor>()) {
if (auto* ctor = call->Target()->As<sem::TypeInitializer>()) {
if (auto* arr = ctor->ReturnType()->As<sem::Array>()) {
// Begin by cloning the array constructor type or name
// Begin by cloning the array initializer type or name
// If this is an unaliased array, this may add a new entry to
// decomposed.
// If this is an aliased array, decomposed should already be

View File

@@ -41,7 +41,7 @@ class Manager final : public Castable<Manager, Transform> {
/// Add pass to the manager of type `T`, constructed with the provided
/// arguments.
/// @param args the arguments to forward to the `T` constructor
/// @param args the arguments to forward to the `T` initializer
template <typename T, typename... ARGS>
void Add(ARGS&&... args) {
transforms_.emplace_back(std::make_unique<T>(std::forward<ARGS>(args)...));

View File

@@ -187,8 +187,8 @@ struct ModuleScopeVarToEntryPointParam::State {
// scope. Disable address space validation on this variable.
auto* disable_validation =
ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace);
auto* constructor = ctx.Clone(var->Declaration()->constructor);
auto* local_var = ctx.dst->Var(new_var_symbol, store_type(), sc, constructor,
auto* initializer = ctx.Clone(var->Declaration()->initializer);
auto* local_var = ctx.dst->Var(new_var_symbol, store_type(), sc, initializer,
utils::Vector{disable_validation});
ctx.InsertFront(func->body->statements, ctx.dst->Decl(local_var));
@@ -400,10 +400,10 @@ struct ModuleScopeVarToEntryPointParam::State {
// Redeclare the variable at function scope.
auto* disable_validation =
ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace);
auto* constructor = ctx.Clone(var->Declaration()->constructor);
auto* initializer = ctx.Clone(var->Declaration()->initializer);
auto* local_var = ctx.dst->Var(new_var_symbol,
CreateASTTypeFor(ctx, var->Type()->UnwrapRef()),
ast::AddressSpace::kPrivate, constructor,
ast::AddressSpace::kPrivate, initializer,
utils::Vector{disable_validation});
ctx.InsertFront(func_ast->body->statements, ctx.dst->Decl(local_var));
local_private_vars_.insert(var);

View File

@@ -213,7 +213,7 @@ fn zoo(@internal(disable_validation__ignore_address_space) @internal(disable_val
EXPECT_EQ(expect, str(got));
}
TEST_F(ModuleScopeVarToEntryPointParamTest, Constructors) {
TEST_F(ModuleScopeVarToEntryPointParamTest, Initializers) {
auto* src = R"(
var<private> a : f32 = 1.0;
var<private> b : f32 = f32();
@@ -238,7 +238,7 @@ fn main() {
EXPECT_EQ(expect, str(got));
}
TEST_F(ModuleScopeVarToEntryPointParamTest, Constructors_OutOfOrder) {
TEST_F(ModuleScopeVarToEntryPointParamTest, Initializers_OutOfOrder) {
auto* src = R"(
@compute @workgroup_size(1)
fn main() {

View File

@@ -138,11 +138,11 @@ struct MultiplanarExternalTexture::State {
// Replace the original texture_external binding with a texture_2d<f32> binding.
auto cloned_attributes = ctx.Clone(global->attributes);
const ast::Expression* cloned_constructor = ctx.Clone(global->constructor);
const ast::Expression* cloned_initializer = ctx.Clone(global->initializer);
auto* replacement =
b.Var(syms.plane_0, b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()),
cloned_constructor, cloned_attributes);
cloned_initializer, cloned_attributes);
ctx.Replace(global, replacement);
}

View File

@@ -22,7 +22,7 @@
#include "src/tint/program_builder.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/module.h"
#include "src/tint/sem/type_constructor.h"
#include "src/tint/sem/type_initializer.h"
using namespace tint::number_suffixes; // NOLINT
@@ -112,7 +112,7 @@ void PadStructs::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
if (!call) {
return nullptr;
}
auto* cons = call->Target()->As<sem::TypeConstructor>();
auto* cons = call->Target()->As<sem::TypeInitializer>();
if (!cons) {
return nullptr;
}

View File

@@ -521,8 +521,8 @@ fn main() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PadStructsTest, Constructor) {
// Calls to a constructor of a padded struct must be modified to initialize the padding.
TEST_F(PadStructsTest, Initializer) {
// Calls to a initializer of a padded struct must be modified to initialize the padding.
auto* src = R"(
struct S {
a : f32,
@@ -557,8 +557,8 @@ fn main() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PadStructsTest, ConstructorZeroArgs) {
// Calls to a zero-argument constructor of a padded struct should not be modified.
TEST_F(PadStructsTest, InitializerZeroArgs) {
// Calls to a zero-argument initializer of a padded struct should not be modified.
auto* src = R"(
struct S {
a : f32,

View File

@@ -16,7 +16,7 @@
#include "src/tint/program_builder.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/statement.h"
#include "src/tint/sem/type_constructor.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/transform/utils/hoist_to_decl_before.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::PromoteInitializersToLet);
@@ -45,9 +45,9 @@ void PromoteInitializersToLet::Run(CloneContext& ctx, const DataMap&, DataMap&)
auto* stmt = sem_stmt->Declaration();
if (auto* src_var_decl = stmt->As<ast::VariableDeclStatement>()) {
if (src_var_decl->variable->constructor == expr->Declaration()) {
if (src_var_decl->variable->initializer == expr->Declaration()) {
// This statement is just a variable declaration with the
// initializer as the constructor value. This is what we're
// initializer as the initializer value. This is what we're
// attempting to transform to, and so ignore.
return true;
}
@@ -68,7 +68,7 @@ void PromoteInitializersToLet::Run(CloneContext& ctx, const DataMap&, DataMap&)
[&](const ast::CallExpression* expr) {
if (auto* sem = ctx.src->Sem().Get(expr)) {
auto* ctor = sem->UnwrapMaterialize()->As<sem::Call>();
if (ctor->Target()->Is<sem::TypeConstructor>()) {
if (ctor->Target()->Is<sem::TypeInitializer>()) {
return promote(sem);
}
}

View File

@@ -19,7 +19,7 @@
namespace tint::transform {
/// A transform that hoists array and structure constructors, and identifiers resolving to a
/// A transform that hoists array and structure initializers, and identifiers resolving to a
/// 'const' array to a 'let' variable, declared just before the statement of usage.
/// This transform is used by backends that do not support expressions that operate on an immediate
/// array or structure. For example, the following is not immediately expressable for HLSL:

View File

@@ -396,7 +396,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
},
[&](const ast::SwitchStatement* s) { ProcessStatement(s->condition); },
[&](const ast::VariableDeclStatement* s) {
ProcessStatement(s->variable->constructor);
ProcessStatement(s->variable->initializer);
});
}
@@ -625,11 +625,11 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
},
[&](const ast::VariableDeclStatement* s) -> const ast::Statement* {
auto* var = s->variable;
if (!var->constructor || !sem.Get(var->constructor)->HasSideEffects()) {
if (!var->initializer || !sem.Get(var->initializer)->HasSideEffects()) {
return nullptr;
}
tint::utils::Vector<const ast::Statement*, 8> stmts;
ctx.Replace(var->constructor, Decompose(var->constructor, &stmts));
ctx.Replace(var->initializer, Decompose(var->initializer, &stmts));
InsertBefore(stmts, s);
return b.Decl(ctx.CloneWithoutTransform(var));
},

View File

@@ -614,7 +614,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, Binary_Arith_InTypeCtor) {
TEST_F(PromoteSideEffectsToDeclTest, Binary_Arith_InTypeInit) {
auto* src = R"(
fn a(i : i32) -> i32 {
@@ -1860,7 +1860,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, Binary_Logical_InTypeCtor) {
TEST_F(PromoteSideEffectsToDeclTest, Binary_Logical_InTypeInit) {
auto* src = R"(
fn a(i : i32) -> bool {
@@ -3030,7 +3030,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, TypeConstructor_Struct) {
TEST_F(PromoteSideEffectsToDeclTest, TypeInitializer_Struct) {
auto* src = R"(
fn a(i : i32) -> i32 {
return 1;
@@ -3072,7 +3072,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, TypeConstructor_Array1D) {
TEST_F(PromoteSideEffectsToDeclTest, TypeInitializer_Array1D) {
auto* src = R"(
fn a(i : i32) -> i32 {
return 1;
@@ -3102,7 +3102,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, TypeConstructor_Array2D) {
TEST_F(PromoteSideEffectsToDeclTest, TypeInitializer_Array2D) {
auto* src = R"(
fn a(i : i32) -> i32 {
return 1;
@@ -3809,7 +3809,7 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, TypeCtor_VarPlusI32CtorPlusVar) {
TEST_F(PromoteSideEffectsToDeclTest, TypeInit_VarPlusI32InitPlusVar) {
auto* src = R"(
fn f() {
var b = 0;

View File

@@ -70,7 +70,7 @@ void RemovePhonies::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
stmt->rhs, ctx.dst->Diagnostics(),
[&](const ast::CallExpression* expr) {
// ast::CallExpression may map to a function or builtin call
// (both may have side-effects), or a type constructor or
// (both may have side-effects), or a type initializer or
// type conversion (both do not have side effects).
auto* call = sem.Get<sem::Call>(expr);
if (!call) {

View File

@@ -112,7 +112,7 @@ struct SimplifyPointers::State {
if (var->Is<sem::LocalVariable>() && //
var->Declaration()->Is<ast::Let>() && //
var->Type()->Is<sem::Pointer>()) {
op.expr = var->Declaration()->constructor;
op.expr = var->Declaration()->initializer;
continue;
}
}
@@ -176,7 +176,7 @@ struct SimplifyPointers::State {
// to be hoist to temporary "saved" variables.
std::vector<const ast::VariableDeclStatement*> saved;
CollectSavedArrayIndices(
var->Declaration()->constructor, [&](const ast::Expression* idx_expr) {
var->Declaration()->initializer, [&](const ast::Expression* idx_expr) {
// We have a sub-expression that needs to be saved.
// Create a new variable
auto saved_name = ctx.dst->Symbols().New(

View File

@@ -163,7 +163,7 @@ struct SpirvAtomic::State {
if (v->type && atomic_variables.emplace(user->Variable()).second) {
ctx.Replace(v->type, AtomicTypeFor(user->Variable()->Type()));
}
if (auto* ctor = user->Variable()->Constructor()) {
if (auto* ctor = user->Variable()->Initializer()) {
atomic_expressions.Add(ctor);
}
},
@@ -266,10 +266,10 @@ struct SpirvAtomic::State {
},
[&](const ast::VariableDeclStatement* decl) {
auto* var = decl->variable;
if (auto* sem_ctor = ctx.src->Sem().Get(var->constructor)) {
if (is_ref_to_atomic_var(sem_ctor)) {
ctx.Replace(var->constructor, [=] {
auto* rhs = ctx.CloneWithoutTransform(var->constructor);
if (auto* sem_init = ctx.src->Sem().Get(var->initializer)) {
if (is_ref_to_atomic_var(sem_init)) {
ctx.Replace(var->initializer, [=] {
auto* rhs = ctx.CloneWithoutTransform(var->initializer);
return b.Call(sem::str(sem::BuiltinType::kAtomicLoad),
b.AddressOf(rhs));
});

View File

@@ -513,7 +513,7 @@ struct Std140::State {
// Found a pointer. As the source variable is a uniform buffer variable,
// this must be a pointer-let. Continue traversing from the let
// initializer.
expr = user->Variable()->Constructor();
expr = user->Variable()->Initializer();
return Action::kContinue;
}
TINT_ICE(Transform, b.Diagnostics())

View File

@@ -57,13 +57,13 @@ void SubstituteOverride::Run(CloneContext& ctx, const DataMap& config, DataMap&)
// No replacement provided, just clone the override node as a const.
auto iter = data->map.find(sem->OverrideId());
if (iter == data->map.end()) {
if (!w->constructor) {
if (!w->initializer) {
ctx.dst->Diagnostics().add_error(
diag::System::Transform,
"Initializer not provided for override, and override not overridden.");
return nullptr;
}
return ctx.dst->Const(src, sym, ty, ctx.Clone(w->constructor));
return ctx.dst->Const(src, sym, ty, ctx.Clone(w->initializer));
}
auto value = iter->second;

View File

@@ -77,7 +77,7 @@ class DataMap {
/// Creates the data of type `T` with the provided arguments and adds it into
/// DataMap keyed by the ClassID of type T.
/// @param args the arguments forwarded to the constructor for type T
/// @param args the arguments forwarded to the initializer for type T
template <typename T, typename... ARGS>
void Add(ARGS&&... args) {
Put(std::make_unique<T>(std::forward<ARGS>(args)...));

View File

@@ -52,19 +52,19 @@ struct Unshadow::State {
auto source = ctx.Clone(decl->source);
auto* type = ctx.Clone(decl->type);
auto* constructor = ctx.Clone(decl->constructor);
auto* initializer = ctx.Clone(decl->initializer);
auto attributes = ctx.Clone(decl->attributes);
return Switch(
decl, //
[&](const ast::Var* var) {
return ctx.dst->Var(source, symbol, type, var->declared_address_space,
var->declared_access, constructor, attributes);
var->declared_access, initializer, attributes);
},
[&](const ast::Let*) {
return ctx.dst->Let(source, symbol, type, constructor, attributes);
return ctx.dst->Let(source, symbol, type, initializer, attributes);
},
[&](const ast::Const*) {
return ctx.dst->Const(source, symbol, type, constructor, attributes);
return ctx.dst->Const(source, symbol, type, initializer, attributes);
},
[&](const ast::Parameter*) {
return ctx.dst->Param(source, symbol, type, attributes);

View File

@@ -295,10 +295,10 @@ class State {
},
[&](const ast::VariableDeclStatement* s) -> const ast::Statement* {
auto* var = s->variable;
if (!var->constructor) {
if (!var->initializer) {
return nullptr;
}
auto* sem_expr = sem.Get(var->constructor);
auto* sem_expr = sem.Get(var->initializer);
if (!MayDiscard(sem_expr)) {
return nullptr;
}

View File

@@ -331,8 +331,8 @@ fn convert_${mat_shape}_f32_f16(value : ${f32_mat_type}) -> ${f16_mat_type} {
EXPECT_EQ(expect, str(got));
}
// Test that VectorizeMatrixConversions transform will not run for matrix constructor.
TEST_P(VectorizeMatrixConversionsTest, NonConversion_ConstructorFromVectors) {
// Test that VectorizeMatrixConversions transform will not run for matrix initializer.
TEST_P(VectorizeMatrixConversionsTest, NonConversion_InitializerFromVectors) {
uint32_t cols = GetParam().first;
uint32_t rows = GetParam().second;
std::string mat_type = "mat" + std::to_string(cols) + "x" + std::to_string(rows) + "<f32>";
@@ -362,9 +362,9 @@ fn main() {
EXPECT_EQ(expect, str(got));
}
// Test that VectorizeMatrixConversions transform will not run for identity matrix constructor,
// Test that VectorizeMatrixConversions transform will not run for identity matrix initializer,
// which also take a single matrix as input.
TEST_P(VectorizeMatrixConversionsTest, NonConversion_IdentityConstructor) {
TEST_P(VectorizeMatrixConversionsTest, NonConversion_IdentityInitializer) {
uint32_t cols = GetParam().first;
uint32_t rows = GetParam().second;
std::string mat_type = "mat" + std::to_string(cols) + "x" + std::to_string(rows) + "<f32>";

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/transform/vectorize_scalar_matrix_constructors.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include <unordered_map>
#include <utility>
@@ -21,21 +21,21 @@
#include "src/tint/sem/abstract_numeric.h"
#include "src/tint/sem/call.h"
#include "src/tint/sem/expression.h"
#include "src/tint/sem/type_constructor.h"
#include "src/tint/sem/type_initializer.h"
#include "src/tint/utils/map.h"
TINT_INSTANTIATE_TYPEINFO(tint::transform::VectorizeScalarMatrixConstructors);
TINT_INSTANTIATE_TYPEINFO(tint::transform::VectorizeScalarMatrixInitializers);
namespace tint::transform {
VectorizeScalarMatrixConstructors::VectorizeScalarMatrixConstructors() = default;
VectorizeScalarMatrixInitializers::VectorizeScalarMatrixInitializers() = default;
VectorizeScalarMatrixConstructors::~VectorizeScalarMatrixConstructors() = default;
VectorizeScalarMatrixInitializers::~VectorizeScalarMatrixInitializers() = default;
bool VectorizeScalarMatrixConstructors::ShouldRun(const Program* program, const DataMap&) const {
bool VectorizeScalarMatrixInitializers::ShouldRun(const Program* program, const DataMap&) const {
for (auto* node : program->ASTNodes().Objects()) {
if (auto* call = program->Sem().Get<sem::Call>(node)) {
if (call->Target()->Is<sem::TypeConstructor>() && call->Type()->Is<sem::Matrix>()) {
if (call->Target()->Is<sem::TypeInitializer>() && call->Type()->Is<sem::Matrix>()) {
auto& args = call->Arguments();
if (!args.IsEmpty() && args[0]->Type()->UnwrapRef()->is_scalar()) {
return true;
@@ -46,13 +46,13 @@ bool VectorizeScalarMatrixConstructors::ShouldRun(const Program* program, const
return false;
}
void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
std::unordered_map<const sem::Matrix*, Symbol> scalar_ctors;
void VectorizeScalarMatrixInitializers::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
std::unordered_map<const sem::Matrix*, Symbol> scalar_inits;
ctx.ReplaceAll([&](const ast::CallExpression* expr) -> const ast::CallExpression* {
auto* call = ctx.src->Sem().Get(expr)->UnwrapMaterialize()->As<sem::Call>();
auto* ty_ctor = call->Target()->As<sem::TypeConstructor>();
if (!ty_ctor) {
auto* ty_init = call->Target()->As<sem::TypeInitializer>();
if (!ty_init) {
return nullptr;
}
auto* mat_type = call->Type()->As<sem::Matrix>();
@@ -65,7 +65,7 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
return nullptr;
}
// If the argument type is a matrix, then this is an identity / conversion constructor.
// If the argument type is a matrix, then this is an identity / conversion initializer.
// 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.
@@ -97,7 +97,7 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
// Generate a helper function for constructing the matrix.
// This is done to ensure that the single argument value is only evaluated once, and
// with the correct expression evaluation order.
auto fn = utils::GetOrCreate(scalar_ctors, mat_type, [&] {
auto fn = utils::GetOrCreate(scalar_inits, mat_type, [&] {
auto name =
ctx.dst->Symbols().New("build_mat" + std::to_string(mat_type->columns()) + "x" +
std::to_string(mat_type->rows()));
@@ -124,7 +124,7 @@ void VectorizeScalarMatrixConstructors::Run(CloneContext& ctx, const DataMap&, D
}
TINT_ICE(Transform, ctx.dst->Diagnostics())
<< "matrix constructor has unexpected number of arguments";
<< "matrix initializer has unexpected number of arguments";
return nullptr;
});

View File

@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_CONSTRUCTORS_H_
#define SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_CONSTRUCTORS_H_
#ifndef SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_INITIALIZERS_H_
#define SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_INITIALIZERS_H_
#include "src/tint/transform/transform.h"
namespace tint::transform {
/// A transform that converts scalar matrix constructors to the vector form.
class VectorizeScalarMatrixConstructors final
: public Castable<VectorizeScalarMatrixConstructors, Transform> {
/// A transform that converts scalar matrix initializers to the vector form.
class VectorizeScalarMatrixInitializers final
: public Castable<VectorizeScalarMatrixInitializers, Transform> {
public:
/// Constructor
VectorizeScalarMatrixConstructors();
VectorizeScalarMatrixInitializers();
/// Destructor
~VectorizeScalarMatrixConstructors() override;
~VectorizeScalarMatrixInitializers() override;
/// @param program the program to inspect
/// @param data optional extra transform-specific input data
@@ -46,4 +46,4 @@ class VectorizeScalarMatrixConstructors final
} // namespace tint::transform
#endif // SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_CONSTRUCTORS_H_
#endif // SRC_TINT_TRANSFORM_VECTORIZE_SCALAR_MATRIX_INITIALIZERS_H_

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "src/tint/transform/vectorize_scalar_matrix_constructors.h"
#include "src/tint/transform/vectorize_scalar_matrix_initializers.h"
#include <string>
#include <utility>
@@ -23,15 +23,15 @@
namespace tint::transform {
namespace {
using VectorizeScalarMatrixConstructorsTest = TransformTestWithParam<std::pair<uint32_t, uint32_t>>;
using VectorizeScalarMatrixInitializersTest = TransformTestWithParam<std::pair<uint32_t, uint32_t>>;
TEST_F(VectorizeScalarMatrixConstructorsTest, ShouldRunEmptyModule) {
TEST_F(VectorizeScalarMatrixInitializersTest, ShouldRunEmptyModule) {
auto* src = R"()";
EXPECT_FALSE(ShouldRun<VectorizeScalarMatrixConstructors>(src));
EXPECT_FALSE(ShouldRun<VectorizeScalarMatrixInitializers>(src));
}
TEST_P(VectorizeScalarMatrixConstructorsTest, MultipleScalars) {
TEST_P(VectorizeScalarMatrixInitializersTest, MultipleScalars) {
uint32_t cols = GetParam().first;
uint32_t rows = GetParam().second;
std::string mat_type = "mat" + std::to_string(cols) + "x" + std::to_string(rows) + "<f32>";
@@ -66,14 +66,14 @@ fn main() {
auto src = utils::ReplaceAll(tmpl, "${values}", scalar_values);
auto expect = utils::ReplaceAll(tmpl, "${values}", vector_values);
EXPECT_TRUE(ShouldRun<VectorizeScalarMatrixConstructors>(src));
EXPECT_TRUE(ShouldRun<VectorizeScalarMatrixInitializers>(src));
auto got = Run<VectorizeScalarMatrixConstructors>(src);
auto got = Run<VectorizeScalarMatrixInitializers>(src);
EXPECT_EQ(expect, str(got));
}
TEST_P(VectorizeScalarMatrixConstructorsTest, MultipleScalarsReference) {
TEST_P(VectorizeScalarMatrixInitializersTest, MultipleScalarsReference) {
uint32_t cols = GetParam().first;
uint32_t rows = GetParam().second;
std::string mat_type = "mat" + std::to_string(cols) + "x" + std::to_string(rows) + "<f32>";
@@ -109,14 +109,14 @@ fn main() {
auto src = utils::ReplaceAll(tmpl, "${values}", scalar_values);
auto expect = utils::ReplaceAll(tmpl, "${values}", vector_values);
EXPECT_TRUE(ShouldRun<VectorizeScalarMatrixConstructors>(src));
EXPECT_TRUE(ShouldRun<VectorizeScalarMatrixInitializers>(src));
auto got = Run<VectorizeScalarMatrixConstructors>(src);
auto got = Run<VectorizeScalarMatrixInitializers>(src);
EXPECT_EQ(expect, str(got));
}
TEST_P(VectorizeScalarMatrixConstructorsTest, NonScalarConstructors) {
TEST_P(VectorizeScalarMatrixInitializersTest, NonScalarInitializers) {
uint32_t cols = GetParam().first;
uint32_t rows = GetParam().second;
std::string mat_type = "mat" + std::to_string(cols) + "x" + std::to_string(rows) + "<f32>";
@@ -139,15 +139,15 @@ fn main() {
auto src = utils::ReplaceAll(tmpl, "${columns}", columns);
auto expect = src;
EXPECT_FALSE(ShouldRun<VectorizeScalarMatrixConstructors>(src));
EXPECT_FALSE(ShouldRun<VectorizeScalarMatrixInitializers>(src));
auto got = Run<VectorizeScalarMatrixConstructors>(src);
auto got = Run<VectorizeScalarMatrixInitializers>(src);
EXPECT_EQ(expect, str(got));
}
INSTANTIATE_TEST_SUITE_P(VectorizeScalarMatrixConstructorsTest,
VectorizeScalarMatrixConstructorsTest,
INSTANTIATE_TEST_SUITE_P(VectorizeScalarMatrixInitializersTest,
VectorizeScalarMatrixInitializersTest,
testing::Values(std::make_pair(2, 2),
std::make_pair(2, 3),
std::make_pair(2, 4),

View File

@@ -396,7 +396,7 @@ struct ZeroInitWorkgroupMemory::State {
}
/// @returns true if a variable with store type `ty` can be efficiently zeroed
/// by assignment of a type constructor without operands. If
/// by assignment of a type initializer without operands. If
/// CanTriviallyZero() returns false, then the type needs to be
/// initialized by decomposing the initialization into multiple
/// sub-initializations.