tint/transform: Skip LocalizeStructArrayAssignment if possible
Change-Id: I148c576f97359923c0d6fd6ffe864ca84ccd5b6b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116869 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
65985d870f
commit
973a685ad3
|
@ -47,21 +47,25 @@ struct LocalizeStructArrayAssignment::State {
|
||||||
utils::Vector<const ast::Statement*, 4> insert_after_stmts;
|
utils::Vector<const ast::Statement*, 4> insert_after_stmts;
|
||||||
} s;
|
} s;
|
||||||
|
|
||||||
ctx.ReplaceAll([&](const ast::AssignmentStatement* assign_stmt) -> const ast::Statement* {
|
bool made_changes = false;
|
||||||
|
|
||||||
|
for (auto* node : ctx.src->ASTNodes().Objects()) {
|
||||||
|
if (auto* assign_stmt = node->As<ast::AssignmentStatement>()) {
|
||||||
// Process if it's an assignment statement to a dynamically indexed array
|
// Process if it's an assignment statement to a dynamically indexed array
|
||||||
// within a struct on a function or private storage variable. This
|
// within a struct on a function or private storage variable. This
|
||||||
// specific use-case is what FXC fails to compile with:
|
// specific use-case is what FXC fails to compile with:
|
||||||
// error X3500: array reference cannot be used as an l-value; not natively
|
// error X3500: array reference cannot be used as an l-value; not natively
|
||||||
// addressable
|
// addressable
|
||||||
if (!ContainsStructArrayIndex(assign_stmt->lhs)) {
|
if (!ContainsStructArrayIndex(assign_stmt->lhs)) {
|
||||||
return nullptr;
|
continue;
|
||||||
}
|
}
|
||||||
auto og = GetOriginatingTypeAndAddressSpace(assign_stmt);
|
auto og = GetOriginatingTypeAndAddressSpace(assign_stmt);
|
||||||
if (!(og.first->Is<sem::Struct>() && (og.second == ast::AddressSpace::kFunction ||
|
if (!(og.first->Is<sem::Struct>() && (og.second == ast::AddressSpace::kFunction ||
|
||||||
og.second == ast::AddressSpace::kPrivate))) {
|
og.second == ast::AddressSpace::kPrivate))) {
|
||||||
return nullptr;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.Replace(assign_stmt, [&, assign_stmt] {
|
||||||
// Reset shared state for this assignment statement
|
// Reset shared state for this assignment statement
|
||||||
s = Shared{};
|
s = Shared{};
|
||||||
|
|
||||||
|
@ -85,6 +89,14 @@ struct LocalizeStructArrayAssignment::State {
|
||||||
return b.Block(std::move(stmts));
|
return b.Block(std::move(stmts));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
made_changes = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!made_changes) {
|
||||||
|
return SkipTransform;
|
||||||
|
}
|
||||||
|
|
||||||
ctx.ReplaceAll(
|
ctx.ReplaceAll(
|
||||||
[&](const ast::IndexAccessorExpression* index_access) -> const ast::Expression* {
|
[&](const ast::IndexAccessorExpression* index_access) -> const ast::Expression* {
|
||||||
if (!s.process_nested_nodes) {
|
if (!s.process_nested_nodes) {
|
||||||
|
|
|
@ -25,9 +25,7 @@ using LocalizeStructArrayAssignmentTest = TransformTest;
|
||||||
|
|
||||||
TEST_F(LocalizeStructArrayAssignmentTest, EmptyModule) {
|
TEST_F(LocalizeStructArrayAssignmentTest, EmptyModule) {
|
||||||
auto* src = R"()";
|
auto* src = R"()";
|
||||||
auto* expect = src;
|
EXPECT_FALSE(ShouldRun<LocalizeStructArrayAssignment>(src));
|
||||||
auto got = Run<Unshadow, SimplifyPointers, LocalizeStructArrayAssignment>(src);
|
|
||||||
EXPECT_EQ(expect, str(got));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LocalizeStructArrayAssignmentTest, StructArray) {
|
TEST_F(LocalizeStructArrayAssignmentTest, StructArray) {
|
||||||
|
@ -842,10 +840,7 @@ fn main() {
|
||||||
|
|
||||||
// Transform does nothing here as we're not actually assigning to the array in
|
// Transform does nothing here as we're not actually assigning to the array in
|
||||||
// the struct.
|
// the struct.
|
||||||
auto* expect = src;
|
EXPECT_FALSE(ShouldRun<LocalizeStructArrayAssignment>(src));
|
||||||
|
|
||||||
auto got = Run<Unshadow, SimplifyPointers, LocalizeStructArrayAssignment>(src);
|
|
||||||
EXPECT_EQ(expect, str(got));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
Loading…
Reference in New Issue