blob: 2938421080ba026050eb00bb587ffcf56cc33ed7 [file] [log] [blame]
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001//===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +00002//
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 Anderson36f62e52009-06-30 17:06:46 +00009//
10// This file declares LLVMContextImpl, the opaque implementation
11// of LLVMContext.
12//
13//===----------------------------------------------------------------------===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +000014
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
16#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
Owen Anderson8e66e0b2009-06-30 00:48:55 +000017
Bill Wendling4607f4b2012-12-20 01:36:59 +000018#include "AttributeImpl.h"
Owen Andersonafd0c4c2009-08-04 22:41:48 +000019#include "ConstantsContext.h"
Owen Andersonc277dc42009-07-16 19:05:41 +000020#include "llvm/ADT/APFloat.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000021#include "llvm/ADT/APInt.h"
Jay Foadc365eea2011-06-22 08:50:06 +000022#include "llvm/ADT/ArrayRef.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000023#include "llvm/ADT/DenseMap.h"
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +000024#include "llvm/ADT/DenseSet.h"
Owen Anderson4118dde2009-07-16 23:44:30 +000025#include "llvm/ADT/FoldingSet.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000026#include "llvm/ADT/Hashing.h"
Jeffrey Yasskin28f24482009-12-17 19:55:06 +000027#include "llvm/ADT/SmallPtrSet.h"
Owen Anderson69ab4162009-07-16 22:11:26 +000028#include "llvm/ADT/StringMap.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000029#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000030#include "llvm/IR/DebugInfoMetadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000031#include "llvm/IR/DerivedTypes.h"
32#include "llvm/IR/LLVMContext.h"
33#include "llvm/IR/Metadata.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000034#include "llvm/IR/ValueHandle.h"
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +000035#include "llvm/Support/Dwarf.h"
Owen Anderson39ede7b2009-07-21 20:13:12 +000036
Owen Anderson20b34ac2009-07-16 18:04:31 +000037namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000038
Owen Anderson20b34ac2009-07-16 18:04:31 +000039class ConstantInt;
Owen Andersonc277dc42009-07-16 19:05:41 +000040class ConstantFP;
Diego Novillo7f8af8b2014-05-22 14:19:46 +000041class DiagnosticInfoOptimizationRemark;
42class DiagnosticInfoOptimizationRemarkMissed;
43class DiagnosticInfoOptimizationRemarkAnalysis;
Philip Reames2b453952015-01-16 20:07:33 +000044class GCStrategy;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000045class LLVMContext;
Owen Anderson20b34ac2009-07-16 18:04:31 +000046class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000047class Value;
Owen Anderson20b34ac2009-07-16 18:04:31 +000048
Benjamin Kramer079b96e2013-09-11 18:05:11 +000049struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000050 static inline APInt getEmptyKey() {
51 APInt V(nullptr, 0);
52 V.VAL = 0;
53 return V;
54 }
55 static inline APInt getTombstoneKey() {
56 APInt V(nullptr, 0);
57 V.VAL = 1;
58 return V;
59 }
60 static unsigned getHashValue(const APInt &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000061 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000062 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000063 static bool isEqual(const APInt &LHS, const APInt &RHS) {
64 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
65 }
Owen Anderson20b34ac2009-07-16 18:04:31 +000066};
67
Benjamin Kramer079b96e2013-09-11 18:05:11 +000068struct DenseMapAPFloatKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000069 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
70 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
71 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000072 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000073 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000074 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
75 return LHS.bitwiseIsEqual(RHS);
76 }
Owen Andersonc277dc42009-07-16 19:05:41 +000077};
78
Benjamin Kramer079b96e2013-09-11 18:05:11 +000079struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000080 struct KeyTy {
81 ArrayRef<Type*> ETypes;
82 bool isPacked;
83 KeyTy(const ArrayRef<Type*>& E, bool P) :
84 ETypes(E), isPacked(P) {}
Rafael Espindola334b73f2014-11-21 18:53:05 +000085 KeyTy(const StructType *ST)
86 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Jay Foad529776c2012-02-23 09:17:40 +000087 bool operator==(const KeyTy& that) const {
88 if (isPacked != that.isPacked)
89 return false;
90 if (ETypes != that.ETypes)
91 return false;
92 return true;
93 }
94 bool operator!=(const KeyTy& that) const {
95 return !this->operator==(that);
96 }
97 };
98 static inline StructType* getEmptyKey() {
99 return DenseMapInfo<StructType*>::getEmptyKey();
100 }
101 static inline StructType* getTombstoneKey() {
102 return DenseMapInfo<StructType*>::getTombstoneKey();
103 }
104 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000105 return hash_combine(hash_combine_range(Key.ETypes.begin(),
106 Key.ETypes.end()),
107 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000108 }
109 static unsigned getHashValue(const StructType *ST) {
110 return getHashValue(KeyTy(ST));
111 }
112 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
113 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
114 return false;
115 return LHS == KeyTy(RHS);
116 }
117 static bool isEqual(const StructType *LHS, const StructType *RHS) {
118 return LHS == RHS;
119 }
120};
121
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000122struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000123 struct KeyTy {
124 const Type *ReturnType;
125 ArrayRef<Type*> Params;
126 bool isVarArg;
127 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
128 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindolae973fd42014-11-21 19:03:35 +0000129 KeyTy(const FunctionType *FT)
130 : ReturnType(FT->getReturnType()), Params(FT->params()),
131 isVarArg(FT->isVarArg()) {}
Jay Foad529776c2012-02-23 09:17:40 +0000132 bool operator==(const KeyTy& that) const {
133 if (ReturnType != that.ReturnType)
134 return false;
135 if (isVarArg != that.isVarArg)
136 return false;
137 if (Params != that.Params)
138 return false;
139 return true;
140 }
141 bool operator!=(const KeyTy& that) const {
142 return !this->operator==(that);
143 }
144 };
145 static inline FunctionType* getEmptyKey() {
146 return DenseMapInfo<FunctionType*>::getEmptyKey();
147 }
148 static inline FunctionType* getTombstoneKey() {
149 return DenseMapInfo<FunctionType*>::getTombstoneKey();
150 }
151 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000152 return hash_combine(Key.ReturnType,
153 hash_combine_range(Key.Params.begin(),
154 Key.Params.end()),
155 Key.isVarArg);
Jay Foad529776c2012-02-23 09:17:40 +0000156 }
157 static unsigned getHashValue(const FunctionType *FT) {
158 return getHashValue(KeyTy(FT));
159 }
160 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
161 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
162 return false;
163 return LHS == KeyTy(RHS);
164 }
165 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
166 return LHS == RHS;
167 }
168};
169
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000170/// \brief Structure for hashing arbitrary MDNode operands.
171class MDNodeOpsKey {
172 ArrayRef<Metadata *> RawOps;
173 ArrayRef<MDOperand> Ops;
174
175 unsigned Hash;
176
177protected:
178 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
179 : RawOps(Ops), Hash(calculateHash(Ops)) {}
180
181 template <class NodeTy>
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000182 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000183 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000184
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000185 template <class NodeTy>
186 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000187 if (getHash() != RHS->getHash())
188 return false;
189
190 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000191 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
192 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000193 }
194
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000195 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000196
197private:
198 template <class T>
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000199 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
200 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000201 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000202 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000203 }
204
205 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
206
207public:
208 unsigned getHash() const { return Hash; }
209};
210
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000211template <class NodeTy> struct MDNodeKeyImpl;
212template <class NodeTy> struct MDNodeInfo;
213
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000214/// Configuration point for MDNodeInfo::isEqual().
215template <class NodeTy> struct MDNodeSubsetEqualImpl {
216 typedef MDNodeKeyImpl<NodeTy> KeyTy;
217 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
218 return false;
219 }
220 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
221 return false;
222 }
223};
224
Duncan P. N. Exon Smith118632d2015-01-12 20:09:34 +0000225/// \brief DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000226///
227/// Note that we don't need the is-function-local bit, since that's implicit in
228/// the operands.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000229template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
230 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
231 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000232
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000233 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000234
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000235 unsigned getHashValue() const { return getHash(); }
236
237 static unsigned calculateHash(MDTuple *N) {
238 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000239 }
240};
241
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000242/// \brief DenseMapInfo for DILocation.
243template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000244 unsigned Line;
245 unsigned Column;
246 Metadata *Scope;
247 Metadata *InlinedAt;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000248
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000249 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
250 Metadata *InlinedAt)
251 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000252
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000253 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000254 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
255 InlinedAt(L->getRawInlinedAt()) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000256
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000257 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000258 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000259 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000260 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000261 unsigned getHashValue() const {
262 return hash_combine(Line, Column, Scope, InlinedAt);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000263 }
264};
265
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000266/// \brief DenseMapInfo for GenericDINode.
267template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000268 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000269 MDString *Header;
270 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000271 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000272 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000273 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000274
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000275 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000276 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000277 compareOps(RHS, 1);
278 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000279
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000280 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
281
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000282 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000283 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000284 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000285};
286
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000287template <> struct MDNodeKeyImpl<DISubrange> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000288 int64_t Count;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000289 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000290
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000291 MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
292 : Count(Count), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000293 MDNodeKeyImpl(const DISubrange *N)
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000294 : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000295
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000296 bool isKeyOf(const DISubrange *RHS) const {
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000297 return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000298 }
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000299 unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000300};
301
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000302template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000303 int64_t Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000304 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000305
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000306 MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000307 MDNodeKeyImpl(const DIEnumerator *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000308 : Value(N->getValue()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000309
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000310 bool isKeyOf(const DIEnumerator *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000311 return Value == RHS->getValue() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000312 }
313 unsigned getHashValue() const { return hash_combine(Value, Name); }
314};
315
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000316template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000317 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000318 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000319 uint64_t SizeInBits;
320 uint64_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000321 unsigned Encoding;
322
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000323 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000324 uint64_t AlignInBits, unsigned Encoding)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000325 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
326 Encoding(Encoding) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000327 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000328 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000329 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
330
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000331 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000332 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000333 SizeInBits == RHS->getSizeInBits() &&
334 AlignInBits == RHS->getAlignInBits() &&
335 Encoding == RHS->getEncoding();
336 }
337 unsigned getHashValue() const {
338 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
339 }
340};
341
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000342template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000343 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000344 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000345 Metadata *File;
346 unsigned Line;
347 Metadata *Scope;
348 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000349 uint64_t SizeInBits;
350 uint64_t AlignInBits;
351 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000352 unsigned Flags;
353 Metadata *ExtraData;
354
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000355 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000356 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
357 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000358 Metadata *ExtraData)
359 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
360 BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
361 OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000362 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000363 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000364 Line(N->getLine()), Scope(N->getRawScope()),
365 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
366 AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
367 Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000368
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000369 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000370 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000371 File == RHS->getRawFile() && Line == RHS->getLine() &&
372 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000373 SizeInBits == RHS->getSizeInBits() &&
374 AlignInBits == RHS->getAlignInBits() &&
375 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000376 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000377 }
378 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000379 // If this is a member inside an ODR type, only hash the type and the name.
380 // Otherwise the hash will be stronger than
381 // MDNodeSubsetEqualImpl::isODRMember().
382 if (Tag == dwarf::DW_TAG_member && Name && Scope && isa<MDString>(Scope))
383 return hash_combine(Name, Scope);
384
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000385 // Intentionally computes the hash on a subset of the operands for
386 // performance reason. The subset has to be significant enough to avoid
387 // collision "most of the time". There is no correctness issue in case of
388 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000389 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000390 }
391};
392
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000393template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
394 typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
395 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
396 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
397 }
398 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
399 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
400 RHS);
401 }
402
403 /// Subprograms compare equal if they declare the same function in an ODR
404 /// type.
405 static bool isODRMember(unsigned Tag, const Metadata *Scope,
406 const MDString *Name, const DIDerivedType *RHS) {
407 // Check whether the LHS is eligible.
408 if (Tag != dwarf::DW_TAG_member || !Name || !Scope || !isa<MDString>(Scope))
409 return false;
410
411 // Compare to the RHS.
412 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
413 Scope == RHS->getRawScope();
414 }
415};
416
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000417template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000418 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000419 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000420 Metadata *File;
421 unsigned Line;
422 Metadata *Scope;
423 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000424 uint64_t SizeInBits;
425 uint64_t AlignInBits;
426 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000427 unsigned Flags;
428 Metadata *Elements;
429 unsigned RuntimeLang;
430 Metadata *VTableHolder;
431 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000432 MDString *Identifier;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000433
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000434 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000435 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
436 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000437 Metadata *Elements, unsigned RuntimeLang,
438 Metadata *VTableHolder, Metadata *TemplateParams,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000439 MDString *Identifier)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000440 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
441 BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
442 OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
443 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
444 TemplateParams(TemplateParams), Identifier(Identifier) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000445 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000446 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000447 Line(N->getLine()), Scope(N->getRawScope()),
448 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
449 AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
450 Flags(N->getFlags()), Elements(N->getRawElements()),
451 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
452 TemplateParams(N->getRawTemplateParams()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000453 Identifier(N->getRawIdentifier()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000454
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000455 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000456 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000457 File == RHS->getRawFile() && Line == RHS->getLine() &&
458 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000459 SizeInBits == RHS->getSizeInBits() &&
460 AlignInBits == RHS->getAlignInBits() &&
461 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000462 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000463 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000464 VTableHolder == RHS->getRawVTableHolder() &&
465 TemplateParams == RHS->getRawTemplateParams() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000466 Identifier == RHS->getRawIdentifier();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000467 }
468 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000469 // Intentionally computes the hash on a subset of the operands for
470 // performance reason. The subset has to be significant enough to avoid
471 // collision "most of the time". There is no correctness issue in case of
472 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000473 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
474 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000475 }
476};
477
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000478template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000479 unsigned Flags;
480 Metadata *TypeArray;
481
482 MDNodeKeyImpl(int64_t Flags, Metadata *TypeArray)
483 : Flags(Flags), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000484 MDNodeKeyImpl(const DISubroutineType *N)
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000485 : Flags(N->getFlags()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000486
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000487 bool isKeyOf(const DISubroutineType *RHS) const {
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000488 return Flags == RHS->getFlags() && TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000489 }
490 unsigned getHashValue() const { return hash_combine(Flags, TypeArray); }
491};
492
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000493template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000494 MDString *Filename;
495 MDString *Directory;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000496
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000497 MDNodeKeyImpl(MDString *Filename, MDString *Directory)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000498 : Filename(Filename), Directory(Directory) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000499 MDNodeKeyImpl(const DIFile *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000500 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000501
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000502 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000503 return Filename == RHS->getRawFilename() &&
504 Directory == RHS->getRawDirectory();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000505 }
506 unsigned getHashValue() const { return hash_combine(Filename, Directory); }
507};
508
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000509template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000510 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000511 MDString *Name;
512 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000513 Metadata *File;
514 unsigned Line;
515 Metadata *Type;
516 bool IsLocalToUnit;
517 bool IsDefinition;
518 unsigned ScopeLine;
519 Metadata *ContainingType;
520 unsigned Virtuality;
521 unsigned VirtualIndex;
522 unsigned Flags;
523 bool IsOptimized;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000524 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000525 Metadata *TemplateParams;
526 Metadata *Declaration;
527 Metadata *Variables;
528
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000529 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000530 Metadata *File, unsigned Line, Metadata *Type,
531 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
532 Metadata *ContainingType, unsigned Virtuality,
533 unsigned VirtualIndex, unsigned Flags, bool IsOptimized,
Adrian Prantl75819ae2016-04-15 15:57:41 +0000534 Metadata *Unit, Metadata *TemplateParams, Metadata *Declaration,
Peter Collingbourned4bff302015-11-05 22:03:56 +0000535 Metadata *Variables)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
537 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
538 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
539 ContainingType(ContainingType), Virtuality(Virtuality),
540 VirtualIndex(VirtualIndex), Flags(Flags), IsOptimized(IsOptimized),
Adrian Prantl75819ae2016-04-15 15:57:41 +0000541 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
Peter Collingbourned4bff302015-11-05 22:03:56 +0000542 Variables(Variables) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000543 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000544 : Scope(N->getRawScope()), Name(N->getRawName()),
545 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000546 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000547 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000548 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000549 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
550 Flags(N->getFlags()), IsOptimized(N->isOptimized()),
Adrian Prantl75819ae2016-04-15 15:57:41 +0000551 Unit(N->getRawUnit()), TemplateParams(N->getRawTemplateParams()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000552 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000553
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000554 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000555 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
556 LinkageName == RHS->getRawLinkageName() &&
557 File == RHS->getRawFile() && Line == RHS->getLine() &&
558 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000559 IsDefinition == RHS->isDefinition() &&
560 ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000561 ContainingType == RHS->getRawContainingType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000562 Virtuality == RHS->getVirtuality() &&
563 VirtualIndex == RHS->getVirtualIndex() && Flags == RHS->getFlags() &&
Adrian Prantl75819ae2016-04-15 15:57:41 +0000564 IsOptimized == RHS->isOptimized() && Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000565 TemplateParams == RHS->getRawTemplateParams() &&
566 Declaration == RHS->getRawDeclaration() &&
567 Variables == RHS->getRawVariables();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000568 }
569 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000570 // If this is a declaration inside an ODR type, only hash the type and the
571 // name. Otherwise the hash will be stronger than
572 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
573 if (!IsDefinition && LinkageName && Scope && isa<MDString>(Scope))
574 return hash_combine(LinkageName, Scope);
575
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000576 // Intentionally computes the hash on a subset of the operands for
577 // performance reason. The subset has to be significant enough to avoid
578 // collision "most of the time". There is no correctness issue in case of
579 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000580 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000581 }
582};
583
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000584template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
585 typedef MDNodeKeyImpl<DISubprogram> KeyTy;
586 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
587 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
588 LHS.LinkageName, RHS);
589 }
590 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
591 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
592 LHS->getRawLinkageName(), RHS);
593 }
594
595 /// Subprograms compare equal if they declare the same function in an ODR
596 /// type.
597 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
598 const MDString *LinkageName,
599 const DISubprogram *RHS) {
600 // Check whether the LHS is eligible.
601 if (IsDefinition || !Scope || !LinkageName || !Scope ||
602 !isa<MDString>(Scope))
603 return false;
604
605 // Compare to the RHS.
606 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
607 LinkageName == RHS->getRawLinkageName();
608 }
609};
610
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000611template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000612 Metadata *Scope;
613 Metadata *File;
614 unsigned Line;
615 unsigned Column;
616
617 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
618 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000619 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000620 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000621 Column(N->getColumn()) {}
622
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000623 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000624 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000625 Line == RHS->getLine() && Column == RHS->getColumn();
626 }
627 unsigned getHashValue() const {
628 return hash_combine(Scope, File, Line, Column);
629 }
630};
631
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000632template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000633 Metadata *Scope;
634 Metadata *File;
635 unsigned Discriminator;
636
637 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
638 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000639 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000640 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000641 Discriminator(N->getDiscriminator()) {}
642
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000643 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000644 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000645 Discriminator == RHS->getDiscriminator();
646 }
647 unsigned getHashValue() const {
648 return hash_combine(Scope, File, Discriminator);
649 }
650};
651
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000652template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653 Metadata *Scope;
654 Metadata *File;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000655 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000656 unsigned Line;
657
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000658 MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000659 : Scope(Scope), File(File), Name(Name), Line(Line) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000660 MDNodeKeyImpl(const DINamespace *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000661 : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000662 Line(N->getLine()) {}
663
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000664 bool isKeyOf(const DINamespace *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000665 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000666 Name == RHS->getRawName() && Line == RHS->getLine();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000667 }
668 unsigned getHashValue() const {
669 return hash_combine(Scope, File, Name, Line);
670 }
671};
672
Adrian Prantlab1243f2015-06-29 23:03:47 +0000673template <> struct MDNodeKeyImpl<DIModule> {
674 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000675 MDString *Name;
676 MDString *ConfigurationMacros;
677 MDString *IncludePath;
678 MDString *ISysRoot;
679 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
680 MDString *IncludePath, MDString *ISysRoot)
681 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
682 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000683 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000684 : Scope(N->getRawScope()), Name(N->getRawName()),
685 ConfigurationMacros(N->getRawConfigurationMacros()),
686 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000687
688 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000689 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
690 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
691 IncludePath == RHS->getRawIncludePath() &&
692 ISysRoot == RHS->getRawISysRoot();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000693 }
694 unsigned getHashValue() const {
695 return hash_combine(Scope, Name,
696 ConfigurationMacros, IncludePath, ISysRoot);
697 }
698};
699
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000700template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000701 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000702 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000703
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000704 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000705 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000706 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000707
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000708 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000709 return Name == RHS->getRawName() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000710 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000711 unsigned getHashValue() const { return hash_combine(Name, Type); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000712};
713
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000714template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000715 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000716 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000717 Metadata *Type;
718 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000719
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000720 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000721 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000722 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000723 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000724 Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000725
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000726 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000727 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000728 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000729 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000730 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000731};
732
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000733template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000734 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000735 MDString *Name;
736 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000737 Metadata *File;
738 unsigned Line;
739 Metadata *Type;
740 bool IsLocalToUnit;
741 bool IsDefinition;
742 Metadata *Variable;
743 Metadata *StaticDataMemberDeclaration;
744
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000745 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000746 Metadata *File, unsigned Line, Metadata *Type,
747 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
748 Metadata *StaticDataMemberDeclaration)
749 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
750 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
751 IsDefinition(IsDefinition), Variable(Variable),
752 StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000753 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000754 : Scope(N->getRawScope()), Name(N->getRawName()),
755 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000756 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000757 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000758 Variable(N->getRawVariable()),
759 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000760
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000761 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000762 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
763 LinkageName == RHS->getRawLinkageName() &&
764 File == RHS->getRawFile() && Line == RHS->getLine() &&
765 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000766 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000767 Variable == RHS->getRawVariable() &&
768 StaticDataMemberDeclaration ==
769 RHS->getRawStaticDataMemberDeclaration();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000770 }
771 unsigned getHashValue() const {
772 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
773 IsLocalToUnit, IsDefinition, Variable,
774 StaticDataMemberDeclaration);
775 }
776};
777
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000778template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000779 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000780 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000781 Metadata *File;
782 unsigned Line;
783 Metadata *Type;
784 unsigned Arg;
785 unsigned Flags;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000786
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000787 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000788 Metadata *Type, unsigned Arg, unsigned Flags)
789 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
790 Flags(Flags) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000791 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000792 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000793 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
794 Flags(N->getFlags()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000795
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000796 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000797 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000798 File == RHS->getRawFile() && Line == RHS->getLine() &&
799 Type == RHS->getRawType() && Arg == RHS->getArg() &&
800 Flags == RHS->getFlags();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000801 }
802 unsigned getHashValue() const {
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000803 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000804 }
805};
806
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000807template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000808 ArrayRef<uint64_t> Elements;
809
810 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000811 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000812
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000813 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000814 return Elements == RHS->getElements();
815 }
816 unsigned getHashValue() const {
817 return hash_combine_range(Elements.begin(), Elements.end());
818 }
819};
820
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000821template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000822 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000823 Metadata *File;
824 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000825 MDString *GetterName;
826 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000827 unsigned Attributes;
828 Metadata *Type;
829
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000830 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
831 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000832 Metadata *Type)
833 : Name(Name), File(File), Line(Line), GetterName(GetterName),
834 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000835 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000836 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
837 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000838 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000839
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000840 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000841 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
842 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
843 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000844 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000845 }
846 unsigned getHashValue() const {
847 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
848 Type);
849 }
850};
851
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000852template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000853 unsigned Tag;
854 Metadata *Scope;
855 Metadata *Entity;
856 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000857 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000858
859 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000860 MDString *Name)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000861 : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000862 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000863 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000864 Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000865
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000866 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000867 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
868 Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000869 Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000870 }
871 unsigned getHashValue() const {
872 return hash_combine(Tag, Scope, Entity, Line, Name);
873 }
874};
875
Amjad Abouda9bcf162015-12-10 12:56:35 +0000876template <> struct MDNodeKeyImpl<DIMacro> {
877 unsigned MIType;
878 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000879 MDString *Name;
880 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +0000881
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000882 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +0000883 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
884 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000885 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
886 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +0000887
888 bool isKeyOf(const DIMacro *RHS) const {
889 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000890 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000891 }
892 unsigned getHashValue() const {
893 return hash_combine(MIType, Line, Name, Value);
894 }
895};
896
897template <> struct MDNodeKeyImpl<DIMacroFile> {
898 unsigned MIType;
899 unsigned Line;
900 Metadata *File;
901 Metadata *Elements;
902
903 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
904 Metadata *Elements)
905 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
906 MDNodeKeyImpl(const DIMacroFile *N)
907 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
908 Elements(N->getRawElements()) {}
909
910 bool isKeyOf(const DIMacroFile *RHS) const {
911 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
912 File == RHS->getRawFile() && File == RHS->getRawElements();
913 }
914 unsigned getHashValue() const {
915 return hash_combine(MIType, Line, File, Elements);
916 }
917};
918
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000919/// \brief DenseMapInfo for MDNode subclasses.
920template <class NodeTy> struct MDNodeInfo {
921 typedef MDNodeKeyImpl<NodeTy> KeyTy;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000922 typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000923 static inline NodeTy *getEmptyKey() {
924 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000925 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000926 static inline NodeTy *getTombstoneKey() {
927 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000928 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000929 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
930 static unsigned getHashValue(const NodeTy *N) {
931 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000932 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000933 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
934 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
935 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000936 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000937 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000938 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000939 if (LHS == RHS)
940 return true;
941 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
942 return false;
943 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000944 }
945};
946
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000947#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
948#include "llvm/IR/Metadata.def"
949
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +0000950/// \brief Map-like storage for metadata attachments.
951class MDAttachmentMap {
952 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
953
954public:
955 bool empty() const { return Attachments.empty(); }
956 size_t size() const { return Attachments.size(); }
957
958 /// \brief Get a particular attachment (if any).
959 MDNode *lookup(unsigned ID) const;
960
961 /// \brief Set an attachment to a particular node.
962 ///
963 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
964 /// ID (if anyway).
965 void set(unsigned ID, MDNode &MD);
966
967 /// \brief Remove an attachment.
968 ///
969 /// Remove the attachment at \c ID, if any.
970 void erase(unsigned ID);
971
972 /// \brief Copy out all the attachments.
973 ///
974 /// Copies all the current attachments into \c Result, sorting by attachment
975 /// ID. This function does \em not clear \c Result.
976 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
977
978 /// \brief Erase matching attachments.
979 ///
980 /// Erases all attachments matching the \c shouldRemove predicate.
981 template <class PredTy> void remove_if(PredTy shouldRemove) {
982 Attachments.erase(
983 std::remove_if(Attachments.begin(), Attachments.end(), shouldRemove),
984 Attachments.end());
985 }
986};
987
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000988class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +0000989public:
Owen Anderson8e89e412010-09-08 18:03:32 +0000990 /// OwnedModules - The set of modules instantiated in this context, and which
991 /// will be automatically deleted if this context is deleted.
992 SmallPtrSet<Module*, 4> OwnedModules;
993
Bob Wilsona594fab2013-02-11 05:37:07 +0000994 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
995 void *InlineAsmDiagContext;
Quentin Colombetb4c44d22013-12-17 17:47:22 +0000996
997 LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
998 void *DiagnosticContext;
Duncan P. N. Exon Smith30c92422014-10-01 18:36:03 +0000999 bool RespectDiagnosticFilters;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001000
Juergen Ributzka34390c72014-05-16 02:33:15 +00001001 LLVMContext::YieldCallbackTy YieldCallback;
1002 void *YieldOpaqueHandle;
1003
Benjamin Kramer8e5dc532014-12-06 13:12:56 +00001004 typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001005 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001006
Benjamin Kramer8e5dc532014-12-06 13:12:56 +00001007 typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
Owen Andersonc277dc42009-07-16 19:05:41 +00001008 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001009
Bill Wendling4607f4b2012-12-20 01:36:59 +00001010 FoldingSet<AttributeImpl> AttrsSet;
Bill Wendling6848e382012-12-19 22:42:22 +00001011 FoldingSet<AttributeSetImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001012 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001013
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001014 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001015 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1016 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001017
Owen Anderson7349ab92015-06-01 22:24:01 +00001018 DenseMap<const Value*, ValueName*> ValueNames;
1019
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001020#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1021 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001022#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001023
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001024 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001025 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001026
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001027 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1028 // aren't in the MDNodeSet, but they're still shared between objects, so no
1029 // one object can destroy them. This set allows us to at least destroy them
1030 // on Context destruction.
Duncan P. N. Exon Smith2bc00f42015-01-19 23:13:14 +00001031 SmallPtrSet<MDNode *, 1> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001032
David Blaikiecb2818f2014-11-25 02:26:22 +00001033 DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001034
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001035 typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001036 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +00001037
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001038 typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001039 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +00001040
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001041 typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001042 VectorConstantsTy VectorConstants;
Owen Anderson0348a132009-07-24 00:36:24 +00001043
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001044 DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
1045
1046 DenseMap<Type*, UndefValue*> UVConstants;
Owen Andersonc8c30262009-07-31 22:45:43 +00001047
Chris Lattner3756b912012-01-23 22:57:10 +00001048 StringMap<ConstantDataSequential*> CDSConstants;
1049
Chandler Carruth6a936922014-01-19 02:13:50 +00001050 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1051 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001052 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001053
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001054 ConstantUniqueMap<InlineAsm> InlineAsms;
1055
Owen Anderson2ad52172009-07-21 02:47:59 +00001056 ConstantInt *TheTrueVal;
1057 ConstantInt *TheFalseVal;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001058
David Majnemer2dd41c52015-11-16 20:55:57 +00001059 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001060
Dan Gohman97d2cb82009-08-25 16:00:35 +00001061 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001062 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001063 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001064 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Dan Gohman97d2cb82009-08-25 16:00:35 +00001065
Chris Lattner07bd69c2011-07-15 05:49:15 +00001066
1067 /// TypeAllocator - All dynamically allocated types are allocated from this.
1068 /// They live forever until the context is torn down.
1069 BumpPtrAllocator TypeAllocator;
1070
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001071 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001072
1073 typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
1074 FunctionTypeSet FunctionTypes;
1075 typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
1076 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001077 StringMap<StructType*> NamedStructTypes;
1078 unsigned NamedStructTypesUniqueID;
1079
1080 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1081 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1082 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1083 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001084
Jeffrey Yasskin28f24482009-12-17 19:55:06 +00001085
Owen Andersone8f21852009-08-18 18:28:58 +00001086 /// ValueHandles - This map keeps track of all of the value handles that are
1087 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001088 /// whether or not a value has an entry in this map.
Owen Andersone8f21852009-08-18 18:28:58 +00001089 typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
1090 ValueHandlesTy ValueHandles;
1091
Chris Lattnera0566972009-12-29 09:01:33 +00001092 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1093 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001094
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001095 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001096 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001097
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001098 /// Collection of per-function metadata used in this context.
1099 DenseMap<const Function *, MDAttachmentMap> FunctionMetadata;
1100
Diego Novillof5041ce2014-03-03 20:06:11 +00001101 /// DiscriminatorTable - This table maps file:line locations to an
1102 /// integer representing the next DWARF path discriminator to assign to
1103 /// instructions in different blocks at the same location.
1104 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1105
Chris Lattner8cb2aeb2010-04-01 00:37:44 +00001106 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1107 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames2b453952015-01-16 20:07:33 +00001108
Sanjoy Das9303c242015-09-24 19:14:18 +00001109 /// \brief A set of interned tags for operand bundles. The StringMap maps
1110 /// bundle tags to their IDs.
1111 ///
1112 /// \see LLVMContext::getOperandBundleTagID
1113 StringMap<uint32_t> BundleTagCache;
1114
1115 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1116 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1117 uint32_t getOperandBundleTagID(StringRef Tag) const;
1118
Mehdi Amini599ebf22016-01-08 02:28:20 +00001119 /// Maintain the GC name for each function.
1120 ///
1121 /// This saves allocating an additional word in Function for programs which
1122 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1123 /// clients which do use GC.
1124 DenseMap<const Function*, std::string> GCNames;
1125
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001126 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1127 /// not.
1128 bool DiscardValueNames = false;
1129
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001130 LLVMContextImpl(LLVMContext &C);
1131 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001132
1133 /// Destroy the ConstantArrays if they are not used.
1134 void dropTriviallyDeadConstantArrays();
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001135};
1136
Alexander Kornienkof00654e2015-06-23 09:49:53 +00001137}
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001138
Owen Anderson36f62e52009-06-30 17:06:46 +00001139#endif