remove_function_reduction_opportunity_finder.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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, uint32_t target_function) const {
  21. if (target_function) {
  22. // If we are targeting a specific function then we are only interested in
  23. // opportunities that simplify the internals of that function; removing
  24. // whole functions does not fit the bill.
  25. return {};
  26. }
  27. std::vector<std::unique_ptr<ReductionOpportunity>> result;
  28. // Consider each function.
  29. for (auto& function : *context->module()) {
  30. if (context->get_def_use_mgr()->NumUses(function.result_id()) > 0) {
  31. // If the function is referenced, ignore it.
  32. continue;
  33. }
  34. result.push_back(
  35. MakeUnique<RemoveFunctionReductionOpportunity>(context, &function));
  36. }
  37. return result;
  38. }
  39. std::string RemoveFunctionReductionOpportunityFinder::GetName() const {
  40. return "RemoveFunctionReductionOpportunityFinder";
  41. }
  42. } // namespace reduce
  43. } // namespace spvtools