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 // Dummy function to make sure the two type tables have the same | 21 // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. |
22 // enumerated types. | |
23 void __attribute__((unused)) xIceTypeMacroIntegrityCheck() { | |
24 | 22 |
25 // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. | 23 // Define a temporary set of enum values based on ICETYPE_TABLE |
26 | 24 enum { |
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, | 25 #define X(tag, size, align, elts, elty, str) _table_tag_##tag, |
30 ICETYPE_TABLE | 26 ICETYPE_TABLE |
31 #undef X | 27 #undef X |
32 _enum_table_tag_Names | 28 _enum_table_tag_Names |
33 }; | 29 }; |
34 // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE | 30 // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE |
35 enum { | 31 enum { |
36 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ | 32 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ |
37 _props_table_tag_##tag, | 33 _props_table_tag_##tag, |
38 ICETYPE_PROPS_TABLE | 34 ICETYPE_PROPS_TABLE |
39 #undef X | 35 #undef X |
40 _enum_props_table_tag_Names | 36 _enum_props_table_tag_Names |
41 }; | 37 }; |
42 // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. | 38 // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. |
43 #define X(tag, size, align, elts, elty, str) \ | 39 #define X(tag, size, align, elts, elty, str) \ |
44 STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); | 40 static_assert( \ |
45 ICETYPE_TABLE; | 41 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \ |
| 42 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE"); |
| 43 ICETYPE_TABLE; |
46 #undef X | 44 #undef X |
47 // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. | 45 // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. |
48 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ | 46 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ |
49 STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); | 47 static_assert( \ |
| 48 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \ |
| 49 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE"); |
| 50 ICETYPE_PROPS_TABLE |
| 51 #undef X |
| 52 |
| 53 // Show vector definitions match in ICETYPE_TABLE and |
| 54 // ICETYPE_PROPS_TABLE. |
| 55 |
| 56 // Define constants for each element size in ICETYPE_TABLE. |
| 57 enum { |
| 58 #define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, |
| 59 ICETYPE_TABLE |
| 60 #undef X |
| 61 _enum_table_elts_Elements = 0 |
| 62 }; |
| 63 // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. |
| 64 enum { |
| 65 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ |
| 66 _props_table_IsVec_##tag = IsVec, |
50 ICETYPE_PROPS_TABLE | 67 ICETYPE_PROPS_TABLE |
51 #undef X | 68 #undef X |
52 | 69 }; |
53 // Show vector definitions match in ICETYPE_TABLE and | |
54 // ICETYPE_PROPS_TABLE. | |
55 | |
56 // Define constants for each element size in ICETYPE_TABLE. | |
57 enum { | |
58 #define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, | |
59 ICETYPE_TABLE | |
60 #undef X | |
61 _enum_table_elts_Elements = 0 | |
62 }; | |
63 // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. | |
64 enum { | |
65 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ | |
66 _props_table_IsVec_##tag = IsVec, | |
67 ICETYPE_PROPS_TABLE | |
68 #undef X | |
69 }; | |
70 // Verify that the number of vector elements is consistent with IsVec. | 70 // Verify that the number of vector elements is consistent with IsVec. |
71 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ | 71 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ |
72 STATIC_ASSERT((_table_elts_##tag > 1) == _props_table_IsVec_##tag); | 72 static_assert((_table_elts_##tag > 1) == _props_table_IsVec_##tag, \ |
73 ICETYPE_PROPS_TABLE; | 73 "Inconsistent vector specification in ICETYPE_PROPS_TABLE"); |
| 74 ICETYPE_PROPS_TABLE; |
74 #undef X | 75 #undef X |
75 } | |
76 | 76 |
77 struct TypeAttributeFields { | 77 struct TypeAttributeFields { |
78 size_t TypeWidthInBytes; | 78 size_t TypeWidthInBytes; |
79 size_t TypeAlignInBytes; | 79 size_t TypeAlignInBytes; |
80 size_t TypeNumElements; | 80 size_t TypeNumElements; |
81 Type TypeElementType; | 81 Type TypeElementType; |
82 const char *DisplayString; | 82 const char *DisplayString; |
83 }; | 83 }; |
84 | 84 |
85 const struct TypeAttributeFields TypeAttributes[] = { | 85 const struct TypeAttributeFields TypeAttributes[] = { |
86 #define X(tag, size, align, elts, elty, str) \ | 86 #define X(tag, size, align, elts, elty, str) \ |
87 { size, align, elts, elty, str } \ | 87 { size, align, elts, elty, str } \ |
88 , | 88 , |
89 ICETYPE_TABLE | 89 ICETYPE_TABLE |
90 #undef X | 90 #undef X |
91 }; | 91 }; |
92 | 92 |
93 struct TypePropertyFields { | 93 struct TypePropertyFields { |
94 bool TypeIsVectorType; | 94 bool TypeIsVectorType; |
95 bool TypeIsIntegerType; | 95 bool TypeIsIntegerType; |
96 bool TypeIsScalarIntegerType; | 96 bool TypeIsScalarIntegerType; |
97 bool TypeIsVectorIntegerType; | 97 bool TypeIsVectorIntegerType; |
98 bool TypeIsIntegerArithmeticType; | 98 bool TypeIsIntegerArithmeticType; |
99 bool TypeIsFloatingType; | 99 bool TypeIsFloatingType; |
100 bool TypeIsScalarFloatingType; | 100 bool TypeIsScalarFloatingType; |
101 bool TypeIsVectorFloatingType; | 101 bool TypeIsVectorFloatingType; |
102 bool TypeIsLoadStoreType; | 102 bool TypeIsLoadStoreType; |
103 Type CompareResultType; | 103 Type CompareResultType; |
104 }; | 104 }; |
105 | 105 |
106 const TypePropertyFields TypePropertiesTable[] = { | 106 const TypePropertyFields TypePropertiesTable[] = { |
107 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ | 107 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ |
108 { \ | 108 { \ |
109 IsVec, IsInt, IsInt && !IsVec, IsInt && IsVec, IsIntArith, IsFloat, \ | 109 IsVec, IsInt, IsInt && !IsVec, IsInt && IsVec, IsIntArith, IsFloat, \ |
110 IsFloat && !IsVec, IsFloat && IsVec, IsLoadStore, CompareResult \ | 110 IsFloat && !IsVec, IsFloat && IsVec, IsLoadStore, CompareResult \ |
111 } \ | 111 } \ |
112 , | 112 , |
113 ICETYPE_PROPS_TABLE | 113 ICETYPE_PROPS_TABLE |
114 #undef X | 114 #undef X |
115 }; | 115 }; |
116 | 116 |
117 } // end anonymous namespace | 117 } // end anonymous namespace |
118 | 118 |
119 size_t typeWidthInBytes(Type Ty) { | 119 size_t typeWidthInBytes(Type Ty) { |
120 size_t Index = static_cast<size_t>(Ty); | 120 size_t Index = static_cast<size_t>(Ty); |
121 if (Index < IceType_NUM) | 121 if (Index < IceType_NUM) |
122 return TypeAttributes[Index].TypeWidthInBytes; | 122 return TypeAttributes[Index].TypeWidthInBytes; |
123 llvm_unreachable("Invalid type for typeWidthInBytes()"); | 123 llvm_unreachable("Invalid type for typeWidthInBytes()"); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 const char *typeString(Type Ty) { | 240 const char *typeString(Type Ty) { |
241 size_t Index = static_cast<size_t>(Ty); | 241 size_t Index = static_cast<size_t>(Ty); |
242 if (Index < IceType_NUM) | 242 if (Index < IceType_NUM) |
243 return TypeAttributes[Index].DisplayString; | 243 return TypeAttributes[Index].DisplayString; |
244 llvm_unreachable("Invalid type for typeString"); | 244 llvm_unreachable("Invalid type for typeString"); |
245 return "???"; | 245 return "???"; |
246 } | 246 } |
247 | 247 |
248 } // end of namespace Ice | 248 } // end of namespace Ice |
OLD | NEW |