tint: Refactor sem::Constant to be less memory-hungry

Change sem::Constant to be an interface to the constant data. Implement
this so that zero-initialized data doesn't need to allocate the full
size of the type.

This also makes usage a lot cleaner (no more flattened-list of
elements!), and gives us a clear path for supporting constant
structures if/when we want to support them.

Bug: chromium:1339558
Bug: chromium:1339561
Bug: chromium:1339580
Bug: chromium:1339597
Change-Id: Ifcd456f69aee18d5b84befa896d7b0189d68c2dd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94942
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton
2022-06-29 19:07:30 +00:00
committed by Dawn LUCI CQ
parent 7a64127a41
commit aa037ac489
41 changed files with 2255 additions and 1786 deletions

View File

@@ -46,7 +46,7 @@ class LocalizeStructArrayAssignment::State {
expr, b.Diagnostics(), [&](const ast::IndexAccessorExpression* ia) {
// Indexing using a runtime value?
auto* idx_sem = ctx.src->Sem().Get(ia->index);
if (!idx_sem->ConstantValue().IsValid()) {
if (!idx_sem->ConstantValue()) {
// Indexing a member access expr?
if (auto* ma = ia->object->As<ast::MemberAccessorExpression>()) {
// That accesses an array?

View File

@@ -275,7 +275,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
if (auto* sem_e = sem.Get(e)) {
if (auto* var_user = sem_e->As<sem::VariableUser>()) {
// Don't hoist constants.
if (var_user->ConstantValue().IsValid()) {
if (var_user->ConstantValue()) {
return false;
}
// Don't hoist read-only variables as they cannot receive

View File

@@ -120,17 +120,18 @@ struct Robustness::State {
return nullptr;
}
if (auto idx_constant = idx_sem->ConstantValue()) {
if (auto* idx_constant = idx_sem->ConstantValue()) {
// Constant value index
if (idx_constant.Type()->Is<sem::I32>()) {
idx.i32 = static_cast<int32_t>(idx_constant.Element<AInt>(0).value);
auto val = std::get<AInt>(idx_constant->Value());
if (idx_constant->Type()->Is<sem::I32>()) {
idx.i32 = static_cast<int32_t>(val);
idx.is_signed = true;
} else if (idx_constant.Type()->Is<sem::U32>()) {
idx.u32 = static_cast<uint32_t>(idx_constant.Element<AInt>(0).value);
} else if (idx_constant->Type()->Is<sem::U32>()) {
idx.u32 = static_cast<uint32_t>(val);
idx.is_signed = false;
} else {
TINT_ICE(Transform, b.Diagnostics()) << "unsupported constant value for accessor "
<< idx_constant.Type()->TypeInfo().name;
<< idx_constant->Type()->TypeInfo().name;
return nullptr;
}
} else {

View File

@@ -358,8 +358,8 @@ struct ZeroInitWorkgroupMemory::State {
continue;
}
auto* sem = ctx.src->Sem().Get(expr);
if (auto c = sem->ConstantValue()) {
workgroup_size_const *= c.Element<AInt>(0).value;
if (auto* c = sem->ConstantValue()) {
workgroup_size_const *= c->As<AInt>();
continue;
}
// Constant value could not be found. Build expression instead.