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