• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/transform/remove_unreachable_statements.h"
16 
17 #include <memory>
18 #include <unordered_map>
19 #include <utility>
20 #include <vector>
21 
22 #include "src/ast/traverse_expressions.h"
23 #include "src/program_builder.h"
24 #include "src/sem/block_statement.h"
25 #include "src/sem/function.h"
26 #include "src/sem/statement.h"
27 #include "src/sem/variable.h"
28 #include "src/utils/map.h"
29 #include "src/utils/scoped_assignment.h"
30 
31 TINT_INSTANTIATE_TYPEINFO(tint::transform::RemoveUnreachableStatements);
32 
33 namespace tint {
34 namespace transform {
35 
36 RemoveUnreachableStatements::RemoveUnreachableStatements() = default;
37 
38 RemoveUnreachableStatements::~RemoveUnreachableStatements() = default;
39 
Run(CloneContext & ctx,const DataMap &,DataMap &)40 void RemoveUnreachableStatements::Run(CloneContext& ctx,
41                                       const DataMap&,
42                                       DataMap&) {
43   for (auto* node : ctx.src->ASTNodes().Objects()) {
44     if (auto* stmt = ctx.src->Sem().Get<sem::Statement>(node)) {
45       if (!stmt->IsReachable()) {
46         RemoveStatement(ctx, stmt->Declaration());
47       }
48     }
49   }
50 
51   ctx.Clone();
52 }
53 
54 }  // namespace transform
55 }  // namespace tint
56