• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- LLVMContextImpl.h - The LLVMContextImpl opaque class ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file declares LLVMContextImpl, the opaque implementation
11 //  of LLVMContext.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
16 #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
17 
18 #include "AttributeImpl.h"
19 #include "ConstantsContext.h"
20 #include "llvm/ADT/APFloat.h"
21 #include "llvm/ADT/APInt.h"
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/DenseSet.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/Hashing.h"
27 #include "llvm/ADT/SmallPtrSet.h"
28 #include "llvm/ADT/StringMap.h"
29 #include "llvm/IR/Constants.h"
30 #include "llvm/IR/DebugInfoMetadata.h"
31 #include "llvm/IR/DerivedTypes.h"
32 #include "llvm/IR/LLVMContext.h"
33 #include "llvm/IR/Metadata.h"
34 #include "llvm/IR/ValueHandle.h"
35 #include "llvm/Support/Dwarf.h"
36 #include <vector>
37 
38 namespace llvm {
39 
40 class ConstantInt;
41 class ConstantFP;
42 class DiagnosticInfoOptimizationRemark;
43 class DiagnosticInfoOptimizationRemarkMissed;
44 class DiagnosticInfoOptimizationRemarkAnalysis;
45 class GCStrategy;
46 class LLVMContext;
47 class Type;
48 class Value;
49 
50 struct DenseMapAPIntKeyInfo {
getEmptyKeyDenseMapAPIntKeyInfo51   static inline APInt getEmptyKey() {
52     APInt V(nullptr, 0);
53     V.VAL = 0;
54     return V;
55   }
getTombstoneKeyDenseMapAPIntKeyInfo56   static inline APInt getTombstoneKey() {
57     APInt V(nullptr, 0);
58     V.VAL = 1;
59     return V;
60   }
getHashValueDenseMapAPIntKeyInfo61   static unsigned getHashValue(const APInt &Key) {
62     return static_cast<unsigned>(hash_value(Key));
63   }
isEqualDenseMapAPIntKeyInfo64   static bool isEqual(const APInt &LHS, const APInt &RHS) {
65     return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
66   }
67 };
68 
69 struct DenseMapAPFloatKeyInfo {
getEmptyKeyDenseMapAPFloatKeyInfo70   static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus, 1); }
getTombstoneKeyDenseMapAPFloatKeyInfo71   static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus, 2); }
getHashValueDenseMapAPFloatKeyInfo72   static unsigned getHashValue(const APFloat &Key) {
73     return static_cast<unsigned>(hash_value(Key));
74   }
isEqualDenseMapAPFloatKeyInfo75   static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
76     return LHS.bitwiseIsEqual(RHS);
77   }
78 };
79 
80 struct AnonStructTypeKeyInfo {
81   struct KeyTy {
82     ArrayRef<Type*> ETypes;
83     bool isPacked;
KeyTyAnonStructTypeKeyInfo::KeyTy84     KeyTy(const ArrayRef<Type*>& E, bool P) :
85       ETypes(E), isPacked(P) {}
KeyTyAnonStructTypeKeyInfo::KeyTy86     KeyTy(const StructType *ST)
87         : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
88     bool operator==(const KeyTy& that) const {
89       if (isPacked != that.isPacked)
90         return false;
91       if (ETypes != that.ETypes)
92         return false;
93       return true;
94     }
95     bool operator!=(const KeyTy& that) const {
96       return !this->operator==(that);
97     }
98   };
getEmptyKeyAnonStructTypeKeyInfo99   static inline StructType* getEmptyKey() {
100     return DenseMapInfo<StructType*>::getEmptyKey();
101   }
getTombstoneKeyAnonStructTypeKeyInfo102   static inline StructType* getTombstoneKey() {
103     return DenseMapInfo<StructType*>::getTombstoneKey();
104   }
getHashValueAnonStructTypeKeyInfo105   static unsigned getHashValue(const KeyTy& Key) {
106     return hash_combine(hash_combine_range(Key.ETypes.begin(),
107                                            Key.ETypes.end()),
108                         Key.isPacked);
109   }
getHashValueAnonStructTypeKeyInfo110   static unsigned getHashValue(const StructType *ST) {
111     return getHashValue(KeyTy(ST));
112   }
isEqualAnonStructTypeKeyInfo113   static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
114     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
115       return false;
116     return LHS == KeyTy(RHS);
117   }
isEqualAnonStructTypeKeyInfo118   static bool isEqual(const StructType *LHS, const StructType *RHS) {
119     return LHS == RHS;
120   }
121 };
122 
123 struct FunctionTypeKeyInfo {
124   struct KeyTy {
125     const Type *ReturnType;
126     ArrayRef<Type*> Params;
127     bool isVarArg;
KeyTyFunctionTypeKeyInfo::KeyTy128     KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
129       ReturnType(R), Params(P), isVarArg(V) {}
KeyTyFunctionTypeKeyInfo::KeyTy130     KeyTy(const FunctionType *FT)
131         : ReturnType(FT->getReturnType()), Params(FT->params()),
132           isVarArg(FT->isVarArg()) {}
133     bool operator==(const KeyTy& that) const {
134       if (ReturnType != that.ReturnType)
135         return false;
136       if (isVarArg != that.isVarArg)
137         return false;
138       if (Params != that.Params)
139         return false;
140       return true;
141     }
142     bool operator!=(const KeyTy& that) const {
143       return !this->operator==(that);
144     }
145   };
getEmptyKeyFunctionTypeKeyInfo146   static inline FunctionType* getEmptyKey() {
147     return DenseMapInfo<FunctionType*>::getEmptyKey();
148   }
getTombstoneKeyFunctionTypeKeyInfo149   static inline FunctionType* getTombstoneKey() {
150     return DenseMapInfo<FunctionType*>::getTombstoneKey();
151   }
getHashValueFunctionTypeKeyInfo152   static unsigned getHashValue(const KeyTy& Key) {
153     return hash_combine(Key.ReturnType,
154                         hash_combine_range(Key.Params.begin(),
155                                            Key.Params.end()),
156                         Key.isVarArg);
157   }
getHashValueFunctionTypeKeyInfo158   static unsigned getHashValue(const FunctionType *FT) {
159     return getHashValue(KeyTy(FT));
160   }
isEqualFunctionTypeKeyInfo161   static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
162     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
163       return false;
164     return LHS == KeyTy(RHS);
165   }
isEqualFunctionTypeKeyInfo166   static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
167     return LHS == RHS;
168   }
169 };
170 
171 /// \brief Structure for hashing arbitrary MDNode operands.
172 class MDNodeOpsKey {
173   ArrayRef<Metadata *> RawOps;
174   ArrayRef<MDOperand> Ops;
175 
176   unsigned Hash;
177 
178 protected:
MDNodeOpsKey(ArrayRef<Metadata * > Ops)179   MDNodeOpsKey(ArrayRef<Metadata *> Ops)
180       : RawOps(Ops), Hash(calculateHash(Ops)) {}
181 
182   template <class NodeTy>
183   MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
184       : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
185 
186   template <class NodeTy>
187   bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
188     if (getHash() != RHS->getHash())
189       return false;
190 
191     assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
192     return RawOps.empty() ? compareOps(Ops, RHS, Offset)
193                           : compareOps(RawOps, RHS, Offset);
194   }
195 
196   static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
197 
198 private:
199   template <class T>
compareOps(ArrayRef<T> Ops,const MDNode * RHS,unsigned Offset)200   static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
201     if (Ops.size() != RHS->getNumOperands() - Offset)
202       return false;
203     return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
204   }
205 
206   static unsigned calculateHash(ArrayRef<Metadata *> Ops);
207 
208 public:
getHash()209   unsigned getHash() const { return Hash; }
210 };
211 
212 template <class NodeTy> struct MDNodeKeyImpl;
213 template <class NodeTy> struct MDNodeInfo;
214 
215 /// Configuration point for MDNodeInfo::isEqual().
216 template <class NodeTy> struct MDNodeSubsetEqualImpl {
217   typedef MDNodeKeyImpl<NodeTy> KeyTy;
isSubsetEqualMDNodeSubsetEqualImpl218   static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
219     return false;
220   }
isSubsetEqualMDNodeSubsetEqualImpl221   static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
222     return false;
223   }
224 };
225 
226 /// \brief DenseMapInfo for MDTuple.
227 ///
228 /// Note that we don't need the is-function-local bit, since that's implicit in
229 /// the operands.
230 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
231   MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
232   MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
233 
234   bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
235 
236   unsigned getHashValue() const { return getHash(); }
237 
238   static unsigned calculateHash(MDTuple *N) {
239     return MDNodeOpsKey::calculateHash(N);
240   }
241 };
242 
243 /// \brief DenseMapInfo for DILocation.
244 template <> struct MDNodeKeyImpl<DILocation> {
245   unsigned Line;
246   unsigned Column;
247   Metadata *Scope;
248   Metadata *InlinedAt;
249 
250   MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
251                 Metadata *InlinedAt)
252       : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
253 
254   MDNodeKeyImpl(const DILocation *L)
255       : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
256         InlinedAt(L->getRawInlinedAt()) {}
257 
258   bool isKeyOf(const DILocation *RHS) const {
259     return Line == RHS->getLine() && Column == RHS->getColumn() &&
260            Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
261   }
262   unsigned getHashValue() const {
263     return hash_combine(Line, Column, Scope, InlinedAt);
264   }
265 };
266 
267 /// \brief DenseMapInfo for GenericDINode.
268 template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
269   unsigned Tag;
270   MDString *Header;
271   MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
272       : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
273   MDNodeKeyImpl(const GenericDINode *N)
274       : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
275 
276   bool isKeyOf(const GenericDINode *RHS) const {
277     return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
278            compareOps(RHS, 1);
279   }
280 
281   unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
282 
283   static unsigned calculateHash(GenericDINode *N) {
284     return MDNodeOpsKey::calculateHash(N, 1);
285   }
286 };
287 
288 template <> struct MDNodeKeyImpl<DISubrange> {
289   int64_t Count;
290   int64_t LowerBound;
291 
292   MDNodeKeyImpl(int64_t Count, int64_t LowerBound)
293       : Count(Count), LowerBound(LowerBound) {}
294   MDNodeKeyImpl(const DISubrange *N)
295       : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
296 
297   bool isKeyOf(const DISubrange *RHS) const {
298     return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
299   }
300   unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
301 };
302 
303 template <> struct MDNodeKeyImpl<DIEnumerator> {
304   int64_t Value;
305   MDString *Name;
306 
307   MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
308   MDNodeKeyImpl(const DIEnumerator *N)
309       : Value(N->getValue()), Name(N->getRawName()) {}
310 
311   bool isKeyOf(const DIEnumerator *RHS) const {
312     return Value == RHS->getValue() && Name == RHS->getRawName();
313   }
314   unsigned getHashValue() const { return hash_combine(Value, Name); }
315 };
316 
317 template <> struct MDNodeKeyImpl<DIBasicType> {
318   unsigned Tag;
319   MDString *Name;
320   uint64_t SizeInBits;
321   uint64_t AlignInBits;
322   unsigned Encoding;
323 
324   MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
325                 uint64_t AlignInBits, unsigned Encoding)
326       : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
327         Encoding(Encoding) {}
328   MDNodeKeyImpl(const DIBasicType *N)
329       : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
330         AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
331 
332   bool isKeyOf(const DIBasicType *RHS) const {
333     return Tag == RHS->getTag() && Name == RHS->getRawName() &&
334            SizeInBits == RHS->getSizeInBits() &&
335            AlignInBits == RHS->getAlignInBits() &&
336            Encoding == RHS->getEncoding();
337   }
338   unsigned getHashValue() const {
339     return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
340   }
341 };
342 
343 template <> struct MDNodeKeyImpl<DIDerivedType> {
344   unsigned Tag;
345   MDString *Name;
346   Metadata *File;
347   unsigned Line;
348   Metadata *Scope;
349   Metadata *BaseType;
350   uint64_t SizeInBits;
351   uint64_t AlignInBits;
352   uint64_t OffsetInBits;
353   unsigned Flags;
354   Metadata *ExtraData;
355 
356   MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
357                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
358                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
359                 Metadata *ExtraData)
360       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
361         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
362         OffsetInBits(OffsetInBits), Flags(Flags), ExtraData(ExtraData) {}
363   MDNodeKeyImpl(const DIDerivedType *N)
364       : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
365         Line(N->getLine()), Scope(N->getRawScope()),
366         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
367         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
368         Flags(N->getFlags()), ExtraData(N->getRawExtraData()) {}
369 
370   bool isKeyOf(const DIDerivedType *RHS) const {
371     return Tag == RHS->getTag() && Name == RHS->getRawName() &&
372            File == RHS->getRawFile() && Line == RHS->getLine() &&
373            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
374            SizeInBits == RHS->getSizeInBits() &&
375            AlignInBits == RHS->getAlignInBits() &&
376            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
377            ExtraData == RHS->getRawExtraData();
378   }
379   unsigned getHashValue() const {
380     // If this is a member inside an ODR type, only hash the type and the name.
381     // Otherwise the hash will be stronger than
382     // MDNodeSubsetEqualImpl::isODRMember().
383     if (Tag == dwarf::DW_TAG_member && Name)
384       if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
385         if (CT->getRawIdentifier())
386           return hash_combine(Name, Scope);
387 
388     // Intentionally computes the hash on a subset of the operands for
389     // performance reason. The subset has to be significant enough to avoid
390     // collision "most of the time". There is no correctness issue in case of
391     // collision because of the full check above.
392     return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
393   }
394 };
395 
396 template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
397   typedef MDNodeKeyImpl<DIDerivedType> KeyTy;
398   static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
399     return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
400   }
401   static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
402     return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
403                        RHS);
404   }
405 
406   /// Subprograms compare equal if they declare the same function in an ODR
407   /// type.
408   static bool isODRMember(unsigned Tag, const Metadata *Scope,
409                           const MDString *Name, const DIDerivedType *RHS) {
410     // Check whether the LHS is eligible.
411     if (Tag != dwarf::DW_TAG_member || !Name)
412       return false;
413 
414     auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
415     if (!CT || !CT->getRawIdentifier())
416       return false;
417 
418     // Compare to the RHS.
419     return Tag == RHS->getTag() && Name == RHS->getRawName() &&
420            Scope == RHS->getRawScope();
421   }
422 };
423 
424 template <> struct MDNodeKeyImpl<DICompositeType> {
425   unsigned Tag;
426   MDString *Name;
427   Metadata *File;
428   unsigned Line;
429   Metadata *Scope;
430   Metadata *BaseType;
431   uint64_t SizeInBits;
432   uint64_t AlignInBits;
433   uint64_t OffsetInBits;
434   unsigned Flags;
435   Metadata *Elements;
436   unsigned RuntimeLang;
437   Metadata *VTableHolder;
438   Metadata *TemplateParams;
439   MDString *Identifier;
440 
441   MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
442                 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
443                 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
444                 Metadata *Elements, unsigned RuntimeLang,
445                 Metadata *VTableHolder, Metadata *TemplateParams,
446                 MDString *Identifier)
447       : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
448         BaseType(BaseType), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
449         OffsetInBits(OffsetInBits), Flags(Flags), Elements(Elements),
450         RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
451         TemplateParams(TemplateParams), Identifier(Identifier) {}
452   MDNodeKeyImpl(const DICompositeType *N)
453       : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
454         Line(N->getLine()), Scope(N->getRawScope()),
455         BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
456         AlignInBits(N->getAlignInBits()), OffsetInBits(N->getOffsetInBits()),
457         Flags(N->getFlags()), Elements(N->getRawElements()),
458         RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
459         TemplateParams(N->getRawTemplateParams()),
460         Identifier(N->getRawIdentifier()) {}
461 
462   bool isKeyOf(const DICompositeType *RHS) const {
463     return Tag == RHS->getTag() && Name == RHS->getRawName() &&
464            File == RHS->getRawFile() && Line == RHS->getLine() &&
465            Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
466            SizeInBits == RHS->getSizeInBits() &&
467            AlignInBits == RHS->getAlignInBits() &&
468            OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
469            Elements == RHS->getRawElements() &&
470            RuntimeLang == RHS->getRuntimeLang() &&
471            VTableHolder == RHS->getRawVTableHolder() &&
472            TemplateParams == RHS->getRawTemplateParams() &&
473            Identifier == RHS->getRawIdentifier();
474   }
475   unsigned getHashValue() const {
476     // Intentionally computes the hash on a subset of the operands for
477     // performance reason. The subset has to be significant enough to avoid
478     // collision "most of the time". There is no correctness issue in case of
479     // collision because of the full check above.
480     return hash_combine(Name, File, Line, BaseType, Scope, Elements,
481                         TemplateParams);
482   }
483 };
484 
485 template <> struct MDNodeKeyImpl<DISubroutineType> {
486   unsigned Flags;
487   uint8_t CC;
488   Metadata *TypeArray;
489 
490   MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
491       : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
492   MDNodeKeyImpl(const DISubroutineType *N)
493       : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
494 
495   bool isKeyOf(const DISubroutineType *RHS) const {
496     return Flags == RHS->getFlags() && CC == RHS->getCC() &&
497            TypeArray == RHS->getRawTypeArray();
498   }
499   unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
500 };
501 
502 template <> struct MDNodeKeyImpl<DIFile> {
503   MDString *Filename;
504   MDString *Directory;
505 
506   MDNodeKeyImpl(MDString *Filename, MDString *Directory)
507       : Filename(Filename), Directory(Directory) {}
508   MDNodeKeyImpl(const DIFile *N)
509       : Filename(N->getRawFilename()), Directory(N->getRawDirectory()) {}
510 
511   bool isKeyOf(const DIFile *RHS) const {
512     return Filename == RHS->getRawFilename() &&
513            Directory == RHS->getRawDirectory();
514   }
515   unsigned getHashValue() const { return hash_combine(Filename, Directory); }
516 };
517 
518 template <> struct MDNodeKeyImpl<DISubprogram> {
519   Metadata *Scope;
520   MDString *Name;
521   MDString *LinkageName;
522   Metadata *File;
523   unsigned Line;
524   Metadata *Type;
525   bool IsLocalToUnit;
526   bool IsDefinition;
527   unsigned ScopeLine;
528   Metadata *ContainingType;
529   unsigned Virtuality;
530   unsigned VirtualIndex;
531   int ThisAdjustment;
532   unsigned Flags;
533   bool IsOptimized;
534   Metadata *Unit;
535   Metadata *TemplateParams;
536   Metadata *Declaration;
537   Metadata *Variables;
538 
539   MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
540                 Metadata *File, unsigned Line, Metadata *Type,
541                 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
542                 Metadata *ContainingType, unsigned Virtuality,
543                 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
544                 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
545                 Metadata *Declaration, Metadata *Variables)
546       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
547         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
548         IsDefinition(IsDefinition), ScopeLine(ScopeLine),
549         ContainingType(ContainingType), Virtuality(Virtuality),
550         VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
551         Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
552         TemplateParams(TemplateParams), Declaration(Declaration),
553         Variables(Variables) {}
554   MDNodeKeyImpl(const DISubprogram *N)
555       : Scope(N->getRawScope()), Name(N->getRawName()),
556         LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
557         Line(N->getLine()), Type(N->getRawType()),
558         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
559         ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
560         Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
561         ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
562         IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
563         TemplateParams(N->getRawTemplateParams()),
564         Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()) {}
565 
566   bool isKeyOf(const DISubprogram *RHS) const {
567     return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
568            LinkageName == RHS->getRawLinkageName() &&
569            File == RHS->getRawFile() && Line == RHS->getLine() &&
570            Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
571            IsDefinition == RHS->isDefinition() &&
572            ScopeLine == RHS->getScopeLine() &&
573            ContainingType == RHS->getRawContainingType() &&
574            Virtuality == RHS->getVirtuality() &&
575            VirtualIndex == RHS->getVirtualIndex() &&
576            ThisAdjustment == RHS->getThisAdjustment() &&
577            Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
578            Unit == RHS->getUnit() &&
579            TemplateParams == RHS->getRawTemplateParams() &&
580            Declaration == RHS->getRawDeclaration() &&
581            Variables == RHS->getRawVariables();
582   }
583   unsigned getHashValue() const {
584     // If this is a declaration inside an ODR type, only hash the type and the
585     // name.  Otherwise the hash will be stronger than
586     // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
587     if (!IsDefinition && LinkageName)
588       if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
589         if (CT->getRawIdentifier())
590           return hash_combine(LinkageName, Scope);
591 
592     // Intentionally computes the hash on a subset of the operands for
593     // performance reason. The subset has to be significant enough to avoid
594     // collision "most of the time". There is no correctness issue in case of
595     // collision because of the full check above.
596     return hash_combine(Name, Scope, File, Type, Line);
597   }
598 };
599 
600 template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
601   typedef MDNodeKeyImpl<DISubprogram> KeyTy;
602   static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
603     return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
604                                     LHS.LinkageName, RHS);
605   }
606   static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
607     return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
608                                     LHS->getRawLinkageName(), RHS);
609   }
610 
611   /// Subprograms compare equal if they declare the same function in an ODR
612   /// type.
613   static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
614                                        const MDString *LinkageName,
615                                        const DISubprogram *RHS) {
616     // Check whether the LHS is eligible.
617     if (IsDefinition || !Scope || !LinkageName)
618       return false;
619 
620     auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
621     if (!CT || !CT->getRawIdentifier())
622       return false;
623 
624     // Compare to the RHS.
625     return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
626            LinkageName == RHS->getRawLinkageName();
627   }
628 };
629 
630 template <> struct MDNodeKeyImpl<DILexicalBlock> {
631   Metadata *Scope;
632   Metadata *File;
633   unsigned Line;
634   unsigned Column;
635 
636   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
637       : Scope(Scope), File(File), Line(Line), Column(Column) {}
638   MDNodeKeyImpl(const DILexicalBlock *N)
639       : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
640         Column(N->getColumn()) {}
641 
642   bool isKeyOf(const DILexicalBlock *RHS) const {
643     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
644            Line == RHS->getLine() && Column == RHS->getColumn();
645   }
646   unsigned getHashValue() const {
647     return hash_combine(Scope, File, Line, Column);
648   }
649 };
650 
651 template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
652   Metadata *Scope;
653   Metadata *File;
654   unsigned Discriminator;
655 
656   MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
657       : Scope(Scope), File(File), Discriminator(Discriminator) {}
658   MDNodeKeyImpl(const DILexicalBlockFile *N)
659       : Scope(N->getRawScope()), File(N->getRawFile()),
660         Discriminator(N->getDiscriminator()) {}
661 
662   bool isKeyOf(const DILexicalBlockFile *RHS) const {
663     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
664            Discriminator == RHS->getDiscriminator();
665   }
666   unsigned getHashValue() const {
667     return hash_combine(Scope, File, Discriminator);
668   }
669 };
670 
671 template <> struct MDNodeKeyImpl<DINamespace> {
672   Metadata *Scope;
673   Metadata *File;
674   MDString *Name;
675   unsigned Line;
676 
677   MDNodeKeyImpl(Metadata *Scope, Metadata *File, MDString *Name, unsigned Line)
678       : Scope(Scope), File(File), Name(Name), Line(Line) {}
679   MDNodeKeyImpl(const DINamespace *N)
680       : Scope(N->getRawScope()), File(N->getRawFile()), Name(N->getRawName()),
681         Line(N->getLine()) {}
682 
683   bool isKeyOf(const DINamespace *RHS) const {
684     return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
685            Name == RHS->getRawName() && Line == RHS->getLine();
686   }
687   unsigned getHashValue() const {
688     return hash_combine(Scope, File, Name, Line);
689   }
690 };
691 
692 template <> struct MDNodeKeyImpl<DIModule> {
693   Metadata *Scope;
694   MDString *Name;
695   MDString *ConfigurationMacros;
696   MDString *IncludePath;
697   MDString *ISysRoot;
698   MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
699                 MDString *IncludePath, MDString *ISysRoot)
700       : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
701         IncludePath(IncludePath), ISysRoot(ISysRoot) {}
702   MDNodeKeyImpl(const DIModule *N)
703       : Scope(N->getRawScope()), Name(N->getRawName()),
704         ConfigurationMacros(N->getRawConfigurationMacros()),
705         IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
706 
707   bool isKeyOf(const DIModule *RHS) const {
708     return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
709            ConfigurationMacros == RHS->getRawConfigurationMacros() &&
710            IncludePath == RHS->getRawIncludePath() &&
711            ISysRoot == RHS->getRawISysRoot();
712   }
713   unsigned getHashValue() const {
714     return hash_combine(Scope, Name,
715                         ConfigurationMacros, IncludePath, ISysRoot);
716   }
717 };
718 
719 template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
720   MDString *Name;
721   Metadata *Type;
722 
723   MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
724   MDNodeKeyImpl(const DITemplateTypeParameter *N)
725       : Name(N->getRawName()), Type(N->getRawType()) {}
726 
727   bool isKeyOf(const DITemplateTypeParameter *RHS) const {
728     return Name == RHS->getRawName() && Type == RHS->getRawType();
729   }
730   unsigned getHashValue() const { return hash_combine(Name, Type); }
731 };
732 
733 template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
734   unsigned Tag;
735   MDString *Name;
736   Metadata *Type;
737   Metadata *Value;
738 
739   MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
740       : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
741   MDNodeKeyImpl(const DITemplateValueParameter *N)
742       : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
743         Value(N->getValue()) {}
744 
745   bool isKeyOf(const DITemplateValueParameter *RHS) const {
746     return Tag == RHS->getTag() && Name == RHS->getRawName() &&
747            Type == RHS->getRawType() && Value == RHS->getValue();
748   }
749   unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
750 };
751 
752 template <> struct MDNodeKeyImpl<DIGlobalVariable> {
753   Metadata *Scope;
754   MDString *Name;
755   MDString *LinkageName;
756   Metadata *File;
757   unsigned Line;
758   Metadata *Type;
759   bool IsLocalToUnit;
760   bool IsDefinition;
761   Metadata *Variable;
762   Metadata *StaticDataMemberDeclaration;
763 
764   MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
765                 Metadata *File, unsigned Line, Metadata *Type,
766                 bool IsLocalToUnit, bool IsDefinition, Metadata *Variable,
767                 Metadata *StaticDataMemberDeclaration)
768       : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
769         Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
770         IsDefinition(IsDefinition), Variable(Variable),
771         StaticDataMemberDeclaration(StaticDataMemberDeclaration) {}
772   MDNodeKeyImpl(const DIGlobalVariable *N)
773       : Scope(N->getRawScope()), Name(N->getRawName()),
774         LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
775         Line(N->getLine()), Type(N->getRawType()),
776         IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
777         Variable(N->getRawVariable()),
778         StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {}
779 
780   bool isKeyOf(const DIGlobalVariable *RHS) const {
781     return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
782            LinkageName == RHS->getRawLinkageName() &&
783            File == RHS->getRawFile() && Line == RHS->getLine() &&
784            Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
785            IsDefinition == RHS->isDefinition() &&
786            Variable == RHS->getRawVariable() &&
787            StaticDataMemberDeclaration ==
788                RHS->getRawStaticDataMemberDeclaration();
789   }
790   unsigned getHashValue() const {
791     return hash_combine(Scope, Name, LinkageName, File, Line, Type,
792                         IsLocalToUnit, IsDefinition, Variable,
793                         StaticDataMemberDeclaration);
794   }
795 };
796 
797 template <> struct MDNodeKeyImpl<DILocalVariable> {
798   Metadata *Scope;
799   MDString *Name;
800   Metadata *File;
801   unsigned Line;
802   Metadata *Type;
803   unsigned Arg;
804   unsigned Flags;
805 
806   MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
807                 Metadata *Type, unsigned Arg, unsigned Flags)
808       : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
809         Flags(Flags) {}
810   MDNodeKeyImpl(const DILocalVariable *N)
811       : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
812         Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
813         Flags(N->getFlags()) {}
814 
815   bool isKeyOf(const DILocalVariable *RHS) const {
816     return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
817            File == RHS->getRawFile() && Line == RHS->getLine() &&
818            Type == RHS->getRawType() && Arg == RHS->getArg() &&
819            Flags == RHS->getFlags();
820   }
821   unsigned getHashValue() const {
822     return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
823   }
824 };
825 
826 template <> struct MDNodeKeyImpl<DIExpression> {
827   ArrayRef<uint64_t> Elements;
828 
829   MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
830   MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
831 
832   bool isKeyOf(const DIExpression *RHS) const {
833     return Elements == RHS->getElements();
834   }
835   unsigned getHashValue() const {
836     return hash_combine_range(Elements.begin(), Elements.end());
837   }
838 };
839 
840 template <> struct MDNodeKeyImpl<DIObjCProperty> {
841   MDString *Name;
842   Metadata *File;
843   unsigned Line;
844   MDString *GetterName;
845   MDString *SetterName;
846   unsigned Attributes;
847   Metadata *Type;
848 
849   MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
850                 MDString *GetterName, MDString *SetterName, unsigned Attributes,
851                 Metadata *Type)
852       : Name(Name), File(File), Line(Line), GetterName(GetterName),
853         SetterName(SetterName), Attributes(Attributes), Type(Type) {}
854   MDNodeKeyImpl(const DIObjCProperty *N)
855       : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
856         GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
857         Attributes(N->getAttributes()), Type(N->getRawType()) {}
858 
859   bool isKeyOf(const DIObjCProperty *RHS) const {
860     return Name == RHS->getRawName() && File == RHS->getRawFile() &&
861            Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
862            SetterName == RHS->getRawSetterName() &&
863            Attributes == RHS->getAttributes() && Type == RHS->getRawType();
864   }
865   unsigned getHashValue() const {
866     return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
867                         Type);
868   }
869 };
870 
871 template <> struct MDNodeKeyImpl<DIImportedEntity> {
872   unsigned Tag;
873   Metadata *Scope;
874   Metadata *Entity;
875   unsigned Line;
876   MDString *Name;
877 
878   MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, unsigned Line,
879                 MDString *Name)
880       : Tag(Tag), Scope(Scope), Entity(Entity), Line(Line), Name(Name) {}
881   MDNodeKeyImpl(const DIImportedEntity *N)
882       : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
883         Line(N->getLine()), Name(N->getRawName()) {}
884 
885   bool isKeyOf(const DIImportedEntity *RHS) const {
886     return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
887            Entity == RHS->getRawEntity() && Line == RHS->getLine() &&
888            Name == RHS->getRawName();
889   }
890   unsigned getHashValue() const {
891     return hash_combine(Tag, Scope, Entity, Line, Name);
892   }
893 };
894 
895 template <> struct MDNodeKeyImpl<DIMacro> {
896   unsigned MIType;
897   unsigned Line;
898   MDString *Name;
899   MDString *Value;
900 
901   MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
902       : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
903   MDNodeKeyImpl(const DIMacro *N)
904       : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
905         Value(N->getRawValue()) {}
906 
907   bool isKeyOf(const DIMacro *RHS) const {
908     return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
909            Name == RHS->getRawName() && Value == RHS->getRawValue();
910   }
911   unsigned getHashValue() const {
912     return hash_combine(MIType, Line, Name, Value);
913   }
914 };
915 
916 template <> struct MDNodeKeyImpl<DIMacroFile> {
917   unsigned MIType;
918   unsigned Line;
919   Metadata *File;
920   Metadata *Elements;
921 
922   MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
923                 Metadata *Elements)
924       : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
925   MDNodeKeyImpl(const DIMacroFile *N)
926       : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
927         Elements(N->getRawElements()) {}
928 
929   bool isKeyOf(const DIMacroFile *RHS) const {
930     return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
931            File == RHS->getRawFile() && File == RHS->getRawElements();
932   }
933   unsigned getHashValue() const {
934     return hash_combine(MIType, Line, File, Elements);
935   }
936 };
937 
938 /// \brief DenseMapInfo for MDNode subclasses.
939 template <class NodeTy> struct MDNodeInfo {
940   typedef MDNodeKeyImpl<NodeTy> KeyTy;
941   typedef MDNodeSubsetEqualImpl<NodeTy> SubsetEqualTy;
942   static inline NodeTy *getEmptyKey() {
943     return DenseMapInfo<NodeTy *>::getEmptyKey();
944   }
945   static inline NodeTy *getTombstoneKey() {
946     return DenseMapInfo<NodeTy *>::getTombstoneKey();
947   }
948   static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
949   static unsigned getHashValue(const NodeTy *N) {
950     return KeyTy(N).getHashValue();
951   }
952   static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
953     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
954       return false;
955     return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
956   }
957   static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
958     if (LHS == RHS)
959       return true;
960     if (RHS == getEmptyKey() || RHS == getTombstoneKey())
961       return false;
962     return SubsetEqualTy::isSubsetEqual(LHS, RHS);
963   }
964 };
965 
966 #define HANDLE_MDNODE_LEAF(CLASS) typedef MDNodeInfo<CLASS> CLASS##Info;
967 #include "llvm/IR/Metadata.def"
968 
969 /// \brief Map-like storage for metadata attachments.
970 class MDAttachmentMap {
971   SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
972 
973 public:
974   bool empty() const { return Attachments.empty(); }
975   size_t size() const { return Attachments.size(); }
976 
977   /// \brief Get a particular attachment (if any).
978   MDNode *lookup(unsigned ID) const;
979 
980   /// \brief Set an attachment to a particular node.
981   ///
982   /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
983   /// ID (if anyway).
984   void set(unsigned ID, MDNode &MD);
985 
986   /// \brief Remove an attachment.
987   ///
988   /// Remove the attachment at \c ID, if any.
989   void erase(unsigned ID);
990 
991   /// \brief Copy out all the attachments.
992   ///
993   /// Copies all the current attachments into \c Result, sorting by attachment
994   /// ID.  This function does \em not clear \c Result.
995   void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
996 
997   /// \brief Erase matching attachments.
998   ///
999   /// Erases all attachments matching the \c shouldRemove predicate.
1000   template <class PredTy> void remove_if(PredTy shouldRemove) {
1001     Attachments.erase(
1002         std::remove_if(Attachments.begin(), Attachments.end(), shouldRemove),
1003         Attachments.end());
1004   }
1005 };
1006 
1007 /// Multimap-like storage for metadata attachments for globals. This differs
1008 /// from MDAttachmentMap in that it allows multiple attachments per metadata
1009 /// kind.
1010 class MDGlobalAttachmentMap {
1011   struct Attachment {
1012     unsigned MDKind;
1013     TrackingMDNodeRef Node;
1014   };
1015   SmallVector<Attachment, 1> Attachments;
1016 
1017 public:
1018   bool empty() const { return Attachments.empty(); }
1019 
1020   /// Appends all attachments with the given ID to \c Result in insertion order.
1021   /// If the global has no attachments with the given ID, or if ID is invalid,
1022   /// leaves Result unchanged.
1023   void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1024 
1025   void insert(unsigned ID, MDNode &MD);
1026   void erase(unsigned ID);
1027 
1028   /// Appends all attachments for the global to \c Result, sorting by attachment
1029   /// ID. Attachments with the same ID appear in insertion order. This function
1030   /// does \em not clear \c Result.
1031   void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1032 };
1033 
1034 class LLVMContextImpl {
1035 public:
1036   /// OwnedModules - The set of modules instantiated in this context, and which
1037   /// will be automatically deleted if this context is deleted.
1038   SmallPtrSet<Module*, 4> OwnedModules;
1039 
1040   LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler;
1041   void *InlineAsmDiagContext;
1042 
1043   LLVMContext::DiagnosticHandlerTy DiagnosticHandler;
1044   void *DiagnosticContext;
1045   bool RespectDiagnosticFilters;
1046 
1047   LLVMContext::YieldCallbackTy YieldCallback;
1048   void *YieldOpaqueHandle;
1049 
1050   typedef DenseMap<APInt, ConstantInt *, DenseMapAPIntKeyInfo> IntMapTy;
1051   IntMapTy IntConstants;
1052 
1053   typedef DenseMap<APFloat, ConstantFP *, DenseMapAPFloatKeyInfo> FPMapTy;
1054   FPMapTy FPConstants;
1055 
1056   FoldingSet<AttributeImpl> AttrsSet;
1057   FoldingSet<AttributeSetImpl> AttrsLists;
1058   FoldingSet<AttributeSetNode> AttrsSetNodes;
1059 
1060   StringMap<MDString, BumpPtrAllocator> MDStringCache;
1061   DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1062   DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
1063 
1064   DenseMap<const Value*, ValueName*> ValueNames;
1065 
1066 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
1067   DenseSet<CLASS *, CLASS##Info> CLASS##s;
1068 #include "llvm/IR/Metadata.def"
1069 
1070   // Optional map for looking up composite types by identifier.
1071   Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
1072 
1073   // MDNodes may be uniqued or not uniqued.  When they're not uniqued, they
1074   // aren't in the MDNodeSet, but they're still shared between objects, so no
1075   // one object can destroy them.  Keep track of them here so we can delete
1076   // them on context teardown.
1077   std::vector<MDNode *> DistinctMDNodes;
1078 
1079   DenseMap<Type*, ConstantAggregateZero*> CAZConstants;
1080 
1081   typedef ConstantUniqueMap<ConstantArray> ArrayConstantsTy;
1082   ArrayConstantsTy ArrayConstants;
1083 
1084   typedef ConstantUniqueMap<ConstantStruct> StructConstantsTy;
1085   StructConstantsTy StructConstants;
1086 
1087   typedef ConstantUniqueMap<ConstantVector> VectorConstantsTy;
1088   VectorConstantsTy VectorConstants;
1089 
1090   DenseMap<PointerType*, ConstantPointerNull*> CPNConstants;
1091 
1092   DenseMap<Type*, UndefValue*> UVConstants;
1093 
1094   StringMap<ConstantDataSequential*> CDSConstants;
1095 
1096   DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1097     BlockAddresses;
1098   ConstantUniqueMap<ConstantExpr> ExprConstants;
1099 
1100   ConstantUniqueMap<InlineAsm> InlineAsms;
1101 
1102   ConstantInt *TheTrueVal;
1103   ConstantInt *TheFalseVal;
1104 
1105   std::unique_ptr<ConstantTokenNone> TheNoneToken;
1106 
1107   // Basic type instances.
1108   Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
1109   Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
1110   IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
1111 
1112 
1113   /// TypeAllocator - All dynamically allocated types are allocated from this.
1114   /// They live forever until the context is torn down.
1115   BumpPtrAllocator TypeAllocator;
1116 
1117   DenseMap<unsigned, IntegerType*> IntegerTypes;
1118 
1119   typedef DenseSet<FunctionType *, FunctionTypeKeyInfo> FunctionTypeSet;
1120   FunctionTypeSet FunctionTypes;
1121   typedef DenseSet<StructType *, AnonStructTypeKeyInfo> StructTypeSet;
1122   StructTypeSet AnonStructTypes;
1123   StringMap<StructType*> NamedStructTypes;
1124   unsigned NamedStructTypesUniqueID;
1125 
1126   DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1127   DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1128   DenseMap<Type*, PointerType*> PointerTypes;  // Pointers in AddrSpace = 0
1129   DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
1130 
1131 
1132   /// ValueHandles - This map keeps track of all of the value handles that are
1133   /// watching a Value*.  The Value::HasValueHandle bit is used to know
1134   /// whether or not a value has an entry in this map.
1135   typedef DenseMap<Value*, ValueHandleBase*> ValueHandlesTy;
1136   ValueHandlesTy ValueHandles;
1137 
1138   /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1139   StringMap<unsigned> CustomMDKindNames;
1140 
1141   /// Collection of per-instruction metadata used in this context.
1142   DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
1143 
1144   /// Collection of per-GlobalObject metadata used in this context.
1145   DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
1146 
1147   /// DiscriminatorTable - This table maps file:line locations to an
1148   /// integer representing the next DWARF path discriminator to assign to
1149   /// instructions in different blocks at the same location.
1150   DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1151 
1152   int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1153   int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
1154 
1155   /// \brief A set of interned tags for operand bundles.  The StringMap maps
1156   /// bundle tags to their IDs.
1157   ///
1158   /// \see LLVMContext::getOperandBundleTagID
1159   StringMap<uint32_t> BundleTagCache;
1160 
1161   StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1162   void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1163   uint32_t getOperandBundleTagID(StringRef Tag) const;
1164 
1165   /// Maintain the GC name for each function.
1166   ///
1167   /// This saves allocating an additional word in Function for programs which
1168   /// do not use GC (i.e., most programs) at the cost of increased overhead for
1169   /// clients which do use GC.
1170   DenseMap<const Function*, std::string> GCNames;
1171 
1172   /// Flag to indicate if Value (other than GlobalValue) retains their name or
1173   /// not.
1174   bool DiscardValueNames = false;
1175 
1176   LLVMContextImpl(LLVMContext &C);
1177   ~LLVMContextImpl();
1178 
1179   /// Destroy the ConstantArrays if they are not used.
1180   void dropTriviallyDeadConstantArrays();
1181 
1182   /// \brief Access the object which manages optimization bisection for failure
1183   /// analysis.
1184   OptBisect &getOptBisect();
1185 };
1186 
1187 }
1188 
1189 #endif
1190