Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1 | //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 8 | // |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 9 | // This file declares LLVMContextImpl, the opaque implementation |
Owen Anderson | 36f62e5 | 2009-06-30 17:06:46 +0000 | [diff] [blame] | 10 | // of LLVMContext. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 13 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H |
| 15 | #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 16 | |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 17 | #include "AttributeImpl.h" |
Owen Anderson | afd0c4c | 2009-08-04 22:41:48 +0000 | [diff] [blame] | 18 | #include "ConstantsContext.h" |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/APFloat.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/APInt.h" |
Jay Foad | c365eea | 2011-06-22 08:50:06 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/ArrayRef.h" |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/DenseMap.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/DenseMapInfo.h" |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/DenseSet.h" |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/FoldingSet.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/Optional.h" |
| 28 | #include "llvm/ADT/STLExtras.h" |
Jeffrey Yasskin | 28f2448 | 2009-12-17 19:55:06 +0000 | [diff] [blame] | 29 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/SmallVector.h" |
Owen Anderson | 69ab416 | 2009-07-16 22:11:26 +0000 | [diff] [blame] | 31 | #include "llvm/ADT/StringMap.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 32 | #include "llvm/ADT/StringRef.h" |
Reid Kleckner | 443423e | 2017-01-10 23:23:58 +0000 | [diff] [blame] | 33 | #include "llvm/ADT/StringSet.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 34 | #include "llvm/BinaryFormat/Dwarf.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 35 | #include "llvm/IR/Constants.h" |
Duncan P. N. Exon Smith | d9901ff | 2015-02-02 18:53:21 +0000 | [diff] [blame] | 36 | #include "llvm/IR/DebugInfoMetadata.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 37 | #include "llvm/IR/DerivedTypes.h" |
| 38 | #include "llvm/IR/LLVMContext.h" |
| 39 | #include "llvm/IR/Metadata.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 40 | #include "llvm/IR/TrackingMDRef.h" |
| 41 | #include "llvm/Support/Allocator.h" |
| 42 | #include "llvm/Support/Casting.h" |
Adam Nemet | a62b7e1 | 2016-09-27 20:55:07 +0000 | [diff] [blame] | 43 | #include "llvm/Support/YAMLTraits.h" |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 44 | #include <algorithm> |
| 45 | #include <cassert> |
| 46 | #include <cstddef> |
| 47 | #include <cstdint> |
| 48 | #include <memory> |
| 49 | #include <string> |
| 50 | #include <utility> |
Duncan P. N. Exon Smith | 3eef9d1 | 2016-04-19 23:59:13 +0000 | [diff] [blame] | 51 | #include <vector> |
Owen Anderson | 39ede7b | 2009-07-21 20:13:12 +0000 | [diff] [blame] | 52 | |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 53 | namespace llvm { |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 54 | |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 55 | class ConstantFP; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 56 | class ConstantInt; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 57 | class Type; |
Owen Anderson | 4118dde | 2009-07-16 23:44:30 +0000 | [diff] [blame] | 58 | class Value; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 59 | class ValueHandleBase; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 60 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 61 | struct DenseMapAPIntKeyInfo { |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 62 | static inline APInt getEmptyKey() { |
| 63 | APInt V(nullptr, 0); |
Craig Topper | b339c6d | 2017-05-03 15:46:24 +0000 | [diff] [blame] | 64 | V.U.VAL = 0; |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 65 | return V; |
| 66 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 67 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 68 | static inline APInt getTombstoneKey() { |
| 69 | APInt V(nullptr, 0); |
Craig Topper | b339c6d | 2017-05-03 15:46:24 +0000 | [diff] [blame] | 70 | V.U.VAL = 1; |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 71 | return V; |
| 72 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 73 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 74 | static unsigned getHashValue(const APInt &Key) { |
Chandler Carruth | 71bd7d1 | 2012-03-04 12:02:57 +0000 | [diff] [blame] | 75 | return static_cast<unsigned>(hash_value(Key)); |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 76 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 77 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 78 | static bool isEqual(const APInt &LHS, const APInt &RHS) { |
| 79 | return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS; |
| 80 | } |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 83 | struct DenseMapAPFloatKeyInfo { |
Stephan Bergmann | 17c7f70 | 2016-12-14 11:57:17 +0000 | [diff] [blame] | 84 | static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); } |
| 85 | static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 86 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 87 | static unsigned getHashValue(const APFloat &Key) { |
Chandler Carruth | 71bd7d1 | 2012-03-04 12:02:57 +0000 | [diff] [blame] | 88 | return static_cast<unsigned>(hash_value(Key)); |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 89 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 90 | |
Benjamin Kramer | 8e5dc53 | 2014-12-06 13:12:56 +0000 | [diff] [blame] | 91 | static bool isEqual(const APFloat &LHS, const APFloat &RHS) { |
| 92 | return LHS.bitwiseIsEqual(RHS); |
| 93 | } |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 94 | }; |
| 95 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 96 | struct AnonStructTypeKeyInfo { |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 97 | struct KeyTy { |
| 98 | ArrayRef<Type*> ETypes; |
| 99 | bool isPacked; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 100 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 101 | KeyTy(const ArrayRef<Type*>& E, bool P) : |
| 102 | ETypes(E), isPacked(P) {} |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 103 | |
Rafael Espindola | 334b73f | 2014-11-21 18:53:05 +0000 | [diff] [blame] | 104 | KeyTy(const StructType *ST) |
| 105 | : ETypes(ST->elements()), isPacked(ST->isPacked()) {} |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 106 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 107 | bool operator==(const KeyTy& that) const { |
| 108 | if (isPacked != that.isPacked) |
| 109 | return false; |
| 110 | if (ETypes != that.ETypes) |
| 111 | return false; |
| 112 | return true; |
| 113 | } |
| 114 | bool operator!=(const KeyTy& that) const { |
| 115 | return !this->operator==(that); |
| 116 | } |
| 117 | }; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 118 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 119 | static inline StructType* getEmptyKey() { |
| 120 | return DenseMapInfo<StructType*>::getEmptyKey(); |
| 121 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 122 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 123 | static inline StructType* getTombstoneKey() { |
| 124 | return DenseMapInfo<StructType*>::getTombstoneKey(); |
| 125 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 126 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 127 | static unsigned getHashValue(const KeyTy& Key) { |
Chandler Carruth | 1d03a3b | 2012-03-01 18:55:25 +0000 | [diff] [blame] | 128 | return hash_combine(hash_combine_range(Key.ETypes.begin(), |
| 129 | Key.ETypes.end()), |
| 130 | Key.isPacked); |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 131 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 132 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 133 | static unsigned getHashValue(const StructType *ST) { |
| 134 | return getHashValue(KeyTy(ST)); |
| 135 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 136 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 137 | static bool isEqual(const KeyTy& LHS, const StructType *RHS) { |
| 138 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 139 | return false; |
| 140 | return LHS == KeyTy(RHS); |
| 141 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 142 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 143 | static bool isEqual(const StructType *LHS, const StructType *RHS) { |
| 144 | return LHS == RHS; |
| 145 | } |
| 146 | }; |
| 147 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 148 | struct FunctionTypeKeyInfo { |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 149 | struct KeyTy { |
| 150 | const Type *ReturnType; |
| 151 | ArrayRef<Type*> Params; |
| 152 | bool isVarArg; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 153 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 154 | KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) : |
| 155 | ReturnType(R), Params(P), isVarArg(V) {} |
Rafael Espindola | e973fd4 | 2014-11-21 19:03:35 +0000 | [diff] [blame] | 156 | KeyTy(const FunctionType *FT) |
| 157 | : ReturnType(FT->getReturnType()), Params(FT->params()), |
| 158 | isVarArg(FT->isVarArg()) {} |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 159 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 160 | bool operator==(const KeyTy& that) const { |
| 161 | if (ReturnType != that.ReturnType) |
| 162 | return false; |
| 163 | if (isVarArg != that.isVarArg) |
| 164 | return false; |
| 165 | if (Params != that.Params) |
| 166 | return false; |
| 167 | return true; |
| 168 | } |
| 169 | bool operator!=(const KeyTy& that) const { |
| 170 | return !this->operator==(that); |
| 171 | } |
| 172 | }; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 173 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 174 | static inline FunctionType* getEmptyKey() { |
| 175 | return DenseMapInfo<FunctionType*>::getEmptyKey(); |
| 176 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 177 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 178 | static inline FunctionType* getTombstoneKey() { |
| 179 | return DenseMapInfo<FunctionType*>::getTombstoneKey(); |
| 180 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 181 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 182 | static unsigned getHashValue(const KeyTy& Key) { |
Chandler Carruth | 1d03a3b | 2012-03-01 18:55:25 +0000 | [diff] [blame] | 183 | return hash_combine(Key.ReturnType, |
| 184 | hash_combine_range(Key.Params.begin(), |
| 185 | Key.Params.end()), |
| 186 | Key.isVarArg); |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 187 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 188 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 189 | static unsigned getHashValue(const FunctionType *FT) { |
| 190 | return getHashValue(KeyTy(FT)); |
| 191 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 192 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 193 | static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) { |
| 194 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 195 | return false; |
| 196 | return LHS == KeyTy(RHS); |
| 197 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 198 | |
Jay Foad | 529776c | 2012-02-23 09:17:40 +0000 | [diff] [blame] | 199 | static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { |
| 200 | return LHS == RHS; |
| 201 | } |
| 202 | }; |
| 203 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 204 | /// Structure for hashing arbitrary MDNode operands. |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 205 | class MDNodeOpsKey { |
| 206 | ArrayRef<Metadata *> RawOps; |
| 207 | ArrayRef<MDOperand> Ops; |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 208 | unsigned Hash; |
| 209 | |
| 210 | protected: |
| 211 | MDNodeOpsKey(ArrayRef<Metadata *> Ops) |
| 212 | : RawOps(Ops), Hash(calculateHash(Ops)) {} |
| 213 | |
| 214 | template <class NodeTy> |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 215 | MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 216 | : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {} |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 217 | |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 218 | template <class NodeTy> |
| 219 | bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const { |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 220 | if (getHash() != RHS->getHash()) |
| 221 | return false; |
| 222 | |
| 223 | assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?"); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 224 | return RawOps.empty() ? compareOps(Ops, RHS, Offset) |
| 225 | : compareOps(RawOps, RHS, Offset); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 228 | static unsigned calculateHash(MDNode *N, unsigned Offset = 0); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 229 | |
| 230 | private: |
| 231 | template <class T> |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 232 | static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) { |
| 233 | if (Ops.size() != RHS->getNumOperands() - Offset) |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 234 | return false; |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 235 | return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset); |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static unsigned calculateHash(ArrayRef<Metadata *> Ops); |
| 239 | |
| 240 | public: |
| 241 | unsigned getHash() const { return Hash; } |
| 242 | }; |
| 243 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 244 | template <class NodeTy> struct MDNodeKeyImpl; |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 245 | |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 246 | /// Configuration point for MDNodeInfo::isEqual(). |
| 247 | template <class NodeTy> struct MDNodeSubsetEqualImpl { |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 248 | using KeyTy = MDNodeKeyImpl<NodeTy>; |
| 249 | |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 250 | static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) { |
| 251 | return false; |
| 252 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 253 | |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 254 | static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) { |
| 255 | return false; |
| 256 | } |
| 257 | }; |
| 258 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 259 | /// DenseMapInfo for MDTuple. |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 260 | /// |
| 261 | /// Note that we don't need the is-function-local bit, since that's implicit in |
| 262 | /// the operands. |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 263 | template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey { |
| 264 | MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {} |
| 265 | MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} |
Duncan P. N. Exon Smith | f39c3b8 | 2014-11-17 23:28:21 +0000 | [diff] [blame] | 266 | |
Duncan P. N. Exon Smith | 9c26d80 | 2015-02-05 00:51:35 +0000 | [diff] [blame] | 267 | bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); } |
Duncan P. N. Exon Smith | 93e983e | 2015-01-19 22:53:18 +0000 | [diff] [blame] | 268 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 269 | unsigned getHashValue() const { return getHash(); } |
| 270 | |
| 271 | static unsigned calculateHash(MDTuple *N) { |
| 272 | return MDNodeOpsKey::calculateHash(N); |
Benjamin Kramer | 2335a5c | 2012-04-11 14:06:54 +0000 | [diff] [blame] | 273 | } |
| 274 | }; |
| 275 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 276 | /// DenseMapInfo for DILocation. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 277 | template <> struct MDNodeKeyImpl<DILocation> { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 278 | unsigned Line; |
| 279 | unsigned Column; |
| 280 | Metadata *Scope; |
| 281 | Metadata *InlinedAt; |
Calixte Denizet | eb7f602 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 282 | bool ImplicitCode; |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 283 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 284 | MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, |
Calixte Denizet | eb7f602 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 285 | Metadata *InlinedAt, bool ImplicitCode) |
| 286 | : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt), |
| 287 | ImplicitCode(ImplicitCode) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 288 | MDNodeKeyImpl(const DILocation *L) |
Duncan P. N. Exon Smith | 2648998 | 2015-03-26 22:05:04 +0000 | [diff] [blame] | 289 | : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), |
Calixte Denizet | eb7f602 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 290 | InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {} |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 291 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 292 | bool isKeyOf(const DILocation *RHS) const { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 293 | return Line == RHS->getLine() && Column == RHS->getColumn() && |
Calixte Denizet | eb7f602 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 294 | Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() && |
| 295 | ImplicitCode == RHS->isImplicitCode(); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 296 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 297 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 298 | unsigned getHashValue() const { |
Calixte Denizet | eb7f602 | 2018-09-20 08:53:06 +0000 | [diff] [blame] | 299 | return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode); |
Duncan P. N. Exon Smith | de03ff5 | 2015-01-13 20:44:56 +0000 | [diff] [blame] | 300 | } |
| 301 | }; |
| 302 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 303 | /// DenseMapInfo for GenericDINode. |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 304 | template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 305 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 306 | MDString *Header; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 307 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 308 | MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 309 | : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 310 | MDNodeKeyImpl(const GenericDINode *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 311 | : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {} |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 312 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 313 | bool isKeyOf(const GenericDINode *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 314 | return Tag == RHS->getTag() && Header == RHS->getRawHeader() && |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 315 | compareOps(RHS, 1); |
| 316 | } |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 317 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 318 | unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); } |
| 319 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 320 | static unsigned calculateHash(GenericDINode *N) { |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 321 | return MDNodeOpsKey::calculateHash(N, 1); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 322 | } |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 325 | template <> struct MDNodeKeyImpl<DISubrange> { |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 326 | Metadata *CountNode; |
Duncan P. N. Exon Smith | 5dcf621 | 2015-04-07 00:39:59 +0000 | [diff] [blame] | 327 | int64_t LowerBound; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 328 | |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 329 | MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound) |
| 330 | : CountNode(CountNode), LowerBound(LowerBound) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 331 | MDNodeKeyImpl(const DISubrange *N) |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 332 | : CountNode(N->getRawCountNode()), |
| 333 | LowerBound(N->getLowerBound()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 334 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 335 | bool isKeyOf(const DISubrange *RHS) const { |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 336 | if (LowerBound != RHS->getLowerBound()) |
| 337 | return false; |
| 338 | |
| 339 | if (auto *RHSCount = RHS->getCount().dyn_cast<ConstantInt*>()) |
| 340 | if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode)) |
| 341 | if (RHSCount->getSExtValue() == |
| 342 | cast<ConstantInt>(MD->getValue())->getSExtValue()) |
| 343 | return true; |
| 344 | |
| 345 | return CountNode == RHS->getRawCountNode(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 346 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 347 | |
Sander de Smalen | fdf4091 | 2018-01-24 09:56:07 +0000 | [diff] [blame] | 348 | unsigned getHashValue() const { |
| 349 | if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode)) |
| 350 | return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(), |
| 351 | LowerBound); |
| 352 | return hash_combine(CountNode, LowerBound); |
| 353 | } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 356 | template <> struct MDNodeKeyImpl<DIEnumerator> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 357 | int64_t Value; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 358 | MDString *Name; |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 359 | bool IsUnsigned; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 360 | |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 361 | MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name) |
| 362 | : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 363 | MDNodeKeyImpl(const DIEnumerator *N) |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 364 | : Value(N->getValue()), Name(N->getRawName()), |
| 365 | IsUnsigned(N->isUnsigned()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 366 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 367 | bool isKeyOf(const DIEnumerator *RHS) const { |
Momchil Velikov | 08dc66e | 2018-02-12 16:10:09 +0000 | [diff] [blame] | 368 | return Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() && |
| 369 | Name == RHS->getRawName(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 370 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 371 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 372 | unsigned getHashValue() const { return hash_combine(Value, Name); } |
| 373 | }; |
| 374 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 375 | template <> struct MDNodeKeyImpl<DIBasicType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 376 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 377 | MDString *Name; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 378 | uint64_t SizeInBits; |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 379 | uint32_t AlignInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 380 | unsigned Encoding; |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 381 | unsigned Flags; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 382 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 383 | MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 384 | uint32_t AlignInBits, unsigned Encoding, unsigned Flags) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 385 | : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 386 | Encoding(Encoding), Flags(Flags) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 387 | MDNodeKeyImpl(const DIBasicType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 388 | : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 389 | AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 390 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 391 | bool isKeyOf(const DIBasicType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 392 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 393 | SizeInBits == RHS->getSizeInBits() && |
| 394 | AlignInBits == RHS->getAlignInBits() && |
Adrian Prantl | 55f4262 | 2018-08-14 19:35:34 +0000 | [diff] [blame] | 395 | Encoding == RHS->getEncoding() && |
| 396 | Flags == RHS->getFlags(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 397 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 398 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 399 | unsigned getHashValue() const { |
| 400 | return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding); |
| 401 | } |
| 402 | }; |
| 403 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 404 | template <> struct MDNodeKeyImpl<DIDerivedType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 405 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 406 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 407 | Metadata *File; |
| 408 | unsigned Line; |
| 409 | Metadata *Scope; |
| 410 | Metadata *BaseType; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 411 | uint64_t SizeInBits; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 412 | uint64_t OffsetInBits; |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 413 | uint32_t AlignInBits; |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 414 | Optional<unsigned> DWARFAddressSpace; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 415 | unsigned Flags; |
| 416 | Metadata *ExtraData; |
| 417 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 418 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 419 | Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 420 | uint32_t AlignInBits, uint64_t OffsetInBits, |
| 421 | Optional<unsigned> DWARFAddressSpace, unsigned Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 422 | Metadata *ExtraData) |
| 423 | : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 424 | BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 425 | AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace), |
| 426 | Flags(Flags), ExtraData(ExtraData) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 427 | MDNodeKeyImpl(const DIDerivedType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 428 | : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 429 | Line(N->getLine()), Scope(N->getRawScope()), |
| 430 | BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 431 | OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()), |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 432 | DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()), |
| 433 | ExtraData(N->getRawExtraData()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 434 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 435 | bool isKeyOf(const DIDerivedType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 436 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 437 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 438 | Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 439 | SizeInBits == RHS->getSizeInBits() && |
| 440 | AlignInBits == RHS->getAlignInBits() && |
Konstantin Zhuravlyov | d5561e0 | 2017-03-08 23:55:44 +0000 | [diff] [blame] | 441 | OffsetInBits == RHS->getOffsetInBits() && |
| 442 | DWARFAddressSpace == RHS->getDWARFAddressSpace() && |
| 443 | Flags == RHS->getFlags() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 444 | ExtraData == RHS->getRawExtraData(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 445 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 446 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 447 | unsigned getHashValue() const { |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 448 | // If this is a member inside an ODR type, only hash the type and the name. |
| 449 | // Otherwise the hash will be stronger than |
| 450 | // MDNodeSubsetEqualImpl::isODRMember(). |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 451 | if (Tag == dwarf::DW_TAG_member && Name) |
| 452 | if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope)) |
| 453 | if (CT->getRawIdentifier()) |
| 454 | return hash_combine(Name, Scope); |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 455 | |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 456 | // Intentionally computes the hash on a subset of the operands for |
| 457 | // performance reason. The subset has to be significant enough to avoid |
| 458 | // collision "most of the time". There is no correctness issue in case of |
| 459 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 460 | return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 461 | } |
| 462 | }; |
| 463 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 464 | template <> struct MDNodeSubsetEqualImpl<DIDerivedType> { |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 465 | using KeyTy = MDNodeKeyImpl<DIDerivedType>; |
| 466 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 467 | static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) { |
| 468 | return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS); |
| 469 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 470 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 471 | static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) { |
| 472 | return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(), |
| 473 | RHS); |
| 474 | } |
| 475 | |
| 476 | /// Subprograms compare equal if they declare the same function in an ODR |
| 477 | /// type. |
| 478 | static bool isODRMember(unsigned Tag, const Metadata *Scope, |
| 479 | const MDString *Name, const DIDerivedType *RHS) { |
| 480 | // Check whether the LHS is eligible. |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 481 | if (Tag != dwarf::DW_TAG_member || !Name) |
| 482 | return false; |
| 483 | |
| 484 | auto *CT = dyn_cast_or_null<DICompositeType>(Scope); |
| 485 | if (!CT || !CT->getRawIdentifier()) |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 486 | return false; |
| 487 | |
| 488 | // Compare to the RHS. |
| 489 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
| 490 | Scope == RHS->getRawScope(); |
| 491 | } |
| 492 | }; |
| 493 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 494 | template <> struct MDNodeKeyImpl<DICompositeType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 495 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 496 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 497 | Metadata *File; |
| 498 | unsigned Line; |
| 499 | Metadata *Scope; |
| 500 | Metadata *BaseType; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 501 | uint64_t SizeInBits; |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 502 | uint64_t OffsetInBits; |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 503 | uint32_t AlignInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 504 | unsigned Flags; |
| 505 | Metadata *Elements; |
| 506 | unsigned RuntimeLang; |
| 507 | Metadata *VTableHolder; |
| 508 | Metadata *TemplateParams; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 509 | MDString *Identifier; |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 510 | Metadata *Discriminator; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 511 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 512 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, |
Duncan P. N. Exon Smith | d34db17 | 2015-02-19 23:56:07 +0000 | [diff] [blame] | 513 | Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 514 | uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 515 | Metadata *Elements, unsigned RuntimeLang, |
| 516 | Metadata *VTableHolder, Metadata *TemplateParams, |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 517 | MDString *Identifier, Metadata *Discriminator) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 518 | : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope), |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 519 | BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), |
| 520 | AlignInBits(AlignInBits), Flags(Flags), Elements(Elements), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 521 | RuntimeLang(RuntimeLang), VTableHolder(VTableHolder), |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 522 | TemplateParams(TemplateParams), Identifier(Identifier), |
| 523 | Discriminator(Discriminator) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 524 | MDNodeKeyImpl(const DICompositeType *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 525 | : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 526 | Line(N->getLine()), Scope(N->getRawScope()), |
| 527 | BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), |
Victor Leschuk | 197aa31 | 2016-10-18 14:31:22 +0000 | [diff] [blame] | 528 | OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()), |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 529 | Flags(N->getFlags()), Elements(N->getRawElements()), |
| 530 | RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()), |
| 531 | TemplateParams(N->getRawTemplateParams()), |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 532 | Identifier(N->getRawIdentifier()), |
| 533 | Discriminator(N->getRawDiscriminator()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 534 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 535 | bool isKeyOf(const DICompositeType *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 536 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 537 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 538 | Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 539 | SizeInBits == RHS->getSizeInBits() && |
| 540 | AlignInBits == RHS->getAlignInBits() && |
| 541 | OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 542 | Elements == RHS->getRawElements() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 543 | RuntimeLang == RHS->getRuntimeLang() && |
Duncan P. N. Exon Smith | 53855f0 | 2015-03-27 23:05:04 +0000 | [diff] [blame] | 544 | VTableHolder == RHS->getRawVTableHolder() && |
| 545 | TemplateParams == RHS->getRawTemplateParams() && |
Adrian Prantl | 8c59921 | 2018-02-06 23:45:59 +0000 | [diff] [blame] | 546 | Identifier == RHS->getRawIdentifier() && |
| 547 | Discriminator == RHS->getRawDiscriminator(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 548 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 549 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 550 | unsigned getHashValue() const { |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 551 | // Intentionally computes the hash on a subset of the operands for |
| 552 | // performance reason. The subset has to be significant enough to avoid |
| 553 | // collision "most of the time". There is no correctness issue in case of |
| 554 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 555 | return hash_combine(Name, File, Line, BaseType, Scope, Elements, |
| 556 | TemplateParams); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 557 | } |
| 558 | }; |
| 559 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 560 | template <> struct MDNodeKeyImpl<DISubroutineType> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 561 | unsigned Flags; |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 562 | uint8_t CC; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 563 | Metadata *TypeArray; |
| 564 | |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 565 | MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray) |
| 566 | : Flags(Flags), CC(CC), TypeArray(TypeArray) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 567 | MDNodeKeyImpl(const DISubroutineType *N) |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 568 | : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 569 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 570 | bool isKeyOf(const DISubroutineType *RHS) const { |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 571 | return Flags == RHS->getFlags() && CC == RHS->getCC() && |
| 572 | TypeArray == RHS->getRawTypeArray(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 573 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 574 | |
Reid Kleckner | de3d8b5 | 2016-06-08 20:34:29 +0000 | [diff] [blame] | 575 | unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 576 | }; |
| 577 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 578 | template <> struct MDNodeKeyImpl<DIFile> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 579 | MDString *Filename; |
| 580 | MDString *Directory; |
Scott Linder | 7160384 | 2018-02-12 19:45:54 +0000 | [diff] [blame] | 581 | Optional<DIFile::ChecksumInfo<MDString *>> Checksum; |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 582 | Optional<MDString *> Source; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 583 | |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 584 | MDNodeKeyImpl(MDString *Filename, MDString *Directory, |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 585 | Optional<DIFile::ChecksumInfo<MDString *>> Checksum, |
| 586 | Optional<MDString *> Source) |
| 587 | : Filename(Filename), Directory(Directory), Checksum(Checksum), |
| 588 | Source(Source) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 589 | MDNodeKeyImpl(const DIFile *N) |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 590 | : Filename(N->getRawFilename()), Directory(N->getRawDirectory()), |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 591 | Checksum(N->getRawChecksum()), Source(N->getRawSource()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 592 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 593 | bool isKeyOf(const DIFile *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 594 | return Filename == RHS->getRawFilename() && |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 595 | Directory == RHS->getRawDirectory() && |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 596 | Checksum == RHS->getRawChecksum() && |
| 597 | Source == RHS->getRawSource(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 598 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 599 | |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 600 | unsigned getHashValue() const { |
Scott Linder | 16c7bda | 2018-02-23 23:01:06 +0000 | [diff] [blame] | 601 | return hash_combine( |
| 602 | Filename, Directory, Checksum ? Checksum->Kind : 0, |
| 603 | Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr)); |
Amjad Aboud | 7faeecc | 2016-12-25 10:12:09 +0000 | [diff] [blame] | 604 | } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 605 | }; |
| 606 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 607 | template <> struct MDNodeKeyImpl<DISubprogram> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 608 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 609 | MDString *Name; |
| 610 | MDString *LinkageName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 611 | Metadata *File; |
| 612 | unsigned Line; |
| 613 | Metadata *Type; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 614 | unsigned ScopeLine; |
| 615 | Metadata *ContainingType; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 616 | unsigned VirtualIndex; |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 617 | int ThisAdjustment; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 618 | unsigned Flags; |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 619 | unsigned SPFlags; |
Adrian Prantl | 75819ae | 2016-04-15 15:57:41 +0000 | [diff] [blame] | 620 | Metadata *Unit; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 621 | Metadata *TemplateParams; |
| 622 | Metadata *Declaration; |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 623 | Metadata *RetainedNodes; |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 624 | Metadata *ThrownTypes; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 625 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 626 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 627 | Metadata *File, unsigned Line, Metadata *Type, |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 628 | unsigned ScopeLine, Metadata *ContainingType, |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 629 | unsigned VirtualIndex, int ThisAdjustment, unsigned Flags, |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 630 | unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams, |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 631 | Metadata *Declaration, Metadata *RetainedNodes, |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 632 | Metadata *ThrownTypes) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 633 | : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 634 | Line(Line), Type(Type), ScopeLine(ScopeLine), |
| 635 | ContainingType(ContainingType), VirtualIndex(VirtualIndex), |
| 636 | ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags), |
| 637 | Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration), |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 638 | RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 639 | MDNodeKeyImpl(const DISubprogram *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 640 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 641 | LinkageName(N->getRawLinkageName()), File(N->getRawFile()), |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 642 | Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()), |
| 643 | ContainingType(N->getRawContainingType()), |
| 644 | VirtualIndex(N->getVirtualIndex()), |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 645 | ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()), |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 646 | SPFlags(N->getSPFlags()), Unit(N->getRawUnit()), |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 647 | TemplateParams(N->getRawTemplateParams()), |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 648 | Declaration(N->getRawDeclaration()), |
| 649 | RetainedNodes(N->getRawRetainedNodes()), |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 650 | ThrownTypes(N->getRawThrownTypes()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 651 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 652 | bool isKeyOf(const DISubprogram *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 653 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 654 | LinkageName == RHS->getRawLinkageName() && |
| 655 | File == RHS->getRawFile() && Line == RHS->getLine() && |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 656 | Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() && |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 657 | ContainingType == RHS->getRawContainingType() && |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 658 | VirtualIndex == RHS->getVirtualIndex() && |
| 659 | ThisAdjustment == RHS->getThisAdjustment() && |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 660 | Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() && |
Reid Kleckner | b5af11d | 2016-07-01 02:41:21 +0000 | [diff] [blame] | 661 | Unit == RHS->getUnit() && |
Duncan P. N. Exon Smith | 869db50 | 2015-03-30 16:19:15 +0000 | [diff] [blame] | 662 | TemplateParams == RHS->getRawTemplateParams() && |
| 663 | Declaration == RHS->getRawDeclaration() && |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 664 | RetainedNodes == RHS->getRawRetainedNodes() && |
Adrian Prantl | 1d12b88 | 2017-04-26 22:56:44 +0000 | [diff] [blame] | 665 | ThrownTypes == RHS->getRawThrownTypes(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 666 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 667 | |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 668 | bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; } |
| 669 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 670 | unsigned getHashValue() const { |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 671 | // If this is a declaration inside an ODR type, only hash the type and the |
| 672 | // name. Otherwise the hash will be stronger than |
| 673 | // MDNodeSubsetEqualImpl::isDeclarationOfODRMember(). |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 674 | if (!isDefinition() && LinkageName) |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 675 | if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope)) |
| 676 | if (CT->getRawIdentifier()) |
| 677 | return hash_combine(LinkageName, Scope); |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 678 | |
Mehdi Amini | 9bc362a | 2016-03-19 01:06:24 +0000 | [diff] [blame] | 679 | // Intentionally computes the hash on a subset of the operands for |
| 680 | // performance reason. The subset has to be significant enough to avoid |
| 681 | // collision "most of the time". There is no correctness issue in case of |
| 682 | // collision because of the full check above. |
Mehdi Amini | 53fc389 | 2016-03-19 00:59:26 +0000 | [diff] [blame] | 683 | return hash_combine(Name, Scope, File, Type, Line); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 684 | } |
| 685 | }; |
| 686 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 687 | template <> struct MDNodeSubsetEqualImpl<DISubprogram> { |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 688 | using KeyTy = MDNodeKeyImpl<DISubprogram>; |
| 689 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 690 | static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { |
Paul Robinson | cda5421 | 2018-11-19 18:29:28 +0000 | [diff] [blame] | 691 | return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope, |
Peter Collingbourne | e69e73c | 2017-02-06 21:23:03 +0000 | [diff] [blame] | 692 | LHS.LinkageName, LHS.TemplateParams, RHS); |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 693 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 694 | |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 695 | static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { |
| 696 | return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), |
Peter Collingbourne | e69e73c | 2017-02-06 21:23:03 +0000 | [diff] [blame] | 697 | LHS->getRawLinkageName(), |
| 698 | LHS->getRawTemplateParams(), RHS); |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | /// Subprograms compare equal if they declare the same function in an ODR |
| 702 | /// type. |
| 703 | static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope, |
| 704 | const MDString *LinkageName, |
Peter Collingbourne | e69e73c | 2017-02-06 21:23:03 +0000 | [diff] [blame] | 705 | const Metadata *TemplateParams, |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 706 | const DISubprogram *RHS) { |
| 707 | // Check whether the LHS is eligible. |
Duncan P. N. Exon Smith | a59d3e5 | 2016-04-23 21:08:00 +0000 | [diff] [blame] | 708 | if (IsDefinition || !Scope || !LinkageName) |
| 709 | return false; |
| 710 | |
| 711 | auto *CT = dyn_cast_or_null<DICompositeType>(Scope); |
| 712 | if (!CT || !CT->getRawIdentifier()) |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 713 | return false; |
| 714 | |
| 715 | // Compare to the RHS. |
Peter Collingbourne | e69e73c | 2017-02-06 21:23:03 +0000 | [diff] [blame] | 716 | // FIXME: We need to compare template parameters here to avoid incorrect |
| 717 | // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram |
| 718 | // has a non-ODR template parameter (i.e., a DICompositeType that does not |
| 719 | // have an identifier). Eventually we should decouple ODR logic from |
| 720 | // uniquing logic. |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 721 | return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() && |
Peter Collingbourne | e69e73c | 2017-02-06 21:23:03 +0000 | [diff] [blame] | 722 | LinkageName == RHS->getRawLinkageName() && |
| 723 | TemplateParams == RHS->getRawTemplateParams(); |
Duncan P. N. Exon Smith | 05ebfd0 | 2016-04-17 02:30:20 +0000 | [diff] [blame] | 724 | } |
| 725 | }; |
| 726 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 727 | template <> struct MDNodeKeyImpl<DILexicalBlock> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 728 | Metadata *Scope; |
| 729 | Metadata *File; |
| 730 | unsigned Line; |
| 731 | unsigned Column; |
| 732 | |
| 733 | MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column) |
| 734 | : Scope(Scope), File(File), Line(Line), Column(Column) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 735 | MDNodeKeyImpl(const DILexicalBlock *N) |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 736 | : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 737 | Column(N->getColumn()) {} |
| 738 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 739 | bool isKeyOf(const DILexicalBlock *RHS) const { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 740 | return Scope == RHS->getRawScope() && File == RHS->getRawFile() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 741 | Line == RHS->getLine() && Column == RHS->getColumn(); |
| 742 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 743 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 744 | unsigned getHashValue() const { |
| 745 | return hash_combine(Scope, File, Line, Column); |
| 746 | } |
| 747 | }; |
| 748 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 749 | template <> struct MDNodeKeyImpl<DILexicalBlockFile> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 750 | Metadata *Scope; |
| 751 | Metadata *File; |
| 752 | unsigned Discriminator; |
| 753 | |
| 754 | MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator) |
| 755 | : Scope(Scope), File(File), Discriminator(Discriminator) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 756 | MDNodeKeyImpl(const DILexicalBlockFile *N) |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 757 | : Scope(N->getRawScope()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 758 | Discriminator(N->getDiscriminator()) {} |
| 759 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 760 | bool isKeyOf(const DILexicalBlockFile *RHS) const { |
Duncan P. N. Exon Smith | 0e202b9 | 2015-03-30 16:37:48 +0000 | [diff] [blame] | 761 | return Scope == RHS->getRawScope() && File == RHS->getRawFile() && |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 762 | Discriminator == RHS->getDiscriminator(); |
| 763 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 764 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 765 | unsigned getHashValue() const { |
| 766 | return hash_combine(Scope, File, Discriminator); |
| 767 | } |
| 768 | }; |
| 769 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 770 | template <> struct MDNodeKeyImpl<DINamespace> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 771 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 772 | MDString *Name; |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 773 | bool ExportSymbols; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 774 | |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 775 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols) |
| 776 | : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 777 | MDNodeKeyImpl(const DINamespace *N) |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 778 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 779 | ExportSymbols(N->getExportSymbols()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 780 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 781 | bool isKeyOf(const DINamespace *RHS) const { |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 782 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
Adrian Prantl | dbfda63 | 2016-11-03 19:42:02 +0000 | [diff] [blame] | 783 | ExportSymbols == RHS->getExportSymbols(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 784 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 785 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 786 | unsigned getHashValue() const { |
Adrian Prantl | fed4f39 | 2017-04-28 22:25:46 +0000 | [diff] [blame] | 787 | return hash_combine(Scope, Name); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 788 | } |
| 789 | }; |
| 790 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 791 | template <> struct MDNodeKeyImpl<DIModule> { |
| 792 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 793 | MDString *Name; |
| 794 | MDString *ConfigurationMacros; |
| 795 | MDString *IncludePath; |
| 796 | MDString *ISysRoot; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 797 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 798 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, |
| 799 | MDString *IncludePath, MDString *ISysRoot) |
| 800 | : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), |
| 801 | IncludePath(IncludePath), ISysRoot(ISysRoot) {} |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 802 | MDNodeKeyImpl(const DIModule *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 803 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 804 | ConfigurationMacros(N->getRawConfigurationMacros()), |
| 805 | IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {} |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 806 | |
| 807 | bool isKeyOf(const DIModule *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 808 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 809 | ConfigurationMacros == RHS->getRawConfigurationMacros() && |
| 810 | IncludePath == RHS->getRawIncludePath() && |
| 811 | ISysRoot == RHS->getRawISysRoot(); |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 812 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 813 | |
Adrian Prantl | ab1243f | 2015-06-29 23:03:47 +0000 | [diff] [blame] | 814 | unsigned getHashValue() const { |
| 815 | return hash_combine(Scope, Name, |
| 816 | ConfigurationMacros, IncludePath, ISysRoot); |
| 817 | } |
| 818 | }; |
| 819 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 820 | template <> struct MDNodeKeyImpl<DITemplateTypeParameter> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 821 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 822 | Metadata *Type; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 823 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 824 | MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 825 | MDNodeKeyImpl(const DITemplateTypeParameter *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 826 | : Name(N->getRawName()), Type(N->getRawType()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 827 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 828 | bool isKeyOf(const DITemplateTypeParameter *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 829 | return Name == RHS->getRawName() && Type == RHS->getRawType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 830 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 831 | |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 832 | unsigned getHashValue() const { return hash_combine(Name, Type); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 833 | }; |
| 834 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 835 | template <> struct MDNodeKeyImpl<DITemplateValueParameter> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 836 | unsigned Tag; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 837 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 838 | Metadata *Type; |
| 839 | Metadata *Value; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 840 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 841 | MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value) |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 842 | : Tag(Tag), Name(Name), Type(Type), Value(Value) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 843 | MDNodeKeyImpl(const DITemplateValueParameter *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 844 | : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()), |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 845 | Value(N->getValue()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 846 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 847 | bool isKeyOf(const DITemplateValueParameter *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 848 | return Tag == RHS->getTag() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | 3ec5fa6 | 2015-04-06 19:03:45 +0000 | [diff] [blame] | 849 | Type == RHS->getRawType() && Value == RHS->getValue(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 850 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 851 | |
Duncan P. N. Exon Smith | 3d62bba | 2015-02-19 00:37:21 +0000 | [diff] [blame] | 852 | unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); } |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 853 | }; |
| 854 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 855 | template <> struct MDNodeKeyImpl<DIGlobalVariable> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 856 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 857 | MDString *Name; |
| 858 | MDString *LinkageName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 859 | Metadata *File; |
| 860 | unsigned Line; |
| 861 | Metadata *Type; |
| 862 | bool IsLocalToUnit; |
| 863 | bool IsDefinition; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 864 | Metadata *StaticDataMemberDeclaration; |
Matthew Voss | f8ab35a | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 865 | Metadata *TemplateParams; |
Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 866 | uint32_t AlignInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 867 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 868 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 869 | Metadata *File, unsigned Line, Metadata *Type, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 870 | bool IsLocalToUnit, bool IsDefinition, |
Matthew Voss | f8ab35a | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 871 | Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams, |
| 872 | uint32_t AlignInBits) |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 873 | : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), |
| 874 | Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 875 | IsDefinition(IsDefinition), |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 876 | StaticDataMemberDeclaration(StaticDataMemberDeclaration), |
Matthew Voss | f8ab35a | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 877 | TemplateParams(TemplateParams), AlignInBits(AlignInBits) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 878 | MDNodeKeyImpl(const DIGlobalVariable *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 879 | : Scope(N->getRawScope()), Name(N->getRawName()), |
| 880 | LinkageName(N->getRawLinkageName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 881 | Line(N->getLine()), Type(N->getRawType()), |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 882 | IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 883 | StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()), |
Matthew Voss | f8ab35a | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 884 | TemplateParams(N->getRawTemplateParams()), |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 885 | AlignInBits(N->getAlignInBits()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 886 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 887 | bool isKeyOf(const DIGlobalVariable *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 888 | 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 Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 892 | IsDefinition == RHS->isDefinition() && |
Duncan P. N. Exon Smith | 3d2afaa | 2015-03-27 17:29:58 +0000 | [diff] [blame] | 893 | StaticDataMemberDeclaration == |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 894 | RHS->getRawStaticDataMemberDeclaration() && |
Matthew Voss | f8ab35a | 2018-10-03 18:44:53 +0000 | [diff] [blame] | 895 | TemplateParams == RHS->getRawTemplateParams() && |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 896 | AlignInBits == RHS->getAlignInBits(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 897 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 898 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 899 | unsigned getHashValue() const { |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 900 | // We do not use AlignInBits in hashing function here on purpose: |
| 901 | // in most cases this param for local variable is zero (for function param |
| 902 | // it is always zero). This leads to lots of hash collisions and errors on |
| 903 | // cases with lots of similar variables. |
| 904 | // clang/test/CodeGen/debug-info-257-args.c is an example of this problem, |
| 905 | // generated IR is random for each run and test fails with Align included. |
| 906 | // TODO: make hashing work fine with such situations |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 907 | return hash_combine(Scope, Name, LinkageName, File, Line, Type, |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 908 | IsLocalToUnit, IsDefinition, /* AlignInBits, */ |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 909 | StaticDataMemberDeclaration); |
| 910 | } |
| 911 | }; |
| 912 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 913 | template <> struct MDNodeKeyImpl<DILocalVariable> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 914 | Metadata *Scope; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 915 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 916 | Metadata *File; |
| 917 | unsigned Line; |
| 918 | Metadata *Type; |
| 919 | unsigned Arg; |
| 920 | unsigned Flags; |
Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 921 | uint32_t AlignInBits; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 922 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 923 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 924 | Metadata *Type, unsigned Arg, unsigned Flags, |
Victor Leschuk | a37660c | 2016-10-26 21:32:29 +0000 | [diff] [blame] | 925 | uint32_t AlignInBits) |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 926 | : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg), |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 927 | Flags(Flags), AlignInBits(AlignInBits) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 928 | MDNodeKeyImpl(const DILocalVariable *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 929 | : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 930 | Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()), |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 931 | Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 932 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 933 | bool isKeyOf(const DILocalVariable *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 934 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 935 | File == RHS->getRawFile() && Line == RHS->getLine() && |
| 936 | Type == RHS->getRawType() && Arg == RHS->getArg() && |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 937 | Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 938 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 939 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 940 | unsigned getHashValue() const { |
Victor Leschuk | 2ede126 | 2016-10-20 00:13:12 +0000 | [diff] [blame] | 941 | // We do not use AlignInBits in hashing function here on purpose: |
| 942 | // in most cases this param for local variable is zero (for function param |
| 943 | // it is always zero). This leads to lots of hash collisions and errors on |
| 944 | // cases with lots of similar variables. |
| 945 | // clang/test/CodeGen/debug-info-257-args.c is an example of this problem, |
| 946 | // generated IR is random for each run and test fails with Align included. |
| 947 | // TODO: make hashing work fine with such situations |
Duncan P. N. Exon Smith | ed013cd | 2015-07-31 18:58:39 +0000 | [diff] [blame] | 948 | return hash_combine(Scope, Name, File, Line, Type, Arg, Flags); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 949 | } |
| 950 | }; |
| 951 | |
Shiva Chen | 2c86455 | 2018-05-09 02:40:45 +0000 | [diff] [blame] | 952 | template <> struct MDNodeKeyImpl<DILabel> { |
| 953 | Metadata *Scope; |
| 954 | MDString *Name; |
| 955 | Metadata *File; |
| 956 | unsigned Line; |
| 957 | |
| 958 | MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line) |
| 959 | : Scope(Scope), Name(Name), File(File), Line(Line) {} |
| 960 | MDNodeKeyImpl(const DILabel *N) |
| 961 | : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), |
| 962 | Line(N->getLine()) {} |
| 963 | |
| 964 | bool isKeyOf(const DILabel *RHS) const { |
| 965 | return Scope == RHS->getRawScope() && Name == RHS->getRawName() && |
| 966 | File == RHS->getRawFile() && Line == RHS->getLine(); |
| 967 | } |
| 968 | |
| 969 | /// Using name and line to get hash value. It should already be mostly unique. |
| 970 | unsigned getHashValue() const { |
| 971 | return hash_combine(Scope, Name, Line); |
| 972 | } |
| 973 | }; |
| 974 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 975 | template <> struct MDNodeKeyImpl<DIExpression> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 976 | ArrayRef<uint64_t> Elements; |
| 977 | |
| 978 | MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 979 | MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 980 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 981 | bool isKeyOf(const DIExpression *RHS) const { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 982 | return Elements == RHS->getElements(); |
| 983 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 984 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 985 | unsigned getHashValue() const { |
| 986 | return hash_combine_range(Elements.begin(), Elements.end()); |
| 987 | } |
| 988 | }; |
| 989 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 990 | template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> { |
| 991 | Metadata *Variable; |
| 992 | Metadata *Expression; |
| 993 | |
| 994 | MDNodeKeyImpl(Metadata *Variable, Metadata *Expression) |
| 995 | : Variable(Variable), Expression(Expression) {} |
| 996 | MDNodeKeyImpl(const DIGlobalVariableExpression *N) |
| 997 | : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {} |
| 998 | |
| 999 | bool isKeyOf(const DIGlobalVariableExpression *RHS) const { |
| 1000 | return Variable == RHS->getRawVariable() && |
| 1001 | Expression == RHS->getRawExpression(); |
| 1002 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1003 | |
Adrian Prantl | bceaaa9 | 2016-12-20 02:09:43 +0000 | [diff] [blame] | 1004 | unsigned getHashValue() const { return hash_combine(Variable, Expression); } |
| 1005 | }; |
| 1006 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1007 | template <> struct MDNodeKeyImpl<DIObjCProperty> { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1008 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1009 | Metadata *File; |
| 1010 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1011 | MDString *GetterName; |
| 1012 | MDString *SetterName; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1013 | unsigned Attributes; |
| 1014 | Metadata *Type; |
| 1015 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1016 | MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line, |
| 1017 | MDString *GetterName, MDString *SetterName, unsigned Attributes, |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1018 | Metadata *Type) |
| 1019 | : Name(Name), File(File), Line(Line), GetterName(GetterName), |
| 1020 | SetterName(SetterName), Attributes(Attributes), Type(Type) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1021 | MDNodeKeyImpl(const DIObjCProperty *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1022 | : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), |
| 1023 | GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()), |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1024 | Attributes(N->getAttributes()), Type(N->getRawType()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1025 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1026 | bool isKeyOf(const DIObjCProperty *RHS) const { |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1027 | return Name == RHS->getRawName() && File == RHS->getRawFile() && |
| 1028 | Line == RHS->getLine() && GetterName == RHS->getRawGetterName() && |
| 1029 | SetterName == RHS->getRawSetterName() && |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1030 | Attributes == RHS->getAttributes() && Type == RHS->getRawType(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1031 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1032 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1033 | unsigned getHashValue() const { |
| 1034 | return hash_combine(Name, File, Line, GetterName, SetterName, Attributes, |
| 1035 | Type); |
| 1036 | } |
| 1037 | }; |
| 1038 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1039 | template <> struct MDNodeKeyImpl<DIImportedEntity> { |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1040 | unsigned Tag; |
| 1041 | Metadata *Scope; |
| 1042 | Metadata *Entity; |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 1043 | Metadata *File; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1044 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1045 | MDString *Name; |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1046 | |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 1047 | MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File, |
| 1048 | unsigned Line, MDString *Name) |
| 1049 | : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line), |
| 1050 | Name(Name) {} |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1051 | MDNodeKeyImpl(const DIImportedEntity *N) |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1052 | : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()), |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 1053 | File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {} |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1054 | |
Duncan P. N. Exon Smith | a9308c4 | 2015-04-29 16:38:44 +0000 | [diff] [blame] | 1055 | bool isKeyOf(const DIImportedEntity *RHS) const { |
Duncan P. N. Exon Smith | f9b4775 | 2015-03-30 17:21:38 +0000 | [diff] [blame] | 1056 | return Tag == RHS->getTag() && Scope == RHS->getRawScope() && |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 1057 | Entity == RHS->getRawEntity() && File == RHS->getFile() && |
| 1058 | Line == RHS->getLine() && Name == RHS->getRawName(); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1059 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1060 | |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1061 | unsigned getHashValue() const { |
Adrian Prantl | d63bfd2 | 2017-07-19 00:09:54 +0000 | [diff] [blame] | 1062 | return hash_combine(Tag, Scope, Entity, File, Line, Name); |
Duncan P. N. Exon Smith | 01fc176 | 2015-02-10 00:52:32 +0000 | [diff] [blame] | 1063 | } |
| 1064 | }; |
| 1065 | |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1066 | template <> struct MDNodeKeyImpl<DIMacro> { |
| 1067 | unsigned MIType; |
| 1068 | unsigned Line; |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1069 | MDString *Name; |
| 1070 | MDString *Value; |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1071 | |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1072 | MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value) |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1073 | : MIType(MIType), Line(Line), Name(Name), Value(Value) {} |
| 1074 | MDNodeKeyImpl(const DIMacro *N) |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1075 | : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()), |
| 1076 | Value(N->getRawValue()) {} |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1077 | |
| 1078 | bool isKeyOf(const DIMacro *RHS) const { |
| 1079 | return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && |
Mehdi Amini | 5d99c4e | 2016-03-19 01:02:34 +0000 | [diff] [blame] | 1080 | Name == RHS->getRawName() && Value == RHS->getRawValue(); |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1081 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1082 | |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1083 | unsigned getHashValue() const { |
| 1084 | return hash_combine(MIType, Line, Name, Value); |
| 1085 | } |
| 1086 | }; |
| 1087 | |
| 1088 | template <> struct MDNodeKeyImpl<DIMacroFile> { |
| 1089 | unsigned MIType; |
| 1090 | unsigned Line; |
| 1091 | Metadata *File; |
| 1092 | Metadata *Elements; |
| 1093 | |
| 1094 | MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File, |
| 1095 | Metadata *Elements) |
| 1096 | : MIType(MIType), Line(Line), File(File), Elements(Elements) {} |
| 1097 | MDNodeKeyImpl(const DIMacroFile *N) |
| 1098 | : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()), |
| 1099 | Elements(N->getRawElements()) {} |
| 1100 | |
| 1101 | bool isKeyOf(const DIMacroFile *RHS) const { |
| 1102 | return MIType == RHS->getMacinfoType() && Line == RHS->getLine() && |
Amjad Aboud | 580498d | 2016-07-31 14:41:50 +0000 | [diff] [blame] | 1103 | File == RHS->getRawFile() && Elements == RHS->getRawElements(); |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1104 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1105 | |
Amjad Aboud | a9bcf16 | 2015-12-10 12:56:35 +0000 | [diff] [blame] | 1106 | unsigned getHashValue() const { |
| 1107 | return hash_combine(MIType, Line, File, Elements); |
| 1108 | } |
| 1109 | }; |
| 1110 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1111 | /// DenseMapInfo for MDNode subclasses. |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1112 | template <class NodeTy> struct MDNodeInfo { |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1113 | using KeyTy = MDNodeKeyImpl<NodeTy>; |
| 1114 | using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>; |
| 1115 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1116 | static inline NodeTy *getEmptyKey() { |
| 1117 | return DenseMapInfo<NodeTy *>::getEmptyKey(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1118 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1119 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1120 | static inline NodeTy *getTombstoneKey() { |
| 1121 | return DenseMapInfo<NodeTy *>::getTombstoneKey(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1122 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1123 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1124 | static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1125 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1126 | static unsigned getHashValue(const NodeTy *N) { |
| 1127 | return KeyTy(N).getHashValue(); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1128 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1129 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1130 | static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) { |
| 1131 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 1132 | return false; |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 1133 | return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1134 | } |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1135 | |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1136 | static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) { |
Duncan P. N. Exon Smith | f229127 | 2016-04-16 23:42:04 +0000 | [diff] [blame] | 1137 | if (LHS == RHS) |
| 1138 | return true; |
| 1139 | if (RHS == getEmptyKey() || RHS == getTombstoneKey()) |
| 1140 | return false; |
| 1141 | return SubsetEqualTy::isSubsetEqual(LHS, RHS); |
Duncan P. N. Exon Smith | fed199a | 2015-01-20 00:01:43 +0000 | [diff] [blame] | 1142 | } |
| 1143 | }; |
| 1144 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1145 | #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>; |
Duncan P. N. Exon Smith | 8af6cfc | 2015-02-04 22:08:30 +0000 | [diff] [blame] | 1146 | #include "llvm/IR/Metadata.def" |
| 1147 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1148 | /// Map-like storage for metadata attachments. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1149 | class MDAttachmentMap { |
| 1150 | SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments; |
| 1151 | |
| 1152 | public: |
| 1153 | bool empty() const { return Attachments.empty(); } |
| 1154 | size_t size() const { return Attachments.size(); } |
| 1155 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1156 | /// Get a particular attachment (if any). |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1157 | MDNode *lookup(unsigned ID) const; |
| 1158 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1159 | /// Set an attachment to a particular node. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1160 | /// |
| 1161 | /// Set the \c ID attachment to \c MD, replacing the current attachment at \c |
| 1162 | /// ID (if anyway). |
| 1163 | void set(unsigned ID, MDNode &MD); |
| 1164 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1165 | /// Remove an attachment. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1166 | /// |
| 1167 | /// Remove the attachment at \c ID, if any. |
Benjamin Kramer | 0deb9a9 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 1168 | bool erase(unsigned ID); |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1169 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1170 | /// Copy out all the attachments. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1171 | /// |
| 1172 | /// Copies all the current attachments into \c Result, sorting by attachment |
| 1173 | /// ID. This function does \em not clear \c Result. |
| 1174 | void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; |
| 1175 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1176 | /// Erase matching attachments. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1177 | /// |
| 1178 | /// Erases all attachments matching the \c shouldRemove predicate. |
| 1179 | template <class PredTy> void remove_if(PredTy shouldRemove) { |
David Majnemer | 2d006e7 | 2016-08-12 04:32:42 +0000 | [diff] [blame] | 1180 | Attachments.erase(llvm::remove_if(Attachments, shouldRemove), |
| 1181 | Attachments.end()); |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1182 | } |
| 1183 | }; |
| 1184 | |
Peter Collingbourne | 382d81c | 2016-06-01 01:17:57 +0000 | [diff] [blame] | 1185 | /// Multimap-like storage for metadata attachments for globals. This differs |
| 1186 | /// from MDAttachmentMap in that it allows multiple attachments per metadata |
| 1187 | /// kind. |
| 1188 | class MDGlobalAttachmentMap { |
| 1189 | struct Attachment { |
| 1190 | unsigned MDKind; |
| 1191 | TrackingMDNodeRef Node; |
| 1192 | }; |
| 1193 | SmallVector<Attachment, 1> Attachments; |
| 1194 | |
| 1195 | public: |
| 1196 | bool empty() const { return Attachments.empty(); } |
| 1197 | |
| 1198 | /// Appends all attachments with the given ID to \c Result in insertion order. |
| 1199 | /// If the global has no attachments with the given ID, or if ID is invalid, |
| 1200 | /// leaves Result unchanged. |
Benjamin Kramer | 0deb9a9 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 1201 | void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const; |
| 1202 | |
| 1203 | /// Returns the first attachment with the given ID or nullptr if no such |
| 1204 | /// attachment exists. |
| 1205 | MDNode *lookup(unsigned ID) const; |
Peter Collingbourne | 382d81c | 2016-06-01 01:17:57 +0000 | [diff] [blame] | 1206 | |
| 1207 | void insert(unsigned ID, MDNode &MD); |
Benjamin Kramer | 0deb9a9 | 2018-05-31 13:29:58 +0000 | [diff] [blame] | 1208 | bool erase(unsigned ID); |
Peter Collingbourne | 382d81c | 2016-06-01 01:17:57 +0000 | [diff] [blame] | 1209 | |
| 1210 | /// Appends all attachments for the global to \c Result, sorting by attachment |
| 1211 | /// ID. Attachments with the same ID appear in insertion order. This function |
| 1212 | /// does \em not clear \c Result. |
| 1213 | void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; |
| 1214 | }; |
| 1215 | |
Benjamin Kramer | 079b96e | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 1216 | class LLVMContextImpl { |
Benjamin Kramer | 78c3bcb | 2009-08-11 17:45:13 +0000 | [diff] [blame] | 1217 | public: |
Owen Anderson | 8e89e41 | 2010-09-08 18:03:32 +0000 | [diff] [blame] | 1218 | /// OwnedModules - The set of modules instantiated in this context, and which |
| 1219 | /// will be automatically deleted if this context is deleted. |
| 1220 | SmallPtrSet<Module*, 4> OwnedModules; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1221 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1222 | LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr; |
| 1223 | void *InlineAsmDiagContext = nullptr; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 1224 | |
Vivek Pandya | b5ab895 | 2017-09-15 20:10:09 +0000 | [diff] [blame] | 1225 | std::unique_ptr<DiagnosticHandler> DiagHandler; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1226 | bool RespectDiagnosticFilters = false; |
Brian Gesiak | 44e5f6c | 2017-06-30 18:13:59 +0000 | [diff] [blame] | 1227 | bool DiagnosticsHotnessRequested = false; |
Brian Gesiak | 4ef3daa | 2017-06-30 23:14:53 +0000 | [diff] [blame] | 1228 | uint64_t DiagnosticsHotnessThreshold = 0; |
Adam Nemet | a62b7e1 | 2016-09-27 20:55:07 +0000 | [diff] [blame] | 1229 | std::unique_ptr<yaml::Output> DiagnosticsOutputFile; |
Quentin Colombet | b4c44d2 | 2013-12-17 17:47:22 +0000 | [diff] [blame] | 1230 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1231 | LLVMContext::YieldCallbackTy YieldCallback = nullptr; |
| 1232 | void *YieldOpaqueHandle = nullptr; |
Juergen Ributzka | 34390c7 | 2014-05-16 02:33:15 +0000 | [diff] [blame] | 1233 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1234 | using IntMapTy = |
| 1235 | DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>; |
Owen Anderson | 20b34ac | 2009-07-16 18:04:31 +0000 | [diff] [blame] | 1236 | IntMapTy IntConstants; |
NAKAMURA Takumi | fc3062f | 2014-12-06 05:57:06 +0000 | [diff] [blame] | 1237 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1238 | using FPMapTy = |
| 1239 | DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>; |
Owen Anderson | c277dc4 | 2009-07-16 19:05:41 +0000 | [diff] [blame] | 1240 | FPMapTy FPConstants; |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1241 | |
Bill Wendling | 4607f4b | 2012-12-20 01:36:59 +0000 | [diff] [blame] | 1242 | FoldingSet<AttributeImpl> AttrsSet; |
Reid Kleckner | b518054 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 1243 | FoldingSet<AttributeListImpl> AttrsLists; |
Bill Wendling | d2e493b | 2013-01-24 00:06:56 +0000 | [diff] [blame] | 1244 | FoldingSet<AttributeSetNode> AttrsSetNodes; |
Bill Wendling | f86efb9 | 2012-11-20 05:09:20 +0000 | [diff] [blame] | 1245 | |
Duncan P. N. Exon Smith | 3e0430e | 2016-04-06 06:41:54 +0000 | [diff] [blame] | 1246 | StringMap<MDString, BumpPtrAllocator> MDStringCache; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1247 | DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata; |
| 1248 | DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues; |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1249 | |
Owen Anderson | 7349ab9 | 2015-06-01 22:24:01 +0000 | [diff] [blame] | 1250 | DenseMap<const Value*, ValueName*> ValueNames; |
| 1251 | |
Duncan P. N. Exon Smith | 55ca964 | 2015-08-03 17:26:41 +0000 | [diff] [blame] | 1252 | #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \ |
| 1253 | DenseSet<CLASS *, CLASS##Info> CLASS##s; |
Duncan P. N. Exon Smith | 104e402 | 2015-02-04 21:46:12 +0000 | [diff] [blame] | 1254 | #include "llvm/IR/Metadata.def" |
Bill Wendling | e38b804 | 2012-09-26 21:07:29 +0000 | [diff] [blame] | 1255 | |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 1256 | // Optional map for looking up composite types by identifier. |
Duncan P. N. Exon Smith | e8b555c | 2016-04-19 16:06:50 +0000 | [diff] [blame] | 1257 | Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap; |
Duncan P. N. Exon Smith | 5ab2be0 | 2016-04-17 03:58:21 +0000 | [diff] [blame] | 1258 | |
Jeffrey Yasskin | 2cc2476 | 2010-03-13 01:26:15 +0000 | [diff] [blame] | 1259 | // MDNodes may be uniqued or not uniqued. When they're not uniqued, they |
| 1260 | // aren't in the MDNodeSet, but they're still shared between objects, so no |
Duncan P. N. Exon Smith | 3eef9d1 | 2016-04-19 23:59:13 +0000 | [diff] [blame] | 1261 | // one object can destroy them. Keep track of them here so we can delete |
| 1262 | // them on context teardown. |
| 1263 | std::vector<MDNode *> DistinctMDNodes; |
Duncan P. N. Exon Smith | 50846f8 | 2014-11-18 00:37:17 +0000 | [diff] [blame] | 1264 | |
Justin Lebar | 611c5c2 | 2016-10-10 16:26:13 +0000 | [diff] [blame] | 1265 | DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants; |
Owen Anderson | 13234f8 | 2009-08-10 18:16:08 +0000 | [diff] [blame] | 1266 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1267 | using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1268 | ArrayConstantsTy ArrayConstants; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1269 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1270 | using StructConstantsTy = ConstantUniqueMap<ConstantStruct>; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1271 | StructConstantsTy StructConstants; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1272 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1273 | using VectorConstantsTy = ConstantUniqueMap<ConstantVector>; |
Owen Anderson | edb4a70 | 2009-07-24 23:12:02 +0000 | [diff] [blame] | 1274 | VectorConstantsTy VectorConstants; |
Chris Lattner | c7f9fd4 | 2012-01-23 15:20:12 +0000 | [diff] [blame] | 1275 | |
Justin Lebar | 611c5c2 | 2016-10-10 16:26:13 +0000 | [diff] [blame] | 1276 | DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants; |
| 1277 | |
| 1278 | DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants; |
| 1279 | |
Chris Lattner | 3756b91 | 2012-01-23 22:57:10 +0000 | [diff] [blame] | 1280 | StringMap<ConstantDataSequential*> CDSConstants; |
| 1281 | |
Chandler Carruth | 6a93692 | 2014-01-19 02:13:50 +0000 | [diff] [blame] | 1282 | DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *> |
| 1283 | BlockAddresses; |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1284 | ConstantUniqueMap<ConstantExpr> ExprConstants; |
Jeffrey Yasskin | ade270e | 2010-03-21 20:37:19 +0000 | [diff] [blame] | 1285 | |
Duncan P. N. Exon Smith | 317c139 | 2014-08-19 16:39:58 +0000 | [diff] [blame] | 1286 | ConstantUniqueMap<InlineAsm> InlineAsms; |
| 1287 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1288 | ConstantInt *TheTrueVal = nullptr; |
| 1289 | ConstantInt *TheFalseVal = nullptr; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1290 | |
David Majnemer | 2dd41c5 | 2015-11-16 20:55:57 +0000 | [diff] [blame] | 1291 | std::unique_ptr<ConstantTokenNone> TheNoneToken; |
David Majnemer | f0f224d | 2015-11-11 21:57:16 +0000 | [diff] [blame] | 1292 | |
Dan Gohman | 97d2cb8 | 2009-08-25 16:00:35 +0000 | [diff] [blame] | 1293 | // Basic type instances. |
David Majnemer | b611e3f | 2015-08-14 05:09:07 +0000 | [diff] [blame] | 1294 | Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1295 | Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; |
Kit Barton | 7291802 | 2015-04-17 15:32:15 +0000 | [diff] [blame] | 1296 | IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1297 | |
Chris Lattner | 07bd69c | 2011-07-15 05:49:15 +0000 | [diff] [blame] | 1298 | /// TypeAllocator - All dynamically allocated types are allocated from this. |
| 1299 | /// They live forever until the context is torn down. |
| 1300 | BumpPtrAllocator TypeAllocator; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1301 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1302 | DenseMap<unsigned, IntegerType*> IntegerTypes; |
Benjamin Kramer | 3280a5d | 2014-12-06 19:22:54 +0000 | [diff] [blame] | 1303 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1304 | using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>; |
Benjamin Kramer | 3280a5d | 2014-12-06 19:22:54 +0000 | [diff] [blame] | 1305 | FunctionTypeSet FunctionTypes; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1306 | using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>; |
Benjamin Kramer | 3280a5d | 2014-12-06 19:22:54 +0000 | [diff] [blame] | 1307 | StructTypeSet AnonStructTypes; |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1308 | StringMap<StructType*> NamedStructTypes; |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1309 | unsigned NamedStructTypesUniqueID = 0; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1310 | |
Chris Lattner | b1ed91f | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 1311 | DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; |
| 1312 | DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; |
| 1313 | DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 |
| 1314 | DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; |
Jeffrey Yasskin | c660b23 | 2010-02-11 06:41:30 +0000 | [diff] [blame] | 1315 | |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 1316 | /// ValueHandles - This map keeps track of all of the value handles that are |
| 1317 | /// watching a Value*. The Value::HasValueHandle bit is used to know |
Michael Ilseman | 516d703 | 2013-03-01 18:48:54 +0000 | [diff] [blame] | 1318 | /// whether or not a value has an entry in this map. |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1319 | using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>; |
Owen Anderson | e8f2185 | 2009-08-18 18:28:58 +0000 | [diff] [blame] | 1320 | ValueHandlesTy ValueHandles; |
Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 1321 | |
Chris Lattner | a056697 | 2009-12-29 09:01:33 +0000 | [diff] [blame] | 1322 | /// CustomMDKindNames - Map to hold the metadata string to ID mapping. |
| 1323 | StringMap<unsigned> CustomMDKindNames; |
Duncan P. N. Exon Smith | 5bf8fef | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 1324 | |
Duncan P. N. Exon Smith | 391fc56 | 2015-04-24 20:16:42 +0000 | [diff] [blame] | 1325 | /// Collection of per-instruction metadata used in this context. |
Duncan P. N. Exon Smith | cbc28dc | 2015-04-24 20:36:25 +0000 | [diff] [blame] | 1326 | DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata; |
Duncan P. N. Exon Smith | 391fc56 | 2015-04-24 20:16:42 +0000 | [diff] [blame] | 1327 | |
Peter Collingbourne | cceae7f | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 1328 | /// Collection of per-GlobalObject metadata used in this context. |
Peter Collingbourne | 382d81c | 2016-06-01 01:17:57 +0000 | [diff] [blame] | 1329 | DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata; |
Duncan P. N. Exon Smith | e2510cd | 2015-04-24 21:51:02 +0000 | [diff] [blame] | 1330 | |
Reid Kleckner | 443423e | 2017-01-10 23:23:58 +0000 | [diff] [blame] | 1331 | /// Collection of per-GlobalObject sections used in this context. |
| 1332 | DenseMap<const GlobalObject *, StringRef> GlobalObjectSections; |
| 1333 | |
| 1334 | /// Stable collection of section strings. |
| 1335 | StringSet<> SectionStrings; |
| 1336 | |
Diego Novillo | f5041ce | 2014-03-03 20:06:11 +0000 | [diff] [blame] | 1337 | /// DiscriminatorTable - This table maps file:line locations to an |
| 1338 | /// integer representing the next DWARF path discriminator to assign to |
| 1339 | /// instructions in different blocks at the same location. |
| 1340 | DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable; |
| 1341 | |
Chris Lattner | 8cb2aeb | 2010-04-01 00:37:44 +0000 | [diff] [blame] | 1342 | int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); |
| 1343 | int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx); |
Philip Reames | 2b45395 | 2015-01-16 20:07:33 +0000 | [diff] [blame] | 1344 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1345 | /// A set of interned tags for operand bundles. The StringMap maps |
Sanjoy Das | 9303c24 | 2015-09-24 19:14:18 +0000 | [diff] [blame] | 1346 | /// bundle tags to their IDs. |
| 1347 | /// |
| 1348 | /// \see LLVMContext::getOperandBundleTagID |
| 1349 | StringMap<uint32_t> BundleTagCache; |
| 1350 | |
| 1351 | StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag); |
| 1352 | void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const; |
| 1353 | uint32_t getOperandBundleTagID(StringRef Tag) const; |
| 1354 | |
Konstantin Zhuravlyov | bb80d3e | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 1355 | /// A set of interned synchronization scopes. The StringMap maps |
| 1356 | /// synchronization scope names to their respective synchronization scope IDs. |
| 1357 | StringMap<SyncScope::ID> SSC; |
| 1358 | |
| 1359 | /// getOrInsertSyncScopeID - Maps synchronization scope name to |
| 1360 | /// synchronization scope ID. Every synchronization scope registered with |
| 1361 | /// LLVMContext has unique ID except pre-defined ones. |
| 1362 | SyncScope::ID getOrInsertSyncScopeID(StringRef SSN); |
| 1363 | |
| 1364 | /// getSyncScopeNames - Populates client supplied SmallVector with |
| 1365 | /// synchronization scope names registered with LLVMContext. Synchronization |
| 1366 | /// scope names are ordered by increasing synchronization scope IDs. |
| 1367 | void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const; |
| 1368 | |
Mehdi Amini | 599ebf2 | 2016-01-08 02:28:20 +0000 | [diff] [blame] | 1369 | /// Maintain the GC name for each function. |
| 1370 | /// |
| 1371 | /// This saves allocating an additional word in Function for programs which |
| 1372 | /// do not use GC (i.e., most programs) at the cost of increased overhead for |
| 1373 | /// clients which do use GC. |
| 1374 | DenseMap<const Function*, std::string> GCNames; |
| 1375 | |
Mehdi Amini | 09b4a8d | 2016-03-10 01:28:54 +0000 | [diff] [blame] | 1376 | /// Flag to indicate if Value (other than GlobalValue) retains their name or |
| 1377 | /// not. |
| 1378 | bool DiscardValueNames = false; |
| 1379 | |
Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 1380 | LLVMContextImpl(LLVMContext &C); |
| 1381 | ~LLVMContextImpl(); |
Manman Ren | dab999d | 2015-01-20 19:24:59 +0000 | [diff] [blame] | 1382 | |
| 1383 | /// Destroy the ConstantArrays if they are not used. |
| 1384 | void dropTriviallyDeadConstantArrays(); |
Andrew Kaylor | aa641a5 | 2016-04-22 22:06:11 +0000 | [diff] [blame] | 1385 | |
Fedor Sergeev | d29884c | 2018-04-05 10:29:37 +0000 | [diff] [blame] | 1386 | mutable OptPassGate *OPG = nullptr; |
| 1387 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1388 | /// Access the object which can disable optional passes and individual |
Fedor Sergeev | d29884c | 2018-04-05 10:29:37 +0000 | [diff] [blame] | 1389 | /// optimizations at compile time. |
| 1390 | OptPassGate &getOptPassGate() const; |
| 1391 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 1392 | /// Set the object which can disable optional passes and individual |
Fedor Sergeev | d29884c | 2018-04-05 10:29:37 +0000 | [diff] [blame] | 1393 | /// optimizations at compile time. |
| 1394 | /// |
| 1395 | /// The lifetime of the object must be guaranteed to extend as long as the |
| 1396 | /// LLVMContext is used by compilation. |
| 1397 | void setOptPassGate(OptPassGate&); |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 1398 | }; |
| 1399 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1400 | } // end namespace llvm |
Owen Anderson | 8e66e0b | 2009-06-30 00:48:55 +0000 | [diff] [blame] | 1401 | |
Eugene Zelenko | de6cce2 | 2017-06-19 22:05:08 +0000 | [diff] [blame] | 1402 | #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H |