1 /* 2 * Copyright (c) 2023 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 MAPLE_IR_INCLUDE_CFG_PRIMITIVE_TYPES_H 17 #define MAPLE_IR_INCLUDE_CFG_PRIMITIVE_TYPES_H 18 19 namespace maple { 20 uint8 GetPointerSize(); // Circular include dependency with mir_type.h 21 22 // Declaration of enum PrimType 23 #define LOAD_ALGO_PRIMARY_TYPE 24 enum PrimType { 25 PTY_begin, // PrimType begin 26 #define PRIMTYPE(P) PTY_##P, 27 #include "prim_types.def" 28 PTY_end, // PrimType end 29 #undef PRIMTYPE 30 }; 31 32 constexpr PrimType kPtyInvalid = PTY_begin; 33 // just for test, no primitive type for derived SIMD types to be defined 34 constexpr PrimType kPtyDerived = PTY_end; 35 36 struct PrimitiveTypeProperty { 37 PrimType type; 38 PrimitiveTypePropertyPrimitiveTypeProperty39 PrimitiveTypeProperty(PrimType type, bool isInteger, bool isUnsigned, bool isAddress, bool isFloat, bool isPointer, 40 bool isSimple) 41 : type(type), 42 isInteger(isInteger), 43 isUnsigned(isUnsigned), 44 isAddress(isAddress), 45 isFloat(isFloat), 46 isPointer(isPointer), 47 isSimple(isSimple) 48 { 49 } 50 IsIntegerPrimitiveTypeProperty51 bool IsInteger() const 52 { 53 return isInteger; 54 } IsUnsignedPrimitiveTypeProperty55 bool IsUnsigned() const 56 { 57 return isUnsigned; 58 } 59 IsAddressPrimitiveTypeProperty60 bool IsAddress() const 61 { 62 if (type == PTY_u64 || type == PTY_u32) { 63 if ((type == PTY_u64 && GetPointerSize() == 8) || // PTY_u64 with 8 byte pointer 64 (type == PTY_u32 && GetPointerSize() == 4)) { // PTY_u32 with 4 byte pointer 65 return true; 66 } else { 67 return false; 68 } 69 } else { 70 return isAddress; 71 } 72 } 73 IsFloatPrimitiveTypeProperty74 bool IsFloat() const 75 { 76 return isFloat; 77 } 78 IsPointerPrimitiveTypeProperty79 bool IsPointer() const 80 { 81 if (type == PTY_u64 || type == PTY_u32) { 82 if ((type == PTY_u64 && GetPointerSize() == 8) || // PTY_u64 with 8 byte pointer 83 (type == PTY_u32 && GetPointerSize() == 4)) { // PTY_u32 with 4 byte pointer 84 return true; 85 } else { 86 return false; 87 } 88 } else { 89 return isPointer; 90 } 91 } 92 IsSimplePrimitiveTypeProperty93 bool IsSimple() const 94 { 95 return isSimple; 96 } 97 98 private: 99 bool isInteger; 100 bool isUnsigned; 101 bool isAddress; 102 bool isFloat; 103 bool isPointer; 104 bool isSimple; 105 }; 106 107 const PrimitiveTypeProperty &GetPrimitiveTypeProperty(PrimType pType); 108 } // namespace maple 109 #endif // MAPLE_IR_INCLUDE_CFG_PRIMITIVE_TYPES_H 110