Chromium Code Reviews| Index: src/IceGlobalContext.cpp |
| diff --git a/src/IceGlobalContext.cpp b/src/IceGlobalContext.cpp |
| index 6badc559aa9236b017ad9ad262d216812c0e25d4..5638937aa0a7cee00c21b23f9fc1c08554cc860f 100644 |
| --- a/src/IceGlobalContext.cpp |
| +++ b/src/IceGlobalContext.cpp |
| @@ -40,6 +40,30 @@ template <> struct hash<Ice::RelocatableTuple> { |
| namespace Ice { |
| +namespace { |
| + |
| +// Define the key comparison function for the constant pool's |
| +// unordered_map, but only for key types of interest: integer types, |
| +// floating point types, and the special RelocatableTuple. |
| +template <typename KeyType, class Enable = void> struct KeyCompare {}; |
| + |
| +template <typename KeyType> |
| +struct KeyCompare<KeyType, |
| + typename std::enable_if< |
| + std::is_integral<KeyType>::value || |
| + std::is_same<KeyType, RelocatableTuple>::value>::type> { |
| + bool operator()(const KeyType &Value1, const KeyType &Value2) const { |
| + return Value1 == Value2; |
| + } |
| +}; |
| +template <typename KeyType> |
| +struct KeyCompare<KeyType, typename std::enable_if< |
| + std::is_floating_point<KeyType>::value>::type> { |
| + bool operator()(const KeyType &Value1, const KeyType &Value2) const { |
| + return !memcmp(&Value1, &Value2, sizeof(KeyType)); |
| + } |
| +}; |
| + |
| // TypePool maps constants of type KeyType (e.g. float) to pointers to |
| // type ValueType (e.g. ConstantFloat). |
| template <Type Ty, typename KeyType, typename ValueType> class TypePool { |
| @@ -65,7 +89,8 @@ public: |
| } |
| private: |
| - typedef std::unordered_map<KeyType, ValueType *> ContainerType; |
| + typedef std::unordered_map<KeyType, ValueType *, std::hash<KeyType>, |
| + KeyCompare<KeyType>> ContainerType; |
|
JF
2015/03/19 20:33:12
Comment on why using std::hash is OK here but the
Jim Stichnoth
2015/03/20 05:29:48
Done.
|
| ContainerType Pool; |
| uint32_t NextPoolID; |
| }; |
| @@ -89,6 +114,8 @@ private: |
| std::vector<ConstantUndef *> Pool; |
| }; |
| +} // end of anonymous namespace |
| + |
| // The global constant pool bundles individual pools of each type of |
| // interest. |
| class ConstantPool { |