Coverage Report

Created: 2023-03-01 07:33

/src/spirv-tools/source/opt/redundancy_elimination.cpp
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2017 Google Inc.
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 "source/opt/redundancy_elimination.h"
16
17
#include "source/opt/value_number_table.h"
18
19
namespace spvtools {
20
namespace opt {
21
22
7.24k
Pass::Status RedundancyEliminationPass::Process() {
23
7.24k
  bool modified = false;
24
7.24k
  ValueNumberTable vnTable(context());
25
26
7.24k
  for (auto& func : *get_module()) {
27
6.99k
    if (func.IsDeclaration()) {
28
0
      continue;
29
0
    }
30
31
    // Build the dominator tree for this function. It is how the code is
32
    // traversed.
33
6.99k
    DominatorTree& dom_tree =
34
6.99k
        context()->GetDominatorAnalysis(&func)->GetDomTree();
35
36
    // Keeps track of all ids that contain a given value number. We keep
37
    // track of multiple values because they could have the same value, but
38
    // different decorations.
39
6.99k
    std::map<uint32_t, uint32_t> value_to_ids;
40
41
6.99k
    if (EliminateRedundanciesFrom(dom_tree.GetRoot(), vnTable, value_to_ids)) {
42
1.76k
      modified = true;
43
1.76k
    }
44
6.99k
  }
45
7.24k
  return (modified ? Status::SuccessWithChange : Status::SuccessWithoutChange);
46
7.24k
}
47
48
bool RedundancyEliminationPass::EliminateRedundanciesFrom(
49
    DominatorTreeNode* bb, const ValueNumberTable& vnTable,
50
167k
    std::map<uint32_t, uint32_t> value_to_ids) {
51
167k
  bool modified = EliminateRedundanciesInBB(bb->bb_, vnTable, &value_to_ids);
52
53
167k
  for (auto dominated_bb : bb->children_) {
54
160k
    modified |= EliminateRedundanciesFrom(dominated_bb, vnTable, value_to_ids);
55
160k
  }
56
57
167k
  return modified;
58
167k
}
59
}  // namespace opt
60
}  // namespace spvtools