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" | |
| 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 xIceTypeMacroIntegrityCheck() { | |
|
jvoung (off chromium)
2014/07/31 16:18:29
you might have to put an "__attribute__((unused))"
Jim Stichnoth
2014/08/01 18:05:33
Definitely, as this had to be added in IceTargetLo
Karl
2014/08/25 17:46:53
Acknowledged.
Karl
2014/08/25 17:46:53
Done.
| |
| 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, IsIntAritArith) _props_table_tag_##tag, | |
|
jvoung (off chromium)
2014/07/31 16:18:29
IsIntAritArith -> IsIntArith
Karl
2014/08/25 17:46:53
Done.
| |
| 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 consistent with IsVec. | |
|
jvoung (off chromium)
2014/07/31 16:18:29
number of vector elements *is* consistent with IsV
Karl
2014/08/25 17:46:53
Done.
| |
| 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 static const struct TypeAttributeFields TypeAttributes[] = { | |
|
Jim Stichnoth
2014/08/01 18:05:34
Don't need "static" inside an anonymous namespace.
Karl
2014/08/25 17:46:53
Done.
| |
| 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 static 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 < llvm::array_lengthof(TypeAttributes)) |
|
Jim Stichnoth
2014/08/01 18:05:33
For all instances of llvm::array_lengthof(TypeAttr
Karl
2014/08/25 17:46:53
Changed to use IceType_NUM.
| |
| 44 Width = TypeAttributes[Index].TypeWidthInBytes; | 121 return TypeAttributes[Index].TypeWidthInBytes; |
| 45 } else { | 122 llvm_unreachable("Invalid type for typeWidthInBytes()"); |
|
jvoung (off chromium)
2014/07/31 16:18:29
Could you leave the return after llvm_unreachable?
Karl
2014/08/25 17:46:53
Done.
| |
| 46 llvm_unreachable("Invalid type for typeWidthInBytes()"); | |
| 47 } | |
| 48 return Width; | |
| 49 } | 123 } |
| 50 | 124 |
| 51 size_t typeAlignInBytes(Type Ty) { | 125 size_t typeAlignInBytes(Type Ty) { |
| 52 size_t Align = 0; | |
| 53 size_t Index = static_cast<size_t>(Ty); | 126 size_t Index = static_cast<size_t>(Ty); |
| 54 if (Index < TypeAttributesSize) { | 127 if (Index < llvm::array_lengthof(TypeAttributes)) |
| 55 Align = TypeAttributes[Index].TypeAlignInBytes; | 128 return TypeAttributes[Index].TypeAlignInBytes; |
| 56 } else { | 129 llvm_unreachable("Invalid type for typeAlignInBytes()"); |
| 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; | |
| 64 size_t Index = static_cast<size_t>(Ty); | 133 size_t Index = static_cast<size_t>(Ty); |
| 65 if (Index < TypeAttributesSize) { | 134 if (Index < llvm::array_lengthof(TypeAttributes)) |
| 66 NumElements = TypeAttributes[Index].TypeNumElements; | 135 return TypeAttributes[Index].TypeNumElements; |
| 67 } else { | 136 llvm_unreachable("Invalid type for typeNumElements()"); |
| 68 llvm_unreachable("Invalid type for typeNumElements()"); | |
| 69 } | |
| 70 return NumElements; | |
| 71 } | 137 } |
| 72 | 138 |
| 73 Type typeElementType(Type Ty) { | 139 Type typeElementType(Type Ty) { |
| 74 Type ElementType = IceType_void; | |
| 75 size_t Index = static_cast<size_t>(Ty); | 140 size_t Index = static_cast<size_t>(Ty); |
| 76 if (Index < TypeAttributesSize) { | 141 if (Index < llvm::array_lengthof(TypeAttributes)) |
| 77 ElementType = TypeAttributes[Index].TypeElementType; | 142 return TypeAttributes[Index].TypeElementType; |
| 78 } else { | 143 llvm_unreachable("Invalid type for typeElementType()"); |
| 79 llvm_unreachable("Invalid type for typeElementType()"); | |
| 80 } | |
| 81 return ElementType; | |
| 82 } | 144 } |
| 83 | 145 |
| 146 bool isVectorType(Type Ty) { | |
| 147 size_t Index = static_cast<size_t>(Ty); | |
| 148 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 149 return TypePropertiesTable[Index].TypeIsVectorType; | |
| 150 llvm_unreachable("Invalid type for isVectorType()"); | |
| 151 } | |
| 152 | |
| 153 bool isIntegerType(Type Ty) { | |
| 154 size_t Index = static_cast<size_t>(Ty); | |
| 155 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 156 return TypePropertiesTable[Index].TypeIsIntegerType; | |
| 157 llvm_unreachable("Invalid type for isIntegerType()"); | |
| 158 } | |
| 159 | |
| 160 bool isScalarIntegerType(Type Ty) { | |
| 161 size_t Index = static_cast<size_t>(Ty); | |
| 162 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 163 return TypePropertiesTable[Index].TypeIsScalarIntegerType; | |
| 164 llvm_unreachable("Invalid type for isScalIntegerType()"); | |
| 165 } | |
| 166 | |
| 167 bool isVectorIntegerType(Type Ty) { | |
| 168 size_t Index = static_cast<size_t>(Ty); | |
| 169 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 170 return TypePropertiesTable[Index].TypeIsVectorIntegerType; | |
| 171 llvm_unreachable("Invalid type for isVectorIntegerType()"); | |
| 172 } | |
| 173 | |
| 174 bool isIntegerArithmeticType(Type Ty) { | |
| 175 size_t Index = static_cast<size_t>(Ty); | |
| 176 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 177 return TypePropertiesTable[Index].TypeIsIntegerArithmeticType; | |
| 178 llvm_unreachable("Invalid type for isIntegerArithmeticType()"); | |
| 179 } | |
| 180 | |
| 181 bool isFloatingType(Type Ty) { | |
| 182 size_t Index = static_cast<size_t>(Ty); | |
| 183 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 184 return TypePropertiesTable[Index].TypeIsFloatingType; | |
| 185 llvm_unreachable("Invalid type for isFloatingType()"); | |
| 186 } | |
| 187 | |
| 188 bool isScalarFloatingType(Type Ty) { | |
| 189 size_t Index = static_cast<size_t>(Ty); | |
| 190 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 191 return TypePropertiesTable[Index].TypeIsScalarFloatingType; | |
| 192 llvm_unreachable("Invalid type for isScalarFloatingType()"); | |
| 193 } | |
| 194 | |
| 195 bool isVectorFloatingType(Type Ty) { | |
| 196 size_t Index = static_cast<size_t>(Ty); | |
| 197 if (Index < llvm::array_lengthof(TypePropertiesTable)) | |
| 198 return TypePropertiesTable[Index].TypeIsVectorFloatingType; | |
| 199 llvm_unreachable("Invalid type for isVectorFloatingType()"); | |
| 200 } | |
| 201 | |
| 202 // ======================== Dump routines ======================== // | |
| 203 | |
| 84 const char *typeString(Type Ty) { | 204 const char *typeString(Type Ty) { |
| 85 size_t Index = static_cast<size_t>(Ty); | 205 size_t Index = static_cast<size_t>(Ty); |
| 86 if (Index < TypeAttributesSize) { | 206 if (Index < llvm::array_lengthof(TypeAttributes)) { |
| 87 return TypeAttributes[Index].DisplayString; | 207 return TypeAttributes[Index].DisplayString; |
| 88 } | 208 } |
| 89 llvm_unreachable("Invalid type for typeString"); | 209 llvm_unreachable("Invalid type for typeString"); |
| 90 return "???"; | 210 return "???"; |
| 91 } | 211 } |
| 92 | 212 |
| 93 } // end of namespace Ice | 213 } // end of namespace Ice |
| OLD | NEW |