tint: Have ast::IdentifierExpression use ast::Identifier

The additional nesting is somewhat unfortunate for pointer
indirection overhead, but this simplfies logic like
transform::Renamer, which can continue to find all the
identifier nodes in the program.

Bug: tint:1257
Change-Id: I8d51dd80dc4c51ef59238959029b8511f1edf70d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118342
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton
2023-02-02 20:37:19 +00:00
committed by Dawn LUCI CQ
parent 08027c662e
commit 6cba18b0fc
44 changed files with 332 additions and 374 deletions

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->symbol);
auto* member = str_ty->FindMember(accessor->member->identifier->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->symbol, accessor->member->symbol})) {
if (to_replace.count({ident->identifier->symbol, accessor->member->identifier->symbol})) {
ctx.Replace(accessor, b.MemberAccessor(get_ubo()->symbol, kNumWorkgroupsMemberName));
}
}

View File

@@ -1263,8 +1263,6 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
// Identifiers that need to keep their symbols preserved.
utils::Hashset<const ast::Identifier*, 8> preserved_identifiers;
// Identifiers expressions that need to keep their symbols preserved.
utils::Hashset<const ast::IdentifierExpression*, 8> preserved_identifiers_expressions;
// Type names that need to keep their symbols preserved.
utils::Hashset<const ast::TypeName*, 8> preserved_type_names;
@@ -1289,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_expressions.Add(accessor->member);
preserved_identifiers.Add(accessor->member->identifier);
} 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_expressions.Add(accessor->member);
preserved_identifiers.Add(accessor->member->identifier);
}
}
}
@@ -1316,7 +1314,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
}
},
[&](const ast::DiagnosticControl* diagnostic) {
preserved_identifiers_expressions.Add(diagnostic->rule_name);
preserved_identifiers.Add(diagnostic->rule_name->identifier);
},
[&](const ast::TypeName* type_name) {
if (is_type_short_name(type_name->name)) {
@@ -1388,16 +1386,6 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
return nullptr; // Clone ident. Uses the symbol remapping above.
});
ctx.ReplaceAll([&](const ast::IdentifierExpression* ident) -> const ast::IdentifierExpression* {
if (preserved_identifiers_expressions.Contains(ident)) {
auto sym_in = ident->symbol;
auto str = src->Symbols().NameFor(sym_in);
auto sym_out = b.Symbols().Register(str);
return ctx.dst->create<ast::IdentifierExpression>(ctx.Clone(ident->source), sym_out);
}
return nullptr; // Clone ident. Uses the symbol remapping above.
});
ctx.ReplaceAll([&](const ast::TypeName* type_name) -> const ast::TypeName* {
if (preserved_type_names.Contains(type_name)) {
auto sym_in = type_name->name;