Chromium Code Reviews| Index: src/IceTypes.cpp |
| diff --git a/src/IceTypes.cpp b/src/IceTypes.cpp |
| index 515be2d667aee80b3d70d6e295704958bec07961..dd374feee46d697ad41a29ccec42d5180d89a92d 100644 |
| --- a/src/IceTypes.cpp |
| +++ b/src/IceTypes.cpp |
| @@ -14,10 +14,66 @@ |
| #include "IceDefs.h" |
| #include "IceTypes.h" |
| +#include "llvm/ADT/STLExtras.h" |
| + |
| namespace Ice { |
| namespace { |
| +// Dummy function to make sure the two type tables have the same |
| +// enumerated types. |
| +void xIceTypeMacroIntegrityCheck() { |
| + |
| + // Show tags match between ICETYPE_TABLE and ICETYPE_PROPS_TABLE. |
| + |
| + // Define a temporary set of enum values based on ICETYPE_TABLE |
| + enum { |
| +#define X(tag, size, align, elts, elty, str) _table_tag_##tag, |
| + ICETYPE_TABLE |
| +#undef X |
| + _enum_table_tag_Names |
| + }; |
| + // Define a temporary set of enum values based on ICETYPE_PROPS_TABLE |
| + enum { |
| +#define X(tag, IsVec, IsInt, IsFloat) _props_table_tag_##tag, |
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| + _enum_props_table_tag_Names |
| + }; |
| +// Assert that tags in ICETYPE_TABLE are also in ICETYPE_PROPS_TABLE. |
| +#define X(tag, size, align, elts, elty, str) \ |
| + STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); |
| + ICETYPE_TABLE; |
| +#undef X |
| +// Assert that tags in ICETYPE_PROPS_TABLE is in ICETYPE_TABLE. |
| +#define X(tag, IsVec, IsInt, IsFloat) \ |
| + STATIC_ASSERT((unsigned)_table_tag_##tag == (unsigned)_props_table_tag_##tag); |
| + ICETYPE_PROPS_TABLE; |
| +#undef X |
| + |
| + // Show vector definitions match in ICETYPE_TABLE and |
| + // ICETYPE_PROPS_TABLE. |
| + |
| + // Define constants for each element size in ICETYPE_TABLE. |
| + enum { |
| +#define X(tag, size, align, elts, elty, str) _table_elts_##tag = elts, |
| + ICETYPE_TABLE |
| +#undef X |
| + _enum_table_elts_Elements = 0 |
| + }; |
| + // Define constants for boolean flag if vector in ICETYPE_PROPS_TABLE. |
| + enum { |
| +#define X(tag, IsVec, IsInt, IsFloat) _props_table_IsVec_##tag = IsVec, |
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| + }; |
| +// 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.
|
| +#define X(tag, IsVec, IsInt, IsFloat) \ |
| + STATIC_ASSERT((_table_elts_##tag > 1) == _props_table_IsVec_##tag); |
| + ICETYPE_PROPS_TABLE; |
| +#undef X |
| +} |
| + |
| const struct { |
| size_t TypeWidthInBytes; |
| size_t TypeAlignInBytes; |
| @@ -81,9 +137,94 @@ Type typeElementType(Type Ty) { |
| return ElementType; |
| } |
| +namespace { |
| + |
| +static const bool IsVectorTable[] = { |
| +#define X(tag, IsVec, IsInt, IsFloat) IsVec, |
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| +}; |
| + |
| +} // end anonymous namespace |
| + |
| +bool isVectorType(Type Ty) { |
| + size_t Index = static_cast<size_t>(Ty); |
| + if (Index < llvm::array_lengthof(IsVectorTable)) |
| + return IsVectorTable[Index]; |
| + llvm_unreachable("Invalid type for isVectorType()"); |
| +} |
| + |
| +namespace { |
| + |
| +static const bool IsScalarIntegerTable[] = { |
| +#define X(tag, IsVec, IsInt, IsFloat) IsInt && !IsVec, |
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| +}; |
| + |
| +} // 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.
|
| + |
| +bool isScalarIntegerType(Type Ty) { |
| + size_t Index = static_cast<size_t>(Ty); |
| + if (Index < llvm::array_lengthof(IsScalarIntegerTable)) |
| + return IsScalarIntegerTable[Index]; |
| + llvm_unreachable("Invalid type for isScalIntegerType()"); |
| +} |
| + |
| +namespace { |
| + |
| +static const bool IsVectorIntegerTable[] = { |
| +#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.
|
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| +}; |
| + |
| +} // end anonymous namespace |
| + |
| +bool isVectorIntegerType(Type Ty) { |
| + size_t Index = static_cast<size_t>(Ty); |
| + if (Index < llvm::array_lengthof(IsVectorIntegerTable)) |
| + return IsVectorIntegerTable[Index]; |
| + llvm_unreachable("Invalid type for IsVectorIntegerType()"); |
| +} |
| + |
| +namespace { |
| + |
| +static const bool IsScalarFloatingTable[] = { |
| +#define X(tag, IsVec, IsInt, IsFloat) IsFloat && !IsVec, |
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| +}; |
| + |
| +} // end anonymous namespace |
| + |
| +bool isScalarFloatingType(Type Ty) { |
| + size_t Index = static_cast<size_t>(Ty); |
| + if (Index < llvm::array_lengthof(IsScalarFloatingTable)) |
| + return IsScalarFloatingTable[Index]; |
| + llvm_unreachable("Invalid type for IsScalarFloatingType()"); |
| +} |
| + |
| +namespace { |
| + |
| +static const bool IsVectorFloatingTable[] = { |
| +#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.
|
| + ICETYPE_PROPS_TABLE |
| +#undef X |
| +}; |
| + |
| +} // end anonymous namespace |
| + |
| +bool isVectorFloatingType(Type Ty) { |
| + size_t Index = static_cast<size_t>(Ty); |
| + if (Index < llvm::array_lengthof(IsVectorFloatingTable)) |
| + return IsVectorFloatingTable[Index]; |
| + llvm_unreachable("Invalid type for IsVectorFloatingType()"); |
| +} |
| + |
| // ======================== Dump routines ======================== // |
| -template <> Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| +Ostream &operator<<(Ostream &Str, const Type &Ty) { |
| size_t Index = static_cast<size_t>(Ty); |
| if (Index < TypeAttributesSize) { |
| Str << TypeAttributes[Index].DisplayString; |