1 /** 2 * Copyright (c) 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 #ifndef COMPILER_OPTIMIZER_CODEGEN_LIB_CALL_INST_H 17 #define COMPILER_OPTIMIZER_CODEGEN_LIB_CALL_INST_H 18 19 #include "compiler/optimizer/ir/graph.h" 20 #include "compiler/optimizer/ir/inst.h" 21 22 namespace panda::compiler { HasLibCall(Inst * inst,Arch arch)23inline bool HasLibCall(Inst *inst, Arch arch) 24 { 25 auto opcode = inst->GetOpcode(); 26 auto type = inst->GetType(); 27 switch (arch) { 28 case Arch::X86_64: 29 case Arch::AARCH64: { 30 if (opcode == Opcode::Mod) { 31 return DataType::IsFloatType(type); 32 } 33 return false; 34 } 35 case Arch::AARCH32: { 36 if (opcode == Opcode::Mod) { 37 return true; 38 } 39 if (opcode == Opcode::Div) { 40 return type == DataType::INT64 || type == DataType::UINT64; 41 } 42 if (opcode == Opcode::Cast) { 43 auto src_type = inst->GetInputType(0); 44 if (DataType::IsFloatType(type)) { 45 return src_type == DataType::INT64 || src_type == DataType::UINT64; 46 } 47 if (DataType::IsFloatType(src_type)) { 48 return type == DataType::INT64 || type == DataType::UINT64; 49 } 50 } 51 return false; 52 } 53 default: 54 UNREACHABLE(); 55 } 56 } 57 } // namespace panda::compiler 58 59 #endif // COMPILER_OPTIMIZER_CODEGEN_LIB_CALL_INST_H 60