Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 1 | //===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file declares LLVMContextImpl, the opaque implementation |
| 11 | // of LLVMContext. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 14 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H |
| 16 | #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 17 | |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 18 | #include "AttributeImpl.h" |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 19 | #include "ConstantsContext.h" |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/APFloat.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/APInt.h" |
Jay Foad | c365eea | 2011-06-22 08:50:06 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/ArrayRef.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/DenseMap.h" |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/DenseSet.h" |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/FoldingSet.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Hashing.h" |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/SmallPtrSet.h" |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/StringMap.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 29 | #include "llvm/IR/Constants.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 30 | #include "llvm/IR/DebugInfoMetadata.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 31 | #include "llvm/IR/DerivedTypes.h" |
| 32 | #include "llvm/IR/LLVMContext.h" |
| 33 | #include "llvm/IR/Metadata.h" |
Chandler Carruth | 4220e9c | 2014-03-04 11:17:44 +0000 | [diff] [blame] | 34 | #include "llvm/IR/ValueHandle.h" |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 35 | #include "llvm/Support/Dwarf.h" |
Duncan P. N. Exon Smith | 3eef9d1 | 2016-04-19 23:59:13 +0000 | [diff] [blame] | 36 | #include <vector> |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 37 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 38 | namespace llvm { |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 39 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 40 | class ConstantInt; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 41 | class ConstantFP; |
Diego Novillo | 7f8af8b | 2014-05-22 14:19:46 +0000 | [diff] [blame] | 42 | class DiagnosticInfoOptimizationRemark; |
| 43 | class DiagnosticInfoOptimizationRemarkMissed; |
| 44 | class DiagnosticInfoOptimizationRemarkAnalysis; |
Philip Reames | 2b45395 | 2015-01-16 20:07:33 +0000 | [diff] [blame] | 45 | class GCStrategy; |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 46 | class LLVMContext; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 47 | class Type; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 48 | class Value; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 49 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 50 | struct DenseMapAPIntKeyInfo { |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 51 | static inline APInt getEmptyKey() { |
| 52 | APInt V(nullptr, 0); |
| 53 | V.VAL = 0; |
| 54 | return V; |
| 55 | } |
| 56 | static inline APInt getTombstoneKey() { |
| 57 | APInt V(nullptr, 0); |
| 58 | V.VAL = 1; |
| 59 | return V; |
| 60 | } |
| 61 | static unsigned getHashValue(const APInt &Key) { |
Chandler Carruth | 71bd7d1 | 2012-03-04 12:02:57 +0000 | [diff] [blame] | 62 | return static_cast<unsigned>(hash_value(Key)); |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 63 | } |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 64 | static bool isEqual(const APInt &LHS, const APInt &RHS) { |
| 65 | return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; |
| 66 | } |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 69 | struct DenseMapAPFloatKeyInfo { |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 70 | static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); } |
| 71 | static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); } |
| 72 | static unsigned getHashValue(const APFloat &Key) { |
Chandler Carruth | 71bd7d1 | 2012-03-04 12:02:57 +0000 | [diff] [blame] | 73 | return static_cast<unsigned>(hash_value(Key)); |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 74 | } |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 75 | static bool isEqual(const APFloat &LHS, const APFloat &RHS) { |
| 76 | return LHS.bitwiseIsEqual(RHS); |
| 77 | } |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 80 | struct AnonStructTypeKeyInfo { |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 81 | struct KeyTy { |
| 82 | ArrayRef<Type*> ETypes; |
| 83 | bool isPacked; |
| 84 | KeyTy(const ArrayRef<Type*>& E, bool P) : |
| 85 | ETypes(E), isPacked(P) {} |
Rafael Espindola | 334b73f | 2014-11-21 18:53:05 +0000 | [diff] [blame] | 86 | KeyTy(const StructType *ST) |
| 87 | : ETypes(ST->elements()), isPacked(ST->isPacked()) {} |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 88 | bool operator==(const KeyTy& that) const { |
| 89 | if (isPacked != that.isPacked) |
| 90 | return false; |
| 91 | if (ETypes != that.ETypes) |
| 92 | return false; |
| 93 | return true; |
| 94 | } |
| 95 | bool operator!=(const KeyTy& that) const { |
| 96 | return !this->operator==(that); |
| 97 | } |
| 98 | }; |
| 99 | static inline StructType* getEmptyKey() { |
| 100 | return DenseMapInfo<StructType*>::getEmptyKey(); |
| 101 | } |
| 102 | static inline StructType* getTombstoneKey() { |
| 103 | return DenseMapInfo<StructType*>::getTombstoneKey(); |
| 104 | } |
| 105 | static unsigned getHashValue(const KeyTy& Key) { |
Chandler Carruth | 1d03a3b | 2012-03-01 18:55:25 +0000 | [diff] [blame] | 106 | return hash_combine(hash_combine_range(Key.ETypes.begin(), |
| 107 | Key.ETypes.end()), |
| 108 | Key.isPacked); |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 109 | } |
| 110 | static unsigned getHashValue(const StructType *ST) { |
| 111 | return getHashValue(KeyTy(ST)); |
| 112 | } |
| 113 | static bool isEqual(const KeyTy& LHS, const StructType *RHS) { |
| 114 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 115 | return false; |
| 116 | return LHS == KeyTy(RHS); |
| 117 | } |
| 118 | static bool isEqual(const StructType *LHS, const StructType *RHS) { |
| 119 | return LHS == RHS; |
| 120 | } |
| 121 | }; |
| 122 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 123 | struct FunctionTypeKeyInfo { |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 124 | struct KeyTy { |
| 125 | const Type *ReturnType; |
| 126 | ArrayRef<Type*> Params; |
| 127 | bool isVarArg; |
| 128 | KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) : |
| 129 | ReturnType(R), Params(P), isVarArg(V) {} |
Rafael Espindola | e973fd4 | 2014-11-21 19:03:35 +0000 | [diff] [blame] | 130 | KeyTy(const FunctionType *FT) |
| 131 | : ReturnType(FT->getReturnType()), Params(FT->params()), |
| 132 | isVarArg(FT->isVarArg()) {} |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 133 | bool operator==(const KeyTy& that) const { |
| 134 | if (ReturnType != that.ReturnType) |
| 135 | return false; |
| 136 | if (isVarArg != that.isVarArg) |
| 137 | return false; |
| 138 | if (Params != that.Params) |
| 139 | return false; |
| 140 | return true; |
| 141 | } |
| 142 | bool operator!=(const KeyTy& that) const { |
| 143 | return !this->operator==(that); |
| 144 | } |
| 145 | }; |
| 146 | static inline FunctionType* getEmptyKey() { |
| 147 | return DenseMapInfo<FunctionType*>::getEmptyKey(); |
| 148 | } |
| 149 | static inline FunctionType* getTombstoneKey() { |
| 150 | return DenseMapInfo<FunctionType*>::getTombstoneKey(); |
| 151 | } |
| 152 | static unsigned getHashValue(const KeyTy& Key) { |
Chandler Carruth | 1d03a3b | 2012-03-01 18:55:25 +0000 | [diff] [blame] | 153 | return hash_combine(Key.ReturnType, |
| 154 | hash_combine_range(Key.Params.begin(), |
| 155 | Key.Params.end()), |
| 156 | Key.isVarArg); |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 157 | } |
| 158 | static unsigned getHashValue(const FunctionType *FT) { |
| 159 | return getHashValue(KeyTy(FT)); |
| 160 | } |
| 161 | static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { |
| 162 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 163 | return false; |
| 164 | return LHS == KeyTy(RHS); |
| 165 | } |
| 166 | static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { |
| 167 | return LHS == RHS; |
| 168 | } |
| 169 | }; |
| 170 | |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 171 | /// \brief Structure for hashing arbitrary MDNode operands. |
| 172 | class MDNodeOpsKey { |
| 173 | ArrayRef<Metadata *> RawOps; |
| 174 | ArrayRef<MDOperand> Ops; |
| 175 | |
| 176 | unsigned Hash; |
| 177 | |
| 178 | protected: |
| 179 | MDNodeOpsKey(ArrayRef<Metadata *> Ops) |
| 180 | : RawOps(Ops), Hash(calculateHash(Ops)) {} |
| 181 | |
| 182 | template <class NodeTy> |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 183 | MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 184 | : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {} |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 185 | |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 186 | template <class NodeTy> |
| 187 | bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const { |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 188 | if (getHash() != RHS->getHash()) |
| 189 | return false; |
| 190 | |
| 191 | assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?"); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 192 | return RawOps.empty() ? compareOps(Ops, RHS, Offset) |
| 193 | : compareOps(RawOps, RHS, Offset); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 196 | static unsigned calculateHash(MDNode *N, unsigned Offset = 0); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 197 | |
| 198 | private: |
| 199 | template <class T> |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 200 | static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) { |
| 201 | if (Ops.size() != RHS->getNumOperands() - Offset) |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 202 | return false; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 203 | return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static unsigned calculateHash(ArrayRef<Metadata *> Ops); |
| 207 | |
| 208 | public: |
| 209 | unsigned getHash() const { return Hash; } |
| 210 | }; |
| 211 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 212 | template <class NodeTy> struct MDNodeKeyImpl; |
| 213 | template <class NodeTy> struct MDNodeInfo; |
| 214 | |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 215 | /// Configuration point for MDNodeInfo::isEqual(). |
| 216 | template <class NodeTy> struct MDNodeSubsetEqualImpl { |
| 217 | typedef MDNodeKeyImpl<NodeTy> KeyTy; |
| 218 | static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) { |
| 219 | return false; |
| 220 | } |
| 221 | static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) { |
| 222 | return false; |
| 223 | } |
| 224 | }; |
| 225 | |
Duncan P. N. Exon Smith | 118632d | 2015-01-12 20:09:34 +0000 | [diff] [blame] | 226 | /// \brief DenseMapInfo for MDTuple. |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 227 | /// |
| 228 | /// Note that we don't need the is-function-local bit, since that's implicit in |
| 229 | /// the operands. |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 230 | template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey { |
| 231 | MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {} |
| 232 | MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 233 | |
Duncan P. N. Exon Smith | 9c26d80 | 2015-02-05 00:51:35 +0000 | [diff] [blame] | 234 | bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); } |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 235 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 236 | unsigned getHashValue() const { return getHash(); } |
| 237 | |
| 238 | static unsigned calculateHash(MDTuple *N) { |
| 239 | return MDNodeOpsKey::calculateHash(N); |
Benjamin Kramer | 2335a5c | 2012-04-11 14:06:54 +0000 | [diff] [blame] | 240 | } |
| 241 | }; |
| 242 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 243 | /// \brief DenseMapInfo for DILocation. |
| 244 | template <> struct MDNodeKeyImpl<DILocation> { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 245 | unsigned Line; |
| 246 | unsigned Column; |
| 247 | Metadata *Scope; |
| 248 | Metadata *InlinedAt; |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 249 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 250 | MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, |
| 251 | Metadata *InlinedAt) |
| 252 | : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 253 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 254 | MDNodeKeyImpl(const DILocation *L) |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 255 | : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), |
| 256 | InlinedAt(L->getRawInlinedAt()) {} |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 257 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 258 | bool isKeyOf(const DILocation *RHS) const { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 259 | return Line == RHS->getLine() && Column == RHS->getColumn() && |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 260 | Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt(); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 261 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 262 | unsigned getHashValue() const { |
| 263 | return hash_combine(Line, Column, Scope, InlinedAt); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 264 | } |
| 265 | }; |
| 266 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 267 | /// \brief DenseMapInfo for GenericDINode. |
| 268 | template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 269 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 270 | MDString *Header; |
| 271 | MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 272 | : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 273 | MDNodeKeyImpl(const GenericDINode *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 274 | : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {} |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 275 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 276 | bool isKeyOf(const GenericDINode *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 277 | return Tag == RHS->getTag() && Header == RHS->getRawHeader() && |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 278 | compareOps(RHS, 1); |
| 279 | } |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 280 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 281 | unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); } |
| 282 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 283 | static unsigned calculateHash(GenericDINode *N) { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 284 | return MDNodeOpsKey::calculateHash(N, 1); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 285 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 288 | template <> struct MDNodeKeyImpl<DISubrange> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 289 | int64_t Count; |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 290 | int64_t LowerBound; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 291 | |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 292 | MDNodeKeyImpl(int64_t Count, int64_t LowerBound) |
| 293 | : Count(Count), LowerBound(LowerBound) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 294 | MDNodeKeyImpl(const DISubrange *N) |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 295 | : Count(N->getCount()), LowerBound(N->getLowerBound()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 296 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 297 | bool isKeyOf(const DISubrange *RHS) const { |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 298 | return Count == RHS->getCount() && LowerBound == RHS->getLowerBound(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 299 | } |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 300 | unsigned getHashValue() const { return hash_combine(Count, LowerBound); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 301 | }; |
| 302 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 303 | template <> struct MDNodeKeyImpl<DIEnumerator> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 304 | int64_t Value; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 305 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 306 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 307 | MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 308 | MDNodeKeyImpl(const DIEnumerator *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 309 | : Value(N->getValue()), Name(N->getRawName()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 310 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 311 | bool isKeyOf(const DIEnumerator *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 312 | return Value == RHS->getValue() && Name == RHS->getRawName(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 313 | } |
| 314 | unsigned getHashValue() const { return hash_combine(Value, Name); } |
| 315 | }; |
| 316 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 317 | template <> struct MDNodeKeyImpl<DIBasicType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 318 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 319 | MDString *Name; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 320 | uint64_t SizeInBits; |
| 321 | uint64_t AlignInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 322 | unsigned Encoding; |
| 323 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 324 | MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 325 | uint64_t AlignInBits, unsigned Encoding) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 326 | : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), |
| 327 | Encoding(Encoding) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 328 | MDNodeKeyImpl(const DIBasicType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 329 | : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 330 | AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {} |
| 331 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 332 | bool isKeyOf(const DIBasicType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 333 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 334 | SizeInBits == RHS->getSizeInBits() && |
| 335 | AlignInBits == RHS->getAlignInBits() && |
| 336 | Encoding == RHS->getEncoding(); |
| 337 | } |
| 338 | unsigned getHashValue() const { |
| 339 | return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding); |
| 340 | } |
| 341 | }; |
| 342 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 343 | template <> struct MDNodeKeyImpl<DIDerivedType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 344 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 345 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 346 | Metadata *File; |
| 347 | unsigned Line; |
| 348 | Metadata *Scope; |
| 349 | Metadata *BaseType; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 350 | uint64_t SizeInBits; |
| 351 | uint64_t AlignInBits; |
| 352 | uint64_t OffsetInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 353 | unsigned Flags; |
| 354 | Metadata *ExtraData; |
| 355 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 356 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 357 | Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
| 358 | uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 359 | Metadata *ExtraData) |
| 360 | : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), |
| 361 | BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits), |
| 362 | OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 363 | MDNodeKeyImpl(const DIDerivedType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 364 | : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 365 | Line(N->getLine()), Scope(N->getRawScope()), |
| 366 | BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), |
| 367 | AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()), |
| 368 | Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 369 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 370 | bool isKeyOf(const DIDerivedType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 371 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 372 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 373 | Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 374 | SizeInBits == RHS->getSizeInBits() && |
| 375 | AlignInBits == RHS->getAlignInBits() && |
| 376 | OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 377 | ExtraData == RHS->getRawExtraData(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 378 | } |
| 379 | unsigned getHashValue() const { |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 380 | // If this is a member inside an ODR type, only hash the type and the name. |
| 381 | // Otherwise the hash will be stronger than |
| 382 | // MDNodeSubsetEqualImpl::isODRMember(). |
| 383 | if (Tag == dwarf::DW_TAG_member && Name && Scope && isa<MDString>(Scope)) |
| 384 | return hash_combine(Name, Scope); |
| 385 | |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 386 | // Intentionally computes the hash on a subset of the operands for |
| 387 | // performance reason. The subset has to be significant enough to avoid |
| 388 | // collision "most of the time". There is no correctness issue in case of |
| 389 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 390 | return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 391 | } |
| 392 | }; |
| 393 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 394 | template <> struct MDNodeSubsetEqualImpl<DIDerivedType> { |
| 395 | typedef MDNodeKeyImpl<DIDerivedType> KeyTy; |
| 396 | static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) { |
| 397 | return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS); |
| 398 | } |
| 399 | static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) { |
| 400 | return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(), |
| 401 | RHS); |
| 402 | } |
| 403 | |
| 404 | /// Subprograms compare equal if they declare the same function in an ODR |
| 405 | /// type. |
| 406 | static bool isODRMember(unsigned Tag, const Metadata *Scope, |
| 407 | const MDString *Name, const DIDerivedType *RHS) { |
| 408 | // Check whether the LHS is eligible. |
| 409 | if (Tag != dwarf::DW_TAG_member || !Name || !Scope || !isa<MDString>(Scope)) |
| 410 | return false; |
| 411 | |
| 412 | // Compare to the RHS. |
| 413 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
| 414 | Scope == RHS->getRawScope(); |
| 415 | } |
| 416 | }; |
| 417 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 418 | template <> struct MDNodeKeyImpl<DICompositeType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 419 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 420 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 421 | Metadata *File; |
| 422 | unsigned Line; |
| 423 | Metadata *Scope; |
| 424 | Metadata *BaseType; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 425 | uint64_t SizeInBits; |
| 426 | uint64_t AlignInBits; |
| 427 | uint64_t OffsetInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 428 | unsigned Flags; |
| 429 | Metadata *Elements; |
| 430 | unsigned RuntimeLang; |
| 431 | Metadata *VTableHolder; |
| 432 | Metadata *TemplateParams; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 433 | MDString *Identifier; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 434 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 435 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 436 | Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
| 437 | uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 438 | Metadata *Elements, unsigned RuntimeLang, |
| 439 | Metadata *VTableHolder, Metadata *TemplateParams, |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 440 | MDString *Identifier) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 441 | : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), |
| 442 | BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits), |
| 443 | OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements), |
| 444 | RuntimeLang(RuntimeLang), VTableHolder(VTableHolder), |
| 445 | TemplateParams(TemplateParams), Identifier(Identifier) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 446 | MDNodeKeyImpl(const DICompositeType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 447 | : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 448 | Line(N->getLine()), Scope(N->getRawScope()), |
| 449 | BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), |
| 450 | AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()), |
| 451 | Flags(N->getFlags()), Elements(N->getRawElements()), |
| 452 | RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()), |
| 453 | TemplateParams(N->getRawTemplateParams()), |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 454 | Identifier(N->getRawIdentifier()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 455 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 456 | bool isKeyOf(const DICompositeType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 457 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 458 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 459 | Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 460 | SizeInBits == RHS->getSizeInBits() && |
| 461 | AlignInBits == RHS->getAlignInBits() && |
| 462 | OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 463 | Elements == RHS->getRawElements() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 464 | RuntimeLang == RHS->getRuntimeLang() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 465 | VTableHolder == RHS->getRawVTableHolder() && |
| 466 | TemplateParams == RHS->getRawTemplateParams() && |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 467 | Identifier == RHS->getRawIdentifier(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 468 | } |
| 469 | unsigned getHashValue() const { |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 470 | // Intentionally computes the hash on a subset of the operands for |
| 471 | // performance reason. The subset has to be significant enough to avoid |
| 472 | // collision "most of the time". There is no correctness issue in case of |
| 473 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 474 | return hash_combine(Name, File, Line, BaseType, Scope, Elements, |
| 475 | TemplateParams); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 476 | } |
| 477 | }; |
| 478 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 479 | template <> struct MDNodeKeyImpl<DISubroutineType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 480 | unsigned Flags; |
| 481 | Metadata *TypeArray; |
| 482 | |
| 483 | MDNodeKeyImpl(int64_t Flags, Metadata *TypeArray) |
| 484 | : Flags(Flags), TypeArray(TypeArray) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 485 | MDNodeKeyImpl(const DISubroutineType *N) |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 486 | : Flags(N->getFlags()), TypeArray(N->getRawTypeArray()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 487 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 488 | bool isKeyOf(const DISubroutineType *RHS) const { |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 489 | return Flags == RHS->getFlags() && TypeArray == RHS->getRawTypeArray(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 490 | } |
| 491 | unsigned getHashValue() const { return hash_combine(Flags, TypeArray); } |
| 492 | }; |
| 493 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 494 | template <> struct MDNodeKeyImpl<DIFile> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 495 | MDString *Filename; |
| 496 | MDString *Directory; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 497 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 498 | MDNodeKeyImpl(MDString *Filename, MDString *Directory) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 499 | : Filename(Filename), Directory(Directory) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 500 | MDNodeKeyImpl(const DIFile *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 501 | : Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 502 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 503 | bool isKeyOf(const DIFile *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 504 | return Filename == RHS->getRawFilename() && |
| 505 | Directory == RHS->getRawDirectory(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 506 | } |
| 507 | unsigned getHashValue() const { return hash_combine(Filename, Directory); } |
| 508 | }; |
| 509 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 510 | template <> struct MDNodeKeyImpl<DISubprogram> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 511 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 512 | MDString *Name; |
| 513 | MDString *LinkageName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 514 | Metadata *File; |
| 515 | unsigned Line; |
| 516 | Metadata *Type; |
| 517 | bool IsLocalToUnit; |
| 518 | bool IsDefinition; |
| 519 | unsigned ScopeLine; |
| 520 | Metadata *ContainingType; |
| 521 | unsigned Virtuality; |
| 522 | unsigned VirtualIndex; |
| 523 | unsigned Flags; |
| 524 | bool IsOptimized; |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 525 | Metadata *Unit; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 526 | Metadata *TemplateParams; |
| 527 | Metadata *Declaration; |
| 528 | Metadata *Variables; |
| 529 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 530 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 531 | Metadata *File, unsigned Line, Metadata *Type, |
| 532 | bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, |
| 533 | Metadata *ContainingType, unsigned Virtuality, |
| 534 | unsigned VirtualIndex, unsigned Flags, bool IsOptimized, |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 535 | Metadata *Unit, Metadata *TemplateParams, Metadata *Declaration, |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 536 | Metadata *Variables) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 537 | : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), |
| 538 | Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), |
| 539 | IsDefinition(IsDefinition), ScopeLine(ScopeLine), |
| 540 | ContainingType(ContainingType), Virtuality(Virtuality), |
| 541 | VirtualIndex(VirtualIndex), Flags(Flags), IsOptimized(IsOptimized), |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 542 | Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration), |
Peter Collingbourne | d4bff30 | 2015-11-05 22:03:56 +0000 | [diff] [blame] | 543 | Variables(Variables) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 544 | MDNodeKeyImpl(const DISubprogram *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 545 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 546 | LinkageName(N->getRawLinkageName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 547 | Line(N->getLine()), Type(N->getRawType()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 548 | IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 549 | ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 550 | Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()), |
| 551 | Flags(N->getFlags()), IsOptimized(N->isOptimized()), |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 552 | Unit(N->getRawUnit()), TemplateParams(N->getRawTemplateParams()), |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 553 | Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 554 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 555 | bool isKeyOf(const DISubprogram *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 556 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 557 | LinkageName == RHS->getRawLinkageName() && |
| 558 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 559 | Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 560 | IsDefinition == RHS->isDefinition() && |
| 561 | ScopeLine == RHS->getScopeLine() && |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 562 | ContainingType == RHS->getRawContainingType() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 563 | Virtuality == RHS->getVirtuality() && |
| 564 | VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() && |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 565 | IsOptimized == RHS->isOptimized() && Unit == RHS->getUnit() && |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 566 | TemplateParams == RHS->getRawTemplateParams() && |
| 567 | Declaration == RHS->getRawDeclaration() && |
| 568 | Variables == RHS->getRawVariables(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 569 | } |
| 570 | unsigned getHashValue() const { |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 571 | // If this is a declaration inside an ODR type, only hash the type and the |
| 572 | // name. Otherwise the hash will be stronger than |
| 573 | // MDNodeSubsetEqualImpl::isDeclarationOfODRMember(). |
| 574 | if (!IsDefinition && LinkageName && Scope && isa<MDString>(Scope)) |
| 575 | return hash_combine(LinkageName, Scope); |
| 576 | |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 577 | // Intentionally computes the hash on a subset of the operands for |
| 578 | // performance reason. The subset has to be significant enough to avoid |
| 579 | // collision "most of the time". There is no correctness issue in case of |
| 580 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 581 | return hash_combine(Name, Scope, File, Type, Line); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 582 | } |
| 583 | }; |
| 584 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 585 | template <> struct MDNodeSubsetEqualImpl<DISubprogram> { |
| 586 | typedef MDNodeKeyImpl<DISubprogram> KeyTy; |
| 587 | static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { |
| 588 | return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope, |
| 589 | LHS.LinkageName, RHS); |
| 590 | } |
| 591 | static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { |
| 592 | return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), |
| 593 | LHS->getRawLinkageName(), RHS); |
| 594 | } |
| 595 | |
| 596 | /// Subprograms compare equal if they declare the same function in an ODR |
| 597 | /// type. |
| 598 | static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope, |
| 599 | const MDString *LinkageName, |
| 600 | const DISubprogram *RHS) { |
| 601 | // Check whether the LHS is eligible. |
| 602 | if (IsDefinition || !Scope || !LinkageName || !Scope || |
| 603 | !isa<MDString>(Scope)) |
| 604 | return false; |
| 605 | |
| 606 | // Compare to the RHS. |
| 607 | return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() && |
| 608 | LinkageName == RHS->getRawLinkageName(); |
| 609 | } |
| 610 | }; |
| 611 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 612 | template <> struct MDNodeKeyImpl<DILexicalBlock> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 613 | Metadata *Scope; |
| 614 | Metadata *File; |
| 615 | unsigned Line; |
| 616 | unsigned Column; |
| 617 | |
| 618 | MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column) |
| 619 | : Scope(Scope), File(File), Line(Line), Column(Column) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 620 | MDNodeKeyImpl(const DILexicalBlock *N) |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 621 | : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 622 | Column(N->getColumn()) {} |
| 623 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 624 | bool isKeyOf(const DILexicalBlock *RHS) const { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 625 | return Scope == RHS->getRawScope() && File == RHS->getRawFile() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 626 | Line == RHS->getLine() && Column == RHS->getColumn(); |
| 627 | } |
| 628 | unsigned getHashValue() const { |
| 629 | return hash_combine(Scope, File, Line, Column); |
| 630 | } |
| 631 | }; |
| 632 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 633 | template <> struct MDNodeKeyImpl<DILexicalBlockFile> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 634 | Metadata *Scope; |
| 635 | Metadata *File; |
| 636 | unsigned Discriminator; |
| 637 | |
| 638 | MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator) |
| 639 | : Scope(Scope), File(File), Discriminator(Discriminator) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 640 | MDNodeKeyImpl(const DILexicalBlockFile *N) |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 641 | : Scope(N->getRawScope()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 642 | Discriminator(N->getDiscriminator()) {} |
| 643 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 644 | bool isKeyOf(const DILexicalBlockFile *RHS) const { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 645 | return Scope == RHS->getRawScope() && File == RHS->getRawFile() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 646 | Discriminator == RHS->getDiscriminator(); |
| 647 | } |
| 648 | unsigned getHashValue() const { |
| 649 | return hash_combine(Scope, File, Discriminator); |
| 650 | } |
| 651 | }; |
| 652 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 653 | template <> struct MDNodeKeyImpl<DINamespace> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 654 | Metadata *Scope; |
| 655 | Metadata *File; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 656 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 657 | unsigned Line; |
| 658 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 659 | MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 660 | : Scope(Scope), File(File), Name(Name), Line(Line) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 661 | MDNodeKeyImpl(const DINamespace *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 662 | : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 663 | Line(N->getLine()) {} |
| 664 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 665 | bool isKeyOf(const DINamespace *RHS) const { |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 666 | return Scope == RHS->getRawScope() && File == RHS->getRawFile() && |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 667 | Name == RHS->getRawName() && Line == RHS->getLine(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 668 | } |
| 669 | unsigned getHashValue() const { |
| 670 | return hash_combine(Scope, File, Name, Line); |
| 671 | } |
| 672 | }; |
| 673 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 674 | template <> struct MDNodeKeyImpl<DIModule> { |
| 675 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 676 | MDString *Name; |
| 677 | MDString *ConfigurationMacros; |
| 678 | MDString *IncludePath; |
| 679 | MDString *ISysRoot; |
| 680 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, |
| 681 | MDString *IncludePath, MDString *ISysRoot) |
| 682 | : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), |
| 683 | IncludePath(IncludePath), ISysRoot(ISysRoot) {} |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 684 | MDNodeKeyImpl(const DIModule *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 685 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 686 | ConfigurationMacros(N->getRawConfigurationMacros()), |
| 687 | IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {} |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 688 | |
| 689 | bool isKeyOf(const DIModule *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 690 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 691 | ConfigurationMacros == RHS->getRawConfigurationMacros() && |
| 692 | IncludePath == RHS->getRawIncludePath() && |
| 693 | ISysRoot == RHS->getRawISysRoot(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 694 | } |
| 695 | unsigned getHashValue() const { |
| 696 | return hash_combine(Scope, Name, |
| 697 | ConfigurationMacros, IncludePath, ISysRoot); |
| 698 | } |
| 699 | }; |
| 700 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 701 | template <> struct MDNodeKeyImpl<DITemplateTypeParameter> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 702 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 703 | Metadata *Type; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 704 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 705 | MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 706 | MDNodeKeyImpl(const DITemplateTypeParameter *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 707 | : Name(N->getRawName()), Type(N->getRawType()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 708 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 709 | bool isKeyOf(const DITemplateTypeParameter *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 710 | return Name == RHS->getRawName() && Type == RHS->getRawType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 711 | } |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 712 | unsigned getHashValue() const { return hash_combine(Name, Type); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 713 | }; |
| 714 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 715 | template <> struct MDNodeKeyImpl<DITemplateValueParameter> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 716 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 717 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 718 | Metadata *Type; |
| 719 | Metadata *Value; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 720 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 721 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value) |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 722 | : Tag(Tag), Name(Name), Type(Type), Value(Value) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 723 | MDNodeKeyImpl(const DITemplateValueParameter *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 724 | : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()), |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 725 | Value(N->getValue()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 726 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 727 | bool isKeyOf(const DITemplateValueParameter *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 728 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 729 | Type == RHS->getRawType() && Value == RHS->getValue(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 730 | } |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 731 | unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 732 | }; |
| 733 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 734 | template <> struct MDNodeKeyImpl<DIGlobalVariable> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 735 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 736 | MDString *Name; |
| 737 | MDString *LinkageName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 738 | Metadata *File; |
| 739 | unsigned Line; |
| 740 | Metadata *Type; |
| 741 | bool IsLocalToUnit; |
| 742 | bool IsDefinition; |
| 743 | Metadata *Variable; |
| 744 | Metadata *StaticDataMemberDeclaration; |
| 745 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 746 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 747 | Metadata *File, unsigned Line, Metadata *Type, |
| 748 | bool IsLocalToUnit, bool IsDefinition, Metadata *Variable, |
| 749 | Metadata *StaticDataMemberDeclaration) |
| 750 | : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), |
| 751 | Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), |
| 752 | IsDefinition(IsDefinition), Variable(Variable), |
| 753 | StaticDataMemberDeclaration(StaticDataMemberDeclaration) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 754 | MDNodeKeyImpl(const DIGlobalVariable *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 755 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 756 | LinkageName(N->getRawLinkageName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 757 | Line(N->getLine()), Type(N->getRawType()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 758 | IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 759 | Variable(N->getRawVariable()), |
| 760 | StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 761 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 762 | bool isKeyOf(const DIGlobalVariable *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 763 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 764 | LinkageName == RHS->getRawLinkageName() && |
| 765 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 766 | Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 767 | IsDefinition == RHS->isDefinition() && |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 768 | Variable == RHS->getRawVariable() && |
| 769 | StaticDataMemberDeclaration == |
| 770 | RHS->getRawStaticDataMemberDeclaration(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 771 | } |
| 772 | unsigned getHashValue() const { |
| 773 | return hash_combine(Scope, Name, LinkageName, File, Line, Type, |
| 774 | IsLocalToUnit, IsDefinition, Variable, |
| 775 | StaticDataMemberDeclaration); |
| 776 | } |
| 777 | }; |
| 778 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 779 | template <> struct MDNodeKeyImpl<DILocalVariable> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 780 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 781 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 782 | Metadata *File; |
| 783 | unsigned Line; |
| 784 | Metadata *Type; |
| 785 | unsigned Arg; |
| 786 | unsigned Flags; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 787 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 788 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 789 | Metadata *Type, unsigned Arg, unsigned Flags) |
| 790 | : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg), |
| 791 | Flags(Flags) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 792 | MDNodeKeyImpl(const DILocalVariable *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 793 | : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 794 | Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()), |
| 795 | Flags(N->getFlags()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 796 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 797 | bool isKeyOf(const DILocalVariable *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 798 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 799 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 800 | Type == RHS->getRawType() && Arg == RHS->getArg() && |
| 801 | Flags == RHS->getFlags(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 802 | } |
| 803 | unsigned getHashValue() const { |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 804 | return hash_combine(Scope, Name, File, Line, Type, Arg, Flags); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 805 | } |
| 806 | }; |
| 807 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 808 | template <> struct MDNodeKeyImpl<DIExpression> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 809 | ArrayRef<uint64_t> Elements; |
| 810 | |
| 811 | MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 812 | MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 813 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 814 | bool isKeyOf(const DIExpression *RHS) const { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 815 | return Elements == RHS->getElements(); |
| 816 | } |
| 817 | unsigned getHashValue() const { |
| 818 | return hash_combine_range(Elements.begin(), Elements.end()); |
| 819 | } |
| 820 | }; |
| 821 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 822 | template <> struct MDNodeKeyImpl<DIObjCProperty> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 823 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 824 | Metadata *File; |
| 825 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 826 | MDString *GetterName; |
| 827 | MDString *SetterName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 828 | unsigned Attributes; |
| 829 | Metadata *Type; |
| 830 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 831 | MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line, |
| 832 | MDString *GetterName, MDString *SetterName, unsigned Attributes, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 833 | Metadata *Type) |
| 834 | : Name(Name), File(File), Line(Line), GetterName(GetterName), |
| 835 | SetterName(SetterName), Attributes(Attributes), Type(Type) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 836 | MDNodeKeyImpl(const DIObjCProperty *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 837 | : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), |
| 838 | GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()), |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 839 | Attributes(N->getAttributes()), Type(N->getRawType()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 840 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 841 | bool isKeyOf(const DIObjCProperty *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 842 | return Name == RHS->getRawName() && File == RHS->getRawFile() && |
| 843 | Line == RHS->getLine() && GetterName == RHS->getRawGetterName() && |
| 844 | SetterName == RHS->getRawSetterName() && |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 845 | Attributes == RHS->getAttributes() && Type == RHS->getRawType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 846 | } |
| 847 | unsigned getHashValue() const { |
| 848 | return hash_combine(Name, File, Line, GetterName, SetterName, Attributes, |
| 849 | Type); |
| 850 | } |
| 851 | }; |
| 852 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 853 | template <> struct MDNodeKeyImpl<DIImportedEntity> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 854 | unsigned Tag; |
| 855 | Metadata *Scope; |
| 856 | Metadata *Entity; |
| 857 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 858 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 859 | |
| 860 | MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line, |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 861 | MDString *Name) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 862 | : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 863 | MDNodeKeyImpl(const DIImportedEntity *N) |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 864 | : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()), |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 865 | Line(N->getLine()), Name(N->getRawName()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 866 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 867 | bool isKeyOf(const DIImportedEntity *RHS) const { |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 868 | return Tag == RHS->getTag() && Scope == RHS->getRawScope() && |
| 869 | Entity == RHS->getRawEntity() && Line == RHS->getLine() && |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 870 | Name == RHS->getRawName(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 871 | } |
| 872 | unsigned getHashValue() const { |
| 873 | return hash_combine(Tag, Scope, Entity, Line, Name); |
| 874 | } |
| 875 | }; |
| 876 | |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 877 | template <> struct MDNodeKeyImpl<DIMacro> { |
| 878 | unsigned MIType; |
| 879 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 880 | MDString *Name; |
| 881 | MDString *Value; |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 882 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 883 | MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value) |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 884 | : MIType(MIType), Line(Line), Name(Name), Value(Value) {} |
| 885 | MDNodeKeyImpl(const DIMacro *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 886 | : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()), |
| 887 | Value(N->getRawValue()) {} |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 888 | |
| 889 | bool isKeyOf(const DIMacro *RHS) const { |
| 890 | return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 891 | Name == RHS->getRawName() && Value == RHS->getRawValue(); |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 892 | } |
| 893 | unsigned getHashValue() const { |
| 894 | return hash_combine(MIType, Line, Name, Value); |
| 895 | } |
| 896 | }; |
| 897 | |
| 898 | template <> struct MDNodeKeyImpl<DIMacroFile> { |
| 899 | unsigned MIType; |
| 900 | unsigned Line; |
| 901 | Metadata *File; |
| 902 | Metadata *Elements; |
| 903 | |
| 904 | MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File, |
| 905 | Metadata *Elements) |
| 906 | : MIType(MIType), Line(Line), File(File), Elements(Elements) {} |
| 907 | MDNodeKeyImpl(const DIMacroFile *N) |
| 908 | : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()), |
| 909 | Elements(N->getRawElements()) {} |
| 910 | |
| 911 | bool isKeyOf(const DIMacroFile *RHS) const { |
| 912 | return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && |
| 913 | File == RHS->getRawFile() && File == RHS->getRawElements(); |
| 914 | } |
| 915 | unsigned getHashValue() const { |
| 916 | return hash_combine(MIType, Line, File, Elements); |
| 917 | } |
| 918 | }; |
| 919 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 920 | /// \brief DenseMapInfo for MDNode subclasses. |
| 921 | template <class NodeTy> struct MDNodeInfo { |
| 922 | typedef MDNodeKeyImpl<NodeTy> KeyTy; |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 923 | typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy; |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 924 | static inline NodeTy *getEmptyKey() { |
| 925 | return DenseMapInfo<NodeTy *>::getEmptyKey(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 926 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 927 | static inline NodeTy *getTombstoneKey() { |
| 928 | return DenseMapInfo<NodeTy *>::getTombstoneKey(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 929 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 930 | static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } |
| 931 | static unsigned getHashValue(const NodeTy *N) { |
| 932 | return KeyTy(N).getHashValue(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 933 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 934 | static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) { |
| 935 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 936 | return false; |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 937 | return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 938 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 939 | static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) { |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 940 | if (LHS == RHS) |
| 941 | return true; |
| 942 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 943 | return false; |
| 944 | return SubsetEqualTy::isSubsetEqual(LHS, RHS); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 945 | } |
| 946 | }; |
| 947 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 948 | #define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info; |
| 949 | #include "llvm/IR/Metadata.def" |
| 950 | |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 951 | /// \brief Map-like storage for metadata attachments. |
| 952 | class MDAttachmentMap { |
| 953 | SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments; |
| 954 | |
| 955 | public: |
| 956 | bool empty() const { return Attachments.empty(); } |
| 957 | size_t size() const { return Attachments.size(); } |
| 958 | |
| 959 | /// \brief Get a particular attachment (if any). |
| 960 | MDNode *lookup(unsigned ID) const; |
| 961 | |
| 962 | /// \brief Set an attachment to a particular node. |
| 963 | /// |
| 964 | /// Set the \c ID attachment to \c MD, replacing the current attachment at \c |
| 965 | /// ID (if anyway). |
| 966 | void set(unsigned ID, MDNode &MD); |
| 967 | |
| 968 | /// \brief Remove an attachment. |
| 969 | /// |
| 970 | /// Remove the attachment at \c ID, if any. |
| 971 | void erase(unsigned ID); |
| 972 | |
| 973 | /// \brief Copy out all the attachments. |
| 974 | /// |
| 975 | /// Copies all the current attachments into \c Result, sorting by attachment |
| 976 | /// ID. This function does \em not clear \c Result. |
| 977 | void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; |
| 978 | |
| 979 | /// \brief Erase matching attachments. |
| 980 | /// |
| 981 | /// Erases all attachments matching the \c shouldRemove predicate. |
| 982 | template <class PredTy> void remove_if(PredTy shouldRemove) { |
| 983 | Attachments.erase( |
| 984 | std::remove_if(Attachments.begin(), Attachments.end(), shouldRemove), |
| 985 | Attachments.end()); |
| 986 | } |
| 987 | }; |
| 988 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 989 | class LLVMContextImpl { |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 990 | public: |
Owen Anderson | 8e89e41 | 2010-09-08 18:03:32 +0000 | [diff] [blame] | 991 | /// OwnedModules - The set of modules instantiated in this context, and which |
| 992 | /// will be automatically deleted if this context is deleted. |
| 993 | SmallPtrSet<Module*, 4> OwnedModules; |
| 994 | |
Bob Wilson | a594fab | 2013-02-11 05:37:07 +0000 | [diff] [blame] | 995 | LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler; |
| 996 | void *InlineAsmDiagContext; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 997 | |
| 998 | LLVMContext::DiagnosticHandlerTy DiagnosticHandler; |
| 999 | void *DiagnosticContext; |
Duncan P. N. Exon Smith | 30c9242 | 2014-10-01 18:36:03 +0000 | [diff] [blame] | 1000 | bool RespectDiagnosticFilters; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 1001 | |
Juergen Ributzka | 34390c7 | 2014-05-16 02:33:15 +0000 | [diff] [blame] | 1002 | LLVMContext::YieldCallbackTy YieldCallback; |
| 1003 | void *YieldOpaqueHandle; |
| 1004 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 1005 | typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 1006 | IntMapTy IntConstants; |
NAKAMURA Takumi | fc3062f | 2014-12-06 05:57:06 +0000 | [diff] [blame] | 1007 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 1008 | typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 1009 | FPMapTy FPConstants; |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1010 | |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 1011 | FoldingSet<AttributeImpl> AttrsSet; |
Bill Wendling | 6848e38 | 2012-12-19 22:42:22 +0000 | [diff] [blame] | 1012 | FoldingSet<AttributeSetImpl> AttrsLists; |
Bill Wendling | d2e493b | 2013-01-24 00:06:56 +0000 | [diff] [blame] | 1013 | FoldingSet<AttributeSetNode> AttrsSetNodes; |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 1014 | |
Duncan P. N. Exon Smith | 3e0430e | 2016-04-06 06:41:54 +0000 | [diff] [blame] | 1015 | StringMap<MDString, BumpPtrAllocator> MDStringCache; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1016 | DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata; |
| 1017 | DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues; |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1018 | |
Owen Anderson | 7349ab9 | 2015-06-01 22:24:01 +0000 | [diff] [blame] | 1019 | DenseMap<const Value*, ValueName*> ValueNames; |
| 1020 | |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1021 | #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \ |
| 1022 | DenseSet<CLASS *, CLASS##Info> CLASS##s; |
Duncan P. N. Exon Smith | 104e402 | 2015-02-04 21:46:12 +0000 | [diff] [blame] | 1023 | #include "llvm/IR/Metadata.def" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1024 | |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 1025 | // Optional map for looking up composite types by identifier. |
Duncan P. N. Exon Smith | e8b555c | 2016-04-19 16:06:50 +0000 | [diff] [blame] | 1026 | Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap; |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 1027 | |
Jeffrey Yasskin | 2cc2476 | 2010-03-13 01:26:15 +0000 | [diff] [blame] | 1028 | // MDNodes may be uniqued or not uniqued. When they're not uniqued, they |
| 1029 | // aren't in the MDNodeSet, but they're still shared between objects, so no |
Duncan P. N. Exon Smith | 3eef9d1 | 2016-04-19 23:59:13 +0000 | [diff] [blame] | 1030 | // one object can destroy them. Keep track of them here so we can delete |
| 1031 | // them on context teardown. |
| 1032 | std::vector<MDNode *> DistinctMDNodes; |
Duncan P. N. Exon Smith | 50846f8 | 2014-11-18 00:37:17 +0000 | [diff] [blame] | 1033 | |
David Blaikie | cb2818f | 2014-11-25 02:26:22 +0000 | [diff] [blame] | 1034 | DenseMap<Type*, ConstantAggregateZero*> CAZConstants; |
Owen Anderson | 13234f8 | 2009-08-10 18:16:08 +0000 | [diff] [blame] | 1035 | |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1036 | typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1037 | ArrayConstantsTy ArrayConstants; |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 1038 | |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1039 | typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1040 | StructConstantsTy StructConstants; |
Owen Anderson | 909f600 | 2009-07-23 23:25:33 +0000 | [diff] [blame] | 1041 | |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1042 | typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1043 | VectorConstantsTy VectorConstants; |
Owen Anderson | 0348a13 | 2009-07-24 00:36:24 +0000 | [diff] [blame] | 1044 | |
Chris Lattner | c7f9fd4 | 2012-01-23 15:20:12 +0000 | [diff] [blame] | 1045 | DenseMap<PointerType*, ConstantPointerNull*> CPNConstants; |
| 1046 | |
| 1047 | DenseMap<Type*, UndefValue*> UVConstants; |
Owen Anderson | c8c3026 | 2009-07-31 22:45:43 +0000 | [diff] [blame] | 1048 | |
Chris Lattner | 3756b91 | 2012-01-23 22:57:10 +0000 | [diff] [blame] | 1049 | StringMap<ConstantDataSequential*> CDSConstants; |
| 1050 | |
Chandler Carruth | 6a93692 | 2014-01-19 02:13:50 +0000 | [diff] [blame] | 1051 | DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *> |
| 1052 | BlockAddresses; |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1053 | ConstantUniqueMap<ConstantExpr> ExprConstants; |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 1054 | |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1055 | ConstantUniqueMap<InlineAsm> InlineAsms; |
| 1056 | |
Owen Anderson | 2ad5217 | 2009-07-21 02:47:59 +0000 | [diff] [blame] | 1057 | ConstantInt *TheTrueVal; |
| 1058 | ConstantInt *TheFalseVal; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1059 | |
David Majnemer | 2dd41c5 | 2015-11-16 20:55:57 +0000 | [diff] [blame] | 1060 | std::unique_ptr<ConstantTokenNone> TheNoneToken; |
David Majnemer | f0f224d | 2015-11-11 21:57:16 +0000 | [diff] [blame] | 1061 | |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame] | 1062 | // Basic type instances. |
David Majnemer | b611e3f | 2015-08-14 05:09:07 +0000 | [diff] [blame] | 1063 | Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1064 | Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; |
Kit Barton | 7291802 | 2015-04-17 15:32:15 +0000 | [diff] [blame] | 1065 | IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame] | 1066 | |
Chris Lattner | 07bd69c | 2011-07-15 05:49:15 +0000 | [diff] [blame] | 1067 | |
| 1068 | /// TypeAllocator - All dynamically allocated types are allocated from this. |
| 1069 | /// They live forever until the context is torn down. |
| 1070 | BumpPtrAllocator TypeAllocator; |
| 1071 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1072 | DenseMap<unsigned, IntegerType*> IntegerTypes; |
Benjamin Kramer | 3280a5d | 2014-12-06 19:22:54 +0000 | [diff] [blame] | 1073 | |
| 1074 | typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet; |
| 1075 | FunctionTypeSet FunctionTypes; |
| 1076 | typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet; |
| 1077 | StructTypeSet AnonStructTypes; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1078 | StringMap<StructType*> NamedStructTypes; |
| 1079 | unsigned NamedStructTypesUniqueID; |
| 1080 | |
| 1081 | DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; |
| 1082 | DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; |
| 1083 | DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 |
| 1084 | DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; |
Jeffrey Yasskin | c660b23 | 2010-02-11 06:41:30 +0000 | [diff] [blame] | 1085 | |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 1086 | |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 1087 | /// ValueHandles - This map keeps track of all of the value handles that are |
| 1088 | /// watching a Value*. The Value::HasValueHandle bit is used to know |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 1089 | /// whether or not a value has an entry in this map. |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 1090 | typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy; |
| 1091 | ValueHandlesTy ValueHandles; |
| 1092 | |
Chris Lattner | a056697 | 2009-12-29 09:01:33 +0000 | [diff] [blame] | 1093 | /// CustomMDKindNames - Map to hold the metadata string to ID mapping. |
| 1094 | StringMap<unsigned> CustomMDKindNames; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1095 | |
Duncan P. N. Exon Smith | 391fc56 | 2015-04-24 20:16:42 +0000 | [diff] [blame] | 1096 | /// Collection of per-instruction metadata used in this context. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1097 | DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata; |
Duncan P. N. Exon Smith | 391fc56 | 2015-04-24 20:16:42 +0000 | [diff] [blame] | 1098 | |
Duncan P. N. Exon Smith | e2510cd | 2015-04-24 21:51:02 +0000 | [diff] [blame] | 1099 | /// Collection of per-function metadata used in this context. |
| 1100 | DenseMap<const Function *, MDAttachmentMap> FunctionMetadata; |
| 1101 | |
Diego Novillo | f5041ce | 2014-03-03 20:06:11 +0000 | [diff] [blame] | 1102 | /// DiscriminatorTable - This table maps file:line locations to an |
| 1103 | /// integer representing the next DWARF path discriminator to assign to |
| 1104 | /// instructions in different blocks at the same location. |
| 1105 | DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable; |
| 1106 | |
Chris Lattner | 8cb2aeb | 2010-04-01 00:37:44 +0000 | [diff] [blame] | 1107 | int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); |
| 1108 | int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx); |
Philip Reames | 2b45395 | 2015-01-16 20:07:33 +0000 | [diff] [blame] | 1109 | |
Sanjoy Das | 9303c24 | 2015-09-24 19:14:18 +0000 | [diff] [blame] | 1110 | /// \brief A set of interned tags for operand bundles. The StringMap maps |
| 1111 | /// bundle tags to their IDs. |
| 1112 | /// |
| 1113 | /// \see LLVMContext::getOperandBundleTagID |
| 1114 | StringMap<uint32_t> BundleTagCache; |
| 1115 | |
| 1116 | StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag); |
| 1117 | void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const; |
| 1118 | uint32_t getOperandBundleTagID(StringRef Tag) const; |
| 1119 | |
Mehdi Amini | 599ebf2 | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 1120 | /// Maintain the GC name for each function. |
| 1121 | /// |
| 1122 | /// This saves allocating an additional word in Function for programs which |
| 1123 | /// do not use GC (i.e., most programs) at the cost of increased overhead for |
| 1124 | /// clients which do use GC. |
| 1125 | DenseMap<const Function*, std::string> GCNames; |
| 1126 | |
Mehdi Amini | 09b4a8d | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 1127 | /// Flag to indicate if Value (other than GlobalValue) retains their name or |
| 1128 | /// not. |
| 1129 | bool DiscardValueNames = false; |
| 1130 | |
Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 1131 | LLVMContextImpl(LLVMContext &C); |
| 1132 | ~LLVMContextImpl(); |
Manman Ren | dab999d | 2015-01-20 19:24:59 +0000 | [diff] [blame] | 1133 | |
| 1134 | /// Destroy the ConstantArrays if they are not used. |
| 1135 | void dropTriviallyDeadConstantArrays(); |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame^] | 1136 | |
| 1137 | /// \brief Access the object which manages optimization bisection for failure |
| 1138 | /// analysis. |
| 1139 | OptBisect &getOptBisect(); |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 1140 | }; |
| 1141 | |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 1142 | } |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 1143 | |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 1144 | #endif |