Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: src/IceTypes.cpp

Issue 1234803007: Introduction of improved switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Safer check for 0 size type Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 /// \file 10 /// \file
(...skipping 12 matching lines...) Expand all
23 const char *TargetArchName[] = { 23 const char *TargetArchName[] = {
24 #define X(tag, str, is_elf64, e_machine, e_flags) str, 24 #define X(tag, str, is_elf64, e_machine, e_flags) str,
25 TARGETARCH_TABLE 25 TARGETARCH_TABLE
26 #undef X 26 #undef X
27 }; 27 };
28 28
29 // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. 29 // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE.
30 30
31 // Define a temporary set of enum values based on ICETYPE_TABLE 31 // Define a temporary set of enum values based on ICETYPE_TABLE
32 enum { 32 enum {
33 #define X(tag, size, align, elts, elty, str) _table_tag_##tag, 33 #define X(tag, sizeLog2, align, elts, elty, str) _table_tag_##tag,
34 ICETYPE_TABLE 34 ICETYPE_TABLE
35 #undef X 35 #undef X
36 _enum_table_tag_Names 36 _enum_table_tag_Names
37 }; 37 };
38 // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE 38 // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE
39 enum { 39 enum {
40 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ 40 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
41 _props_table_tag_##tag, 41 _props_table_tag_##tag,
42 ICETYPE_PROPS_TABLE 42 ICETYPE_PROPS_TABLE
43 #undef X 43 #undef X
44 _enum_props_table_tag_Names 44 _enum_props_table_tag_Names
45 }; 45 };
46 // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. 46 // Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE.
47 #define X(tag, size, align, elts, elty, str) \ 47 #define X(tag, sizeLog2, align, elts, elty, str) \
48 static_assert( \ 48 static_assert( \
49 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \ 49 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \
50 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE"); 50 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE");
51 ICETYPE_TABLE 51 ICETYPE_TABLE
52 #undef X 52 #undef X
53 // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. 53 // Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE.
54 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ 54 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
55 static_assert( \ 55 static_assert( \
56 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \ 56 (unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag, \
57 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE"); 57 "Inconsistency between ICETYPE_PROPS_TABLE and ICETYPE_TABLE");
58 ICETYPE_PROPS_TABLE 58 ICETYPE_PROPS_TABLE
59 #undef X 59 #undef X
60 60
61 // Show vector definitions match in ICETYPE_TABLE and 61 // Show vector definitions match in ICETYPE_TABLE and
62 // ICETYPE_PROPS_TABLE. 62 // ICETYPE_PROPS_TABLE.
63 63
64 // Define constants for each element size in ICETYPE_TABLE. 64 // Define constants for each element size in ICETYPE_TABLE.
65 enum { 65 enum {
66 #define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, 66 #define X(tag, sizeLog2, align, elts, elty, str) _table_elts_##tag = elts,
67 ICETYPE_TABLE 67 ICETYPE_TABLE
68 #undef X 68 #undef X
69 _enum_table_elts_Elements = 0 69 _enum_table_elts_Elements = 0
70 }; 70 };
71 // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. 71 // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE.
72 enum { 72 enum {
73 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ 73 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
74 _props_table_IsVec_##tag = IsVec, 74 _props_table_IsVec_##tag = IsVec,
75 ICETYPE_PROPS_TABLE 75 ICETYPE_PROPS_TABLE
76 #undef X 76 #undef X
77 }; 77 };
78 // Verify that the number of vector elements is consistent with IsVec. 78 // Verify that the number of vector elements is consistent with IsVec.
79 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \ 79 #define X(tag, IsVec, IsInt, IsFloat, IsIntArith, IsLoadStore, CompareResult) \
80 static_assert((_table_elts_##tag > 1) == _props_table_IsVec_##tag, \ 80 static_assert((_table_elts_##tag > 1) == _props_table_IsVec_##tag, \
81 "Inconsistent vector specification in ICETYPE_PROPS_TABLE"); 81 "Inconsistent vector specification in ICETYPE_PROPS_TABLE");
82 ICETYPE_PROPS_TABLE 82 ICETYPE_PROPS_TABLE
83 #undef X 83 #undef X
84 84
85 struct TypeAttributeFields { 85 struct TypeAttributeFields {
86 size_t TypeWidthInBytes; 86 int8_t TypeWidthInBytesLog2;
87 size_t TypeAlignInBytes; 87 size_t TypeAlignInBytes;
88 size_t TypeNumElements; 88 size_t TypeNumElements;
89 Type TypeElementType; 89 Type TypeElementType;
90 const char *DisplayString; 90 const char *DisplayString;
91 }; 91 };
92 92
93 const struct TypeAttributeFields TypeAttributes[] = { 93 const struct TypeAttributeFields TypeAttributes[] = {
94 #define X(tag, size, align, elts, elty, str) \ 94 #define X(tag, sizeLog2, align, elts, elty, str) \
95 { size, align, elts, elty, str } \ 95 { sizeLog2, align, elts, elty, str } \
96 , 96 ,
97 ICETYPE_TABLE 97 ICETYPE_TABLE
98 #undef X 98 #undef X
99 }; 99 };
100 100
101 struct TypePropertyFields { 101 struct TypePropertyFields {
102 bool TypeIsVectorType; 102 bool TypeIsVectorType;
103 bool TypeIsIntegerType; 103 bool TypeIsIntegerType;
104 bool TypeIsScalarIntegerType; 104 bool TypeIsScalarIntegerType;
105 bool TypeIsVectorIntegerType; 105 bool TypeIsVectorIntegerType;
(...skipping 20 matching lines...) Expand all
126 126
127 const char *targetArchString(const TargetArch Arch) { 127 const char *targetArchString(const TargetArch Arch) {
128 size_t Index = static_cast<size_t>(Arch); 128 size_t Index = static_cast<size_t>(Arch);
129 if (Index < TargetArch_NUM) 129 if (Index < TargetArch_NUM)
130 return TargetArchName[Index]; 130 return TargetArchName[Index];
131 llvm_unreachable("Invalid target arch for targetArchString"); 131 llvm_unreachable("Invalid target arch for targetArchString");
132 return "???"; 132 return "???";
133 } 133 }
134 134
135 size_t typeWidthInBytes(Type Ty) { 135 size_t typeWidthInBytes(Type Ty) {
136 int8_t Shift = typeWidthInBytesLog2(Ty);
137 return (Shift < 0) ? 0 : 1 << Shift;
138 }
139
140 int8_t typeWidthInBytesLog2(Type Ty) {
136 size_t Index = static_cast<size_t>(Ty); 141 size_t Index = static_cast<size_t>(Ty);
137 if (Index < IceType_NUM) 142 if (Index < IceType_NUM)
138 return TypeAttributes[Index].TypeWidthInBytes; 143 return TypeAttributes[Index].TypeWidthInBytesLog2;
139 llvm_unreachable("Invalid type for typeWidthInBytes()"); 144 llvm_unreachable("Invalid type for typeWidthInBytesLog2()");
140 return 0; 145 return 0;
141 } 146 }
142 147
143 size_t typeAlignInBytes(Type Ty) { 148 size_t typeAlignInBytes(Type Ty) {
144 size_t Index = static_cast<size_t>(Ty); 149 size_t Index = static_cast<size_t>(Ty);
145 if (Index < IceType_NUM) 150 if (Index < IceType_NUM)
146 return TypeAttributes[Index].TypeAlignInBytes; 151 return TypeAttributes[Index].TypeAlignInBytes;
147 llvm_unreachable("Invalid type for typeAlignInBytes()"); 152 llvm_unreachable("Invalid type for typeAlignInBytes()");
148 return 1; 153 return 1;
149 } 154 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 IsFirst = false; 276 IsFirst = false;
272 } else { 277 } else {
273 Stream << ", "; 278 Stream << ", ";
274 } 279 }
275 Stream << ArgTy; 280 Stream << ArgTy;
276 } 281 }
277 Stream << ")"; 282 Stream << ")";
278 } 283 }
279 284
280 } // end of namespace Ice 285 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTypes.h ('k') | src/IceTypes.def » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698