blob: 705ffdc587269ef11aefd43714e94f593dae9715 [file] [log] [blame]
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001//===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Owen Anderson8e66e0b2009-06-30 00:48:55 +00006//
7//===----------------------------------------------------------------------===//
Owen Anderson36f62e52009-06-30 17:06:46 +00008//
Fangrui Songf78650a2018-07-30 19:41:25 +00009// This file declares LLVMContextImpl, the opaque implementation
Owen Anderson36f62e52009-06-30 17:06:46 +000010// of LLVMContext.
11//
12//===----------------------------------------------------------------------===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +000013
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
15#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
Owen Anderson8e66e0b2009-06-30 00:48:55 +000016
Bill Wendling4607f4b2012-12-20 01:36:59 +000017#include "AttributeImpl.h"
Owen Andersonafd0c4c2009-08-04 22:41:48 +000018#include "ConstantsContext.h"
Owen Andersonc277dc42009-07-16 19:05:41 +000019#include "llvm/ADT/APFloat.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000020#include "llvm/ADT/APInt.h"
Jay Foadc365eea2011-06-22 08:50:06 +000021#include "llvm/ADT/ArrayRef.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000022#include "llvm/ADT/DenseMap.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000023#include "llvm/ADT/DenseMapInfo.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"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000027#include "llvm/ADT/Optional.h"
28#include "llvm/ADT/STLExtras.h"
Jeffrey Yasskin28f24482009-12-17 19:55:06 +000029#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000030#include "llvm/ADT/SmallVector.h"
Owen Anderson69ab4162009-07-16 22:11:26 +000031#include "llvm/ADT/StringMap.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000032#include "llvm/BinaryFormat/Dwarf.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000033#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000034#include "llvm/IR/DebugInfoMetadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000035#include "llvm/IR/DerivedTypes.h"
36#include "llvm/IR/LLVMContext.h"
Francis Visoiu Mistrih7531a502019-10-28 14:53:31 -070037#include "llvm/IR/LLVMRemarkStreamer.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000038#include "llvm/IR/Metadata.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000039#include "llvm/IR/TrackingMDRef.h"
40#include "llvm/Support/Allocator.h"
41#include "llvm/Support/Casting.h"
Peter Collingbourne10c548c2019-05-29 03:28:51 +000042#include "llvm/Support/StringSaver.h"
Adam Nemeta62b7e12016-09-27 20:55:07 +000043#include "llvm/Support/YAMLTraits.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000044#include <algorithm>
45#include <cassert>
46#include <cstddef>
47#include <cstdint>
48#include <memory>
49#include <string>
50#include <utility>
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +000051#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000052
Owen Anderson20b34ac2009-07-16 18:04:31 +000053namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000054
Simon Pilgrim716a5872020-04-24 13:07:02 +010055class StringRef;
Owen Anderson20b34ac2009-07-16 18:04:31 +000056class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000057class Value;
Eugene Zelenkode6cce22017-06-19 22:05:08 +000058class ValueHandleBase;
Owen Anderson20b34ac2009-07-16 18:04:31 +000059
Benjamin Kramer079b96e2013-09-11 18:05:11 +000060struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000061 static inline APInt getEmptyKey() {
62 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000063 V.U.VAL = 0;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000064 return V;
65 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000066
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000067 static inline APInt getTombstoneKey() {
68 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000069 V.U.VAL = 1;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000070 return V;
71 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000072
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000073 static unsigned getHashValue(const APInt &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000074 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000075 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000076
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000077 static bool isEqual(const APInt &LHS, const APInt &RHS) {
78 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
79 }
Owen Anderson20b34ac2009-07-16 18:04:31 +000080};
81
Benjamin Kramer079b96e2013-09-11 18:05:11 +000082struct DenseMapAPFloatKeyInfo {
Stephan Bergmann17c7f702016-12-14 11:57:17 +000083 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
84 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000085
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000086 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000087 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000088 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000089
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000090 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
91 return LHS.bitwiseIsEqual(RHS);
92 }
Owen Andersonc277dc42009-07-16 19:05:41 +000093};
94
Benjamin Kramer079b96e2013-09-11 18:05:11 +000095struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000096 struct KeyTy {
97 ArrayRef<Type*> ETypes;
98 bool isPacked;
Eugene Zelenkode6cce22017-06-19 22:05:08 +000099
Jay Foad529776c2012-02-23 09:17:40 +0000100 KeyTy(const ArrayRef<Type*>& E, bool P) :
101 ETypes(E), isPacked(P) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000102
Rafael Espindola334b73f2014-11-21 18:53:05 +0000103 KeyTy(const StructType *ST)
104 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000105
Jay Foad529776c2012-02-23 09:17:40 +0000106 bool operator==(const KeyTy& that) const {
107 if (isPacked != that.isPacked)
108 return false;
109 if (ETypes != that.ETypes)
110 return false;
111 return true;
112 }
113 bool operator!=(const KeyTy& that) const {
114 return !this->operator==(that);
115 }
116 };
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000117
Jay Foad529776c2012-02-23 09:17:40 +0000118 static inline StructType* getEmptyKey() {
119 return DenseMapInfo<StructType*>::getEmptyKey();
120 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000121
Jay Foad529776c2012-02-23 09:17:40 +0000122 static inline StructType* getTombstoneKey() {
123 return DenseMapInfo<StructType*>::getTombstoneKey();
124 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000125
Jay Foad529776c2012-02-23 09:17:40 +0000126 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000127 return hash_combine(hash_combine_range(Key.ETypes.begin(),
128 Key.ETypes.end()),
129 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000130 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000131
Jay Foad529776c2012-02-23 09:17:40 +0000132 static unsigned getHashValue(const StructType *ST) {
133 return getHashValue(KeyTy(ST));
134 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000135
Jay Foad529776c2012-02-23 09:17:40 +0000136 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
137 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
138 return false;
139 return LHS == KeyTy(RHS);
140 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000141
Jay Foad529776c2012-02-23 09:17:40 +0000142 static bool isEqual(const StructType *LHS, const StructType *RHS) {
143 return LHS == RHS;
144 }
145};
146
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000147struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000148 struct KeyTy {
149 const Type *ReturnType;
150 ArrayRef<Type*> Params;
151 bool isVarArg;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000152
Jay Foad529776c2012-02-23 09:17:40 +0000153 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
154 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindolae973fd42014-11-21 19:03:35 +0000155 KeyTy(const FunctionType *FT)
156 : ReturnType(FT->getReturnType()), Params(FT->params()),
157 isVarArg(FT->isVarArg()) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000158
Jay Foad529776c2012-02-23 09:17:40 +0000159 bool operator==(const KeyTy& that) const {
160 if (ReturnType != that.ReturnType)
161 return false;
162 if (isVarArg != that.isVarArg)
163 return false;
164 if (Params != that.Params)
165 return false;
166 return true;
167 }
168 bool operator!=(const KeyTy& that) const {
169 return !this->operator==(that);
170 }
171 };
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000172
Jay Foad529776c2012-02-23 09:17:40 +0000173 static inline FunctionType* getEmptyKey() {
174 return DenseMapInfo<FunctionType*>::getEmptyKey();
175 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000176
Jay Foad529776c2012-02-23 09:17:40 +0000177 static inline FunctionType* getTombstoneKey() {
178 return DenseMapInfo<FunctionType*>::getTombstoneKey();
179 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000180
Jay Foad529776c2012-02-23 09:17:40 +0000181 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000182 return hash_combine(Key.ReturnType,
183 hash_combine_range(Key.Params.begin(),
184 Key.Params.end()),
185 Key.isVarArg);
Jay Foad529776c2012-02-23 09:17:40 +0000186 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000187
Jay Foad529776c2012-02-23 09:17:40 +0000188 static unsigned getHashValue(const FunctionType *FT) {
189 return getHashValue(KeyTy(FT));
190 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000191
Jay Foad529776c2012-02-23 09:17:40 +0000192 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
193 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
194 return false;
195 return LHS == KeyTy(RHS);
196 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000197
Jay Foad529776c2012-02-23 09:17:40 +0000198 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
199 return LHS == RHS;
200 }
201};
202
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000203/// Structure for hashing arbitrary MDNode operands.
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000204class MDNodeOpsKey {
205 ArrayRef<Metadata *> RawOps;
206 ArrayRef<MDOperand> Ops;
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000207 unsigned Hash;
208
209protected:
210 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
211 : RawOps(Ops), Hash(calculateHash(Ops)) {}
212
213 template <class NodeTy>
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000214 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000215 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000216
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000217 template <class NodeTy>
218 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000219 if (getHash() != RHS->getHash())
220 return false;
221
222 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000223 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
224 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000225 }
226
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000227 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000228
229private:
230 template <class T>
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000231 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
232 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000233 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000234 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000235 }
236
237 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
238
239public:
240 unsigned getHash() const { return Hash; }
241};
242
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000243template <class NodeTy> struct MDNodeKeyImpl;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000244
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000245/// Configuration point for MDNodeInfo::isEqual().
246template <class NodeTy> struct MDNodeSubsetEqualImpl {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000247 using KeyTy = MDNodeKeyImpl<NodeTy>;
248
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000249 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
250 return false;
251 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000252
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000253 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
254 return false;
255 }
256};
257
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000258/// DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000259///
260/// Note that we don't need the is-function-local bit, since that's implicit in
261/// the operands.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000262template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
263 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
264 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +0000265
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000266 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000267
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000268 unsigned getHashValue() const { return getHash(); }
269
270 static unsigned calculateHash(MDTuple *N) {
271 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000272 }
273};
274
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000275/// DenseMapInfo for DILocation.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000276template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000277 unsigned Line;
278 unsigned Column;
279 Metadata *Scope;
280 Metadata *InlinedAt;
Calixte Denizeteb7f6022018-09-20 08:53:06 +0000281 bool ImplicitCode;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000282
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000283 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
Calixte Denizeteb7f6022018-09-20 08:53:06 +0000284 Metadata *InlinedAt, bool ImplicitCode)
285 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
286 ImplicitCode(ImplicitCode) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000287 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000288 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
Calixte Denizeteb7f6022018-09-20 08:53:06 +0000289 InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000290
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000291 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000292 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Calixte Denizeteb7f6022018-09-20 08:53:06 +0000293 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
294 ImplicitCode == RHS->isImplicitCode();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000295 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000296
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000297 unsigned getHashValue() const {
Calixte Denizeteb7f6022018-09-20 08:53:06 +0000298 return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000299 }
300};
301
Adrian Prantl5f8f34e42018-05-01 15:54:18 +0000302/// DenseMapInfo for GenericDINode.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000303template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000304 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000305 MDString *Header;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000306
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000307 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000308 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000309 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000310 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000311
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000312 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000313 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000314 compareOps(RHS, 1);
315 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000316
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000317 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
318
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000319 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000320 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000321 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000322};
323
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000324template <> struct MDNodeKeyImpl<DISubrange> {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000325 Metadata *CountNode;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000326 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000327
Sander de Smalenfdf40912018-01-24 09:56:07 +0000328 MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
329 : CountNode(CountNode), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000330 MDNodeKeyImpl(const DISubrange *N)
Sander de Smalenfdf40912018-01-24 09:56:07 +0000331 : CountNode(N->getRawCountNode()),
332 LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000333
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334 bool isKeyOf(const DISubrange *RHS) const {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000335 if (LowerBound != RHS->getLowerBound())
336 return false;
337
338 if (auto *RHSCount = RHS->getCount().dyn_cast<ConstantInt*>())
339 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
340 if (RHSCount->getSExtValue() ==
341 cast<ConstantInt>(MD->getValue())->getSExtValue())
342 return true;
343
344 return CountNode == RHS->getRawCountNode();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000345 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000346
Sander de Smalenfdf40912018-01-24 09:56:07 +0000347 unsigned getHashValue() const {
348 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
349 return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
350 LowerBound);
351 return hash_combine(CountNode, LowerBound);
352 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000353};
354
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000355template <> struct MDNodeKeyImpl<DIEnumerator> {
LemonBoyaad3d572020-04-18 11:31:38 -0700356 APInt Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000357 MDString *Name;
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000358 bool IsUnsigned;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000359
LemonBoyaad3d572020-04-18 11:31:38 -0700360 MDNodeKeyImpl(APInt Value, bool IsUnsigned, MDString *Name)
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000361 : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
LemonBoyaad3d572020-04-18 11:31:38 -0700362 MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
363 : Value(APInt(64, Value, !IsUnsigned)), Name(Name),
364 IsUnsigned(IsUnsigned) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000365 MDNodeKeyImpl(const DIEnumerator *N)
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000366 : Value(N->getValue()), Name(N->getRawName()),
367 IsUnsigned(N->isUnsigned()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000368
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000369 bool isKeyOf(const DIEnumerator *RHS) const {
LemonBoyaad3d572020-04-18 11:31:38 -0700370 return APInt::isSameValue(Value, RHS->getValue()) &&
371 IsUnsigned == RHS->isUnsigned() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000372 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000373
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000374 unsigned getHashValue() const { return hash_combine(Value, Name); }
375};
376
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000377template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000378 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000379 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000380 uint64_t SizeInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000381 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000382 unsigned Encoding;
Adrian Prantl55f42622018-08-14 19:35:34 +0000383 unsigned Flags;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000384
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000385 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Adrian Prantl55f42622018-08-14 19:35:34 +0000386 uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000387 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
Adrian Prantl55f42622018-08-14 19:35:34 +0000388 Encoding(Encoding), Flags(Flags) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000389 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000390 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Adrian Prantl55f42622018-08-14 19:35:34 +0000391 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000392
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000393 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000394 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000395 SizeInBits == RHS->getSizeInBits() &&
396 AlignInBits == RHS->getAlignInBits() &&
Adrian Prantl55f42622018-08-14 19:35:34 +0000397 Encoding == RHS->getEncoding() &&
398 Flags == RHS->getFlags();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000399 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000400
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000401 unsigned getHashValue() const {
402 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
403 }
404};
405
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000406template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000407 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000408 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000409 Metadata *File;
410 unsigned Line;
411 Metadata *Scope;
412 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000413 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000414 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000415 uint32_t AlignInBits;
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000416 Optional<unsigned> DWARFAddressSpace;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000417 unsigned Flags;
418 Metadata *ExtraData;
419
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000420 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000421 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000422 uint32_t AlignInBits, uint64_t OffsetInBits,
423 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000424 Metadata *ExtraData)
425 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000426 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000427 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
428 Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000429 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000430 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000431 Line(N->getLine()), Scope(N->getRawScope()),
432 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000433 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000434 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
435 ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000436
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000437 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000438 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000439 File == RHS->getRawFile() && Line == RHS->getLine() &&
440 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000441 SizeInBits == RHS->getSizeInBits() &&
442 AlignInBits == RHS->getAlignInBits() &&
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000443 OffsetInBits == RHS->getOffsetInBits() &&
444 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
445 Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000446 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000447 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000448
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000449 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000450 // If this is a member inside an ODR type, only hash the type and the name.
451 // Otherwise the hash will be stronger than
452 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000453 if (Tag == dwarf::DW_TAG_member && Name)
454 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
455 if (CT->getRawIdentifier())
456 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000457
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000458 // Intentionally computes the hash on a subset of the operands for
459 // performance reason. The subset has to be significant enough to avoid
460 // collision "most of the time". There is no correctness issue in case of
461 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000462 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000463 }
464};
465
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000466template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000467 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
468
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000469 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
470 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
471 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000472
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000473 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
474 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
475 RHS);
476 }
477
478 /// Subprograms compare equal if they declare the same function in an ODR
479 /// type.
480 static bool isODRMember(unsigned Tag, const Metadata *Scope,
481 const MDString *Name, const DIDerivedType *RHS) {
482 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000483 if (Tag != dwarf::DW_TAG_member || !Name)
484 return false;
485
486 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
487 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000488 return false;
489
490 // Compare to the RHS.
491 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
492 Scope == RHS->getRawScope();
493 }
494};
495
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000496template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000497 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000498 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000499 Metadata *File;
500 unsigned Line;
501 Metadata *Scope;
502 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000503 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000504 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000505 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000506 unsigned Flags;
507 Metadata *Elements;
508 unsigned RuntimeLang;
509 Metadata *VTableHolder;
510 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000511 MDString *Identifier;
Adrian Prantl8c599212018-02-06 23:45:59 +0000512 Metadata *Discriminator;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000513
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000514 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000515 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000516 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000517 Metadata *Elements, unsigned RuntimeLang,
518 Metadata *VTableHolder, Metadata *TemplateParams,
Adrian Prantl8c599212018-02-06 23:45:59 +0000519 MDString *Identifier, Metadata *Discriminator)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000520 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000521 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
522 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000523 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
Adrian Prantl8c599212018-02-06 23:45:59 +0000524 TemplateParams(TemplateParams), Identifier(Identifier),
525 Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000526 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000527 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000528 Line(N->getLine()), Scope(N->getRawScope()),
529 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000530 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000531 Flags(N->getFlags()), Elements(N->getRawElements()),
532 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
533 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl8c599212018-02-06 23:45:59 +0000534 Identifier(N->getRawIdentifier()),
535 Discriminator(N->getRawDiscriminator()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000537 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000538 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000539 File == RHS->getRawFile() && Line == RHS->getLine() &&
540 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000541 SizeInBits == RHS->getSizeInBits() &&
542 AlignInBits == RHS->getAlignInBits() &&
543 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000544 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000545 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000546 VTableHolder == RHS->getRawVTableHolder() &&
547 TemplateParams == RHS->getRawTemplateParams() &&
Adrian Prantl8c599212018-02-06 23:45:59 +0000548 Identifier == RHS->getRawIdentifier() &&
549 Discriminator == RHS->getRawDiscriminator();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000550 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000551
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000552 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000553 // Intentionally computes the hash on a subset of the operands for
554 // performance reason. The subset has to be significant enough to avoid
555 // collision "most of the time". There is no correctness issue in case of
556 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000557 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
558 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000559 }
560};
561
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000562template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000563 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000564 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000565 Metadata *TypeArray;
566
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000567 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
568 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000569 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000570 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000571
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000572 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000573 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
574 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000575 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000576
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000577 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000578};
579
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000580template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000581 MDString *Filename;
582 MDString *Directory;
Scott Linder71603842018-02-12 19:45:54 +0000583 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
Scott Linder16c7bda2018-02-23 23:01:06 +0000584 Optional<MDString *> Source;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000585
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000586 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
Scott Linder16c7bda2018-02-23 23:01:06 +0000587 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
588 Optional<MDString *> Source)
589 : Filename(Filename), Directory(Directory), Checksum(Checksum),
590 Source(Source) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000591 MDNodeKeyImpl(const DIFile *N)
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000592 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
Scott Linder16c7bda2018-02-23 23:01:06 +0000593 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000594
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000595 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000596 return Filename == RHS->getRawFilename() &&
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000597 Directory == RHS->getRawDirectory() &&
Scott Linder16c7bda2018-02-23 23:01:06 +0000598 Checksum == RHS->getRawChecksum() &&
599 Source == RHS->getRawSource();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000600 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000601
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000602 unsigned getHashValue() const {
Scott Linder16c7bda2018-02-23 23:01:06 +0000603 return hash_combine(
604 Filename, Directory, Checksum ? Checksum->Kind : 0,
605 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000606 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000607};
608
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000609template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000610 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000611 MDString *Name;
612 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000613 Metadata *File;
614 unsigned Line;
615 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000616 unsigned ScopeLine;
617 Metadata *ContainingType;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000618 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000619 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000620 unsigned Flags;
Paul Robinsoncda54212018-11-19 18:29:28 +0000621 unsigned SPFlags;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000622 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000623 Metadata *TemplateParams;
624 Metadata *Declaration;
Shiva Chen2c864552018-05-09 02:40:45 +0000625 Metadata *RetainedNodes;
Adrian Prantl1d12b882017-04-26 22:56:44 +0000626 Metadata *ThrownTypes;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000627
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000628 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000629 Metadata *File, unsigned Line, Metadata *Type,
Paul Robinsoncda54212018-11-19 18:29:28 +0000630 unsigned ScopeLine, Metadata *ContainingType,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000631 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
Paul Robinsoncda54212018-11-19 18:29:28 +0000632 unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
Shiva Chen2c864552018-05-09 02:40:45 +0000633 Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000634 Metadata *ThrownTypes)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000635 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
Paul Robinsoncda54212018-11-19 18:29:28 +0000636 Line(Line), Type(Type), ScopeLine(ScopeLine),
637 ContainingType(ContainingType), VirtualIndex(VirtualIndex),
638 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
639 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
Shiva Chen2c864552018-05-09 02:40:45 +0000640 RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000641 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000642 : Scope(N->getRawScope()), Name(N->getRawName()),
643 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000644 Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()),
645 ContainingType(N->getRawContainingType()),
646 VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000647 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000648 SPFlags(N->getSPFlags()), Unit(N->getRawUnit()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000649 TemplateParams(N->getRawTemplateParams()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000650 Declaration(N->getRawDeclaration()),
651 RetainedNodes(N->getRawRetainedNodes()),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000652 ThrownTypes(N->getRawThrownTypes()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000654 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000655 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
656 LinkageName == RHS->getRawLinkageName() &&
657 File == RHS->getRawFile() && Line == RHS->getLine() &&
Paul Robinsoncda54212018-11-19 18:29:28 +0000658 Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000659 ContainingType == RHS->getRawContainingType() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000660 VirtualIndex == RHS->getVirtualIndex() &&
661 ThisAdjustment == RHS->getThisAdjustment() &&
Paul Robinsoncda54212018-11-19 18:29:28 +0000662 Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000663 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000664 TemplateParams == RHS->getRawTemplateParams() &&
665 Declaration == RHS->getRawDeclaration() &&
Shiva Chen2c864552018-05-09 02:40:45 +0000666 RetainedNodes == RHS->getRawRetainedNodes() &&
Adrian Prantl1d12b882017-04-26 22:56:44 +0000667 ThrownTypes == RHS->getRawThrownTypes();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000668 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000669
Paul Robinsoncda54212018-11-19 18:29:28 +0000670 bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
671
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000672 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000673 // If this is a declaration inside an ODR type, only hash the type and the
674 // name. Otherwise the hash will be stronger than
675 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Paul Robinsoncda54212018-11-19 18:29:28 +0000676 if (!isDefinition() && LinkageName)
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000677 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
678 if (CT->getRawIdentifier())
679 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000680
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000681 // Intentionally computes the hash on a subset of the operands for
682 // performance reason. The subset has to be significant enough to avoid
683 // collision "most of the time". There is no correctness issue in case of
684 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000685 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000686 }
687};
688
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000689template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000690 using KeyTy = MDNodeKeyImpl<DISubprogram>;
691
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000692 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
Paul Robinsoncda54212018-11-19 18:29:28 +0000693 return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000694 LHS.LinkageName, LHS.TemplateParams, RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000695 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000696
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000697 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
698 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000699 LHS->getRawLinkageName(),
700 LHS->getRawTemplateParams(), RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000701 }
702
703 /// Subprograms compare equal if they declare the same function in an ODR
704 /// type.
705 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
706 const MDString *LinkageName,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000707 const Metadata *TemplateParams,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000708 const DISubprogram *RHS) {
709 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000710 if (IsDefinition || !Scope || !LinkageName)
711 return false;
712
713 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
714 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000715 return false;
716
717 // Compare to the RHS.
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000718 // FIXME: We need to compare template parameters here to avoid incorrect
719 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
720 // has a non-ODR template parameter (i.e., a DICompositeType that does not
721 // have an identifier). Eventually we should decouple ODR logic from
722 // uniquing logic.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000723 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000724 LinkageName == RHS->getRawLinkageName() &&
725 TemplateParams == RHS->getRawTemplateParams();
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000726 }
727};
728
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000729template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000730 Metadata *Scope;
731 Metadata *File;
732 unsigned Line;
733 unsigned Column;
734
735 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
736 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000737 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000738 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000739 Column(N->getColumn()) {}
740
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000741 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000742 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000743 Line == RHS->getLine() && Column == RHS->getColumn();
744 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000745
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000746 unsigned getHashValue() const {
747 return hash_combine(Scope, File, Line, Column);
748 }
749};
750
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000751template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000752 Metadata *Scope;
753 Metadata *File;
754 unsigned Discriminator;
755
756 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
757 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000758 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000759 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000760 Discriminator(N->getDiscriminator()) {}
761
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000762 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000763 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000764 Discriminator == RHS->getDiscriminator();
765 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000766
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000767 unsigned getHashValue() const {
768 return hash_combine(Scope, File, Discriminator);
769 }
770};
771
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000772template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000773 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000774 MDString *Name;
Adrian Prantldbfda632016-11-03 19:42:02 +0000775 bool ExportSymbols;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000776
Adrian Prantlfed4f392017-04-28 22:25:46 +0000777 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
778 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000779 MDNodeKeyImpl(const DINamespace *N)
Adrian Prantlfed4f392017-04-28 22:25:46 +0000780 : Scope(N->getRawScope()), Name(N->getRawName()),
781 ExportSymbols(N->getExportSymbols()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000782
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000783 bool isKeyOf(const DINamespace *RHS) const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000784 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Adrian Prantldbfda632016-11-03 19:42:02 +0000785 ExportSymbols == RHS->getExportSymbols();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000786 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000787
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000788 unsigned getHashValue() const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000789 return hash_combine(Scope, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000790 }
791};
792
Adrian Prantl6ed57062019-04-08 19:13:55 +0000793template <> struct MDNodeKeyImpl<DICommonBlock> {
794 Metadata *Scope;
795 Metadata *Decl;
796 MDString *Name;
797 Metadata *File;
798 unsigned LineNo;
799
800 MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name,
801 Metadata *File, unsigned LineNo)
802 : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {}
803 MDNodeKeyImpl(const DICommonBlock *N)
804 : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()),
805 File(N->getRawFile()), LineNo(N->getLineNo()) {}
806
807 bool isKeyOf(const DICommonBlock *RHS) const {
808 return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() &&
809 Name == RHS->getRawName() && File == RHS->getRawFile() &&
810 LineNo == RHS->getLineNo();
811 }
812
813 unsigned getHashValue() const {
814 return hash_combine(Scope, Decl, Name, File, LineNo);
815 }
816};
817
Adrian Prantlab1243f2015-06-29 23:03:47 +0000818template <> struct MDNodeKeyImpl<DIModule> {
819 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000820 MDString *Name;
821 MDString *ConfigurationMacros;
822 MDString *IncludePath;
Adrian Prantld5180ea2020-03-03 16:05:23 -0800823 MDString *APINotesFile;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000824
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000825 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
Adrian Prantld5180ea2020-03-03 16:05:23 -0800826 MDString *IncludePath, MDString *APINotesFile)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000827 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
Adrian Prantld5180ea2020-03-03 16:05:23 -0800828 IncludePath(IncludePath), APINotesFile(APINotesFile) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000829 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000830 : Scope(N->getRawScope()), Name(N->getRawName()),
831 ConfigurationMacros(N->getRawConfigurationMacros()),
Adrian Prantld5180ea2020-03-03 16:05:23 -0800832 IncludePath(N->getRawIncludePath()),
833 APINotesFile(N->getRawAPINotesFile()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000834
835 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000836 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
837 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
Adrian Prantld5180ea2020-03-03 16:05:23 -0800838 IncludePath == RHS->getRawIncludePath() &&
839 APINotesFile == RHS->getRawAPINotesFile();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000840 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000841
Adrian Prantlab1243f2015-06-29 23:03:47 +0000842 unsigned getHashValue() const {
Adrian Prantl7b303702020-01-14 13:37:04 -0800843 return hash_combine(Scope, Name, ConfigurationMacros, IncludePath);
Adrian Prantlab1243f2015-06-29 23:03:47 +0000844 }
845};
846
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000847template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000848 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000849 Metadata *Type;
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530850 bool IsDefault;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000851
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530852 MDNodeKeyImpl(MDString *Name, Metadata *Type, bool IsDefault)
853 : Name(Name), Type(Type), IsDefault(IsDefault) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000854 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530855 : Name(N->getRawName()), Type(N->getRawType()),
856 IsDefault(N->isDefault()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000857
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000858 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530859 return Name == RHS->getRawName() && Type == RHS->getRawType() &&
860 IsDefault == RHS->isDefault();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000861 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000862
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530863 unsigned getHashValue() const { return hash_combine(Name, Type, IsDefault); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000864};
865
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000866template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000867 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000868 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000869 Metadata *Type;
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530870 bool IsDefault;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000871 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000872
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530873 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, bool IsDefault,
874 Metadata *Value)
875 : Tag(Tag), Name(Name), Type(Type), IsDefault(IsDefault), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000876 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000877 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530878 IsDefault(N->isDefault()), Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000879
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000880 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000881 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530882 Type == RHS->getRawType() && IsDefault == RHS->isDefault() &&
883 Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000884 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000885
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530886 unsigned getHashValue() const {
887 return hash_combine(Tag, Name, Type, IsDefault, Value);
888 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000889};
890
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000891template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000892 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000893 MDString *Name;
894 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000895 Metadata *File;
896 unsigned Line;
897 Metadata *Type;
898 bool IsLocalToUnit;
899 bool IsDefinition;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000900 Metadata *StaticDataMemberDeclaration;
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000901 Metadata *TemplateParams;
Victor Leschuka37660c2016-10-26 21:32:29 +0000902 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000903
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000904 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000905 Metadata *File, unsigned Line, Metadata *Type,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000906 bool IsLocalToUnit, bool IsDefinition,
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000907 Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
908 uint32_t AlignInBits)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000909 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
910 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000911 IsDefinition(IsDefinition),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000912 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000913 TemplateParams(TemplateParams), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000914 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000915 : Scope(N->getRawScope()), Name(N->getRawName()),
916 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000917 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000918 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000919 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000920 TemplateParams(N->getRawTemplateParams()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000921 AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000922
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000923 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000924 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
925 LinkageName == RHS->getRawLinkageName() &&
926 File == RHS->getRawFile() && Line == RHS->getLine() &&
927 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000928 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000929 StaticDataMemberDeclaration ==
Victor Leschuk2ede1262016-10-20 00:13:12 +0000930 RHS->getRawStaticDataMemberDeclaration() &&
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000931 TemplateParams == RHS->getRawTemplateParams() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000932 AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000933 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000934
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000935 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000936 // We do not use AlignInBits in hashing function here on purpose:
937 // in most cases this param for local variable is zero (for function param
938 // it is always zero). This leads to lots of hash collisions and errors on
939 // cases with lots of similar variables.
940 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
941 // generated IR is random for each run and test fails with Align included.
942 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000943 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000944 IsLocalToUnit, IsDefinition, /* AlignInBits, */
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000945 StaticDataMemberDeclaration);
946 }
947};
948
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000949template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000950 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000951 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000952 Metadata *File;
953 unsigned Line;
954 Metadata *Type;
955 unsigned Arg;
956 unsigned Flags;
Victor Leschuka37660c2016-10-26 21:32:29 +0000957 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000958
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000959 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000960 Metadata *Type, unsigned Arg, unsigned Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000961 uint32_t AlignInBits)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000962 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000963 Flags(Flags), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000964 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000965 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000966 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000967 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000968
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000969 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000970 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000971 File == RHS->getRawFile() && Line == RHS->getLine() &&
972 Type == RHS->getRawType() && Arg == RHS->getArg() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000973 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000974 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000975
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000976 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000977 // We do not use AlignInBits in hashing function here on purpose:
978 // in most cases this param for local variable is zero (for function param
979 // it is always zero). This leads to lots of hash collisions and errors on
980 // cases with lots of similar variables.
981 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
982 // generated IR is random for each run and test fails with Align included.
983 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000984 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000985 }
986};
987
Shiva Chen2c864552018-05-09 02:40:45 +0000988template <> struct MDNodeKeyImpl<DILabel> {
989 Metadata *Scope;
990 MDString *Name;
991 Metadata *File;
992 unsigned Line;
993
994 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
995 : Scope(Scope), Name(Name), File(File), Line(Line) {}
996 MDNodeKeyImpl(const DILabel *N)
997 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
998 Line(N->getLine()) {}
999
1000 bool isKeyOf(const DILabel *RHS) const {
1001 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
1002 File == RHS->getRawFile() && Line == RHS->getLine();
1003 }
1004
1005 /// Using name and line to get hash value. It should already be mostly unique.
1006 unsigned getHashValue() const {
1007 return hash_combine(Scope, Name, Line);
1008 }
1009};
1010
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001011template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001012 ArrayRef<uint64_t> Elements;
1013
1014 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001015 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001016
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001017 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001018 return Elements == RHS->getElements();
1019 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001020
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001021 unsigned getHashValue() const {
1022 return hash_combine_range(Elements.begin(), Elements.end());
1023 }
1024};
1025
Adrian Prantlbceaaa92016-12-20 02:09:43 +00001026template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
1027 Metadata *Variable;
1028 Metadata *Expression;
1029
1030 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
1031 : Variable(Variable), Expression(Expression) {}
1032 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
1033 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
1034
1035 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
1036 return Variable == RHS->getRawVariable() &&
1037 Expression == RHS->getRawExpression();
1038 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001039
Adrian Prantlbceaaa92016-12-20 02:09:43 +00001040 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
1041};
1042
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001043template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001044 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001045 Metadata *File;
1046 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001047 MDString *GetterName;
1048 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001049 unsigned Attributes;
1050 Metadata *Type;
1051
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001052 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
1053 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001054 Metadata *Type)
1055 : Name(Name), File(File), Line(Line), GetterName(GetterName),
1056 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001057 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001058 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
1059 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001060 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001061
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001062 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001063 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1064 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1065 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001066 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001067 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001068
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001069 unsigned getHashValue() const {
1070 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1071 Type);
1072 }
1073};
1074
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001075template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001076 unsigned Tag;
1077 Metadata *Scope;
1078 Metadata *Entity;
Adrian Prantld63bfd22017-07-19 00:09:54 +00001079 Metadata *File;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001080 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001081 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001082
Adrian Prantld63bfd22017-07-19 00:09:54 +00001083 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1084 unsigned Line, MDString *Name)
1085 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1086 Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001087 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001088 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Adrian Prantld63bfd22017-07-19 00:09:54 +00001089 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001090
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001091 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001092 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
Adrian Prantld63bfd22017-07-19 00:09:54 +00001093 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1094 Line == RHS->getLine() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001095 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001096
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001097 unsigned getHashValue() const {
Adrian Prantld63bfd22017-07-19 00:09:54 +00001098 return hash_combine(Tag, Scope, Entity, File, Line, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001099 }
1100};
1101
Amjad Abouda9bcf162015-12-10 12:56:35 +00001102template <> struct MDNodeKeyImpl<DIMacro> {
1103 unsigned MIType;
1104 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001105 MDString *Name;
1106 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +00001107
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001108 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +00001109 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1110 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001111 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1112 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001113
1114 bool isKeyOf(const DIMacro *RHS) const {
1115 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001116 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +00001117 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001118
Amjad Abouda9bcf162015-12-10 12:56:35 +00001119 unsigned getHashValue() const {
1120 return hash_combine(MIType, Line, Name, Value);
1121 }
1122};
1123
1124template <> struct MDNodeKeyImpl<DIMacroFile> {
1125 unsigned MIType;
1126 unsigned Line;
1127 Metadata *File;
1128 Metadata *Elements;
1129
1130 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1131 Metadata *Elements)
1132 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1133 MDNodeKeyImpl(const DIMacroFile *N)
1134 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1135 Elements(N->getRawElements()) {}
1136
1137 bool isKeyOf(const DIMacroFile *RHS) const {
1138 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +00001139 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +00001140 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001141
Amjad Abouda9bcf162015-12-10 12:56:35 +00001142 unsigned getHashValue() const {
1143 return hash_combine(MIType, Line, File, Elements);
1144 }
1145};
1146
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001147/// DenseMapInfo for MDNode subclasses.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001148template <class NodeTy> struct MDNodeInfo {
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001149 using KeyTy = MDNodeKeyImpl<NodeTy>;
1150 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1151
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001152 static inline NodeTy *getEmptyKey() {
1153 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001154 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001155
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001156 static inline NodeTy *getTombstoneKey() {
1157 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001158 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001159
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001160 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001161
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001162 static unsigned getHashValue(const NodeTy *N) {
1163 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001164 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001165
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001166 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1167 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1168 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001169 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001170 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001171
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001172 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001173 if (LHS == RHS)
1174 return true;
1175 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1176 return false;
1177 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001178 }
1179};
1180
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001181#define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001182#include "llvm/IR/Metadata.def"
1183
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001184/// Map-like storage for metadata attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001185class MDAttachmentMap {
1186 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1187
1188public:
1189 bool empty() const { return Attachments.empty(); }
1190 size_t size() const { return Attachments.size(); }
1191
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001192 /// Get a particular attachment (if any).
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001193 MDNode *lookup(unsigned ID) const;
1194
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001195 /// Set an attachment to a particular node.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001196 ///
1197 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1198 /// ID (if anyway).
1199 void set(unsigned ID, MDNode &MD);
1200
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001201 /// Remove an attachment.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001202 ///
1203 /// Remove the attachment at \c ID, if any.
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001204 bool erase(unsigned ID);
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001205
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001206 /// Copy out all the attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001207 ///
1208 /// Copies all the current attachments into \c Result, sorting by attachment
1209 /// ID. This function does \em not clear \c Result.
1210 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1211
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001212 /// Erase matching attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001213 ///
1214 /// Erases all attachments matching the \c shouldRemove predicate.
1215 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemer2d006e72016-08-12 04:32:42 +00001216 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1217 Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001218 }
1219};
1220
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001221/// Multimap-like storage for metadata attachments for globals. This differs
1222/// from MDAttachmentMap in that it allows multiple attachments per metadata
1223/// kind.
1224class MDGlobalAttachmentMap {
1225 struct Attachment {
1226 unsigned MDKind;
1227 TrackingMDNodeRef Node;
1228 };
1229 SmallVector<Attachment, 1> Attachments;
1230
1231public:
1232 bool empty() const { return Attachments.empty(); }
1233
1234 /// Appends all attachments with the given ID to \c Result in insertion order.
1235 /// If the global has no attachments with the given ID, or if ID is invalid,
1236 /// leaves Result unchanged.
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001237 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
1238
1239 /// Returns the first attachment with the given ID or nullptr if no such
1240 /// attachment exists.
1241 MDNode *lookup(unsigned ID) const;
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001242
1243 void insert(unsigned ID, MDNode &MD);
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001244 bool erase(unsigned ID);
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001245
1246 /// Appends all attachments for the global to \c Result, sorting by attachment
1247 /// ID. Attachments with the same ID appear in insertion order. This function
1248 /// does \em not clear \c Result.
1249 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1250};
1251
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001252class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001253public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001254 /// OwnedModules - The set of modules instantiated in this context, and which
1255 /// will be automatically deleted if this context is deleted.
1256 SmallPtrSet<Module*, 4> OwnedModules;
Fangrui Songf78650a2018-07-30 19:41:25 +00001257
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001258 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1259 void *InlineAsmDiagContext = nullptr;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001260
Francis Visoiu Mistrih7531a502019-10-28 14:53:31 -07001261 /// The main remark streamer used by all the other streamers (e.g. IR, MIR,
1262 /// frontends, etc.). This should only be used by the specific streamers, and
1263 /// never directly.
1264 std::unique_ptr<remarks::RemarkStreamer> MainRemarkStreamer;
1265
Vivek Pandyab5ab8952017-09-15 20:10:09 +00001266 std::unique_ptr<DiagnosticHandler> DiagHandler;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001267 bool RespectDiagnosticFilters = false;
Brian Gesiak44e5f6c2017-06-30 18:13:59 +00001268 bool DiagnosticsHotnessRequested = false;
Brian Gesiak4ef3daa2017-06-30 23:14:53 +00001269 uint64_t DiagnosticsHotnessThreshold = 0;
Francis Visoiu Mistrih7531a502019-10-28 14:53:31 -07001270 /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter.
Francis Visoiu Mistrih31258872020-02-04 17:42:47 -08001271 std::unique_ptr<LLVMRemarkStreamer> LLVMRS;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001272
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001273 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1274 void *YieldOpaqueHandle = nullptr;
Juergen Ributzka34390c72014-05-16 02:33:15 +00001275
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001276 using IntMapTy =
1277 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001278 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001279
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001280 using FPMapTy =
1281 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
Owen Andersonc277dc42009-07-16 19:05:41 +00001282 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001283
Bill Wendling4607f4b2012-12-20 01:36:59 +00001284 FoldingSet<AttributeImpl> AttrsSet;
Reid Klecknerb5180542017-03-21 16:57:19 +00001285 FoldingSet<AttributeListImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001286 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001287
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001288 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001289 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1290 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001291
Owen Anderson7349ab92015-06-01 22:24:01 +00001292 DenseMap<const Value*, ValueName*> ValueNames;
1293
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001294#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1295 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001296#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001297
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001298 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001299 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001300
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001301 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1302 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001303 // one object can destroy them. Keep track of them here so we can delete
1304 // them on context teardown.
1305 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001306
Justin Lebar611c5c22016-10-10 16:26:13 +00001307 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001308
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001309 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001310 ArrayConstantsTy ArrayConstants;
Fangrui Songf78650a2018-07-30 19:41:25 +00001311
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001312 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001313 StructConstantsTy StructConstants;
Fangrui Songf78650a2018-07-30 19:41:25 +00001314
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001315 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001316 VectorConstantsTy VectorConstants;
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001317
Justin Lebar611c5c22016-10-10 16:26:13 +00001318 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1319
1320 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1321
Chris Lattner3756b912012-01-23 22:57:10 +00001322 StringMap<ConstantDataSequential*> CDSConstants;
1323
Chandler Carruth6a936922014-01-19 02:13:50 +00001324 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1325 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001326 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001327
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001328 ConstantUniqueMap<InlineAsm> InlineAsms;
1329
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001330 ConstantInt *TheTrueVal = nullptr;
1331 ConstantInt *TheFalseVal = nullptr;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001332
David Majnemer2dd41c52015-11-16 20:55:57 +00001333 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001334
Dan Gohman97d2cb82009-08-25 16:00:35 +00001335 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001336 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001337 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001338 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Fangrui Songf78650a2018-07-30 19:41:25 +00001339
Peter Collingbourne10c548c2019-05-29 03:28:51 +00001340 BumpPtrAllocator Alloc;
1341 UniqueStringSaver Saver{Alloc};
Fangrui Songf78650a2018-07-30 19:41:25 +00001342
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001343 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001344
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001345 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001346 FunctionTypeSet FunctionTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001347 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001348 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001349 StringMap<StructType*> NamedStructTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001350 unsigned NamedStructTypesUniqueID = 0;
Fangrui Songf78650a2018-07-30 19:41:25 +00001351
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001352 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
Graham Hunter957c40d2019-07-05 12:48:16 +00001353 DenseMap<std::pair<Type *, ElementCount>, VectorType*> VectorTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001354 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1355 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001356
Owen Andersone8f21852009-08-18 18:28:58 +00001357 /// ValueHandles - This map keeps track of all of the value handles that are
1358 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001359 /// whether or not a value has an entry in this map.
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001360 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
Owen Andersone8f21852009-08-18 18:28:58 +00001361 ValueHandlesTy ValueHandles;
Fangrui Songf78650a2018-07-30 19:41:25 +00001362
Chris Lattnera0566972009-12-29 09:01:33 +00001363 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1364 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001365
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001366 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001367 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001368
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001369 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001370 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001371
Reid Kleckner443423e2017-01-10 23:23:58 +00001372 /// Collection of per-GlobalObject sections used in this context.
1373 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1374
Peter Collingbourne31fda092019-05-29 03:29:01 +00001375 /// Collection of per-GlobalValue partitions used in this context.
1376 DenseMap<const GlobalValue *, StringRef> GlobalValuePartitions;
1377
Diego Novillof5041ce2014-03-03 20:06:11 +00001378 /// DiscriminatorTable - This table maps file:line locations to an
1379 /// integer representing the next DWARF path discriminator to assign to
1380 /// instructions in different blocks at the same location.
1381 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1382
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001383 /// A set of interned tags for operand bundles. The StringMap maps
Sanjoy Das9303c242015-09-24 19:14:18 +00001384 /// bundle tags to their IDs.
1385 ///
1386 /// \see LLVMContext::getOperandBundleTagID
1387 StringMap<uint32_t> BundleTagCache;
1388
1389 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1390 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1391 uint32_t getOperandBundleTagID(StringRef Tag) const;
1392
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00001393 /// A set of interned synchronization scopes. The StringMap maps
1394 /// synchronization scope names to their respective synchronization scope IDs.
1395 StringMap<SyncScope::ID> SSC;
1396
1397 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1398 /// synchronization scope ID. Every synchronization scope registered with
1399 /// LLVMContext has unique ID except pre-defined ones.
1400 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1401
1402 /// getSyncScopeNames - Populates client supplied SmallVector with
1403 /// synchronization scope names registered with LLVMContext. Synchronization
1404 /// scope names are ordered by increasing synchronization scope IDs.
1405 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1406
Mehdi Amini599ebf22016-01-08 02:28:20 +00001407 /// Maintain the GC name for each function.
1408 ///
1409 /// This saves allocating an additional word in Function for programs which
1410 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1411 /// clients which do use GC.
1412 DenseMap<const Function*, std::string> GCNames;
1413
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001414 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1415 /// not.
1416 bool DiscardValueNames = false;
1417
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001418 LLVMContextImpl(LLVMContext &C);
1419 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001420
1421 /// Destroy the ConstantArrays if they are not used.
1422 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001423
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001424 mutable OptPassGate *OPG = nullptr;
1425
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001426 /// Access the object which can disable optional passes and individual
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001427 /// optimizations at compile time.
1428 OptPassGate &getOptPassGate() const;
1429
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001430 /// Set the object which can disable optional passes and individual
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001431 /// optimizations at compile time.
1432 ///
1433 /// The lifetime of the object must be guaranteed to extend as long as the
1434 /// LLVMContext is used by compilation.
1435 void setOptPassGate(OptPassGate&);
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001436};
1437
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001438} // end namespace llvm
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001439
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001440#endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H