1/** 2 * Copyright (c) 2021-2022 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// NOLINTNEXTLINE(misc-definitions-in-headers,readability-function-size) 17inline void AdjustFlags([[maybe_unused]] RuntimeInterface::IntrinsicId intrinsic, [[maybe_unused]] Inst *inst) 18{ 19 // Note: code relies on current intrinsic instruction default flags 20% if Compiler::intrinsics.any? {|intrinsic| !intrinsic.clear_flags.empty? or !intrinsic.set_flags.empty?} 21 switch (intrinsic) 22 { 23% Compiler::intrinsics.select {|intrinsic| !intrinsic.clear_flags.empty? or !intrinsic.set_flags.empty?}.each do |intrinsic| 24 case RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>: 25 { 26 constexpr auto clear_flags = <%= intrinsic.clear_flags.empty? ? "0U" : intrinsic.clear_flags.collect { |f| "compiler::inst_flags::" + f.upcase }.join("|") %>; 27 constexpr auto set_flags = <%= intrinsic.set_flags.empty? ? "0U" : intrinsic.set_flags.collect { |f| "compiler::inst_flags::" + f.upcase }.join("|") %>; 28 static_assert((set_flags & clear_flags) == 0, "<%= intrinsic.enum_name %> clear_flags cannot intersect set_flags"); 29% if !intrinsic.static 30 static_assert((clear_flags & compiler::inst_flags::REQUIRE_STATE) == 0, "<%= intrinsic.enum_name %> requires save_state because virtual call might cause NPE"); 31% end 32% if !intrinsic.clear_flags.empty? 33 inst->ClearFlag(static_cast<inst_flags::Flags>(clear_flags)); 34% end 35% if !intrinsic.set_flags.empty? 36 static_assert((set_flags & compiler::inst_flags::CAN_THROW) == 0 || (clear_flags & (compiler::inst_flags::REQUIRE_STATE | compiler::inst_flags::RUNTIME_CALL)) == 0, "<%= intrinsic.enum_name %> cannot set can_throw flag"); 37 inst->SetFlag(static_cast<inst_flags::Flags>(set_flags)); 38% end 39 break; 40 } 41% end 42 default: 43 return; 44 } 45% end 46} 47 48inline bool IsIrtocIntrinsic(RuntimeInterface::IntrinsicId intrinsic) 49{ 50 switch (intrinsic) 51 { 52% Compiler::intrinsics.select(&:is_irtoc?).each do |intrinsic| 53 case RuntimeInterface::IntrinsicId::<%= intrinsic.entrypoint_name %>: 54% end 55 return true; 56 default: 57 return false; 58 } 59} 60