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 |
| 23 // Dummy function to make sure the two type tables have the same | |
| 24 // enumerated types. | |
| 25 void 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) _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) \ | |
| 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) _props_table_IsVec_##tag = IsVec, | |
| 67 ICETYPE_PROPS_TABLE | |
| 68 #undef X | |
| 69 }; | |
| 70 // Verify Number vector elements consistent with IsVec. | |
|
jvoung (off chromium)
2014/07/25 22:42:08
nit: "Verify Number vector" -> "Verify that the nu
Karl
2014/07/30 20:16:15
Done.
| |
| 71 #define X(tag, IsVec, IsInt, IsFloat) \ | |
| 72 STATIC_ASSERT((_table_elts_##tag > 1) == _props_table_IsVec_##tag); | |
| 73 ICETYPE_PROPS_TABLE; | |
| 74 #undef X | |
| 75 } | |
| 76 | |
| 21 const struct { | 77 const struct { |
| 22 size_t TypeWidthInBytes; | 78 size_t TypeWidthInBytes; |
| 23 size_t TypeAlignInBytes; | 79 size_t TypeAlignInBytes; |
| 24 size_t TypeNumElements; | 80 size_t TypeNumElements; |
| 25 Type TypeElementType; | 81 Type TypeElementType; |
| 26 const char *DisplayString; | 82 const char *DisplayString; |
| 27 } TypeAttributes[] = { | 83 } TypeAttributes[] = { |
| 28 #define X(tag, size, align, elts, elty, str) \ | 84 #define X(tag, size, align, elts, elty, str) \ |
| 29 { size, align, elts, elty, str } \ | 85 { size, align, elts, elty, str } \ |
| 30 , | 86 , |
| 31 ICETYPE_TABLE | 87 ICETYPE_TABLE |
| 32 #undef X | 88 #undef X |
| 33 }; | 89 }; |
| 34 | 90 |
| 35 const size_t TypeAttributesSize = | 91 const size_t TypeAttributesSize = |
|
Karl
2014/07/30 20:16:15
Removed this and replaced with llvm::array_lengtho
| |
| 36 sizeof(TypeAttributes) / sizeof(*TypeAttributes); | 92 sizeof(TypeAttributes) / sizeof(*TypeAttributes); |
| 37 | 93 |
| 38 } // end anonymous namespace | 94 } // end anonymous namespace |
| 39 | 95 |
| 40 size_t typeWidthInBytes(Type Ty) { | 96 size_t typeWidthInBytes(Type Ty) { |
| 41 size_t Width = 0; | 97 size_t Width = 0; |
| 42 size_t Index = static_cast<size_t>(Ty); | 98 size_t Index = static_cast<size_t>(Ty); |
| 43 if (Index < TypeAttributesSize) { | 99 if (Index < TypeAttributesSize) { |
| 44 Width = TypeAttributes[Index].TypeWidthInBytes; | 100 Width = TypeAttributes[Index].TypeWidthInBytes; |
| 45 } else { | 101 } else { |
| 46 llvm_unreachable("Invalid type for typeWidthInBytes()"); | 102 llvm_unreachable("Invalid type for typeWidthInBytes()"); |
| 47 } | 103 } |
| 48 return Width; | 104 return Width; |
| 49 } | 105 } |
| 50 | 106 |
| 51 size_t typeAlignInBytes(Type Ty) { | 107 size_t typeAlignInBytes(Type Ty) { |
| 52 size_t Align = 0; | 108 size_t Align = 0; |
| 53 size_t Index = static_cast<size_t>(Ty); | 109 size_t Index = static_cast<size_t>(Ty); |
| 54 if (Index < TypeAttributesSize) { | 110 if (Index < TypeAttributesSize) { |
|
Karl
2014/07/30 20:16:15
Simplified this (and subsequent functions) to not
| |
| 55 Align = TypeAttributes[Index].TypeAlignInBytes; | 111 Align = TypeAttributes[Index].TypeAlignInBytes; |
| 56 } else { | 112 } else { |
| 57 llvm_unreachable("Invalid type for typeAlignInBytes()"); | 113 llvm_unreachable("Invalid type for typeAlignInBytes()"); |
| 58 } | 114 } |
| 59 return Align; | 115 return Align; |
| 60 } | 116 } |
| 61 | 117 |
| 62 size_t typeNumElements(Type Ty) { | 118 size_t typeNumElements(Type Ty) { |
| 63 size_t NumElements = 0; | 119 size_t NumElements = 0; |
| 64 size_t Index = static_cast<size_t>(Ty); | 120 size_t Index = static_cast<size_t>(Ty); |
| 65 if (Index < TypeAttributesSize) { | 121 if (Index < TypeAttributesSize) { |
| 66 NumElements = TypeAttributes[Index].TypeNumElements; | 122 NumElements = TypeAttributes[Index].TypeNumElements; |
| 67 } else { | 123 } else { |
| 68 llvm_unreachable("Invalid type for typeNumElements()"); | 124 llvm_unreachable("Invalid type for typeNumElements()"); |
| 69 } | 125 } |
| 70 return NumElements; | 126 return NumElements; |
| 71 } | 127 } |
| 72 | 128 |
| 73 Type typeElementType(Type Ty) { | 129 Type typeElementType(Type Ty) { |
| 74 Type ElementType = IceType_void; | 130 Type ElementType = IceType_void; |
| 75 size_t Index = static_cast<size_t>(Ty); | 131 size_t Index = static_cast<size_t>(Ty); |
| 76 if (Index < TypeAttributesSize) { | 132 if (Index < TypeAttributesSize) { |
| 77 ElementType = TypeAttributes[Index].TypeElementType; | 133 ElementType = TypeAttributes[Index].TypeElementType; |
| 78 } else { | 134 } else { |
| 79 llvm_unreachable("Invalid type for typeElementType()"); | 135 llvm_unreachable("Invalid type for typeElementType()"); |
| 80 } | 136 } |
| 81 return ElementType; | 137 return ElementType; |
| 82 } | 138 } |
| 83 | 139 |
| 140 namespace { | |
| 141 | |
| 142 static const bool IsVectorTable[] = { | |
| 143 #define X(tag, IsVec, IsInt, IsFloat) IsVec, | |
| 144 ICETYPE_PROPS_TABLE | |
| 145 #undef X | |
| 146 }; | |
| 147 | |
| 148 } // end anonymous namespace | |
| 149 | |
| 150 bool isVectorType(Type Ty) { | |
| 151 size_t Index = static_cast<size_t>(Ty); | |
| 152 if (Index < llvm::array_lengthof(IsVectorTable)) | |
| 153 return IsVectorTable[Index]; | |
| 154 llvm_unreachable("Invalid type for isVectorType()"); | |
| 155 } | |
| 156 | |
| 157 namespace { | |
| 158 | |
| 159 static const bool IsScalarIntegerTable[] = { | |
| 160 #define X(tag, IsVec, IsInt, IsFloat) IsInt && !IsVec, | |
| 161 ICETYPE_PROPS_TABLE | |
| 162 #undef X | |
| 163 }; | |
| 164 | |
| 165 } // end anonymous namespace | |
|
jvoung (off chromium)
2014/07/25 22:42:09
I think it would be nicer to just have all the tab
Karl
2014/07/30 20:16:15
Merged into a single table of structs.
| |
| 166 | |
| 167 bool isScalarIntegerType(Type Ty) { | |
| 168 size_t Index = static_cast<size_t>(Ty); | |
| 169 if (Index < llvm::array_lengthof(IsScalarIntegerTable)) | |
| 170 return IsScalarIntegerTable[Index]; | |
| 171 llvm_unreachable("Invalid type for isScalIntegerType()"); | |
| 172 } | |
| 173 | |
| 174 namespace { | |
| 175 | |
| 176 static const bool IsVectorIntegerTable[] = { | |
| 177 #define X(tag, IsVec, IsInt, IsFloat) IsInt &&IsVec, | |
|
jvoung (off chromium)
2014/07/25 22:42:08
space between && and IsVec
Karl
2014/07/30 20:16:15
Done.
| |
| 178 ICETYPE_PROPS_TABLE | |
| 179 #undef X | |
| 180 }; | |
| 181 | |
| 182 } // end anonymous namespace | |
| 183 | |
| 184 bool isVectorIntegerType(Type Ty) { | |
| 185 size_t Index = static_cast<size_t>(Ty); | |
| 186 if (Index < llvm::array_lengthof(IsVectorIntegerTable)) | |
| 187 return IsVectorIntegerTable[Index]; | |
| 188 llvm_unreachable("Invalid type for IsVectorIntegerType()"); | |
| 189 } | |
| 190 | |
| 191 namespace { | |
| 192 | |
| 193 static const bool IsScalarFloatingTable[] = { | |
| 194 #define X(tag, IsVec, IsInt, IsFloat) IsFloat && !IsVec, | |
| 195 ICETYPE_PROPS_TABLE | |
| 196 #undef X | |
| 197 }; | |
| 198 | |
| 199 } // end anonymous namespace | |
| 200 | |
| 201 bool isScalarFloatingType(Type Ty) { | |
| 202 size_t Index = static_cast<size_t>(Ty); | |
| 203 if (Index < llvm::array_lengthof(IsScalarFloatingTable)) | |
| 204 return IsScalarFloatingTable[Index]; | |
| 205 llvm_unreachable("Invalid type for IsScalarFloatingType()"); | |
| 206 } | |
| 207 | |
| 208 namespace { | |
| 209 | |
| 210 static const bool IsVectorFloatingTable[] = { | |
| 211 #define X(tag, IsVec, IsInt, IsFloat) IsFloat &&IsVec, | |
|
jvoung (off chromium)
2014/07/25 22:42:09
space between && and IsVec
Karl
2014/07/30 20:16:15
Done.
| |
| 212 ICETYPE_PROPS_TABLE | |
| 213 #undef X | |
| 214 }; | |
| 215 | |
| 216 } // end anonymous namespace | |
| 217 | |
| 218 bool isVectorFloatingType(Type Ty) { | |
| 219 size_t Index = static_cast<size_t>(Ty); | |
| 220 if (Index < llvm::array_lengthof(IsVectorFloatingTable)) | |
| 221 return IsVectorFloatingTable[Index]; | |
| 222 llvm_unreachable("Invalid type for IsVectorFloatingType()"); | |
| 223 } | |
| 224 | |
| 84 // ======================== Dump routines ======================== // | 225 // ======================== Dump routines ======================== // |
| 85 | 226 |
| 86 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { | 227 Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| 87 size_t Index = static_cast<size_t>(Ty); | 228 size_t Index = static_cast<size_t>(Ty); |
| 88 if (Index < TypeAttributesSize) { | 229 if (Index < TypeAttributesSize) { |
| 89 Str << TypeAttributes[Index].DisplayString; | 230 Str << TypeAttributes[Index].DisplayString; |
| 90 } else { | 231 } else { |
| 91 Str << "???"; | 232 Str << "???"; |
| 92 llvm_unreachable("Invalid type for printing"); | 233 llvm_unreachable("Invalid type for printing"); |
| 93 } | 234 } |
| 94 | 235 |
| 95 return Str; | 236 return Str; |
| 96 } | 237 } |
| 97 | 238 |
| 98 } // end of namespace Ice | 239 } // end of namespace Ice |
| OLD | NEW |