blob: 1c7d8746d242fdcb4143179d10248d14eb2b5482 [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;
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530326 Metadata *LowerBound;
327 Metadata *UpperBound;
328 Metadata *Stride;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000329
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530330 MDNodeKeyImpl(Metadata *CountNode, Metadata *LowerBound, Metadata *UpperBound,
331 Metadata *Stride)
332 : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound),
333 Stride(Stride) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000334 MDNodeKeyImpl(const DISubrange *N)
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530335 : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()),
336 UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000337
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000338 bool isKeyOf(const DISubrange *RHS) const {
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530339 auto BoundsEqual = [=](Metadata *Node1, Metadata *Node2) -> bool {
340 if (Node1 == Node2)
341 return true;
Sander de Smalenfdf40912018-01-24 09:56:07 +0000342
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530343 ConstantAsMetadata *MD1 = dyn_cast_or_null<ConstantAsMetadata>(Node1);
344 ConstantAsMetadata *MD2 = dyn_cast_or_null<ConstantAsMetadata>(Node2);
345 if (MD1 && MD2) {
346 ConstantInt *CV1 = cast<ConstantInt>(MD1->getValue());
347 ConstantInt *CV2 = cast<ConstantInt>(MD2->getValue());
348 if (CV1->getSExtValue() == CV2->getSExtValue())
Sander de Smalenfdf40912018-01-24 09:56:07 +0000349 return true;
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530350 }
351 return false;
352 };
Sander de Smalenfdf40912018-01-24 09:56:07 +0000353
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530354 return BoundsEqual(CountNode, RHS->getRawCountNode()) &&
355 BoundsEqual(LowerBound, RHS->getRawLowerBound()) &&
356 BoundsEqual(UpperBound, RHS->getRawUpperBound()) &&
357 BoundsEqual(Stride, RHS->getRawStride());
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000358 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000359
Sander de Smalenfdf40912018-01-24 09:56:07 +0000360 unsigned getHashValue() const {
Alok Kumar Sharmad20bf5a2020-05-28 13:31:22 +0530361 if (CountNode)
362 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
363 return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
364 LowerBound, UpperBound, Stride);
365 return hash_combine(CountNode, LowerBound, UpperBound, Stride);
Sander de Smalenfdf40912018-01-24 09:56:07 +0000366 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000367};
368
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000369template <> struct MDNodeKeyImpl<DIEnumerator> {
LemonBoyaad3d572020-04-18 11:31:38 -0700370 APInt Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000371 MDString *Name;
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000372 bool IsUnsigned;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000373
LemonBoyaad3d572020-04-18 11:31:38 -0700374 MDNodeKeyImpl(APInt Value, bool IsUnsigned, MDString *Name)
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000375 : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
LemonBoyaad3d572020-04-18 11:31:38 -0700376 MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
377 : Value(APInt(64, Value, !IsUnsigned)), Name(Name),
378 IsUnsigned(IsUnsigned) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000379 MDNodeKeyImpl(const DIEnumerator *N)
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000380 : Value(N->getValue()), Name(N->getRawName()),
381 IsUnsigned(N->isUnsigned()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000382
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000383 bool isKeyOf(const DIEnumerator *RHS) const {
LemonBoyaad3d572020-04-18 11:31:38 -0700384 return APInt::isSameValue(Value, RHS->getValue()) &&
385 IsUnsigned == RHS->isUnsigned() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000386 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000387
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000388 unsigned getHashValue() const { return hash_combine(Value, Name); }
389};
390
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000391template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000392 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000393 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000394 uint64_t SizeInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000395 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000396 unsigned Encoding;
Adrian Prantl55f42622018-08-14 19:35:34 +0000397 unsigned Flags;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000398
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000399 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Adrian Prantl55f42622018-08-14 19:35:34 +0000400 uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000401 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
Adrian Prantl55f42622018-08-14 19:35:34 +0000402 Encoding(Encoding), Flags(Flags) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000403 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000404 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Adrian Prantl55f42622018-08-14 19:35:34 +0000405 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000406
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000407 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000408 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000409 SizeInBits == RHS->getSizeInBits() &&
410 AlignInBits == RHS->getAlignInBits() &&
Adrian Prantl55f42622018-08-14 19:35:34 +0000411 Encoding == RHS->getEncoding() &&
412 Flags == RHS->getFlags();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000413 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000414
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000415 unsigned getHashValue() const {
416 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
417 }
418};
419
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000420template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000421 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000422 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000423 Metadata *File;
424 unsigned Line;
425 Metadata *Scope;
426 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000427 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000428 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000429 uint32_t AlignInBits;
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000430 Optional<unsigned> DWARFAddressSpace;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000431 unsigned Flags;
432 Metadata *ExtraData;
433
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000434 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000435 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000436 uint32_t AlignInBits, uint64_t OffsetInBits,
437 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000438 Metadata *ExtraData)
439 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000440 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000441 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
442 Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000443 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000444 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000445 Line(N->getLine()), Scope(N->getRawScope()),
446 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000447 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000448 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
449 ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000450
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000451 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000452 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000453 File == RHS->getRawFile() && Line == RHS->getLine() &&
454 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000455 SizeInBits == RHS->getSizeInBits() &&
456 AlignInBits == RHS->getAlignInBits() &&
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000457 OffsetInBits == RHS->getOffsetInBits() &&
458 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
459 Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000460 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000461 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000462
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000463 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000464 // If this is a member inside an ODR type, only hash the type and the name.
465 // Otherwise the hash will be stronger than
466 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000467 if (Tag == dwarf::DW_TAG_member && Name)
468 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
469 if (CT->getRawIdentifier())
470 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000471
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000472 // Intentionally computes the hash on a subset of the operands for
473 // performance reason. The subset has to be significant enough to avoid
474 // collision "most of the time". There is no correctness issue in case of
475 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000476 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000477 }
478};
479
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000480template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000481 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
482
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000483 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
484 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
485 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000486
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000487 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
488 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
489 RHS);
490 }
491
492 /// Subprograms compare equal if they declare the same function in an ODR
493 /// type.
494 static bool isODRMember(unsigned Tag, const Metadata *Scope,
495 const MDString *Name, const DIDerivedType *RHS) {
496 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000497 if (Tag != dwarf::DW_TAG_member || !Name)
498 return false;
499
500 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
501 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000502 return false;
503
504 // Compare to the RHS.
505 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
506 Scope == RHS->getRawScope();
507 }
508};
509
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000510template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000511 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000512 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000513 Metadata *File;
514 unsigned Line;
515 Metadata *Scope;
516 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000517 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000518 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000519 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000520 unsigned Flags;
521 Metadata *Elements;
522 unsigned RuntimeLang;
523 Metadata *VTableHolder;
524 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000525 MDString *Identifier;
Adrian Prantl8c599212018-02-06 23:45:59 +0000526 Metadata *Discriminator;
Alok Kumar Sharma4042ada2020-05-15 11:24:27 +0530527 Metadata *DataLocation;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000528
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000529 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000530 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000531 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000532 Metadata *Elements, unsigned RuntimeLang,
533 Metadata *VTableHolder, Metadata *TemplateParams,
Alok Kumar Sharma4042ada2020-05-15 11:24:27 +0530534 MDString *Identifier, Metadata *Discriminator,
535 Metadata *DataLocation)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000536 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000537 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
538 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000539 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
Adrian Prantl8c599212018-02-06 23:45:59 +0000540 TemplateParams(TemplateParams), Identifier(Identifier),
Alok Kumar Sharma4042ada2020-05-15 11:24:27 +0530541 Discriminator(Discriminator), DataLocation(DataLocation) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000542 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000543 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000544 Line(N->getLine()), Scope(N->getRawScope()),
545 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000546 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000547 Flags(N->getFlags()), Elements(N->getRawElements()),
548 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
549 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl8c599212018-02-06 23:45:59 +0000550 Identifier(N->getRawIdentifier()),
Alok Kumar Sharma4042ada2020-05-15 11:24:27 +0530551 Discriminator(N->getRawDiscriminator()),
552 DataLocation(N->getRawDataLocation()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000553
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000554 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000555 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000556 File == RHS->getRawFile() && Line == RHS->getLine() &&
557 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000558 SizeInBits == RHS->getSizeInBits() &&
559 AlignInBits == RHS->getAlignInBits() &&
560 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000561 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000562 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000563 VTableHolder == RHS->getRawVTableHolder() &&
564 TemplateParams == RHS->getRawTemplateParams() &&
Adrian Prantl8c599212018-02-06 23:45:59 +0000565 Identifier == RHS->getRawIdentifier() &&
Alok Kumar Sharma4042ada2020-05-15 11:24:27 +0530566 Discriminator == RHS->getRawDiscriminator() &&
567 DataLocation == RHS->getRawDataLocation();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000568 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000569
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000570 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000571 // Intentionally computes the hash on a subset of the operands for
572 // performance reason. The subset has to be significant enough to avoid
573 // collision "most of the time". There is no correctness issue in case of
574 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000575 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
576 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000577 }
578};
579
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000580template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000581 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000582 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000583 Metadata *TypeArray;
584
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000585 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
586 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000587 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000588 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000589
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000590 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000591 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
592 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000593 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000594
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000595 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000596};
597
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000598template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000599 MDString *Filename;
600 MDString *Directory;
Scott Linder71603842018-02-12 19:45:54 +0000601 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
Scott Linder16c7bda2018-02-23 23:01:06 +0000602 Optional<MDString *> Source;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000603
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000604 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
Scott Linder16c7bda2018-02-23 23:01:06 +0000605 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
606 Optional<MDString *> Source)
607 : Filename(Filename), Directory(Directory), Checksum(Checksum),
608 Source(Source) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000609 MDNodeKeyImpl(const DIFile *N)
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000610 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
Scott Linder16c7bda2018-02-23 23:01:06 +0000611 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000612
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000613 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000614 return Filename == RHS->getRawFilename() &&
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000615 Directory == RHS->getRawDirectory() &&
Scott Linder16c7bda2018-02-23 23:01:06 +0000616 Checksum == RHS->getRawChecksum() &&
617 Source == RHS->getRawSource();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000618 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000619
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000620 unsigned getHashValue() const {
Scott Linder16c7bda2018-02-23 23:01:06 +0000621 return hash_combine(
622 Filename, Directory, Checksum ? Checksum->Kind : 0,
623 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000624 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000625};
626
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000627template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000628 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000629 MDString *Name;
630 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000631 Metadata *File;
632 unsigned Line;
633 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000634 unsigned ScopeLine;
635 Metadata *ContainingType;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000636 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000637 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000638 unsigned Flags;
Paul Robinsoncda54212018-11-19 18:29:28 +0000639 unsigned SPFlags;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000640 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000641 Metadata *TemplateParams;
642 Metadata *Declaration;
Shiva Chen2c864552018-05-09 02:40:45 +0000643 Metadata *RetainedNodes;
Adrian Prantl1d12b882017-04-26 22:56:44 +0000644 Metadata *ThrownTypes;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000645
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000646 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000647 Metadata *File, unsigned Line, Metadata *Type,
Paul Robinsoncda54212018-11-19 18:29:28 +0000648 unsigned ScopeLine, Metadata *ContainingType,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000649 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
Paul Robinsoncda54212018-11-19 18:29:28 +0000650 unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
Shiva Chen2c864552018-05-09 02:40:45 +0000651 Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000652 Metadata *ThrownTypes)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
Paul Robinsoncda54212018-11-19 18:29:28 +0000654 Line(Line), Type(Type), ScopeLine(ScopeLine),
655 ContainingType(ContainingType), VirtualIndex(VirtualIndex),
656 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
657 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
Shiva Chen2c864552018-05-09 02:40:45 +0000658 RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000659 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000660 : Scope(N->getRawScope()), Name(N->getRawName()),
661 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000662 Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()),
663 ContainingType(N->getRawContainingType()),
664 VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000665 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000666 SPFlags(N->getSPFlags()), Unit(N->getRawUnit()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000667 TemplateParams(N->getRawTemplateParams()),
Paul Robinsoncda54212018-11-19 18:29:28 +0000668 Declaration(N->getRawDeclaration()),
669 RetainedNodes(N->getRawRetainedNodes()),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000670 ThrownTypes(N->getRawThrownTypes()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000671
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000672 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000673 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
674 LinkageName == RHS->getRawLinkageName() &&
675 File == RHS->getRawFile() && Line == RHS->getLine() &&
Paul Robinsoncda54212018-11-19 18:29:28 +0000676 Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000677 ContainingType == RHS->getRawContainingType() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000678 VirtualIndex == RHS->getVirtualIndex() &&
679 ThisAdjustment == RHS->getThisAdjustment() &&
Paul Robinsoncda54212018-11-19 18:29:28 +0000680 Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000681 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000682 TemplateParams == RHS->getRawTemplateParams() &&
683 Declaration == RHS->getRawDeclaration() &&
Shiva Chen2c864552018-05-09 02:40:45 +0000684 RetainedNodes == RHS->getRawRetainedNodes() &&
Adrian Prantl1d12b882017-04-26 22:56:44 +0000685 ThrownTypes == RHS->getRawThrownTypes();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000686 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000687
Paul Robinsoncda54212018-11-19 18:29:28 +0000688 bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
689
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000690 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000691 // If this is a declaration inside an ODR type, only hash the type and the
692 // name. Otherwise the hash will be stronger than
693 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Paul Robinsoncda54212018-11-19 18:29:28 +0000694 if (!isDefinition() && LinkageName)
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000695 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
696 if (CT->getRawIdentifier())
697 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000698
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000699 // Intentionally computes the hash on a subset of the operands for
700 // performance reason. The subset has to be significant enough to avoid
701 // collision "most of the time". There is no correctness issue in case of
702 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000703 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000704 }
705};
706
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000707template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000708 using KeyTy = MDNodeKeyImpl<DISubprogram>;
709
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000710 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
Paul Robinsoncda54212018-11-19 18:29:28 +0000711 return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000712 LHS.LinkageName, LHS.TemplateParams, RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000713 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000714
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000715 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
716 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000717 LHS->getRawLinkageName(),
718 LHS->getRawTemplateParams(), RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000719 }
720
721 /// Subprograms compare equal if they declare the same function in an ODR
722 /// type.
723 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
724 const MDString *LinkageName,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000725 const Metadata *TemplateParams,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000726 const DISubprogram *RHS) {
727 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000728 if (IsDefinition || !Scope || !LinkageName)
729 return false;
730
731 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
732 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000733 return false;
734
735 // Compare to the RHS.
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000736 // FIXME: We need to compare template parameters here to avoid incorrect
737 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
738 // has a non-ODR template parameter (i.e., a DICompositeType that does not
739 // have an identifier). Eventually we should decouple ODR logic from
740 // uniquing logic.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000741 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000742 LinkageName == RHS->getRawLinkageName() &&
743 TemplateParams == RHS->getRawTemplateParams();
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000744 }
745};
746
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000747template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000748 Metadata *Scope;
749 Metadata *File;
750 unsigned Line;
751 unsigned Column;
752
753 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
754 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000755 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000756 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000757 Column(N->getColumn()) {}
758
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000759 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000760 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000761 Line == RHS->getLine() && Column == RHS->getColumn();
762 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000763
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000764 unsigned getHashValue() const {
765 return hash_combine(Scope, File, Line, Column);
766 }
767};
768
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000769template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000770 Metadata *Scope;
771 Metadata *File;
772 unsigned Discriminator;
773
774 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
775 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000776 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000777 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000778 Discriminator(N->getDiscriminator()) {}
779
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000780 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000781 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000782 Discriminator == RHS->getDiscriminator();
783 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000784
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000785 unsigned getHashValue() const {
786 return hash_combine(Scope, File, Discriminator);
787 }
788};
789
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000790template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000791 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000792 MDString *Name;
Adrian Prantldbfda632016-11-03 19:42:02 +0000793 bool ExportSymbols;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000794
Adrian Prantlfed4f392017-04-28 22:25:46 +0000795 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
796 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000797 MDNodeKeyImpl(const DINamespace *N)
Adrian Prantlfed4f392017-04-28 22:25:46 +0000798 : Scope(N->getRawScope()), Name(N->getRawName()),
799 ExportSymbols(N->getExportSymbols()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000800
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000801 bool isKeyOf(const DINamespace *RHS) const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000802 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Adrian Prantldbfda632016-11-03 19:42:02 +0000803 ExportSymbols == RHS->getExportSymbols();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000804 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000805
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000806 unsigned getHashValue() const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000807 return hash_combine(Scope, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000808 }
809};
810
Adrian Prantl6ed57062019-04-08 19:13:55 +0000811template <> struct MDNodeKeyImpl<DICommonBlock> {
812 Metadata *Scope;
813 Metadata *Decl;
814 MDString *Name;
815 Metadata *File;
816 unsigned LineNo;
817
818 MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name,
819 Metadata *File, unsigned LineNo)
820 : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {}
821 MDNodeKeyImpl(const DICommonBlock *N)
822 : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()),
823 File(N->getRawFile()), LineNo(N->getLineNo()) {}
824
825 bool isKeyOf(const DICommonBlock *RHS) const {
826 return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() &&
827 Name == RHS->getRawName() && File == RHS->getRawFile() &&
828 LineNo == RHS->getLineNo();
829 }
830
831 unsigned getHashValue() const {
832 return hash_combine(Scope, Decl, Name, File, LineNo);
833 }
834};
835
Adrian Prantlab1243f2015-06-29 23:03:47 +0000836template <> struct MDNodeKeyImpl<DIModule> {
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530837 Metadata *File;
Adrian Prantlab1243f2015-06-29 23:03:47 +0000838 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000839 MDString *Name;
840 MDString *ConfigurationMacros;
841 MDString *IncludePath;
Adrian Prantld5180ea2020-03-03 16:05:23 -0800842 MDString *APINotesFile;
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530843 unsigned LineNo;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000844
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530845 MDNodeKeyImpl(Metadata *File, Metadata *Scope, MDString *Name,
846 MDString *ConfigurationMacros, MDString *IncludePath,
847 MDString *APINotesFile, unsigned LineNo)
848 : File(File), Scope(Scope), Name(Name),
849 ConfigurationMacros(ConfigurationMacros), IncludePath(IncludePath),
850 APINotesFile(APINotesFile), LineNo(LineNo) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000851 MDNodeKeyImpl(const DIModule *N)
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530852 : File(N->getRawFile()), Scope(N->getRawScope()), Name(N->getRawName()),
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000853 ConfigurationMacros(N->getRawConfigurationMacros()),
Adrian Prantld5180ea2020-03-03 16:05:23 -0800854 IncludePath(N->getRawIncludePath()),
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530855 APINotesFile(N->getRawAPINotesFile()), LineNo(N->getLineNo()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000856
857 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000858 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
859 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
Adrian Prantld5180ea2020-03-03 16:05:23 -0800860 IncludePath == RHS->getRawIncludePath() &&
Sourabh Singh Tomare59744f2020-05-08 11:31:41 +0530861 APINotesFile == RHS->getRawAPINotesFile() &&
862 File == RHS->getRawFile() && LineNo == RHS->getLineNo();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000863 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000864
Adrian Prantlab1243f2015-06-29 23:03:47 +0000865 unsigned getHashValue() const {
Adrian Prantl7b303702020-01-14 13:37:04 -0800866 return hash_combine(Scope, Name, ConfigurationMacros, IncludePath);
Adrian Prantlab1243f2015-06-29 23:03:47 +0000867 }
868};
869
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000870template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000871 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000872 Metadata *Type;
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530873 bool IsDefault;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000874
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530875 MDNodeKeyImpl(MDString *Name, Metadata *Type, bool IsDefault)
876 : Name(Name), Type(Type), IsDefault(IsDefault) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000877 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530878 : Name(N->getRawName()), Type(N->getRawType()),
879 IsDefault(N->isDefault()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000880
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000881 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530882 return Name == RHS->getRawName() && Type == RHS->getRawType() &&
883 IsDefault == RHS->isDefault();
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 { return hash_combine(Name, Type, IsDefault); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000887};
888
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000889template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000890 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000891 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000892 Metadata *Type;
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530893 bool IsDefault;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000894 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000895
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530896 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, bool IsDefault,
897 Metadata *Value)
898 : Tag(Tag), Name(Name), Type(Type), IsDefault(IsDefault), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000899 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000900 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530901 IsDefault(N->isDefault()), Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000902
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000903 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000904 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530905 Type == RHS->getRawType() && IsDefault == RHS->isDefault() &&
906 Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000907 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000908
Awanish Pandey7a42bab2020-03-02 10:52:12 +0530909 unsigned getHashValue() const {
910 return hash_combine(Tag, Name, Type, IsDefault, Value);
911 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000912};
913
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000914template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000915 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000916 MDString *Name;
917 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000918 Metadata *File;
919 unsigned Line;
920 Metadata *Type;
921 bool IsLocalToUnit;
922 bool IsDefinition;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000923 Metadata *StaticDataMemberDeclaration;
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000924 Metadata *TemplateParams;
Victor Leschuka37660c2016-10-26 21:32:29 +0000925 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000926
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000927 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000928 Metadata *File, unsigned Line, Metadata *Type,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000929 bool IsLocalToUnit, bool IsDefinition,
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000930 Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
931 uint32_t AlignInBits)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000932 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
933 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000934 IsDefinition(IsDefinition),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000935 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000936 TemplateParams(TemplateParams), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000937 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000938 : Scope(N->getRawScope()), Name(N->getRawName()),
939 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000940 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000941 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000942 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000943 TemplateParams(N->getRawTemplateParams()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000944 AlignInBits(N->getAlignInBits()) {}
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 DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000947 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
948 LinkageName == RHS->getRawLinkageName() &&
949 File == RHS->getRawFile() && Line == RHS->getLine() &&
950 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000951 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000952 StaticDataMemberDeclaration ==
Victor Leschuk2ede1262016-10-20 00:13:12 +0000953 RHS->getRawStaticDataMemberDeclaration() &&
Matthew Vossf8ab35a2018-10-03 18:44:53 +0000954 TemplateParams == RHS->getRawTemplateParams() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000955 AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000956 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000957
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000958 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000959 // We do not use AlignInBits in hashing function here on purpose:
960 // in most cases this param for local variable is zero (for function param
961 // it is always zero). This leads to lots of hash collisions and errors on
962 // cases with lots of similar variables.
963 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
964 // generated IR is random for each run and test fails with Align included.
965 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000966 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000967 IsLocalToUnit, IsDefinition, /* AlignInBits, */
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000968 StaticDataMemberDeclaration);
969 }
970};
971
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000972template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000973 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000974 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000975 Metadata *File;
976 unsigned Line;
977 Metadata *Type;
978 unsigned Arg;
979 unsigned Flags;
Victor Leschuka37660c2016-10-26 21:32:29 +0000980 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000981
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000982 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000983 Metadata *Type, unsigned Arg, unsigned Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000984 uint32_t AlignInBits)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000985 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000986 Flags(Flags), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000987 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000988 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000989 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000990 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000991
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000992 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000993 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000994 File == RHS->getRawFile() && Line == RHS->getLine() &&
995 Type == RHS->getRawType() && Arg == RHS->getArg() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000996 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000997 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000998
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000999 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +00001000 // We do not use AlignInBits in hashing function here on purpose:
1001 // in most cases this param for local variable is zero (for function param
1002 // it is always zero). This leads to lots of hash collisions and errors on
1003 // cases with lots of similar variables.
1004 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
1005 // generated IR is random for each run and test fails with Align included.
1006 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +00001007 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001008 }
1009};
1010
Shiva Chen2c864552018-05-09 02:40:45 +00001011template <> struct MDNodeKeyImpl<DILabel> {
1012 Metadata *Scope;
1013 MDString *Name;
1014 Metadata *File;
1015 unsigned Line;
1016
1017 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
1018 : Scope(Scope), Name(Name), File(File), Line(Line) {}
1019 MDNodeKeyImpl(const DILabel *N)
1020 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
1021 Line(N->getLine()) {}
1022
1023 bool isKeyOf(const DILabel *RHS) const {
1024 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
1025 File == RHS->getRawFile() && Line == RHS->getLine();
1026 }
1027
1028 /// Using name and line to get hash value. It should already be mostly unique.
1029 unsigned getHashValue() const {
1030 return hash_combine(Scope, Name, Line);
1031 }
1032};
1033
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001034template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001035 ArrayRef<uint64_t> Elements;
1036
1037 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001038 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001039
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001040 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001041 return Elements == RHS->getElements();
1042 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001043
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001044 unsigned getHashValue() const {
1045 return hash_combine_range(Elements.begin(), Elements.end());
1046 }
1047};
1048
Adrian Prantlbceaaa92016-12-20 02:09:43 +00001049template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
1050 Metadata *Variable;
1051 Metadata *Expression;
1052
1053 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
1054 : Variable(Variable), Expression(Expression) {}
1055 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
1056 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
1057
1058 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
1059 return Variable == RHS->getRawVariable() &&
1060 Expression == RHS->getRawExpression();
1061 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001062
Adrian Prantlbceaaa92016-12-20 02:09:43 +00001063 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
1064};
1065
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001066template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001067 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001068 Metadata *File;
1069 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001070 MDString *GetterName;
1071 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001072 unsigned Attributes;
1073 Metadata *Type;
1074
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001075 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
1076 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001077 Metadata *Type)
1078 : Name(Name), File(File), Line(Line), GetterName(GetterName),
1079 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001080 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001081 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
1082 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001083 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001084
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001085 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001086 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1087 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1088 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001089 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001090 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001091
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001092 unsigned getHashValue() const {
1093 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1094 Type);
1095 }
1096};
1097
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001098template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001099 unsigned Tag;
1100 Metadata *Scope;
1101 Metadata *Entity;
Adrian Prantld63bfd22017-07-19 00:09:54 +00001102 Metadata *File;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001103 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001104 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001105
Adrian Prantld63bfd22017-07-19 00:09:54 +00001106 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1107 unsigned Line, MDString *Name)
1108 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1109 Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001110 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001111 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Adrian Prantld63bfd22017-07-19 00:09:54 +00001112 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001113
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001114 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001115 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
Adrian Prantld63bfd22017-07-19 00:09:54 +00001116 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1117 Line == RHS->getLine() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001118 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001119
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001120 unsigned getHashValue() const {
Adrian Prantld63bfd22017-07-19 00:09:54 +00001121 return hash_combine(Tag, Scope, Entity, File, Line, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001122 }
1123};
1124
Amjad Abouda9bcf162015-12-10 12:56:35 +00001125template <> struct MDNodeKeyImpl<DIMacro> {
1126 unsigned MIType;
1127 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001128 MDString *Name;
1129 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +00001130
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001131 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +00001132 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1133 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001134 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1135 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001136
1137 bool isKeyOf(const DIMacro *RHS) const {
1138 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001139 Name == RHS->getRawName() && Value == RHS->getRawValue();
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, Name, Value);
1144 }
1145};
1146
1147template <> struct MDNodeKeyImpl<DIMacroFile> {
1148 unsigned MIType;
1149 unsigned Line;
1150 Metadata *File;
1151 Metadata *Elements;
1152
1153 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1154 Metadata *Elements)
1155 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1156 MDNodeKeyImpl(const DIMacroFile *N)
1157 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1158 Elements(N->getRawElements()) {}
1159
1160 bool isKeyOf(const DIMacroFile *RHS) const {
1161 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +00001162 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +00001163 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001164
Amjad Abouda9bcf162015-12-10 12:56:35 +00001165 unsigned getHashValue() const {
1166 return hash_combine(MIType, Line, File, Elements);
1167 }
1168};
1169
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001170/// DenseMapInfo for MDNode subclasses.
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001171template <class NodeTy> struct MDNodeInfo {
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001172 using KeyTy = MDNodeKeyImpl<NodeTy>;
1173 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1174
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001175 static inline NodeTy *getEmptyKey() {
1176 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001177 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001178
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001179 static inline NodeTy *getTombstoneKey() {
1180 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001181 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001182
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001183 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001184
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001185 static unsigned getHashValue(const NodeTy *N) {
1186 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001187 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001188
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001189 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1190 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1191 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001192 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001193 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001194
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001195 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001196 if (LHS == RHS)
1197 return true;
1198 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1199 return false;
1200 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001201 }
1202};
1203
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001204#define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001205#include "llvm/IR/Metadata.def"
1206
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001207/// Map-like storage for metadata attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001208class MDAttachmentMap {
1209 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1210
1211public:
1212 bool empty() const { return Attachments.empty(); }
1213 size_t size() const { return Attachments.size(); }
1214
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001215 /// Get a particular attachment (if any).
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001216 MDNode *lookup(unsigned ID) const;
1217
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001218 /// Set an attachment to a particular node.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001219 ///
1220 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1221 /// ID (if anyway).
1222 void set(unsigned ID, MDNode &MD);
1223
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001224 /// Remove an attachment.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001225 ///
1226 /// Remove the attachment at \c ID, if any.
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001227 bool erase(unsigned ID);
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001228
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001229 /// Copy out all the attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001230 ///
1231 /// Copies all the current attachments into \c Result, sorting by attachment
1232 /// ID. This function does \em not clear \c Result.
1233 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1234
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001235 /// Erase matching attachments.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001236 ///
1237 /// Erases all attachments matching the \c shouldRemove predicate.
1238 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemer2d006e72016-08-12 04:32:42 +00001239 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1240 Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001241 }
1242};
1243
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001244/// Multimap-like storage for metadata attachments for globals. This differs
1245/// from MDAttachmentMap in that it allows multiple attachments per metadata
1246/// kind.
1247class MDGlobalAttachmentMap {
1248 struct Attachment {
1249 unsigned MDKind;
1250 TrackingMDNodeRef Node;
1251 };
1252 SmallVector<Attachment, 1> Attachments;
1253
1254public:
1255 bool empty() const { return Attachments.empty(); }
1256
1257 /// Appends all attachments with the given ID to \c Result in insertion order.
1258 /// If the global has no attachments with the given ID, or if ID is invalid,
1259 /// leaves Result unchanged.
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001260 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
1261
1262 /// Returns the first attachment with the given ID or nullptr if no such
1263 /// attachment exists.
1264 MDNode *lookup(unsigned ID) const;
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001265
1266 void insert(unsigned ID, MDNode &MD);
Benjamin Kramer0deb9a92018-05-31 13:29:58 +00001267 bool erase(unsigned ID);
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001268
1269 /// Appends all attachments for the global to \c Result, sorting by attachment
1270 /// ID. Attachments with the same ID appear in insertion order. This function
1271 /// does \em not clear \c Result.
1272 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1273};
1274
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001275class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001276public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001277 /// OwnedModules - The set of modules instantiated in this context, and which
1278 /// will be automatically deleted if this context is deleted.
1279 SmallPtrSet<Module*, 4> OwnedModules;
Fangrui Songf78650a2018-07-30 19:41:25 +00001280
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001281 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1282 void *InlineAsmDiagContext = nullptr;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001283
Francis Visoiu Mistrih7531a502019-10-28 14:53:31 -07001284 /// The main remark streamer used by all the other streamers (e.g. IR, MIR,
1285 /// frontends, etc.). This should only be used by the specific streamers, and
1286 /// never directly.
1287 std::unique_ptr<remarks::RemarkStreamer> MainRemarkStreamer;
1288
Vivek Pandyab5ab8952017-09-15 20:10:09 +00001289 std::unique_ptr<DiagnosticHandler> DiagHandler;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001290 bool RespectDiagnosticFilters = false;
Brian Gesiak44e5f6c2017-06-30 18:13:59 +00001291 bool DiagnosticsHotnessRequested = false;
Brian Gesiak4ef3daa2017-06-30 23:14:53 +00001292 uint64_t DiagnosticsHotnessThreshold = 0;
Francis Visoiu Mistrih7531a502019-10-28 14:53:31 -07001293 /// The specialized remark streamer used by LLVM's OptimizationRemarkEmitter.
Francis Visoiu Mistrih31258872020-02-04 17:42:47 -08001294 std::unique_ptr<LLVMRemarkStreamer> LLVMRS;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001295
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001296 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1297 void *YieldOpaqueHandle = nullptr;
Juergen Ributzka34390c72014-05-16 02:33:15 +00001298
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001299 using IntMapTy =
1300 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001301 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001302
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001303 using FPMapTy =
1304 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
Owen Andersonc277dc42009-07-16 19:05:41 +00001305 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001306
Bill Wendling4607f4b2012-12-20 01:36:59 +00001307 FoldingSet<AttributeImpl> AttrsSet;
Reid Klecknerb5180542017-03-21 16:57:19 +00001308 FoldingSet<AttributeListImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001309 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001310
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001311 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001312 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1313 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001314
Owen Anderson7349ab92015-06-01 22:24:01 +00001315 DenseMap<const Value*, ValueName*> ValueNames;
1316
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001317#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1318 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001319#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001320
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001321 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001322 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001323
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001324 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1325 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001326 // one object can destroy them. Keep track of them here so we can delete
1327 // them on context teardown.
1328 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001329
Justin Lebar611c5c22016-10-10 16:26:13 +00001330 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001331
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001332 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001333 ArrayConstantsTy ArrayConstants;
Fangrui Songf78650a2018-07-30 19:41:25 +00001334
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001335 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001336 StructConstantsTy StructConstants;
Fangrui Songf78650a2018-07-30 19:41:25 +00001337
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001338 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001339 VectorConstantsTy VectorConstants;
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001340
Justin Lebar611c5c22016-10-10 16:26:13 +00001341 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1342
1343 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1344
Chris Lattner3756b912012-01-23 22:57:10 +00001345 StringMap<ConstantDataSequential*> CDSConstants;
1346
Chandler Carruth6a936922014-01-19 02:13:50 +00001347 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1348 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001349 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001350
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001351 ConstantUniqueMap<InlineAsm> InlineAsms;
1352
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001353 ConstantInt *TheTrueVal = nullptr;
1354 ConstantInt *TheFalseVal = nullptr;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001355
David Majnemer2dd41c52015-11-16 20:55:57 +00001356 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001357
Dan Gohman97d2cb82009-08-25 16:00:35 +00001358 // Basic type instances.
Ties Stuij8c24f332020-03-31 23:49:38 +01001359 Type VoidTy, LabelTy, HalfTy, BFloatTy, FloatTy, DoubleTy, MetadataTy,
1360 TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001361 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001362 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Fangrui Songf78650a2018-07-30 19:41:25 +00001363
Peter Collingbourne10c548c2019-05-29 03:28:51 +00001364 BumpPtrAllocator Alloc;
1365 UniqueStringSaver Saver{Alloc};
Fangrui Songf78650a2018-07-30 19:41:25 +00001366
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001367 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001368
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001369 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001370 FunctionTypeSet FunctionTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001371 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001372 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001373 StringMap<StructType*> NamedStructTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001374 unsigned NamedStructTypesUniqueID = 0;
Fangrui Songf78650a2018-07-30 19:41:25 +00001375
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001376 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
Graham Hunter957c40d2019-07-05 12:48:16 +00001377 DenseMap<std::pair<Type *, ElementCount>, VectorType*> VectorTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001378 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1379 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001380
Owen Andersone8f21852009-08-18 18:28:58 +00001381 /// ValueHandles - This map keeps track of all of the value handles that are
1382 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001383 /// whether or not a value has an entry in this map.
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001384 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
Owen Andersone8f21852009-08-18 18:28:58 +00001385 ValueHandlesTy ValueHandles;
Fangrui Songf78650a2018-07-30 19:41:25 +00001386
Chris Lattnera0566972009-12-29 09:01:33 +00001387 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1388 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001389
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001390 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001391 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001392
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001393 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001394 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001395
Reid Kleckner443423e2017-01-10 23:23:58 +00001396 /// Collection of per-GlobalObject sections used in this context.
1397 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1398
Peter Collingbourne31fda092019-05-29 03:29:01 +00001399 /// Collection of per-GlobalValue partitions used in this context.
1400 DenseMap<const GlobalValue *, StringRef> GlobalValuePartitions;
1401
Diego Novillof5041ce2014-03-03 20:06:11 +00001402 /// DiscriminatorTable - This table maps file:line locations to an
1403 /// integer representing the next DWARF path discriminator to assign to
1404 /// instructions in different blocks at the same location.
1405 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1406
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001407 /// A set of interned tags for operand bundles. The StringMap maps
Sanjoy Das9303c242015-09-24 19:14:18 +00001408 /// bundle tags to their IDs.
1409 ///
1410 /// \see LLVMContext::getOperandBundleTagID
1411 StringMap<uint32_t> BundleTagCache;
1412
1413 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1414 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1415 uint32_t getOperandBundleTagID(StringRef Tag) const;
1416
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00001417 /// A set of interned synchronization scopes. The StringMap maps
1418 /// synchronization scope names to their respective synchronization scope IDs.
1419 StringMap<SyncScope::ID> SSC;
1420
1421 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1422 /// synchronization scope ID. Every synchronization scope registered with
1423 /// LLVMContext has unique ID except pre-defined ones.
1424 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1425
1426 /// getSyncScopeNames - Populates client supplied SmallVector with
1427 /// synchronization scope names registered with LLVMContext. Synchronization
1428 /// scope names are ordered by increasing synchronization scope IDs.
1429 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1430
Mehdi Amini599ebf22016-01-08 02:28:20 +00001431 /// Maintain the GC name for each function.
1432 ///
1433 /// This saves allocating an additional word in Function for programs which
1434 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1435 /// clients which do use GC.
1436 DenseMap<const Function*, std::string> GCNames;
1437
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001438 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1439 /// not.
1440 bool DiscardValueNames = false;
1441
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001442 LLVMContextImpl(LLVMContext &C);
1443 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001444
1445 /// Destroy the ConstantArrays if they are not used.
1446 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001447
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001448 mutable OptPassGate *OPG = nullptr;
1449
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001450 /// Access the object which can disable optional passes and individual
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001451 /// optimizations at compile time.
1452 OptPassGate &getOptPassGate() const;
1453
Adrian Prantl5f8f34e42018-05-01 15:54:18 +00001454 /// Set the object which can disable optional passes and individual
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001455 /// optimizations at compile time.
1456 ///
1457 /// The lifetime of the object must be guaranteed to extend as long as the
1458 /// LLVMContext is used by compilation.
1459 void setOptPassGate(OptPassGate&);
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001460};
1461
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001462} // end namespace llvm
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001463
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001464#endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H