diff options
author | 2018-05-01 18:46:31 -0700 | |
---|---|---|
committer | 2018-05-01 18:49:56 -0700 | |
commit | 69b2c639f55b065a5dbf829351034441bebc8437 (patch) | |
tree | 89869d4af178dba875557e4280ece30a642bf20b /tensorflow/core/lib/hash | |
parent | c8ae9e86f33053484b05e405dadd2c8a98b8b41b (diff) |
[XLA:CPU] Re-use the same llvm::GlobalVariable for identical literals
This isn't necessary today, but it will be after an optimization change I'm
about to make.
LLVM has a constant merging pass too, but one of the motivations here is to
avoid the LLVM compile time overhead of having many large arrays in the IR.
PiperOrigin-RevId: 195032900
Diffstat (limited to 'tensorflow/core/lib/hash')
-rw-r--r-- | tensorflow/core/lib/hash/hash.h | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tensorflow/core/lib/hash/hash.h b/tensorflow/core/lib/hash/hash.h index ca05e6346e..3f85303c0f 100644 --- a/tensorflow/core/lib/hash/hash.h +++ b/tensorflow/core/lib/hash/hash.h @@ -21,6 +21,7 @@ limitations under the License. #include <stddef.h> #include <stdint.h> +#include <functional> #include <string> #include "tensorflow/core/lib/core/stringpiece.h" @@ -49,12 +50,28 @@ inline uint64 Hash64Combine(uint64 a, uint64 b) { // In particular, tensorflow::hash is not the identity function for pointers. // This is important for power-of-two sized hashtables like FlatMap and FlatSet, // because otherwise they waste the majority of their hash buckets. -template <typename T> +// +// The second type argument is only used for SFNIAE below. +template <typename T, typename = void> struct hash { size_t operator()(const T& t) const { return std::hash<T>()(t); } }; template <typename T> +struct hash<T, typename std::enable_if<std::is_enum<T>::value>::type> { + size_t operator()(T value) const { + // This works around a defect in the std::hash C++ spec that isn't fixed in + // (at least) gcc 4.8.4: + // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2148 + // + // We should be able to remove this and use the default + // tensorflow::hash<EnumTy>() once we stop building with GCC versions old + // enough to not have this defect fixed. + return std::hash<uint64>()(static_cast<uint64>(value)); + } +}; + +template <typename T> struct hash<T*> { size_t operator()(const T* t) const { // Hash pointers as integers, but bring more entropy to the lower bits. |