tint/ast: Change Variable::symbol to Variable::name

Variable::name is an ast::Identifier.

The goal here is to have all AST nodes use an identifier instead of
symbols directly. This will greatly simplify the renamer transform,
and gives the symbol a Source location, which is helpful for
diagnostics and tooling.

Change-Id: I71fe3e8df3d22b12d4a3430c41f236ddf5bc0b9e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119282
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2023-02-09 10:34:14 +00:00
parent 199440e37c
commit 651d9e2558
51 changed files with 237 additions and 219 deletions

View File

@@ -70,7 +70,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
auto* wrapper = wrapper_structs.GetOrCreate(ty, [&] {
auto* block = b.ASTNodes().Create<BlockAttribute>(b.ID(), b.AllocateNodeID());
auto wrapper_name = src->Symbols().NameFor(global->symbol) + "_block";
auto wrapper_name = src->Symbols().NameFor(global->name->symbol) + "_block";
auto* ret = b.create<ast::Struct>(
b.Symbols().New(wrapper_name),
utils::Vector{b.Member(kMemberName, CreateASTTypeFor(ctx, ty))},
@@ -84,7 +84,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
// any usage of the original variable.
for (auto* user : var->Users()) {
ctx.Replace(user->Declaration(),
b.MemberAccessor(ctx.Clone(global->symbol), kMemberName));
b.MemberAccessor(ctx.Clone(global->name->symbol), kMemberName));
}
} else {
// Add a block attribute to this struct directly.

View File

@@ -131,7 +131,7 @@ struct ArrayLengthFromUniform::State {
// Load the total storage buffer size from the UBO.
uint32_t array_index = size_index / 4;
auto* vec_expr = b.IndexAccessor(
b.MemberAccessor(get_ubo()->symbol, kBufferSizeMemberName), u32(array_index));
b.MemberAccessor(get_ubo()->name->symbol, kBufferSizeMemberName), u32(array_index));
uint32_t vec_index = size_index % 4;
auto* total_storage_buffer_size = b.IndexAccessor(vec_expr, u32(vec_index));

View File

@@ -139,9 +139,9 @@ Transform::ApplyResult BindingRemapper::Apply(const Program* src,
}
auto* ty = sem->Type()->UnwrapRef();
const ast::Type* inner_ty = CreateASTTypeFor(ctx, ty);
auto* new_var = b.Var(ctx.Clone(var->source), ctx.Clone(var->symbol), inner_ty,
var->declared_address_space, ac, ctx.Clone(var->initializer),
ctx.Clone(var->attributes));
auto* new_var = b.Var(ctx.Clone(var->source), ctx.Clone(var->name->symbol),
inner_ty, var->declared_address_space, ac,
ctx.Clone(var->initializer), ctx.Clone(var->attributes));
ctx.Replace(var, new_var);
}

View File

@@ -192,7 +192,7 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src,
// translated to:
// X.GetDimensions(ARGS..) by the writer
buffer_size, b.AddressOf(ctx.Clone(storage_buffer_expr)),
b.AddressOf(b.Expr(buffer_size_result->variable->symbol))));
b.AddressOf(b.Expr(buffer_size_result->variable->name->symbol))));
// Calculate actual array length
// total_storage_buffer_size - array_offset

View File

@@ -334,7 +334,7 @@ struct CanonicalizeEntryPointIO::State {
}
}
auto name = ctx.src->Symbols().NameFor(param->Declaration()->symbol);
auto name = ctx.src->Symbols().NameFor(param->Declaration()->name->symbol);
auto* input_expr = AddInput(name, param->Type(), param->Location(), std::move(attributes));
inner_call_parameters.Push(input_expr);
}
@@ -615,7 +615,7 @@ struct CanonicalizeEntryPointIO::State {
// Process the original return type to determine the outputs that the
// outer function needs to produce.
ProcessReturnType(func_sem->ReturnType(), inner_result->symbol);
ProcessReturnType(func_sem->ReturnType(), inner_result->name->symbol);
}
// Add a fixed sample mask, if necessary.

View File

