Coverage Report

Created: 2026-02-14 06:30

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/spirv-tools/source/opt/relax_float_ops_pass.h
Line
Count
Source
1
// Copyright (c) 2019 Valve Corporation
2
// Copyright (c) 2019 LunarG Inc.
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
// you may not use this file except in compliance with the License.
6
// You may obtain a copy of the License at
7
//
8
//     http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15
16
#ifndef LIBSPIRV_OPT_RELAX_FLOAT_OPS_PASS_H_
17
#define LIBSPIRV_OPT_RELAX_FLOAT_OPS_PASS_H_
18
19
#include "source/opt/ir_builder.h"
20
#include "source/opt/pass.h"
21
22
namespace spvtools {
23
namespace opt {
24
25
class RelaxFloatOpsPass : public Pass {
26
 public:
27
0
  RelaxFloatOpsPass() : Pass() {}
28
29
0
  ~RelaxFloatOpsPass() override = default;
30
31
0
  IRContext::Analysis GetPreservedAnalyses() override {
32
0
    return IRContext::kAnalysisDefUse | IRContext::kAnalysisInstrToBlockMapping;
33
0
  }
34
35
  // See optimizer.hpp for pass user documentation.
36
  Status Process() override;
37
38
0
  const char* name() const override { return "convert-to-half-pass"; }
39
40
 private:
41
  // Return true if |inst| can have the RelaxedPrecision decoration applied
42
  // to it.
43
  bool IsRelaxable(Instruction* inst);
44
45
  // Return true if |inst| returns scalar, vector or matrix type with base
46
  // float and width 32
47
  bool IsFloat32(Instruction* inst);
48
49
  // Return true if |r_id| is decorated with RelaxedPrecision
50
  bool IsRelaxed(uint32_t r_id);
51
52
  // If |inst| is an instruction of float32-based type and is not decorated
53
  // RelaxedPrecision, add such a decoration to the module.
54
  bool ProcessInst(Instruction* inst);
55
56
  // Call ProcessInst on every instruction in |func|.
57
  bool ProcessFunction(Function* func);
58
59
  Pass::Status ProcessImpl();
60
61
  // Initialize state for converting to half
62
  void Initialize();
63
64
  struct hasher {
65
0
    size_t operator()(const spv::Op& op) const noexcept {
66
0
      return std::hash<uint32_t>()(uint32_t(op));
67
0
    }
68
  };
69
70
  // Set of float result core operations to be processed
71
  std::unordered_set<spv::Op, hasher> target_ops_core_f_rslt_;
72
73
  // Set of float operand core operations to be processed
74
  std::unordered_set<spv::Op, hasher> target_ops_core_f_opnd_;
75
76
  // Set of 450 extension operations to be processed
77
  std::unordered_set<uint32_t> target_ops_450_;
78
79
  // Set of sample operations
80
  std::unordered_set<spv::Op, hasher> sample_ops_;
81
};
82
83
}  // namespace opt
84
}  // namespace spvtools
85
86
#endif  // LIBSPIRV_OPT_RELAX_FLOAT_OPS_PASS_H_