blob: 6f2f60110cafd02c2a03bc216cd9d67b807fc2ae [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"
Adam Nemeta62b7e12016-09-27 20:55:07 +000036#include "llvm/Support/YAMLTraits.h"
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +000037#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000038
Owen Anderson20b34ac2009-07-16 18:04:31 +000039namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000040
Owen Anderson20b34ac2009-07-16 18:04:31 +000041class ConstantInt;
Owen Andersonc277dc42009-07-16 19:05:41 +000042class ConstantFP;
Diego Novillo7f8af8b2014-05-22 14:19:46 +000043class DiagnosticInfoOptimizationRemark;
44class DiagnosticInfoOptimizationRemarkMissed;
45class DiagnosticInfoOptimizationRemarkAnalysis;
Philip Reames2b453952015-01-16 20:07:33 +000046class GCStrategy;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000047class LLVMContext;
Owen Anderson20b34ac2009-07-16 18:04:31 +000048class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000049class Value;
Owen Anderson20b34ac2009-07-16 18:04:31 +000050
Benjamin Kramer079b96e2013-09-11 18:05:11 +000051struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000052 static inline APInt getEmptyKey() {
53 APInt V(nullptr, 0);
54 V.VAL = 0;
55 return V;
56 }
57 static inline APInt getTombstoneKey() {
58 APInt V(nullptr, 0);
59 V.VAL = 1;
60 return V;
61 }
62 static unsigned getHashValue(const APInt &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000063 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000064 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000065 static bool isEqual(const APInt &LHS, const APInt &RHS) {
66 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
67 }
Owen Anderson20b34ac2009-07-16 18:04:31 +000068};
69
Benjamin Kramer079b96e2013-09-11 18:05:11 +000070struct DenseMapAPFloatKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000071 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
72 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
73 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000074 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000075 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000076 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
77 return LHS.bitwiseIsEqual(RHS);
78 }
Owen Andersonc277dc42009-07-16 19:05:41 +000079};
80
Benjamin Kramer079b96e2013-09-11 18:05:11 +000081struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000082 struct KeyTy {
83 ArrayRef<Type*> ETypes;
84 bool isPacked;
85 KeyTy(const ArrayRef<Type*>& E, bool P) :
86 ETypes(E), isPacked(P) {}
Rafael Espindola334b73f2014-11-21 18:53:05 +000087 KeyTy(const StructType *ST)
88 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Jay Foad529776c2012-02-23 09:17:40 +000089 bool operator==(const KeyTy& that) const {
90 if (isPacked != that.isPacked)
91 return false;
92 if (ETypes != that.ETypes)
93 return false;
94 return true;
95 }
96 bool operator!=(const KeyTy& that) const {
97 return !this->operator==(that);
98 }
99 };
100 static inline StructType* getEmptyKey() {
101 return DenseMapInfo<StructType*>::getEmptyKey();
102 }
103 static inline StructType* getTombstoneKey() {
104 return DenseMapInfo<StructType*>::getTombstoneKey();
105 }
106 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000107 return hash_combine(hash_combine_range(Key.ETypes.begin(),
108 Key.ETypes.end()),
109 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000110 }
111 static unsigned getHashValue(const StructType *ST) {
112 return getHashValue(KeyTy(ST));
113 }
114 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
115 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
116 return false;
117 return LHS == KeyTy(RHS);
118 }
119 static bool isEqual(const StructType *LHS, const StructType *RHS) {
120 return LHS == RHS;
121 }
122};
123
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000124struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000125 struct KeyTy {
126 const Type *ReturnType;
127 ArrayRef<Type*> Params;
128 bool isVarArg;
129 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
130 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindolae973fd42014-11-21 19:03:35 +0000131 KeyTy(const FunctionType *FT)
132 : ReturnType(FT->getReturnType()), Params(FT->params()),
133 isVarArg(FT->isVarArg()) {}
Jay Foad529776c2012-02-23 09:17:40 +0000134 bool operator==(const KeyTy& that) const {
135 if (ReturnType != that.ReturnType)
136 return false;
137 if (isVarArg != that.isVarArg)
138 return false;
139 if (Params != that.Params)
140 return false;
141 return true;
142 }
143 bool operator!=(const KeyTy& that) const {
144 return !this->operator==(that);
145 }
146 };
147 static inline FunctionType* getEmptyKey() {
148 return DenseMapInfo<FunctionType*>::getEmptyKey();
149 }
150 static inline FunctionType* getTombstoneKey() {
151 return DenseMapInfo<FunctionType*>::getTombstoneKey();
152 }
153 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000154 return hash_combine(Key.ReturnType,
155 hash_combine_range(Key.Params.begin(),
156 Key.Params.end()),
157 Key.isVarArg);
Jay Foad529776c2012-02-23 09:17:40 +0000158 }
159 static unsigned getHashValue(const FunctionType *FT) {
160 return getHashValue(KeyTy(FT));
161 }
162 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
163 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
164 return false;
165 return LHS == KeyTy(RHS);
166 }
167 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
168 return LHS == RHS;
169 }
170};
171
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000172/// \brief Structure for hashing arbitrary MDNode operands.
173class MDNodeOpsKey {
174 ArrayRef<Metadata *> RawOps;
175 ArrayRef<MDOperand> Ops;
176
177 unsigned Hash;
178
179protected:
180 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
181 : RawOps(Ops), Hash(calculateHash(Ops)) {}
182
183 template <class NodeTy>
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000184 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000185 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000186
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000187 template <class NodeTy>
188 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000189 if (getHash() != RHS->getHash())
190 return false;
191
192 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000193 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
194 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000195 }
196
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000197 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000198
199private:
200 template <class T>
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000201 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
202 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000203 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000204 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000205 }
206
207 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
208
209public:
210 unsigned getHash() const { return Hash; }
211};
212
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000213template <class NodeTy> struct MDNodeKeyImpl;
214template <class NodeTy> struct MDNodeInfo;
215
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000216/// Configuration point for MDNodeInfo::isEqual().
217template <class NodeTy> struct MDNodeSubsetEqualImpl {
218 typedef MDNodeKeyImpl<NodeTy> KeyTy;
219 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
220 return false;
221 }
222 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
223 return false;
224 }
225};
226
Duncan P. N. Exon Smith118632d2015-01-12 20:09:34 +0000227/// \brief DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000228///
229/// Note that we don't need the is-function-local bit, since that's implicit in
230/// the operands.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000231template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
232 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
233 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000234
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000235 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000236
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000237 unsigned getHashValue() const { return getHash(); }
238
239 static unsigned calculateHash(MDTuple *N) {
240 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000241 }
242};
243
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000244/// \brief DenseMapInfo for DILocation.
245template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000246 unsigned Line;
247 unsigned Column;
248 Metadata *Scope;
249 Metadata *InlinedAt;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000250
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000251 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
252 Metadata *InlinedAt)
253 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000254
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000255 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000256 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
257 InlinedAt(L->getRawInlinedAt()) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000258
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000259 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000260 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000261 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000262 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000263 unsigned getHashValue() const {
264 return hash_combine(Line, Column, Scope, InlinedAt);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000265 }
266};
267
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000268/// \brief DenseMapInfo for GenericDINode.
269template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000270 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000271 MDString *Header;
272 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000273 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000274 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000275 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000276
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000277 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000278 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000279 compareOps(RHS, 1);
280 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000281
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000282 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
283
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000284 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000285 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000286 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000287};
288
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000289template <> struct MDNodeKeyImpl<DISubrange> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000290 int64_t Count;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000291 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000292
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000293 MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
294 : Count(Count), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000295 MDNodeKeyImpl(const DISubrange *N)
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000296 : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000297
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000298 bool isKeyOf(const DISubrange *RHS) const {
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000299 return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000300 }
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000301 unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000302};
303
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000304template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000305 int64_t Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000306 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000307
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000308 MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000309 MDNodeKeyImpl(const DIEnumerator *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000310 : Value(N->getValue()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000311
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000312 bool isKeyOf(const DIEnumerator *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000313 return Value == RHS->getValue() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000314 }
315 unsigned getHashValue() const { return hash_combine(Value, Name); }
316};
317
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000318template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000319 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000320 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000321 uint64_t SizeInBits;
322 uint64_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000323 unsigned Encoding;
324
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000325 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000326 uint64_t AlignInBits, unsigned Encoding)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000327 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
328 Encoding(Encoding) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000329 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000330 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000331 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
332
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000333 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000334 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000335 SizeInBits == RHS->getSizeInBits() &&
336 AlignInBits == RHS->getAlignInBits() &&
337 Encoding == RHS->getEncoding();
338 }
339 unsigned getHashValue() const {
340 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
341 }
342};
343
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000344template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000345 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000346 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000347 Metadata *File;
348 unsigned Line;
349 Metadata *Scope;
350 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000351 uint64_t SizeInBits;
352 uint64_t AlignInBits;
353 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000354 unsigned Flags;
355 Metadata *ExtraData;
356
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000357 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000358 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
359 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000360 Metadata *ExtraData)
361 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
362 BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
363 OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000364 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000365 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000366 Line(N->getLine()), Scope(N->getRawScope()),
367 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
368 AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
369 Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000370
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000371 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000372 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000373 File == RHS->getRawFile() && Line == RHS->getLine() &&
374 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000375 SizeInBits == RHS->getSizeInBits() &&
376 AlignInBits == RHS->getAlignInBits() &&
377 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000378 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000379 }
380 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000381 // If this is a member inside an ODR type, only hash the type and the name.
382 // Otherwise the hash will be stronger than
383 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000384 if (Tag == dwarf::DW_TAG_member && Name)
385 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
386 if (CT->getRawIdentifier())
387 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000388
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000389 // Intentionally computes the hash on a subset of the operands for
390 // performance reason. The subset has to be significant enough to avoid
391 // collision "most of the time". There is no correctness issue in case of
392 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000393 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000394 }
395};
396
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000397template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
398 typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
399 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
400 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
401 }
402 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
403 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
404 RHS);
405 }
406
407 /// Subprograms compare equal if they declare the same function in an ODR
408 /// type.
409 static bool isODRMember(unsigned Tag, const Metadata *Scope,
410 const MDString *Name, const DIDerivedType *RHS) {
411 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000412 if (Tag != dwarf::DW_TAG_member || !Name)
413 return false;
414
415 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
416 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000417 return false;
418
419 // Compare to the RHS.
420 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
421 Scope == RHS->getRawScope();
422 }
423};
424
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000425template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000426 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000427 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000428 Metadata *File;
429 unsigned Line;
430 Metadata *Scope;
431 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000432 uint64_t SizeInBits;
433 uint64_t AlignInBits;
434 uint64_t OffsetInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000435 unsigned Flags;
436 Metadata *Elements;
437 unsigned RuntimeLang;
438 Metadata *VTableHolder;
439 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000440 MDString *Identifier;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000441
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000442 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000443 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
444 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000445 Metadata *Elements, unsigned RuntimeLang,
446 Metadata *VTableHolder, Metadata *TemplateParams,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000447 MDString *Identifier)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000448 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
449 BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
450 OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
451 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
452 TemplateParams(TemplateParams), Identifier(Identifier) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000453 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000454 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000455 Line(N->getLine()), Scope(N->getRawScope()),
456 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
457 AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
458 Flags(N->getFlags()), Elements(N->getRawElements()),
459 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
460 TemplateParams(N->getRawTemplateParams()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000461 Identifier(N->getRawIdentifier()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000462
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000463 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000464 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000465 File == RHS->getRawFile() && Line == RHS->getLine() &&
466 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000467 SizeInBits == RHS->getSizeInBits() &&
468 AlignInBits == RHS->getAlignInBits() &&
469 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000470 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000471 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000472 VTableHolder == RHS->getRawVTableHolder() &&
473 TemplateParams == RHS->getRawTemplateParams() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000474 Identifier == RHS->getRawIdentifier();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000475 }
476 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000477 // Intentionally computes the hash on a subset of the operands for
478 // performance reason. The subset has to be significant enough to avoid
479 // collision "most of the time". There is no correctness issue in case of
480 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000481 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
482 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000483 }
484};
485
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000486template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000487 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000488 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000489 Metadata *TypeArray;
490
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000491 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
492 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000493 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000494 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000495
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000496 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000497 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
498 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000499 }
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000500 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000501};
502
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000503template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000504 MDString *Filename;
505 MDString *Directory;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000506
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000507 MDNodeKeyImpl(MDString *Filename, MDString *Directory)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000508 : Filename(Filename), Directory(Directory) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000509 MDNodeKeyImpl(const DIFile *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000510 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000511
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000512 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000513 return Filename == RHS->getRawFilename() &&
514 Directory == RHS->getRawDirectory();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000515 }
516 unsigned getHashValue() const { return hash_combine(Filename, Directory); }
517};
518
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000519template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000520 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000521 MDString *Name;
522 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000523 Metadata *File;
524 unsigned Line;
525 Metadata *Type;
526 bool IsLocalToUnit;
527 bool IsDefinition;
528 unsigned ScopeLine;
529 Metadata *ContainingType;
530 unsigned Virtuality;
531 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000532 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000533 unsigned Flags;
534 bool IsOptimized;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000535 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536 Metadata *TemplateParams;
537 Metadata *Declaration;
538 Metadata *Variables;
539
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000540 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000541 Metadata *File, unsigned Line, Metadata *Type,
542 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
543 Metadata *ContainingType, unsigned Virtuality,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000544 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
545 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
546 Metadata *Declaration, Metadata *Variables)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000547 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
548 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
549 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
550 ContainingType(ContainingType), Virtuality(Virtuality),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000551 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
552 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
553 TemplateParams(TemplateParams), Declaration(Declaration),
Peter Collingbourned4bff302015-11-05 22:03:56 +0000554 Variables(Variables) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000555 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000556 : Scope(N->getRawScope()), Name(N->getRawName()),
557 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000558 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000559 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000560 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000561 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000562 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
563 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
564 TemplateParams(N->getRawTemplateParams()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000565 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000566
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000567 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000568 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
569 LinkageName == RHS->getRawLinkageName() &&
570 File == RHS->getRawFile() && Line == RHS->getLine() &&
571 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000572 IsDefinition == RHS->isDefinition() &&
573 ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000574 ContainingType == RHS->getRawContainingType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000575 Virtuality == RHS->getVirtuality() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000576 VirtualIndex == RHS->getVirtualIndex() &&
577 ThisAdjustment == RHS->getThisAdjustment() &&
578 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
579 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000580 TemplateParams == RHS->getRawTemplateParams() &&
581 Declaration == RHS->getRawDeclaration() &&
582 Variables == RHS->getRawVariables();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000583 }
584 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000585 // If this is a declaration inside an ODR type, only hash the type and the
586 // name. Otherwise the hash will be stronger than
587 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000588 if (!IsDefinition && LinkageName)
589 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
590 if (CT->getRawIdentifier())
591 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000592
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000593 // Intentionally computes the hash on a subset of the operands for
594 // performance reason. The subset has to be significant enough to avoid
595 // collision "most of the time". There is no correctness issue in case of
596 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000597 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000598 }
599};
600
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000601template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
602 typedef MDNodeKeyImpl<DISubprogram> KeyTy;
603 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
604 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
605 LHS.LinkageName, RHS);
606 }
607 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
608 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
609 LHS->getRawLinkageName(), RHS);
610 }
611
612 /// Subprograms compare equal if they declare the same function in an ODR
613 /// type.
614 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
615 const MDString *LinkageName,
616 const DISubprogram *RHS) {
617 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000618 if (IsDefinition || !Scope || !LinkageName)
619 return false;
620
621 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
622 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000623 return false;
624
625 // Compare to the RHS.
626 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
627 LinkageName == RHS->getRawLinkageName();
628 }
629};
630
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000631template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000632 Metadata *Scope;
633 Metadata *File;
634 unsigned Line;
635 unsigned Column;
636
637 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
638 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000639 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000640 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000641 Column(N->getColumn()) {}
642
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000643 bool isKeyOf(const DILexicalBlock *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 Line == RHS->getLine() && Column == RHS->getColumn();
646 }
647 unsigned getHashValue() const {
648 return hash_combine(Scope, File, Line, Column);
649 }
650};
651
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000652template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653 Metadata *Scope;
654 Metadata *File;
655 unsigned Discriminator;
656
657 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
658 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000659 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000660 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000661 Discriminator(N->getDiscriminator()) {}
662
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000663 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000664 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000665 Discriminator == RHS->getDiscriminator();
666 }
667 unsigned getHashValue() const {
668 return hash_combine(Scope, File, Discriminator);
669 }
670};
671
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000672template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000673 Metadata *Scope;
674 Metadata *File;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000675 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000676 unsigned Line;
677
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000678 MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000679 : Scope(Scope), File(File), Name(Name), Line(Line) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000680 MDNodeKeyImpl(const DINamespace *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000681 : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000682 Line(N->getLine()) {}
683
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000684 bool isKeyOf(const DINamespace *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000685 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000686 Name == RHS->getRawName() && Line == RHS->getLine();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000687 }
688 unsigned getHashValue() const {
689 return hash_combine(Scope, File, Name, Line);
690 }
691};
692
Adrian Prantlab1243f2015-06-29 23:03:47 +0000693template <> struct MDNodeKeyImpl<DIModule> {
694 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000695 MDString *Name;
696 MDString *ConfigurationMacros;
697 MDString *IncludePath;
698 MDString *ISysRoot;
699 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
700 MDString *IncludePath, MDString *ISysRoot)
701 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
702 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000703 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000704 : Scope(N->getRawScope()), Name(N->getRawName()),
705 ConfigurationMacros(N->getRawConfigurationMacros()),
706 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000707
708 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000709 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
710 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
711 IncludePath == RHS->getRawIncludePath() &&
712 ISysRoot == RHS->getRawISysRoot();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000713 }
714 unsigned getHashValue() const {
715 return hash_combine(Scope, Name,
716 ConfigurationMacros, IncludePath, ISysRoot);
717 }
718};
719
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000720template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000721 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000722 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000723
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000724 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000725 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000726 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000727
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000728 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000729 return Name == RHS->getRawName() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000730 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000731 unsigned getHashValue() const { return hash_combine(Name, Type); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000732};
733
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000734template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000735 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000736 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000737 Metadata *Type;
738 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000739
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000740 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000741 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000742 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000743 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000744 Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000745
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000746 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000747 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000748 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000749 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000750 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000751};
752
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000753template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000754 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000755 MDString *Name;
756 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000757 Metadata *File;
758 unsigned Line;
759 Metadata *Type;
760 bool IsLocalToUnit;
761 bool IsDefinition;
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000762 Metadata *Expr;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000763 Metadata *StaticDataMemberDeclaration;
764
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000765 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000766 Metadata *File, unsigned Line, Metadata *Type,
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000767 bool IsLocalToUnit, bool IsDefinition, Metadata *Expr,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000768 Metadata *StaticDataMemberDeclaration)
769 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
770 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000771 IsDefinition(IsDefinition), Expr(Expr),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000772 StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000773 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000774 : Scope(N->getRawScope()), Name(N->getRawName()),
775 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000776 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000777 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000778 Expr(N->getRawExpr()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000779 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000780
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000781 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000782 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
783 LinkageName == RHS->getRawLinkageName() &&
784 File == RHS->getRawFile() && Line == RHS->getLine() &&
785 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000786 IsDefinition == RHS->isDefinition() &&
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000787 Expr == RHS->getRawExpr() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000788 StaticDataMemberDeclaration ==
789 RHS->getRawStaticDataMemberDeclaration();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000790 }
791 unsigned getHashValue() const {
792 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Peter Collingbourned4135bb2016-09-13 01:12:59 +0000793 IsLocalToUnit, IsDefinition, Expr,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000794 StaticDataMemberDeclaration);
795 }
796};
797
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000798template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000799 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000800 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000801 Metadata *File;
802 unsigned Line;
803 Metadata *Type;
804 unsigned Arg;
805 unsigned Flags;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000806
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000807 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000808 Metadata *Type, unsigned Arg, unsigned Flags)
809 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
810 Flags(Flags) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000811 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000812 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000813 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
814 Flags(N->getFlags()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000815
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000816 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000817 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000818 File == RHS->getRawFile() && Line == RHS->getLine() &&
819 Type == RHS->getRawType() && Arg == RHS->getArg() &&
820 Flags == RHS->getFlags();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000821 }
822 unsigned getHashValue() const {
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000823 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000824 }
825};
826
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000827template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000828 ArrayRef<uint64_t> Elements;
829
830 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000831 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000832
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000833 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000834 return Elements == RHS->getElements();
835 }
836 unsigned getHashValue() const {
837 return hash_combine_range(Elements.begin(), Elements.end());
838 }
839};
840
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000841template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000842 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000843 Metadata *File;
844 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000845 MDString *GetterName;
846 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000847 unsigned Attributes;
848 Metadata *Type;
849
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000850 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
851 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000852 Metadata *Type)
853 : Name(Name), File(File), Line(Line), GetterName(GetterName),
854 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000855 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000856 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
857 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000858 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000859
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000860 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000861 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
862 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
863 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000864 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000865 }
866 unsigned getHashValue() const {
867 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
868 Type);
869 }
870};
871
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000872template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000873 unsigned Tag;
874 Metadata *Scope;
875 Metadata *Entity;
876 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000877 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000878
879 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000880 MDString *Name)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000881 : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000882 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000883 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000884 Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000885
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000886 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000887 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
888 Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000889 Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000890 }
891 unsigned getHashValue() const {
892 return hash_combine(Tag, Scope, Entity, Line, Name);
893 }
894};
895
Amjad Abouda9bcf162015-12-10 12:56:35 +0000896template <> struct MDNodeKeyImpl<DIMacro> {
897 unsigned MIType;
898 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000899 MDString *Name;
900 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +0000901
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000902 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +0000903 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
904 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000905 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
906 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +0000907
908 bool isKeyOf(const DIMacro *RHS) const {
909 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000910 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000911 }
912 unsigned getHashValue() const {
913 return hash_combine(MIType, Line, Name, Value);
914 }
915};
916
917template <> struct MDNodeKeyImpl<DIMacroFile> {
918 unsigned MIType;
919 unsigned Line;
920 Metadata *File;
921 Metadata *Elements;
922
923 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
924 Metadata *Elements)
925 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
926 MDNodeKeyImpl(const DIMacroFile *N)
927 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
928 Elements(N->getRawElements()) {}
929
930 bool isKeyOf(const DIMacroFile *RHS) const {
931 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +0000932 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000933 }
934 unsigned getHashValue() const {
935 return hash_combine(MIType, Line, File, Elements);
936 }
937};
938
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000939/// \brief DenseMapInfo for MDNode subclasses.
940template <class NodeTy> struct MDNodeInfo {
941 typedef MDNodeKeyImpl<NodeTy> KeyTy;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000942 typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000943 static inline NodeTy *getEmptyKey() {
944 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000945 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000946 static inline NodeTy *getTombstoneKey() {
947 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000948 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000949 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
950 static unsigned getHashValue(const NodeTy *N) {
951 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000952 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000953 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
954 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
955 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000956 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000957 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000958 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000959 if (LHS == RHS)
960 return true;
961 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
962 return false;
963 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000964 }
965};
966
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000967#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
968#include "llvm/IR/Metadata.def"
969
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +0000970/// \brief Map-like storage for metadata attachments.
971class MDAttachmentMap {
972 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
973
974public:
975 bool empty() const { return Attachments.empty(); }
976 size_t size() const { return Attachments.size(); }
977
978 /// \brief Get a particular attachment (if any).
979 MDNode *lookup(unsigned ID) const;
980
981 /// \brief Set an attachment to a particular node.
982 ///
983 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
984 /// ID (if anyway).
985 void set(unsigned ID, MDNode &MD);
986
987 /// \brief Remove an attachment.
988 ///
989 /// Remove the attachment at \c ID, if any.
990 void erase(unsigned ID);
991
992 /// \brief Copy out all the attachments.
993 ///
994 /// Copies all the current attachments into \c Result, sorting by attachment
995 /// ID. This function does \em not clear \c Result.
996 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
997
998 /// \brief Erase matching attachments.
999 ///
1000 /// Erases all attachments matching the \c shouldRemove predicate.
1001 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemer2d006e72016-08-12 04:32:42 +00001002 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1003 Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001004 }
1005};
1006
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001007/// Multimap-like storage for metadata attachments for globals. This differs
1008/// from MDAttachmentMap in that it allows multiple attachments per metadata
1009/// kind.
1010class MDGlobalAttachmentMap {
1011 struct Attachment {
1012 unsigned MDKind;
1013 TrackingMDNodeRef Node;
1014 };
1015 SmallVector<Attachment, 1> Attachments;
1016
1017public:
1018 bool empty() const { return Attachments.empty(); }
1019
1020 /// Appends all attachments with the given ID to \c Result in insertion order.
1021 /// If the global has no attachments with the given ID, or if ID is invalid,
1022 /// leaves Result unchanged.
1023 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1024
1025 void insert(unsigned ID, MDNode &MD);
1026 void erase(unsigned ID);
1027
1028 /// Appends all attachments for the global to \c Result, sorting by attachment
1029 /// ID. Attachments with the same ID appear in insertion order. This function
1030 /// does \em not clear \c Result.
1031 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1032};
1033
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001034class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001035public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001036 /// OwnedModules - The set of modules instantiated in this context, and which
1037 /// will be automatically deleted if this context is deleted.
1038 SmallPtrSet<Module*, 4> OwnedModules;
1039
Bob Wilsona594fab2013-02-11 05:37:07 +00001040 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
1041 void *InlineAsmDiagContext;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001042
1043 LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
1044 void *DiagnosticContext;
Duncan P. N. Exon Smith30c92422014-10-01 18:36:03 +00001045 bool RespectDiagnosticFilters;
Adam Nemetaad81602016-07-15 17:23:20 +00001046 bool DiagnosticHotnessRequested;
Adam Nemeta62b7e12016-09-27 20:55:07 +00001047 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001048
Juergen Ributzka34390c72014-05-16 02:33:15 +00001049 LLVMContext::YieldCallbackTy YieldCallback;
1050 void *YieldOpaqueHandle;
1051
Justin Lebar611c5c22016-10-10 16:26:13 +00001052 typedef DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>
1053 IntMapTy;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001054 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001055
Justin Lebar611c5c22016-10-10 16:26:13 +00001056 typedef DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>
1057 FPMapTy;
Owen Andersonc277dc42009-07-16 19:05:41 +00001058 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001059
Bill Wendling4607f4b2012-12-20 01:36:59 +00001060 FoldingSet<AttributeImpl> AttrsSet;
Bill Wendling6848e382012-12-19 22:42:22 +00001061 FoldingSet<AttributeSetImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001062 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001063
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001064 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001065 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1066 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001067
Owen Anderson7349ab92015-06-01 22:24:01 +00001068 DenseMap<const Value*, ValueName*> ValueNames;
1069
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001070#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1071 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001072#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001073
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001074 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001075 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001076
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001077 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1078 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001079 // one object can destroy them. Keep track of them here so we can delete
1080 // them on context teardown.
1081 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001082
Justin Lebar611c5c22016-10-10 16:26:13 +00001083 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001084
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001085 typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001086 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +00001087
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001088 typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001089 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +00001090
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001091 typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001092 VectorConstantsTy VectorConstants;
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001093
Justin Lebar611c5c22016-10-10 16:26:13 +00001094 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1095
1096 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1097
Chris Lattner3756b912012-01-23 22:57:10 +00001098 StringMap<ConstantDataSequential*> CDSConstants;
1099
Chandler Carruth6a936922014-01-19 02:13:50 +00001100 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1101 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001102 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001103
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001104 ConstantUniqueMap<InlineAsm> InlineAsms;
1105
Owen Anderson2ad52172009-07-21 02:47:59 +00001106 ConstantInt *TheTrueVal;
1107 ConstantInt *TheFalseVal;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001108
David Majnemer2dd41c52015-11-16 20:55:57 +00001109 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001110
Dan Gohman97d2cb82009-08-25 16:00:35 +00001111 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001112 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001113 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001114 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Dan Gohman97d2cb82009-08-25 16:00:35 +00001115
Chris Lattner07bd69c2011-07-15 05:49:15 +00001116
1117 /// TypeAllocator - All dynamically allocated types are allocated from this.
1118 /// They live forever until the context is torn down.
1119 BumpPtrAllocator TypeAllocator;
1120
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001121 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001122
1123 typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
1124 FunctionTypeSet FunctionTypes;
1125 typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
1126 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001127 StringMap<StructType*> NamedStructTypes;
1128 unsigned NamedStructTypesUniqueID;
1129
1130 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1131 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1132 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1133 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001134
Jeffrey Yasskin28f24482009-12-17 19:55:06 +00001135
Owen Andersone8f21852009-08-18 18:28:58 +00001136 /// ValueHandles - This map keeps track of all of the value handles that are
1137 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001138 /// whether or not a value has an entry in this map.
Owen Andersone8f21852009-08-18 18:28:58 +00001139 typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
1140 ValueHandlesTy ValueHandles;
1141
Chris Lattnera0566972009-12-29 09:01:33 +00001142 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1143 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001144
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001145 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001146 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001147
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001148 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001149 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001150
Diego Novillof5041ce2014-03-03 20:06:11 +00001151 /// DiscriminatorTable - This table maps file:line locations to an
1152 /// integer representing the next DWARF path discriminator to assign to
1153 /// instructions in different blocks at the same location.
1154 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1155
Chris Lattner8cb2aeb2010-04-01 00:37:44 +00001156 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1157 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames2b453952015-01-16 20:07:33 +00001158
Sanjoy Das9303c242015-09-24 19:14:18 +00001159 /// \brief A set of interned tags for operand bundles. The StringMap maps
1160 /// bundle tags to their IDs.
1161 ///
1162 /// \see LLVMContext::getOperandBundleTagID
1163 StringMap<uint32_t> BundleTagCache;
1164
1165 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1166 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1167 uint32_t getOperandBundleTagID(StringRef Tag) const;
1168
Mehdi Amini599ebf22016-01-08 02:28:20 +00001169 /// Maintain the GC name for each function.
1170 ///
1171 /// This saves allocating an additional word in Function for programs which
1172 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1173 /// clients which do use GC.
1174 DenseMap<const Function*, std::string> GCNames;
1175
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001176 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1177 /// not.
1178 bool DiscardValueNames = false;
1179
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001180 LLVMContextImpl(LLVMContext &C);
1181 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001182
1183 /// Destroy the ConstantArrays if they are not used.
1184 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001185
1186 /// \brief Access the object which manages optimization bisection for failure
1187 /// analysis.
1188 OptBisect &getOptBisect();
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001189};
1190
Alexander Kornienkof00654e2015-06-23 09:49:53 +00001191}
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001192
Owen Anderson36f62e52009-06-30 17:06:46 +00001193#endif