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