fuzzer_pass_interchange_zero_like_constants.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright (c) 2020 Stefano Milizia
  2. // Copyright (c) 2020 Google LLC
  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. #ifndef SOURCE_FUZZ_FUZZER_PASS_INTERCHANGE_ZERO_LIKE_CONSTANTS_H_
  16. #define SOURCE_FUZZ_FUZZER_PASS_INTERCHANGE_ZERO_LIKE_CONSTANTS_H_
  17. #include "source/fuzz/fuzzer_pass.h"
  18. namespace spvtools {
  19. namespace fuzz {
  20. // A pass that:
  21. // - Finds all the zero-like constant definitions in the module and adds the
  22. // definitions of the corresponding synonym, recording the fact that they
  23. // are synonymous. If the synonym is already in the module, it does not
  24. // add a new one.
  25. // - For each use of a zero-like constant, decides whether to change it to the
  26. // id of the toggled constant.
  27. class FuzzerPassInterchangeZeroLikeConstants : public FuzzerPass {
  28. public:
  29. FuzzerPassInterchangeZeroLikeConstants(
  30. opt::IRContext* ir_context, TransformationContext* transformation_context,
  31. FuzzerContext* fuzzer_context,
  32. protobufs::TransformationSequence* transformations,
  33. bool ignore_inapplicable_transformations);
  34. void Apply() override;
  35. private:
  36. // Given the declaration of a zero-like constant, it finds or creates the
  37. // corresponding toggled constant (a scalar constant of value 0 becomes a
  38. // null constant of the same type and vice versa).
  39. // Returns the id of the toggled instruction if the constant is zero-like,
  40. // 0 otherwise.
  41. uint32_t FindOrCreateToggledConstant(opt::Instruction* declaration);
  42. };
  43. } // namespace fuzz
  44. } // namespace spvtools
  45. #endif // SOURCE_FUZZ_FUZZER_PASS_INTERCHANGE_ZERO_LIKE_CONSTANTS_H_