blob: 2d120869860a0eb02500ab5f036d02262b909d93 [file] [log] [blame]
Eugene Zelenkof1934002017-06-19 22:05:08 +00001//===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
Owen Anderson2bc29dc2009-06-30 00:48:55 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Owen Anderson52170072009-06-30 17:06:46 +00009//
Fangrui Songaf7b1832018-07-30 19:41:25 +000010// This file declares LLVMContextImpl, the opaque implementation
Owen Anderson52170072009-06-30 17:06:46 +000011// of LLVMContext.
12//
13//===----------------------------------------------------------------------===//
Owen Anderson2bc29dc2009-06-30 00:48:55 +000014
Benjamin Kramer00e08fc2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
16#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
Owen Anderson2bc29dc2009-06-30 00:48:55 +000017
Bill Wendlingf6670722012-12-20 01:36:59 +000018#include "AttributeImpl.h"
Owen Anderson48b2f3e2009-08-04 22:41:48 +000019#include "ConstantsContext.h"
Owen Anderson914e50c2009-07-16 19:05:41 +000020#include "llvm/ADT/APFloat.h"
Owen Anderson001dbfe2009-07-16 18:04:31 +000021#include "llvm/ADT/APInt.h"
Jay Foad2a4a6fe2011-06-22 08:50:06 +000022#include "llvm/ADT/ArrayRef.h"
Owen Anderson001dbfe2009-07-16 18:04:31 +000023#include "llvm/ADT/DenseMap.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000024#include "llvm/ADT/DenseMapInfo.h"
Duncan P. N. Exon Smith66a2b052014-11-17 23:28:21 +000025#include "llvm/ADT/DenseSet.h"
Owen Andersonce032b42009-07-16 23:44:30 +000026#include "llvm/ADT/FoldingSet.h"
Chandler Carrutha1514e22012-12-04 07:12:27 +000027#include "llvm/ADT/Hashing.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000028#include "llvm/ADT/Optional.h"
29#include "llvm/ADT/STLExtras.h"
Jeffrey Yasskinad715f82009-12-17 19:55:06 +000030#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000031#include "llvm/ADT/SmallVector.h"
Owen Andersonaad3fb72009-07-16 22:11:26 +000032#include "llvm/ADT/StringMap.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000033#include "llvm/ADT/StringRef.h"
Reid Kleckner7b685032017-01-10 23:23:58 +000034#include "llvm/ADT/StringSet.h"
Zachary Turner19ca2b02017-06-07 03:48:56 +000035#include "llvm/BinaryFormat/Dwarf.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000036#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithca8d3bf2015-02-02 18:53:21 +000037#include "llvm/IR/DebugInfoMetadata.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000038#include "llvm/IR/DerivedTypes.h"
39#include "llvm/IR/LLVMContext.h"
40#include "llvm/IR/Metadata.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000041#include "llvm/IR/TrackingMDRef.h"
42#include "llvm/Support/Allocator.h"
43#include "llvm/Support/Casting.h"
Adam Nemet47c0d492016-09-27 20:55:07 +000044#include "llvm/Support/YAMLTraits.h"
Eugene Zelenkof1934002017-06-19 22:05:08 +000045#include <algorithm>
46#include <cassert>
47#include <cstddef>
48#include <cstdint>
49#include <memory>
50#include <string>
51#include <utility>
Duncan P. N. Exon Smith995d8632016-04-19 23:59:13 +000052#include <vector>
Owen Anderson16e298f2009-07-21 20:13:12 +000053
Owen Anderson001dbfe2009-07-16 18:04:31 +000054namespace llvm {
Owen Andersoneed707b2009-07-24 23:12:02 +000055
Owen Anderson914e50c2009-07-16 19:05:41 +000056class ConstantFP;
Eugene Zelenkof1934002017-06-19 22:05:08 +000057class ConstantInt;
Owen Anderson001dbfe2009-07-16 18:04:31 +000058class Type;
Owen Andersonce032b42009-07-16 23:44:30 +000059class Value;
Eugene Zelenkof1934002017-06-19 22:05:08 +000060class ValueHandleBase;
Owen Anderson001dbfe2009-07-16 18:04:31 +000061
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000062struct DenseMapAPIntKeyInfo {
Benjamin Kramer51df2c22014-12-06 13:12:56 +000063 static inline APInt getEmptyKey() {
64 APInt V(nullptr, 0);
Craig Topper52bc9d92017-05-03 15:46:24 +000065 V.U.VAL = 0;
Benjamin Kramer51df2c22014-12-06 13:12:56 +000066 return V;
67 }
Eugene Zelenkof1934002017-06-19 22:05:08 +000068
Benjamin Kramer51df2c22014-12-06 13:12:56 +000069 static inline APInt getTombstoneKey() {
70 APInt V(nullptr, 0);
Craig Topper52bc9d92017-05-03 15:46:24 +000071 V.U.VAL = 1;
Benjamin Kramer51df2c22014-12-06 13:12:56 +000072 return V;
73 }
Eugene Zelenkof1934002017-06-19 22:05:08 +000074
Benjamin Kramer51df2c22014-12-06 13:12:56 +000075 static unsigned getHashValue(const APInt &Key) {
Chandler Carruthed7692a2012-03-04 12:02:57 +000076 return static_cast<unsigned>(hash_value(Key));
Owen Anderson001dbfe2009-07-16 18:04:31 +000077 }
Eugene Zelenkof1934002017-06-19 22:05:08 +000078
Benjamin Kramer51df2c22014-12-06 13:12:56 +000079 static bool isEqual(const APInt &LHS, const APInt &RHS) {
80 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
81 }
Owen Anderson001dbfe2009-07-16 18:04:31 +000082};
83
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000084struct DenseMapAPFloatKeyInfo {
Stephan Bergmann20a600c2016-12-14 11:57:17 +000085 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
86 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
Eugene Zelenkof1934002017-06-19 22:05:08 +000087
Benjamin Kramer51df2c22014-12-06 13:12:56 +000088 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruthed7692a2012-03-04 12:02:57 +000089 return static_cast<unsigned>(hash_value(Key));
Owen Anderson914e50c2009-07-16 19:05:41 +000090 }
Eugene Zelenkof1934002017-06-19 22:05:08 +000091
Benjamin Kramer51df2c22014-12-06 13:12:56 +000092 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
93 return LHS.bitwiseIsEqual(RHS);
94 }
Owen Anderson914e50c2009-07-16 19:05:41 +000095};
96
Benjamin Kramer55c06ae2013-09-11 18:05:11 +000097struct AnonStructTypeKeyInfo {
Jay Foadbdf17482012-02-23 09:17:40 +000098 struct KeyTy {
99 ArrayRef<Type*> ETypes;
100 bool isPacked;
Eugene Zelenkof1934002017-06-19 22:05:08 +0000101
Jay Foadbdf17482012-02-23 09:17:40 +0000102 KeyTy(const ArrayRef<Type*>& E, bool P) :
103 ETypes(E), isPacked(P) {}
Eugene Zelenkof1934002017-06-19 22:05:08 +0000104
Rafael Espindola633e9682014-11-21 18:53:05 +0000105 KeyTy(const StructType *ST)
106 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Eugene Zelenkof1934002017-06-19 22:05:08 +0000107
Jay Foadbdf17482012-02-23 09:17:40 +0000108 bool operator==(const KeyTy& that) const {
109 if (isPacked != that.isPacked)
110 return false;
111 if (ETypes != that.ETypes)
112 return false;
113 return true;
114 }
115 bool operator!=(const KeyTy& that) const {
116 return !this->operator==(that);
117 }
118 };
Eugene Zelenkof1934002017-06-19 22:05:08 +0000119
Jay Foadbdf17482012-02-23 09:17:40 +0000120 static inline StructType* getEmptyKey() {
121 return DenseMapInfo<StructType*>::getEmptyKey();
122 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000123
Jay Foadbdf17482012-02-23 09:17:40 +0000124 static inline StructType* getTombstoneKey() {
125 return DenseMapInfo<StructType*>::getTombstoneKey();
126 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000127
Jay Foadbdf17482012-02-23 09:17:40 +0000128 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth0b66c6f2012-03-01 18:55:25 +0000129 return hash_combine(hash_combine_range(Key.ETypes.begin(),
130 Key.ETypes.end()),
131 Key.isPacked);
Jay Foadbdf17482012-02-23 09:17:40 +0000132 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000133
Jay Foadbdf17482012-02-23 09:17:40 +0000134 static unsigned getHashValue(const StructType *ST) {
135 return getHashValue(KeyTy(ST));
136 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000137
Jay Foadbdf17482012-02-23 09:17:40 +0000138 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
139 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
140 return false;
141 return LHS == KeyTy(RHS);
142 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000143
Jay Foadbdf17482012-02-23 09:17:40 +0000144 static bool isEqual(const StructType *LHS, const StructType *RHS) {
145 return LHS == RHS;
146 }
147};
148
Benjamin Kramer55c06ae2013-09-11 18:05:11 +0000149struct FunctionTypeKeyInfo {
Jay Foadbdf17482012-02-23 09:17:40 +0000150 struct KeyTy {
151 const Type *ReturnType;
152 ArrayRef<Type*> Params;
153 bool isVarArg;
Eugene Zelenkof1934002017-06-19 22:05:08 +0000154
Jay Foadbdf17482012-02-23 09:17:40 +0000155 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
156 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindola0b835fc2014-11-21 19:03:35 +0000157 KeyTy(const FunctionType *FT)
158 : ReturnType(FT->getReturnType()), Params(FT->params()),
159 isVarArg(FT->isVarArg()) {}
Eugene Zelenkof1934002017-06-19 22:05:08 +0000160
Jay Foadbdf17482012-02-23 09:17:40 +0000161 bool operator==(const KeyTy& that) const {
162 if (ReturnType != that.ReturnType)
163 return false;
164 if (isVarArg != that.isVarArg)
165 return false;
166 if (Params != that.Params)
167 return false;
168 return true;
169 }
170 bool operator!=(const KeyTy& that) const {
171 return !this->operator==(that);
172 }
173 };
Eugene Zelenkof1934002017-06-19 22:05:08 +0000174
Jay Foadbdf17482012-02-23 09:17:40 +0000175 static inline FunctionType* getEmptyKey() {
176 return DenseMapInfo<FunctionType*>::getEmptyKey();
177 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000178
Jay Foadbdf17482012-02-23 09:17:40 +0000179 static inline FunctionType* getTombstoneKey() {
180 return DenseMapInfo<FunctionType*>::getTombstoneKey();
181 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000182
Jay Foadbdf17482012-02-23 09:17:40 +0000183 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth0b66c6f2012-03-01 18:55:25 +0000184 return hash_combine(Key.ReturnType,
185 hash_combine_range(Key.Params.begin(),
186 Key.Params.end()),
187 Key.isVarArg);
Jay Foadbdf17482012-02-23 09:17:40 +0000188 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000189
Jay Foadbdf17482012-02-23 09:17:40 +0000190 static unsigned getHashValue(const FunctionType *FT) {
191 return getHashValue(KeyTy(FT));
192 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000193
Jay Foadbdf17482012-02-23 09:17:40 +0000194 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
195 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
196 return false;
197 return LHS == KeyTy(RHS);
198 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000199
Jay Foadbdf17482012-02-23 09:17:40 +0000200 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
201 return LHS == RHS;
202 }
203};
204
Adrian Prantl26b584c2018-05-01 15:54:18 +0000205/// Structure for hashing arbitrary MDNode operands.
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000206class MDNodeOpsKey {
207 ArrayRef<Metadata *> RawOps;
208 ArrayRef<MDOperand> Ops;
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000209 unsigned Hash;
210
211protected:
212 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
213 : RawOps(Ops), Hash(calculateHash(Ops)) {}
214
215 template <class NodeTy>
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000216 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000217 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000218
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000219 template <class NodeTy>
220 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000221 if (getHash() != RHS->getHash())
222 return false;
223
224 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000225 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
226 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000227 }
228
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000229 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000230
231private:
232 template <class T>
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000233 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
234 if (Ops.size() != RHS->getNumOperands() - Offset)
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000235 return false;
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000236 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000237 }
238
239 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
240
241public:
242 unsigned getHash() const { return Hash; }
243};
244
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000245template <class NodeTy> struct MDNodeKeyImpl;
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000246
Duncan P. N. Exon Smith44387cf2016-04-16 23:42:04 +0000247/// Configuration point for MDNodeInfo::isEqual().
248template <class NodeTy> struct MDNodeSubsetEqualImpl {
Eugene Zelenkof1934002017-06-19 22:05:08 +0000249 using KeyTy = MDNodeKeyImpl<NodeTy>;
250
Duncan P. N. Exon Smith44387cf2016-04-16 23:42:04 +0000251 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
252 return false;
253 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000254
Duncan P. N. Exon Smith44387cf2016-04-16 23:42:04 +0000255 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
256 return false;
257 }
258};
259
Adrian Prantl26b584c2018-05-01 15:54:18 +0000260/// DenseMapInfo for MDTuple.
Duncan P. N. Exon Smith66a2b052014-11-17 23:28:21 +0000261///
262/// Note that we don't need the is-function-local bit, since that's implicit in
263/// the operands.
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000264template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
265 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
266 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
Duncan P. N. Exon Smith66a2b052014-11-17 23:28:21 +0000267
Duncan P. N. Exon Smith09b44e92015-02-05 00:51:35 +0000268 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smithfce53dd2015-01-19 22:53:18 +0000269
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000270 unsigned getHashValue() const { return getHash(); }
271
272 static unsigned calculateHash(MDTuple *N) {
273 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer611afc02012-04-11 14:06:54 +0000274 }
275};
276
Adrian Prantl26b584c2018-05-01 15:54:18 +0000277/// DenseMapInfo for DILocation.
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000278template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000279 unsigned Line;
280 unsigned Column;
281 Metadata *Scope;
282 Metadata *InlinedAt;
Calixte Denizet44db1d12018-09-20 08:53:06 +0000283 bool ImplicitCode;
Duncan P. N. Exon Smithd6409622015-01-13 20:44:56 +0000284
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000285 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
Calixte Denizet44db1d12018-09-20 08:53:06 +0000286 Metadata *InlinedAt, bool ImplicitCode)
287 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
288 ImplicitCode(ImplicitCode) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000289 MDNodeKeyImpl(const DILocation *L)
Duncan P. N. Exon Smithc4eafd22015-03-26 22:05:04 +0000290 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
Calixte Denizet44db1d12018-09-20 08:53:06 +0000291 InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
Duncan P. N. Exon Smithd6409622015-01-13 20:44:56 +0000292
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000293 bool isKeyOf(const DILocation *RHS) const {
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000294 return Line == RHS->getLine() && Column == RHS->getColumn() &&
Calixte Denizet44db1d12018-09-20 08:53:06 +0000295 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
296 ImplicitCode == RHS->isImplicitCode();
Duncan P. N. Exon Smithd6409622015-01-13 20:44:56 +0000297 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000298
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000299 unsigned getHashValue() const {
Calixte Denizet44db1d12018-09-20 08:53:06 +0000300 return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
Duncan P. N. Exon Smithd6409622015-01-13 20:44:56 +0000301 }
302};
303
Adrian Prantl26b584c2018-05-01 15:54:18 +0000304/// DenseMapInfo for GenericDINode.
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000305template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000306 unsigned Tag;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000307 MDString *Header;
Eugene Zelenkof1934002017-06-19 22:05:08 +0000308
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000309 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000310 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000311 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000312 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000313
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000314 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000315 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000316 compareOps(RHS, 1);
317 }
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000318
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000319 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
320
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000321 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000322 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +0000323 }
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +0000324};
325
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000326template <> struct MDNodeKeyImpl<DISubrange> {
Sander de Smalen959cee72018-01-24 09:56:07 +0000327 Metadata *CountNode;
Duncan P. N. Exon Smith329f8212015-04-07 00:39:59 +0000328 int64_t LowerBound;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000329
Sander de Smalen959cee72018-01-24 09:56:07 +0000330 MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
331 : CountNode(CountNode), LowerBound(LowerBound) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000332 MDNodeKeyImpl(const DISubrange *N)
Sander de Smalen959cee72018-01-24 09:56:07 +0000333 : CountNode(N->getRawCountNode()),
334 LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000335
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000336 bool isKeyOf(const DISubrange *RHS) const {
Sander de Smalen959cee72018-01-24 09:56:07 +0000337 if (LowerBound != RHS->getLowerBound())
338 return false;
339
340 if (auto *RHSCount = RHS->getCount().dyn_cast<ConstantInt*>())
341 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
342 if (RHSCount->getSExtValue() ==
343 cast<ConstantInt>(MD->getValue())->getSExtValue())
344 return true;
345
346 return CountNode == RHS->getRawCountNode();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000347 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000348
Sander de Smalen959cee72018-01-24 09:56:07 +0000349 unsigned getHashValue() const {
350 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
351 return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
352 LowerBound);
353 return hash_combine(CountNode, LowerBound);
354 }
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000355};
356
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000357template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000358 int64_t Value;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000359 MDString *Name;
Momchil Velikov0c69bf42018-02-12 16:10:09 +0000360 bool IsUnsigned;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000361
Momchil Velikov0c69bf42018-02-12 16:10:09 +0000362 MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
363 : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000364 MDNodeKeyImpl(const DIEnumerator *N)
Momchil Velikov0c69bf42018-02-12 16:10:09 +0000365 : Value(N->getValue()), Name(N->getRawName()),
366 IsUnsigned(N->isUnsigned()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000367
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000368 bool isKeyOf(const DIEnumerator *RHS) const {
Momchil Velikov0c69bf42018-02-12 16:10:09 +0000369 return Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
370 Name == RHS->getRawName();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000371 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000372
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000373 unsigned getHashValue() const { return hash_combine(Value, Name); }
374};
375
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000376template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000377 unsigned Tag;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000378 MDString *Name;
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000379 uint64_t SizeInBits;
Victor Leschuk58be60c2016-10-18 14:31:22 +0000380 uint32_t AlignInBits;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000381 unsigned Encoding;
Adrian Prantlc4d19092018-08-14 19:35:34 +0000382 unsigned Flags;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000383
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000384 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Adrian Prantlc4d19092018-08-14 19:35:34 +0000385 uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000386 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
Adrian Prantlc4d19092018-08-14 19:35:34 +0000387 Encoding(Encoding), Flags(Flags) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000388 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000389 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Adrian Prantlc4d19092018-08-14 19:35:34 +0000390 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000391
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000392 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000393 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000394 SizeInBits == RHS->getSizeInBits() &&
395 AlignInBits == RHS->getAlignInBits() &&
Adrian Prantlc4d19092018-08-14 19:35:34 +0000396 Encoding == RHS->getEncoding() &&
397 Flags == RHS->getFlags();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000398 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000399
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000400 unsigned getHashValue() const {
401 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
402 }
403};
404
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000405template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000406 unsigned Tag;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000407 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000408 Metadata *File;
409 unsigned Line;
410 Metadata *Scope;
411 Metadata *BaseType;
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000412 uint64_t SizeInBits;
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000413 uint64_t OffsetInBits;
Victor Leschuk58be60c2016-10-18 14:31:22 +0000414 uint32_t AlignInBits;
Konstantin Zhuravlyov2cee5cc2017-03-08 23:55:44 +0000415 Optional<unsigned> DWARFAddressSpace;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000416 unsigned Flags;
417 Metadata *ExtraData;
418
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000419 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000420 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyov2cee5cc2017-03-08 23:55:44 +0000421 uint32_t AlignInBits, uint64_t OffsetInBits,
422 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000423 Metadata *ExtraData)
424 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk58be60c2016-10-18 14:31:22 +0000425 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
Konstantin Zhuravlyov2cee5cc2017-03-08 23:55:44 +0000426 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
427 Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000428 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000429 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000430 Line(N->getLine()), Scope(N->getRawScope()),
431 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk58be60c2016-10-18 14:31:22 +0000432 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Konstantin Zhuravlyov2cee5cc2017-03-08 23:55:44 +0000433 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
434 ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000435
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000436 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000437 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000438 File == RHS->getRawFile() && Line == RHS->getLine() &&
439 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000440 SizeInBits == RHS->getSizeInBits() &&
441 AlignInBits == RHS->getAlignInBits() &&
Konstantin Zhuravlyov2cee5cc2017-03-08 23:55:44 +0000442 OffsetInBits == RHS->getOffsetInBits() &&
443 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
444 Flags == RHS->getFlags() &&
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000445 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000446 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000447
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000448 unsigned getHashValue() const {
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000449 // If this is a member inside an ODR type, only hash the type and the name.
450 // Otherwise the hash will be stronger than
451 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smithde748402016-04-23 21:08:00 +0000452 if (Tag == dwarf::DW_TAG_member && Name)
453 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
454 if (CT->getRawIdentifier())
455 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000456
Mehdi Amini991382f2016-03-19 01:06:24 +0000457 // Intentionally computes the hash on a subset of the operands for
458 // performance reason. The subset has to be significant enough to avoid
459 // collision "most of the time". There is no correctness issue in case of
460 // collision because of the full check above.
Mehdi Amini343753f2016-03-19 00:59:26 +0000461 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000462 }
463};
464
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000465template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
Eugene Zelenkof1934002017-06-19 22:05:08 +0000466 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
467
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000468 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
469 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
470 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000471
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000472 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
473 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
474 RHS);
475 }
476
477 /// Subprograms compare equal if they declare the same function in an ODR
478 /// type.
479 static bool isODRMember(unsigned Tag, const Metadata *Scope,
480 const MDString *Name, const DIDerivedType *RHS) {
481 // Check whether the LHS is eligible.
Duncan P. N. Exon Smithde748402016-04-23 21:08:00 +0000482 if (Tag != dwarf::DW_TAG_member || !Name)
483 return false;
484
485 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
486 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000487 return false;
488
489 // Compare to the RHS.
490 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
491 Scope == RHS->getRawScope();
492 }
493};
494
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000495template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000496 unsigned Tag;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000497 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000498 Metadata *File;
499 unsigned Line;
500 Metadata *Scope;
501 Metadata *BaseType;
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000502 uint64_t SizeInBits;
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000503 uint64_t OffsetInBits;
Victor Leschuk58be60c2016-10-18 14:31:22 +0000504 uint32_t AlignInBits;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000505 unsigned Flags;
506 Metadata *Elements;
507 unsigned RuntimeLang;
508 Metadata *VTableHolder;
509 Metadata *TemplateParams;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000510 MDString *Identifier;
Adrian Prantl04aa6502018-02-06 23:45:59 +0000511 Metadata *Discriminator;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000512
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000513 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smith8a76ab62015-02-19 23:56:07 +0000514 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk58be60c2016-10-18 14:31:22 +0000515 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000516 Metadata *Elements, unsigned RuntimeLang,
517 Metadata *VTableHolder, Metadata *TemplateParams,
Adrian Prantl04aa6502018-02-06 23:45:59 +0000518 MDString *Identifier, Metadata *Discriminator)
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000519 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk58be60c2016-10-18 14:31:22 +0000520 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
521 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000522 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
Adrian Prantl04aa6502018-02-06 23:45:59 +0000523 TemplateParams(TemplateParams), Identifier(Identifier),
524 Discriminator(Discriminator) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000525 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000526 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000527 Line(N->getLine()), Scope(N->getRawScope()),
528 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk58be60c2016-10-18 14:31:22 +0000529 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000530 Flags(N->getFlags()), Elements(N->getRawElements()),
531 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
532 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl04aa6502018-02-06 23:45:59 +0000533 Identifier(N->getRawIdentifier()),
534 Discriminator(N->getRawDiscriminator()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000535
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000536 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000537 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000538 File == RHS->getRawFile() && Line == RHS->getLine() &&
539 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000540 SizeInBits == RHS->getSizeInBits() &&
541 AlignInBits == RHS->getAlignInBits() &&
542 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000543 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000544 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smithb9433702015-03-27 23:05:04 +0000545 VTableHolder == RHS->getRawVTableHolder() &&
546 TemplateParams == RHS->getRawTemplateParams() &&
Adrian Prantl04aa6502018-02-06 23:45:59 +0000547 Identifier == RHS->getRawIdentifier() &&
548 Discriminator == RHS->getRawDiscriminator();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000549 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000550
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000551 unsigned getHashValue() const {
Mehdi Amini991382f2016-03-19 01:06:24 +0000552 // Intentionally computes the hash on a subset of the operands for
553 // performance reason. The subset has to be significant enough to avoid
554 // collision "most of the time". There is no correctness issue in case of
555 // collision because of the full check above.
Mehdi Amini343753f2016-03-19 00:59:26 +0000556 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
557 TemplateParams);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000558 }
559};
560
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000561template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000562 unsigned Flags;
Reid Kleckner3d3aca22016-06-08 20:34:29 +0000563 uint8_t CC;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000564 Metadata *TypeArray;
565
Reid Kleckner3d3aca22016-06-08 20:34:29 +0000566 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
567 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000568 MDNodeKeyImpl(const DISubroutineType *N)
Reid Kleckner3d3aca22016-06-08 20:34:29 +0000569 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000570
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000571 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Kleckner3d3aca22016-06-08 20:34:29 +0000572 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
573 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000574 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000575
Reid Kleckner3d3aca22016-06-08 20:34:29 +0000576 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000577};
578
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000579template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000580 MDString *Filename;
581 MDString *Directory;
Scott Linder48632522018-02-12 19:45:54 +0000582 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
Scott Linder5e4b5152018-02-23 23:01:06 +0000583 Optional<MDString *> Source;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000584
Amjad Aboud4e2e80b2016-12-25 10:12:09 +0000585 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
Scott Linder5e4b5152018-02-23 23:01:06 +0000586 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
587 Optional<MDString *> Source)
588 : Filename(Filename), Directory(Directory), Checksum(Checksum),
589 Source(Source) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000590 MDNodeKeyImpl(const DIFile *N)
Amjad Aboud4e2e80b2016-12-25 10:12:09 +0000591 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
Scott Linder5e4b5152018-02-23 23:01:06 +0000592 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000593
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000594 bool isKeyOf(const DIFile *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000595 return Filename == RHS->getRawFilename() &&
Amjad Aboud4e2e80b2016-12-25 10:12:09 +0000596 Directory == RHS->getRawDirectory() &&
Scott Linder5e4b5152018-02-23 23:01:06 +0000597 Checksum == RHS->getRawChecksum() &&
598 Source == RHS->getRawSource();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000599 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000600
Amjad Aboud4e2e80b2016-12-25 10:12:09 +0000601 unsigned getHashValue() const {
Scott Linder5e4b5152018-02-23 23:01:06 +0000602 return hash_combine(
603 Filename, Directory, Checksum ? Checksum->Kind : 0,
604 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
Amjad Aboud4e2e80b2016-12-25 10:12:09 +0000605 }
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000606};
607
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000608template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000609 Metadata *Scope;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000610 MDString *Name;
611 MDString *LinkageName;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000612 Metadata *File;
613 unsigned Line;
614 Metadata *Type;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000615 unsigned ScopeLine;
616 Metadata *ContainingType;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000617 unsigned VirtualIndex;
Reid Klecknerbd79db22016-07-01 02:41:21 +0000618 int ThisAdjustment;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000619 unsigned Flags;
Paul Robinsoneaa73532018-11-19 18:29:28 +0000620 unsigned SPFlags;
Adrian Prantl4eeaa0d2016-04-15 15:57:41 +0000621 Metadata *Unit;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000622 Metadata *TemplateParams;
623 Metadata *Declaration;
Shiva Chena8a13bc2018-05-09 02:40:45 +0000624 Metadata *RetainedNodes;
Adrian Prantl1bf62972017-04-26 22:56:44 +0000625 Metadata *ThrownTypes;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000626
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000627 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000628 Metadata *File, unsigned Line, Metadata *Type,
Paul Robinsoneaa73532018-11-19 18:29:28 +0000629 unsigned ScopeLine, Metadata *ContainingType,
Reid Klecknerbd79db22016-07-01 02:41:21 +0000630 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
Paul Robinsoneaa73532018-11-19 18:29:28 +0000631 unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
Shiva Chena8a13bc2018-05-09 02:40:45 +0000632 Metadata *Declaration, Metadata *RetainedNodes,
Adrian Prantl1bf62972017-04-26 22:56:44 +0000633 Metadata *ThrownTypes)
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000634 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
Paul Robinsoneaa73532018-11-19 18:29:28 +0000635 Line(Line), Type(Type), ScopeLine(ScopeLine),
636 ContainingType(ContainingType), VirtualIndex(VirtualIndex),
637 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
638 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
Shiva Chena8a13bc2018-05-09 02:40:45 +0000639 RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000640 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000641 : Scope(N->getRawScope()), Name(N->getRawName()),
642 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Paul Robinsoneaa73532018-11-19 18:29:28 +0000643 Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()),
644 ContainingType(N->getRawContainingType()),
645 VirtualIndex(N->getVirtualIndex()),
Reid Klecknerbd79db22016-07-01 02:41:21 +0000646 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
Paul Robinsoneaa73532018-11-19 18:29:28 +0000647 SPFlags(N->getSPFlags()), Unit(N->getRawUnit()),
Reid Klecknerbd79db22016-07-01 02:41:21 +0000648 TemplateParams(N->getRawTemplateParams()),
Paul Robinsoneaa73532018-11-19 18:29:28 +0000649 Declaration(N->getRawDeclaration()),
650 RetainedNodes(N->getRawRetainedNodes()),
Adrian Prantl1bf62972017-04-26 22:56:44 +0000651 ThrownTypes(N->getRawThrownTypes()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000652
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000653 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000654 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
655 LinkageName == RHS->getRawLinkageName() &&
656 File == RHS->getRawFile() && Line == RHS->getLine() &&
Paul Robinsoneaa73532018-11-19 18:29:28 +0000657 Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smithbd38c8d2015-03-30 16:19:15 +0000658 ContainingType == RHS->getRawContainingType() &&
Reid Klecknerbd79db22016-07-01 02:41:21 +0000659 VirtualIndex == RHS->getVirtualIndex() &&
660 ThisAdjustment == RHS->getThisAdjustment() &&
Paul Robinsoneaa73532018-11-19 18:29:28 +0000661 Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() &&
Reid Klecknerbd79db22016-07-01 02:41:21 +0000662 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smithbd38c8d2015-03-30 16:19:15 +0000663 TemplateParams == RHS->getRawTemplateParams() &&
664 Declaration == RHS->getRawDeclaration() &&
Shiva Chena8a13bc2018-05-09 02:40:45 +0000665 RetainedNodes == RHS->getRawRetainedNodes() &&
Adrian Prantl1bf62972017-04-26 22:56:44 +0000666 ThrownTypes == RHS->getRawThrownTypes();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000667 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000668
Paul Robinsoneaa73532018-11-19 18:29:28 +0000669 bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
670
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000671 unsigned getHashValue() const {
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000672 // If this is a declaration inside an ODR type, only hash the type and the
673 // name. Otherwise the hash will be stronger than
674 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Paul Robinsoneaa73532018-11-19 18:29:28 +0000675 if (!isDefinition() && LinkageName)
Duncan P. N. Exon Smithde748402016-04-23 21:08:00 +0000676 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
677 if (CT->getRawIdentifier())
678 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000679
Mehdi Amini991382f2016-03-19 01:06:24 +0000680 // Intentionally computes the hash on a subset of the operands for
681 // performance reason. The subset has to be significant enough to avoid
682 // collision "most of the time". There is no correctness issue in case of
683 // collision because of the full check above.
Mehdi Amini343753f2016-03-19 00:59:26 +0000684 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000685 }
686};
687
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000688template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
Eugene Zelenkof1934002017-06-19 22:05:08 +0000689 using KeyTy = MDNodeKeyImpl<DISubprogram>;
690
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000691 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
Paul Robinsoneaa73532018-11-19 18:29:28 +0000692 return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope,
Peter Collingbourne6db63482017-02-06 21:23:03 +0000693 LHS.LinkageName, LHS.TemplateParams, RHS);
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000694 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000695
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000696 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
697 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
Peter Collingbourne6db63482017-02-06 21:23:03 +0000698 LHS->getRawLinkageName(),
699 LHS->getRawTemplateParams(), RHS);
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000700 }
701
702 /// Subprograms compare equal if they declare the same function in an ODR
703 /// type.
704 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
705 const MDString *LinkageName,
Peter Collingbourne6db63482017-02-06 21:23:03 +0000706 const Metadata *TemplateParams,
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000707 const DISubprogram *RHS) {
708 // Check whether the LHS is eligible.
Duncan P. N. Exon Smithde748402016-04-23 21:08:00 +0000709 if (IsDefinition || !Scope || !LinkageName)
710 return false;
711
712 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
713 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000714 return false;
715
716 // Compare to the RHS.
Peter Collingbourne6db63482017-02-06 21:23:03 +0000717 // FIXME: We need to compare template parameters here to avoid incorrect
718 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
719 // has a non-ODR template parameter (i.e., a DICompositeType that does not
720 // have an identifier). Eventually we should decouple ODR logic from
721 // uniquing logic.
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000722 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
Peter Collingbourne6db63482017-02-06 21:23:03 +0000723 LinkageName == RHS->getRawLinkageName() &&
724 TemplateParams == RHS->getRawTemplateParams();
Duncan P. N. Exon Smith12a8b142016-04-17 02:30:20 +0000725 }
726};
727
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000728template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000729 Metadata *Scope;
730 Metadata *File;
731 unsigned Line;
732 unsigned Column;
733
734 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
735 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000736 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smithd3ec0ca2015-03-30 16:37:48 +0000737 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000738 Column(N->getColumn()) {}
739
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000740 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smithd3ec0ca2015-03-30 16:37:48 +0000741 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000742 Line == RHS->getLine() && Column == RHS->getColumn();
743 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000744
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000745 unsigned getHashValue() const {
746 return hash_combine(Scope, File, Line, Column);
747 }
748};
749
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000750template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000751 Metadata *Scope;
752 Metadata *File;
753 unsigned Discriminator;
754
755 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
756 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000757 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smithd3ec0ca2015-03-30 16:37:48 +0000758 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000759 Discriminator(N->getDiscriminator()) {}
760
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000761 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smithd3ec0ca2015-03-30 16:37:48 +0000762 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000763 Discriminator == RHS->getDiscriminator();
764 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000765
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000766 unsigned getHashValue() const {
767 return hash_combine(Scope, File, Discriminator);
768 }
769};
770
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000771template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000772 Metadata *Scope;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000773 MDString *Name;
Adrian Prantl60a7c432016-11-03 19:42:02 +0000774 bool ExportSymbols;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000775
Adrian Prantl841400b2017-04-28 22:25:46 +0000776 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
777 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000778 MDNodeKeyImpl(const DINamespace *N)
Adrian Prantl841400b2017-04-28 22:25:46 +0000779 : Scope(N->getRawScope()), Name(N->getRawName()),
780 ExportSymbols(N->getExportSymbols()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000781
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000782 bool isKeyOf(const DINamespace *RHS) const {
Adrian Prantl841400b2017-04-28 22:25:46 +0000783 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Adrian Prantl60a7c432016-11-03 19:42:02 +0000784 ExportSymbols == RHS->getExportSymbols();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000785 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000786
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000787 unsigned getHashValue() const {
Adrian Prantl841400b2017-04-28 22:25:46 +0000788 return hash_combine(Scope, Name);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000789 }
790};
791
Adrian Prantl71776472015-06-29 23:03:47 +0000792template <> struct MDNodeKeyImpl<DIModule> {
793 Metadata *Scope;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000794 MDString *Name;
795 MDString *ConfigurationMacros;
796 MDString *IncludePath;
797 MDString *ISysRoot;
Eugene Zelenkof1934002017-06-19 22:05:08 +0000798
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000799 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
800 MDString *IncludePath, MDString *ISysRoot)
801 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
802 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantl71776472015-06-29 23:03:47 +0000803 MDNodeKeyImpl(const DIModule *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000804 : Scope(N->getRawScope()), Name(N->getRawName()),
805 ConfigurationMacros(N->getRawConfigurationMacros()),
806 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantl71776472015-06-29 23:03:47 +0000807
808 bool isKeyOf(const DIModule *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000809 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
810 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
811 IncludePath == RHS->getRawIncludePath() &&
812 ISysRoot == RHS->getRawISysRoot();
Adrian Prantl71776472015-06-29 23:03:47 +0000813 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000814
Adrian Prantl71776472015-06-29 23:03:47 +0000815 unsigned getHashValue() const {
816 return hash_combine(Scope, Name,
817 ConfigurationMacros, IncludePath, ISysRoot);
818 }
819};
820
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000821template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000822 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000823 Metadata *Type;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000824
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000825 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000826 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000827 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000828
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000829 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000830 return Name == RHS->getRawName() && Type == RHS->getRawType();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000831 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000832
Duncan P. N. Exon Smitheac950e2015-02-19 00:37:21 +0000833 unsigned getHashValue() const { return hash_combine(Name, Type); }
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000834};
835
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000836template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000837 unsigned Tag;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000838 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000839 Metadata *Type;
840 Metadata *Value;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000841
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000842 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smitheac950e2015-02-19 00:37:21 +0000843 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000844 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000845 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smitheac950e2015-02-19 00:37:21 +0000846 Value(N->getValue()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000847
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000848 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000849 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithe009b6f2015-04-06 19:03:45 +0000850 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000851 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000852
Duncan P. N. Exon Smitheac950e2015-02-19 00:37:21 +0000853 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000854};
855
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000856template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000857 Metadata *Scope;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000858 MDString *Name;
859 MDString *LinkageName;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000860 Metadata *File;
861 unsigned Line;
862 Metadata *Type;
863 bool IsLocalToUnit;
864 bool IsDefinition;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000865 Metadata *StaticDataMemberDeclaration;
Matthew Vossfff44e62018-10-03 18:44:53 +0000866 Metadata *TemplateParams;
Victor Leschuk7614f6d2016-10-26 21:32:29 +0000867 uint32_t AlignInBits;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000868
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000869 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000870 Metadata *File, unsigned Line, Metadata *Type,
Victor Leschuke69c4592016-10-20 00:13:12 +0000871 bool IsLocalToUnit, bool IsDefinition,
Matthew Vossfff44e62018-10-03 18:44:53 +0000872 Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
873 uint32_t AlignInBits)
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000874 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
875 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Adrian Prantl7b500b42016-12-20 02:09:43 +0000876 IsDefinition(IsDefinition),
Victor Leschuke69c4592016-10-20 00:13:12 +0000877 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
Matthew Vossfff44e62018-10-03 18:44:53 +0000878 TemplateParams(TemplateParams), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000879 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000880 : Scope(N->getRawScope()), Name(N->getRawName()),
881 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smitha9902da2015-03-27 17:29:58 +0000882 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000883 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Victor Leschuke69c4592016-10-20 00:13:12 +0000884 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
Matthew Vossfff44e62018-10-03 18:44:53 +0000885 TemplateParams(N->getRawTemplateParams()),
Victor Leschuke69c4592016-10-20 00:13:12 +0000886 AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000887
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000888 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000889 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
890 LinkageName == RHS->getRawLinkageName() &&
891 File == RHS->getRawFile() && Line == RHS->getLine() &&
892 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000893 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smitha9902da2015-03-27 17:29:58 +0000894 StaticDataMemberDeclaration ==
Victor Leschuke69c4592016-10-20 00:13:12 +0000895 RHS->getRawStaticDataMemberDeclaration() &&
Matthew Vossfff44e62018-10-03 18:44:53 +0000896 TemplateParams == RHS->getRawTemplateParams() &&
Victor Leschuke69c4592016-10-20 00:13:12 +0000897 AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000898 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000899
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000900 unsigned getHashValue() const {
Victor Leschuke69c4592016-10-20 00:13:12 +0000901 // We do not use AlignInBits in hashing function here on purpose:
902 // in most cases this param for local variable is zero (for function param
903 // it is always zero). This leads to lots of hash collisions and errors on
904 // cases with lots of similar variables.
905 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
906 // generated IR is random for each run and test fails with Align included.
907 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000908 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Adrian Prantl7b500b42016-12-20 02:09:43 +0000909 IsLocalToUnit, IsDefinition, /* AlignInBits, */
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000910 StaticDataMemberDeclaration);
911 }
912};
913
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000914template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000915 Metadata *Scope;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000916 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000917 Metadata *File;
918 unsigned Line;
919 Metadata *Type;
920 unsigned Arg;
921 unsigned Flags;
Victor Leschuk7614f6d2016-10-26 21:32:29 +0000922 uint32_t AlignInBits;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000923
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000924 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Victor Leschuke69c4592016-10-20 00:13:12 +0000925 Metadata *Type, unsigned Arg, unsigned Flags,
Victor Leschuk7614f6d2016-10-26 21:32:29 +0000926 uint32_t AlignInBits)
Duncan P. N. Exon Smithbf2040f2015-07-31 18:58:39 +0000927 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Victor Leschuke69c4592016-10-20 00:13:12 +0000928 Flags(Flags), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000929 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000930 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithbf2040f2015-07-31 18:58:39 +0000931 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Victor Leschuke69c4592016-10-20 00:13:12 +0000932 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000933
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000934 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +0000935 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithbf2040f2015-07-31 18:58:39 +0000936 File == RHS->getRawFile() && Line == RHS->getLine() &&
937 Type == RHS->getRawType() && Arg == RHS->getArg() &&
Victor Leschuke69c4592016-10-20 00:13:12 +0000938 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000939 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000940
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000941 unsigned getHashValue() const {
Victor Leschuke69c4592016-10-20 00:13:12 +0000942 // We do not use AlignInBits in hashing function here on purpose:
943 // in most cases this param for local variable is zero (for function param
944 // it is always zero). This leads to lots of hash collisions and errors on
945 // cases with lots of similar variables.
946 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
947 // generated IR is random for each run and test fails with Align included.
948 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smithbf2040f2015-07-31 18:58:39 +0000949 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000950 }
951};
952
Shiva Chena8a13bc2018-05-09 02:40:45 +0000953template <> struct MDNodeKeyImpl<DILabel> {
954 Metadata *Scope;
955 MDString *Name;
956 Metadata *File;
957 unsigned Line;
958
959 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
960 : Scope(Scope), Name(Name), File(File), Line(Line) {}
961 MDNodeKeyImpl(const DILabel *N)
962 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
963 Line(N->getLine()) {}
964
965 bool isKeyOf(const DILabel *RHS) const {
966 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
967 File == RHS->getRawFile() && Line == RHS->getLine();
968 }
969
970 /// Using name and line to get hash value. It should already be mostly unique.
971 unsigned getHashValue() const {
972 return hash_combine(Scope, Name, Line);
973 }
974};
975
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000976template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000977 ArrayRef<uint64_t> Elements;
978
979 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000980 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000981
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +0000982 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000983 return Elements == RHS->getElements();
984 }
Eugene Zelenkof1934002017-06-19 22:05:08 +0000985
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +0000986 unsigned getHashValue() const {
987 return hash_combine_range(Elements.begin(), Elements.end());
988 }
989};
990
Adrian Prantl7b500b42016-12-20 02:09:43 +0000991template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
992 Metadata *Variable;
993 Metadata *Expression;
994
995 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
996 : Variable(Variable), Expression(Expression) {}
997 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
998 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
999
1000 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
1001 return Variable == RHS->getRawVariable() &&
1002 Expression == RHS->getRawExpression();
1003 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001004
Adrian Prantl7b500b42016-12-20 02:09:43 +00001005 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
1006};
1007
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001008template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001009 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001010 Metadata *File;
1011 unsigned Line;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001012 MDString *GetterName;
1013 MDString *SetterName;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001014 unsigned Attributes;
1015 Metadata *Type;
1016
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001017 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
1018 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001019 Metadata *Type)
1020 : Name(Name), File(File), Line(Line), GetterName(GetterName),
1021 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001022 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001023 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
1024 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smith73802572015-03-30 17:21:38 +00001025 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001026
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001027 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001028 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1029 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1030 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smith73802572015-03-30 17:21:38 +00001031 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001032 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001033
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001034 unsigned getHashValue() const {
1035 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1036 Type);
1037 }
1038};
1039
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001040template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001041 unsigned Tag;
1042 Metadata *Scope;
1043 Metadata *Entity;
Adrian Prantl9563b5a2017-07-19 00:09:54 +00001044 Metadata *File;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001045 unsigned Line;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001046 MDString *Name;
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001047
Adrian Prantl9563b5a2017-07-19 00:09:54 +00001048 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1049 unsigned Line, MDString *Name)
1050 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1051 Name(Name) {}
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001052 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smith73802572015-03-30 17:21:38 +00001053 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Adrian Prantl9563b5a2017-07-19 00:09:54 +00001054 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001055
Duncan P. N. Exon Smithe56023a2015-04-29 16:38:44 +00001056 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smith73802572015-03-30 17:21:38 +00001057 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
Adrian Prantl9563b5a2017-07-19 00:09:54 +00001058 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1059 Line == RHS->getLine() && Name == RHS->getRawName();
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001060 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001061
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001062 unsigned getHashValue() const {
Adrian Prantl9563b5a2017-07-19 00:09:54 +00001063 return hash_combine(Tag, Scope, Entity, File, Line, Name);
Duncan P. N. Exon Smith14fcfef2015-02-10 00:52:32 +00001064 }
1065};
1066
Amjad Aboud7db39802015-12-10 12:56:35 +00001067template <> struct MDNodeKeyImpl<DIMacro> {
1068 unsigned MIType;
1069 unsigned Line;
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001070 MDString *Name;
1071 MDString *Value;
Amjad Aboud7db39802015-12-10 12:56:35 +00001072
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001073 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Aboud7db39802015-12-10 12:56:35 +00001074 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1075 MDNodeKeyImpl(const DIMacro *N)
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001076 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1077 Value(N->getRawValue()) {}
Amjad Aboud7db39802015-12-10 12:56:35 +00001078
1079 bool isKeyOf(const DIMacro *RHS) const {
1080 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Aminibef5d7a2016-03-19 01:02:34 +00001081 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Aboud7db39802015-12-10 12:56:35 +00001082 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001083
Amjad Aboud7db39802015-12-10 12:56:35 +00001084 unsigned getHashValue() const {
1085 return hash_combine(MIType, Line, Name, Value);
1086 }
1087};
1088
1089template <> struct MDNodeKeyImpl<DIMacroFile> {
1090 unsigned MIType;
1091 unsigned Line;
1092 Metadata *File;
1093 Metadata *Elements;
1094
1095 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1096 Metadata *Elements)
1097 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1098 MDNodeKeyImpl(const DIMacroFile *N)
1099 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1100 Elements(N->getRawElements()) {}
1101
1102 bool isKeyOf(const DIMacroFile *RHS) const {
1103 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud67b00992016-07-31 14:41:50 +00001104 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Aboud7db39802015-12-10 12:56:35 +00001105 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001106
Amjad Aboud7db39802015-12-10 12:56:35 +00001107 unsigned getHashValue() const {
1108 return hash_combine(MIType, Line, File, Elements);
1109 }
1110};
1111
Adrian Prantl26b584c2018-05-01 15:54:18 +00001112/// DenseMapInfo for MDNode subclasses.
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001113template <class NodeTy> struct MDNodeInfo {
Eugene Zelenkof1934002017-06-19 22:05:08 +00001114 using KeyTy = MDNodeKeyImpl<NodeTy>;
1115 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1116
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001117 static inline NodeTy *getEmptyKey() {
1118 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +00001119 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001120
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001121 static inline NodeTy *getTombstoneKey() {
1122 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +00001123 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001124
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001125 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001126
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001127 static unsigned getHashValue(const NodeTy *N) {
1128 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +00001129 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001130
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001131 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1132 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1133 return false;
Duncan P. N. Exon Smith44387cf2016-04-16 23:42:04 +00001134 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +00001135 }
Eugene Zelenkof1934002017-06-19 22:05:08 +00001136
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001137 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smith44387cf2016-04-16 23:42:04 +00001138 if (LHS == RHS)
1139 return true;
1140 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1141 return false;
1142 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smith0a9f9212015-01-20 00:01:43 +00001143 }
1144};
1145
Eugene Zelenkof1934002017-06-19 22:05:08 +00001146#define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
Duncan P. N. Exon Smith89032482015-02-04 22:08:30 +00001147#include "llvm/IR/Metadata.def"
1148
Adrian Prantl26b584c2018-05-01 15:54:18 +00001149/// Map-like storage for metadata attachments.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001150class MDAttachmentMap {
1151 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1152
1153public:
1154 bool empty() const { return Attachments.empty(); }
1155 size_t size() const { return Attachments.size(); }
1156
Adrian Prantl26b584c2018-05-01 15:54:18 +00001157 /// Get a particular attachment (if any).
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001158 MDNode *lookup(unsigned ID) const;
1159
Adrian Prantl26b584c2018-05-01 15:54:18 +00001160 /// Set an attachment to a particular node.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001161 ///
1162 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1163 /// ID (if anyway).
1164 void set(unsigned ID, MDNode &MD);
1165
Adrian Prantl26b584c2018-05-01 15:54:18 +00001166 /// Remove an attachment.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001167 ///
1168 /// Remove the attachment at \c ID, if any.
Benjamin Kramerf4eac502018-05-31 13:29:58 +00001169 bool erase(unsigned ID);
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001170
Adrian Prantl26b584c2018-05-01 15:54:18 +00001171 /// Copy out all the attachments.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001172 ///
1173 /// Copies all the current attachments into \c Result, sorting by attachment
1174 /// ID. This function does \em not clear \c Result.
1175 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1176
Adrian Prantl26b584c2018-05-01 15:54:18 +00001177 /// Erase matching attachments.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001178 ///
1179 /// Erases all attachments matching the \c shouldRemove predicate.
1180 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemerac0eb3d2016-08-12 04:32:42 +00001181 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1182 Attachments.end());
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001183 }
1184};
1185
Peter Collingbourned8d85ac2016-06-01 01:17:57 +00001186/// Multimap-like storage for metadata attachments for globals. This differs
1187/// from MDAttachmentMap in that it allows multiple attachments per metadata
1188/// kind.
1189class MDGlobalAttachmentMap {
1190 struct Attachment {
1191 unsigned MDKind;
1192 TrackingMDNodeRef Node;
1193 };
1194 SmallVector<Attachment, 1> Attachments;
1195
1196public:
1197 bool empty() const { return Attachments.empty(); }
1198
1199 /// Appends all attachments with the given ID to \c Result in insertion order.
1200 /// If the global has no attachments with the given ID, or if ID is invalid,
1201 /// leaves Result unchanged.
Benjamin Kramerf4eac502018-05-31 13:29:58 +00001202 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
1203
1204 /// Returns the first attachment with the given ID or nullptr if no such
1205 /// attachment exists.
1206 MDNode *lookup(unsigned ID) const;
Peter Collingbourned8d85ac2016-06-01 01:17:57 +00001207
1208 void insert(unsigned ID, MDNode &MD);
Benjamin Kramerf4eac502018-05-31 13:29:58 +00001209 bool erase(unsigned ID);
Peter Collingbourned8d85ac2016-06-01 01:17:57 +00001210
1211 /// Appends all attachments for the global to \c Result, sorting by attachment
1212 /// ID. Attachments with the same ID appear in insertion order. This function
1213 /// does \em not clear \c Result.
1214 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1215};
1216
Benjamin Kramer55c06ae2013-09-11 18:05:11 +00001217class LLVMContextImpl {
Benjamin Kramer12ddd402009-08-11 17:45:13 +00001218public:
Owen Anderson30268be2010-09-08 18:03:32 +00001219 /// OwnedModules - The set of modules instantiated in this context, and which
1220 /// will be automatically deleted if this context is deleted.
1221 SmallPtrSet<Module*, 4> OwnedModules;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001222
Eugene Zelenkof1934002017-06-19 22:05:08 +00001223 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1224 void *InlineAsmDiagContext = nullptr;
Quentin Colombetde262fe2013-12-17 17:47:22 +00001225
Vivek Pandya18b4c372017-09-15 20:10:09 +00001226 std::unique_ptr<DiagnosticHandler> DiagHandler;
Eugene Zelenkof1934002017-06-19 22:05:08 +00001227 bool RespectDiagnosticFilters = false;
Brian Gesiak8e8ec782017-06-30 18:13:59 +00001228 bool DiagnosticsHotnessRequested = false;
Brian Gesiake3305282017-06-30 23:14:53 +00001229 uint64_t DiagnosticsHotnessThreshold = 0;
Adam Nemet47c0d492016-09-27 20:55:07 +00001230 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
Quentin Colombetde262fe2013-12-17 17:47:22 +00001231
Eugene Zelenkof1934002017-06-19 22:05:08 +00001232 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1233 void *YieldOpaqueHandle = nullptr;
Juergen Ributzka9bc1b732014-05-16 02:33:15 +00001234
Eugene Zelenkof1934002017-06-19 22:05:08 +00001235 using IntMapTy =
1236 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
Owen Anderson001dbfe2009-07-16 18:04:31 +00001237 IntMapTy IntConstants;
NAKAMURA Takumic5890982014-12-06 05:57:06 +00001238
Eugene Zelenkof1934002017-06-19 22:05:08 +00001239 using FPMapTy =
1240 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
Owen Anderson914e50c2009-07-16 19:05:41 +00001241 FPMapTy FPConstants;
Bill Wendling2c79ecb2012-09-26 21:07:29 +00001242
Bill Wendlingf6670722012-12-20 01:36:59 +00001243 FoldingSet<AttributeImpl> AttrsSet;
Reid Kleckner67077702017-03-21 16:57:19 +00001244 FoldingSet<AttributeListImpl> AttrsLists;
Bill Wendling3467e302013-01-24 00:06:56 +00001245 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendling0976e002012-11-20 05:09:20 +00001246
Duncan P. N. Exon Smithadb72b92016-04-06 06:41:54 +00001247 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smithdad20b22014-12-09 18:38:53 +00001248 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1249 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendling2c79ecb2012-09-26 21:07:29 +00001250
Owen Andersonbd84bdb2015-06-01 22:24:01 +00001251 DenseMap<const Value*, ValueName*> ValueNames;
1252
Duncan P. N. Exon Smithc61bc482015-08-03 17:26:41 +00001253#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1254 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smitha1966292015-02-04 21:46:12 +00001255#include "llvm/IR/Metadata.def"
Bill Wendling2c79ecb2012-09-26 21:07:29 +00001256
Duncan P. N. Exon Smith9bb5d5d2016-04-17 03:58:21 +00001257 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smith75cc0512016-04-19 16:06:50 +00001258 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith9bb5d5d2016-04-17 03:58:21 +00001259
Jeffrey Yasskin6f555ca2010-03-13 01:26:15 +00001260 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1261 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith995d8632016-04-19 23:59:13 +00001262 // one object can destroy them. Keep track of them here so we can delete
1263 // them on context teardown.
1264 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith2c38b002014-11-18 00:37:17 +00001265
Justin Lebara2e3c5a2016-10-10 16:26:13 +00001266 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson0631fce2009-08-10 18:16:08 +00001267
Eugene Zelenkof1934002017-06-19 22:05:08 +00001268 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
Owen Andersoneed707b2009-07-24 23:12:02 +00001269 ArrayConstantsTy ArrayConstants;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001270
Eugene Zelenkof1934002017-06-19 22:05:08 +00001271 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
Owen Andersoneed707b2009-07-24 23:12:02 +00001272 StructConstantsTy StructConstants;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001273
Eugene Zelenkof1934002017-06-19 22:05:08 +00001274 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
Owen Andersoneed707b2009-07-24 23:12:02 +00001275 VectorConstantsTy VectorConstants;
Chris Lattner9df0fb42012-01-23 15:20:12 +00001276
Justin Lebara2e3c5a2016-10-10 16:26:13 +00001277 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1278
1279 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1280
Chris Lattner27dd9cf2012-01-23 22:57:10 +00001281 StringMap<ConstantDataSequential*> CDSConstants;
1282
Chandler Carruth60e425e2014-01-19 02:13:50 +00001283 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1284 BlockAddresses;
Duncan P. N. Exon Smith7116af62014-08-19 16:39:58 +00001285 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinbf48a9b2010-03-21 20:37:19 +00001286
Duncan P. N. Exon Smith7116af62014-08-19 16:39:58 +00001287 ConstantUniqueMap<InlineAsm> InlineAsms;
1288
Eugene Zelenkof1934002017-06-19 22:05:08 +00001289 ConstantInt *TheTrueVal = nullptr;
1290 ConstantInt *TheFalseVal = nullptr;
Duncan P. N. Exon Smithdad20b22014-12-09 18:38:53 +00001291
David Majnemer3ee61b82015-11-16 20:55:57 +00001292 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemer83fc12a2015-11-11 21:57:16 +00001293
Dan Gohman63a03cf2009-08-25 16:00:35 +00001294 // Basic type instances.
David Majnemer2dacece2015-08-14 05:09:07 +00001295 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattner1afcace2011-07-09 17:41:24 +00001296 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Bartonfbfd58a2015-04-17 15:32:15 +00001297 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001298
Chris Lattnerba3ddf32011-07-15 05:49:15 +00001299 /// TypeAllocator - All dynamically allocated types are allocated from this.
1300 /// They live forever until the context is torn down.
1301 BumpPtrAllocator TypeAllocator;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001302
Chris Lattner1afcace2011-07-09 17:41:24 +00001303 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer29917252014-12-06 19:22:54 +00001304
Eugene Zelenkof1934002017-06-19 22:05:08 +00001305 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
Benjamin Kramer29917252014-12-06 19:22:54 +00001306 FunctionTypeSet FunctionTypes;
Eugene Zelenkof1934002017-06-19 22:05:08 +00001307 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
Benjamin Kramer29917252014-12-06 19:22:54 +00001308 StructTypeSet AnonStructTypes;
Chris Lattner1afcace2011-07-09 17:41:24 +00001309 StringMap<StructType*> NamedStructTypes;
Eugene Zelenkof1934002017-06-19 22:05:08 +00001310 unsigned NamedStructTypesUniqueID = 0;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001311
Chris Lattner1afcace2011-07-09 17:41:24 +00001312 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1313 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1314 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1315 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskin9233b152010-02-11 06:41:30 +00001316
Owen Anderson4d919432009-08-18 18:28:58 +00001317 /// ValueHandles - This map keeps track of all of the value handles that are
1318 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman4c8e74f2013-03-01 18:48:54 +00001319 /// whether or not a value has an entry in this map.
Eugene Zelenkof1934002017-06-19 22:05:08 +00001320 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
Owen Anderson4d919432009-08-18 18:28:58 +00001321 ValueHandlesTy ValueHandles;
Fangrui Songaf7b1832018-07-30 19:41:25 +00001322
Chris Lattner08113472009-12-29 09:01:33 +00001323 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1324 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smithdad20b22014-12-09 18:38:53 +00001325
Duncan P. N. Exon Smith4eae7e02015-04-24 20:16:42 +00001326 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smith223d9cf2015-04-24 20:36:25 +00001327 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith4eae7e02015-04-24 20:16:42 +00001328
Peter Collingbourne6aef9f92016-05-31 23:01:54 +00001329 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourned8d85ac2016-06-01 01:17:57 +00001330 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smitheb79bb62015-04-24 21:51:02 +00001331
Reid Kleckner7b685032017-01-10 23:23:58 +00001332 /// Collection of per-GlobalObject sections used in this context.
1333 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1334
1335 /// Stable collection of section strings.
1336 StringSet<> SectionStrings;
1337
Diego Novillof05b45f2014-03-03 20:06:11 +00001338 /// DiscriminatorTable - This table maps file:line locations to an
1339 /// integer representing the next DWARF path discriminator to assign to
1340 /// instructions in different blocks at the same location.
1341 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1342
Chris Lattnerb2279252010-04-01 00:37:44 +00001343 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1344 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames07fbc5c2015-01-16 20:07:33 +00001345
Adrian Prantl26b584c2018-05-01 15:54:18 +00001346 /// A set of interned tags for operand bundles. The StringMap maps
Sanjoy Das5b674c02015-09-24 19:14:18 +00001347 /// bundle tags to their IDs.
1348 ///
1349 /// \see LLVMContext::getOperandBundleTagID
1350 StringMap<uint32_t> BundleTagCache;
1351
1352 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1353 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1354 uint32_t getOperandBundleTagID(StringRef Tag) const;
1355
Konstantin Zhuravlyov8f856852017-07-11 22:23:00 +00001356 /// A set of interned synchronization scopes. The StringMap maps
1357 /// synchronization scope names to their respective synchronization scope IDs.
1358 StringMap<SyncScope::ID> SSC;
1359
1360 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1361 /// synchronization scope ID. Every synchronization scope registered with
1362 /// LLVMContext has unique ID except pre-defined ones.
1363 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1364
1365 /// getSyncScopeNames - Populates client supplied SmallVector with
1366 /// synchronization scope names registered with LLVMContext. Synchronization
1367 /// scope names are ordered by increasing synchronization scope IDs.
1368 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1369
Mehdi Amini3569d3c2016-01-08 02:28:20 +00001370 /// Maintain the GC name for each function.
1371 ///
1372 /// This saves allocating an additional word in Function for programs which
1373 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1374 /// clients which do use GC.
1375 DenseMap<const Function*, std::string> GCNames;
1376
Mehdi Amini2de99272016-03-10 01:28:54 +00001377 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1378 /// not.
1379 bool DiscardValueNames = false;
1380
Jeffrey Yasskin2f1efd62010-03-21 21:17:34 +00001381 LLVMContextImpl(LLVMContext &C);
1382 ~LLVMContextImpl();
Manman Ren0d12d4e2015-01-20 19:24:59 +00001383
1384 /// Destroy the ConstantArrays if they are not used.
1385 void dropTriviallyDeadConstantArrays();
Andrew Kaylor1e455c52016-04-22 22:06:11 +00001386
Fedor Sergeev46d5e2b2018-04-05 10:29:37 +00001387 mutable OptPassGate *OPG = nullptr;
1388
Adrian Prantl26b584c2018-05-01 15:54:18 +00001389 /// Access the object which can disable optional passes and individual
Fedor Sergeev46d5e2b2018-04-05 10:29:37 +00001390 /// optimizations at compile time.
1391 OptPassGate &getOptPassGate() const;
1392
Adrian Prantl26b584c2018-05-01 15:54:18 +00001393 /// Set the object which can disable optional passes and individual
Fedor Sergeev46d5e2b2018-04-05 10:29:37 +00001394 /// optimizations at compile time.
1395 ///
1396 /// The lifetime of the object must be guaranteed to extend as long as the
1397 /// LLVMContext is used by compilation.
1398 void setOptPassGate(OptPassGate&);
Owen Anderson2bc29dc2009-06-30 00:48:55 +00001399};
1400
Eugene Zelenkof1934002017-06-19 22:05:08 +00001401} // end namespace llvm
Owen Anderson2bc29dc2009-06-30 00:48:55 +00001402
Eugene Zelenkof1934002017-06-19 22:05:08 +00001403#endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H