tint: Have ast::MemberAccessorExpression use ast::Identifier

Instead of ast::IdentifierExpression
The member is not an expression, but a name.

Fixed: tint:1257
Change-Id: I879ddf09c3e521a18cef85422bb2f8fe78cddf5b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118343
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
Ben Clayton
2023-02-02 20:44:53 +00:00
committed by Dawn LUCI CQ
parent 6cba18b0fc
commit a4117ca21b
27 changed files with 109 additions and 145 deletions

View File

@@ -439,7 +439,7 @@ struct CanonicalizeEntryPointIO::State {
const ast::Expression* GLPosition(const char* component) {
Symbol pos = ctx.dst->Symbols().Register("gl_Position");
Symbol c = ctx.dst->Symbols().Register(component);
return ctx.dst->MemberAccessor(ctx.dst->Expr(pos), ctx.dst->Expr(c));
return ctx.dst->MemberAccessor(ctx.dst->Expr(pos), c);
}
/// Create the wrapper function's struct parameter and type objects.

View File

@@ -915,7 +915,7 @@ Transform::ApplyResult DecomposeMemoryAccess::Apply(const Program* src,
} else {
if (auto access = state.TakeAccess(accessor->structure)) {
auto* str_ty = access.type->As<sem::Struct>();
auto* member = str_ty->FindMember(accessor->member->identifier->symbol);
auto* member = str_ty->FindMember(accessor->member->symbol);
auto offset = member->Offset();
state.AddAccess(accessor, {
access.var,

View File

@@ -177,7 +177,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src,
continue;
}
if (to_replace.count({ident->identifier->symbol, accessor->member->identifier->symbol})) {
if (to_replace.count({ident->identifier->symbol, accessor->member->symbol})) {
ctx.Replace(accessor, b.MemberAccessor(get_ubo()->symbol, kNumWorkgroupsMemberName));
}
}

View File

@@ -134,7 +134,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
return false;
},
[&](const ast::MemberAccessorExpression* e) {
if (HasSideEffects(e->structure) || HasSideEffects(e->member)) {
if (HasSideEffects(e->structure)) {
return true;
}
no_side_effects.insert(e);
@@ -216,7 +216,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
return false;
};
auto binary_process = [&](auto* lhs, auto* rhs) {
auto binary_process = [&](const ast::Expression* lhs, const ast::Expression* rhs) {
// If neither side causes side-effects, but at least one receives them,
// let parent node hoist. This avoids over-hoisting side-effect receivers
// of compound binary expressions (e.g. for "((a && b) && c) && f()", we
@@ -236,7 +236,8 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
return false;
};
auto accessor_process = [&](auto* lhs, auto* rhs) {
auto accessor_process = [&](const ast::Expression* lhs,
const ast::Expression* rhs = nullptr) {
auto maybe = process(lhs);
// If lhs is a variable, let parent node hoist otherwise flush it right
// away. This is to avoid over-hoisting the lhs of accessor chains (e.g.
@@ -247,7 +248,9 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
Flush(maybe_hoist);
maybe = false;
}
default_process(rhs);
if (rhs) {
default_process(rhs);
}
return maybe;
};
@@ -320,9 +323,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
[&](const ast::IndexAccessorExpression* e) {
return accessor_process(e->object, e->index);
},
[&](const ast::MemberAccessorExpression* e) {
return accessor_process(e->structure, e->member);
},
[&](const ast::MemberAccessorExpression* e) { return accessor_process(e->structure); },
[&](const ast::LiteralExpression*) {
// Leaf
return false;
@@ -519,7 +520,6 @@ class DecomposeSideEffects::DecomposeState : public StateBase {
},
[&](const ast::MemberAccessorExpression* member) {
ctx.Replace(member->structure, decompose(member->structure));
ctx.Replace(member->member, decompose(member->member));
return clone_maybe_hoisted(member);
},
[&](const ast::UnaryOpExpression* unary) {

View File

@@ -1287,11 +1287,11 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
[&](const ast::MemberAccessorExpression* accessor) {
auto* sem = src->Sem().Get(accessor)->UnwrapLoad();
if (sem->Is<sem::Swizzle>()) {
preserved_identifiers.Add(accessor->member->identifier);
preserved_identifiers.Add(accessor->member);
} else if (auto* str_expr = src->Sem().Get(accessor->structure)) {
if (auto* ty = str_expr->Type()->UnwrapRef()->As<sem::Struct>()) {
if (ty->Declaration() == nullptr) { // Builtin structure
preserved_identifiers.Add(accessor->member->identifier);
preserved_identifiers.Add(accessor->member);
}
}
}

View File

@@ -90,7 +90,7 @@ struct SpirvAtomic::State {
auto old_value_decl = b.Decl(b.Let(
old_value,
b.MemberAccessor(b.Call(sem::str(stub->builtin), std::move(out_args)),
b.Expr("old_value"))));
"old_value")));
ctx.InsertBefore(block->statements, call->Stmt()->Declaration(),
old_value_decl);
ctx.Replace(call->Declaration(), b.Expr(old_value));