Coverage Report

Created: 2026-05-16 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/spirv-tools/source/opt/eliminate_dead_functions_pass.cpp
Line
Count
Source
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/eliminate_dead_functions_pass.h"
16
#include "source/opt/eliminate_dead_functions_util.h"
17
18
#include <unordered_set>
19
20
#include "source/opt/ir_context.h"
21
22
namespace spvtools {
23
namespace opt {
24
25
20.1k
Pass::Status EliminateDeadFunctionsPass::Process() {
26
  // Identify live functions first.  Those that are not live
27
  // are dead.
28
20.1k
  std::unordered_set<const Function*> live_function_set;
29
20.1k
  ProcessFunction mark_live = [&live_function_set](Function* fp) {
30
18.7k
    live_function_set.insert(fp);
31
18.7k
    return false;
32
18.7k
  };
33
20.1k
  context()->ProcessReachableCallTree(mark_live);
34
35
20.1k
  bool modified = false;
36
20.1k
  for (auto funcIter = get_module()->begin();
37
49.9k
       funcIter != get_module()->end();) {
38
29.8k
    if (live_function_set.count(&*funcIter) == 0) {
39
11.1k
      modified = true;
40
11.1k
      funcIter =
41
11.1k
          eliminatedeadfunctionsutil::EliminateFunction(context(), &funcIter);
42
18.7k
    } else {
43
18.7k
      ++funcIter;
44
18.7k
    }
45
29.8k
  }
46
47
20.1k
  return modified ? Pass::Status::SuccessWithChange
48
20.1k
                  : Pass::Status::SuccessWithoutChange;
49
20.1k
}
50
51
}  // namespace opt
52
}  // namespace spvtools