tint: Minor no-op cleanup changes

Change-Id: I91ad6044e7809ed2deab0fbd4417da90c7870d81
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99705
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-08-23 16:23:05 +00:00 committed by Dawn LUCI CQ
parent e3f2005b2d
commit b90b6bff1d
5 changed files with 133 additions and 178 deletions

View File

@ -2183,26 +2183,27 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
auto* object = sem_.Get(expr->structure); auto* object = sem_.Get(expr->structure);
auto* source_var = object->SourceVariable(); auto* source_var = object->SourceVariable();
const sem::Type* ret = nullptr; const sem::Type* ty = nullptr;
utils::Vector<uint32_t, 4> swizzle;
// Object may be a side-effecting expression (e.g. function call). // Object may be a side-effecting expression (e.g. function call).
bool has_side_effects = object && object->HasSideEffects(); bool has_side_effects = object && object->HasSideEffects();
if (auto* str = storage_ty->As<sem::Struct>()) { return Switch(
storage_ty, //
[&](const sem::Struct* str) -> sem::Expression* {
Mark(expr->member); Mark(expr->member);
auto symbol = expr->member->symbol; auto symbol = expr->member->symbol;
const sem::StructMember* member = nullptr; const sem::StructMember* member = nullptr;
for (auto* m : str->Members()) { for (auto* m : str->Members()) {
if (m->Name() == symbol) { if (m->Name() == symbol) {
ret = m->Type(); ty = m->Type();
member = m; member = m;
break; break;
} }
} }
if (ret == nullptr) { if (ty == nullptr) {
AddError("struct member " + builder_->Symbols().NameFor(symbol) + " not found", AddError("struct member " + builder_->Symbols().NameFor(symbol) + " not found",
expr->source); expr->source);
return nullptr; return nullptr;
@ -2210,23 +2211,23 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
// If we're extracting from a reference, we return a reference. // If we're extracting from a reference, we return a reference.
if (auto* ref = structure->As<sem::Reference>()) { if (auto* ref = structure->As<sem::Reference>()) {
ret = builder_->create<sem::Reference>(ret, ref->StorageClass(), ref->Access()); ty = builder_->create<sem::Reference>(ty, ref->StorageClass(), ref->Access());
} }
const sem::Constant* val = nullptr; auto val = const_eval_.MemberAccess(object, member);
if (auto r = const_eval_.MemberAccess(object, member)) { if (!val) {
val = r.Get();
} else {
return nullptr; return nullptr;
} }
return builder_->create<sem::StructMemberAccess>(expr, ret, current_statement_, val, object, return builder_->create<sem::StructMemberAccess>(expr, ty, current_statement_,
member, has_side_effects, source_var); val.Get(), object, member,
} has_side_effects, source_var);
},
if (auto* vec = storage_ty->As<sem::Vector>()) { [&](const sem::Vector* vec) -> sem::Expression* {
Mark(expr->member); Mark(expr->member);
std::string s = builder_->Symbols().NameFor(expr->member->symbol); std::string s = builder_->Symbols().NameFor(expr->member->symbol);
auto size = s.size(); auto size = s.size();
utils::Vector<uint32_t, 4> swizzle;
swizzle.Reserve(s.size()); swizzle.Reserve(s.size());
for (auto c : s) { for (auto c : s) {
@ -2276,28 +2277,30 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e
if (size == 1) { if (size == 1) {
// A single element swizzle is just the type of the vector. // A single element swizzle is just the type of the vector.
ret = vec->type(); ty = vec->type();
// If we're extracting from a reference, we return a reference. // If we're extracting from a reference, we return a reference.
if (auto* ref = structure->As<sem::Reference>()) { if (auto* ref = structure->As<sem::Reference>()) {
ret = builder_->create<sem::Reference>(ret, ref->StorageClass(), ref->Access()); ty = builder_->create<sem::Reference>(ty, ref->StorageClass(), ref->Access());
} }
} else { } else {
// The vector will have a number of components equal to the length of // The vector will have a number of components equal to the length of
// the swizzle. // the swizzle.
ret = builder_->create<sem::Vector>(vec->type(), static_cast<uint32_t>(size)); ty = builder_->create<sem::Vector>(vec->type(), static_cast<uint32_t>(size));
}
if (auto r = const_eval_.Swizzle(ret, object, swizzle)) {
auto* val = r.Get();
return builder_->create<sem::Swizzle>(expr, ret, current_statement_, val, object,
std::move(swizzle), has_side_effects, source_var);
} }
auto val = const_eval_.Swizzle(ty, object, swizzle);
if (!val) {
return nullptr; return nullptr;
} }
return builder_->create<sem::Swizzle>(expr, ty, current_statement_, val.Get(), object,
std::move(swizzle), has_side_effects, source_var);
},
[&](Default) {
AddError("invalid member accessor expression. Expected vector or struct, got '" + AddError("invalid member accessor expression. Expected vector or struct, got '" +
sem_.TypeNameOf(storage_ty) + "'", sem_.TypeNameOf(storage_ty) + "'",
expr->structure->source); expr->structure->source);
return nullptr; return nullptr;
});
} }
sem::Expression* Resolver::Binary(const ast::BinaryExpression* expr) { sem::Expression* Resolver::Binary(const ast::BinaryExpression* expr) {

View File

@ -145,7 +145,7 @@ void FirstIndexOffset::Run(CloneContext& ctx, const DataMap& inputs, DataMap& ou
} }
} }
} }
// Not interested in this experssion. Just clone. // Not interested in this expression. Just clone.
return nullptr; return nullptr;
}); });
} }

View File

