From 9393eb354ff7cc08a8cc0a4ec6ed5c55b100abf5 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 15 Apr 2014 07:08:40 +0000 Subject: [PATCH] Add a DenseMapInfo specialization for PointerUnion. In tree user to land shortly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206253 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/PointerUnion.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/llvm/ADT/PointerUnion.h b/include/llvm/ADT/PointerUnion.h index 8cbe8d1df75..dafd0e05109 100644 --- a/include/llvm/ADT/PointerUnion.h +++ b/include/llvm/ADT/PointerUnion.h @@ -15,6 +15,7 @@ #ifndef LLVM_ADT_POINTERUNION_H #define LLVM_ADT_POINTERUNION_H +#include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/Support/Compiler.h" @@ -455,6 +456,33 @@ namespace llvm { ::NumLowBitsAvailable }; }; + + // Teach DenseMap how to use PointerUnions as keys. + template + struct DenseMapInfo > { + typedef PointerUnion Pair; + typedef DenseMapInfo FirstInfo; + typedef DenseMapInfo SecondInfo; + + static inline Pair getEmptyKey() { + return Pair(FirstInfo::getEmptyKey()); + } + static inline Pair getTombstoneKey() { + return Pair(FirstInfo::getTombstoneKey()); + } + static unsigned getHashValue(const Pair &PairVal) { + intptr_t key = (intptr_t)PairVal.getOpaqueValue(); + return DenseMapInfo::getHashValue(key); + } + static bool isEqual(const Pair &LHS, const Pair &RHS) { + return LHS.template is() == RHS.template is() && + (LHS.template is() ? + FirstInfo::isEqual(LHS.template get(), + RHS.template get()) : + SecondInfo::isEqual(LHS.template get(), + RHS.template get())); + } + }; } #endif