reduction_opportunity.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2018 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_REDUCE_REDUCTION_OPPORTUNITY_H_
  15. #define SOURCE_REDUCE_REDUCTION_OPPORTUNITY_H_
  16. #include "spirv-tools/libspirv.hpp"
  17. namespace spvtools {
  18. namespace reduce {
  19. // Abstract class: an opportunity to apply a reducing transformation.
  20. class ReductionOpportunity {
  21. public:
  22. ReductionOpportunity() = default;
  23. virtual ~ReductionOpportunity() = default;
  24. // Returns true if this opportunity has not been disabled by the application
  25. // of another conflicting opportunity.
  26. virtual bool PreconditionHolds() = 0;
  27. // Applies the opportunity, mutating the module from which the opportunity was
  28. // created. It is a no-op if PreconditionHolds() returns false.
  29. void TryToApply();
  30. protected:
  31. // Applies the opportunity, mutating the module from which the opportunity was
  32. // created.
  33. // Precondition: PreconditionHolds() must return true.
  34. virtual void Apply() = 0;
  35. };
  36. } // namespace reduce
  37. } // namespace spvtools
  38. #endif // SOURCE_REDUCE_REDUCTION_OPPORTUNITY_H_