transformation_swap_two_functions.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2021 Shiyu Liu
  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_TRANSFORMATION_SWAP_TWO_FUNCTIONS_H_
  15. #define SOURCE_FUZZ_TRANSFORMATION_SWAP_TWO_FUNCTIONS_H_
  16. #include "source/fuzz/protobufs/spirvfuzz_protobufs.h"
  17. #include "source/fuzz/transformation.h"
  18. #include "source/fuzz/transformation_context.h"
  19. #include "source/opt/ir_context.h"
  20. namespace spvtools {
  21. namespace fuzz {
  22. class TransformationSwapTwoFunctions : public Transformation {
  23. public:
  24. explicit TransformationSwapTwoFunctions(
  25. protobufs::TransformationSwapTwoFunctions message);
  26. TransformationSwapTwoFunctions(uint32_t function_id1, uint32_t function_id2);
  27. // |function_id1| and |function_id1| should all be existing ids.
  28. // Swap function operation is only permitted if:
  29. // - both ids must be ids of functions.
  30. // - both ids can be found in the module.
  31. // - function_id1 and function_id2 are not the same.
  32. bool IsApplicable(
  33. opt::IRContext* ir_context,
  34. const TransformationContext& transformation_context) const override;
  35. // OpFunction with |function_id1| and |function_id1| are swapped.
  36. void Apply(opt::IRContext* ir_context,
  37. TransformationContext* transformation_context) const override;
  38. std::unordered_set<uint32_t> GetFreshIds() const override;
  39. protobufs::Transformation ToMessage() const override;
  40. private:
  41. protobufs::TransformationSwapTwoFunctions message_;
  42. };
  43. } // namespace fuzz
  44. } // namespace spvtools
  45. #endif // SOURCE_FUZZ_TRANSFORMATION_SWAP_TWO_FUNCTIONS_H_