LLVM  7.0.0svn
LLVMContextImpl.h
Go to the documentation of this file.
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/DenseMapInfo.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/FoldingSet.h"
27 #include "llvm/ADT/Hashing.h"
28 #include "llvm/ADT/Optional.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringMap.h"
33 #include "llvm/ADT/StringRef.h"
34 #include "llvm/ADT/StringSet.h"
36 #include "llvm/IR/Constants.h"
38 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/LLVMContext.h"
40 #include "llvm/IR/Metadata.h"
41 #include "llvm/IR/TrackingMDRef.h"
42 #include "llvm/Support/Allocator.h"
43 #include "llvm/Support/Casting.h"
45 #include <algorithm>
46 #include <cassert>
47 #include <cstddef>
48 #include <cstdint>
49 #include <memory>
50 #include <string>
51 #include <utility>
52 #include <vector>
53 
54 namespace llvm {
55 
56 class ConstantFP;
57 class ConstantInt;
58 class Type;
59 class Value;
60 class ValueHandleBase;
61 
63  static inline APInt getEmptyKey() {
64  APInt V(nullptr, 0);
65  V.U.VAL = 0;
66  return V;
67  }
68 
69  static inline APInt getTombstoneKey() {
70  APInt V(nullptr, 0);
71  V.U.VAL = 1;
72  return V;
73  }
74 
75  static unsigned getHashValue(const APInt &Key) {
76  return static_cast<unsigned>(hash_value(Key));
77  }
78 
79  static bool isEqual(const APInt &LHS, const APInt &RHS) {
80  return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
81  }
82 };
83 
85  static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
86  static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
87 
88  static unsigned getHashValue(const APFloat &Key) {
89  return static_cast<unsigned>(hash_value(Key));
90  }
91 
92  static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
93  return LHS.bitwiseIsEqual(RHS);
94  }
95 };
96 
98  struct KeyTy {
100  bool isPacked;
101 
102  KeyTy(const ArrayRef<Type*>& E, bool P) :
103  ETypes(E), isPacked(P) {}
104 
106  : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
107 
108  bool operator==(const KeyTy& that) const {
109  if (isPacked != that.isPacked)
110  return false;
111  if (ETypes != that.ETypes)
112  return false;
113  return true;
114  }
115  bool operator!=(const KeyTy& that) const {
116  return !this->operator==(that);
117  }
118  };
119 
120  static inline StructType* getEmptyKey() {
122  }
123 
124  static inline StructType* getTombstoneKey() {
126  }
127 
128  static unsigned getHashValue(const KeyTy& Key) {
129  return hash_combine(hash_combine_range(Key.ETypes.begin(),
130  Key.ETypes.end()),
131  Key.isPacked);
132  }
133 
134  static unsigned getHashValue(const StructType *ST) {
135  return getHashValue(KeyTy(ST));
136  }
137 
138  static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
139  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
140  return false;
141  return LHS == KeyTy(RHS);
142  }
143 
144  static bool isEqual(const StructType *LHS, const StructType *RHS) {
145  return LHS == RHS;
146  }
147 };
148 
150  struct KeyTy {
151  const Type *ReturnType;
153  bool isVarArg;
154 
155  KeyTy(const Type* R, const ArrayRef<Type*>& P, bool V) :
156  ReturnType(R), Params(P), isVarArg(V) {}
157  KeyTy(const FunctionType *FT)
158  : ReturnType(FT->getReturnType()), Params(FT->params()),
159  isVarArg(FT->isVarArg()) {}
160 
161  bool operator==(const KeyTy& that) const {
162  if (ReturnType != that.ReturnType)
163  return false;
164  if (isVarArg != that.isVarArg)
165  return false;
166  if (Params != that.Params)
167  return false;
168  return true;
169  }
170  bool operator!=(const KeyTy& that) const {
171  return !this->operator==(that);
172  }
173  };
174 
175  static inline FunctionType* getEmptyKey() {
177  }
178 
179  static inline FunctionType* getTombstoneKey() {
181  }
182 
183  static unsigned getHashValue(const KeyTy& Key) {
184  return hash_combine(Key.ReturnType,
185  hash_combine_range(Key.Params.begin(),
186  Key.Params.end()),
187  Key.isVarArg);
188  }
189 
190  static unsigned getHashValue(const FunctionType *FT) {
191  return getHashValue(KeyTy(FT));
192  }
193 
194  static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
195  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
196  return false;
197  return LHS == KeyTy(RHS);
198  }
199 
200  static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
201  return LHS == RHS;
202  }
203 };
204 
205 /// \brief Structure for hashing arbitrary MDNode operands.
207  ArrayRef<Metadata *> RawOps;
209  unsigned Hash;
210 
211 protected:
213  : RawOps(Ops), Hash(calculateHash(Ops)) {}
214 
215  template <class NodeTy>
216  MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
217  : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
218 
219  template <class NodeTy>
220  bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
221  if (getHash() != RHS->getHash())
222  return false;
223 
224  assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
225  return RawOps.empty() ? compareOps(Ops, RHS, Offset)
226  : compareOps(RawOps, RHS, Offset);
227  }
228 
229  static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
230 
231 private:
232  template <class T>
233  static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
234  if (Ops.size() != RHS->getNumOperands() - Offset)
235  return false;
236  return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
237  }
238 
239  static unsigned calculateHash(ArrayRef<Metadata *> Ops);
240 
241 public:
242  unsigned getHash() const { return Hash; }
243 };
244 
245 template <class NodeTy> struct MDNodeKeyImpl;
246 
247 /// Configuration point for MDNodeInfo::isEqual().
248 template <class NodeTy> struct MDNodeSubsetEqualImpl {
250 
251  static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
252  return false;
253  }
254 
255  static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
256  return false;
257  }
258 };
259 
260 /// \brief DenseMapInfo for MDTuple.
261 ///
262 /// Note that we don't need the is-function-local bit, since that's implicit in
263 /// the operands.
264 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
267 
268  bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
269 
270  unsigned getHashValue() const { return getHash(); }
271 
272  static unsigned calculateHash(MDTuple *N) {
273  return MDNodeOpsKey::calculateHash(N);
274  }
275 };
276 
277 /// \brief DenseMapInfo for DILocation.
278 template <> struct MDNodeKeyImpl<DILocation> {
279  unsigned Line;
280  unsigned Column;
283 
284  MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
285  Metadata *InlinedAt)
286  : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
288  : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
289  InlinedAt(L->getRawInlinedAt()) {}
290 
291  bool isKeyOf(const DILocation *RHS) const {
292  return Line == RHS->getLine() && Column == RHS->getColumn() &&
293  Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
294  }
295 
296  unsigned getHashValue() const {
297  return hash_combine(Line, Column, Scope, InlinedAt);
298  }
299 };
300 
301 /// \brief DenseMapInfo for GenericDINode.
302 template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
303  unsigned Tag;
305 
306  MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
307  : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
309  : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
310 
311  bool isKeyOf(const GenericDINode *RHS) const {
312  return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
313  compareOps(RHS, 1);
314  }
315 
316  unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
317 
318  static unsigned calculateHash(GenericDINode *N) {
319  return MDNodeOpsKey::calculateHash(N, 1);
320  }
321 };
322 
323 template <> struct MDNodeKeyImpl<DISubrange> {
325  int64_t LowerBound;
326 
327  MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
328  : CountNode(CountNode), LowerBound(LowerBound) {}
330  : CountNode(N->getRawCountNode()),
331  LowerBound(N->getLowerBound()) {}
332 
333  bool isKeyOf(const DISubrange *RHS) const {
334  if (LowerBound != RHS->getLowerBound())
335  return false;
336 
337  if (auto *RHSCount = RHS->getCount().dyn_cast<ConstantInt*>())
338  if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
339  if (RHSCount->getSExtValue() ==
340  cast<ConstantInt>(MD->getValue())->getSExtValue())
341  return true;
342 
343  return CountNode == RHS->getRawCountNode();
344  }
345 
346  unsigned getHashValue() const {
347  if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
348  return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
349  LowerBound);
350  return hash_combine(CountNode, LowerBound);
351  }
352 };
353 
354 template <> struct MDNodeKeyImpl<DIEnumerator> {
355  int64_t Value;
358 
359  MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
360  : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
362  : Value(N->getValue()), Name(N->getRawName()),
363  IsUnsigned(N->isUnsigned()) {}
364 
365  bool isKeyOf(const DIEnumerator *RHS) const {
366  return Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
367  Name == RHS->getRawName();
368  }
369 
370  unsigned getHashValue() const { return hash_combine(Value, Name); }
371 };
372 
373 template <> struct MDNodeKeyImpl<DIBasicType> {
374  unsigned Tag;
376  uint64_t SizeInBits;
378  unsigned Encoding;
379 
380  MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
381  uint32_t AlignInBits, unsigned Encoding)
382  : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
383  Encoding(Encoding) {}
385  : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
386  AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
387 
388  bool isKeyOf(const DIBasicType *RHS) const {
389  return Tag == RHS->getTag() && Name == RHS->getRawName() &&
390  SizeInBits == RHS->getSizeInBits() &&
391  AlignInBits == RHS->getAlignInBits() &&
392  Encoding == RHS->getEncoding();
393  }
394 
395  unsigned getHashValue() const {
396  return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
397  }
398 };
399 
400 template <> struct MDNodeKeyImpl<DIDerivedType> {
401  unsigned Tag;
404  unsigned Line;
407  uint64_t SizeInBits;
408  uint64_t OffsetInBits;
411  unsigned Flags;
413 
414  MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
415  Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
416  uint32_t AlignInBits, uint64_t OffsetInBits,
417  Optional<unsigned> DWARFAddressSpace, unsigned Flags,
418  Metadata *ExtraData)
419  : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
420  BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
421  AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
422  Flags(Flags), ExtraData(ExtraData) {}
424  : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
425  Line(N->getLine()), Scope(N->getRawScope()),
426  BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
427  OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
428  DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
429  ExtraData(N->getRawExtraData()) {}
430 
431  bool isKeyOf(const DIDerivedType *RHS) const {
432  return Tag == RHS->getTag() && Name == RHS->getRawName() &&
433  File == RHS->getRawFile() && Line == RHS->getLine() &&
434  Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
435  SizeInBits == RHS->getSizeInBits() &&
436  AlignInBits == RHS->getAlignInBits() &&
437  OffsetInBits == RHS->getOffsetInBits() &&
438  DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
439  Flags == RHS->getFlags() &&
440  ExtraData == RHS->getRawExtraData();
441  }
442 
443  unsigned getHashValue() const {
444  // If this is a member inside an ODR type, only hash the type and the name.
445  // Otherwise the hash will be stronger than
446  // MDNodeSubsetEqualImpl::isODRMember().
447  if (Tag == dwarf::DW_TAG_member && Name)
448  if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
449  if (CT->getRawIdentifier())
450  return hash_combine(Name, Scope);
451 
452  // Intentionally computes the hash on a subset of the operands for
453  // performance reason. The subset has to be significant enough to avoid
454  // collision "most of the time". There is no correctness issue in case of
455  // collision because of the full check above.
456  return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
457  }
458 };
459 
462 
463  static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
464  return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
465  }
466 
467  static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
468  return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
469  RHS);
470  }
471 
472  /// Subprograms compare equal if they declare the same function in an ODR
473  /// type.
474  static bool isODRMember(unsigned Tag, const Metadata *Scope,
475  const MDString *Name, const DIDerivedType *RHS) {
476  // Check whether the LHS is eligible.
477  if (Tag != dwarf::DW_TAG_member || !Name)
478  return false;
479 
480  auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
481  if (!CT || !CT->getRawIdentifier())
482  return false;
483 
484  // Compare to the RHS.
485  return Tag == RHS->getTag() && Name == RHS->getRawName() &&
486  Scope == RHS->getRawScope();
487  }
488 };
489 
490 template <> struct MDNodeKeyImpl<DICompositeType> {
491  unsigned Tag;
494  unsigned Line;
497  uint64_t SizeInBits;
498  uint64_t OffsetInBits;
500  unsigned Flags;
502  unsigned RuntimeLang;
507 
508  MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
509  Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
510  uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
511  Metadata *Elements, unsigned RuntimeLang,
512  Metadata *VTableHolder, Metadata *TemplateParams,
513  MDString *Identifier, Metadata *Discriminator)
514  : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
515  BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
516  AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
517  RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
518  TemplateParams(TemplateParams), Identifier(Identifier),
519  Discriminator(Discriminator) {}
521  : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
522  Line(N->getLine()), Scope(N->getRawScope()),
523  BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
524  OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
525  Flags(N->getFlags()), Elements(N->getRawElements()),
526  RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
527  TemplateParams(N->getRawTemplateParams()),
528  Identifier(N->getRawIdentifier()),
529  Discriminator(N->getRawDiscriminator()) {}
530 
531  bool isKeyOf(const DICompositeType *RHS) const {
532  return Tag == RHS->getTag() && Name == RHS->getRawName() &&
533  File == RHS->getRawFile() && Line == RHS->getLine() &&
534  Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
535  SizeInBits == RHS->getSizeInBits() &&
536  AlignInBits == RHS->getAlignInBits() &&
537  OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
538  Elements == RHS->getRawElements() &&
539  RuntimeLang == RHS->getRuntimeLang() &&
540  VTableHolder == RHS->getRawVTableHolder() &&
541  TemplateParams == RHS->getRawTemplateParams() &&
542  Identifier == RHS->getRawIdentifier() &&
543  Discriminator == RHS->getRawDiscriminator();
544  }
545 
546  unsigned getHashValue() const {
547  // Intentionally computes the hash on a subset of the operands for
548  // performance reason. The subset has to be significant enough to avoid
549  // collision "most of the time". There is no correctness issue in case of
550  // collision because of the full check above.
551  return hash_combine(Name, File, Line, BaseType, Scope, Elements,
552  TemplateParams);
553  }
554 };
555 
556 template <> struct MDNodeKeyImpl<DISubroutineType> {
557  unsigned Flags;
558  uint8_t CC;
560 
561  MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
562  : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
564  : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
565 
566  bool isKeyOf(const DISubroutineType *RHS) const {
567  return Flags == RHS->getFlags() && CC == RHS->getCC() &&
568  TypeArray == RHS->getRawTypeArray();
569  }
570 
571  unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
572 };
573 
574 template <> struct MDNodeKeyImpl<DIFile> {
578 
579  MDNodeKeyImpl(MDString *Filename, MDString *Directory,
581  : Filename(Filename), Directory(Directory), Checksum(Checksum) {}
583  : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
584  Checksum(N->getRawChecksum()) {}
585 
586  bool isKeyOf(const DIFile *RHS) const {
587  return Filename == RHS->getRawFilename() &&
588  Directory == RHS->getRawDirectory() &&
589  Checksum == RHS->getRawChecksum();
590  }
591 
592  unsigned getHashValue() const {
593  if (Checksum)
594  return hash_combine(Filename, Directory, Checksum->Kind, Checksum->Value);
595  return hash_combine(Filename, Directory);
596  }
597 };
598 
599 template <> struct MDNodeKeyImpl<DISubprogram> {
604  unsigned Line;
608  unsigned ScopeLine;
610  unsigned Virtuality;
611  unsigned VirtualIndex;
613  unsigned Flags;
620 
621  MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
622  Metadata *File, unsigned Line, Metadata *Type,
623  bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
624  Metadata *ContainingType, unsigned Virtuality,
625  unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
626  bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
627  Metadata *Declaration, Metadata *Variables,
628  Metadata *ThrownTypes)
629  : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
630  Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
631  IsDefinition(IsDefinition), ScopeLine(ScopeLine),
632  ContainingType(ContainingType), Virtuality(Virtuality),
633  VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
634  Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
635  TemplateParams(TemplateParams), Declaration(Declaration),
636  Variables(Variables), ThrownTypes(ThrownTypes) {}
638  : Scope(N->getRawScope()), Name(N->getRawName()),
639  LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
640  Line(N->getLine()), Type(N->getRawType()),
641  IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
642  ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
643  Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
644  ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
645  IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
646  TemplateParams(N->getRawTemplateParams()),
647  Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()),
648  ThrownTypes(N->getRawThrownTypes()) {}
649 
650  bool isKeyOf(const DISubprogram *RHS) const {
651  return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
652  LinkageName == RHS->getRawLinkageName() &&
653  File == RHS->getRawFile() && Line == RHS->getLine() &&
654  Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
655  IsDefinition == RHS->isDefinition() &&
656  ScopeLine == RHS->getScopeLine() &&
657  ContainingType == RHS->getRawContainingType() &&
658  Virtuality == RHS->getVirtuality() &&
659  VirtualIndex == RHS->getVirtualIndex() &&
660  ThisAdjustment == RHS->getThisAdjustment() &&
661  Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
662  Unit == RHS->getUnit() &&
663  TemplateParams == RHS->getRawTemplateParams() &&
664  Declaration == RHS->getRawDeclaration() &&
665  Variables == RHS->getRawVariables() &&
666  ThrownTypes == RHS->getRawThrownTypes();
667  }
668 
669  unsigned getHashValue() const {
670  // If this is a declaration inside an ODR type, only hash the type and the
671  // name. Otherwise the hash will be stronger than
672  // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
673  if (!IsDefinition && LinkageName)
674  if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
675  if (CT->getRawIdentifier())
676  return hash_combine(LinkageName, Scope);
677 
678  // Intentionally computes the hash on a subset of the operands for
679  // performance reason. The subset has to be significant enough to avoid
680  // collision "most of the time". There is no correctness issue in case of
681  // collision because of the full check above.
682  return hash_combine(Name, Scope, File, Type, Line);
683  }
684 };
685 
686 template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
688 
689  static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
690  return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
691  LHS.LinkageName, LHS.TemplateParams, RHS);
692  }
693 
694  static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
695  return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
696  LHS->getRawLinkageName(),
697  LHS->getRawTemplateParams(), RHS);
698  }
699 
700  /// Subprograms compare equal if they declare the same function in an ODR
701  /// type.
702  static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
703  const MDString *LinkageName,
704  const Metadata *TemplateParams,
705  const DISubprogram *RHS) {
706  // Check whether the LHS is eligible.
707  if (IsDefinition || !Scope || !LinkageName)
708  return false;
709 
710  auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
711  if (!CT || !CT->getRawIdentifier())
712  return false;
713 
714  // Compare to the RHS.
715  // FIXME: We need to compare template parameters here to avoid incorrect
716  // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
717  // has a non-ODR template parameter (i.e., a DICompositeType that does not
718  // have an identifier). Eventually we should decouple ODR logic from
719  // uniquing logic.
720  return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
721  LinkageName == RHS->getRawLinkageName() &&
722  TemplateParams == RHS->getRawTemplateParams();
723  }
724 };
725 
726 template <> struct MDNodeKeyImpl<DILexicalBlock> {
729  unsigned Line;
730  unsigned Column;
731 
732  MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
733  : Scope(Scope), File(File), Line(Line), Column(Column) {}
735  : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
736  Column(N->getColumn()) {}
737 
738  bool isKeyOf(const DILexicalBlock *RHS) const {
739  return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
740  Line == RHS->getLine() && Column == RHS->getColumn();
741  }
742 
743  unsigned getHashValue() const {
744  return hash_combine(Scope, File, Line, Column);
745  }
746 };
747 
748 template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
751  unsigned Discriminator;
752 
753  MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
754  : Scope(Scope), File(File), Discriminator(Discriminator) {}
756  : Scope(N->getRawScope()), File(N->getRawFile()),
757  Discriminator(N->getDiscriminator()) {}
758 
759  bool isKeyOf(const DILexicalBlockFile *RHS) const {
760  return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
761  Discriminator == RHS->getDiscriminator();
762  }
763 
764  unsigned getHashValue() const {
765  return hash_combine(Scope, File, Discriminator);
766  }
767 };
768 
769 template <> struct MDNodeKeyImpl<DINamespace> {
773 
774  MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
775  : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
777  : Scope(N->getRawScope()), Name(N->getRawName()),
778  ExportSymbols(N->getExportSymbols()) {}
779 
780  bool isKeyOf(const DINamespace *RHS) const {
781  return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
782  ExportSymbols == RHS->getExportSymbols();
783  }
784 
785  unsigned getHashValue() const {
786  return hash_combine(Scope, Name);
787  }
788 };
789 
790 template <> struct MDNodeKeyImpl<DIModule> {
796 
797  MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
798  MDString *IncludePath, MDString *ISysRoot)
799  : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
800  IncludePath(IncludePath), ISysRoot(ISysRoot) {}
802  : Scope(N->getRawScope()), Name(N->getRawName()),
803  ConfigurationMacros(N->getRawConfigurationMacros()),
804  IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
805 
806  bool isKeyOf(const DIModule *RHS) const {
807  return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
808  ConfigurationMacros == RHS->getRawConfigurationMacros() &&
809  IncludePath == RHS->getRawIncludePath() &&
810  ISysRoot == RHS->getRawISysRoot();
811  }
812 
813  unsigned getHashValue() const {
814  return hash_combine(Scope, Name,
815  ConfigurationMacros, IncludePath, ISysRoot);
816  }
817 };
818 
822 
823  MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
825  : Name(N->getRawName()), Type(N->getRawType()) {}
826 
827  bool isKeyOf(const DITemplateTypeParameter *RHS) const {
828  return Name == RHS->getRawName() && Type == RHS->getRawType();
829  }
830 
831  unsigned getHashValue() const { return hash_combine(Name, Type); }
832 };
833 
835  unsigned Tag;
839 
840  MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
841  : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
843  : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
844  Value(N->getValue()) {}
845 
846  bool isKeyOf(const DITemplateValueParameter *RHS) const {
847  return Tag == RHS->getTag() && Name == RHS->getRawName() &&
848  Type == RHS->getRawType() && Value == RHS->getValue();
849  }
850 
851  unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
852 };
853 
854 template <> struct MDNodeKeyImpl<DIGlobalVariable> {
859  unsigned Line;
865 
866  MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
867  Metadata *File, unsigned Line, Metadata *Type,
868  bool IsLocalToUnit, bool IsDefinition,
869  Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
870  : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
871  Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
872  IsDefinition(IsDefinition),
873  StaticDataMemberDeclaration(StaticDataMemberDeclaration),
874  AlignInBits(AlignInBits) {}
876  : Scope(N->getRawScope()), Name(N->getRawName()),
877  LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
878  Line(N->getLine()), Type(N->getRawType()),
879  IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
880  StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
881  AlignInBits(N->getAlignInBits()) {}
882 
883  bool isKeyOf(const DIGlobalVariable *RHS) const {
884  return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
885  LinkageName == RHS->getRawLinkageName() &&
886  File == RHS->getRawFile() && Line == RHS->getLine() &&
887  Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
888  IsDefinition == RHS->isDefinition() &&
889  StaticDataMemberDeclaration ==
891  AlignInBits == RHS->getAlignInBits();
892  }
893 
894  unsigned getHashValue() const {
895  // We do not use AlignInBits in hashing function here on purpose:
896  // in most cases this param for local variable is zero (for function param
897  // it is always zero). This leads to lots of hash collisions and errors on
898  // cases with lots of similar variables.
899  // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
900  // generated IR is random for each run and test fails with Align included.
901  // TODO: make hashing work fine with such situations
902  return hash_combine(Scope, Name, LinkageName, File, Line, Type,
903  IsLocalToUnit, IsDefinition, /* AlignInBits, */
904  StaticDataMemberDeclaration);
905  }
906 };
907 
908 template <> struct MDNodeKeyImpl<DILocalVariable> {
912  unsigned Line;
914  unsigned Arg;
915  unsigned Flags;
917 
918  MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
919  Metadata *Type, unsigned Arg, unsigned Flags,
920  uint32_t AlignInBits)
921  : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
922  Flags(Flags), AlignInBits(AlignInBits) {}
924  : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
925  Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
926  Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
927 
928  bool isKeyOf(const DILocalVariable *RHS) const {
929  return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
930  File == RHS->getRawFile() && Line == RHS->getLine() &&
931  Type == RHS->getRawType() && Arg == RHS->getArg() &&
932  Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
933  }
934 
935  unsigned getHashValue() const {
936  // We do not use AlignInBits in hashing function here on purpose:
937  // in most cases this param for local variable is zero (for function param
938  // it is always zero). This leads to lots of hash collisions and errors on
939  // cases with lots of similar variables.
940  // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
941  // generated IR is random for each run and test fails with Align included.
942  // TODO: make hashing work fine with such situations
943  return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
944  }
945 };
946 
947 template <> struct MDNodeKeyImpl<DIExpression> {
949 
950  MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
951  MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
952 
953  bool isKeyOf(const DIExpression *RHS) const {
954  return Elements == RHS->getElements();
955  }
956 
957  unsigned getHashValue() const {
958  return hash_combine_range(Elements.begin(), Elements.end());
959  }
960 };
961 
965 
966  MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
967  : Variable(Variable), Expression(Expression) {}
969  : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
970 
971  bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
972  return Variable == RHS->getRawVariable() &&
973  Expression == RHS->getRawExpression();
974  }
975 
976  unsigned getHashValue() const { return hash_combine(Variable, Expression); }
977 };
978 
979 template <> struct MDNodeKeyImpl<DIObjCProperty> {
982  unsigned Line;
985  unsigned Attributes;
987 
988  MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
989  MDString *GetterName, MDString *SetterName, unsigned Attributes,
990  Metadata *Type)
991  : Name(Name), File(File), Line(Line), GetterName(GetterName),
992  SetterName(SetterName), Attributes(Attributes), Type(Type) {}
994  : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
995  GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
996  Attributes(N->getAttributes()), Type(N->getRawType()) {}
997 
998  bool isKeyOf(const DIObjCProperty *RHS) const {
999  return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1000  Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1001  SetterName == RHS->getRawSetterName() &&
1002  Attributes == RHS->getAttributes() && Type == RHS->getRawType();
1003  }
1004 
1005  unsigned getHashValue() const {
1006  return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1007  Type);
1008  }
1009 };
1010 
1011 template <> struct MDNodeKeyImpl<DIImportedEntity> {
1012  unsigned Tag;
1016  unsigned Line;
1018 
1019  MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1020  unsigned Line, MDString *Name)
1021  : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1022  Name(Name) {}
1024  : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
1025  File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
1026 
1027  bool isKeyOf(const DIImportedEntity *RHS) const {
1028  return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
1029  Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1030  Line == RHS->getLine() && Name == RHS->getRawName();
1031  }
1032 
1033  unsigned getHashValue() const {
1034  return hash_combine(Tag, Scope, Entity, File, Line, Name);
1035  }
1036 };
1037 
1038 template <> struct MDNodeKeyImpl<DIMacro> {
1039  unsigned MIType;
1040  unsigned Line;
1043 
1044  MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
1045  : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1047  : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1048  Value(N->getRawValue()) {}
1049 
1050  bool isKeyOf(const DIMacro *RHS) const {
1051  return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1052  Name == RHS->getRawName() && Value == RHS->getRawValue();
1053  }
1054 
1055  unsigned getHashValue() const {
1056  return hash_combine(MIType, Line, Name, Value);
1057  }
1058 };
1059 
1060 template <> struct MDNodeKeyImpl<DIMacroFile> {
1061  unsigned MIType;
1062  unsigned Line;
1065 
1066  MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1067  Metadata *Elements)
1068  : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1070  : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1071  Elements(N->getRawElements()) {}
1072 
1073  bool isKeyOf(const DIMacroFile *RHS) const {
1074  return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1075  File == RHS->getRawFile() && Elements == RHS->getRawElements();
1076  }
1077 
1078  unsigned getHashValue() const {
1079  return hash_combine(MIType, Line, File, Elements);
1080  }
1081 };
1082 
1083 /// \brief DenseMapInfo for MDNode subclasses.
1084 template <class NodeTy> struct MDNodeInfo {
1087 
1088  static inline NodeTy *getEmptyKey() {
1090  }
1091 
1092  static inline NodeTy *getTombstoneKey() {
1094  }
1095 
1096  static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
1097 
1098  static unsigned getHashValue(const NodeTy *N) {
1099  return KeyTy(N).getHashValue();
1100  }
1101 
1102  static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1103  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1104  return false;
1105  return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
1106  }
1107 
1108  static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
1109  if (LHS == RHS)
1110  return true;
1111  if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1112  return false;
1113  return SubsetEqualTy::isSubsetEqual(LHS, RHS);
1114  }
1115 };
1116 
1117 #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
1118 #include "llvm/IR/Metadata.def"
1119 
1120 /// \brief Map-like storage for metadata attachments.
1123 
1124 public:
1125  bool empty() const { return Attachments.empty(); }
1126  size_t size() const { return Attachments.size(); }
1127 
1128  /// \brief Get a particular attachment (if any).
1129  MDNode *lookup(unsigned ID) const;
1130 
1131  /// \brief Set an attachment to a particular node.
1132  ///
1133  /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1134  /// ID (if anyway).
1135  void set(unsigned ID, MDNode &MD);
1136 
1137  /// \brief Remove an attachment.
1138  ///
1139  /// Remove the attachment at \c ID, if any.
1140  void erase(unsigned ID);
1141 
1142  /// \brief Copy out all the attachments.
1143  ///
1144  /// Copies all the current attachments into \c Result, sorting by attachment
1145  /// ID. This function does \em not clear \c Result.
1146  void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1147 
1148  /// \brief Erase matching attachments.
1149  ///
1150  /// Erases all attachments matching the \c shouldRemove predicate.
1151  template <class PredTy> void remove_if(PredTy shouldRemove) {
1152  Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1153  Attachments.end());
1154  }
1155 };
1156 
1157 /// Multimap-like storage for metadata attachments for globals. This differs
1158 /// from MDAttachmentMap in that it allows multiple attachments per metadata
1159 /// kind.
1161  struct Attachment {
1162  unsigned MDKind;
1163  TrackingMDNodeRef Node;
1164  };
1165  SmallVector<Attachment, 1> Attachments;
1166 
1167 public:
1168  bool empty() const { return Attachments.empty(); }
1169 
1170  /// Appends all attachments with the given ID to \c Result in insertion order.
1171  /// If the global has no attachments with the given ID, or if ID is invalid,
1172  /// leaves Result unchanged.
1173  void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1174 
1175  void insert(unsigned ID, MDNode &MD);
1176  void erase(unsigned ID);
1177 
1178  /// Appends all attachments for the global to \c Result, sorting by attachment
1179  /// ID. Attachments with the same ID appear in insertion order. This function
1180  /// does \em not clear \c Result.
1181  void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1182 };
1183 
1185 public:
1186  /// OwnedModules - The set of modules instantiated in this context, and which
1187  /// will be automatically deleted if this context is deleted.
1189 
1190  LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1191  void *InlineAsmDiagContext = nullptr;
1192 
1193  std::unique_ptr<DiagnosticHandler> DiagHandler;
1194  bool RespectDiagnosticFilters = false;
1195  bool DiagnosticsHotnessRequested = false;
1196  uint64_t DiagnosticsHotnessThreshold = 0;
1197  std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
1198 
1199  LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1200  void *YieldOpaqueHandle = nullptr;
1201 
1202  using IntMapTy =
1205 
1206  using FPMapTy =
1209 
1213 
1217 
1219 
1220 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1221  DenseSet<CLASS *, CLASS##Info> CLASS##s;
1222 #include "llvm/IR/Metadata.def"
1223 
1224  // Optional map for looking up composite types by identifier.
1226 
1227  // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1228  // aren't in the MDNodeSet, but they're still shared between objects, so no
1229  // one object can destroy them. Keep track of them here so we can delete
1230  // them on context teardown.
1231  std::vector<MDNode *> DistinctMDNodes;
1232 
1234 
1237 
1240 
1243 
1245 
1247 
1249 
1253 
1255 
1256  ConstantInt *TheTrueVal = nullptr;
1257  ConstantInt *TheFalseVal = nullptr;
1258 
1259  std::unique_ptr<ConstantTokenNone> TheNoneToken;
1260 
1261  // Basic type instances.
1262  Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
1263  Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
1264  IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
1265 
1266  /// TypeAllocator - All dynamically allocated types are allocated from this.
1267  /// They live forever until the context is torn down.
1269 
1271 
1277  unsigned NamedStructTypesUniqueID = 0;
1278 
1281  DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1283 
1284  /// ValueHandles - This map keeps track of all of the value handles that are
1285  /// watching a Value*. The Value::HasValueHandle bit is used to know
1286  /// whether or not a value has an entry in this map.
1289 
1290  /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1292 
1293  /// Collection of per-instruction metadata used in this context.
1295 
1296  /// Collection of per-GlobalObject metadata used in this context.
1298 
1299  /// Collection of per-GlobalObject sections used in this context.
1301 
1302  /// Stable collection of section strings.
1304 
1305  /// DiscriminatorTable - This table maps file:line locations to an
1306  /// integer representing the next DWARF path discriminator to assign to
1307  /// instructions in different blocks at the same location.
1309 
1310  int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1311  int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
1312 
1313  /// \brief A set of interned tags for operand bundles. The StringMap maps
1314  /// bundle tags to their IDs.
1315  ///
1316  /// \see LLVMContext::getOperandBundleTagID
1318 
1319  StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1320  void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1321  uint32_t getOperandBundleTagID(StringRef Tag) const;
1322 
1323  /// A set of interned synchronization scopes. The StringMap maps
1324  /// synchronization scope names to their respective synchronization scope IDs.
1326 
1327  /// getOrInsertSyncScopeID - Maps synchronization scope name to
1328  /// synchronization scope ID. Every synchronization scope registered with
1329  /// LLVMContext has unique ID except pre-defined ones.
1330  SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1331 
1332  /// getSyncScopeNames - Populates client supplied SmallVector with
1333  /// synchronization scope names registered with LLVMContext. Synchronization
1334  /// scope names are ordered by increasing synchronization scope IDs.
1335  void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1336 
1337  /// Maintain the GC name for each function.
1338  ///
1339  /// This saves allocating an additional word in Function for programs which
1340  /// do not use GC (i.e., most programs) at the cost of increased overhead for
1341  /// clients which do use GC.
1343 
1344  /// Flag to indicate if Value (other than GlobalValue) retains their name or
1345  /// not.
1346  bool DiscardValueNames = false;
1347 
1349  ~LLVMContextImpl();
1350 
1351  /// Destroy the ConstantArrays if they are not used.
1352  void dropTriviallyDeadConstantArrays();
1353 
1354  /// \brief Access the object which manages optimization bisection for failure
1355  /// analysis.
1356  OptBisect &getOptBisect();
1357 };
1358 
1359 } // end namespace llvm
1360 
1361 #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H
static unsigned calculateHash(MDNode *N, unsigned Offset=0)
DIFlags getFlags() const
static APInt getTombstoneKey()
uint64_t CallInst * C
static bool isEqual(const KeyTy &LHS, const FunctionType *RHS)
static APFloat getTombstoneKey()
MDString * getRawName() const
DenseMap< unsigned, IntegerType * > IntegerTypes
ArrayRef< uint64_t > getElements() const
uint64_t getOffsetInBits() const
static bool isEqual(const NodeTy *LHS, const NodeTy *RHS)
bool isKeyOf(const MDTuple *RHS) const
StringMap< MDString, BumpPtrAllocator > MDStringCache
static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS)
unsigned getLine() const
MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, Metadata *Type, unsigned Arg, unsigned Flags, uint32_t AlignInBits)
static unsigned getHashValue(const KeyTy &Key)
FoldingSet< AttributeImpl > AttrsSet
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
static unsigned getHashValue(const KeyTy &Key)
Metadata * getRawScope() const
Structure for hashing arbitrary MDNode operands.
MDString * getRawName() const
Metadata * getRawVTableHolder() const
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
iterator begin() const
Definition: ArrayRef.h:137
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
MDString * getRawName() const
static StructType * getTombstoneKey()
void(*)(LLVMContext *Context, void *OpaqueHandle) YieldCallbackTy
Defines the type of a yield callback.
Definition: LLVMContext.h:175
Configuration point for MDNodeInfo::isEqual().
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags, Metadata *Elements, unsigned RuntimeLang, Metadata *VTableHolder, Metadata *TemplateParams, MDString *Identifier, Metadata *Discriminator)
DenseMap< Value *, ValueAsMetadata * > ValuesAsMetadata
unsigned getDiscriminator() const
MDString * getRawValue() const
bool isKeyOf(const DIMacro *RHS) const
MDNodeKeyImpl(const GenericDINode *N)
Metadata * getRawFile() const
Return the raw underlying file.
static bool isEqual(const KeyTy &LHS, const StructType *RHS)
This file contains the declarations for metadata subclasses.
Metadata * getRawInlinedAt() const
bool operator!=(const KeyTy &that) const
static unsigned getHashValue(const StructType *ST)
bool isKeyOf(const DINamespace *RHS) const
MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line, MDString *GetterName, MDString *SetterName, unsigned Attributes, Metadata *Type)
Metadata node.
Definition: Metadata.h:862
Metadata * getRawScope() const
MDNodeOpsKey(const NodeTy *N, unsigned Offset=0)
DenseMap< std::pair< Type *, unsigned >, PointerType * > ASPointerTypes
MDNodeKeyImpl(const DISubrange *N)
MDNodeKeyImpl(const DITemplateTypeParameter *N)
unsigned getVirtuality(StringRef VirtualityString)
Definition: Dwarf.cpp:291
MDNodeKeyImpl(ArrayRef< uint64_t > Elements)
MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
Multimap-like storage for metadata attachments for globals.
static unsigned calculateHash(GenericDINode *N)
Tuple of metadata.
Definition: Metadata.h:1104
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Definition: APInt.h:1488
MDNodeKeyImpl(const DIEnumerator *N)
MDString * getRawName() const
static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS)
static NodeTy * getEmptyKey()
bool isKeyOf(const DISubroutineType *RHS) const
The address of a basic block.
Definition: Constants.h:818
Metadata * getRawTypeArray() const
DenseMap< const Instruction *, MDAttachmentMap > InstructionMetadata
Collection of per-instruction metadata used in this context.
static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope, const MDString *LinkageName, const Metadata *TemplateParams, const DISubprogram *RHS)
Subprograms compare equal if they declare the same function in an ODR type.
MDNodeKeyImpl(const DIGlobalVariable *N)
static unsigned getHashValue(const APFloat &Key)
MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File, Metadata *Elements)
static bool isEqual(const APInt &LHS, const APInt &RHS)
unsigned getTag() const
Class to represent struct types.
Definition: DerivedTypes.h:201
Array subrange.
KeyTy(const FunctionType *FT)
uint64_t VAL
Used to store the <= 64 bits integer value.
Definition: APInt.h:87
MDNodeKeyImpl(const DIBasicType *N)
MDString * getRawSetterName() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
DenseMap< std::pair< Type *, uint64_t >, ArrayType * > ArrayTypes
std::unique_ptr< DiagnosticHandler > DiagHandler
std::vector< MDNode * > DistinctMDNodes
uint64_t getSizeInBits() const
Metadata * getRawType() const
DenseMap< const Value *, ValueName * > ValueNames
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
BumpPtrAllocator TypeAllocator
TypeAllocator - All dynamically allocated types are allocated from this.
unsigned getHash() const
This file implements a class to represent arbitrary precision integral constant values and operations...
static unsigned getHashValue(const FunctionType *FT)
MDString * getRawISysRoot() const
static StructType * getEmptyKey()
ConstantUniqueMap< InlineAsm > InlineAsms
op_iterator op_begin() const
Definition: Metadata.h:1057
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
MDNodeKeyImpl(const DISubprogram *N)
bool getExportSymbols() const
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros, MDString *IncludePath, MDString *ISysRoot)
Subprogram description.
Key
PAL metadata keys.
Class to represent function types.
Definition: DerivedTypes.h:103
Optional< DIFile::ChecksumInfo< MDString * > > Checksum
unsigned getRuntimeLang() const
MDString * getRawName() const
Class to represent array types.
Definition: DerivedTypes.h:369
Enumeration value.
std::unique_ptr< ConstantTokenNone > TheNoneToken
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4428
uint32_t getAlignInBits() const
ArrayConstantsTy ArrayConstants
bool isKeyOf(const DISubprogram *RHS) const
Metadata * getRawEntity() const
Debug location.
DenseMap< std::pair< Type *, unsigned >, VectorType * > VectorTypes
MDNodeKeyImpl(MDString *Name, Metadata *Type)
bool isKeyOf(const DITemplateValueParameter *RHS) const
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, Metadata *ContainingType, unsigned Virtuality, unsigned VirtualIndex, int ThisAdjustment, unsigned Flags, bool IsOptimized, Metadata *Unit, Metadata *TemplateParams, Metadata *Declaration, Metadata *Variables, Metadata *ThrownTypes)
bool isKeyOf(const DIMacroFile *RHS) const
StringMap< SyncScope::ID > SSC
A set of interned synchronization scopes.
Class to represent pointers.
Definition: DerivedTypes.h:467
Metadata * getRawFile() const
unsigned getLine() const
bool isKeyOf(const DIGlobalVariable *RHS) const
MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File, unsigned Line, MDString *Name)
bool isKeyOf(const DISubrange *RHS) const
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
This class implements a mechanism to disable passes and individual optimizations at compile time base...
Definition: OptBisect.h:28
#define P(N)
StringMap< unsigned > CustomMDKindNames
CustomMDKindNames - Map to hold the metadata string to ID mapping.
bool operator==(const KeyTy &that) const
bool isKeyOf(const DILexicalBlock *RHS) const
unsigned getColumn() const
static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS)
Metadata * getRawDiscriminator() const
MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
A single checksum, represented by a Kind and a Value (a string).
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
bool operator!=(const KeyTy &that) const
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:143
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
CountType getCount() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
MDNodeKeyImpl(const DIExpression *N)
static unsigned calculateHash(MDTuple *N)
MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
unsigned getAttributes() const
bool compareOps(const NodeTy *RHS, unsigned Offset=0) const
StringMap< uint32_t > BundleTagCache
A set of interned tags for operand bundles.
bool isKeyOf(const DIGlobalVariableExpression *RHS) const
static bool isEqual(const FunctionType *LHS, const FunctionType *RHS)
MDNodeKeyImpl(const DIObjCProperty *N)
MDNodeKeyImpl(const DISubroutineType *N)
MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
A pair of DIGlobalVariable and DIExpression.
This file declares a class to represent arbitrary precision floating point values and provide a varie...
bool isKeyOf(const DIImportedEntity *RHS) const
This file defines various helper methods and classes used by LLVMContextImpl for creating and managin...
ValueHandlesTy ValueHandles
MDNodeKeyImpl(const DILexicalBlockFile *N)
MDNodeKeyImpl(const DICompositeType *N)
static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS)
Class to represent integer types.
Definition: DerivedTypes.h:40
static FunctionType * getEmptyKey()
MDNodeKeyImpl(const DIDerivedType *N)
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:854
static unsigned getHashValue(const NodeTy *N)
MDString * getRawConfigurationMacros() const
bool isKeyOf(const DIEnumerator *RHS) const
iterator erase(const_iterator CI)
Definition: SmallVector.h:447
unsigned getLine() const
bool isKeyOf(const DIBasicType *RHS) const
DenseMap< const GlobalObject *, StringRef > GlobalObjectSections
Collection of per-GlobalObject sections used in this context.
static bool isEqual(const APFloat &LHS, const APFloat &RHS)
Metadata * getRawType() const
MDString * getRawName() const
MDString * getRawName() const
FoldingSet - This template class is used to instantiate a specialized implementation of the folding s...
Definition: FoldingSet.h:474
VectorConstantsTy VectorConstants
MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
An imported module (C++ using directive or similar).
static bool isEqual(const KeyTy &LHS, const NodeTy *RHS)
Metadata * getRawElements() const
int64_t getValue() const
DenseMap< Metadata *, MetadataAsValue * > MetadataAsValues
static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS)
Metadata * getRawScope() const
DenseMap< const GlobalObject *, MDGlobalAttachmentMap > GlobalObjectMetadata
Collection of per-GlobalObject metadata used in this context.
This is the shared class of boolean and integer constants.
Definition: Constants.h:84
MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
Metadata * getRawTemplateParams() const
static NodeTy * getTombstoneKey()
unsigned getLine() const
MDNodeKeyImpl(const DIGlobalVariableExpression *N)
bool isKeyOf(const DIDerivedType *RHS) const
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:862
iterator end() const
Definition: ArrayRef.h:138
FunctionTypeSet FunctionTypes
MDString * getRawHeader() const
FoldingSet< AttributeListImpl > AttrsLists
MDNodeKeyImpl(ArrayRef< Metadata *> Ops)
static Optional< unsigned > getTag(const TargetRegisterInfo *TRI, const MachineInstr &MI, const LoadInfo &LI)
Metadata * getRawElements() const
Metadata * getRawFile() const
DWARF expression.
bool isKeyOf(const DITemplateTypeParameter *RHS) const
SmallPtrSet< Module *, 4 > OwnedModules
OwnedModules - The set of modules instantiated in this context, and which will be automatically delet...
MDNodeKeyImpl(const DITemplateValueParameter *N)
MDNodeKeyImpl(MDString *Filename, MDString *Directory, Optional< DIFile::ChecksumInfo< MDString *>> Checksum)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:222
MDNodeKeyImpl(const DINamespace *N)
Class to represent vector types.
Definition: DerivedTypes.h:393
static bool isEqual(const StructType *LHS, const StructType *RHS)
This file contains constants used for implementing Dwarf debug support.
Class for arbitrary precision integers.
Definition: APInt.h:69
Metadata * getRawFile() const
bool isKeyOf(const DICompositeType *RHS) const
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:602
A (clang) module that has been imported by the compile unit.
void(*)(const SMDiagnostic &, void *Context, unsigned LocCookie) InlineAsmDiagHandlerTy
Definition: LLVMContext.h:171
DenseMapInfo for MDNode subclasses.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:480
static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS)
Generic tagged DWARF-like metadata node.
MDNodeKeyImpl(const DILocalVariable *N)
MDNodeKeyImpl(const DIImportedEntity *N)
Metadata * getRawBaseType() const
static FunctionType * getTombstoneKey()
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
MDNodeKeyImpl(const DILocation *L)
bool isKeyOf(const DILexicalBlockFile *RHS) const
Type array for a subprogram.
StructTypeSet AnonStructTypes
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
MDString * getRawIdentifier() const
unsigned getEncoding() const
bool isKeyOf(const GenericDINode *RHS) const
static unsigned getHashValue(const APInt &Key)
DenseMap< std::pair< const char *, unsigned >, unsigned > DiscriminatorTable
DiscriminatorTable - This table maps file:line locations to an integer representing the next DWARF pa...
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:61
StringMap< StructType * > NamedStructTypes
Metadata * getRawScope() const
static bool isODRMember(unsigned Tag, const Metadata *Scope, const MDString *Name, const DIDerivedType *RHS)
Subprograms compare equal if they declare the same function in an ODR type.
std::unique_ptr< yaml::Output > DiagnosticsOutputFile
#define N
static const fltSemantics & Bogus() LLVM_READNONE
A Pseudo fltsemantic used to construct APFloats that cannot conflict with anything real...
Definition: APFloat.cpp:131
DenseMap< const Function *, std::string > GCNames
Maintain the GC name for each function.
MDString * getRawName() const
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, uint32_t AlignInBits, unsigned Encoding)
unsigned getMacinfoType() const
MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, Metadata *InlinedAt)
ConstantUniqueMap< ConstantExpr > ExprConstants
bool operator==(const KeyTy &that) const
MDString * getRawLinkageName() const
Metadata * getRawStaticDataMemberDeclaration() const
KeyTy(const Type *R, const ArrayRef< Type *> &P, bool V)
unsigned getTag() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line, Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, Optional< unsigned > DWARFAddressSpace, unsigned Flags, Metadata *ExtraData)
uint32_t getAlignInBits() const
MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef< Metadata *> DwarfOps)
bool isKeyOf(const DIFile *RHS) const
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, bool IsLocalToUnit, bool IsDefinition, Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
StructConstantsTy StructConstants
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
void remove_if(PredTy shouldRemove)
Erase matching attachments.
bool bitwiseIsEqual(const APFloat &RHS) const
Definition: APFloat.h:1112
MDNodeKeyImpl(const DILexicalBlock *N)
StringSet - A wrapper for StringMap that provides set-like functionality.
Definition: StringSet.h:28
bool isKeyOf(const DIModule *RHS) const
FoldingSet< AttributeSetNode > AttrsSetNodes
Metadata * getRawScope() const
bool isKeyOf(const DILocation *RHS) const
bool isKeyOf(const DIObjCProperty *RHS) const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
A single uniqued string.
Definition: Metadata.h:602
MDString * getRawIncludePath() const
bool isKeyOf(const DILocalVariable *RHS) const
unsigned getLine() const
DenseMap< Type *, PointerType * > PointerTypes
bool operator==(uint64_t V1, const APInt &V2)
Definition: APInt.h:1946
MDNodeOpsKey(ArrayRef< Metadata *> Ops)
Metadata * getRawType() const
Metadata * getRawScope() const
unsigned getNumOperands() const
Return number of MDNode operands.
Definition: Metadata.h:1073
Map-like storage for metadata attachments.
KeyTy(const ArrayRef< Type *> &E, bool P)
StringMap< ConstantDataSequential * > CDSConstants
Optional< DenseMap< const MDString *, DICompositeType * > > DITypeMap
MDString * getRawName() const
Root of the metadata hierarchy.
Definition: Metadata.h:58
unsigned getLine() const
MDString * getRawGetterName() const
MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
Metadata * getRawScope() const
StringSet SectionStrings
Stable collection of section strings.
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144
IntegerType * Int32Ty
static unsigned getHashValue(const KeyTy &Key)
Basic type, like &#39;int&#39; or &#39;float&#39;.
MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
bool isKeyOf(const DIExpression *RHS) const