blob: b2ba9d38a81945f9cff920ee7b0defedda55eb22 [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//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Owen Anderson36f62e52009-06-30 17:06:46 +00009//
10// This file declares LLVMContextImpl, the opaque implementation
11// of LLVMContext.
12//
13//===----------------------------------------------------------------------===//
Owen Anderson8e66e0b2009-06-30 00:48:55 +000014
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
16#define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
Owen Anderson8e66e0b2009-06-30 00:48:55 +000017
Bill Wendling4607f4b2012-12-20 01:36:59 +000018#include "AttributeImpl.h"
Owen Andersonafd0c4c2009-08-04 22:41:48 +000019#include "ConstantsContext.h"
Owen Andersonc277dc42009-07-16 19:05:41 +000020#include "llvm/ADT/APFloat.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000021#include "llvm/ADT/APInt.h"
Jay Foadc365eea2011-06-22 08:50:06 +000022#include "llvm/ADT/ArrayRef.h"
Owen Anderson20b34ac2009-07-16 18:04:31 +000023#include "llvm/ADT/DenseMap.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000024#include "llvm/ADT/DenseMapInfo.h"
Duncan P. N. Exon Smithf39c3b82014-11-17 23:28:21 +000025#include "llvm/ADT/DenseSet.h"
Owen Anderson4118dde2009-07-16 23:44:30 +000026#include "llvm/ADT/FoldingSet.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000027#include "llvm/ADT/Hashing.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000028#include "llvm/ADT/Optional.h"
29#include "llvm/ADT/STLExtras.h"
Jeffrey Yasskin28f24482009-12-17 19:55:06 +000030#include "llvm/ADT/SmallPtrSet.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000031#include "llvm/ADT/SmallVector.h"
Owen Anderson69ab4162009-07-16 22:11:26 +000032#include "llvm/ADT/StringMap.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000033#include "llvm/ADT/StringRef.h"
Reid Kleckner443423e2017-01-10 23:23:58 +000034#include "llvm/ADT/StringSet.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000035#include "llvm/BinaryFormat/Dwarf.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000036#include "llvm/IR/Constants.h"
Duncan P. N. Exon Smithd9901ff2015-02-02 18:53:21 +000037#include "llvm/IR/DebugInfoMetadata.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000038#include "llvm/IR/DerivedTypes.h"
39#include "llvm/IR/LLVMContext.h"
40#include "llvm/IR/Metadata.h"
Eugene Zelenkode6cce22017-06-19 22:05:08 +000041#include "llvm/IR/TrackingMDRef.h"
42#include "llvm/Support/Allocator.h"
43#include "llvm/Support/Casting.h"
Adam Nemeta62b7e12016-09-27 20:55:07 +000044#include "llvm/Support/YAMLTraits.h"
Eugene Zelenkode6cce22017-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 Smith3eef9d12016-04-19 23:59:13 +000052#include <vector>
Owen Anderson39ede7b2009-07-21 20:13:12 +000053
Owen Anderson20b34ac2009-07-16 18:04:31 +000054namespace llvm {
Owen Andersonedb4a702009-07-24 23:12:02 +000055
Owen Andersonc277dc42009-07-16 19:05:41 +000056class ConstantFP;
Eugene Zelenkode6cce22017-06-19 22:05:08 +000057class ConstantInt;
Owen Anderson20b34ac2009-07-16 18:04:31 +000058class Type;
Owen Anderson4118dde2009-07-16 23:44:30 +000059class Value;
Eugene Zelenkode6cce22017-06-19 22:05:08 +000060class ValueHandleBase;
Owen Anderson20b34ac2009-07-16 18:04:31 +000061
Benjamin Kramer079b96e2013-09-11 18:05:11 +000062struct DenseMapAPIntKeyInfo {
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000063 static inline APInt getEmptyKey() {
64 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000065 V.U.VAL = 0;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000066 return V;
67 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000068
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000069 static inline APInt getTombstoneKey() {
70 APInt V(nullptr, 0);
Craig Topperb339c6d2017-05-03 15:46:24 +000071 V.U.VAL = 1;
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000072 return V;
73 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000074
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000075 static unsigned getHashValue(const APInt &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000076 return static_cast<unsigned>(hash_value(Key));
Owen Anderson20b34ac2009-07-16 18:04:31 +000077 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000078
Benjamin Kramer8e5dc532014-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 Anderson20b34ac2009-07-16 18:04:31 +000082};
83
Benjamin Kramer079b96e2013-09-11 18:05:11 +000084struct DenseMapAPFloatKeyInfo {
Stephan Bergmann17c7f702016-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 Zelenkode6cce22017-06-19 22:05:08 +000087
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000088 static unsigned getHashValue(const APFloat &Key) {
Chandler Carruth71bd7d12012-03-04 12:02:57 +000089 return static_cast<unsigned>(hash_value(Key));
Owen Andersonc277dc42009-07-16 19:05:41 +000090 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +000091
Benjamin Kramer8e5dc532014-12-06 13:12:56 +000092 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
93 return LHS.bitwiseIsEqual(RHS);
94 }
Owen Andersonc277dc42009-07-16 19:05:41 +000095};
96
Benjamin Kramer079b96e2013-09-11 18:05:11 +000097struct AnonStructTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +000098 struct KeyTy {
99 ArrayRef<Type*> ETypes;
100 bool isPacked;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000101
Jay Foad529776c2012-02-23 09:17:40 +0000102 KeyTy(const ArrayRef<Type*>& E, bool P) :
103 ETypes(E), isPacked(P) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000104
Rafael Espindola334b73f2014-11-21 18:53:05 +0000105 KeyTy(const StructType *ST)
106 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000107
Jay Foad529776c2012-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 Zelenkode6cce22017-06-19 22:05:08 +0000119
Jay Foad529776c2012-02-23 09:17:40 +0000120 static inline StructType* getEmptyKey() {
121 return DenseMapInfo<StructType*>::getEmptyKey();
122 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000123
Jay Foad529776c2012-02-23 09:17:40 +0000124 static inline StructType* getTombstoneKey() {
125 return DenseMapInfo<StructType*>::getTombstoneKey();
126 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000127
Jay Foad529776c2012-02-23 09:17:40 +0000128 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-03-01 18:55:25 +0000129 return hash_combine(hash_combine_range(Key.ETypes.begin(),
130 Key.ETypes.end()),
131 Key.isPacked);
Jay Foad529776c2012-02-23 09:17:40 +0000132 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000133
Jay Foad529776c2012-02-23 09:17:40 +0000134 static unsigned getHashValue(const StructType *ST) {
135 return getHashValue(KeyTy(ST));
136 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000137
Jay Foad529776c2012-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 Zelenkode6cce22017-06-19 22:05:08 +0000143
Jay Foad529776c2012-02-23 09:17:40 +0000144 static bool isEqual(const StructType *LHS, const StructType *RHS) {
145 return LHS == RHS;
146 }
147};
148
Benjamin Kramer079b96e2013-09-11 18:05:11 +0000149struct FunctionTypeKeyInfo {
Jay Foad529776c2012-02-23 09:17:40 +0000150 struct KeyTy {
151 const Type *ReturnType;
152 ArrayRef<Type*> Params;
153 bool isVarArg;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000154
Jay Foad529776c2012-02-23 09:17:40 +0000155 KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
156 ReturnType(R), Params(P), isVarArg(V) {}
Rafael Espindolae973fd42014-11-21 19:03:35 +0000157 KeyTy(const FunctionType *FT)
158 : ReturnType(FT->getReturnType()), Params(FT->params()),
159 isVarArg(FT->isVarArg()) {}
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000160
Jay Foad529776c2012-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 Zelenkode6cce22017-06-19 22:05:08 +0000174
Jay Foad529776c2012-02-23 09:17:40 +0000175 static inline FunctionType* getEmptyKey() {
176 return DenseMapInfo<FunctionType*>::getEmptyKey();
177 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000178
Jay Foad529776c2012-02-23 09:17:40 +0000179 static inline FunctionType* getTombstoneKey() {
180 return DenseMapInfo<FunctionType*>::getTombstoneKey();
181 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000182
Jay Foad529776c2012-02-23 09:17:40 +0000183 static unsigned getHashValue(const KeyTy& Key) {
Chandler Carruth1d03a3b2012-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 Foad529776c2012-02-23 09:17:40 +0000188 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000189
Jay Foad529776c2012-02-23 09:17:40 +0000190 static unsigned getHashValue(const FunctionType *FT) {
191 return getHashValue(KeyTy(FT));
192 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000193
Jay Foad529776c2012-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 Zelenkode6cce22017-06-19 22:05:08 +0000199
Jay Foad529776c2012-02-23 09:17:40 +0000200 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
201 return LHS == RHS;
202 }
203};
204
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000205/// \brief Structure for hashing arbitrary MDNode operands.
206class MDNodeOpsKey {
207 ArrayRef<Metadata *> RawOps;
208 ArrayRef<MDOperand> Ops;
Duncan P. N. Exon Smith93e983e2015-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 Smith8af6cfc2015-02-04 22:08:30 +0000216 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000217 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000218
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000219 template <class NodeTy>
220 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
Duncan P. N. Exon Smith93e983e2015-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 Smithfed199a2015-01-20 00:01:43 +0000225 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
226 : compareOps(RawOps, RHS, Offset);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000227 }
228
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000229 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000230
231private:
232 template <class T>
Duncan P. N. Exon Smithfed199a2015-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 Smith93e983e2015-01-19 22:53:18 +0000235 return false;
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000236 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
Duncan P. N. Exon Smith93e983e2015-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 Smith8af6cfc2015-02-04 22:08:30 +0000245template <class NodeTy> struct MDNodeKeyImpl;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000246
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000247/// Configuration point for MDNodeInfo::isEqual().
248template <class NodeTy> struct MDNodeSubsetEqualImpl {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000249 using KeyTy = MDNodeKeyImpl<NodeTy>;
250
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000251 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
252 return false;
253 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000254
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +0000255 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
256 return false;
257 }
258};
259
Duncan P. N. Exon Smith118632d2015-01-12 20:09:34 +0000260/// \brief DenseMapInfo for MDTuple.
Duncan P. N. Exon Smithf39c3b82014-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 Smith8af6cfc2015-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 Smithf39c3b82014-11-17 23:28:21 +0000267
Duncan P. N. Exon Smith9c26d802015-02-05 00:51:35 +0000268 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
Duncan P. N. Exon Smith93e983e2015-01-19 22:53:18 +0000269
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000270 unsigned getHashValue() const { return getHash(); }
271
272 static unsigned calculateHash(MDTuple *N) {
273 return MDNodeOpsKey::calculateHash(N);
Benjamin Kramer2335a5c2012-04-11 14:06:54 +0000274 }
275};
276
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000277/// \brief DenseMapInfo for DILocation.
278template <> struct MDNodeKeyImpl<DILocation> {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000279 unsigned Line;
280 unsigned Column;
281 Metadata *Scope;
282 Metadata *InlinedAt;
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000283
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000284 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
285 Metadata *InlinedAt)
286 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
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()),
289 InlinedAt(L->getRawInlinedAt()) {}
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() &&
Duncan P. N. Exon Smith26489982015-03-26 22:05:04 +0000293 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000294 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000295
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000296 unsigned getHashValue() const {
297 return hash_combine(Line, Column, Scope, InlinedAt);
Duncan P. N. Exon Smithde03ff52015-01-13 20:44:56 +0000298 }
299};
300
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000301/// \brief DenseMapInfo for GenericDINode.
302template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000303 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000304 MDString *Header;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000305
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000306 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000307 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000308 MDNodeKeyImpl(const GenericDINode *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000309 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000310
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000311 bool isKeyOf(const GenericDINode *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000312 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000313 compareOps(RHS, 1);
314 }
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000315
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000316 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
317
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000318 static unsigned calculateHash(GenericDINode *N) {
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000319 return MDNodeOpsKey::calculateHash(N, 1);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +0000320 }
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +0000321};
322
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000323template <> struct MDNodeKeyImpl<DISubrange> {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000324 Metadata *CountNode;
Duncan P. N. Exon Smith5dcf6212015-04-07 00:39:59 +0000325 int64_t LowerBound;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000326
Sander de Smalenfdf40912018-01-24 09:56:07 +0000327 MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
328 : CountNode(CountNode), LowerBound(LowerBound) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000329 MDNodeKeyImpl(const DISubrange *N)
Sander de Smalenfdf40912018-01-24 09:56:07 +0000330 : CountNode(N->getRawCountNode()),
331 LowerBound(N->getLowerBound()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000332
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000333 bool isKeyOf(const DISubrange *RHS) const {
Sander de Smalenfdf40912018-01-24 09:56:07 +0000334 if (LowerBound != RHS->getLowerBound())
335 return false;
336
337 if (auto *RHSCount = RHS->getCount().dyn_cast<ConstantInt*>())
338 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
339 if (RHSCount->getSExtValue() ==
340 cast<ConstantInt>(MD->getValue())->getSExtValue())
341 return true;
342
343 return CountNode == RHS->getRawCountNode();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000344 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000345
Sander de Smalenfdf40912018-01-24 09:56:07 +0000346 unsigned getHashValue() const {
347 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
348 return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
349 LowerBound);
350 return hash_combine(CountNode, LowerBound);
351 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000352};
353
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000354template <> struct MDNodeKeyImpl<DIEnumerator> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000355 int64_t Value;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000356 MDString *Name;
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000357 bool IsUnsigned;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000358
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000359 MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
360 : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000361 MDNodeKeyImpl(const DIEnumerator *N)
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000362 : Value(N->getValue()), Name(N->getRawName()),
363 IsUnsigned(N->isUnsigned()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000364
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000365 bool isKeyOf(const DIEnumerator *RHS) const {
Momchil Velikov08dc66e2018-02-12 16:10:09 +0000366 return Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
367 Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000368 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000369
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000370 unsigned getHashValue() const { return hash_combine(Value, Name); }
371};
372
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000373template <> struct MDNodeKeyImpl<DIBasicType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000374 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000375 MDString *Name;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000376 uint64_t SizeInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000377 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000378 unsigned Encoding;
379
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000380 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000381 uint32_t AlignInBits, unsigned Encoding)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000382 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
383 Encoding(Encoding) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000384 MDNodeKeyImpl(const DIBasicType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000385 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000386 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
387
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000388 bool isKeyOf(const DIBasicType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000389 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000390 SizeInBits == RHS->getSizeInBits() &&
391 AlignInBits == RHS->getAlignInBits() &&
392 Encoding == RHS->getEncoding();
393 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000394
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000395 unsigned getHashValue() const {
396 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
397 }
398};
399
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000400template <> struct MDNodeKeyImpl<DIDerivedType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000401 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000402 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000403 Metadata *File;
404 unsigned Line;
405 Metadata *Scope;
406 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000407 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000408 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000409 uint32_t AlignInBits;
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000410 Optional<unsigned> DWARFAddressSpace;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000411 unsigned Flags;
412 Metadata *ExtraData;
413
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000414 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000415 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000416 uint32_t AlignInBits, uint64_t OffsetInBits,
417 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000418 Metadata *ExtraData)
419 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000420 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000421 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
422 Flags(Flags), ExtraData(ExtraData) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000423 MDNodeKeyImpl(const DIDerivedType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000424 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000425 Line(N->getLine()), Scope(N->getRawScope()),
426 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000427 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000428 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
429 ExtraData(N->getRawExtraData()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000430
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000431 bool isKeyOf(const DIDerivedType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000432 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000433 File == RHS->getRawFile() && Line == RHS->getLine() &&
434 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000435 SizeInBits == RHS->getSizeInBits() &&
436 AlignInBits == RHS->getAlignInBits() &&
Konstantin Zhuravlyovd5561e02017-03-08 23:55:44 +0000437 OffsetInBits == RHS->getOffsetInBits() &&
438 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
439 Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000440 ExtraData == RHS->getRawExtraData();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000441 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000442
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000443 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000444 // If this is a member inside an ODR type, only hash the type and the name.
445 // Otherwise the hash will be stronger than
446 // MDNodeSubsetEqualImpl::isODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000447 if (Tag == dwarf::DW_TAG_member && Name)
448 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
449 if (CT->getRawIdentifier())
450 return hash_combine(Name, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000451
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000452 // Intentionally computes the hash on a subset of the operands for
453 // performance reason. The subset has to be significant enough to avoid
454 // collision "most of the time". There is no correctness issue in case of
455 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000456 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000457 }
458};
459
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000460template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000461 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
462
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000463 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
464 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
465 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000466
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000467 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
468 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
469 RHS);
470 }
471
472 /// Subprograms compare equal if they declare the same function in an ODR
473 /// type.
474 static bool isODRMember(unsigned Tag, const Metadata *Scope,
475 const MDString *Name, const DIDerivedType *RHS) {
476 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000477 if (Tag != dwarf::DW_TAG_member || !Name)
478 return false;
479
480 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
481 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000482 return false;
483
484 // Compare to the RHS.
485 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
486 Scope == RHS->getRawScope();
487 }
488};
489
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000490template <> struct MDNodeKeyImpl<DICompositeType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000491 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000492 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000493 Metadata *File;
494 unsigned Line;
495 Metadata *Scope;
496 Metadata *BaseType;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000497 uint64_t SizeInBits;
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000498 uint64_t OffsetInBits;
Victor Leschuk197aa312016-10-18 14:31:22 +0000499 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000500 unsigned Flags;
501 Metadata *Elements;
502 unsigned RuntimeLang;
503 Metadata *VTableHolder;
504 Metadata *TemplateParams;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000505 MDString *Identifier;
Adrian Prantl8c599212018-02-06 23:45:59 +0000506 Metadata *Discriminator;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000507
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000508 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
Duncan P. N. Exon Smithd34db172015-02-19 23:56:07 +0000509 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
Victor Leschuk197aa312016-10-18 14:31:22 +0000510 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000511 Metadata *Elements, unsigned RuntimeLang,
512 Metadata *VTableHolder, Metadata *TemplateParams,
Adrian Prantl8c599212018-02-06 23:45:59 +0000513 MDString *Identifier, Metadata *Discriminator)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000514 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
Victor Leschuk197aa312016-10-18 14:31:22 +0000515 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
516 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000517 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
Adrian Prantl8c599212018-02-06 23:45:59 +0000518 TemplateParams(TemplateParams), Identifier(Identifier),
519 Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000520 MDNodeKeyImpl(const DICompositeType *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000521 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000522 Line(N->getLine()), Scope(N->getRawScope()),
523 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
Victor Leschuk197aa312016-10-18 14:31:22 +0000524 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000525 Flags(N->getFlags()), Elements(N->getRawElements()),
526 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
527 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl8c599212018-02-06 23:45:59 +0000528 Identifier(N->getRawIdentifier()),
529 Discriminator(N->getRawDiscriminator()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000530
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000531 bool isKeyOf(const DICompositeType *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000532 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000533 File == RHS->getRawFile() && Line == RHS->getLine() &&
534 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000535 SizeInBits == RHS->getSizeInBits() &&
536 AlignInBits == RHS->getAlignInBits() &&
537 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000538 Elements == RHS->getRawElements() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000539 RuntimeLang == RHS->getRuntimeLang() &&
Duncan P. N. Exon Smith53855f02015-03-27 23:05:04 +0000540 VTableHolder == RHS->getRawVTableHolder() &&
541 TemplateParams == RHS->getRawTemplateParams() &&
Adrian Prantl8c599212018-02-06 23:45:59 +0000542 Identifier == RHS->getRawIdentifier() &&
543 Discriminator == RHS->getRawDiscriminator();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000544 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000545
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000546 unsigned getHashValue() const {
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000547 // Intentionally computes the hash on a subset of the operands for
548 // performance reason. The subset has to be significant enough to avoid
549 // collision "most of the time". There is no correctness issue in case of
550 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000551 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
552 TemplateParams);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000553 }
554};
555
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000556template <> struct MDNodeKeyImpl<DISubroutineType> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000557 unsigned Flags;
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000558 uint8_t CC;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000559 Metadata *TypeArray;
560
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000561 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
562 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000563 MDNodeKeyImpl(const DISubroutineType *N)
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000564 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000565
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000566 bool isKeyOf(const DISubroutineType *RHS) const {
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000567 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
568 TypeArray == RHS->getRawTypeArray();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000569 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000570
Reid Klecknerde3d8b52016-06-08 20:34:29 +0000571 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000572};
573
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000574template <> struct MDNodeKeyImpl<DIFile> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000575 MDString *Filename;
576 MDString *Directory;
Scott Linder71603842018-02-12 19:45:54 +0000577 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
Scott Linder16c7bda2018-02-23 23:01:06 +0000578 Optional<MDString *> Source;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000579
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000580 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
Scott Linder16c7bda2018-02-23 23:01:06 +0000581 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
582 Optional<MDString *> Source)
583 : Filename(Filename), Directory(Directory), Checksum(Checksum),
584 Source(Source) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000585 MDNodeKeyImpl(const DIFile *N)
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000586 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
Scott Linder16c7bda2018-02-23 23:01:06 +0000587 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000588
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000589 bool isKeyOf(const DIFile *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000590 return Filename == RHS->getRawFilename() &&
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000591 Directory == RHS->getRawDirectory() &&
Scott Linder16c7bda2018-02-23 23:01:06 +0000592 Checksum == RHS->getRawChecksum() &&
593 Source == RHS->getRawSource();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000594 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000595
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000596 unsigned getHashValue() const {
Scott Linder16c7bda2018-02-23 23:01:06 +0000597 return hash_combine(
598 Filename, Directory, Checksum ? Checksum->Kind : 0,
599 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
Amjad Aboud7faeecc2016-12-25 10:12:09 +0000600 }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000601};
602
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000603template <> struct MDNodeKeyImpl<DISubprogram> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000604 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000605 MDString *Name;
606 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000607 Metadata *File;
608 unsigned Line;
609 Metadata *Type;
610 bool IsLocalToUnit;
611 bool IsDefinition;
612 unsigned ScopeLine;
613 Metadata *ContainingType;
614 unsigned Virtuality;
615 unsigned VirtualIndex;
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000616 int ThisAdjustment;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000617 unsigned Flags;
618 bool IsOptimized;
Adrian Prantl75819ae2016-04-15 15:57:41 +0000619 Metadata *Unit;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000620 Metadata *TemplateParams;
621 Metadata *Declaration;
622 Metadata *Variables;
Adrian Prantl1d12b882017-04-26 22:56:44 +0000623 Metadata *ThrownTypes;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000624
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000625 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000626 Metadata *File, unsigned Line, Metadata *Type,
627 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
628 Metadata *ContainingType, unsigned Virtuality,
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000629 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
630 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
Adrian Prantl1d12b882017-04-26 22:56:44 +0000631 Metadata *Declaration, Metadata *Variables,
632 Metadata *ThrownTypes)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000633 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
634 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
635 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
636 ContainingType(ContainingType), Virtuality(Virtuality),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000637 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
638 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
639 TemplateParams(TemplateParams), Declaration(Declaration),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000640 Variables(Variables), ThrownTypes(ThrownTypes) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000641 MDNodeKeyImpl(const DISubprogram *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000642 : Scope(N->getRawScope()), Name(N->getRawName()),
643 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000644 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000645 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000646 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000647 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000648 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
649 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
650 TemplateParams(N->getRawTemplateParams()),
Adrian Prantl1d12b882017-04-26 22:56:44 +0000651 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()),
652 ThrownTypes(N->getRawThrownTypes()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000653
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000654 bool isKeyOf(const DISubprogram *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000655 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
656 LinkageName == RHS->getRawLinkageName() &&
657 File == RHS->getRawFile() && Line == RHS->getLine() &&
658 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000659 IsDefinition == RHS->isDefinition() &&
660 ScopeLine == RHS->getScopeLine() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000661 ContainingType == RHS->getRawContainingType() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000662 Virtuality == RHS->getVirtuality() &&
Reid Klecknerb5af11d2016-07-01 02:41:21 +0000663 VirtualIndex == RHS->getVirtualIndex() &&
664 ThisAdjustment == RHS->getThisAdjustment() &&
665 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
666 Unit == RHS->getUnit() &&
Duncan P. N. Exon Smith869db502015-03-30 16:19:15 +0000667 TemplateParams == RHS->getRawTemplateParams() &&
668 Declaration == RHS->getRawDeclaration() &&
Adrian Prantl1d12b882017-04-26 22:56:44 +0000669 Variables == RHS->getRawVariables() &&
670 ThrownTypes == RHS->getRawThrownTypes();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000671 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000672
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000673 unsigned getHashValue() const {
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000674 // If this is a declaration inside an ODR type, only hash the type and the
675 // name. Otherwise the hash will be stronger than
676 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000677 if (!IsDefinition && LinkageName)
678 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
679 if (CT->getRawIdentifier())
680 return hash_combine(LinkageName, Scope);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000681
Mehdi Amini9bc362a2016-03-19 01:06:24 +0000682 // Intentionally computes the hash on a subset of the operands for
683 // performance reason. The subset has to be significant enough to avoid
684 // collision "most of the time". There is no correctness issue in case of
685 // collision because of the full check above.
Mehdi Amini53fc3892016-03-19 00:59:26 +0000686 return hash_combine(Name, Scope, File, Type, Line);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000687 }
688};
689
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000690template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000691 using KeyTy = MDNodeKeyImpl<DISubprogram>;
692
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000693 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
694 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000695 LHS.LinkageName, LHS.TemplateParams, RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000696 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000697
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000698 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
699 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000700 LHS->getRawLinkageName(),
701 LHS->getRawTemplateParams(), RHS);
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000702 }
703
704 /// Subprograms compare equal if they declare the same function in an ODR
705 /// type.
706 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
707 const MDString *LinkageName,
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000708 const Metadata *TemplateParams,
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000709 const DISubprogram *RHS) {
710 // Check whether the LHS is eligible.
Duncan P. N. Exon Smitha59d3e52016-04-23 21:08:00 +0000711 if (IsDefinition || !Scope || !LinkageName)
712 return false;
713
714 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
715 if (!CT || !CT->getRawIdentifier())
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000716 return false;
717
718 // Compare to the RHS.
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000719 // FIXME: We need to compare template parameters here to avoid incorrect
720 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
721 // has a non-ODR template parameter (i.e., a DICompositeType that does not
722 // have an identifier). Eventually we should decouple ODR logic from
723 // uniquing logic.
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000724 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
Peter Collingbournee69e73c2017-02-06 21:23:03 +0000725 LinkageName == RHS->getRawLinkageName() &&
726 TemplateParams == RHS->getRawTemplateParams();
Duncan P. N. Exon Smith05ebfd02016-04-17 02:30:20 +0000727 }
728};
729
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000730template <> struct MDNodeKeyImpl<DILexicalBlock> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000731 Metadata *Scope;
732 Metadata *File;
733 unsigned Line;
734 unsigned Column;
735
736 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
737 : Scope(Scope), File(File), Line(Line), Column(Column) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000738 MDNodeKeyImpl(const DILexicalBlock *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000739 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000740 Column(N->getColumn()) {}
741
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000742 bool isKeyOf(const DILexicalBlock *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000743 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000744 Line == RHS->getLine() && Column == RHS->getColumn();
745 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000746
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000747 unsigned getHashValue() const {
748 return hash_combine(Scope, File, Line, Column);
749 }
750};
751
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000752template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000753 Metadata *Scope;
754 Metadata *File;
755 unsigned Discriminator;
756
757 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
758 : Scope(Scope), File(File), Discriminator(Discriminator) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000759 MDNodeKeyImpl(const DILexicalBlockFile *N)
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000760 : Scope(N->getRawScope()), File(N->getRawFile()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000761 Discriminator(N->getDiscriminator()) {}
762
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000763 bool isKeyOf(const DILexicalBlockFile *RHS) const {
Duncan P. N. Exon Smith0e202b92015-03-30 16:37:48 +0000764 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000765 Discriminator == RHS->getDiscriminator();
766 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000767
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000768 unsigned getHashValue() const {
769 return hash_combine(Scope, File, Discriminator);
770 }
771};
772
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000773template <> struct MDNodeKeyImpl<DINamespace> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000774 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000775 MDString *Name;
Adrian Prantldbfda632016-11-03 19:42:02 +0000776 bool ExportSymbols;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000777
Adrian Prantlfed4f392017-04-28 22:25:46 +0000778 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
779 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000780 MDNodeKeyImpl(const DINamespace *N)
Adrian Prantlfed4f392017-04-28 22:25:46 +0000781 : Scope(N->getRawScope()), Name(N->getRawName()),
782 ExportSymbols(N->getExportSymbols()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000783
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000784 bool isKeyOf(const DINamespace *RHS) const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000785 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Adrian Prantldbfda632016-11-03 19:42:02 +0000786 ExportSymbols == RHS->getExportSymbols();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000787 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000788
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000789 unsigned getHashValue() const {
Adrian Prantlfed4f392017-04-28 22:25:46 +0000790 return hash_combine(Scope, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000791 }
792};
793
Adrian Prantlab1243f2015-06-29 23:03:47 +0000794template <> struct MDNodeKeyImpl<DIModule> {
795 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000796 MDString *Name;
797 MDString *ConfigurationMacros;
798 MDString *IncludePath;
799 MDString *ISysRoot;
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000800
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000801 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
802 MDString *IncludePath, MDString *ISysRoot)
803 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
804 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000805 MDNodeKeyImpl(const DIModule *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000806 : Scope(N->getRawScope()), Name(N->getRawName()),
807 ConfigurationMacros(N->getRawConfigurationMacros()),
808 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
Adrian Prantlab1243f2015-06-29 23:03:47 +0000809
810 bool isKeyOf(const DIModule *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000811 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
812 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
813 IncludePath == RHS->getRawIncludePath() &&
814 ISysRoot == RHS->getRawISysRoot();
Adrian Prantlab1243f2015-06-29 23:03:47 +0000815 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000816
Adrian Prantlab1243f2015-06-29 23:03:47 +0000817 unsigned getHashValue() const {
818 return hash_combine(Scope, Name,
819 ConfigurationMacros, IncludePath, ISysRoot);
820 }
821};
822
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000823template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000824 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000825 Metadata *Type;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000826
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000827 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000828 MDNodeKeyImpl(const DITemplateTypeParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000829 : Name(N->getRawName()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000830
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000831 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000832 return Name == RHS->getRawName() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000833 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000834
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000835 unsigned getHashValue() const { return hash_combine(Name, Type); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000836};
837
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000838template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000839 unsigned Tag;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000840 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000841 Metadata *Type;
842 Metadata *Value;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000843
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000844 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000845 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000846 MDNodeKeyImpl(const DITemplateValueParameter *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000847 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000848 Value(N->getValue()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000849
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000850 bool isKeyOf(const DITemplateValueParameter *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000851 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smith3ec5fa62015-04-06 19:03:45 +0000852 Type == RHS->getRawType() && Value == RHS->getValue();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000853 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000854
Duncan P. N. Exon Smith3d62bba2015-02-19 00:37:21 +0000855 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000856};
857
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000858template <> struct MDNodeKeyImpl<DIGlobalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000859 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000860 MDString *Name;
861 MDString *LinkageName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000862 Metadata *File;
863 unsigned Line;
864 Metadata *Type;
865 bool IsLocalToUnit;
866 bool IsDefinition;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000867 Metadata *StaticDataMemberDeclaration;
Victor Leschuka37660c2016-10-26 21:32:29 +0000868 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000869
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000870 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000871 Metadata *File, unsigned Line, Metadata *Type,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000872 bool IsLocalToUnit, bool IsDefinition,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000873 Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000874 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
875 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000876 IsDefinition(IsDefinition),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000877 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
878 AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000879 MDNodeKeyImpl(const DIGlobalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000880 : Scope(N->getRawScope()), Name(N->getRawName()),
881 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000882 Line(N->getLine()), Type(N->getRawType()),
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000883 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000884 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
885 AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000886
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000887 bool isKeyOf(const DIGlobalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000888 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
889 LinkageName == RHS->getRawLinkageName() &&
890 File == RHS->getRawFile() && Line == RHS->getLine() &&
891 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000892 IsDefinition == RHS->isDefinition() &&
Duncan P. N. Exon Smith3d2afaa2015-03-27 17:29:58 +0000893 StaticDataMemberDeclaration ==
Victor Leschuk2ede1262016-10-20 00:13:12 +0000894 RHS->getRawStaticDataMemberDeclaration() &&
895 AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000896 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000897
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000898 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000899 // We do not use AlignInBits in hashing function here on purpose:
900 // in most cases this param for local variable is zero (for function param
901 // it is always zero). This leads to lots of hash collisions and errors on
902 // cases with lots of similar variables.
903 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
904 // generated IR is random for each run and test fails with Align included.
905 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000906 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000907 IsLocalToUnit, IsDefinition, /* AlignInBits, */
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000908 StaticDataMemberDeclaration);
909 }
910};
911
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000912template <> struct MDNodeKeyImpl<DILocalVariable> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000913 Metadata *Scope;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000914 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000915 Metadata *File;
916 unsigned Line;
917 Metadata *Type;
918 unsigned Arg;
919 unsigned Flags;
Victor Leschuka37660c2016-10-26 21:32:29 +0000920 uint32_t AlignInBits;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000921
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000922 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Victor Leschuk2ede1262016-10-20 00:13:12 +0000923 Metadata *Type, unsigned Arg, unsigned Flags,
Victor Leschuka37660c2016-10-26 21:32:29 +0000924 uint32_t AlignInBits)
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000925 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000926 Flags(Flags), AlignInBits(AlignInBits) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000927 MDNodeKeyImpl(const DILocalVariable *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000928 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000929 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Victor Leschuk2ede1262016-10-20 00:13:12 +0000930 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000931
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000932 bool isKeyOf(const DILocalVariable *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000933 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000934 File == RHS->getRawFile() && Line == RHS->getLine() &&
935 Type == RHS->getRawType() && Arg == RHS->getArg() &&
Victor Leschuk2ede1262016-10-20 00:13:12 +0000936 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000937 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000938
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000939 unsigned getHashValue() const {
Victor Leschuk2ede1262016-10-20 00:13:12 +0000940 // We do not use AlignInBits in hashing function here on purpose:
941 // in most cases this param for local variable is zero (for function param
942 // it is always zero). This leads to lots of hash collisions and errors on
943 // cases with lots of similar variables.
944 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
945 // generated IR is random for each run and test fails with Align included.
946 // TODO: make hashing work fine with such situations
Duncan P. N. Exon Smithed013cd2015-07-31 18:58:39 +0000947 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000948 }
949};
950
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000951template <> struct MDNodeKeyImpl<DIExpression> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000952 ArrayRef<uint64_t> Elements;
953
954 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000955 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000956
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000957 bool isKeyOf(const DIExpression *RHS) const {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000958 return Elements == RHS->getElements();
959 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000960
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000961 unsigned getHashValue() const {
962 return hash_combine_range(Elements.begin(), Elements.end());
963 }
964};
965
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000966template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
967 Metadata *Variable;
968 Metadata *Expression;
969
970 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
971 : Variable(Variable), Expression(Expression) {}
972 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
973 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
974
975 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
976 return Variable == RHS->getRawVariable() &&
977 Expression == RHS->getRawExpression();
978 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +0000979
Adrian Prantlbceaaa92016-12-20 02:09:43 +0000980 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
981};
982
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000983template <> struct MDNodeKeyImpl<DIObjCProperty> {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000984 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000985 Metadata *File;
986 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000987 MDString *GetterName;
988 MDString *SetterName;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000989 unsigned Attributes;
990 Metadata *Type;
991
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000992 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
993 MDString *GetterName, MDString *SetterName, unsigned Attributes,
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +0000994 Metadata *Type)
995 : Name(Name), File(File), Line(Line), GetterName(GetterName),
996 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000997 MDNodeKeyImpl(const DIObjCProperty *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +0000998 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
999 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001000 Attributes(N->getAttributes()), Type(N->getRawType()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001001
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001002 bool isKeyOf(const DIObjCProperty *RHS) const {
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001003 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1004 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1005 SetterName == RHS->getRawSetterName() &&
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001006 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001007 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001008
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001009 unsigned getHashValue() const {
1010 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1011 Type);
1012 }
1013};
1014
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001015template <> struct MDNodeKeyImpl<DIImportedEntity> {
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001016 unsigned Tag;
1017 Metadata *Scope;
1018 Metadata *Entity;
Adrian Prantld63bfd22017-07-19 00:09:54 +00001019 Metadata *File;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001020 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001021 MDString *Name;
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001022
Adrian Prantld63bfd22017-07-19 00:09:54 +00001023 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1024 unsigned Line, MDString *Name)
1025 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1026 Name(Name) {}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001027 MDNodeKeyImpl(const DIImportedEntity *N)
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001028 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
Adrian Prantld63bfd22017-07-19 00:09:54 +00001029 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001030
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +00001031 bool isKeyOf(const DIImportedEntity *RHS) const {
Duncan P. N. Exon Smithf9b47752015-03-30 17:21:38 +00001032 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
Adrian Prantld63bfd22017-07-19 00:09:54 +00001033 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1034 Line == RHS->getLine() && Name == RHS->getRawName();
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001035 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001036
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001037 unsigned getHashValue() const {
Adrian Prantld63bfd22017-07-19 00:09:54 +00001038 return hash_combine(Tag, Scope, Entity, File, Line, Name);
Duncan P. N. Exon Smith01fc1762015-02-10 00:52:32 +00001039 }
1040};
1041
Amjad Abouda9bcf162015-12-10 12:56:35 +00001042template <> struct MDNodeKeyImpl<DIMacro> {
1043 unsigned MIType;
1044 unsigned Line;
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001045 MDString *Name;
1046 MDString *Value;
Amjad Abouda9bcf162015-12-10 12:56:35 +00001047
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001048 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
Amjad Abouda9bcf162015-12-10 12:56:35 +00001049 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1050 MDNodeKeyImpl(const DIMacro *N)
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001051 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1052 Value(N->getRawValue()) {}
Amjad Abouda9bcf162015-12-10 12:56:35 +00001053
1054 bool isKeyOf(const DIMacro *RHS) const {
1055 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Mehdi Amini5d99c4e2016-03-19 01:02:34 +00001056 Name == RHS->getRawName() && Value == RHS->getRawValue();
Amjad Abouda9bcf162015-12-10 12:56:35 +00001057 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001058
Amjad Abouda9bcf162015-12-10 12:56:35 +00001059 unsigned getHashValue() const {
1060 return hash_combine(MIType, Line, Name, Value);
1061 }
1062};
1063
1064template <> struct MDNodeKeyImpl<DIMacroFile> {
1065 unsigned MIType;
1066 unsigned Line;
1067 Metadata *File;
1068 Metadata *Elements;
1069
1070 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1071 Metadata *Elements)
1072 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1073 MDNodeKeyImpl(const DIMacroFile *N)
1074 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1075 Elements(N->getRawElements()) {}
1076
1077 bool isKeyOf(const DIMacroFile *RHS) const {
1078 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
Amjad Aboud580498d2016-07-31 14:41:50 +00001079 File == RHS->getRawFile() && Elements == RHS->getRawElements();
Amjad Abouda9bcf162015-12-10 12:56:35 +00001080 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001081
Amjad Abouda9bcf162015-12-10 12:56:35 +00001082 unsigned getHashValue() const {
1083 return hash_combine(MIType, Line, File, Elements);
1084 }
1085};
1086
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001087/// \brief DenseMapInfo for MDNode subclasses.
1088template <class NodeTy> struct MDNodeInfo {
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001089 using KeyTy = MDNodeKeyImpl<NodeTy>;
1090 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1091
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001092 static inline NodeTy *getEmptyKey() {
1093 return DenseMapInfo<NodeTy *>::getEmptyKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001094 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001095
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001096 static inline NodeTy *getTombstoneKey() {
1097 return DenseMapInfo<NodeTy *>::getTombstoneKey();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001098 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001099
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001100 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001101
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001102 static unsigned getHashValue(const NodeTy *N) {
1103 return KeyTy(N).getHashValue();
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001104 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001105
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001106 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1107 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1108 return false;
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001109 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001110 }
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001111
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001112 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
Duncan P. N. Exon Smithf2291272016-04-16 23:42:04 +00001113 if (LHS == RHS)
1114 return true;
1115 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1116 return false;
1117 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
Duncan P. N. Exon Smithfed199a2015-01-20 00:01:43 +00001118 }
1119};
1120
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001121#define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
Duncan P. N. Exon Smith8af6cfc2015-02-04 22:08:30 +00001122#include "llvm/IR/Metadata.def"
1123
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001124/// \brief Map-like storage for metadata attachments.
1125class MDAttachmentMap {
1126 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1127
1128public:
1129 bool empty() const { return Attachments.empty(); }
1130 size_t size() const { return Attachments.size(); }
1131
1132 /// \brief Get a particular attachment (if any).
1133 MDNode *lookup(unsigned ID) const;
1134
1135 /// \brief Set an attachment to a particular node.
1136 ///
1137 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1138 /// ID (if anyway).
1139 void set(unsigned ID, MDNode &MD);
1140
1141 /// \brief Remove an attachment.
1142 ///
1143 /// Remove the attachment at \c ID, if any.
1144 void erase(unsigned ID);
1145
1146 /// \brief Copy out all the attachments.
1147 ///
1148 /// Copies all the current attachments into \c Result, sorting by attachment
1149 /// ID. This function does \em not clear \c Result.
1150 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1151
1152 /// \brief Erase matching attachments.
1153 ///
1154 /// Erases all attachments matching the \c shouldRemove predicate.
1155 template <class PredTy> void remove_if(PredTy shouldRemove) {
David Majnemer2d006e72016-08-12 04:32:42 +00001156 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1157 Attachments.end());
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001158 }
1159};
1160
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001161/// Multimap-like storage for metadata attachments for globals. This differs
1162/// from MDAttachmentMap in that it allows multiple attachments per metadata
1163/// kind.
1164class MDGlobalAttachmentMap {
1165 struct Attachment {
1166 unsigned MDKind;
1167 TrackingMDNodeRef Node;
1168 };
1169 SmallVector<Attachment, 1> Attachments;
1170
1171public:
1172 bool empty() const { return Attachments.empty(); }
1173
1174 /// Appends all attachments with the given ID to \c Result in insertion order.
1175 /// If the global has no attachments with the given ID, or if ID is invalid,
1176 /// leaves Result unchanged.
1177 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1178
1179 void insert(unsigned ID, MDNode &MD);
1180 void erase(unsigned ID);
1181
1182 /// Appends all attachments for the global to \c Result, sorting by attachment
1183 /// ID. Attachments with the same ID appear in insertion order. This function
1184 /// does \em not clear \c Result.
1185 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1186};
1187
Benjamin Kramer079b96e2013-09-11 18:05:11 +00001188class LLVMContextImpl {
Benjamin Kramer78c3bcb2009-08-11 17:45:13 +00001189public:
Owen Anderson8e89e412010-09-08 18:03:32 +00001190 /// OwnedModules - The set of modules instantiated in this context, and which
1191 /// will be automatically deleted if this context is deleted.
1192 SmallPtrSet<Module*, 4> OwnedModules;
1193
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001194 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1195 void *InlineAsmDiagContext = nullptr;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001196
Vivek Pandyab5ab8952017-09-15 20:10:09 +00001197 std::unique_ptr<DiagnosticHandler> DiagHandler;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001198 bool RespectDiagnosticFilters = false;
Brian Gesiak44e5f6c2017-06-30 18:13:59 +00001199 bool DiagnosticsHotnessRequested = false;
Brian Gesiak4ef3daa2017-06-30 23:14:53 +00001200 uint64_t DiagnosticsHotnessThreshold = 0;
Adam Nemeta62b7e12016-09-27 20:55:07 +00001201 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
Quentin Colombetb4c44d22013-12-17 17:47:22 +00001202
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001203 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1204 void *YieldOpaqueHandle = nullptr;
Juergen Ributzka34390c72014-05-16 02:33:15 +00001205
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001206 using IntMapTy =
1207 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
Owen Anderson20b34ac2009-07-16 18:04:31 +00001208 IntMapTy IntConstants;
NAKAMURA Takumifc3062f2014-12-06 05:57:06 +00001209
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001210 using FPMapTy =
1211 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
Owen Andersonc277dc42009-07-16 19:05:41 +00001212 FPMapTy FPConstants;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001213
Bill Wendling4607f4b2012-12-20 01:36:59 +00001214 FoldingSet<AttributeImpl> AttrsSet;
Reid Klecknerb5180542017-03-21 16:57:19 +00001215 FoldingSet<AttributeListImpl> AttrsLists;
Bill Wendlingd2e493b2013-01-24 00:06:56 +00001216 FoldingSet<AttributeSetNode> AttrsSetNodes;
Bill Wendlingf86efb92012-11-20 05:09:20 +00001217
Duncan P. N. Exon Smith3e0430e2016-04-06 06:41:54 +00001218 StringMap<MDString, BumpPtrAllocator> MDStringCache;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001219 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1220 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
Bill Wendlinge38b8042012-09-26 21:07:29 +00001221
Owen Anderson7349ab92015-06-01 22:24:01 +00001222 DenseMap<const Value*, ValueName*> ValueNames;
1223
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +00001224#define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1225 DenseSet<CLASS *, CLASS##Info> CLASS##s;
Duncan P. N. Exon Smith104e4022015-02-04 21:46:12 +00001226#include "llvm/IR/Metadata.def"
Bill Wendlinge38b8042012-09-26 21:07:29 +00001227
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001228 // Optional map for looking up composite types by identifier.
Duncan P. N. Exon Smithe8b555c2016-04-19 16:06:50 +00001229 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
Duncan P. N. Exon Smith5ab2be02016-04-17 03:58:21 +00001230
Jeffrey Yasskin2cc24762010-03-13 01:26:15 +00001231 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1232 // aren't in the MDNodeSet, but they're still shared between objects, so no
Duncan P. N. Exon Smith3eef9d12016-04-19 23:59:13 +00001233 // one object can destroy them. Keep track of them here so we can delete
1234 // them on context teardown.
1235 std::vector<MDNode *> DistinctMDNodes;
Duncan P. N. Exon Smith50846f82014-11-18 00:37:17 +00001236
Justin Lebar611c5c22016-10-10 16:26:13 +00001237 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
Owen Anderson13234f82009-08-10 18:16:08 +00001238
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001239 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001240 ArrayConstantsTy ArrayConstants;
Owen Anderson39ede7b2009-07-21 20:13:12 +00001241
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001242 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001243 StructConstantsTy StructConstants;
Owen Anderson909f6002009-07-23 23:25:33 +00001244
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001245 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
Owen Andersonedb4a702009-07-24 23:12:02 +00001246 VectorConstantsTy VectorConstants;
Chris Lattnerc7f9fd42012-01-23 15:20:12 +00001247
Justin Lebar611c5c22016-10-10 16:26:13 +00001248 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1249
1250 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1251
Chris Lattner3756b912012-01-23 22:57:10 +00001252 StringMap<ConstantDataSequential*> CDSConstants;
1253
Chandler Carruth6a936922014-01-19 02:13:50 +00001254 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1255 BlockAddresses;
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001256 ConstantUniqueMap<ConstantExpr> ExprConstants;
Jeffrey Yasskinade270e2010-03-21 20:37:19 +00001257
Duncan P. N. Exon Smith317c1392014-08-19 16:39:58 +00001258 ConstantUniqueMap<InlineAsm> InlineAsms;
1259
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001260 ConstantInt *TheTrueVal = nullptr;
1261 ConstantInt *TheFalseVal = nullptr;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001262
David Majnemer2dd41c52015-11-16 20:55:57 +00001263 std::unique_ptr<ConstantTokenNone> TheNoneToken;
David Majnemerf0f224d2015-11-11 21:57:16 +00001264
Dan Gohman97d2cb82009-08-25 16:00:35 +00001265 // Basic type instances.
David Majnemerb611e3f2015-08-14 05:09:07 +00001266 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001267 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
Kit Barton72918022015-04-17 15:32:15 +00001268 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
Chris Lattner07bd69c2011-07-15 05:49:15 +00001269
1270 /// TypeAllocator - All dynamically allocated types are allocated from this.
1271 /// They live forever until the context is torn down.
1272 BumpPtrAllocator TypeAllocator;
1273
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001274 DenseMap<unsigned, IntegerType*> IntegerTypes;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001275
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001276 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001277 FunctionTypeSet FunctionTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001278 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
Benjamin Kramer3280a5d2014-12-06 19:22:54 +00001279 StructTypeSet AnonStructTypes;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001280 StringMap<StructType*> NamedStructTypes;
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001281 unsigned NamedStructTypesUniqueID = 0;
Chris Lattnerb1ed91f2011-07-09 17:41:24 +00001282
1283 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1284 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1285 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1286 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
Jeffrey Yasskinc660b232010-02-11 06:41:30 +00001287
Owen Andersone8f21852009-08-18 18:28:58 +00001288 /// ValueHandles - This map keeps track of all of the value handles that are
1289 /// watching a Value*. The Value::HasValueHandle bit is used to know
Michael Ilseman516d7032013-03-01 18:48:54 +00001290 /// whether or not a value has an entry in this map.
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001291 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
Owen Andersone8f21852009-08-18 18:28:58 +00001292 ValueHandlesTy ValueHandles;
1293
Chris Lattnera0566972009-12-29 09:01:33 +00001294 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1295 StringMap<unsigned> CustomMDKindNames;
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +00001296
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001297 /// Collection of per-instruction metadata used in this context.
Duncan P. N. Exon Smithcbc28dc2015-04-24 20:36:25 +00001298 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
Duncan P. N. Exon Smith391fc562015-04-24 20:16:42 +00001299
Peter Collingbournecceae7f2016-05-31 23:01:54 +00001300 /// Collection of per-GlobalObject metadata used in this context.
Peter Collingbourne382d81c2016-06-01 01:17:57 +00001301 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
Duncan P. N. Exon Smithe2510cd2015-04-24 21:51:02 +00001302
Reid Kleckner443423e2017-01-10 23:23:58 +00001303 /// Collection of per-GlobalObject sections used in this context.
1304 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1305
1306 /// Stable collection of section strings.
1307 StringSet<> SectionStrings;
1308
Diego Novillof5041ce2014-03-03 20:06:11 +00001309 /// DiscriminatorTable - This table maps file:line locations to an
1310 /// integer representing the next DWARF path discriminator to assign to
1311 /// instructions in different blocks at the same location.
1312 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1313
Chris Lattner8cb2aeb2010-04-01 00:37:44 +00001314 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1315 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
Philip Reames2b453952015-01-16 20:07:33 +00001316
Sanjoy Das9303c242015-09-24 19:14:18 +00001317 /// \brief A set of interned tags for operand bundles. The StringMap maps
1318 /// bundle tags to their IDs.
1319 ///
1320 /// \see LLVMContext::getOperandBundleTagID
1321 StringMap<uint32_t> BundleTagCache;
1322
1323 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1324 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1325 uint32_t getOperandBundleTagID(StringRef Tag) const;
1326
Konstantin Zhuravlyovbb80d3e2017-07-11 22:23:00 +00001327 /// A set of interned synchronization scopes. The StringMap maps
1328 /// synchronization scope names to their respective synchronization scope IDs.
1329 StringMap<SyncScope::ID> SSC;
1330
1331 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1332 /// synchronization scope ID. Every synchronization scope registered with
1333 /// LLVMContext has unique ID except pre-defined ones.
1334 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1335
1336 /// getSyncScopeNames - Populates client supplied SmallVector with
1337 /// synchronization scope names registered with LLVMContext. Synchronization
1338 /// scope names are ordered by increasing synchronization scope IDs.
1339 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1340
Mehdi Amini599ebf22016-01-08 02:28:20 +00001341 /// Maintain the GC name for each function.
1342 ///
1343 /// This saves allocating an additional word in Function for programs which
1344 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1345 /// clients which do use GC.
1346 DenseMap<const Function*, std::string> GCNames;
1347
Mehdi Amini09b4a8d2016-03-10 01:28:54 +00001348 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1349 /// not.
1350 bool DiscardValueNames = false;
1351
Jeffrey Yasskin4cfb3a72010-03-21 21:17:34 +00001352 LLVMContextImpl(LLVMContext &C);
1353 ~LLVMContextImpl();
Manman Rendab999d2015-01-20 19:24:59 +00001354
1355 /// Destroy the ConstantArrays if they are not used.
1356 void dropTriviallyDeadConstantArrays();
Andrew Kayloraa641a52016-04-22 22:06:11 +00001357
Fedor Sergeevd29884c2018-04-05 10:29:37 +00001358 mutable OptPassGate *OPG = nullptr;
1359
1360 /// \brief Access the object which can disable optional passes and individual
1361 /// optimizations at compile time.
1362 OptPassGate &getOptPassGate() const;
1363
1364 /// \brief Set the object which can disable optional passes and individual
1365 /// optimizations at compile time.
1366 ///
1367 /// The lifetime of the object must be guaranteed to extend as long as the
1368 /// LLVMContext is used by compilation.
1369 void setOptPassGate(OptPassGate&);
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001370};
1371
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001372} // end namespace llvm
Owen Anderson8e66e0b2009-06-30 00:48:55 +00001373
Eugene Zelenkode6cce22017-06-19 22:05:08 +00001374#endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H