1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 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 16 #include "spirv_opt_strip_extensions.h" 17 18 #include "source/opt/ir_context.h" 19 #include "source/util/string_utils.h" 20 21 namespace spvtools { 22 23 namespace opt { 24 Process()25Pass::Status StripPreprocessorDebugInfoPass::Process() 26 { 27 std::vector<Instruction*> to_kill; 28 29 for (auto& dbg : context()->debugs1()) { 30 if (dbg.opcode() == spv::Op::OpSourceExtension) { 31 const std::string ext_name = dbg.GetInOperand(0).AsString(); 32 if (ext_name == "GL_GOOGLE_cpp_style_line_directive" || ext_name == "GL_GOOGLE_include_directive") { 33 to_kill.push_back(&dbg); 34 } 35 } 36 } 37 38 bool modified = !to_kill.empty(); 39 40 for (auto* inst : to_kill) { 41 context()->KillInst(inst); 42 } 43 44 return modified ? Status::SuccessWithChange : Status::SuccessWithoutChange; 45 } 46 47 } // namespace opt 48 } // namespace spvtools 49