@ -1743,31 +1743,15 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* exp
} }
} }
return Switch( return Switch(
expr, expr, //
[&](const ast::IndexAccessorExpression* a) { // [&](const ast::IndexAccessorExpression* a) { return EmitIndexAccessor(out, a); },
return EmitIndexAccessor(out, a); [&](const ast::BinaryExpression* b) { return EmitBinary(out, b); },
}, [&](const ast::BitcastExpression* b) { return EmitBitcast(out, b); },
[&](const ast::BinaryExpression* b) { // [&](const ast::CallExpression* c) { return EmitCall(out, c); },
return EmitBinary(out, b); [&](const ast::IdentifierExpression* i) { return EmitIdentifier(out, i); },
}, [&](const ast::LiteralExpression* l) { return EmitLiteral(out, l); },
[&](const ast::BitcastExpression* b) { // [&](const ast::MemberAccessorExpression* m) { return EmitMemberAccessor(out, m); },
return EmitBitcast(out, b); [&](const ast::UnaryOpExpression* u) { return EmitUnaryOp(out, u); },
},
[&](const ast::CallExpression* c) { //
return EmitCall(out, c);
},
[&](const ast::IdentifierExpression* i) { //
return EmitIdentifier(out, i);
},
[&](const ast::LiteralExpression* l) { //
return EmitLiteral(out, l);
},
[&](const ast::MemberAccessorExpression* m) { //
return EmitMemberAccessor(out, m);
},
[&](const ast::UnaryOpExpression* u) { //
return EmitUnaryOp(out, u);
},
[&](Default) { // [&](Default) { //
diagnostics_.add_error(diag::System::Writer, "unknown expression type: " + diagnostics_.add_error(diag::System::Writer, "unknown expression type: " +
std::string(expr->TypeInfo().name)); std::string(expr->TypeInfo().name));

View File

@ -2631,32 +2631,16 @@ bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* exp
} }
} }
return Switch( return Switch(
expr, expr, //
[&](const ast::IndexAccessorExpression* a) { // [&](const ast::IndexAccessorExpression* a) { return EmitIndexAccessor(out, a); },
return EmitIndexAccessor(out, a); [&](const ast::BinaryExpression* b) { return EmitBinary(out, b); },
}, [&](const ast::BitcastExpression* b) { return EmitBitcast(out, b); },
[&](const ast::BinaryExpression* b) { // [&](const ast::CallExpression* c) { return EmitCall(out, c); },
return EmitBinary(out, b); [&](const ast::IdentifierExpression* i) { return EmitIdentifier(out, i); },
}, [&](const ast::LiteralExpression* l) { return EmitLiteral(out, l); },
[&](const ast::BitcastExpression* b) { // [&](const ast::MemberAccessorExpression* m) { return EmitMemberAccessor(out, m); },
return EmitBitcast(out, b); [&](const ast::UnaryOpExpression* u) { return EmitUnaryOp(out, u); },
}, [&](Default) {
[&](const ast::CallExpression* c) { //
return EmitCall(out, c);
},
[&](const ast::IdentifierExpression* i) { //
return EmitIdentifier(out, i);
},
[&](const ast::LiteralExpression* l) { //
return EmitLiteral(out, l);
},
[&](const ast::MemberAccessorExpression* m) { //
return EmitMemberAccessor(out, m);
},
[&](const ast::UnaryOpExpression* u) { //
return EmitUnaryOp(out, u);
},
[&](Default) { //
diagnostics_.add_error(diag::System::Writer, "unknown expression type: " + diagnostics_.add_error(diag::System::Writer, "unknown expression type: " +
std::string(expr->TypeInfo().name)); std::string(expr->TypeInfo().name));
return false; return false;

View File

@ -1764,36 +1764,20 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression*
bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) { bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) {
if (auto* sem = builder_.Sem().Get(expr)) { if (auto* sem = builder_.Sem().Get(expr)) {
if (auto constant = sem->ConstantValue()) { if (auto* constant = sem->ConstantValue()) {
return EmitConstant(out, constant); return EmitConstant(out, constant);
} }
} }
return Switch( return Switch(
expr, expr, //
[&](const ast::IndexAccessorExpression* a) { // [&](const ast::IndexAccessorExpression* a) { return EmitIndexAccessor(out, a); },
return EmitIndexAccessor(out, a); [&](const ast::BinaryExpression* b) { return EmitBinary(out, b); },
}, [&](const ast::BitcastExpression* b) { return EmitBitcast(out, b); },
[&](const ast::BinaryExpression* b) { // [&](const ast::CallExpression* c) { return EmitCall(out, c); },
return EmitBinary(out, b); [&](const ast::IdentifierExpression* i) { return EmitIdentifier(out, i); },
}, [&](const ast::LiteralExpression* l) { return EmitLiteral(out, l); },
[&](const ast::BitcastExpression* b) { // [&](const ast::MemberAccessorExpression* m) { return EmitMemberAccessor(out, m); },
return EmitBitcast(out, b); [&](const ast::UnaryOpExpression* u) { return EmitUnaryOp(out, u); },
},
[&](const ast::CallExpression* c) { //
return EmitCall(out, c);
},
[&](const ast::IdentifierExpression* i) { //
return EmitIdentifier(out, i);
},
[&](const ast::LiteralExpression* l) { //
return EmitLiteral(out, l);
},
[&](const ast::MemberAccessorExpression* m) { //
return EmitMemberAccessor(out, m);
},
[&](const ast::UnaryOpExpression* u) { //
return EmitUnaryOp(out, u);
},
[&](Default) { // [&](Default) { //
diagnostics_.add_error(diag::System::Writer, "unknown expression type: " + diagnostics_.add_error(diag::System::Writer, "unknown expression type: " +
std::string(expr->TypeInfo().name)); std::string(expr->TypeInfo().name));