blob: 9db30da89ed085bc2228d1d259d54b69f1d5925a [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"
Reid Kleckner443423e2017-01-10 23:23:58 +000029#include "llvm/ADT/StringSet.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000030#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000031#include "llvm/IR/DebugInfoMetadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000032#include "llvm/IR/DerivedTypes.h"
33#include "llvm/IR/LLVMContext.h"
34#include "llvm/IR/Metadata.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000035#include "llvm/IR/ValueHandle.h"
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +000036#include "llvm/Support/Dwarf.h"
Adam Nemeta62b7e12016-09-27 20:55:07 +000037#include "llvm/Support/YAMLTraits.h"
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +000038#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000039
Owen Anderson20b34ac2009-07-16 18:04:31 +000040namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000041
Owen Anderson20b34ac2009-07-16 18:04:31 +000042class ConstantInt;
Owen Andersonc277dc42009-07-16 19:05:41 +000043class ConstantFP;
Diego Novillo7f8af8b2014-05-22 14:19:46 +000044class DiagnosticInfoOptimizationRemark;
45class DiagnosticInfoOptimizationRemarkMissed;
46class DiagnosticInfoOptimizationRemarkAnalysis;
Philip Reames2b453952015-01-16 20:07:33 +000047class GCStrategy;
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +000048class LLVMContext;
Owen Anderson20b34ac2009-07-16 18:04:31 +000049class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000050class Value;
Owen Anderson20b34ac2009-07-16 18:04:31 +000051
Benjamin Kramer079b96e2013-09-11 18:05:11 +000052struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000053 static inline APInt getEmptyKey() {
54 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000055 V.U.VAL = 0;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000056 return V;
57 }
58 static inline APInt getTombstoneKey() {
59 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000060 V.U.VAL = 1;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000061 return V;
62 }
63 static unsigned getHashValue(const APInt &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000064 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000065 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000066 static bool isEqual(const APInt &LHS, const APInt &RHS) {
67 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
68 }
Owen Anderson20b34ac2009-07-16 18:04:31 +000069};
70
Benjamin Kramer079b96e2013-09-11 18:05:11 +000071struct DenseMapAPFloatKeyInfo {
Stephan Bergmann17c7f702016-12-14 11:57:17 +000072 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
73 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000074 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000075 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000076 }
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000077 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
78 return LHS.bitwiseIsEqual(RHS);
79 }
Owen Andersonc277dc42009-07-16 19:05:41 +000080};
81
Benjamin Kramer079b96e2013-09-11 18:05:11 +000082struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000083 struct KeyTy {
84 ArrayRef<Type*> ETypes;
85 bool isPacked;
86 KeyTy(const ArrayRef<Type*>& E, bool P) :
87 ETypes(E), isPacked(P) {}
Rafael Espindola334b73f2014-11-21 18:53:05 +000088 KeyTy(const StructType *ST)
89 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Jay Foad529776c2012-02-23 09:17:40 +000090 bool operator==(const KeyTy& that) const {
91 if (isPacked != that.isPacked)
92 return false;
93 if (ETypes != that.ETypes)
94 return false;
95 return true;
96 }
97 bool operator!=(const KeyTy& that) const {
98 return !this->operator==(that);
99 }
100 };
101 static inline StructType* getEmptyKey() {
102 return DenseMapInfo<StructType*>::getEmptyKey();
103 }
104 static inline StructType* getTombstoneKey() {
105 return DenseMapInfo<StructType*>::getTombstoneKey();
106 }
107 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000108 return hash_combine(hash_combine_range(Key.ETypes.begin(),
109 Key.ETypes.end()),
110 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000111 }
112 static unsigned getHashValue(const StructType *ST) {
113 return getHashValue(KeyTy(ST));
114 }
115 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
116 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
117 return false;
118 return LHS == KeyTy(RHS);
119 }
120 static bool isEqual(const StructType *LHS, const StructType *RHS) {
121 return LHS == RHS;
122 }
123};
124
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000125struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000126 struct KeyTy {
127 const Type *ReturnType;
128 ArrayRef<Type*> Params;
129 bool isVarArg;
130 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
131 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindolae973fd42014-11-21 19:03:35 +0000132 KeyTy(const FunctionType *FT)
133 : ReturnType(FT->getReturnType()), Params(FT->params()),
134 isVarArg(FT->isVarArg()) {}
Jay Foad529776c2012-02-23 09:17:40 +0000135 bool operator==(const KeyTy& that) const {
136 if (ReturnType != that.ReturnType)
137 return false;
138 if (isVarArg != that.isVarArg)
139 return false;
140 if (Params != that.Params)
141 return false;
142 return true;
143 }
144 bool operator!=(const KeyTy& that) const {
145 return !this->operator==(that);
146 }
147 };
148 static inline FunctionType* getEmptyKey() {
149 return DenseMapInfo<FunctionType*>::getEmptyKey();
150 }
151 static inline FunctionType* getTombstoneKey() {
152 return DenseMapInfo<FunctionType*>::getTombstoneKey();
153 }
154 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000155 return hash_combine(Key.ReturnType,
156 hash_combine_range(Key.Params.begin(),
157 Key.Params.end()),
158 Key.isVarArg);
Jay Foad529776c2012-02-23 09:17:40 +0000159 }
160 static unsigned getHashValue(const FunctionType *FT) {
161 return getHashValue(KeyTy(FT));
162 }
163 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
164 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
165 return false;
166 return LHS == KeyTy(RHS);
167 }
168 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
169 return LHS == RHS;
170 }
171};
172
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000173/// \brief Structure for hashing arbitrary MDNode operands.
174class MDNodeOpsKey {
175 ArrayRef<Metadata *> RawOps;
176 ArrayRef<MDOperand> Ops;
177
178 unsigned Hash;
179
180protected:
181 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
182 : RawOps(Ops), Hash(calculateHash(Ops)) {}
183
184 template <class NodeTy>
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000185 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000186 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000187
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000188 template <class NodeTy>
189 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000190 if (getHash() != RHS->getHash())
191 return false;
192
193 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000194 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
195 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000196 }
197
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000198 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000199
200private:
201 template <class T>
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000202 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
203 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000204 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000205 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000206 }
207
208 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
209
210public:
211 unsigned getHash() const { return Hash; }
212};
213
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000214template <class NodeTy> struct MDNodeKeyImpl;
215template <class NodeTy> struct MDNodeInfo;
216
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000217/// Configuration point for MDNodeInfo::isEqual().
218template <class NodeTy> struct MDNodeSubsetEqualImpl {
219 typedef MDNodeKeyImpl<NodeTy> KeyTy;
220 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
221 return false;
222 }
223 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
224 return false;
225 }
226};
227
Duncan P. N. Exon Smith118632d2015-01-12 20:09:34 +0000228/// \brief DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000229///
230/// Note that we don't need the is-function-local bit, since that's implicit in
231/// the operands.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000232template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
233 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
234 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000235
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000236 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000237
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000238 unsigned getHashValue() const { return getHash(); }
239
240 static unsigned calculateHash(MDTuple *N) {
241 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000242 }
243};
244
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000245/// \brief DenseMapInfo for DILocation.
246template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000247 unsigned Line;
248 unsigned Column;
249 Metadata *Scope;
250 Metadata *InlinedAt;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000251
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000252 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
253 Metadata *InlinedAt)
254 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000255
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000256 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000257 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
258 InlinedAt(L->getRawInlinedAt()) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000259
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000260 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000261 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000262 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000263 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000264 unsigned getHashValue() const {
265 return hash_combine(Line, Column, Scope, InlinedAt);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000266 }
267};
268
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000269/// \brief DenseMapInfo for GenericDINode.
270template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000271 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000272 MDString *Header;
273 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000274 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000275 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000276 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000277
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000278 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000279 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000280 compareOps(RHS, 1);
281 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000282
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000283 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
284
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000285 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000286 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000287 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000288};
289
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000290template <> struct MDNodeKeyImpl<DISubrange> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000291 int64_t Count;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000292 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000293
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000294 MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
295 : Count(Count), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000296 MDNodeKeyImpl(const DISubrange *N)
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000297 : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000298
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000299 bool isKeyOf(const DISubrange *RHS) const {
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000300 return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000301 }
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000302 unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000303};
304
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000305template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000306 int64_t Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000307 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000308
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000309 MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000310 MDNodeKeyImpl(const DIEnumerator *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000311 : Value(N->getValue()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000312
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000313 bool isKeyOf(const DIEnumerator *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000314 return Value == RHS->getValue() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000315 }
316 unsigned getHashValue() const { return hash_combine(Value, Name); }
317};
318
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000319template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000320 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000321 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000322 uint64_t SizeInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000323 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000324 unsigned Encoding;
325
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000326 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000327 uint32_t AlignInBits, unsigned Encoding)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000328 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
329 Encoding(Encoding) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000330 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000331 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000332 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
333
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000335 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000336 SizeInBits == RHS->getSizeInBits() &&
337 AlignInBits == RHS->getAlignInBits() &&
338 Encoding == RHS->getEncoding();
339 }
340 unsigned getHashValue() const {
341 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
342 }
343};
344
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000345template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000346 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000347 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000348 Metadata *File;
349 unsigned Line;
350 Metadata *Scope;
351 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000352 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000353 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000354 uint32_t AlignInBits;
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000355 Optional<unsigned> DWARFAddressSpace;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000356 unsigned Flags;
357 Metadata *ExtraData;
358
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000359 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000360 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000361 uint32_t AlignInBits, uint64_t OffsetInBits,
362 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000363 Metadata *ExtraData)
364 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000365 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000366 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
367 Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000368 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000369 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000370 Line(N->getLine()), Scope(N->getRawScope()),
371 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000372 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000373 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
374 ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000375
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000376 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000377 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000378 File == RHS->getRawFile() && Line == RHS->getLine() &&
379 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000380 SizeInBits == RHS->getSizeInBits() &&
381 AlignInBits == RHS->getAlignInBits() &&
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000382 OffsetInBits == RHS->getOffsetInBits() &&
383 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
384 Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000385 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000386 }
387 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000388 // If this is a member inside an ODR type, only hash the type and the name.
389 // Otherwise the hash will be stronger than
390 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000391 if (Tag == dwarf::DW_TAG_member && Name)
392 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
393 if (CT->getRawIdentifier())
394 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000395
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000396 // Intentionally computes the hash on a subset of the operands for
397 // performance reason. The subset has to be significant enough to avoid
398 // collision "most of the time". There is no correctness issue in case of
399 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000400 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000401 }
402};
403
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000404template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
405 typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
406 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
407 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
408 }
409 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
410 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
411 RHS);
412 }
413
414 /// Subprograms compare equal if they declare the same function in an ODR
415 /// type.
416 static bool isODRMember(unsigned Tag, const Metadata *Scope,
417 const MDString *Name, const DIDerivedType *RHS) {
418 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000419 if (Tag != dwarf::DW_TAG_member || !Name)
420 return false;
421
422 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
423 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000424 return false;
425
426 // Compare to the RHS.
427 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
428 Scope == RHS->getRawScope();
429 }
430};
431
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000432template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000433 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000434 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000435 Metadata *File;
436 unsigned Line;
437 Metadata *Scope;
438 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000439 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000440 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000441 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000442 unsigned Flags;
443 Metadata *Elements;
444 unsigned RuntimeLang;
445 Metadata *VTableHolder;
446 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000447 MDString *Identifier;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000448
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000449 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000450 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000451 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000452 Metadata *Elements, unsigned RuntimeLang,
453 Metadata *VTableHolder, Metadata *TemplateParams,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000454 MDString *Identifier)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000455 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000456 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
457 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000458 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
459 TemplateParams(TemplateParams), Identifier(Identifier) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000460 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000461 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000462 Line(N->getLine()), Scope(N->getRawScope()),
463 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000464 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000465 Flags(N->getFlags()), Elements(N->getRawElements()),
466 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
467 TemplateParams(N->getRawTemplateParams()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000468 Identifier(N->getRawIdentifier()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000469
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000470 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000471 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000472 File == RHS->getRawFile() && Line == RHS->getLine() &&
473 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000474 SizeInBits == RHS->getSizeInBits() &&
475 AlignInBits == RHS->getAlignInBits() &&
476 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000477 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000478 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000479 VTableHolder == RHS->getRawVTableHolder() &&
480 TemplateParams == RHS->getRawTemplateParams() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000481 Identifier == RHS->getRawIdentifier();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000482 }
483 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000484 // Intentionally computes the hash on a subset of the operands for
485 // performance reason. The subset has to be significant enough to avoid
486 // collision "most of the time". There is no correctness issue in case of
487 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000488 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
489 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000490 }
491};
492
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000493template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000494 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000495 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000496 Metadata *TypeArray;
497
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000498 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
499 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000500 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000501 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000502
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000503 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000504 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
505 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000506 }
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000507 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000508};
509
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000510template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000511 MDString *Filename;
512 MDString *Directory;
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000513 DIFile::ChecksumKind CSKind;
514 MDString *Checksum;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000515
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000516 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
517 DIFile::ChecksumKind CSKind, MDString *Checksum)
518 : Filename(Filename), Directory(Directory), CSKind(CSKind),
519 Checksum(Checksum) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000520 MDNodeKeyImpl(const DIFile *N)
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000521 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
522 CSKind(N->getChecksumKind()), Checksum(N->getRawChecksum()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000523
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000524 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000525 return Filename == RHS->getRawFilename() &&
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000526 Directory == RHS->getRawDirectory() &&
527 CSKind == RHS->getChecksumKind() &&
528 Checksum == RHS->getRawChecksum();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000529 }
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000530 unsigned getHashValue() const {
531 return hash_combine(Filename, Directory, CSKind, Checksum);
532 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000533};
534
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000535template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000537 MDString *Name;
538 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000539 Metadata *File;
540 unsigned Line;
541 Metadata *Type;
542 bool IsLocalToUnit;
543 bool IsDefinition;
544 unsigned ScopeLine;
545 Metadata *ContainingType;
546 unsigned Virtuality;
547 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000548 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000549 unsigned Flags;
550 bool IsOptimized;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000551 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000552 Metadata *TemplateParams;
553 Metadata *Declaration;
554 Metadata *Variables;
Adrian Prantl1d12b882017-04-26 22:56:44 +0000555 Metadata *ThrownTypes;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000556
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000557 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000558 Metadata *File, unsigned Line, Metadata *Type,
559 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
560 Metadata *ContainingType, unsigned Virtuality,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000561 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
562 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000563 Metadata *Declaration, Metadata *Variables,
564 Metadata *ThrownTypes)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000565 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
566 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
567 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
568 ContainingType(ContainingType), Virtuality(Virtuality),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000569 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
570 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
571 TemplateParams(TemplateParams), Declaration(Declaration),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000572 Variables(Variables), ThrownTypes(ThrownTypes) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000573 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000574 : Scope(N->getRawScope()), Name(N->getRawName()),
575 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000576 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000577 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000578 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000579 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000580 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
581 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
582 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000583 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()),
584 ThrownTypes(N->getRawThrownTypes()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000585
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000586 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000587 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
588 LinkageName == RHS->getRawLinkageName() &&
589 File == RHS->getRawFile() && Line == RHS->getLine() &&
590 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000591 IsDefinition == RHS->isDefinition() &&
592 ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000593 ContainingType == RHS->getRawContainingType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000594 Virtuality == RHS->getVirtuality() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000595 VirtualIndex == RHS->getVirtualIndex() &&
596 ThisAdjustment == RHS->getThisAdjustment() &&
597 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
598 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000599 TemplateParams == RHS->getRawTemplateParams() &&
600 Declaration == RHS->getRawDeclaration() &&
Adrian Prantl1d12b882017-04-26 22:56:44 +0000601 Variables == RHS->getRawVariables() &&
602 ThrownTypes == RHS->getRawThrownTypes();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000603 }
604 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000605 // If this is a declaration inside an ODR type, only hash the type and the
606 // name. Otherwise the hash will be stronger than
607 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000608 if (!IsDefinition && LinkageName)
609 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
610 if (CT->getRawIdentifier())
611 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000612
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000613 // Intentionally computes the hash on a subset of the operands for
614 // performance reason. The subset has to be significant enough to avoid
615 // collision "most of the time". There is no correctness issue in case of
616 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000617 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000618 }
619};
620
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000621template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
622 typedef MDNodeKeyImpl<DISubprogram> KeyTy;
623 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
624 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000625 LHS.LinkageName, LHS.TemplateParams, RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000626 }
627 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
628 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000629 LHS->getRawLinkageName(),
630 LHS->getRawTemplateParams(), RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000631 }
632
633 /// Subprograms compare equal if they declare the same function in an ODR
634 /// type.
635 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
636 const MDString *LinkageName,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000637 const Metadata *TemplateParams,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000638 const DISubprogram *RHS) {
639 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000640 if (IsDefinition || !Scope || !LinkageName)
641 return false;
642
643 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
644 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000645 return false;
646
647 // Compare to the RHS.
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000648 // FIXME: We need to compare template parameters here to avoid incorrect
649 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
650 // has a non-ODR template parameter (i.e., a DICompositeType that does not
651 // have an identifier). Eventually we should decouple ODR logic from
652 // uniquing logic.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000653 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000654 LinkageName == RHS->getRawLinkageName() &&
655 TemplateParams == RHS->getRawTemplateParams();
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000656 }
657};
658
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000659template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000660 Metadata *Scope;
661 Metadata *File;
662 unsigned Line;
663 unsigned Column;
664
665 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
666 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000667 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000668 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000669 Column(N->getColumn()) {}
670
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000671 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000672 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000673 Line == RHS->getLine() && Column == RHS->getColumn();
674 }
675 unsigned getHashValue() const {
676 return hash_combine(Scope, File, Line, Column);
677 }
678};
679
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000680template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000681 Metadata *Scope;
682 Metadata *File;
683 unsigned Discriminator;
684
685 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
686 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000687 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000688 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000689 Discriminator(N->getDiscriminator()) {}
690
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000691 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000692 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000693 Discriminator == RHS->getDiscriminator();
694 }
695 unsigned getHashValue() const {
696 return hash_combine(Scope, File, Discriminator);
697 }
698};
699
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000700template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000701 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000702 MDString *Name;
Adrian Prantldbfda632016-11-03 19:42:02 +0000703 bool ExportSymbols;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000704
Adrian Prantlfed4f392017-04-28 22:25:46 +0000705 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
706 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000707 MDNodeKeyImpl(const DINamespace *N)
Adrian Prantlfed4f392017-04-28 22:25:46 +0000708 : Scope(N->getRawScope()), Name(N->getRawName()),
709 ExportSymbols(N->getExportSymbols()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000710
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000711 bool isKeyOf(const DINamespace *RHS) const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000712 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Adrian Prantldbfda632016-11-03 19:42:02 +0000713 ExportSymbols == RHS->getExportSymbols();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000714 }
715 unsigned getHashValue() const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000716 return hash_combine(Scope, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000717 }
718};
719
Adrian Prantlab1243f2015-06-29 23:03:47 +0000720template <> struct MDNodeKeyImpl<DIModule> {
721 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000722 MDString *Name;
723 MDString *ConfigurationMacros;
724 MDString *IncludePath;
725 MDString *ISysRoot;
726 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
727 MDString *IncludePath, MDString *ISysRoot)
728 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
729 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000730 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000731 : Scope(N->getRawScope()), Name(N->getRawName()),
732 ConfigurationMacros(N->getRawConfigurationMacros()),
733 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000734
735 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000736 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
737 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
738 IncludePath == RHS->getRawIncludePath() &&
739 ISysRoot == RHS->getRawISysRoot();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000740 }
741 unsigned getHashValue() const {
742 return hash_combine(Scope, Name,
743 ConfigurationMacros, IncludePath, ISysRoot);
744 }
745};
746
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000747template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000748 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000749 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000750
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000751 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000752 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000753 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000754
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000755 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000756 return Name == RHS->getRawName() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000757 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000758 unsigned getHashValue() const { return hash_combine(Name, Type); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000759};
760
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000761template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000762 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000763 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000764 Metadata *Type;
765 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000766
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000767 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000768 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000769 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000770 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000771 Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000772
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000773 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000774 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000775 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000776 }
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000777 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000778};
779
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000780template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000781 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000782 MDString *Name;
783 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000784 Metadata *File;
785 unsigned Line;
786 Metadata *Type;
787 bool IsLocalToUnit;
788 bool IsDefinition;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000789 Metadata *StaticDataMemberDeclaration;
Victor Leschuka37660c2016-10-26 21:32:29 +0000790 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000791
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000792 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000793 Metadata *File, unsigned Line, Metadata *Type,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000794 bool IsLocalToUnit, bool IsDefinition,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000795 Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000796 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
797 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000798 IsDefinition(IsDefinition),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000799 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
800 AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000801 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000802 : Scope(N->getRawScope()), Name(N->getRawName()),
803 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000804 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000805 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000806 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
807 AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000808
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000809 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000810 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
811 LinkageName == RHS->getRawLinkageName() &&
812 File == RHS->getRawFile() && Line == RHS->getLine() &&
813 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000814 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000815 StaticDataMemberDeclaration ==
Victor Leschuk2ede1262016-10-20 00:13:12 +0000816 RHS->getRawStaticDataMemberDeclaration() &&
817 AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000818 }
819 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000820 // We do not use AlignInBits in hashing function here on purpose:
821 // in most cases this param for local variable is zero (for function param
822 // it is always zero). This leads to lots of hash collisions and errors on
823 // cases with lots of similar variables.
824 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
825 // generated IR is random for each run and test fails with Align included.
826 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000827 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000828 IsLocalToUnit, IsDefinition, /* AlignInBits, */
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000829 StaticDataMemberDeclaration);
830 }
831};
832
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000833template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000834 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000835 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000836 Metadata *File;
837 unsigned Line;
838 Metadata *Type;
839 unsigned Arg;
840 unsigned Flags;
Victor Leschuka37660c2016-10-26 21:32:29 +0000841 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000842
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000843 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000844 Metadata *Type, unsigned Arg, unsigned Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000845 uint32_t AlignInBits)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000846 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000847 Flags(Flags), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000848 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000849 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000850 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000851 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000852
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000853 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000854 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000855 File == RHS->getRawFile() && Line == RHS->getLine() &&
856 Type == RHS->getRawType() && Arg == RHS->getArg() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000857 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000858 }
859 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000860 // We do not use AlignInBits in hashing function here on purpose:
861 // in most cases this param for local variable is zero (for function param
862 // it is always zero). This leads to lots of hash collisions and errors on
863 // cases with lots of similar variables.
864 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
865 // generated IR is random for each run and test fails with Align included.
866 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000867 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000868 }
869};
870
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000871template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000872 ArrayRef<uint64_t> Elements;
873
874 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000875 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000876
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000877 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000878 return Elements == RHS->getElements();
879 }
880 unsigned getHashValue() const {
881 return hash_combine_range(Elements.begin(), Elements.end());
882 }
883};
884
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000885template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
886 Metadata *Variable;
887 Metadata *Expression;
888
889 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
890 : Variable(Variable), Expression(Expression) {}
891 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
892 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
893
894 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
895 return Variable == RHS->getRawVariable() &&
896 Expression == RHS->getRawExpression();
897 }
898 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
899};
900
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000901template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000902 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000903 Metadata *File;
904 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000905 MDString *GetterName;
906 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000907 unsigned Attributes;
908 Metadata *Type;
909
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000910 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
911 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000912 Metadata *Type)
913 : Name(Name), File(File), Line(Line), GetterName(GetterName),
914 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000915 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000916 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
917 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000918 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000919
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000920 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000921 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
922 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
923 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000924 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000925 }
926 unsigned getHashValue() const {
927 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
928 Type);
929 }
930};
931
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000932template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000933 unsigned Tag;
934 Metadata *Scope;
935 Metadata *Entity;
936 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000937 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000938
939 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000940 MDString *Name)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000941 : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000942 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000943 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000944 Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000945
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000946 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +0000947 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
948 Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000949 Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000950 }
951 unsigned getHashValue() const {
952 return hash_combine(Tag, Scope, Entity, Line, Name);
953 }
954};
955
Amjad Abouda9bcf162015-12-10 12:56:35 +0000956template <> struct MDNodeKeyImpl<DIMacro> {
957 unsigned MIType;
958 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000959 MDString *Name;
960 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +0000961
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000962 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +0000963 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
964 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000965 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
966 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +0000967
968 bool isKeyOf(const DIMacro *RHS) const {
969 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000970 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000971 }
972 unsigned getHashValue() const {
973 return hash_combine(MIType, Line, Name, Value);
974 }
975};
976
977template <> struct MDNodeKeyImpl<DIMacroFile> {
978 unsigned MIType;
979 unsigned Line;
980 Metadata *File;
981 Metadata *Elements;
982
983 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
984 Metadata *Elements)
985 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
986 MDNodeKeyImpl(const DIMacroFile *N)
987 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
988 Elements(N->getRawElements()) {}
989
990 bool isKeyOf(const DIMacroFile *RHS) const {
991 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +0000992 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +0000993 }
994 unsigned getHashValue() const {
995 return hash_combine(MIType, Line, File, Elements);
996 }
997};
998
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000999/// \brief DenseMapInfo for MDNode subclasses.
1000template <class NodeTy> struct MDNodeInfo {
1001 typedef MDNodeKeyImpl<NodeTy> KeyTy;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001002 typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001003 static inline NodeTy *getEmptyKey() {
1004 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001005 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001006 static inline NodeTy *getTombstoneKey() {
1007 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001008 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001009 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
1010 static unsigned getHashValue(const NodeTy *N) {
1011 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001012 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001013 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1014 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1015 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001016 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001017 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001018 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001019 if (LHS == RHS)
1020 return true;
1021 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1022 return false;
1023 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001024 }
1025};
1026
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001027#define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
1028#include "llvm/IR/Metadata.def"
1029
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001030/// \brief Map-like storage for metadata attachments.
1031class MDAttachmentMap {
1032 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1033
1034public:
1035 bool empty() const { return Attachments.empty(); }
1036 size_t size() const { return Attachments.size(); }
1037
1038 /// \brief Get a particular attachment (if any).
1039 MDNode *lookup(unsigned ID) const;
1040
1041 /// \brief Set an attachment to a particular node.
1042 ///
1043 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1044 /// ID (if anyway).
1045 void set(unsigned ID, MDNode &MD);
1046
1047 /// \brief Remove an attachment.
1048 ///
1049 /// Remove the attachment at \c ID, if any.
1050 void erase(unsigned ID);
1051
1052 /// \brief Copy out all the attachments.
1053 ///
1054 /// Copies all the current attachments into \c Result, sorting by attachment
1055 /// ID. This function does \em not clear \c Result.
1056 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1057
1058 /// \brief Erase matching attachments.
1059 ///
1060 /// Erases all attachments matching the \c shouldRemove predicate.
1061 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemer2d006e72016-08-12 04:32:42 +00001062 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1063 Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001064 }
1065};
1066
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001067/// Multimap-like storage for metadata attachments for globals. This differs
1068/// from MDAttachmentMap in that it allows multiple attachments per metadata
1069/// kind.
1070class MDGlobalAttachmentMap {
1071 struct Attachment {
1072 unsigned MDKind;
1073 TrackingMDNodeRef Node;
1074 };
1075 SmallVector<Attachment, 1> Attachments;
1076
1077public:
1078 bool empty() const { return Attachments.empty(); }
1079
1080 /// Appends all attachments with the given ID to \c Result in insertion order.
1081 /// If the global has no attachments with the given ID, or if ID is invalid,
1082 /// leaves Result unchanged.
1083 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1084
1085 void insert(unsigned ID, MDNode &MD);
1086 void erase(unsigned ID);
1087
1088 /// Appends all attachments for the global to \c Result, sorting by attachment
1089 /// ID. Attachments with the same ID appear in insertion order. This function
1090 /// does \em not clear \c Result.
1091 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1092};
1093
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001094class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001095public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001096 /// OwnedModules - The set of modules instantiated in this context, and which
1097 /// will be automatically deleted if this context is deleted.
1098 SmallPtrSet<Module*, 4> OwnedModules;
1099
Bob Wilsona594fab2013-02-11 05:37:07 +00001100 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
1101 void *InlineAsmDiagContext;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001102
1103 LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
1104 void *DiagnosticContext;
Duncan P. N. Exon Smith30c92422014-10-01 18:36:03 +00001105 bool RespectDiagnosticFilters;
Adam Nemetaad81602016-07-15 17:23:20 +00001106 bool DiagnosticHotnessRequested;
Adam Nemeta62b7e12016-09-27 20:55:07 +00001107 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001108
Juergen Ributzka34390c72014-05-16 02:33:15 +00001109 LLVMContext::YieldCallbackTy YieldCallback;
1110 void *YieldOpaqueHandle;
1111
Justin Lebar611c5c22016-10-10 16:26:13 +00001112 typedef DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>
1113 IntMapTy;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001114 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001115
Justin Lebar611c5c22016-10-10 16:26:13 +00001116 typedef DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>
1117 FPMapTy;
Owen Andersonc277dc42009-07-16 19:05:41 +00001118 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001119
Bill Wendling4607f4b2012-12-20 01:36:59 +00001120 FoldingSet<AttributeImpl> AttrsSet;
Reid Klecknerb5180542017-03-21 16:57:19 +00001121 FoldingSet<AttributeListImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001122 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001123
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001124 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001125 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1126 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001127
Owen Anderson7349ab92015-06-01 22:24:01 +00001128 DenseMap<const Value*, ValueName*> ValueNames;
1129
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001130#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1131 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001132#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001133
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001134 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001135 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001136
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001137 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1138 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001139 // one object can destroy them. Keep track of them here so we can delete
1140 // them on context teardown.
1141 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001142
Justin Lebar611c5c22016-10-10 16:26:13 +00001143 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001144
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001145 typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001146 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +00001147
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001148 typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001149 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +00001150
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001151 typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
Owen Andersonedb4a702009-07-24 23:12:02 +00001152 VectorConstantsTy VectorConstants;
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001153
Justin Lebar611c5c22016-10-10 16:26:13 +00001154 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1155
1156 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1157
Chris Lattner3756b912012-01-23 22:57:10 +00001158 StringMap<ConstantDataSequential*> CDSConstants;
1159
Chandler Carruth6a936922014-01-19 02:13:50 +00001160 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1161 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001162 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001163
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001164 ConstantUniqueMap<InlineAsm> InlineAsms;
1165
Owen Anderson2ad52172009-07-21 02:47:59 +00001166 ConstantInt *TheTrueVal;
1167 ConstantInt *TheFalseVal;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001168
David Majnemer2dd41c52015-11-16 20:55:57 +00001169 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001170
Dan Gohman97d2cb82009-08-25 16:00:35 +00001171 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001172 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001173 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001174 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Dan Gohman97d2cb82009-08-25 16:00:35 +00001175
Chris Lattner07bd69c2011-07-15 05:49:15 +00001176
1177 /// TypeAllocator - All dynamically allocated types are allocated from this.
1178 /// They live forever until the context is torn down.
1179 BumpPtrAllocator TypeAllocator;
1180
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001181 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001182
1183 typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
1184 FunctionTypeSet FunctionTypes;
1185 typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
1186 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001187 StringMap<StructType*> NamedStructTypes;
1188 unsigned NamedStructTypesUniqueID;
1189
1190 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1191 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1192 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1193 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001194
Jeffrey Yasskin28f24482009-12-17 19:55:06 +00001195
Owen Andersone8f21852009-08-18 18:28:58 +00001196 /// ValueHandles - This map keeps track of all of the value handles that are
1197 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001198 /// whether or not a value has an entry in this map.
Owen Andersone8f21852009-08-18 18:28:58 +00001199 typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
1200 ValueHandlesTy ValueHandles;
1201
Chris Lattnera0566972009-12-29 09:01:33 +00001202 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1203 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001204
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001205 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001206 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001207
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001208 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001209 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001210
Reid Kleckner443423e2017-01-10 23:23:58 +00001211 /// Collection of per-GlobalObject sections used in this context.
1212 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1213
1214 /// Stable collection of section strings.
1215 StringSet<> SectionStrings;
1216
Diego Novillof5041ce2014-03-03 20:06:11 +00001217 /// DiscriminatorTable - This table maps file:line locations to an
1218 /// integer representing the next DWARF path discriminator to assign to
1219 /// instructions in different blocks at the same location.
1220 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1221
Chris Lattner8cb2aeb2010-04-01 00:37:44 +00001222 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1223 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames2b453952015-01-16 20:07:33 +00001224
Sanjoy Das9303c242015-09-24 19:14:18 +00001225 /// \brief A set of interned tags for operand bundles. The StringMap maps
1226 /// bundle tags to their IDs.
1227 ///
1228 /// \see LLVMContext::getOperandBundleTagID
1229 StringMap<uint32_t> BundleTagCache;
1230
1231 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1232 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1233 uint32_t getOperandBundleTagID(StringRef Tag) const;
1234
Mehdi Amini599ebf22016-01-08 02:28:20 +00001235 /// Maintain the GC name for each function.
1236 ///
1237 /// This saves allocating an additional word in Function for programs which
1238 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1239 /// clients which do use GC.
1240 DenseMap<const Function*, std::string> GCNames;
1241
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001242 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1243 /// not.
1244 bool DiscardValueNames = false;
1245
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001246 LLVMContextImpl(LLVMContext &C);
1247 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001248
1249 /// Destroy the ConstantArrays if they are not used.
1250 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001251
1252 /// \brief Access the object which manages optimization bisection for failure
1253 /// analysis.
1254 OptBisect &getOptBisect();
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001255};
1256
Alexander Kornienkof00654e2015-06-23 09:49:53 +00001257}
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001258
Owen Anderson36f62e52009-06-30 17:06:46 +00001259#endif