blob: e808a60aa1b5695c69badf1b7455293863e1cf3e [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"
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +000036#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000037
Owen Anderson20b34ac2009-07-16 18:04:31 +000038namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000039
Owen Anderson20b34ac2009-07-16 18:04:31 +000040class ConstantInt;
Owen Andersonc277dc42009-07-16 19:05:41 +000041class ConstantFP;
Diego Novillo7f8af8b2014-05-22 14:19:46 +000042class DiagnosticInfoOptimizationRemark;
43class DiagnosticInfoOptimizationRemarkMissed;
44class DiagnosticInfoOptimizationRemarkAnalysis;
Philip Reames2b453952015-01-16 20:07:33 +000045class GCStrategy;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000046class LLVMContext;
Owen Anderson20b34ac2009-07-16 18:04:31 +000047class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000048class Value;
Owen Anderson20b34ac2009-07-16 18:04:31 +000049
Benjamin Kramer079b96e2013-09-11 18:05:11 +000050struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000051 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 Carruth71bd7d12012-03-04 12:02:57 +000062 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000063 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000064 static bool isEqual(const APInt &LHS, const APInt &RHS) {
65 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
66 }
Owen Anderson20b34ac2009-07-16 18:04:31 +000067};
68
Benjamin Kramer079b96e2013-09-11 18:05:11 +000069struct DenseMapAPFloatKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000070 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 Carruth71bd7d12012-03-04 12:02:57 +000073 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000074 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000075 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
76 return LHS.bitwiseIsEqual(RHS);
77 }
Owen Andersonc277dc42009-07-16 19:05:41 +000078};
79
Benjamin Kramer079b96e2013-09-11 18:05:11 +000080struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000081 struct KeyTy {
82 ArrayRef<Type*> ETypes;
83 bool isPacked;
84 KeyTy(const ArrayRef<Type*>& E, bool P) :
85 ETypes(E), isPacked(P) {}
Rafael Espindola334b73f2014-11-21 18:53:05 +000086 KeyTy(const StructType *ST)
87 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Jay Foad529776c2012-02-23 09:17:40 +000088 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 Carruth1d03a3b2012-03-01 18:55:25 +0000106 return hash_combine(hash_combine_range(Key.ETypes.begin(),
107 Key.ETypes.end()),
108 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000109 }
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 Kramer079b96e2013-09-11 18:05:11 +0000123struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000124 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 Espindolae973fd42014-11-21 19:03:35 +0000130 KeyTy(const FunctionType *FT)
131 : ReturnType(FT->getReturnType()), Params(FT->params()),
132 isVarArg(FT->isVarArg()) {}
Jay Foad529776c2012-02-23 09:17:40 +0000133 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 Carruth1d03a3b2012-03-01 18:55:25 +0000153 return hash_combine(Key.ReturnType,
154 hash_combine_range(Key.Params.begin(),
155 Key.Params.end()),
156 Key.isVarArg);
Jay Foad529776c2012-02-23 09:17:40 +0000157 }
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 Smith93e983e2015-01-19 22:53:18 +0000171/// \brief Structure for hashing arbitrary MDNode operands.
172class MDNodeOpsKey {
173 ArrayRef<Metadata *> RawOps;
174 ArrayRef<MDOperand> Ops;
175
176 unsigned Hash;
177
178protected:
179 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
180 : RawOps(Ops), Hash(calculateHash(Ops)) {}
181
182 template <class NodeTy>
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000183 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000184 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000185
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000186 template <class NodeTy>
187 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000188 if (getHash() != RHS->getHash())
189 return false;
190
191 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000192 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
193 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000194 }
195
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000196 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000197
198private:
199 template <class T>
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000200 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
201 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000202 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000203 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000204 }
205
206 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
207
208public:
209 unsigned getHash() const { return Hash; }
210};
211
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000212template <class NodeTy> struct MDNodeKeyImpl;
213template <class NodeTy> struct MDNodeInfo;
214
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000215/// Configuration point for MDNodeInfo::isEqual().
216template <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 Smith118632d2015-01-12 20:09:34 +0000226/// \brief DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000227///
228/// Note that we don't need the is-function-local bit, since that's implicit in
229/// the operands.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000230template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
231 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
232 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000233
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000234 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000235
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000236 unsigned getHashValue() const { return getHash(); }
237
238 static unsigned calculateHash(MDTuple *N) {
239 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000240 }
241};
242
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000243/// \brief DenseMapInfo for DILocation.
244template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000245 unsigned Line;
246 unsigned Column;
247 Metadata *Scope;
248 Metadata *InlinedAt;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000249
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000250 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
251 Metadata *InlinedAt)
252 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000253
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000254 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000255 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
256 InlinedAt(L->getRawInlinedAt()) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000257
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000258 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000259 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000260 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000261 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000262 unsigned getHashValue() const {
263 return hash_combine(Line, Column, Scope, InlinedAt);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000264 }
265};
266
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000267/// \brief DenseMapInfo for GenericDINode.
268template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000269 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000270 MDString *Header;
271 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000272 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000273 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000274 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000275
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000276 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000277 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000278 compareOps(RHS, 1);
279 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000280
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000281 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
282
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000283 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000284 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000285 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000286};
287
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000288template <> struct MDNodeKeyImpl<DISubrange> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000289 int64_t Count;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000290 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000291
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000292 MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
293 : Count(Count), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000294 MDNodeKeyImpl(const DISubrange *N)
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000295 : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000296
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000297 bool isKeyOf(const DISubrange *RHS) const {
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000298 return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000299 }
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000300 unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000301};
302
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000303template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000304 int64_t Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000305 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000306
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000307 MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000308 MDNodeKeyImpl(const DIEnumerator *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000309 : Value(N->getValue()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000310
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000311 bool isKeyOf(const DIEnumerator *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000312 return Value == RHS->getValue() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000313 }
314 unsigned getHashValue() const { return hash_combine(Value, Name); }
315};
316
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000317template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000318 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000319 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000320 uint64_t SizeInBits;
321 uint64_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000322 unsigned Encoding;
323
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000324 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000325 uint64_t AlignInBits, unsigned Encoding)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000326 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
327 Encoding(Encoding) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000328 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000329 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000330 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
331
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000332 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000333 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000334 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 Smitha9308c42015-04-29 16:38:44 +0000343template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000344 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000345 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000346 Metadata *File;
347 unsigned Line;
348 Metadata *Scope;
349 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000350 uint64_t SizeInBits;
351 uint64_t AlignInBits;
352 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000353 unsigned Flags;
354 Metadata *ExtraData;
355
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000356 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000357 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
358 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000359 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 Smitha9308c42015-04-29 16:38:44 +0000363 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000364 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000365 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 Smith01fc1762015-02-10 00:52:32 +0000369
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000370 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000371 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000372 File == RHS->getRawFile() && Line == RHS->getLine() &&
373 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000374 SizeInBits == RHS->getSizeInBits() &&
375 AlignInBits == RHS->getAlignInBits() &&
376 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000377 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000378 }
379 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000380 // 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().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000383 if (Tag == dwarf::DW_TAG_member && Name)
384 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
385 if (CT->getRawIdentifier())
386 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000387
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000388 // Intentionally computes the hash on a subset of the operands for
389 // performance reason. The subset has to be significant enough to avoid
390 // collision "most of the time". There is no correctness issue in case of
391 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000392 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000393 }
394};
395
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000396template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
397 typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
398 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
399 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
400 }
401 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
402 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
403 RHS);
404 }
405
406 /// Subprograms compare equal if they declare the same function in an ODR
407 /// type.
408 static bool isODRMember(unsigned Tag, const Metadata *Scope,
409 const MDString *Name, const DIDerivedType *RHS) {
410 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000411 if (Tag != dwarf::DW_TAG_member || !Name)
412 return false;
413
414 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
415 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000416 return false;
417
418 // Compare to the RHS.
419 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
420 Scope == RHS->getRawScope();
421 }
422};
423
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000424template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000425 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000426 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000427 Metadata *File;
428 unsigned Line;
429 Metadata *Scope;
430 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000431 uint64_t SizeInBits;
432 uint64_t AlignInBits;
433 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000434 unsigned Flags;
435 Metadata *Elements;
436 unsigned RuntimeLang;
437 Metadata *VTableHolder;
438 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000439 MDString *Identifier;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000440
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000441 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000442 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
443 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000444 Metadata *Elements, unsigned RuntimeLang,
445 Metadata *VTableHolder, Metadata *TemplateParams,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000446 MDString *Identifier)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000447 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
448 BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
449 OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
450 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
451 TemplateParams(TemplateParams), Identifier(Identifier) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000452 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000453 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000454 Line(N->getLine()), Scope(N->getRawScope()),
455 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
456 AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
457 Flags(N->getFlags()), Elements(N->getRawElements()),
458 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
459 TemplateParams(N->getRawTemplateParams()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000460 Identifier(N->getRawIdentifier()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000461
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000462 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000463 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000464 File == RHS->getRawFile() && Line == RHS->getLine() &&
465 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000466 SizeInBits == RHS->getSizeInBits() &&
467 AlignInBits == RHS->getAlignInBits() &&
468 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000469 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000470 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000471 VTableHolder == RHS->getRawVTableHolder() &&
472 TemplateParams == RHS->getRawTemplateParams() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000473 Identifier == RHS->getRawIdentifier();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000474 }
475 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000476 // Intentionally computes the hash on a subset of the operands for
477 // performance reason. The subset has to be significant enough to avoid
478 // collision "most of the time". There is no correctness issue in case of
479 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000480 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
481 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000482 }
483};
484
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000485template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000486 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000487 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000488 Metadata *TypeArray;
489
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000490 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
491 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000492 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000493 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000494
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000495 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000496 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
497 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000498 }
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000499 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000500};
501
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000502template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000503 MDString *Filename;
504 MDString *Directory;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000505
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000506 MDNodeKeyImpl(MDString *Filename, MDString *Directory)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000507 : Filename(Filename), Directory(Directory) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000508 MDNodeKeyImpl(const DIFile *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000509 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000510
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000511 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000512 return Filename == RHS->getRawFilename() &&
513 Directory == RHS->getRawDirectory();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000514 }
515 unsigned getHashValue() const { return hash_combine(Filename, Directory); }
516};
517
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000518template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000519 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000520 MDString *Name;
521 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000522 Metadata *File;
523 unsigned Line;
524 Metadata *Type;
525 bool IsLocalToUnit;
526 bool IsDefinition;
527 unsigned ScopeLine;
528 Metadata *ContainingType;
529 unsigned Virtuality;
530 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000531 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000532 unsigned Flags;
533 bool IsOptimized;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000534 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000535 Metadata *TemplateParams;
536 Metadata *Declaration;
537 Metadata *Variables;
538
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000539 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000540 Metadata *File, unsigned Line, Metadata *Type,
541 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
542 Metadata *ContainingType, unsigned Virtuality,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000543 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
544 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
545 Metadata *Declaration, Metadata *Variables)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000546 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
547 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
548 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
549 ContainingType(ContainingType), Virtuality(Virtuality),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000550 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
551 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
552 TemplateParams(TemplateParams), Declaration(Declaration),
Peter Collingbourned4bff302015-11-05 22:03:56 +0000553 Variables(Variables) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000554 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000555 : Scope(N->getRawScope()), Name(N->getRawName()),
556 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000557 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000558 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000559 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000560 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000561 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
562 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
563 TemplateParams(N->getRawTemplateParams()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000564 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000565
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000566 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000567 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
568 LinkageName == RHS->getRawLinkageName() &&
569 File == RHS->getRawFile() && Line == RHS->getLine() &&
570 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000571 IsDefinition == RHS->isDefinition() &&
572 ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000573 ContainingType == RHS->getRawContainingType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000574 Virtuality == RHS->getVirtuality() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000575 VirtualIndex == RHS->getVirtualIndex() &&
576 ThisAdjustment == RHS->getThisAdjustment() &&
577 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
578 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000579 TemplateParams == RHS->getRawTemplateParams() &&
580 Declaration == RHS->getRawDeclaration() &&
581 Variables == RHS->getRawVariables();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000582 }
583 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000584 // If this is a declaration inside an ODR type, only hash the type and the
585 // name. Otherwise the hash will be stronger than
586 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000587 if (!IsDefinition && LinkageName)
588 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
589 if (CT->getRawIdentifier())
590 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000591
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000592 // Intentionally computes the hash on a subset of the operands for
593 // performance reason. The subset has to be significant enough to avoid
594 // collision "most of the time". There is no correctness issue in case of
595 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000596 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000597 }
598};
599
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000600template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
601 typedef MDNodeKeyImpl<DISubprogram> KeyTy;
602 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
603 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
604 LHS.LinkageName, RHS);
605 }
606 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
607 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
608 LHS->getRawLinkageName(), RHS);
609 }
610
611 /// Subprograms compare equal if they declare the same function in an ODR
612 /// type.
613 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
614 const MDString *LinkageName,
615 const DISubprogram *RHS) {
616 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000617 if (IsDefinition || !Scope || !LinkageName)
618 return false;
619
620 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
621 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000622 return false;
623
624 // Compare to the RHS.
625 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
626 LinkageName == RHS->getRawLinkageName();
627 }
628};
629
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000630template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000631 Metadata *Scope;
632 Metadata *File;
633 unsigned Line;
634 unsigned Column;
635
636 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
637 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000638 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000639 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000640 Column(N->getColumn()) {}
641
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000642 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000643 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000644 Line == RHS->getLine() && Column == RHS->getColumn();
645 }
646 unsigned getHashValue() const {
647 return hash_combine(Scope, File, Line, Column);
648 }
649};
650
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000651template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000652 Metadata *Scope;
653 Metadata *File;
654 unsigned Discriminator;
655
656 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
657 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000658 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000659 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000660 Discriminator(N->getDiscriminator()) {}
661
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000662 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000663 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000664 Discriminator == RHS->getDiscriminator();
665 }
666 unsigned getHashValue() const {
667 return hash_combine(Scope, File, Discriminator);
668 }
669};
670
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000671template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000672 Metadata *Scope;
673 Metadata *File;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000674 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000675 unsigned Line;
676
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000677 MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000678 : Scope(Scope), File(File), Name(Name), Line(Line) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000679 MDNodeKeyImpl(const DINamespace *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000680 : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000681 Line(N->getLine()) {}
682
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000683 bool isKeyOf(const DINamespace *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000684 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000685 Name == RHS->getRawName() && Line == RHS->getLine();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000686 }
687 unsigned getHashValue() const {
688 return hash_combine(Scope, File, Name, Line);
689 }
690};
691
Adrian Prantlab1243f2015-06-29 23:03:47 +0000692template <> struct MDNodeKeyImpl<DIModule> {
693 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000694 MDString *Name;
695 MDString *ConfigurationMacros;
696 MDString *IncludePath;
697 MDString *ISysRoot;
698 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
699 MDString *IncludePath, MDString *ISysRoot)
700 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
701 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000702 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000703 : Scope(N->getRawScope()), Name(N->getRawName()),
704 ConfigurationMacros(N->getRawConfigurationMacros()),
705 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000706
707 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000708 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
709 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
710 IncludePath == RHS->getRawIncludePath() &&
711 ISysRoot == RHS->getRawISysRoot();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000712 }
713 unsigned getHashValue() const {
714 return hash_combine(Scope, Name,
715 ConfigurationMacros, IncludePath, ISysRoot);
716 }
717};
718
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000719template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000720 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000721 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000722
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000723 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000724 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000725 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000726
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000727 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000728 return Name == RHS->getRawName() && Type == RHS->getRawType();
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(Name, Type); }
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<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000734 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000735 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000736 Metadata *Type;
737 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000738
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000739 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000740 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000741 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000742 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000743 Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000744
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000745 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000746 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000747 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000748 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000749 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000750};
751
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000752template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000753 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000754 MDString *Name;
755 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000756 Metadata *File;
757 unsigned Line;
758 Metadata *Type;
759 bool IsLocalToUnit;
760 bool IsDefinition;
761 Metadata *Variable;
762 Metadata *StaticDataMemberDeclaration;
763
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000764 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000765 Metadata *File, unsigned Line, Metadata *Type,
766 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
767 Metadata *StaticDataMemberDeclaration)
768 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
769 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
770 IsDefinition(IsDefinition), Variable(Variable),
771 StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000772 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000773 : Scope(N->getRawScope()), Name(N->getRawName()),
774 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000775 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000776 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000777 Variable(N->getRawVariable()),
778 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000779
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000780 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000781 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
782 LinkageName == RHS->getRawLinkageName() &&
783 File == RHS->getRawFile() && Line == RHS->getLine() &&
784 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000785 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000786 Variable == RHS->getRawVariable() &&
787 StaticDataMemberDeclaration ==
788 RHS->getRawStaticDataMemberDeclaration();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000789 }
790 unsigned getHashValue() const {
791 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
792 IsLocalToUnit, IsDefinition, Variable,
793 StaticDataMemberDeclaration);
794 }
795};
796
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000797template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000798 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000799 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000800 Metadata *File;
801 unsigned Line;
802 Metadata *Type;
803 unsigned Arg;
804 unsigned Flags;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000805
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000806 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000807 Metadata *Type, unsigned Arg, unsigned Flags)
808 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
809 Flags(Flags) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000810 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000811 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000812 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
813 Flags(N->getFlags()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000814
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000815 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000816 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000817 File == RHS->getRawFile() && Line == RHS->getLine() &&
818 Type == RHS->getRawType() && Arg == RHS->getArg() &&
819 Flags == RHS->getFlags();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000820 }
821 unsigned getHashValue() const {
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000822 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000823 }
824};
825
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000826template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000827 ArrayRef<uint64_t> Elements;
828
829 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000830 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000831
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000832 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000833 return Elements == RHS->getElements();
834 }
835 unsigned getHashValue() const {
836 return hash_combine_range(Elements.begin(), Elements.end());
837 }
838};
839
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000840template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000841 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000842 Metadata *File;
843 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000844 MDString *GetterName;
845 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000846 unsigned Attributes;
847 Metadata *Type;
848
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000849 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
850 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000851 Metadata *Type)
852 : Name(Name), File(File), Line(Line), GetterName(GetterName),
853 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000854 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000855 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
856 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000857 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000858
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000859 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000860 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
861 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
862 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000863 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000864 }
865 unsigned getHashValue() const {
866 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
867 Type);
868 }
869};
870
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000871template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000872 unsigned Tag;
873 Metadata *Scope;
874 Metadata *Entity;
875 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000876 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000877
878 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000879 MDString *Name)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000880 : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000881 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000882 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000883 Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000884
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000885 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000886 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
887 Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000888 Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000889 }
890 unsigned getHashValue() const {
891 return hash_combine(Tag, Scope, Entity, Line, Name);
892 }
893};
894
Amjad Abouda9bcf162015-12-10 12:56:35 +0000895template <> struct MDNodeKeyImpl<DIMacro> {
896 unsigned MIType;
897 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000898 MDString *Name;
899 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +0000900
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000901 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +0000902 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
903 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000904 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
905 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +0000906
907 bool isKeyOf(const DIMacro *RHS) const {
908 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000909 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000910 }
911 unsigned getHashValue() const {
912 return hash_combine(MIType, Line, Name, Value);
913 }
914};
915
916template <> struct MDNodeKeyImpl<DIMacroFile> {
917 unsigned MIType;
918 unsigned Line;
919 Metadata *File;
920 Metadata *Elements;
921
922 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
923 Metadata *Elements)
924 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
925 MDNodeKeyImpl(const DIMacroFile *N)
926 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
927 Elements(N->getRawElements()) {}
928
929 bool isKeyOf(const DIMacroFile *RHS) const {
930 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +0000931 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000932 }
933 unsigned getHashValue() const {
934 return hash_combine(MIType, Line, File, Elements);
935 }
936};
937
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000938/// \brief DenseMapInfo for MDNode subclasses.
939template <class NodeTy> struct MDNodeInfo {
940 typedef MDNodeKeyImpl<NodeTy> KeyTy;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000941 typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000942 static inline NodeTy *getEmptyKey() {
943 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000944 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000945 static inline NodeTy *getTombstoneKey() {
946 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000947 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000948 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
949 static unsigned getHashValue(const NodeTy *N) {
950 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000951 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000952 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
953 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
954 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000955 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000956 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000957 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000958 if (LHS == RHS)
959 return true;
960 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
961 return false;
962 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000963 }
964};
965
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000966#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
967#include "llvm/IR/Metadata.def"
968
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +0000969/// \brief Map-like storage for metadata attachments.
970class MDAttachmentMap {
971 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
972
973public:
974 bool empty() const { return Attachments.empty(); }
975 size_t size() const { return Attachments.size(); }
976
977 /// \brief Get a particular attachment (if any).
978 MDNode *lookup(unsigned ID) const;
979
980 /// \brief Set an attachment to a particular node.
981 ///
982 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
983 /// ID (if anyway).
984 void set(unsigned ID, MDNode &MD);
985
986 /// \brief Remove an attachment.
987 ///
988 /// Remove the attachment at \c ID, if any.
989 void erase(unsigned ID);
990
991 /// \brief Copy out all the attachments.
992 ///
993 /// Copies all the current attachments into \c Result, sorting by attachment
994 /// ID. This function does \em not clear \c Result.
995 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
996
997 /// \brief Erase matching attachments.
998 ///
999 /// Erases all attachments matching the \c shouldRemove predicate.
1000 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemerc7004902016-08-12 04:32:37 +00001001 Attachments.erase(remove_if(Attachments, shouldRemove), Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001002 }
1003};
1004
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001005/// Multimap-like storage for metadata attachments for globals. This differs
1006/// from MDAttachmentMap in that it allows multiple attachments per metadata
1007/// kind.
1008class MDGlobalAttachmentMap {
1009 struct Attachment {
1010 unsigned MDKind;
1011 TrackingMDNodeRef Node;
1012 };
1013 SmallVector<Attachment, 1> Attachments;
1014
1015public:
1016 bool empty() const { return Attachments.empty(); }
1017
1018 /// Appends all attachments with the given ID to \c Result in insertion order.
1019 /// If the global has no attachments with the given ID, or if ID is invalid,
1020 /// leaves Result unchanged.
1021 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1022
1023 void insert(unsigned ID, MDNode &MD);
1024 void erase(unsigned ID);
1025
1026 /// Appends all attachments for the global to \c Result, sorting by attachment
1027 /// ID. Attachments with the same ID appear in insertion order. This function
1028 /// does \em not clear \c Result.
1029 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1030};
1031
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001032class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001033public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001034 /// OwnedModules - The set of modules instantiated in this context, and which
1035 /// will be automatically deleted if this context is deleted.
1036 SmallPtrSet<Module*, 4> OwnedModules;
1037
Bob Wilsona594fab2013-02-11 05:37:07 +00001038 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
1039 void *InlineAsmDiagContext;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001040
1041 LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
1042 void *DiagnosticContext;
Duncan P. N. Exon Smith30c92422014-10-01 18:36:03 +00001043 bool RespectDiagnosticFilters;
Adam Nemetaad81602016-07-15 17:23:20 +00001044 bool DiagnosticHotnessRequested;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001045
Juergen Ributzka34390c72014-05-16 02:33:15 +00001046 LLVMContext::YieldCallbackTy YieldCallback;
1047 void *YieldOpaqueHandle;
1048
Benjamin Kramer8e5dc532014-12-06 13:12:56 +00001049 typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001050 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001051
Benjamin Kramer8e5dc532014-12-06 13:12:56 +00001052 typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
Owen Andersonc277dc42009-07-16 19:05:41 +00001053 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001054
Bill Wendling4607f4b2012-12-20 01:36:59 +00001055 FoldingSet<AttributeImpl> AttrsSet;
Bill Wendling6848e382012-12-19 22:42:22 +00001056 FoldingSet<AttributeSetImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001057 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001058
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001059 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001060 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1061 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001062
Owen Anderson7349ab92015-06-01 22:24:01 +00001063 DenseMap<const Value*, ValueName*> ValueNames;
1064
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001065#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1066 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001067#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001068
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001069 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001070 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001071
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001072 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1073 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001074 // one object can destroy them. Keep track of them here so we can delete
1075 // them on context teardown.
1076 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001077
David Blaikiecb2818f2014-11-25 02:26:22 +00001078 DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001079
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001080 typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001081 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +00001082
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001083 typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001084 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +00001085
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001086 typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001087 VectorConstantsTy VectorConstants;
Owen Anderson0348a132009-07-24 00:36:24 +00001088
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001089 DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
1090
1091 DenseMap<Type*, UndefValue*> UVConstants;
Owen Andersonc8c30262009-07-31 22:45:43 +00001092
Chris Lattner3756b912012-01-23 22:57:10 +00001093 StringMap<ConstantDataSequential*> CDSConstants;
1094
Chandler Carruth6a936922014-01-19 02:13:50 +00001095 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1096 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001097 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001098
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001099 ConstantUniqueMap<InlineAsm> InlineAsms;
1100
Owen Anderson2ad52172009-07-21 02:47:59 +00001101 ConstantInt *TheTrueVal;
1102 ConstantInt *TheFalseVal;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001103
David Majnemer2dd41c52015-11-16 20:55:57 +00001104 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001105
Dan Gohman97d2cb82009-08-25 16:00:35 +00001106 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001107 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001108 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001109 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Dan Gohman97d2cb82009-08-25 16:00:35 +00001110
Chris Lattner07bd69c2011-07-15 05:49:15 +00001111
1112 /// TypeAllocator - All dynamically allocated types are allocated from this.
1113 /// They live forever until the context is torn down.
1114 BumpPtrAllocator TypeAllocator;
1115
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001116 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001117
1118 typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
1119 FunctionTypeSet FunctionTypes;
1120 typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
1121 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001122 StringMap<StructType*> NamedStructTypes;
1123 unsigned NamedStructTypesUniqueID;
1124
1125 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1126 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1127 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1128 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001129
Jeffrey Yasskin28f24482009-12-17 19:55:06 +00001130
Owen Andersone8f21852009-08-18 18:28:58 +00001131 /// ValueHandles - This map keeps track of all of the value handles that are
1132 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001133 /// whether or not a value has an entry in this map.
Owen Andersone8f21852009-08-18 18:28:58 +00001134 typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
1135 ValueHandlesTy ValueHandles;
1136
Chris Lattnera0566972009-12-29 09:01:33 +00001137 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1138 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001139
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001140 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001141 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001142
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001143 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001144 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001145
Diego Novillof5041ce2014-03-03 20:06:11 +00001146 /// DiscriminatorTable - This table maps file:line locations to an
1147 /// integer representing the next DWARF path discriminator to assign to
1148 /// instructions in different blocks at the same location.
1149 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1150
Chris Lattner8cb2aeb2010-04-01 00:37:44 +00001151 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1152 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames2b453952015-01-16 20:07:33 +00001153
Sanjoy Das9303c242015-09-24 19:14:18 +00001154 /// \brief A set of interned tags for operand bundles. The StringMap maps
1155 /// bundle tags to their IDs.
1156 ///
1157 /// \see LLVMContext::getOperandBundleTagID
1158 StringMap<uint32_t> BundleTagCache;
1159
1160 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1161 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1162 uint32_t getOperandBundleTagID(StringRef Tag) const;
1163
Mehdi Amini599ebf22016-01-08 02:28:20 +00001164 /// Maintain the GC name for each function.
1165 ///
1166 /// This saves allocating an additional word in Function for programs which
1167 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1168 /// clients which do use GC.
1169 DenseMap<const Function*, std::string> GCNames;
1170
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001171 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1172 /// not.
1173 bool DiscardValueNames = false;
1174
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001175 LLVMContextImpl(LLVMContext &C);
1176 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001177
1178 /// Destroy the ConstantArrays if they are not used.
1179 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001180
1181 /// \brief Access the object which manages optimization bisection for failure
1182 /// analysis.
1183 OptBisect &getOptBisect();
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001184};
1185
Alexander Kornienkof00654e2015-06-23 09:49:53 +00001186}
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001187
Owen Anderson36f62e52009-06-30 17:06:46 +00001188#endif