| OLD | NEW |
| 1 //===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===// | 1 //===- subzero/src/IceTypes.cpp - Primitive type properties ---------------===// |
| 2 // | 2 // |
| 3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file defines a few attributes of Subzero primitive types. | 10 // This file defines a few attributes of Subzero primitive types. |
| 11 // | 11 // |
| 12 //===----------------------------------------------------------------------===// | 12 //===----------------------------------------------------------------------===// |
| 13 | 13 |
| 14 #include "IceDefs.h" | 14 #include "IceDefs.h" |
| 15 #include "IceTypes.h" | 15 #include "IceTypes.h" |
| 16 | 16 |
| 17 namespace Ice { | 17 namespace Ice { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const struct { | 21 // Dummy function to make sure the two type tables have the same |
| 22 // enumerated types. |
| 23 void __attribute__((unused)) xIceTypeMacroIntegrityCheck() { |
| 24 |
| 25 // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. |
| 26 |
| 27 // Define a temporary set of enum values based on ICETYPE_TABLE |
| 28 enum { |
| 29 #define X(tag, size, align, elts, elty, str) _table_tag_##tag, |
| 30 ICETYPE_TABLE |
| 31 #undef X |
| 32 _enum_table_tag_Names |
| 33 }; |
| 34 // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE |
| 35 enum { |
| 36 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith) _props_table_tag_##tag, |
| 37 ICETYPE_PROPS_TABLE |
| 38 #undef X |
| 39 _enum_props_table_tag_Names |
| 40 }; |
| 41 // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. |
| 42 #define X(tag, size, align, elts, elty, str) \ |
| 43 STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); |
| 44 ICETYPE_TABLE; |
| 45 #undef X |
| 46 // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. |
| 47 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith) \ |
| 48 STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); |
| 49 ICETYPE_PROPS_TABLE; |
| 50 #undef X |
| 51 |
| 52 // Show vector definitions match in ICETYPE_TABLE and |
| 53 // ICETYPE_PROPS_TABLE. |
| 54 |
| 55 // Define constants for each element size in ICETYPE_TABLE. |
| 56 enum { |
| 57 #define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, |
| 58 ICETYPE_TABLE |
| 59 #undef X |
| 60 _enum_table_elts_Elements = 0 |
| 61 }; |
| 62 // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. |
| 63 enum { |
| 64 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith) \ |
| 65 _props_table_IsVec_##tag = IsVec, |
| 66 ICETYPE_PROPS_TABLE |
| 67 #undef X |
| 68 }; |
| 69 // Verify that the number of vector elements is consistent with IsVec. |
| 70 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith) \ |
| 71 STATIC_ASSERT((_table_elts_##tag > 1) == _props_table_IsVec_##tag); |
| 72 ICETYPE_PROPS_TABLE; |
| 73 #undef X |
| 74 } |
| 75 |
| 76 struct TypeAttributeFields { |
| 22 size_t TypeWidthInBytes; | 77 size_t TypeWidthInBytes; |
| 23 size_t TypeAlignInBytes; | 78 size_t TypeAlignInBytes; |
| 24 size_t TypeNumElements; | 79 size_t TypeNumElements; |
| 25 Type TypeElementType; | 80 Type TypeElementType; |
| 26 const char *DisplayString; | 81 const char *DisplayString; |
| 27 } TypeAttributes[] = { | 82 }; |
| 83 |
| 84 const struct TypeAttributeFields TypeAttributes[] = { |
| 28 #define X(tag, size, align, elts, elty, str) \ | 85 #define X(tag, size, align, elts, elty, str) \ |
| 29 { size, align, elts, elty, str } \ | 86 { size, align, elts, elty, str } \ |
| 30 , | 87 , |
| 31 ICETYPE_TABLE | 88 ICETYPE_TABLE |
| 32 #undef X | 89 #undef X |
| 33 }; | 90 }; |
| 34 | 91 |
| 35 const size_t TypeAttributesSize = | 92 struct TypePropertyFields { |
| 36 sizeof(TypeAttributes) / sizeof(*TypeAttributes); | 93 bool TypeIsVectorType; |
| 94 bool TypeIsIntegerType; |
| 95 bool TypeIsScalarIntegerType; |
| 96 bool TypeIsVectorIntegerType; |
| 97 bool TypeIsIntegerArithmeticType; |
| 98 bool TypeIsFloatingType; |
| 99 bool TypeIsScalarFloatingType; |
| 100 bool TypeIsVectorFloatingType; |
| 101 }; |
| 102 |
| 103 const TypePropertyFields TypePropertiesTable[] = { |
| 104 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith) \ |
| 105 { \ |
| 106 IsVec, IsInt, IsInt && !IsVec, IsInt && IsVec, IsIntArith, IsFloat, \ |
| 107 IsFloat && !IsVec, IsFloat && IsVec \ |
| 108 } \ |
| 109 , |
| 110 ICETYPE_PROPS_TABLE |
| 111 #undef X |
| 112 }; |
| 37 | 113 |
| 38 } // end anonymous namespace | 114 } // end anonymous namespace |
| 39 | 115 |
| 40 size_t typeWidthInBytes(Type Ty) { | 116 size_t typeWidthInBytes(Type Ty) { |
| 41 size_t Width = 0; | 117 size_t Index = static_cast<size_t>(Ty); |
| 42 size_t Index = static_cast<size_t>(Ty); | 118 if (Index < IceType_NUM) |
| 43 if (Index < TypeAttributesSize) { | 119 return TypeAttributes[Index].TypeWidthInBytes; |
| 44 Width = TypeAttributes[Index].TypeWidthInBytes; | 120 llvm_unreachable("Invalid type for typeWidthInBytes()"); |
| 45 } else { | 121 return 0; |
| 46 llvm_unreachable("Invalid type for typeWidthInBytes()"); | |
| 47 } | |
| 48 return Width; | |
| 49 } | 122 } |
| 50 | 123 |
| 51 size_t typeAlignInBytes(Type Ty) { | 124 size_t typeAlignInBytes(Type Ty) { |
| 52 size_t Align = 0; | 125 size_t Index = static_cast<size_t>(Ty); |
| 53 size_t Index = static_cast<size_t>(Ty); | 126 if (Index < IceType_NUM) |
| 54 if (Index < TypeAttributesSize) { | 127 return TypeAttributes[Index].TypeAlignInBytes; |
| 55 Align = TypeAttributes[Index].TypeAlignInBytes; | 128 llvm_unreachable("Invalid type for typeAlignInBytes()"); |
| 56 } else { | 129 return 1; |
| 57 llvm_unreachable("Invalid type for typeAlignInBytes()"); | |
| 58 } | |
| 59 return Align; | |
| 60 } | 130 } |
| 61 | 131 |
| 62 size_t typeNumElements(Type Ty) { | 132 size_t typeNumElements(Type Ty) { |
| 63 size_t NumElements = 0; | 133 size_t Index = static_cast<size_t>(Ty); |
| 64 size_t Index = static_cast<size_t>(Ty); | 134 if (Index < IceType_NUM) |
| 65 if (Index < TypeAttributesSize) { | 135 return TypeAttributes[Index].TypeNumElements; |
| 66 NumElements = TypeAttributes[Index].TypeNumElements; | 136 llvm_unreachable("Invalid type for typeNumElements()"); |
| 67 } else { | 137 return 1; |
| 68 llvm_unreachable("Invalid type for typeNumElements()"); | |
| 69 } | |
| 70 return NumElements; | |
| 71 } | 138 } |
| 72 | 139 |
| 73 Type typeElementType(Type Ty) { | 140 Type typeElementType(Type Ty) { |
| 74 Type ElementType = IceType_void; | 141 size_t Index = static_cast<size_t>(Ty); |
| 75 size_t Index = static_cast<size_t>(Ty); | 142 if (Index < IceType_NUM) |
| 76 if (Index < TypeAttributesSize) { | 143 return TypeAttributes[Index].TypeElementType; |
| 77 ElementType = TypeAttributes[Index].TypeElementType; | 144 llvm_unreachable("Invalid type for typeElementType()"); |
| 78 } else { | 145 return IceType_void; |
| 79 llvm_unreachable("Invalid type for typeElementType()"); | 146 } |
| 80 } | 147 |
| 81 return ElementType; | 148 bool isVectorType(Type Ty) { |
| 82 } | 149 size_t Index = static_cast<size_t>(Ty); |
| 150 if (Index < IceType_NUM) |
| 151 return TypePropertiesTable[Index].TypeIsVectorType; |
| 152 llvm_unreachable("Invalid type for isVectorType()"); |
| 153 return false; |
| 154 } |
| 155 |
| 156 bool isIntegerType(Type Ty) { |
| 157 size_t Index = static_cast<size_t>(Ty); |
| 158 if (Index < IceType_NUM) |
| 159 return TypePropertiesTable[Index].TypeIsIntegerType; |
| 160 llvm_unreachable("Invalid type for isIntegerType()"); |
| 161 return false; |
| 162 } |
| 163 |
| 164 bool isScalarIntegerType(Type Ty) { |
| 165 size_t Index = static_cast<size_t>(Ty); |
| 166 if (Index < IceType_NUM) |
| 167 return TypePropertiesTable[Index].TypeIsScalarIntegerType; |
| 168 llvm_unreachable("Invalid type for isScalIntegerType()"); |
| 169 return false; |
| 170 } |
| 171 |
| 172 bool isVectorIntegerType(Type Ty) { |
| 173 size_t Index = static_cast<size_t>(Ty); |
| 174 if (Index < IceType_NUM) |
| 175 return TypePropertiesTable[Index].TypeIsVectorIntegerType; |
| 176 llvm_unreachable("Invalid type for isVectorIntegerType()"); |
| 177 return false; |
| 178 } |
| 179 |
| 180 bool isIntegerArithmeticType(Type Ty) { |
| 181 size_t Index = static_cast<size_t>(Ty); |
| 182 if (Index < IceType_NUM) |
| 183 return TypePropertiesTable[Index].TypeIsIntegerArithmeticType; |
| 184 llvm_unreachable("Invalid type for isIntegerArithmeticType()"); |
| 185 return false; |
| 186 } |
| 187 |
| 188 bool isFloatingType(Type Ty) { |
| 189 size_t Index = static_cast<size_t>(Ty); |
| 190 if (Index < IceType_NUM) |
| 191 return TypePropertiesTable[Index].TypeIsFloatingType; |
| 192 llvm_unreachable("Invalid type for isFloatingType()"); |
| 193 return false; |
| 194 } |
| 195 |
| 196 bool isScalarFloatingType(Type Ty) { |
| 197 size_t Index = static_cast<size_t>(Ty); |
| 198 if (Index < IceType_NUM) |
| 199 return TypePropertiesTable[Index].TypeIsScalarFloatingType; |
| 200 llvm_unreachable("Invalid type for isScalarFloatingType()"); |
| 201 return false; |
| 202 } |
| 203 |
| 204 bool isVectorFloatingType(Type Ty) { |
| 205 size_t Index = static_cast<size_t>(Ty); |
| 206 if (Index < IceType_NUM) |
| 207 return TypePropertiesTable[Index].TypeIsVectorFloatingType; |
| 208 llvm_unreachable("Invalid type for isVectorFloatingType()"); |
| 209 return false; |
| 210 } |
| 211 |
| 212 // ======================== Dump routines ======================== // |
| 83 | 213 |
| 84 const char *typeString(Type Ty) { | 214 const char *typeString(Type Ty) { |
| 85 size_t Index = static_cast<size_t>(Ty); | 215 size_t Index = static_cast<size_t>(Ty); |
| 86 if (Index < TypeAttributesSize) { | 216 if (Index < IceType_NUM) |
| 87 return TypeAttributes[Index].DisplayString; | 217 return TypeAttributes[Index].DisplayString; |
| 88 } | |
| 89 llvm_unreachable("Invalid type for typeString"); | 218 llvm_unreachable("Invalid type for typeString"); |
| 90 return "???"; | 219 return "???"; |
| 91 } | 220 } |
| 92 | 221 |
| 93 } // end of namespace Ice | 222 } // end of namespace Ice |
| OLD | NEW |