mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-29 16:35:43 +00:00
Migrate some of the validation logic over to use the results of behavior analysis. The most significant changes are: * Unreachable-statements now consider merge-points of control flow. For example, if all branches of a if-statement or switch-statement either return or discard, the next statement will be considered unreachable. * Unreachable statements are no longer an error, but a warning. See https://github.com/gpuweb/gpuweb/issues/2378. * Statements that follow a loops that does not break, or have a conditional will now be considered unreachable. * Unreachable statements produced by the SPIR-V reader are now removed using the new RemoveUnreachableStatements transform. Some other new changes include additional validation for the continuing block for for-loops, to match the rules of a loop continuing block. The new cases this validation is testing for are not expressible in WGSL, but some transforms may produce complex continuing statements that might violate these rules. All the writers are able to decay these complex for-loop continuing statements to regular loops. Bug: tint:1302 Change-Id: I0d8a48c73d5d5c30a1cddf92cc3383a692a58e61 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/71500 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: David Neto <dneto@google.com>
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
// Copyright 2021 The Tint Authors.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "src/transform/remove_unreachable_statements.h"
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
#include "src/ast/traverse_expressions.h"
|
|
#include "src/program_builder.h"
|
|
#include "src/sem/block_statement.h"
|
|
#include "src/sem/function.h"
|
|
#include "src/sem/statement.h"
|
|
#include "src/sem/variable.h"
|
|
#include "src/utils/map.h"
|
|
#include "src/utils/scoped_assignment.h"
|
|
|
|
TINT_INSTANTIATE_TYPEINFO(tint::transform::RemoveUnreachableStatements);
|
|
|
|
namespace tint {
|
|
namespace transform {
|
|
|
|
RemoveUnreachableStatements::RemoveUnreachableStatements() = default;
|
|
|
|
RemoveUnreachableStatements::~RemoveUnreachableStatements() = default;
|
|
|
|
void RemoveUnreachableStatements::Run(CloneContext& ctx,
|
|
const DataMap&,
|
|
DataMap&) {
|
|
for (auto* node : ctx.src->ASTNodes().Objects()) {
|
|
if (auto* stmt = ctx.src->Sem().Get<sem::Statement>(node)) {
|
|
if (!stmt->IsReachable()) {
|
|
RemoveStatement(ctx, stmt->Declaration());
|
|
}
|
|
}
|
|
}
|
|
|
|
ctx.Clone();
|
|
}
|
|
|
|
} // namespace transform
|
|
} // namespace tint
|