fuzzer_pass_construct_composites.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2019 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_CONSTRUCT_COMPOSITES_H_
  15. #define SOURCE_FUZZ_FUZZER_PASS_CONSTRUCT_COMPOSITES_H_
  16. #include <unordered_map>
  17. #include <vector>
  18. #include "source/fuzz/fuzzer_pass.h"
  19. namespace spvtools {
  20. namespace fuzz {
  21. // A fuzzer pass for constructing composite objects from smaller objects.
  22. class FuzzerPassConstructComposites : public FuzzerPass {
  23. public:
  24. FuzzerPassConstructComposites(
  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. // Used to map a type id to the ids of relevant instructions of the type.
  32. using TypeIdToInstructions =
  33. std::unordered_map<uint32_t, std::vector<uint32_t>>;
  34. // Requires that |array_type_instruction| has opcode OpTypeArray.
  35. // Attempts to find suitable instruction result ids from the values of
  36. // |type_id_to_available_instructions| that would allow a composite of type
  37. // |array_type_instruction| to be constructed. Returns said ids if they can
  38. // be found and an empty vector otherwise.
  39. std::vector<uint32_t> FindComponentsToConstructArray(
  40. const opt::Instruction& array_type_instruction,
  41. const TypeIdToInstructions& type_id_to_available_instructions);
  42. // Similar to FindComponentsToConstructArray, but for matrices.
  43. std::vector<uint32_t> FindComponentsToConstructMatrix(
  44. const opt::Instruction& matrix_type_instruction,
  45. const TypeIdToInstructions& type_id_to_available_instructions);
  46. // Similar to FindComponentsToConstructArray, but for structs.
  47. std::vector<uint32_t> FindComponentsToConstructStruct(
  48. const opt::Instruction& struct_type_instruction,
  49. const TypeIdToInstructions& type_id_to_available_instructions);
  50. // Similar to FindComponentsToConstructArray, but for vectors.
  51. std::vector<uint32_t> FindComponentsToConstructVector(
  52. const opt::Instruction& vector_type_instruction,
  53. const TypeIdToInstructions& type_id_to_available_instructions);
  54. };
  55. } // namespace fuzz
  56. } // namespace spvtools
  57. #endif // SOURCE_FUZZ_FUZZER_PASS_CONSTRUCT_COMPOSITES_H_