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