@@ -185,10 +185,10 @@ struct CombineSamplers::State {
const sem::Variable* texture_var = pair.first;
const sem::Variable* sampler_var = pair.second;
std::string name =
ctx.src->Symbols().NameFor(texture_var->Declaration()->symbol);
ctx.src->Symbols().NameFor(texture_var->Declaration()->name->symbol);
if (sampler_var) {
name +=
"_" + ctx.src->Symbols().NameFor(sampler_var->Declaration()->symbol);
name += "_" + ctx.src->Symbols().NameFor(
sampler_var->Declaration()->name->symbol);
}
if (IsGlobal(pair)) {
// Both texture and sampler are global; add a new global variable
@@ -263,7 +263,7 @@ struct CombineSamplers::State {
? global_combined_texture_samplers_[new_pair]
: function_combined_texture_samplers_[call->Stmt()->Function()]
[new_pair];
args.Push(ctx.dst->Expr(var->symbol));
args.Push(ctx.dst->Expr(var->name->symbol));
} else if (auto* sampler_type = type->As<type::Sampler>()) {
type::SamplerKind kind = sampler_type->kind();
int index = (kind == type::SamplerKind::kSampler) ? 0 : 1;
@@ -271,7 +271,7 @@ struct CombineSamplers::State {
if (!p) {
p = CreatePlaceholder(kind);
}
args.Push(ctx.dst->Expr(p->symbol));
args.Push(ctx.dst->Expr(p->name->symbol));
} else {
args.Push(ctx.Clone(arg));
}
@@ -317,7 +317,7 @@ struct CombineSamplers::State {
? global_combined_texture_samplers_[new_pair]
: function_combined_texture_samplers_[call->Stmt()->Function()]
[new_pair];
auto* arg = ctx.dst->Expr(var->symbol);
auto* arg = ctx.dst->Expr(var->name->symbol);
args.Push(arg);
}
// Append all of the remaining non-texture and non-sampler

View File

@@ -711,13 +711,13 @@ struct DirectVariableAccess::State {
PtrParamSymbols symbols;
if (requires_base_ptr_param && requires_indices_param) {
auto original_name = param->Declaration()->symbol;
auto original_name = param->Declaration()->name->symbol;
symbols.base_ptr = UniqueSymbolWithSuffix(original_name, "_base");
symbols.indices = UniqueSymbolWithSuffix(original_name, "_indices");
} else if (requires_base_ptr_param) {
symbols.base_ptr = ctx.Clone(param->Declaration()->symbol);
symbols.base_ptr = ctx.Clone(param->Declaration()->name->symbol);
} else if (requires_indices_param) {
symbols.indices = ctx.Clone(param->Declaration()->symbol);
symbols.indices = ctx.Clone(param->Declaration()->name->symbol);
}
// Remember this base pointer name.
@@ -1085,7 +1085,7 @@ struct DirectVariableAccess::State {
if (IsPrivateOrFunction(shape.root.address_space)) {
ss << "F";
} else {
ss << ctx.src->Symbols().NameFor(shape.root.variable->Declaration()->symbol);
ss << ctx.src->Symbols().NameFor(shape.root.variable->Declaration()->name->symbol);
}
for (auto& op : shape.ops) {
@@ -1122,7 +1122,7 @@ struct DirectVariableAccess::State {
}
}
const ast::Expression* expr = b.Expr(ctx.Clone(root.variable->Declaration()->symbol));
const ast::Expression* expr = b.Expr(ctx.Clone(root.variable->Declaration()->name->symbol));
if (deref) {
if (root.variable->Type()->Is<type::Pointer>()) {
expr = b.Deref(expr);

View File

@@ -174,7 +174,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// TODO(jrprice): Do this for all other workgroup variables too.
// Create a member in the workgroup parameter struct.
auto member = ctx.Clone(var->Declaration()->symbol);
auto member = ctx.Clone(var->Declaration()->name->symbol);
workgroup_parameter_members.Push(ctx.dst->Member(member, store_type()));
CloneStructTypes(var->Type()->UnwrapRef());

View File

@@ -139,7 +139,7 @@ struct MultiplanarExternalTexture::State {
// with the texture_external binding that corresponds with the new destination bindings.
// NewBindingSymbols new_binding_syms;
auto& syms = new_binding_symbols[sem_var];
syms.plane_0 = ctx.Clone(global->symbol);
syms.plane_0 = ctx.Clone(global->name->symbol);
syms.plane_1 = b.Symbols().New("ext_tex_plane_1");
b.GlobalVar(syms.plane_1, b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()),
b.Group(AInt(bps.plane_1.group)), b.Binding(AInt(bps.plane_1.binding)));
@@ -174,7 +174,7 @@ struct MultiplanarExternalTexture::State {
// into the transform state so they can be used when transforming function
// calls.
auto& syms = new_binding_symbols[sem_var];
syms.plane_0 = ctx.Clone(param->symbol);
syms.plane_0 = ctx.Clone(param->name->symbol);
syms.plane_1 = b.Symbols().New("ext_tex_plane_1");
syms.params = b.Symbols().New("ext_tex_params");
auto tex2d_f32 = [&] {

View File

@@ -107,7 +107,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src,
// Capture the symbols that would be used to access this member, which
// we will replace later. We currently have no way to get from the
// parameter directly to the member accessor expressions that use it.
to_replace.insert({param->Declaration()->symbol, member->Name()});
to_replace.insert({param->Declaration()->name->symbol, member->Name()});
// Remove the struct member.
// The CanonicalizeEntryPointIO transform will have generated this
@@ -178,7 +178,8 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src,
}
if (to_replace.count({ident->identifier->symbol, accessor->member->symbol})) {
ctx.Replace(accessor, b.MemberAccessor(get_ubo()->symbol, kNumWorkgroupsMemberName));
ctx.Replace(accessor,
b.MemberAccessor(get_ubo()->name->symbol, kNumWorkgroupsMemberName));
}
}

View File

@@ -158,7 +158,8 @@ struct SimplifyPointers::State {
// We have a sub-expression that needs to be saved.
// Create a new variable
auto saved_name = ctx.dst->Symbols().New(
ctx.src->Symbols().NameFor(var->Declaration()->symbol) + "_save");
ctx.src->Symbols().NameFor(var->Declaration()->name->symbol) +
"_save");
auto* decl =
ctx.dst->Decl(ctx.dst->Let(saved_name, ctx.Clone(idx_expr)));
saved.Push(decl);

View File

@@ -529,7 +529,7 @@ struct Std140::State {
}
TINT_ICE(Transform, b.Diagnostics())
<< "unexpected variable found walking access chain: "
<< sym.NameFor(user->Variable()->Declaration()->symbol);
<< sym.NameFor(user->Variable()->Declaration()->name->symbol);
return Action::kError;
},
[&](const sem::StructMemberAccess* a) {
@@ -879,7 +879,9 @@ struct Std140::State {
});
// Method for generating dynamic index expressions.
// These are passed in as arguments to the function.
auto dynamic_index = [&](size_t idx) { return b.Expr(dynamic_index_params[idx]->symbol); };
auto dynamic_index = [&](size_t idx) {
return b.Expr(dynamic_index_params[idx]->name->symbol);
};
// Fetch the access chain indices of the matrix access and the parameter index that
// holds the matrix column index.
@@ -987,7 +989,9 @@ struct Std140::State {
});
// Method for generating dynamic index expressions.
// These are passed in as arguments to the function.
auto dynamic_index = [&](size_t idx) { return b.Expr(dynamic_index_params[idx]->symbol); };
auto dynamic_index = [&](size_t idx) {
return b.Expr(dynamic_index_params[idx]->name->symbol);
};
const ast::Expression* expr = nullptr;
const type::Type* ty = nullptr;
@@ -1073,8 +1077,9 @@ struct Std140::State {
auto& access = chain.indices[index];
if (std::get_if<UniformVariable>(&access)) {
const auto* expr = b.Expr(ctx.Clone(chain.var->Declaration()->symbol));
const auto name = src->Symbols().NameFor(chain.var->Declaration()->symbol);
const auto symbol = chain.var->Declaration()->name->symbol;
const auto* expr = b.Expr(ctx.Clone(symbol));
const auto name = src->Symbols().NameFor(symbol);
ty = chain.var->Type()->UnwrapRef();
return {expr, ty, name};
}

View File

@@ -63,7 +63,7 @@ Transform::ApplyResult SubstituteOverride::Apply(const Program* src,
auto* sem = ctx.src->Sem().Get(w);
auto source = ctx.Clone(w->source);
auto sym = ctx.Clone(w->symbol);
auto sym = ctx.Clone(w->name->symbol);
auto* ty = ctx.Clone(w->type);
// No replacement provided, just clone the override node as a const.

View File

@@ -85,9 +85,9 @@ struct Texture1DTo2D::State {
auto create_var = [&](const ast::Variable* v, ast::Type* type) -> const ast::Variable* {
if (v->As<ast::Parameter>()) {
return ctx.dst->Param(ctx.Clone(v->symbol), type, ctx.Clone(v->attributes));
return ctx.dst->Param(ctx.Clone(v->name->symbol), type, ctx.Clone(v->attributes));
} else {
return ctx.dst->Var(ctx.Clone(v->symbol), type, ctx.Clone(v->attributes));
return ctx.dst->Var(ctx.Clone(v->name->symbol), type, ctx.Clone(v->attributes));
}
};

View File

@@ -51,7 +51,7 @@ struct Unshadow::State {
auto rename = [&](const sem::Variable* v) -> const ast::Variable* {
auto* decl = v->Declaration();
auto name = src->Symbols().NameFor(decl->symbol);
auto name = src->Symbols().NameFor(decl->name->symbol);
auto symbol = b.Symbols().New(name);
renamed_to.Add(v, symbol);

View File

@@ -756,7 +756,7 @@ struct VertexPulling::State {
void ProcessNonStructParameter(const ast::Function* func, const ast::Parameter* param) {
if (ast::HasAttribute<ast::LocationAttribute>(param->attributes)) {
// Create a function-scope variable to replace the parameter.
auto func_var_sym = ctx.Clone(param->symbol);
auto func_var_sym = ctx.Clone(param->name->symbol);
auto* func_var_type = ctx.Clone(param->type);
auto* func_var = b.Var(func_var_sym, func_var_type);
ctx.InsertFront(func->body->statements, b.Decl(func_var));
@@ -780,9 +780,13 @@ struct VertexPulling::State {
}
// Check for existing vertex_index and instance_index builtins.
if (builtin->builtin == ast::BuiltinValue::kVertexIndex) {
vertex_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->symbol)); };
vertex_index_expr = [this, param]() {
return b.Expr(ctx.Clone(param->name->symbol));
};
} else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) {
instance_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->symbol)); };
instance_index_expr = [this, param]() {
return b.Expr(ctx.Clone(param->name->symbol));
};
}
new_function_parameters.Push(ctx.Clone(param));
}
@@ -799,7 +803,7 @@ struct VertexPulling::State {
void ProcessStructParameter(const ast::Function* func,
const ast::Parameter* param,
const ast::Struct* struct_ty) {
auto param_sym = ctx.Clone(param->symbol);
auto param_sym = ctx.Clone(param->name->symbol);
// Process the struct members.
bool has_locations = false;

View File

@@ -141,7 +141,7 @@ struct ZeroInitWorkgroupMemory::State {
for (auto* var : func->TransitivelyReferencedGlobals()) {
if (var->AddressSpace() == type::AddressSpace::kWorkgroup) {
auto get_expr = [&](uint32_t num_values) {
auto var_name = ctx.Clone(var->Declaration()->symbol);
auto var_name = ctx.Clone(var->Declaration()->name->symbol);
return Expression{b.Expr(var_name), num_values, ArrayIndices{}};
};
if (!BuildZeroingStatements(var->Type()->UnwrapRef(), get_expr)) {
@@ -160,7 +160,7 @@ struct ZeroInitWorkgroupMemory::State {
for (auto* param : fn->params) {
if (auto* builtin = ast::GetAttribute<ast::BuiltinAttribute>(param->attributes)) {
if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) {
local_index = [=] { return b.Expr(ctx.Clone(param->symbol)); };
local_index = [=] { return b.Expr(ctx.Clone(param->name->symbol)); };
break;
}
}
@@ -171,7 +171,7 @@ struct ZeroInitWorkgroupMemory::State {
member->Declaration()->attributes)) {
if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) {
local_index = [=] {
auto* param_expr = b.Expr(ctx.Clone(param->symbol));
auto* param_expr = b.Expr(ctx.Clone(param->name->symbol));
auto* member_name = ctx.Clone(member->Declaration()->name);
return b.MemberAccessor(param_expr, member_name);
};
@@ -188,7 +188,7 @@ struct ZeroInitWorkgroupMemory::State {
b.Builtin(ast::BuiltinValue::kLocalInvocationIndex),
});
ctx.InsertBack(fn->params, param);
local_index = [=] { return b.Expr(param->symbol); };
local_index = [=] { return b.Expr(param->name->symbol); };
}
// Take the zeroing statements and bin them by the number of iterations