remove_function_reduction_opportunity.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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.h"
  15. #include "source/opt/eliminate_dead_functions_util.h"
  16. namespace spvtools {
  17. namespace reduce {
  18. bool RemoveFunctionReductionOpportunity::PreconditionHolds() {
  19. // Removing one function cannot influence whether another function can be
  20. // removed.
  21. return true;
  22. }
  23. void RemoveFunctionReductionOpportunity::Apply() {
  24. for (opt::Module::iterator function_it = context_->module()->begin();
  25. function_it != context_->module()->end(); ++function_it) {
  26. if (&*function_it == function_) {
  27. function_it.Erase();
  28. context_->InvalidateAnalysesExceptFor(opt::IRContext::kAnalysisNone);
  29. return;
  30. }
  31. }
  32. assert(0 && "Function to be removed was not found.");
  33. }
  34. } // namespace reduce
  35. } // namespace spvtools