change_operand_reduction_opportunity.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_CHANGE_OPERAND_REDUCTION_OPPORTUNITY_H_
  15. #define SOURCE_REDUCE_CHANGE_OPERAND_REDUCTION_OPPORTUNITY_H_
  16. #include "source/opt/instruction.h"
  17. #include "source/reduce/reduction_opportunity.h"
  18. #include "spirv-tools/libspirv.h"
  19. namespace spvtools {
  20. namespace reduce {
  21. // An opportunity to replace an id operand of an instruction with some other id.
  22. class ChangeOperandReductionOpportunity : public ReductionOpportunity {
  23. public:
  24. // Constructs the opportunity to replace operand |operand_index| of |inst|
  25. // with |new_id|.
  26. ChangeOperandReductionOpportunity(opt::Instruction* inst,
  27. uint32_t operand_index, uint32_t new_id)
  28. : inst_(inst),
  29. operand_index_(operand_index),
  30. original_id_(inst->GetOperand(operand_index).words[0]),
  31. original_type_(inst->GetOperand(operand_index).type),
  32. new_id_(new_id) {}
  33. bool PreconditionHolds() override;
  34. protected:
  35. void Apply() override;
  36. private:
  37. opt::Instruction* const inst_;
  38. const uint32_t operand_index_;
  39. const uint32_t original_id_;
  40. const spv_operand_type_t original_type_;
  41. const uint32_t new_id_;
  42. };
  43. } // namespace reduce
  44. } // namespace spvtools
  45. #endif // SOURCE_REDUCE_CHANGE_OPERAND_REDUCTION_OPPORTUNITY_H_