1 //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares LLVMContextImpl, the opaque implementation
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
16 #define LLVM_LIB_IR_LLVMCONTEXTIMPL_H
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"
35 #include "llvm/BinaryFormat/Dwarf.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DebugInfoMetadata.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"
44 #include "llvm/Support/YAMLTraits.h"
60 class ValueHandleBase;
62 struct DenseMapAPIntKeyInfo {
63 static inline APInt getEmptyKey() {
69 static inline APInt getTombstoneKey() {
75 static unsigned getHashValue(const APInt &Key) {
76 return static_cast<unsigned>(hash_value(Key));
79 static bool isEqual(const APInt &LHS, const APInt &RHS) {
80 return LHS.getBitWidth() == RHS.getBitWidth() && LHS == RHS;
84 struct DenseMapAPFloatKeyInfo {
85 static inline APFloat getEmptyKey() { return APFloat(APFloat::Bogus(), 1); }
86 static inline APFloat getTombstoneKey() { return APFloat(APFloat::Bogus(), 2); }
88 static unsigned getHashValue(const APFloat &Key) {
89 return static_cast<unsigned>(hash_value(Key));
92 static bool isEqual(const APFloat &LHS, const APFloat &RHS) {
93 return LHS.bitwiseIsEqual(RHS);
97 struct AnonStructTypeKeyInfo {
99 ArrayRef<Type*> ETypes;
102 KeyTy(const ArrayRef<Type*>& E, bool P) :
103 ETypes(E), isPacked(P) {}
105 KeyTy(const StructType *ST)
106 : ETypes(ST->elements()), isPacked(ST->isPacked()) {}
108 bool operator==(const KeyTy& that) const {
109 if (isPacked != that.isPacked)
111 if (ETypes != that.ETypes)
115 bool operator!=(const KeyTy& that) const {
116 return !this->operator==(that);
120 static inline StructType* getEmptyKey() {
121 return DenseMapInfo<StructType*>::getEmptyKey();
124 static inline StructType* getTombstoneKey() {
125 return DenseMapInfo<StructType*>::getTombstoneKey();
128 static unsigned getHashValue(const KeyTy& Key) {
129 return hash_combine(hash_combine_range(Key.ETypes.begin(),
134 static unsigned getHashValue(const StructType *ST) {
135 return getHashValue(KeyTy(ST));
138 static bool isEqual(const KeyTy& LHS, const StructType *RHS) {
139 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
141 return LHS == KeyTy(RHS);
144 static bool isEqual(const StructType *LHS, const StructType *RHS) {
149 struct FunctionTypeKeyInfo {
151 const Type *ReturnType;
152 ArrayRef<Type*> Params;
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()) {}
161 bool operator==(const KeyTy& that) const {
162 if (ReturnType != that.ReturnType)
164 if (isVarArg != that.isVarArg)
166 if (Params != that.Params)
170 bool operator!=(const KeyTy& that) const {
171 return !this->operator==(that);
175 static inline FunctionType* getEmptyKey() {
176 return DenseMapInfo<FunctionType*>::getEmptyKey();
179 static inline FunctionType* getTombstoneKey() {
180 return DenseMapInfo<FunctionType*>::getTombstoneKey();
183 static unsigned getHashValue(const KeyTy& Key) {
184 return hash_combine(Key.ReturnType,
185 hash_combine_range(Key.Params.begin(),
190 static unsigned getHashValue(const FunctionType *FT) {
191 return getHashValue(KeyTy(FT));
194 static bool isEqual(const KeyTy& LHS, const FunctionType *RHS) {
195 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
197 return LHS == KeyTy(RHS);
200 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
205 /// Structure for hashing arbitrary MDNode operands.
207 ArrayRef<Metadata *> RawOps;
208 ArrayRef<MDOperand> Ops;
212 MDNodeOpsKey(ArrayRef<Metadata *> Ops)
213 : RawOps(Ops), Hash(calculateHash(Ops)) {}
215 template <class NodeTy>
216 MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0)
217 : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {}
219 template <class NodeTy>
220 bool compareOps(const NodeTy *RHS, unsigned Offset = 0) const {
221 if (getHash() != RHS->getHash())
224 assert((RawOps.empty() || Ops.empty()) && "Two sets of operands?");
225 return RawOps.empty() ? compareOps(Ops, RHS, Offset)
226 : compareOps(RawOps, RHS, Offset);
229 static unsigned calculateHash(MDNode *N, unsigned Offset = 0);
233 static bool compareOps(ArrayRef<T> Ops, const MDNode *RHS, unsigned Offset) {
234 if (Ops.size() != RHS->getNumOperands() - Offset)
236 return std::equal(Ops.begin(), Ops.end(), RHS->op_begin() + Offset);
239 static unsigned calculateHash(ArrayRef<Metadata *> Ops);
242 unsigned getHash() const { return Hash; }
245 template <class NodeTy> struct MDNodeKeyImpl;
247 /// Configuration point for MDNodeInfo::isEqual().
248 template <class NodeTy> struct MDNodeSubsetEqualImpl {
249 using KeyTy = MDNodeKeyImpl<NodeTy>;
251 static bool isSubsetEqual(const KeyTy &LHS, const NodeTy *RHS) {
255 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
260 /// DenseMapInfo for MDTuple.
262 /// Note that we don't need the is-function-local bit, since that's implicit in
264 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
265 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
266 MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {}
268 bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); }
270 unsigned getHashValue() const { return getHash(); }
272 static unsigned calculateHash(MDTuple *N) {
273 return MDNodeOpsKey::calculateHash(N);
277 /// DenseMapInfo for DILocation.
278 template <> struct MDNodeKeyImpl<DILocation> {
284 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
286 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {}
287 MDNodeKeyImpl(const DILocation *L)
288 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
289 InlinedAt(L->getRawInlinedAt()) {}
291 bool isKeyOf(const DILocation *RHS) const {
292 return Line == RHS->getLine() && Column == RHS->getColumn() &&
293 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt();
296 unsigned getHashValue() const {
297 return hash_combine(Line, Column, Scope, InlinedAt);
301 /// DenseMapInfo for GenericDINode.
302 template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
306 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
307 : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {}
308 MDNodeKeyImpl(const GenericDINode *N)
309 : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {}
311 bool isKeyOf(const GenericDINode *RHS) const {
312 return Tag == RHS->getTag() && Header == RHS->getRawHeader() &&
316 unsigned getHashValue() const { return hash_combine(getHash(), Tag, Header); }
318 static unsigned calculateHash(GenericDINode *N) {
319 return MDNodeOpsKey::calculateHash(N, 1);
323 template <> struct MDNodeKeyImpl<DISubrange> {
327 MDNodeKeyImpl(Metadata *CountNode, int64_t LowerBound)
328 : CountNode(CountNode), LowerBound(LowerBound) {}
329 MDNodeKeyImpl(const DISubrange *N)
330 : CountNode(N->getRawCountNode()),
331 LowerBound(N->getLowerBound()) {}
333 bool isKeyOf(const DISubrange *RHS) const {
334 if (LowerBound != RHS->getLowerBound())
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())
343 return CountNode == RHS->getRawCountNode();
346 unsigned getHashValue() const {
347 if (auto *MD = dyn_cast<ConstantAsMetadata>(CountNode))
348 return hash_combine(cast<ConstantInt>(MD->getValue())->getSExtValue(),
350 return hash_combine(CountNode, LowerBound);
354 template <> struct MDNodeKeyImpl<DIEnumerator> {
359 MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name)
360 : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {}
361 MDNodeKeyImpl(const DIEnumerator *N)
362 : Value(N->getValue()), Name(N->getRawName()),
363 IsUnsigned(N->isUnsigned()) {}
365 bool isKeyOf(const DIEnumerator *RHS) const {
366 return Value == RHS->getValue() && IsUnsigned == RHS->isUnsigned() &&
367 Name == RHS->getRawName();
370 unsigned getHashValue() const { return hash_combine(Value, Name); }
373 template <> struct MDNodeKeyImpl<DIBasicType> {
377 uint32_t AlignInBits;
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) {}
384 MDNodeKeyImpl(const DIBasicType *N)
385 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
386 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
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();
395 unsigned getHashValue() const {
396 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
400 template <> struct MDNodeKeyImpl<DIDerivedType> {
408 uint64_t OffsetInBits;
409 uint32_t AlignInBits;
410 Optional<unsigned> DWARFAddressSpace;
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,
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) {}
423 MDNodeKeyImpl(const DIDerivedType *N)
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()) {}
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();
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);
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);
460 template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
461 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
463 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
464 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
467 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
468 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
472 /// Subprograms compare equal if they declare the same function in an ODR
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)
480 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
481 if (!CT || !CT->getRawIdentifier())
484 // Compare to the RHS.
485 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
486 Scope == RHS->getRawScope();
490 template <> struct MDNodeKeyImpl<DICompositeType> {
498 uint64_t OffsetInBits;
499 uint32_t AlignInBits;
502 unsigned RuntimeLang;
503 Metadata *VTableHolder;
504 Metadata *TemplateParams;
505 MDString *Identifier;
506 Metadata *Discriminator;
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) {}
520 MDNodeKeyImpl(const DICompositeType *N)
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()) {}
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();
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,
556 template <> struct MDNodeKeyImpl<DISubroutineType> {
561 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
562 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
563 MDNodeKeyImpl(const DISubroutineType *N)
564 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
566 bool isKeyOf(const DISubroutineType *RHS) const {
567 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
568 TypeArray == RHS->getRawTypeArray();
571 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
574 template <> struct MDNodeKeyImpl<DIFile> {
577 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
578 Optional<MDString *> Source;
580 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
581 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
582 Optional<MDString *> Source)
583 : Filename(Filename), Directory(Directory), Checksum(Checksum),
585 MDNodeKeyImpl(const DIFile *N)
586 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
587 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
589 bool isKeyOf(const DIFile *RHS) const {
590 return Filename == RHS->getRawFilename() &&
591 Directory == RHS->getRawDirectory() &&
592 Checksum == RHS->getRawChecksum() &&
593 Source == RHS->getRawSource();
596 unsigned getHashValue() const {
598 Filename, Directory, Checksum ? Checksum->Kind : 0,
599 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
603 template <> struct MDNodeKeyImpl<DISubprogram> {
606 MDString *LinkageName;
613 Metadata *ContainingType;
615 unsigned VirtualIndex;
620 Metadata *TemplateParams;
621 Metadata *Declaration;
622 Metadata *RetainedNodes;
623 Metadata *ThrownTypes;
625 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
626 Metadata *File, unsigned Line, Metadata *Type,
627 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
628 Metadata *ContainingType, unsigned Virtuality,
629 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
630 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
631 Metadata *Declaration, Metadata *RetainedNodes,
632 Metadata *ThrownTypes)
633 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
634 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
635 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
636 ContainingType(ContainingType), Virtuality(Virtuality),
637 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
638 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
639 TemplateParams(TemplateParams), Declaration(Declaration),
640 RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
641 MDNodeKeyImpl(const DISubprogram *N)
642 : Scope(N->getRawScope()), Name(N->getRawName()),
643 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
644 Line(N->getLine()), Type(N->getRawType()),
645 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
646 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
647 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
648 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
649 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
650 TemplateParams(N->getRawTemplateParams()),
651 Declaration(N->getRawDeclaration()), RetainedNodes(N->getRawRetainedNodes()),
652 ThrownTypes(N->getRawThrownTypes()) {}
654 bool isKeyOf(const DISubprogram *RHS) const {
655 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
656 LinkageName == RHS->getRawLinkageName() &&
657 File == RHS->getRawFile() && Line == RHS->getLine() &&
658 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
659 IsDefinition == RHS->isDefinition() &&
660 ScopeLine == RHS->getScopeLine() &&
661 ContainingType == RHS->getRawContainingType() &&
662 Virtuality == RHS->getVirtuality() &&
663 VirtualIndex == RHS->getVirtualIndex() &&
664 ThisAdjustment == RHS->getThisAdjustment() &&
665 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
666 Unit == RHS->getUnit() &&
667 TemplateParams == RHS->getRawTemplateParams() &&
668 Declaration == RHS->getRawDeclaration() &&
669 RetainedNodes == RHS->getRawRetainedNodes() &&
670 ThrownTypes == RHS->getRawThrownTypes();
673 unsigned getHashValue() const {
674 // If this is a declaration inside an ODR type, only hash the type and the
675 // name. Otherwise the hash will be stronger than
676 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
677 if (!IsDefinition && LinkageName)
678 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
679 if (CT->getRawIdentifier())
680 return hash_combine(LinkageName, Scope);
682 // Intentionally computes the hash on a subset of the operands for
683 // performance reason. The subset has to be significant enough to avoid
684 // collision "most of the time". There is no correctness issue in case of
685 // collision because of the full check above.
686 return hash_combine(Name, Scope, File, Type, Line);
690 template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
691 using KeyTy = MDNodeKeyImpl<DISubprogram>;
693 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
694 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
695 LHS.LinkageName, LHS.TemplateParams, RHS);
698 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
699 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
700 LHS->getRawLinkageName(),
701 LHS->getRawTemplateParams(), RHS);
704 /// Subprograms compare equal if they declare the same function in an ODR
706 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
707 const MDString *LinkageName,
708 const Metadata *TemplateParams,
709 const DISubprogram *RHS) {
710 // Check whether the LHS is eligible.
711 if (IsDefinition || !Scope || !LinkageName)
714 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
715 if (!CT || !CT->getRawIdentifier())
718 // Compare to the RHS.
719 // FIXME: We need to compare template parameters here to avoid incorrect
720 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
721 // has a non-ODR template parameter (i.e., a DICompositeType that does not
722 // have an identifier). Eventually we should decouple ODR logic from
724 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
725 LinkageName == RHS->getRawLinkageName() &&
726 TemplateParams == RHS->getRawTemplateParams();
730 template <> struct MDNodeKeyImpl<DILexicalBlock> {
736 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
737 : Scope(Scope), File(File), Line(Line), Column(Column) {}
738 MDNodeKeyImpl(const DILexicalBlock *N)
739 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
740 Column(N->getColumn()) {}
742 bool isKeyOf(const DILexicalBlock *RHS) const {
743 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
744 Line == RHS->getLine() && Column == RHS->getColumn();
747 unsigned getHashValue() const {
748 return hash_combine(Scope, File, Line, Column);
752 template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
755 unsigned Discriminator;
757 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
758 : Scope(Scope), File(File), Discriminator(Discriminator) {}
759 MDNodeKeyImpl(const DILexicalBlockFile *N)
760 : Scope(N->getRawScope()), File(N->getRawFile()),
761 Discriminator(N->getDiscriminator()) {}
763 bool isKeyOf(const DILexicalBlockFile *RHS) const {
764 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
765 Discriminator == RHS->getDiscriminator();
768 unsigned getHashValue() const {
769 return hash_combine(Scope, File, Discriminator);
773 template <> struct MDNodeKeyImpl<DINamespace> {
778 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
779 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
780 MDNodeKeyImpl(const DINamespace *N)
781 : Scope(N->getRawScope()), Name(N->getRawName()),
782 ExportSymbols(N->getExportSymbols()) {}
784 bool isKeyOf(const DINamespace *RHS) const {
785 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
786 ExportSymbols == RHS->getExportSymbols();
789 unsigned getHashValue() const {
790 return hash_combine(Scope, Name);
794 template <> struct MDNodeKeyImpl<DIModule> {
797 MDString *ConfigurationMacros;
798 MDString *IncludePath;
801 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
802 MDString *IncludePath, MDString *ISysRoot)
803 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
804 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
805 MDNodeKeyImpl(const DIModule *N)
806 : Scope(N->getRawScope()), Name(N->getRawName()),
807 ConfigurationMacros(N->getRawConfigurationMacros()),
808 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
810 bool isKeyOf(const DIModule *RHS) const {
811 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
812 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
813 IncludePath == RHS->getRawIncludePath() &&
814 ISysRoot == RHS->getRawISysRoot();
817 unsigned getHashValue() const {
818 return hash_combine(Scope, Name,
819 ConfigurationMacros, IncludePath, ISysRoot);
823 template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
827 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
828 MDNodeKeyImpl(const DITemplateTypeParameter *N)
829 : Name(N->getRawName()), Type(N->getRawType()) {}
831 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
832 return Name == RHS->getRawName() && Type == RHS->getRawType();
835 unsigned getHashValue() const { return hash_combine(Name, Type); }
838 template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
844 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
845 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
846 MDNodeKeyImpl(const DITemplateValueParameter *N)
847 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
848 Value(N->getValue()) {}
850 bool isKeyOf(const DITemplateValueParameter *RHS) const {
851 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
852 Type == RHS->getRawType() && Value == RHS->getValue();
855 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
858 template <> struct MDNodeKeyImpl<DIGlobalVariable> {
861 MDString *LinkageName;
867 Metadata *StaticDataMemberDeclaration;
868 uint32_t AlignInBits;
870 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
871 Metadata *File, unsigned Line, Metadata *Type,
872 bool IsLocalToUnit, bool IsDefinition,
873 Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
874 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
875 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
876 IsDefinition(IsDefinition),
877 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
878 AlignInBits(AlignInBits) {}
879 MDNodeKeyImpl(const DIGlobalVariable *N)
880 : Scope(N->getRawScope()), Name(N->getRawName()),
881 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
882 Line(N->getLine()), Type(N->getRawType()),
883 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
884 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
885 AlignInBits(N->getAlignInBits()) {}
887 bool isKeyOf(const DIGlobalVariable *RHS) const {
888 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
889 LinkageName == RHS->getRawLinkageName() &&
890 File == RHS->getRawFile() && Line == RHS->getLine() &&
891 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
892 IsDefinition == RHS->isDefinition() &&
893 StaticDataMemberDeclaration ==
894 RHS->getRawStaticDataMemberDeclaration() &&
895 AlignInBits == RHS->getAlignInBits();
898 unsigned getHashValue() const {
899 // We do not use AlignInBits in hashing function here on purpose:
900 // in most cases this param for local variable is zero (for function param
901 // it is always zero). This leads to lots of hash collisions and errors on
902 // cases with lots of similar variables.
903 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
904 // generated IR is random for each run and test fails with Align included.
905 // TODO: make hashing work fine with such situations
906 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
907 IsLocalToUnit, IsDefinition, /* AlignInBits, */
908 StaticDataMemberDeclaration);
912 template <> struct MDNodeKeyImpl<DILocalVariable> {
920 uint32_t AlignInBits;
922 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
923 Metadata *Type, unsigned Arg, unsigned Flags,
924 uint32_t AlignInBits)
925 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
926 Flags(Flags), AlignInBits(AlignInBits) {}
927 MDNodeKeyImpl(const DILocalVariable *N)
928 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
929 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
930 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
932 bool isKeyOf(const DILocalVariable *RHS) const {
933 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
934 File == RHS->getRawFile() && Line == RHS->getLine() &&
935 Type == RHS->getRawType() && Arg == RHS->getArg() &&
936 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
939 unsigned getHashValue() const {
940 // We do not use AlignInBits in hashing function here on purpose:
941 // in most cases this param for local variable is zero (for function param
942 // it is always zero). This leads to lots of hash collisions and errors on
943 // cases with lots of similar variables.
944 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
945 // generated IR is random for each run and test fails with Align included.
946 // TODO: make hashing work fine with such situations
947 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
951 template <> struct MDNodeKeyImpl<DILabel> {
957 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
958 : Scope(Scope), Name(Name), File(File), Line(Line) {}
959 MDNodeKeyImpl(const DILabel *N)
960 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
961 Line(N->getLine()) {}
963 bool isKeyOf(const DILabel *RHS) const {
964 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
965 File == RHS->getRawFile() && Line == RHS->getLine();
968 /// Using name and line to get hash value. It should already be mostly unique.
969 unsigned getHashValue() const {
970 return hash_combine(Scope, Name, Line);
974 template <> struct MDNodeKeyImpl<DIExpression> {
975 ArrayRef<uint64_t> Elements;
977 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
978 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
980 bool isKeyOf(const DIExpression *RHS) const {
981 return Elements == RHS->getElements();
984 unsigned getHashValue() const {
985 return hash_combine_range(Elements.begin(), Elements.end());
989 template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
991 Metadata *Expression;
993 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
994 : Variable(Variable), Expression(Expression) {}
995 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
996 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
998 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
999 return Variable == RHS->getRawVariable() &&
1000 Expression == RHS->getRawExpression();
1003 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
1006 template <> struct MDNodeKeyImpl<DIObjCProperty> {
1010 MDString *GetterName;
1011 MDString *SetterName;
1012 unsigned Attributes;
1015 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
1016 MDString *GetterName, MDString *SetterName, unsigned Attributes,
1018 : Name(Name), File(File), Line(Line), GetterName(GetterName),
1019 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
1020 MDNodeKeyImpl(const DIObjCProperty *N)
1021 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
1022 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
1023 Attributes(N->getAttributes()), Type(N->getRawType()) {}
1025 bool isKeyOf(const DIObjCProperty *RHS) const {
1026 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
1027 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
1028 SetterName == RHS->getRawSetterName() &&
1029 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
1032 unsigned getHashValue() const {
1033 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
1038 template <> struct MDNodeKeyImpl<DIImportedEntity> {
1046 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
1047 unsigned Line, MDString *Name)
1048 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1050 MDNodeKeyImpl(const DIImportedEntity *N)
1051 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
1052 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
1054 bool isKeyOf(const DIImportedEntity *RHS) const {
1055 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
1056 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1057 Line == RHS->getLine() && Name == RHS->getRawName();
1060 unsigned getHashValue() const {
1061 return hash_combine(Tag, Scope, Entity, File, Line, Name);
1065 template <> struct MDNodeKeyImpl<DIMacro> {
1071 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
1072 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1073 MDNodeKeyImpl(const DIMacro *N)
1074 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1075 Value(N->getRawValue()) {}
1077 bool isKeyOf(const DIMacro *RHS) const {
1078 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1079 Name == RHS->getRawName() && Value == RHS->getRawValue();
1082 unsigned getHashValue() const {
1083 return hash_combine(MIType, Line, Name, Value);
1087 template <> struct MDNodeKeyImpl<DIMacroFile> {
1093 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1095 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1096 MDNodeKeyImpl(const DIMacroFile *N)
1097 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1098 Elements(N->getRawElements()) {}
1100 bool isKeyOf(const DIMacroFile *RHS) const {
1101 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1102 File == RHS->getRawFile() && Elements == RHS->getRawElements();
1105 unsigned getHashValue() const {
1106 return hash_combine(MIType, Line, File, Elements);
1110 /// DenseMapInfo for MDNode subclasses.
1111 template <class NodeTy> struct MDNodeInfo {
1112 using KeyTy = MDNodeKeyImpl<NodeTy>;
1113 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1115 static inline NodeTy *getEmptyKey() {
1116 return DenseMapInfo<NodeTy *>::getEmptyKey();
1119 static inline NodeTy *getTombstoneKey() {
1120 return DenseMapInfo<NodeTy *>::getTombstoneKey();
1123 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
1125 static unsigned getHashValue(const NodeTy *N) {
1126 return KeyTy(N).getHashValue();
1129 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1130 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1132 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
1135 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
1138 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1140 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
1144 #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
1145 #include "llvm/IR/Metadata.def"
1147 /// Map-like storage for metadata attachments.
1148 class MDAttachmentMap {
1149 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1152 bool empty() const { return Attachments.empty(); }
1153 size_t size() const { return Attachments.size(); }
1155 /// Get a particular attachment (if any).
1156 MDNode *lookup(unsigned ID) const;
1158 /// Set an attachment to a particular node.
1160 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1162 void set(unsigned ID, MDNode &MD);
1164 /// Remove an attachment.
1166 /// Remove the attachment at \c ID, if any.
1167 bool erase(unsigned ID);
1169 /// Copy out all the attachments.
1171 /// Copies all the current attachments into \c Result, sorting by attachment
1172 /// ID. This function does \em not clear \c Result.
1173 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1175 /// Erase matching attachments.
1177 /// Erases all attachments matching the \c shouldRemove predicate.
1178 template <class PredTy> void remove_if(PredTy shouldRemove) {
1179 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1184 /// Multimap-like storage for metadata attachments for globals. This differs
1185 /// from MDAttachmentMap in that it allows multiple attachments per metadata
1187 class MDGlobalAttachmentMap {
1190 TrackingMDNodeRef Node;
1192 SmallVector<Attachment, 1> Attachments;
1195 bool empty() const { return Attachments.empty(); }
1197 /// Appends all attachments with the given ID to \c Result in insertion order.
1198 /// If the global has no attachments with the given ID, or if ID is invalid,
1199 /// leaves Result unchanged.
1200 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
1202 /// Returns the first attachment with the given ID or nullptr if no such
1203 /// attachment exists.
1204 MDNode *lookup(unsigned ID) const;
1206 void insert(unsigned ID, MDNode &MD);
1207 bool erase(unsigned ID);
1209 /// Appends all attachments for the global to \c Result, sorting by attachment
1210 /// ID. Attachments with the same ID appear in insertion order. This function
1211 /// does \em not clear \c Result.
1212 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1215 class LLVMContextImpl {
1217 /// OwnedModules - The set of modules instantiated in this context, and which
1218 /// will be automatically deleted if this context is deleted.
1219 SmallPtrSet<Module*, 4> OwnedModules;
1221 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1222 void *InlineAsmDiagContext = nullptr;
1224 std::unique_ptr<DiagnosticHandler> DiagHandler;
1225 bool RespectDiagnosticFilters = false;
1226 bool DiagnosticsHotnessRequested = false;
1227 uint64_t DiagnosticsHotnessThreshold = 0;
1228 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
1230 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1231 void *YieldOpaqueHandle = nullptr;
1234 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
1235 IntMapTy IntConstants;
1238 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
1239 FPMapTy FPConstants;
1241 FoldingSet<AttributeImpl> AttrsSet;
1242 FoldingSet<AttributeListImpl> AttrsLists;
1243 FoldingSet<AttributeSetNode> AttrsSetNodes;
1245 StringMap<MDString, BumpPtrAllocator> MDStringCache;
1246 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1247 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
1249 DenseMap<const Value*, ValueName*> ValueNames;
1251 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1252 DenseSet<CLASS *, CLASS##Info> CLASS##s;
1253 #include "llvm/IR/Metadata.def"
1255 // Optional map for looking up composite types by identifier.
1256 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
1258 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1259 // aren't in the MDNodeSet, but they're still shared between objects, so no
1260 // one object can destroy them. Keep track of them here so we can delete
1261 // them on context teardown.
1262 std::vector<MDNode *> DistinctMDNodes;
1264 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
1266 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
1267 ArrayConstantsTy ArrayConstants;
1269 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
1270 StructConstantsTy StructConstants;
1272 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
1273 VectorConstantsTy VectorConstants;
1275 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1277 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1279 StringMap<ConstantDataSequential*> CDSConstants;
1281 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1283 ConstantUniqueMap<ConstantExpr> ExprConstants;
1285 ConstantUniqueMap<InlineAsm> InlineAsms;
1287 ConstantInt *TheTrueVal = nullptr;
1288 ConstantInt *TheFalseVal = nullptr;
1290 std::unique_ptr<ConstantTokenNone> TheNoneToken;
1292 // Basic type instances.
1293 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
1294 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
1295 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
1297 /// TypeAllocator - All dynamically allocated types are allocated from this.
1298 /// They live forever until the context is torn down.
1299 BumpPtrAllocator TypeAllocator;
1301 DenseMap<unsigned, IntegerType*> IntegerTypes;
1303 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
1304 FunctionTypeSet FunctionTypes;
1305 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
1306 StructTypeSet AnonStructTypes;
1307 StringMap<StructType*> NamedStructTypes;
1308 unsigned NamedStructTypesUniqueID = 0;
1310 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1311 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1312 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1313 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
1315 /// ValueHandles - This map keeps track of all of the value handles that are
1316 /// watching a Value*. The Value::HasValueHandle bit is used to know
1317 /// whether or not a value has an entry in this map.
1318 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
1319 ValueHandlesTy ValueHandles;
1321 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1322 StringMap<unsigned> CustomMDKindNames;
1324 /// Collection of per-instruction metadata used in this context.
1325 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
1327 /// Collection of per-GlobalObject metadata used in this context.
1328 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
1330 /// Collection of per-GlobalObject sections used in this context.
1331 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1333 /// Stable collection of section strings.
1334 StringSet<> SectionStrings;
1336 /// DiscriminatorTable - This table maps file:line locations to an
1337 /// integer representing the next DWARF path discriminator to assign to
1338 /// instructions in different blocks at the same location.
1339 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1341 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1342 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
1344 /// A set of interned tags for operand bundles. The StringMap maps
1345 /// bundle tags to their IDs.
1347 /// \see LLVMContext::getOperandBundleTagID
1348 StringMap<uint32_t> BundleTagCache;
1350 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1351 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1352 uint32_t getOperandBundleTagID(StringRef Tag) const;
1354 /// A set of interned synchronization scopes. The StringMap maps
1355 /// synchronization scope names to their respective synchronization scope IDs.
1356 StringMap<SyncScope::ID> SSC;
1358 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1359 /// synchronization scope ID. Every synchronization scope registered with
1360 /// LLVMContext has unique ID except pre-defined ones.
1361 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1363 /// getSyncScopeNames - Populates client supplied SmallVector with
1364 /// synchronization scope names registered with LLVMContext. Synchronization
1365 /// scope names are ordered by increasing synchronization scope IDs.
1366 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1368 /// Maintain the GC name for each function.
1370 /// This saves allocating an additional word in Function for programs which
1371 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1372 /// clients which do use GC.
1373 DenseMap<const Function*, std::string> GCNames;
1375 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1377 bool DiscardValueNames = false;
1379 LLVMContextImpl(LLVMContext &C);
1382 /// Destroy the ConstantArrays if they are not used.
1383 void dropTriviallyDeadConstantArrays();
1385 mutable OptPassGate *OPG = nullptr;
1387 /// Access the object which can disable optional passes and individual
1388 /// optimizations at compile time.
1389 OptPassGate &getOptPassGate() const;
1391 /// Set the object which can disable optional passes and individual
1392 /// optimizations at compile time.
1394 /// The lifetime of the object must be guaranteed to extend as long as the
1395 /// LLVMContext is used by compilation.
1396 void setOptPassGate(OptPassGate&);
1399 } // end namespace llvm
1401 #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H