fuzzer_pass_add_equation_instructions.h 3.2 KB

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