remove_function_reduction_opportunity_finder.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2019 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. #include "source/reduce/remove_function_reduction_opportunity_finder.h"
  15. #include "source/reduce/remove_function_reduction_opportunity.h"
  16. namespace spvtools {
  17. namespace reduce {
  18. std::vector<std::unique_ptr<ReductionOpportunity>>
  19. RemoveFunctionReductionOpportunityFinder::GetAvailableOpportunities(
  20. opt::IRContext* context) const {
  21. std::vector<std::unique_ptr<ReductionOpportunity>> result;
  22. // Consider each function.
  23. for (auto& function : *context->module()) {
  24. if (context->get_def_use_mgr()->NumUses(function.result_id()) > 0) {
  25. // If the function is referenced, ignore it.
  26. continue;
  27. }
  28. result.push_back(
  29. MakeUnique<RemoveFunctionReductionOpportunity>(context, &function));
  30. }
  31. return result;
  32. }
  33. std::string RemoveFunctionReductionOpportunityFinder::GetName() const {
  34. return "RemoveFunctionReductionOpportunityFinder";
  35. }
  36. } // namespace reduce
  37. } // namespace spvtools