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, bool isDynamic, bool isDynamicAny, bool isDynamicNone, bool isVector) 41 : type(type), 42 isInteger(isInteger), 43 isUnsigned(isUnsigned), 44 isAddress(isAddress), 45 isFloat(isFloat), 46 isPointer(isPointer), 47 isSimple(isSimple), 48 isDynamic(isDynamic), 49 isDynamicAny(isDynamicAny), 50 isDynamicNone(isDynamicNone), 51 isVector(isVector) 52 { 53 } 54 IsIntegerPrimitiveTypeProperty55 bool IsInteger() const 56 { 57 return isInteger; 58 } IsUnsignedPrimitiveTypeProperty59 bool IsUnsigned() const 60 { 61 return isUnsigned; 62 } 63 IsAddressPrimitiveTypeProperty64 bool IsAddress() const 65 { 66 if (type == PTY_u64 || type == PTY_u32) { 67 if ((type == PTY_u64 && GetPointerSize() == 8) || // PTY_u64 with 8 byte pointer 68 (type == PTY_u32 && GetPointerSize() == 4)) { // PTY_u32 with 4 byte pointer 69 return true; 70 } else { 71 return false; 72 } 73 } else { 74 return isAddress; 75 } 76 } 77 IsFloatPrimitiveTypeProperty78 bool IsFloat() const 79 { 80 return isFloat; 81 } 82 IsPointerPrimitiveTypeProperty83 bool IsPointer() const 84 { 85 if (type == PTY_u64 || type == PTY_u32) { 86 if ((type == PTY_u64 && GetPointerSize() == 8) || // PTY_u64 with 8 byte pointer 87 (type == PTY_u32 && GetPointerSize() == 4)) { // PTY_u32 with 4 byte pointer 88 return true; 89 } else { 90 return false; 91 } 92 } else { 93 return isPointer; 94 } 95 } 96 IsSimplePrimitiveTypeProperty97 bool IsSimple() const 98 { 99 return isSimple; 100 } IsDynamicPrimitiveTypeProperty101 bool IsDynamic() const 102 { 103 return isDynamic; 104 } IsDynamicAnyPrimitiveTypeProperty105 bool IsDynamicAny() const 106 { 107 return isDynamicAny; 108 } IsDynamicNonePrimitiveTypeProperty109 bool IsDynamicNone() const 110 { 111 return isDynamicNone; 112 } IsVectorPrimitiveTypeProperty113 bool IsVector() const 114 { 115 return isVector; 116 } 117 118 private: 119 bool isInteger; 120 bool isUnsigned; 121 bool isAddress; 122 bool isFloat; 123 bool isPointer; 124 bool isSimple; 125 bool isDynamic; 126 bool isDynamicAny; 127 bool isDynamicNone; 128 bool isVector; 129 }; 130 131 const PrimitiveTypeProperty &GetPrimitiveTypeProperty(PrimType pType); 132 } // namespace maple 133 #endif // MAPLE_IR_INCLUDE_CFG_PRIMITIVE_TYPES_H 134