Debian Codegraph @

third_party/spirv-tools/source/fuzz/fuzzer_pass_add_equation_instructions.h

raw
1 // Copyright (c) 2020 Google LLC
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 #ifndef SOURCE_FUZZ_FUZZER_PASS_ADD_EQUATION_INSTRUCTIONS_H_
16 #define SOURCE_FUZZ_FUZZER_PASS_ADD_EQUATION_INSTRUCTIONS_H_
17
18 #include <vector>
19
20 #include "source/fuzz/fuzzer_pass.h"
21
22 namespace spvtools {
23 namespace fuzz {
24
25 // Fuzzer pass that sprinkles instructions through the module that define
26 // equations using various arithmetic and logical operators.
27 class FuzzerPassAddEquationInstructions : public FuzzerPass {
28 public:
29 FuzzerPassAddEquationInstructions(
30 opt::IRContext* ir_context, TransformationContext* transformation_context,
31 FuzzerContext* fuzzer_context,
32 protobufs::TransformationSequence* transformations);
33
34 ~FuzzerPassAddEquationInstructions();
35
36 void Apply() override;
37
38 private:
39 // Yields those instructions in |instructions| that have integer scalar or
40 // vector result type.
41 std::vector<opt::Instruction*> GetIntegerInstructions(
42 const std::vector<opt::Instruction*>& instructions) const;
43
44 // Returns only instructions, that have either a scalar floating-point or a
45 // vector type.
46 std::vector<opt::Instruction*> GetFloatInstructions(
47 const std::vector<opt::Instruction*>& instructions) const;
48
49 // Yields those instructions in |instructions| that have boolean scalar or
50 // vector result type.
51 std::vector<opt::Instruction*> GetBooleanInstructions(
52 const std::vector<opt::Instruction*>& instructions) const;
53
54 // Yields those instructions in |instructions| that have a scalar numerical or
55 // a vector of numerical components type. Only 16, 32 and 64-bit numericals
56 // are supported if both OpTypeInt and OpTypeFloat instructions can be created
57 // with the specified width (e.g. for 16-bit types both Float16 and Int16
58 // capabilities must be present).
59 std::vector<opt::Instruction*> GetNumericalInstructions(
60 const std::vector<opt::Instruction*>& instructions) const;
61
62 // Requires that |instructions| are scalars or vectors of some type. Returns
63 // only those instructions whose width is |width|. If |width| is 1 this means
64 // the scalars.
65 std::vector<opt::Instruction*> RestrictToVectorWidth(
66 const std::vector<opt::Instruction*>& instructions,
67 uint32_t vector_width) const;
68
69 // Requires that |instructions| are integer or float scalars or vectors.
70 // Returns only those instructions for which the bit-width of the underlying
71 // integer or floating-point type is |bit_width|.
72 std::vector<opt::Instruction*> RestrictToElementBitWidth(
73 const std::vector<opt::Instruction*>& instructions,
74 uint32_t bit_width) const;
75 };
76
77 } // namespace fuzz
78 } // namespace spvtools
79
80 #endif // SOURCE_FUZZ_FUZZER_PASS_ADD_EQUATION_INSTRUCTIONS_H_