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 namespace Ice { | 17 namespace Ice { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const struct { | 21 const struct { |
| 22 size_t TypeWidthInBytes; | 22 size_t TypeWidthInBytes; |
| 23 size_t TypeAlignInBytes; | 23 size_t TypeAlignInBytes; |
| 24 size_t TypeNumElements; | 24 size_t TypeNumElements; |
| 25 Type TypeElementType; | 25 Type TypeElementType; |
| 26 const char *DisplayString; | 26 const char *DisplayString; |
| 27 uint32_t TypeFlags; | |
| 27 } TypeAttributes[] = { | 28 } TypeAttributes[] = { |
| 28 #define X(tag, size, align, elts, elty, str) \ | 29 #define X(tag, size, align, elts, elty, str, flags) \ |
| 29 { size, align, elts, elty, str } \ | 30 { size, align, elts, elty, str, flags } \ |
| 30 , | 31 , |
| 31 ICETYPE_TABLE | 32 ICETYPE_TABLE |
| 32 #undef X | 33 #undef X |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 const size_t TypeAttributesSize = | 36 const size_t TypeAttributesSize = |
| 36 sizeof(TypeAttributes) / sizeof(*TypeAttributes); | 37 sizeof(TypeAttributes) / sizeof(*TypeAttributes); |
| 37 | 38 |
| 38 } // end anonymous namespace | 39 } // end anonymous namespace |
| 39 | 40 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 Type ElementType = IceType_void; | 75 Type ElementType = IceType_void; |
| 75 size_t Index = static_cast<size_t>(Ty); | 76 size_t Index = static_cast<size_t>(Ty); |
| 76 if (Index < TypeAttributesSize) { | 77 if (Index < TypeAttributesSize) { |
| 77 ElementType = TypeAttributes[Index].TypeElementType; | 78 ElementType = TypeAttributes[Index].TypeElementType; |
| 78 } else { | 79 } else { |
| 79 llvm_unreachable("Invalid type for typeElementType()"); | 80 llvm_unreachable("Invalid type for typeElementType()"); |
| 80 } | 81 } |
| 81 return ElementType; | 82 return ElementType; |
| 82 } | 83 } |
| 83 | 84 |
| 85 bool isIntegerType(Type Ty) { | |
| 86 bool IsInteger = false; | |
| 87 size_t Index = static_cast<size_t>(Ty); | |
| 88 if (Index < TypeAttributesSize) { | |
| 89 IsInteger = | |
| 90 static_cast<bool>(TypeAttributes[Index].TypeFlags & TypeFlagIsInteger); | |
|
jvoung (off chromium)
2014/07/23 16:10:17
Does this need to be a bitset (w/ Flag & Bit), or
Karl
2014/07/23 20:22:20
I would actually like to convert checks like "isVa
| |
| 91 } else { | |
| 92 llvm_unreachable("Invalid type for typeIsInteger()"); | |
| 93 } | |
| 94 return IsInteger; | |
| 95 } | |
| 96 | |
| 97 bool isFloatingType(Type Ty) { | |
| 98 bool IsFloating = false; | |
| 99 size_t Index = static_cast<size_t>(Ty); | |
| 100 if (Index < TypeAttributesSize) { | |
| 101 IsFloating = | |
| 102 static_cast<bool>(TypeAttributes[Index].TypeFlags & TypeFlagIsFloating); | |
| 103 } else { | |
| 104 llvm_unreachable("Invalid type for typeIsFloating()"); | |
| 105 } | |
| 106 return IsFloating; | |
| 107 } | |
| 108 | |
| 84 // ======================== Dump routines ======================== // | 109 // ======================== Dump routines ======================== // |
| 85 | 110 |
| 86 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { | 111 template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| 87 size_t Index = static_cast<size_t>(Ty); | 112 size_t Index = static_cast<size_t>(Ty); |
| 88 if (Index < TypeAttributesSize) { | 113 if (Index < TypeAttributesSize) { |
| 89 Str << TypeAttributes[Index].DisplayString; | 114 Str << TypeAttributes[Index].DisplayString; |
| 90 } else { | 115 } else { |
| 91 Str << "???"; | 116 Str << "???"; |
| 92 llvm_unreachable("Invalid type for printing"); | 117 llvm_unreachable("Invalid type for printing"); |
| 93 } | 118 } |
| 94 | 119 |
| 95 return Str; | 120 return Str; |
| 96 } | 121 } |
| 97 | 122 |
| 98 } // end of namespace Ice | 123 } // end of namespace Ice |
| OLD | NEW |