transformation_add_loop_preheader.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_TRANSFORMATION_ADD_LOOP_PREHEADER_H
  15. #define SOURCE_FUZZ_TRANSFORMATION_ADD_LOOP_PREHEADER_H
  16. #include "source/fuzz/transformation.h"
  17. namespace spvtools {
  18. namespace fuzz {
  19. class TransformationAddLoopPreheader : public Transformation {
  20. public:
  21. explicit TransformationAddLoopPreheader(
  22. protobufs::TransformationAddLoopPreheader message);
  23. TransformationAddLoopPreheader(uint32_t loop_header_block, uint32_t fresh_id,
  24. std::vector<uint32_t> phi_id);
  25. // - |message_.loop_header_block| must be the id of a loop header block in
  26. // the given module.
  27. // - |message_.fresh_id| must be an available id.
  28. // - |message_.phi_ids| must be a list of available ids.
  29. // It can be empty if the loop header only has one predecessor outside of
  30. // the loop. Otherwise, it must contain at least as many ids as OpPhi
  31. // instructions in the loop header block.
  32. bool IsApplicable(
  33. opt::IRContext* ir_context,
  34. const TransformationContext& transformation_context) const override;
  35. // Adds a preheader block as the unique out-of-loop predecessor of the given
  36. // loop header block. All of the existing out-of-loop predecessors of the
  37. // header are changed so that they branch to the preheader instead.
  38. void Apply(opt::IRContext* ir_context,
  39. TransformationContext* transformation_context) const override;
  40. std::unordered_set<uint32_t> GetFreshIds() const override;
  41. protobufs::Transformation ToMessage() const override;
  42. private:
  43. protobufs::TransformationAddLoopPreheader message_;
  44. };
  45. } // namespace fuzz
  46. } // namespace spvtools
  47. #endif // SOURCE_FUZZ_TRANSFORMATION_ADD_LOOP_PREHEADER_H