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

Side by Side Diff: src/IceTypes.cpp

Issue 1674033002: Subzero: Clean up some uses of *_cast<>. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: More code review changes Created 4 years, 10 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/IceTargetLoweringX86BaseImpl.h ('k') | src/PNaClTranslator.cpp » ('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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 IceType_##CompareResult \ 126 IceType_##CompareResult \
127 } \ 127 } \
128 , 128 ,
129 ICETYPE_PROPS_TABLE 129 ICETYPE_PROPS_TABLE
130 #undef X 130 #undef X
131 }; 131 };
132 132
133 } // end anonymous namespace 133 } // end anonymous namespace
134 134
135 const char *targetArchString(const TargetArch Arch) { 135 const char *targetArchString(const TargetArch Arch) {
136 size_t Index = static_cast<size_t>(Arch); 136 if (Arch < TargetArch_NUM)
137 if (Index < TargetArch_NUM) 137 return TargetArchName[Arch];
138 return TargetArchName[Index];
139 llvm_unreachable("Invalid target arch for targetArchString"); 138 llvm_unreachable("Invalid target arch for targetArchString");
140 return "???"; 139 return "???";
141 } 140 }
142 141
143 size_t typeWidthInBytes(Type Ty) { 142 size_t typeWidthInBytes(Type Ty) {
144 int8_t Shift = typeWidthInBytesLog2(Ty); 143 int8_t Shift = typeWidthInBytesLog2(Ty);
145 return (Shift < 0) ? 0 : 1 << Shift; 144 return (Shift < 0) ? 0 : 1 << Shift;
146 } 145 }
147 146
148 int8_t typeWidthInBytesLog2(Type Ty) { 147 int8_t typeWidthInBytesLog2(Type Ty) {
149 size_t Index = static_cast<size_t>(Ty); 148 if (Ty < IceType_NUM)
150 if (Index < IceType_NUM) 149 return TypeAttributes[Ty].TypeWidthInBytesLog2;
151 return TypeAttributes[Index].TypeWidthInBytesLog2;
152 llvm_unreachable("Invalid type for typeWidthInBytesLog2()"); 150 llvm_unreachable("Invalid type for typeWidthInBytesLog2()");
153 return 0; 151 return 0;
154 } 152 }
155 153
156 size_t typeAlignInBytes(Type Ty) { 154 size_t typeAlignInBytes(Type Ty) {
157 size_t Index = static_cast<size_t>(Ty); 155 if (Ty < IceType_NUM)
158 if (Index < IceType_NUM) 156 return TypeAttributes[Ty].TypeAlignInBytes;
159 return TypeAttributes[Index].TypeAlignInBytes;
160 llvm_unreachable("Invalid type for typeAlignInBytes()"); 157 llvm_unreachable("Invalid type for typeAlignInBytes()");
161 return 1; 158 return 1;
162 } 159 }
163 160
164 size_t typeNumElements(Type Ty) { 161 size_t typeNumElements(Type Ty) {
165 size_t Index = static_cast<size_t>(Ty); 162 if (Ty < IceType_NUM)
166 if (Index < IceType_NUM) 163 return TypeAttributes[Ty].TypeNumElements;
167 return TypeAttributes[Index].TypeNumElements;
168 llvm_unreachable("Invalid type for typeNumElements()"); 164 llvm_unreachable("Invalid type for typeNumElements()");
169 return 1; 165 return 1;
170 } 166 }
171 167
172 Type typeElementType(Type Ty) { 168 Type typeElementType(Type Ty) {
173 size_t Index = static_cast<size_t>(Ty); 169 if (Ty < IceType_NUM)
174 if (Index < IceType_NUM) 170 return TypeAttributes[Ty].TypeElementType;
175 return TypeAttributes[Index].TypeElementType;
176 llvm_unreachable("Invalid type for typeElementType()"); 171 llvm_unreachable("Invalid type for typeElementType()");
177 return IceType_void; 172 return IceType_void;
178 } 173 }
179 174
180 bool isVectorType(Type Ty) { 175 bool isVectorType(Type Ty) {
181 size_t Index = static_cast<size_t>(Ty); 176 if (Ty < IceType_NUM)
182 if (Index < IceType_NUM) 177 return TypePropertiesTable[Ty].TypeIsVectorType;
183 return TypePropertiesTable[Index].TypeIsVectorType;
184 llvm_unreachable("Invalid type for isVectorType()"); 178 llvm_unreachable("Invalid type for isVectorType()");
185 return false; 179 return false;
186 } 180 }
187 181
188 bool isIntegerType(Type Ty) { 182 bool isIntegerType(Type Ty) {
189 size_t Index = static_cast<size_t>(Ty); 183 if (Ty < IceType_NUM)
190 if (Index < IceType_NUM) 184 return TypePropertiesTable[Ty].TypeIsIntegerType;
191 return TypePropertiesTable[Index].TypeIsIntegerType;
192 llvm_unreachable("Invalid type for isIntegerType()"); 185 llvm_unreachable("Invalid type for isIntegerType()");
193 return false; 186 return false;
194 } 187 }
195 188
196 bool isScalarIntegerType(Type Ty) { 189 bool isScalarIntegerType(Type Ty) {
197 size_t Index = static_cast<size_t>(Ty); 190 if (Ty < IceType_NUM)
198 if (Index < IceType_NUM) 191 return TypePropertiesTable[Ty].TypeIsScalarIntegerType;
199 return TypePropertiesTable[Index].TypeIsScalarIntegerType;
200 llvm_unreachable("Invalid type for isScalIntegerType()"); 192 llvm_unreachable("Invalid type for isScalIntegerType()");
201 return false; 193 return false;
202 } 194 }
203 195
204 bool isVectorIntegerType(Type Ty) { 196 bool isVectorIntegerType(Type Ty) {
205 size_t Index = static_cast<size_t>(Ty); 197 if (Ty < IceType_NUM)
206 if (Index < IceType_NUM) 198 return TypePropertiesTable[Ty].TypeIsVectorIntegerType;
207 return TypePropertiesTable[Index].TypeIsVectorIntegerType;
208 llvm_unreachable("Invalid type for isVectorIntegerType()"); 199 llvm_unreachable("Invalid type for isVectorIntegerType()");
209 return false; 200 return false;
210 } 201 }
211 202
212 bool isIntegerArithmeticType(Type Ty) { 203 bool isIntegerArithmeticType(Type Ty) {
213 size_t Index = static_cast<size_t>(Ty); 204 if (Ty < IceType_NUM)
214 if (Index < IceType_NUM) 205 return TypePropertiesTable[Ty].TypeIsIntegerArithmeticType;
215 return TypePropertiesTable[Index].TypeIsIntegerArithmeticType;
216 llvm_unreachable("Invalid type for isIntegerArithmeticType()"); 206 llvm_unreachable("Invalid type for isIntegerArithmeticType()");
217 return false; 207 return false;
218 } 208 }
219 209
220 bool isFloatingType(Type Ty) { 210 bool isFloatingType(Type Ty) {
221 size_t Index = static_cast<size_t>(Ty); 211 if (Ty < IceType_NUM)
222 if (Index < IceType_NUM) 212 return TypePropertiesTable[Ty].TypeIsFloatingType;
223 return TypePropertiesTable[Index].TypeIsFloatingType;
224 llvm_unreachable("Invalid type for isFloatingType()"); 213 llvm_unreachable("Invalid type for isFloatingType()");
225 return false; 214 return false;
226 } 215 }
227 216
228 bool isScalarFloatingType(Type Ty) { 217 bool isScalarFloatingType(Type Ty) {
229 size_t Index = static_cast<size_t>(Ty); 218 if (Ty < IceType_NUM)
230 if (Index < IceType_NUM) 219 return TypePropertiesTable[Ty].TypeIsScalarFloatingType;
231 return TypePropertiesTable[Index].TypeIsScalarFloatingType;
232 llvm_unreachable("Invalid type for isScalarFloatingType()"); 220 llvm_unreachable("Invalid type for isScalarFloatingType()");
233 return false; 221 return false;
234 } 222 }
235 223
236 bool isVectorFloatingType(Type Ty) { 224 bool isVectorFloatingType(Type Ty) {
237 size_t Index = static_cast<size_t>(Ty); 225 if (Ty < IceType_NUM)
238 if (Index < IceType_NUM) 226 return TypePropertiesTable[Ty].TypeIsVectorFloatingType;
239 return TypePropertiesTable[Index].TypeIsVectorFloatingType;
240 llvm_unreachable("Invalid type for isVectorFloatingType()"); 227 llvm_unreachable("Invalid type for isVectorFloatingType()");
241 return false; 228 return false;
242 } 229 }
243 230
244 bool isLoadStoreType(Type Ty) { 231 bool isLoadStoreType(Type Ty) {
245 size_t Index = static_cast<size_t>(Ty); 232 if (Ty < IceType_NUM)
246 if (Index < IceType_NUM) 233 return TypePropertiesTable[Ty].TypeIsLoadStoreType;
247 return TypePropertiesTable[Index].TypeIsLoadStoreType;
248 llvm_unreachable("Invalid type for isLoadStoreType()"); 234 llvm_unreachable("Invalid type for isLoadStoreType()");
249 return false; 235 return false;
250 } 236 }
251 237
252 bool isCallParameterType(Type Ty) { 238 bool isCallParameterType(Type Ty) {
253 size_t Index = static_cast<size_t>(Ty); 239 if (Ty < IceType_NUM)
254 if (Index < IceType_NUM) 240 return TypePropertiesTable[Ty].TypeIsCallParameterType;
255 return TypePropertiesTable[Index].TypeIsCallParameterType;
256 llvm_unreachable("Invalid type for isCallParameterType()"); 241 llvm_unreachable("Invalid type for isCallParameterType()");
257 return false; 242 return false;
258 } 243 }
259 244
260 Type getCompareResultType(Type Ty) { 245 Type getCompareResultType(Type Ty) {
261 size_t Index = static_cast<size_t>(Ty); 246 if (Ty < IceType_NUM)
262 if (Index < IceType_NUM) 247 return TypePropertiesTable[Ty].CompareResultType;
263 return TypePropertiesTable[Index].CompareResultType;
264 llvm_unreachable("Invalid type for getCompareResultType"); 248 llvm_unreachable("Invalid type for getCompareResultType");
265 return IceType_void; 249 return IceType_void;
266 } 250 }
267 251
268 SizeT getScalarIntBitWidth(Type Ty) { 252 SizeT getScalarIntBitWidth(Type Ty) {
269 assert(isScalarIntegerType(Ty)); 253 assert(isScalarIntegerType(Ty));
270 if (Ty == IceType_i1) 254 if (Ty == IceType_i1)
271 return 1; 255 return 1;
272 return typeWidthInBytes(Ty) * CHAR_BIT; 256 return typeWidthInBytes(Ty) * CHAR_BIT;
273 } 257 }
274 258
275 // ======================== Dump routines ======================== // 259 // ======================== Dump routines ======================== //
276 260
277 const char *typeString(Type Ty) { 261 const char *typeString(Type Ty) {
278 size_t Index = static_cast<size_t>(Ty); 262 if (Ty < IceType_NUM)
279 if (Index < IceType_NUM) 263 return TypeAttributes[Ty].DisplayString;
280 return TypeAttributes[Index].DisplayString;
281 llvm_unreachable("Invalid type for typeString"); 264 llvm_unreachable("Invalid type for typeString");
282 return "???"; 265 return "???";
283 } 266 }
284 267
285 const char *regClassString(RegClass C) { 268 const char *regClassString(RegClass C) {
286 if (static_cast<size_t>(C) < IceType_NUM) 269 if (static_cast<size_t>(C) < IceType_NUM)
287 return TypeAttributes[C].RegClassString; 270 return TypeAttributes[C].RegClassString;
288 llvm_unreachable("Invalid type for regClassString"); 271 llvm_unreachable("Invalid type for regClassString");
289 return "???"; 272 return "???";
290 } 273 }
291 274
292 void FuncSigType::dump(Ostream &Stream) const { 275 void FuncSigType::dump(Ostream &Stream) const {
293 if (!BuildDefs::dump()) 276 if (!BuildDefs::dump())
294 return; 277 return;
295 Stream << ReturnType << " ("; 278 Stream << ReturnType << " (";
296 bool IsFirst = true; 279 bool IsFirst = true;
297 for (const Type ArgTy : ArgList) { 280 for (const Type ArgTy : ArgList) {
298 if (IsFirst) { 281 if (IsFirst) {
299 IsFirst = false; 282 IsFirst = false;
300 } else { 283 } else {
301 Stream << ", "; 284 Stream << ", ";
302 } 285 }
303 Stream << ArgTy; 286 Stream << ArgTy;
304 } 287 }
305 Stream << ")"; 288 Stream << ")";
306 } 289 }
307 290
308 } // end of namespace Ice 291 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX86BaseImpl.h ('k') | src/PNaClTranslator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698