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 bool ignore_inapplicable_transformations); 34 35 void Apply() override; 36 37 private: 38 // Yields those instructions in |instructions| that have integer scalar or 39 // vector result type. 40 std::vector<opt::Instruction*> GetIntegerInstructions( 41 const std::vector<opt::Instruction*>& instructions) const; 42 43 // Returns only instructions, that have either a scalar floating-point or a 44 // vector type. 45 std::vector<opt::Instruction*> GetFloatInstructions( 46 const std::vector<opt::Instruction*>& instructions) const; 47 48 // Yields those instructions in |instructions| that have boolean scalar or 49 // vector result type. 50 std::vector<opt::Instruction*> GetBooleanInstructions( 51 const std::vector<opt::Instruction*>& instructions) const; 52 53 // Yields those instructions in |instructions| that have a scalar numerical or 54 // a vector of numerical components type. Only 16, 32 and 64-bit numericals 55 // are supported if both OpTypeInt and OpTypeFloat instructions can be created 56 // with the specified width (e.g. for 16-bit types both Float16 and Int16 57 // capabilities must be present). 58 std::vector<opt::Instruction*> GetNumericalInstructions( 59 const std::vector<opt::Instruction*>& instructions) const; 60 61 // Requires that |instructions| are scalars or vectors of some type. Returns 62 // only those instructions whose width is |width|. If |width| is 1 this means 63 // the scalars. 64 std::vector<opt::Instruction*> RestrictToVectorWidth( 65 const std::vector<opt::Instruction*>& instructions, 66 uint32_t vector_width) const; 67 68 // Requires that |instructions| are integer or float scalars or vectors. 69 // Returns only those instructions for which the bit-width of the underlying 70 // integer or floating-point type is |bit_width|. 71 std::vector<opt::Instruction*> RestrictToElementBitWidth( 72 const std::vector<opt::Instruction*>& instructions, 73 uint32_t bit_width) const; 74 }; 75 76 } // namespace fuzz 77 } // namespace spvtools 78 79 #endif // SOURCE_FUZZ_FUZZER_PASS_ADD_EQUATION_INSTRUCTIONS_H_ 80