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 /// \brief 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 /// \brief 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 /// \brief 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 /// \brief 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(int64_t Count, int64_t LowerBound)
328 : Count(Count), LowerBound(LowerBound) {}
329 MDNodeKeyImpl(const DISubrange *N)
330 : Count(N->getCount()), LowerBound(N->getLowerBound()) {}
332 bool isKeyOf(const DISubrange *RHS) const {
333 return Count == RHS->getCount() && LowerBound == RHS->getLowerBound();
336 unsigned getHashValue() const { return hash_combine(Count, LowerBound); }
339 template <> struct MDNodeKeyImpl<DIEnumerator> {
343 MDNodeKeyImpl(int64_t Value, MDString *Name) : Value(Value), Name(Name) {}
344 MDNodeKeyImpl(const DIEnumerator *N)
345 : Value(N->getValue()), Name(N->getRawName()) {}
347 bool isKeyOf(const DIEnumerator *RHS) const {
348 return Value == RHS->getValue() && Name == RHS->getRawName();
351 unsigned getHashValue() const { return hash_combine(Value, Name); }
354 template <> struct MDNodeKeyImpl<DIBasicType> {
358 uint32_t AlignInBits;
361 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
362 uint32_t AlignInBits, unsigned Encoding)
363 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
364 Encoding(Encoding) {}
365 MDNodeKeyImpl(const DIBasicType *N)
366 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
367 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {}
369 bool isKeyOf(const DIBasicType *RHS) const {
370 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
371 SizeInBits == RHS->getSizeInBits() &&
372 AlignInBits == RHS->getAlignInBits() &&
373 Encoding == RHS->getEncoding();
376 unsigned getHashValue() const {
377 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
381 template <> struct MDNodeKeyImpl<DIDerivedType> {
389 uint64_t OffsetInBits;
390 uint32_t AlignInBits;
391 Optional<unsigned> DWARFAddressSpace;
395 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
396 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
397 uint32_t AlignInBits, uint64_t OffsetInBits,
398 Optional<unsigned> DWARFAddressSpace, unsigned Flags,
400 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
401 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
402 AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace),
403 Flags(Flags), ExtraData(ExtraData) {}
404 MDNodeKeyImpl(const DIDerivedType *N)
405 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
406 Line(N->getLine()), Scope(N->getRawScope()),
407 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
408 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
409 DWARFAddressSpace(N->getDWARFAddressSpace()), Flags(N->getFlags()),
410 ExtraData(N->getRawExtraData()) {}
412 bool isKeyOf(const DIDerivedType *RHS) const {
413 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
414 File == RHS->getRawFile() && Line == RHS->getLine() &&
415 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
416 SizeInBits == RHS->getSizeInBits() &&
417 AlignInBits == RHS->getAlignInBits() &&
418 OffsetInBits == RHS->getOffsetInBits() &&
419 DWARFAddressSpace == RHS->getDWARFAddressSpace() &&
420 Flags == RHS->getFlags() &&
421 ExtraData == RHS->getRawExtraData();
424 unsigned getHashValue() const {
425 // If this is a member inside an ODR type, only hash the type and the name.
426 // Otherwise the hash will be stronger than
427 // MDNodeSubsetEqualImpl::isODRMember().
428 if (Tag == dwarf::DW_TAG_member && Name)
429 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
430 if (CT->getRawIdentifier())
431 return hash_combine(Name, Scope);
433 // Intentionally computes the hash on a subset of the operands for
434 // performance reason. The subset has to be significant enough to avoid
435 // collision "most of the time". There is no correctness issue in case of
436 // collision because of the full check above.
437 return hash_combine(Tag, Name, File, Line, Scope, BaseType, Flags);
441 template <> struct MDNodeSubsetEqualImpl<DIDerivedType> {
442 using KeyTy = MDNodeKeyImpl<DIDerivedType>;
444 static bool isSubsetEqual(const KeyTy &LHS, const DIDerivedType *RHS) {
445 return isODRMember(LHS.Tag, LHS.Scope, LHS.Name, RHS);
448 static bool isSubsetEqual(const DIDerivedType *LHS, const DIDerivedType *RHS) {
449 return isODRMember(LHS->getTag(), LHS->getRawScope(), LHS->getRawName(),
453 /// Subprograms compare equal if they declare the same function in an ODR
455 static bool isODRMember(unsigned Tag, const Metadata *Scope,
456 const MDString *Name, const DIDerivedType *RHS) {
457 // Check whether the LHS is eligible.
458 if (Tag != dwarf::DW_TAG_member || !Name)
461 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
462 if (!CT || !CT->getRawIdentifier())
465 // Compare to the RHS.
466 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
467 Scope == RHS->getRawScope();
471 template <> struct MDNodeKeyImpl<DICompositeType> {
479 uint64_t OffsetInBits;
480 uint32_t AlignInBits;
483 unsigned RuntimeLang;
484 Metadata *VTableHolder;
485 Metadata *TemplateParams;
486 MDString *Identifier;
488 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *File, unsigned Line,
489 Metadata *Scope, Metadata *BaseType, uint64_t SizeInBits,
490 uint32_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
491 Metadata *Elements, unsigned RuntimeLang,
492 Metadata *VTableHolder, Metadata *TemplateParams,
493 MDString *Identifier)
494 : Tag(Tag), Name(Name), File(File), Line(Line), Scope(Scope),
495 BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits),
496 AlignInBits(AlignInBits), Flags(Flags), Elements(Elements),
497 RuntimeLang(RuntimeLang), VTableHolder(VTableHolder),
498 TemplateParams(TemplateParams), Identifier(Identifier) {}
499 MDNodeKeyImpl(const DICompositeType *N)
500 : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()),
501 Line(N->getLine()), Scope(N->getRawScope()),
502 BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()),
503 OffsetInBits(N->getOffsetInBits()), AlignInBits(N->getAlignInBits()),
504 Flags(N->getFlags()), Elements(N->getRawElements()),
505 RuntimeLang(N->getRuntimeLang()), VTableHolder(N->getRawVTableHolder()),
506 TemplateParams(N->getRawTemplateParams()),
507 Identifier(N->getRawIdentifier()) {}
509 bool isKeyOf(const DICompositeType *RHS) const {
510 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
511 File == RHS->getRawFile() && Line == RHS->getLine() &&
512 Scope == RHS->getRawScope() && BaseType == RHS->getRawBaseType() &&
513 SizeInBits == RHS->getSizeInBits() &&
514 AlignInBits == RHS->getAlignInBits() &&
515 OffsetInBits == RHS->getOffsetInBits() && Flags == RHS->getFlags() &&
516 Elements == RHS->getRawElements() &&
517 RuntimeLang == RHS->getRuntimeLang() &&
518 VTableHolder == RHS->getRawVTableHolder() &&
519 TemplateParams == RHS->getRawTemplateParams() &&
520 Identifier == RHS->getRawIdentifier();
523 unsigned getHashValue() const {
524 // Intentionally computes the hash on a subset of the operands for
525 // performance reason. The subset has to be significant enough to avoid
526 // collision "most of the time". There is no correctness issue in case of
527 // collision because of the full check above.
528 return hash_combine(Name, File, Line, BaseType, Scope, Elements,
533 template <> struct MDNodeKeyImpl<DISubroutineType> {
538 MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray)
539 : Flags(Flags), CC(CC), TypeArray(TypeArray) {}
540 MDNodeKeyImpl(const DISubroutineType *N)
541 : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {}
543 bool isKeyOf(const DISubroutineType *RHS) const {
544 return Flags == RHS->getFlags() && CC == RHS->getCC() &&
545 TypeArray == RHS->getRawTypeArray();
548 unsigned getHashValue() const { return hash_combine(Flags, CC, TypeArray); }
551 template <> struct MDNodeKeyImpl<DIFile> {
554 DIFile::ChecksumKind CSKind;
557 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
558 DIFile::ChecksumKind CSKind, MDString *Checksum)
559 : Filename(Filename), Directory(Directory), CSKind(CSKind),
560 Checksum(Checksum) {}
561 MDNodeKeyImpl(const DIFile *N)
562 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
563 CSKind(N->getChecksumKind()), Checksum(N->getRawChecksum()) {}
565 bool isKeyOf(const DIFile *RHS) const {
566 return Filename == RHS->getRawFilename() &&
567 Directory == RHS->getRawDirectory() &&
568 CSKind == RHS->getChecksumKind() &&
569 Checksum == RHS->getRawChecksum();
572 unsigned getHashValue() const {
573 return hash_combine(Filename, Directory, CSKind, Checksum);
577 template <> struct MDNodeKeyImpl<DISubprogram> {
580 MDString *LinkageName;
587 Metadata *ContainingType;
589 unsigned VirtualIndex;
594 Metadata *TemplateParams;
595 Metadata *Declaration;
597 Metadata *ThrownTypes;
599 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
600 Metadata *File, unsigned Line, Metadata *Type,
601 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine,
602 Metadata *ContainingType, unsigned Virtuality,
603 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
604 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams,
605 Metadata *Declaration, Metadata *Variables,
606 Metadata *ThrownTypes)
607 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
608 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
609 IsDefinition(IsDefinition), ScopeLine(ScopeLine),
610 ContainingType(ContainingType), Virtuality(Virtuality),
611 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment),
612 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit),
613 TemplateParams(TemplateParams), Declaration(Declaration),
614 Variables(Variables), ThrownTypes(ThrownTypes) {}
615 MDNodeKeyImpl(const DISubprogram *N)
616 : Scope(N->getRawScope()), Name(N->getRawName()),
617 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
618 Line(N->getLine()), Type(N->getRawType()),
619 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
620 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()),
621 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
622 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
623 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()),
624 TemplateParams(N->getRawTemplateParams()),
625 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()),
626 ThrownTypes(N->getRawThrownTypes()) {}
628 bool isKeyOf(const DISubprogram *RHS) const {
629 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
630 LinkageName == RHS->getRawLinkageName() &&
631 File == RHS->getRawFile() && Line == RHS->getLine() &&
632 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
633 IsDefinition == RHS->isDefinition() &&
634 ScopeLine == RHS->getScopeLine() &&
635 ContainingType == RHS->getRawContainingType() &&
636 Virtuality == RHS->getVirtuality() &&
637 VirtualIndex == RHS->getVirtualIndex() &&
638 ThisAdjustment == RHS->getThisAdjustment() &&
639 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() &&
640 Unit == RHS->getUnit() &&
641 TemplateParams == RHS->getRawTemplateParams() &&
642 Declaration == RHS->getRawDeclaration() &&
643 Variables == RHS->getRawVariables() &&
644 ThrownTypes == RHS->getRawThrownTypes();
647 unsigned getHashValue() const {
648 // If this is a declaration inside an ODR type, only hash the type and the
649 // name. Otherwise the hash will be stronger than
650 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
651 if (!IsDefinition && LinkageName)
652 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
653 if (CT->getRawIdentifier())
654 return hash_combine(LinkageName, Scope);
656 // Intentionally computes the hash on a subset of the operands for
657 // performance reason. The subset has to be significant enough to avoid
658 // collision "most of the time". There is no correctness issue in case of
659 // collision because of the full check above.
660 return hash_combine(Name, Scope, File, Type, Line);
664 template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
665 using KeyTy = MDNodeKeyImpl<DISubprogram>;
667 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
668 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope,
669 LHS.LinkageName, LHS.TemplateParams, RHS);
672 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
673 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
674 LHS->getRawLinkageName(),
675 LHS->getRawTemplateParams(), RHS);
678 /// Subprograms compare equal if they declare the same function in an ODR
680 static bool isDeclarationOfODRMember(bool IsDefinition, const Metadata *Scope,
681 const MDString *LinkageName,
682 const Metadata *TemplateParams,
683 const DISubprogram *RHS) {
684 // Check whether the LHS is eligible.
685 if (IsDefinition || !Scope || !LinkageName)
688 auto *CT = dyn_cast_or_null<DICompositeType>(Scope);
689 if (!CT || !CT->getRawIdentifier())
692 // Compare to the RHS.
693 // FIXME: We need to compare template parameters here to avoid incorrect
694 // collisions in mapMetadata when RF_MoveDistinctMDs and a ODR-DISubprogram
695 // has a non-ODR template parameter (i.e., a DICompositeType that does not
696 // have an identifier). Eventually we should decouple ODR logic from
698 return IsDefinition == RHS->isDefinition() && Scope == RHS->getRawScope() &&
699 LinkageName == RHS->getRawLinkageName() &&
700 TemplateParams == RHS->getRawTemplateParams();
704 template <> struct MDNodeKeyImpl<DILexicalBlock> {
710 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column)
711 : Scope(Scope), File(File), Line(Line), Column(Column) {}
712 MDNodeKeyImpl(const DILexicalBlock *N)
713 : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()),
714 Column(N->getColumn()) {}
716 bool isKeyOf(const DILexicalBlock *RHS) const {
717 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
718 Line == RHS->getLine() && Column == RHS->getColumn();
721 unsigned getHashValue() const {
722 return hash_combine(Scope, File, Line, Column);
726 template <> struct MDNodeKeyImpl<DILexicalBlockFile> {
729 unsigned Discriminator;
731 MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator)
732 : Scope(Scope), File(File), Discriminator(Discriminator) {}
733 MDNodeKeyImpl(const DILexicalBlockFile *N)
734 : Scope(N->getRawScope()), File(N->getRawFile()),
735 Discriminator(N->getDiscriminator()) {}
737 bool isKeyOf(const DILexicalBlockFile *RHS) const {
738 return Scope == RHS->getRawScope() && File == RHS->getRawFile() &&
739 Discriminator == RHS->getDiscriminator();
742 unsigned getHashValue() const {
743 return hash_combine(Scope, File, Discriminator);
747 template <> struct MDNodeKeyImpl<DINamespace> {
752 MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols)
753 : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {}
754 MDNodeKeyImpl(const DINamespace *N)
755 : Scope(N->getRawScope()), Name(N->getRawName()),
756 ExportSymbols(N->getExportSymbols()) {}
758 bool isKeyOf(const DINamespace *RHS) const {
759 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
760 ExportSymbols == RHS->getExportSymbols();
763 unsigned getHashValue() const {
764 return hash_combine(Scope, Name);
768 template <> struct MDNodeKeyImpl<DIModule> {
771 MDString *ConfigurationMacros;
772 MDString *IncludePath;
775 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *ConfigurationMacros,
776 MDString *IncludePath, MDString *ISysRoot)
777 : Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros),
778 IncludePath(IncludePath), ISysRoot(ISysRoot) {}
779 MDNodeKeyImpl(const DIModule *N)
780 : Scope(N->getRawScope()), Name(N->getRawName()),
781 ConfigurationMacros(N->getRawConfigurationMacros()),
782 IncludePath(N->getRawIncludePath()), ISysRoot(N->getRawISysRoot()) {}
784 bool isKeyOf(const DIModule *RHS) const {
785 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
786 ConfigurationMacros == RHS->getRawConfigurationMacros() &&
787 IncludePath == RHS->getRawIncludePath() &&
788 ISysRoot == RHS->getRawISysRoot();
791 unsigned getHashValue() const {
792 return hash_combine(Scope, Name,
793 ConfigurationMacros, IncludePath, ISysRoot);
797 template <> struct MDNodeKeyImpl<DITemplateTypeParameter> {
801 MDNodeKeyImpl(MDString *Name, Metadata *Type) : Name(Name), Type(Type) {}
802 MDNodeKeyImpl(const DITemplateTypeParameter *N)
803 : Name(N->getRawName()), Type(N->getRawType()) {}
805 bool isKeyOf(const DITemplateTypeParameter *RHS) const {
806 return Name == RHS->getRawName() && Type == RHS->getRawType();
809 unsigned getHashValue() const { return hash_combine(Name, Type); }
812 template <> struct MDNodeKeyImpl<DITemplateValueParameter> {
818 MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, Metadata *Value)
819 : Tag(Tag), Name(Name), Type(Type), Value(Value) {}
820 MDNodeKeyImpl(const DITemplateValueParameter *N)
821 : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()),
822 Value(N->getValue()) {}
824 bool isKeyOf(const DITemplateValueParameter *RHS) const {
825 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
826 Type == RHS->getRawType() && Value == RHS->getValue();
829 unsigned getHashValue() const { return hash_combine(Tag, Name, Type, Value); }
832 template <> struct MDNodeKeyImpl<DIGlobalVariable> {
835 MDString *LinkageName;
841 Metadata *StaticDataMemberDeclaration;
842 uint32_t AlignInBits;
844 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
845 Metadata *File, unsigned Line, Metadata *Type,
846 bool IsLocalToUnit, bool IsDefinition,
847 Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits)
848 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
849 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
850 IsDefinition(IsDefinition),
851 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
852 AlignInBits(AlignInBits) {}
853 MDNodeKeyImpl(const DIGlobalVariable *N)
854 : Scope(N->getRawScope()), Name(N->getRawName()),
855 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
856 Line(N->getLine()), Type(N->getRawType()),
857 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
858 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
859 AlignInBits(N->getAlignInBits()) {}
861 bool isKeyOf(const DIGlobalVariable *RHS) const {
862 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
863 LinkageName == RHS->getRawLinkageName() &&
864 File == RHS->getRawFile() && Line == RHS->getLine() &&
865 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
866 IsDefinition == RHS->isDefinition() &&
867 StaticDataMemberDeclaration ==
868 RHS->getRawStaticDataMemberDeclaration() &&
869 AlignInBits == RHS->getAlignInBits();
872 unsigned getHashValue() const {
873 // We do not use AlignInBits in hashing function here on purpose:
874 // in most cases this param for local variable is zero (for function param
875 // it is always zero). This leads to lots of hash collisions and errors on
876 // cases with lots of similar variables.
877 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
878 // generated IR is random for each run and test fails with Align included.
879 // TODO: make hashing work fine with such situations
880 return hash_combine(Scope, Name, LinkageName, File, Line, Type,
881 IsLocalToUnit, IsDefinition, /* AlignInBits, */
882 StaticDataMemberDeclaration);
886 template <> struct MDNodeKeyImpl<DILocalVariable> {
894 uint32_t AlignInBits;
896 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
897 Metadata *Type, unsigned Arg, unsigned Flags,
898 uint32_t AlignInBits)
899 : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
900 Flags(Flags), AlignInBits(AlignInBits) {}
901 MDNodeKeyImpl(const DILocalVariable *N)
902 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
903 Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
904 Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
906 bool isKeyOf(const DILocalVariable *RHS) const {
907 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
908 File == RHS->getRawFile() && Line == RHS->getLine() &&
909 Type == RHS->getRawType() && Arg == RHS->getArg() &&
910 Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
913 unsigned getHashValue() const {
914 // We do not use AlignInBits in hashing function here on purpose:
915 // in most cases this param for local variable is zero (for function param
916 // it is always zero). This leads to lots of hash collisions and errors on
917 // cases with lots of similar variables.
918 // clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
919 // generated IR is random for each run and test fails with Align included.
920 // TODO: make hashing work fine with such situations
921 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
925 template <> struct MDNodeKeyImpl<DIExpression> {
926 ArrayRef<uint64_t> Elements;
928 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
929 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
931 bool isKeyOf(const DIExpression *RHS) const {
932 return Elements == RHS->getElements();
935 unsigned getHashValue() const {
936 return hash_combine_range(Elements.begin(), Elements.end());
940 template <> struct MDNodeKeyImpl<DIGlobalVariableExpression> {
942 Metadata *Expression;
944 MDNodeKeyImpl(Metadata *Variable, Metadata *Expression)
945 : Variable(Variable), Expression(Expression) {}
946 MDNodeKeyImpl(const DIGlobalVariableExpression *N)
947 : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {}
949 bool isKeyOf(const DIGlobalVariableExpression *RHS) const {
950 return Variable == RHS->getRawVariable() &&
951 Expression == RHS->getRawExpression();
954 unsigned getHashValue() const { return hash_combine(Variable, Expression); }
957 template <> struct MDNodeKeyImpl<DIObjCProperty> {
961 MDString *GetterName;
962 MDString *SetterName;
966 MDNodeKeyImpl(MDString *Name, Metadata *File, unsigned Line,
967 MDString *GetterName, MDString *SetterName, unsigned Attributes,
969 : Name(Name), File(File), Line(Line), GetterName(GetterName),
970 SetterName(SetterName), Attributes(Attributes), Type(Type) {}
971 MDNodeKeyImpl(const DIObjCProperty *N)
972 : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()),
973 GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()),
974 Attributes(N->getAttributes()), Type(N->getRawType()) {}
976 bool isKeyOf(const DIObjCProperty *RHS) const {
977 return Name == RHS->getRawName() && File == RHS->getRawFile() &&
978 Line == RHS->getLine() && GetterName == RHS->getRawGetterName() &&
979 SetterName == RHS->getRawSetterName() &&
980 Attributes == RHS->getAttributes() && Type == RHS->getRawType();
983 unsigned getHashValue() const {
984 return hash_combine(Name, File, Line, GetterName, SetterName, Attributes,
989 template <> struct MDNodeKeyImpl<DIImportedEntity> {
997 MDNodeKeyImpl(unsigned Tag, Metadata *Scope, Metadata *Entity, Metadata *File,
998 unsigned Line, MDString *Name)
999 : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line),
1001 MDNodeKeyImpl(const DIImportedEntity *N)
1002 : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()),
1003 File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()) {}
1005 bool isKeyOf(const DIImportedEntity *RHS) const {
1006 return Tag == RHS->getTag() && Scope == RHS->getRawScope() &&
1007 Entity == RHS->getRawEntity() && File == RHS->getFile() &&
1008 Line == RHS->getLine() && Name == RHS->getRawName();
1011 unsigned getHashValue() const {
1012 return hash_combine(Tag, Scope, Entity, File, Line, Name);
1016 template <> struct MDNodeKeyImpl<DIMacro> {
1022 MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value)
1023 : MIType(MIType), Line(Line), Name(Name), Value(Value) {}
1024 MDNodeKeyImpl(const DIMacro *N)
1025 : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()),
1026 Value(N->getRawValue()) {}
1028 bool isKeyOf(const DIMacro *RHS) const {
1029 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1030 Name == RHS->getRawName() && Value == RHS->getRawValue();
1033 unsigned getHashValue() const {
1034 return hash_combine(MIType, Line, Name, Value);
1038 template <> struct MDNodeKeyImpl<DIMacroFile> {
1044 MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File,
1046 : MIType(MIType), Line(Line), File(File), Elements(Elements) {}
1047 MDNodeKeyImpl(const DIMacroFile *N)
1048 : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()),
1049 Elements(N->getRawElements()) {}
1051 bool isKeyOf(const DIMacroFile *RHS) const {
1052 return MIType == RHS->getMacinfoType() && Line == RHS->getLine() &&
1053 File == RHS->getRawFile() && Elements == RHS->getRawElements();
1056 unsigned getHashValue() const {
1057 return hash_combine(MIType, Line, File, Elements);
1061 /// \brief DenseMapInfo for MDNode subclasses.
1062 template <class NodeTy> struct MDNodeInfo {
1063 using KeyTy = MDNodeKeyImpl<NodeTy>;
1064 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1066 static inline NodeTy *getEmptyKey() {
1067 return DenseMapInfo<NodeTy *>::getEmptyKey();
1070 static inline NodeTy *getTombstoneKey() {
1071 return DenseMapInfo<NodeTy *>::getTombstoneKey();
1074 static unsigned getHashValue(const KeyTy &Key) { return Key.getHashValue(); }
1076 static unsigned getHashValue(const NodeTy *N) {
1077 return KeyTy(N).getHashValue();
1080 static bool isEqual(const KeyTy &LHS, const NodeTy *RHS) {
1081 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1083 return SubsetEqualTy::isSubsetEqual(LHS, RHS) || LHS.isKeyOf(RHS);
1086 static bool isEqual(const NodeTy *LHS, const NodeTy *RHS) {
1089 if (RHS == getEmptyKey() || RHS == getTombstoneKey())
1091 return SubsetEqualTy::isSubsetEqual(LHS, RHS);
1095 #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
1096 #include "llvm/IR/Metadata.def"
1098 /// \brief Map-like storage for metadata attachments.
1099 class MDAttachmentMap {
1100 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1103 bool empty() const { return Attachments.empty(); }
1104 size_t size() const { return Attachments.size(); }
1106 /// \brief Get a particular attachment (if any).
1107 MDNode *lookup(unsigned ID) const;
1109 /// \brief Set an attachment to a particular node.
1111 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1113 void set(unsigned ID, MDNode &MD);
1115 /// \brief Remove an attachment.
1117 /// Remove the attachment at \c ID, if any.
1118 void erase(unsigned ID);
1120 /// \brief Copy out all the attachments.
1122 /// Copies all the current attachments into \c Result, sorting by attachment
1123 /// ID. This function does \em not clear \c Result.
1124 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1126 /// \brief Erase matching attachments.
1128 /// Erases all attachments matching the \c shouldRemove predicate.
1129 template <class PredTy> void remove_if(PredTy shouldRemove) {
1130 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1135 /// Multimap-like storage for metadata attachments for globals. This differs
1136 /// from MDAttachmentMap in that it allows multiple attachments per metadata
1138 class MDGlobalAttachmentMap {
1141 TrackingMDNodeRef Node;
1143 SmallVector<Attachment, 1> Attachments;
1146 bool empty() const { return Attachments.empty(); }
1148 /// Appends all attachments with the given ID to \c Result in insertion order.
1149 /// If the global has no attachments with the given ID, or if ID is invalid,
1150 /// leaves Result unchanged.
1151 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result);
1153 void insert(unsigned ID, MDNode &MD);
1154 void erase(unsigned ID);
1156 /// Appends all attachments for the global to \c Result, sorting by attachment
1157 /// ID. Attachments with the same ID appear in insertion order. This function
1158 /// does \em not clear \c Result.
1159 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1162 class LLVMContextImpl {
1164 /// OwnedModules - The set of modules instantiated in this context, and which
1165 /// will be automatically deleted if this context is deleted.
1166 SmallPtrSet<Module*, 4> OwnedModules;
1168 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1169 void *InlineAsmDiagContext = nullptr;
1171 std::unique_ptr<DiagnosticHandler> DiagHandler;
1172 bool RespectDiagnosticFilters = false;
1173 bool DiagnosticsHotnessRequested = false;
1174 uint64_t DiagnosticsHotnessThreshold = 0;
1175 std::unique_ptr<yaml::Output> DiagnosticsOutputFile;
1177 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1178 void *YieldOpaqueHandle = nullptr;
1181 DenseMap<APInt, std::unique_ptr<ConstantInt>, DenseMapAPIntKeyInfo>;
1182 IntMapTy IntConstants;
1185 DenseMap<APFloat, std::unique_ptr<ConstantFP>, DenseMapAPFloatKeyInfo>;
1186 FPMapTy FPConstants;
1188 FoldingSet<AttributeImpl> AttrsSet;
1189 FoldingSet<AttributeListImpl> AttrsLists;
1190 FoldingSet<AttributeSetNode> AttrsSetNodes;
1192 StringMap<MDString, BumpPtrAllocator> MDStringCache;
1193 DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;
1194 DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;
1196 DenseMap<const Value*, ValueName*> ValueNames;
1198 #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS) \
1199 DenseSet<CLASS *, CLASS##Info> CLASS##s;
1200 #include "llvm/IR/Metadata.def"
1202 // Optional map for looking up composite types by identifier.
1203 Optional<DenseMap<const MDString *, DICompositeType *>> DITypeMap;
1205 // MDNodes may be uniqued or not uniqued. When they're not uniqued, they
1206 // aren't in the MDNodeSet, but they're still shared between objects, so no
1207 // one object can destroy them. Keep track of them here so we can delete
1208 // them on context teardown.
1209 std::vector<MDNode *> DistinctMDNodes;
1211 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
1213 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
1214 ArrayConstantsTy ArrayConstants;
1216 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
1217 StructConstantsTy StructConstants;
1219 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
1220 VectorConstantsTy VectorConstants;
1222 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1224 DenseMap<Type *, std::unique_ptr<UndefValue>> UVConstants;
1226 StringMap<ConstantDataSequential*> CDSConstants;
1228 DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *>
1230 ConstantUniqueMap<ConstantExpr> ExprConstants;
1232 ConstantUniqueMap<InlineAsm> InlineAsms;
1234 ConstantInt *TheTrueVal = nullptr;
1235 ConstantInt *TheFalseVal = nullptr;
1237 std::unique_ptr<ConstantTokenNone> TheNoneToken;
1239 // Basic type instances.
1240 Type VoidTy, LabelTy, HalfTy, FloatTy, DoubleTy, MetadataTy, TokenTy;
1241 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
1242 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
1244 /// TypeAllocator - All dynamically allocated types are allocated from this.
1245 /// They live forever until the context is torn down.
1246 BumpPtrAllocator TypeAllocator;
1248 DenseMap<unsigned, IntegerType*> IntegerTypes;
1250 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
1251 FunctionTypeSet FunctionTypes;
1252 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
1253 StructTypeSet AnonStructTypes;
1254 StringMap<StructType*> NamedStructTypes;
1255 unsigned NamedStructTypesUniqueID = 0;
1257 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1258 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes;
1259 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1260 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
1262 /// ValueHandles - This map keeps track of all of the value handles that are
1263 /// watching a Value*. The Value::HasValueHandle bit is used to know
1264 /// whether or not a value has an entry in this map.
1265 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
1266 ValueHandlesTy ValueHandles;
1268 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1269 StringMap<unsigned> CustomMDKindNames;
1271 /// Collection of per-instruction metadata used in this context.
1272 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
1274 /// Collection of per-GlobalObject metadata used in this context.
1275 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
1277 /// Collection of per-GlobalObject sections used in this context.
1278 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1280 /// Stable collection of section strings.
1281 StringSet<> SectionStrings;
1283 /// DiscriminatorTable - This table maps file:line locations to an
1284 /// integer representing the next DWARF path discriminator to assign to
1285 /// instructions in different blocks at the same location.
1286 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1288 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1289 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
1291 /// \brief A set of interned tags for operand bundles. The StringMap maps
1292 /// bundle tags to their IDs.
1294 /// \see LLVMContext::getOperandBundleTagID
1295 StringMap<uint32_t> BundleTagCache;
1297 StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef Tag);
1298 void getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const;
1299 uint32_t getOperandBundleTagID(StringRef Tag) const;
1301 /// A set of interned synchronization scopes. The StringMap maps
1302 /// synchronization scope names to their respective synchronization scope IDs.
1303 StringMap<SyncScope::ID> SSC;
1305 /// getOrInsertSyncScopeID - Maps synchronization scope name to
1306 /// synchronization scope ID. Every synchronization scope registered with
1307 /// LLVMContext has unique ID except pre-defined ones.
1308 SyncScope::ID getOrInsertSyncScopeID(StringRef SSN);
1310 /// getSyncScopeNames - Populates client supplied SmallVector with
1311 /// synchronization scope names registered with LLVMContext. Synchronization
1312 /// scope names are ordered by increasing synchronization scope IDs.
1313 void getSyncScopeNames(SmallVectorImpl<StringRef> &SSNs) const;
1315 /// Maintain the GC name for each function.
1317 /// This saves allocating an additional word in Function for programs which
1318 /// do not use GC (i.e., most programs) at the cost of increased overhead for
1319 /// clients which do use GC.
1320 DenseMap<const Function*, std::string> GCNames;
1322 /// Flag to indicate if Value (other than GlobalValue) retains their name or
1324 bool DiscardValueNames = false;
1326 LLVMContextImpl(LLVMContext &C);
1329 /// Destroy the ConstantArrays if they are not used.
1330 void dropTriviallyDeadConstantArrays();
1332 /// \brief Access the object which manages optimization bisection for failure
1334 OptBisect &getOptBisect();
1337 } // end namespace llvm
1339 #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H