remove_dontinline_pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright (c) 2022 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/opt/remove_dontinline_pass.h"
  15. namespace spvtools {
  16. namespace opt {
  17. Pass::Status RemoveDontInline::Process() {
  18. bool modified = false;
  19. modified = ClearDontInlineFunctionControl();
  20. return (modified ? Status::SuccessWithChange : Status::SuccessWithoutChange);
  21. }
  22. bool RemoveDontInline::ClearDontInlineFunctionControl() {
  23. bool modified = false;
  24. for (auto& func : *get_module()) {
  25. ClearDontInlineFunctionControl(&func);
  26. }
  27. return modified;
  28. }
  29. bool RemoveDontInline::ClearDontInlineFunctionControl(Function* function) {
  30. constexpr uint32_t kFunctionControlInOperandIdx = 0;
  31. Instruction* function_inst = &function->DefInst();
  32. uint32_t function_control =
  33. function_inst->GetSingleWordInOperand(kFunctionControlInOperandIdx);
  34. if ((function_control & uint32_t(spv::FunctionControlMask::DontInline)) ==
  35. 0) {
  36. return false;
  37. }
  38. function_control &= ~uint32_t(spv::FunctionControlMask::DontInline);
  39. function_inst->SetInOperand(kFunctionControlInOperandIdx, {function_control});
  40. return true;
  41. }
  42. } // namespace opt
  43. } // namespace spvtools