comparison lib/IR/LLVMContextImpl.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents 7c836c76d71d c2174574ed3a
children
comparison
equal deleted inserted replaced
146:3fc4d5c3e21e 148:63bd29f05246
1 //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===// 1 //===- LLVMContextImpl.h - The LLVMContextImpl opaque class -----*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // 4 // See https://llvm.org/LICENSE.txt for license information.
5 // This file is distributed under the University of Illinois Open Source 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 // License. See LICENSE.TXT for details.
7 // 6 //
8 //===----------------------------------------------------------------------===// 7 //===----------------------------------------------------------------------===//
9 // 8 //
10 // This file declares LLVMContextImpl, the opaque implementation 9 // This file declares LLVMContextImpl, the opaque implementation
11 // of LLVMContext. 10 // of LLVMContext.
12 // 11 //
13 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
14 13
15 #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H 14 #ifndef LLVM_LIB_IR_LLVMCONTEXTIMPL_H
29 #include "llvm/ADT/STLExtras.h" 28 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/ADT/SmallPtrSet.h" 29 #include "llvm/ADT/SmallPtrSet.h"
31 #include "llvm/ADT/SmallVector.h" 30 #include "llvm/ADT/SmallVector.h"
32 #include "llvm/ADT/StringMap.h" 31 #include "llvm/ADT/StringMap.h"
33 #include "llvm/ADT/StringRef.h" 32 #include "llvm/ADT/StringRef.h"
34 #include "llvm/ADT/StringSet.h"
35 #include "llvm/BinaryFormat/Dwarf.h" 33 #include "llvm/BinaryFormat/Dwarf.h"
36 #include "llvm/IR/Constants.h" 34 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DebugInfoMetadata.h" 35 #include "llvm/IR/DebugInfoMetadata.h"
38 #include "llvm/IR/DerivedTypes.h" 36 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/LLVMContext.h" 37 #include "llvm/IR/LLVMContext.h"
40 #include "llvm/IR/Metadata.h" 38 #include "llvm/IR/Metadata.h"
39 #include "llvm/IR/RemarkStreamer.h"
41 #include "llvm/IR/TrackingMDRef.h" 40 #include "llvm/IR/TrackingMDRef.h"
42 #include "llvm/Support/Allocator.h" 41 #include "llvm/Support/Allocator.h"
43 #include "llvm/Support/Casting.h" 42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/StringSaver.h"
44 #include "llvm/Support/YAMLTraits.h" 44 #include "llvm/Support/YAMLTraits.h"
45 #include <algorithm> 45 #include <algorithm>
46 #include <cassert> 46 #include <cassert>
47 #include <cstddef> 47 #include <cstddef>
48 #include <cstdint> 48 #include <cstdint>
200 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) { 200 static bool isEqual(const FunctionType *LHS, const FunctionType *RHS) {
201 return LHS == RHS; 201 return LHS == RHS;
202 } 202 }
203 }; 203 };
204 204
205 /// \brief Structure for hashing arbitrary MDNode operands. 205 /// Structure for hashing arbitrary MDNode operands.
206 class MDNodeOpsKey { 206 class MDNodeOpsKey {
207 ArrayRef<Metadata *> RawOps; 207 ArrayRef<Metadata *> RawOps;
208 ArrayRef<MDOperand> Ops; 208 ArrayRef<MDOperand> Ops;
209 unsigned Hash; 209 unsigned Hash;
210 210
255 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) { 255 static bool isSubsetEqual(const NodeTy *LHS, const NodeTy *RHS) {
256 return false; 256 return false;
257 } 257 }
258 }; 258 };
259 259
260 /// \brief DenseMapInfo for MDTuple. 260 /// DenseMapInfo for MDTuple.
261 /// 261 ///
262 /// Note that we don't need the is-function-local bit, since that's implicit in 262 /// Note that we don't need the is-function-local bit, since that's implicit in
263 /// the operands. 263 /// the operands.
264 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey { 264 template <> struct MDNodeKeyImpl<MDTuple> : MDNodeOpsKey {
265 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {} 265 MDNodeKeyImpl(ArrayRef<Metadata *> Ops) : MDNodeOpsKey(Ops) {}
272 static unsigned calculateHash(MDTuple *N) { 272 static unsigned calculateHash(MDTuple *N) {
273 return MDNodeOpsKey::calculateHash(N); 273 return MDNodeOpsKey::calculateHash(N);
274 } 274 }
275 }; 275 };
276 276
277 /// \brief DenseMapInfo for DILocation. 277 /// DenseMapInfo for DILocation.
278 template <> struct MDNodeKeyImpl<DILocation> { 278 template <> struct MDNodeKeyImpl<DILocation> {
279 unsigned Line; 279 unsigned Line;
280 unsigned Column; 280 unsigned Column;
281 Metadata *Scope; 281 Metadata *Scope;
282 Metadata *InlinedAt; 282 Metadata *InlinedAt;
283 bool ImplicitCode;
283 284
284 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope, 285 MDNodeKeyImpl(unsigned Line, unsigned Column, Metadata *Scope,
285 Metadata *InlinedAt) 286 Metadata *InlinedAt, bool ImplicitCode)
286 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt) {} 287 : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt),
288 ImplicitCode(ImplicitCode) {}
287 MDNodeKeyImpl(const DILocation *L) 289 MDNodeKeyImpl(const DILocation *L)
288 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), 290 : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()),
289 InlinedAt(L->getRawInlinedAt()) {} 291 InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {}
290 292
291 bool isKeyOf(const DILocation *RHS) const { 293 bool isKeyOf(const DILocation *RHS) const {
292 return Line == RHS->getLine() && Column == RHS->getColumn() && 294 return Line == RHS->getLine() && Column == RHS->getColumn() &&
293 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt(); 295 Scope == RHS->getRawScope() && InlinedAt == RHS->getRawInlinedAt() &&
294 } 296 ImplicitCode == RHS->isImplicitCode();
295 297 }
296 unsigned getHashValue() const { 298
297 return hash_combine(Line, Column, Scope, InlinedAt); 299 unsigned getHashValue() const {
298 } 300 return hash_combine(Line, Column, Scope, InlinedAt, ImplicitCode);
299 }; 301 }
300 302 };
301 /// \brief DenseMapInfo for GenericDINode. 303
304 /// DenseMapInfo for GenericDINode.
302 template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey { 305 template <> struct MDNodeKeyImpl<GenericDINode> : MDNodeOpsKey {
303 unsigned Tag; 306 unsigned Tag;
304 MDString *Header; 307 MDString *Header;
305 308
306 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps) 309 MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef<Metadata *> DwarfOps)
374 unsigned Tag; 377 unsigned Tag;
375 MDString *Name; 378 MDString *Name;
376 uint64_t SizeInBits; 379 uint64_t SizeInBits;
377 uint32_t AlignInBits; 380 uint32_t AlignInBits;
378 unsigned Encoding; 381 unsigned Encoding;
382 unsigned Flags;
379 383
380 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits, 384 MDNodeKeyImpl(unsigned Tag, MDString *Name, uint64_t SizeInBits,
381 uint32_t AlignInBits, unsigned Encoding) 385 uint32_t AlignInBits, unsigned Encoding, unsigned Flags)
382 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), 386 : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits),
383 Encoding(Encoding) {} 387 Encoding(Encoding), Flags(Flags) {}
384 MDNodeKeyImpl(const DIBasicType *N) 388 MDNodeKeyImpl(const DIBasicType *N)
385 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), 389 : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()),
386 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()) {} 390 AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {}
387 391
388 bool isKeyOf(const DIBasicType *RHS) const { 392 bool isKeyOf(const DIBasicType *RHS) const {
389 return Tag == RHS->getTag() && Name == RHS->getRawName() && 393 return Tag == RHS->getTag() && Name == RHS->getRawName() &&
390 SizeInBits == RHS->getSizeInBits() && 394 SizeInBits == RHS->getSizeInBits() &&
391 AlignInBits == RHS->getAlignInBits() && 395 AlignInBits == RHS->getAlignInBits() &&
392 Encoding == RHS->getEncoding(); 396 Encoding == RHS->getEncoding() &&
397 Flags == RHS->getFlags();
393 } 398 }
394 399
395 unsigned getHashValue() const { 400 unsigned getHashValue() const {
396 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding); 401 return hash_combine(Tag, Name, SizeInBits, AlignInBits, Encoding);
397 } 402 }
573 578
574 template <> struct MDNodeKeyImpl<DIFile> { 579 template <> struct MDNodeKeyImpl<DIFile> {
575 MDString *Filename; 580 MDString *Filename;
576 MDString *Directory; 581 MDString *Directory;
577 Optional<DIFile::ChecksumInfo<MDString *>> Checksum; 582 Optional<DIFile::ChecksumInfo<MDString *>> Checksum;
583 Optional<MDString *> Source;
578 584
579 MDNodeKeyImpl(MDString *Filename, MDString *Directory, 585 MDNodeKeyImpl(MDString *Filename, MDString *Directory,
580 Optional<DIFile::ChecksumInfo<MDString *>> Checksum) 586 Optional<DIFile::ChecksumInfo<MDString *>> Checksum,
581 : Filename(Filename), Directory(Directory), Checksum(Checksum) {} 587 Optional<MDString *> Source)
588 : Filename(Filename), Directory(Directory), Checksum(Checksum),
589 Source(Source) {}
582 MDNodeKeyImpl(const DIFile *N) 590 MDNodeKeyImpl(const DIFile *N)
583 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()), 591 : Filename(N->getRawFilename()), Directory(N->getRawDirectory()),
584 Checksum(N->getRawChecksum()) {} 592 Checksum(N->getRawChecksum()), Source(N->getRawSource()) {}
585 593
586 bool isKeyOf(const DIFile *RHS) const { 594 bool isKeyOf(const DIFile *RHS) const {
587 return Filename == RHS->getRawFilename() && 595 return Filename == RHS->getRawFilename() &&
588 Directory == RHS->getRawDirectory() && 596 Directory == RHS->getRawDirectory() &&
589 Checksum == RHS->getRawChecksum(); 597 Checksum == RHS->getRawChecksum() &&
590 } 598 Source == RHS->getRawSource();
591 599 }
592 unsigned getHashValue() const { 600
593 if (Checksum) 601 unsigned getHashValue() const {
594 return hash_combine(Filename, Directory, Checksum->Kind, Checksum->Value); 602 return hash_combine(
595 return hash_combine(Filename, Directory); 603 Filename, Directory, Checksum ? Checksum->Kind : 0,
604 Checksum ? Checksum->Value : nullptr, Source.getValueOr(nullptr));
596 } 605 }
597 }; 606 };
598 607
599 template <> struct MDNodeKeyImpl<DISubprogram> { 608 template <> struct MDNodeKeyImpl<DISubprogram> {
600 Metadata *Scope; 609 Metadata *Scope;
601 MDString *Name; 610 MDString *Name;
602 MDString *LinkageName; 611 MDString *LinkageName;
603 Metadata *File; 612 Metadata *File;
604 unsigned Line; 613 unsigned Line;
605 Metadata *Type; 614 Metadata *Type;
606 bool IsLocalToUnit;
607 bool IsDefinition;
608 unsigned ScopeLine; 615 unsigned ScopeLine;
609 Metadata *ContainingType; 616 Metadata *ContainingType;
610 unsigned Virtuality;
611 unsigned VirtualIndex; 617 unsigned VirtualIndex;
612 int ThisAdjustment; 618 int ThisAdjustment;
613 unsigned Flags; 619 unsigned Flags;
614 bool IsOptimized; 620 unsigned SPFlags;
615 Metadata *Unit; 621 Metadata *Unit;
616 Metadata *TemplateParams; 622 Metadata *TemplateParams;
617 Metadata *Declaration; 623 Metadata *Declaration;
618 Metadata *Variables; 624 Metadata *RetainedNodes;
619 Metadata *ThrownTypes; 625 Metadata *ThrownTypes;
620 626
621 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, 627 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
622 Metadata *File, unsigned Line, Metadata *Type, 628 Metadata *File, unsigned Line, Metadata *Type,
623 bool IsLocalToUnit, bool IsDefinition, unsigned ScopeLine, 629 unsigned ScopeLine, Metadata *ContainingType,
624 Metadata *ContainingType, unsigned Virtuality,
625 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags, 630 unsigned VirtualIndex, int ThisAdjustment, unsigned Flags,
626 bool IsOptimized, Metadata *Unit, Metadata *TemplateParams, 631 unsigned SPFlags, Metadata *Unit, Metadata *TemplateParams,
627 Metadata *Declaration, Metadata *Variables, 632 Metadata *Declaration, Metadata *RetainedNodes,
628 Metadata *ThrownTypes) 633 Metadata *ThrownTypes)
629 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), 634 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
630 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), 635 Line(Line), Type(Type), ScopeLine(ScopeLine),
631 IsDefinition(IsDefinition), ScopeLine(ScopeLine), 636 ContainingType(ContainingType), VirtualIndex(VirtualIndex),
632 ContainingType(ContainingType), Virtuality(Virtuality), 637 ThisAdjustment(ThisAdjustment), Flags(Flags), SPFlags(SPFlags),
633 VirtualIndex(VirtualIndex), ThisAdjustment(ThisAdjustment), 638 Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration),
634 Flags(Flags), IsOptimized(IsOptimized), Unit(Unit), 639 RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes) {}
635 TemplateParams(TemplateParams), Declaration(Declaration),
636 Variables(Variables), ThrownTypes(ThrownTypes) {}
637 MDNodeKeyImpl(const DISubprogram *N) 640 MDNodeKeyImpl(const DISubprogram *N)
638 : Scope(N->getRawScope()), Name(N->getRawName()), 641 : Scope(N->getRawScope()), Name(N->getRawName()),
639 LinkageName(N->getRawLinkageName()), File(N->getRawFile()), 642 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
640 Line(N->getLine()), Type(N->getRawType()), 643 Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()),
641 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), 644 ContainingType(N->getRawContainingType()),
642 ScopeLine(N->getScopeLine()), ContainingType(N->getRawContainingType()), 645 VirtualIndex(N->getVirtualIndex()),
643 Virtuality(N->getVirtuality()), VirtualIndex(N->getVirtualIndex()),
644 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()), 646 ThisAdjustment(N->getThisAdjustment()), Flags(N->getFlags()),
645 IsOptimized(N->isOptimized()), Unit(N->getRawUnit()), 647 SPFlags(N->getSPFlags()), Unit(N->getRawUnit()),
646 TemplateParams(N->getRawTemplateParams()), 648 TemplateParams(N->getRawTemplateParams()),
647 Declaration(N->getRawDeclaration()), Variables(N->getRawVariables()), 649 Declaration(N->getRawDeclaration()),
650 RetainedNodes(N->getRawRetainedNodes()),
648 ThrownTypes(N->getRawThrownTypes()) {} 651 ThrownTypes(N->getRawThrownTypes()) {}
649 652
650 bool isKeyOf(const DISubprogram *RHS) const { 653 bool isKeyOf(const DISubprogram *RHS) const {
651 return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 654 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
652 LinkageName == RHS->getRawLinkageName() && 655 LinkageName == RHS->getRawLinkageName() &&
653 File == RHS->getRawFile() && Line == RHS->getLine() && 656 File == RHS->getRawFile() && Line == RHS->getLine() &&
654 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() && 657 Type == RHS->getRawType() && ScopeLine == RHS->getScopeLine() &&
655 IsDefinition == RHS->isDefinition() &&
656 ScopeLine == RHS->getScopeLine() &&
657 ContainingType == RHS->getRawContainingType() && 658 ContainingType == RHS->getRawContainingType() &&
658 Virtuality == RHS->getVirtuality() &&
659 VirtualIndex == RHS->getVirtualIndex() && 659 VirtualIndex == RHS->getVirtualIndex() &&
660 ThisAdjustment == RHS->getThisAdjustment() && 660 ThisAdjustment == RHS->getThisAdjustment() &&
661 Flags == RHS->getFlags() && IsOptimized == RHS->isOptimized() && 661 Flags == RHS->getFlags() && SPFlags == RHS->getSPFlags() &&
662 Unit == RHS->getUnit() && 662 Unit == RHS->getUnit() &&
663 TemplateParams == RHS->getRawTemplateParams() && 663 TemplateParams == RHS->getRawTemplateParams() &&
664 Declaration == RHS->getRawDeclaration() && 664 Declaration == RHS->getRawDeclaration() &&
665 Variables == RHS->getRawVariables() && 665 RetainedNodes == RHS->getRawRetainedNodes() &&
666 ThrownTypes == RHS->getRawThrownTypes(); 666 ThrownTypes == RHS->getRawThrownTypes();
667 } 667 }
668
669 bool isDefinition() const { return SPFlags & DISubprogram::SPFlagDefinition; }
668 670
669 unsigned getHashValue() const { 671 unsigned getHashValue() const {
670 // If this is a declaration inside an ODR type, only hash the type and the 672 // If this is a declaration inside an ODR type, only hash the type and the
671 // name. Otherwise the hash will be stronger than 673 // name. Otherwise the hash will be stronger than
672 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember(). 674 // MDNodeSubsetEqualImpl::isDeclarationOfODRMember().
673 if (!IsDefinition && LinkageName) 675 if (!isDefinition() && LinkageName)
674 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope)) 676 if (auto *CT = dyn_cast_or_null<DICompositeType>(Scope))
675 if (CT->getRawIdentifier()) 677 if (CT->getRawIdentifier())
676 return hash_combine(LinkageName, Scope); 678 return hash_combine(LinkageName, Scope);
677 679
678 // Intentionally computes the hash on a subset of the operands for 680 // Intentionally computes the hash on a subset of the operands for
685 687
686 template <> struct MDNodeSubsetEqualImpl<DISubprogram> { 688 template <> struct MDNodeSubsetEqualImpl<DISubprogram> {
687 using KeyTy = MDNodeKeyImpl<DISubprogram>; 689 using KeyTy = MDNodeKeyImpl<DISubprogram>;
688 690
689 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) { 691 static bool isSubsetEqual(const KeyTy &LHS, const DISubprogram *RHS) {
690 return isDeclarationOfODRMember(LHS.IsDefinition, LHS.Scope, 692 return isDeclarationOfODRMember(LHS.isDefinition(), LHS.Scope,
691 LHS.LinkageName, LHS.TemplateParams, RHS); 693 LHS.LinkageName, LHS.TemplateParams, RHS);
692 } 694 }
693 695
694 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) { 696 static bool isSubsetEqual(const DISubprogram *LHS, const DISubprogram *RHS) {
695 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(), 697 return isDeclarationOfODRMember(LHS->isDefinition(), LHS->getRawScope(),
785 unsigned getHashValue() const { 787 unsigned getHashValue() const {
786 return hash_combine(Scope, Name); 788 return hash_combine(Scope, Name);
787 } 789 }
788 }; 790 };
789 791
792 template <> struct MDNodeKeyImpl<DICommonBlock> {
793 Metadata *Scope;
794 Metadata *Decl;
795 MDString *Name;
796 Metadata *File;
797 unsigned LineNo;
798
799 MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name,
800 Metadata *File, unsigned LineNo)
801 : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {}
802 MDNodeKeyImpl(const DICommonBlock *N)
803 : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()),
804 File(N->getRawFile()), LineNo(N->getLineNo()) {}
805
806 bool isKeyOf(const DICommonBlock *RHS) const {
807 return Scope == RHS->getRawScope() && Decl == RHS->getRawDecl() &&
808 Name == RHS->getRawName() && File == RHS->getRawFile() &&
809 LineNo == RHS->getLineNo();
810 }
811
812 unsigned getHashValue() const {
813 return hash_combine(Scope, Decl, Name, File, LineNo);
814 }
815 };
816
790 template <> struct MDNodeKeyImpl<DIModule> { 817 template <> struct MDNodeKeyImpl<DIModule> {
791 Metadata *Scope; 818 Metadata *Scope;
792 MDString *Name; 819 MDString *Name;
793 MDString *ConfigurationMacros; 820 MDString *ConfigurationMacros;
794 MDString *IncludePath; 821 MDString *IncludePath;
859 unsigned Line; 886 unsigned Line;
860 Metadata *Type; 887 Metadata *Type;
861 bool IsLocalToUnit; 888 bool IsLocalToUnit;
862 bool IsDefinition; 889 bool IsDefinition;
863 Metadata *StaticDataMemberDeclaration; 890 Metadata *StaticDataMemberDeclaration;
891 Metadata *TemplateParams;
864 uint32_t AlignInBits; 892 uint32_t AlignInBits;
865 893
866 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, 894 MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
867 Metadata *File, unsigned Line, Metadata *Type, 895 Metadata *File, unsigned Line, Metadata *Type,
868 bool IsLocalToUnit, bool IsDefinition, 896 bool IsLocalToUnit, bool IsDefinition,
869 Metadata *StaticDataMemberDeclaration, uint32_t AlignInBits) 897 Metadata *StaticDataMemberDeclaration, Metadata *TemplateParams,
898 uint32_t AlignInBits)
870 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), 899 : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
871 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), 900 Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
872 IsDefinition(IsDefinition), 901 IsDefinition(IsDefinition),
873 StaticDataMemberDeclaration(StaticDataMemberDeclaration), 902 StaticDataMemberDeclaration(StaticDataMemberDeclaration),
874 AlignInBits(AlignInBits) {} 903 TemplateParams(TemplateParams), AlignInBits(AlignInBits) {}
875 MDNodeKeyImpl(const DIGlobalVariable *N) 904 MDNodeKeyImpl(const DIGlobalVariable *N)
876 : Scope(N->getRawScope()), Name(N->getRawName()), 905 : Scope(N->getRawScope()), Name(N->getRawName()),
877 LinkageName(N->getRawLinkageName()), File(N->getRawFile()), 906 LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
878 Line(N->getLine()), Type(N->getRawType()), 907 Line(N->getLine()), Type(N->getRawType()),
879 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), 908 IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
880 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()), 909 StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
910 TemplateParams(N->getRawTemplateParams()),
881 AlignInBits(N->getAlignInBits()) {} 911 AlignInBits(N->getAlignInBits()) {}
882 912
883 bool isKeyOf(const DIGlobalVariable *RHS) const { 913 bool isKeyOf(const DIGlobalVariable *RHS) const {
884 return Scope == RHS->getRawScope() && Name == RHS->getRawName() && 914 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
885 LinkageName == RHS->getRawLinkageName() && 915 LinkageName == RHS->getRawLinkageName() &&
886 File == RHS->getRawFile() && Line == RHS->getLine() && 916 File == RHS->getRawFile() && Line == RHS->getLine() &&
887 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() && 917 Type == RHS->getRawType() && IsLocalToUnit == RHS->isLocalToUnit() &&
888 IsDefinition == RHS->isDefinition() && 918 IsDefinition == RHS->isDefinition() &&
889 StaticDataMemberDeclaration == 919 StaticDataMemberDeclaration ==
890 RHS->getRawStaticDataMemberDeclaration() && 920 RHS->getRawStaticDataMemberDeclaration() &&
921 TemplateParams == RHS->getRawTemplateParams() &&
891 AlignInBits == RHS->getAlignInBits(); 922 AlignInBits == RHS->getAlignInBits();
892 } 923 }
893 924
894 unsigned getHashValue() const { 925 unsigned getHashValue() const {
895 // We do not use AlignInBits in hashing function here on purpose: 926 // We do not use AlignInBits in hashing function here on purpose:
942 // TODO: make hashing work fine with such situations 973 // TODO: make hashing work fine with such situations
943 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags); 974 return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
944 } 975 }
945 }; 976 };
946 977
978 template <> struct MDNodeKeyImpl<DILabel> {
979 Metadata *Scope;
980 MDString *Name;
981 Metadata *File;
982 unsigned Line;
983
984 MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line)
985 : Scope(Scope), Name(Name), File(File), Line(Line) {}
986 MDNodeKeyImpl(const DILabel *N)
987 : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
988 Line(N->getLine()) {}
989
990 bool isKeyOf(const DILabel *RHS) const {
991 return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
992 File == RHS->getRawFile() && Line == RHS->getLine();
993 }
994
995 /// Using name and line to get hash value. It should already be mostly unique.
996 unsigned getHashValue() const {
997 return hash_combine(Scope, Name, Line);
998 }
999 };
1000
947 template <> struct MDNodeKeyImpl<DIExpression> { 1001 template <> struct MDNodeKeyImpl<DIExpression> {
948 ArrayRef<uint64_t> Elements; 1002 ArrayRef<uint64_t> Elements;
949 1003
950 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {} 1004 MDNodeKeyImpl(ArrayRef<uint64_t> Elements) : Elements(Elements) {}
951 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} 1005 MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {}
1078 unsigned getHashValue() const { 1132 unsigned getHashValue() const {
1079 return hash_combine(MIType, Line, File, Elements); 1133 return hash_combine(MIType, Line, File, Elements);
1080 } 1134 }
1081 }; 1135 };
1082 1136
1083 /// \brief DenseMapInfo for MDNode subclasses. 1137 /// DenseMapInfo for MDNode subclasses.
1084 template <class NodeTy> struct MDNodeInfo { 1138 template <class NodeTy> struct MDNodeInfo {
1085 using KeyTy = MDNodeKeyImpl<NodeTy>; 1139 using KeyTy = MDNodeKeyImpl<NodeTy>;
1086 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>; 1140 using SubsetEqualTy = MDNodeSubsetEqualImpl<NodeTy>;
1087 1141
1088 static inline NodeTy *getEmptyKey() { 1142 static inline NodeTy *getEmptyKey() {
1115 }; 1169 };
1116 1170
1117 #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>; 1171 #define HANDLE_MDNODE_LEAF(CLASS) using CLASS##Info = MDNodeInfo<CLASS>;
1118 #include "llvm/IR/Metadata.def" 1172 #include "llvm/IR/Metadata.def"
1119 1173
1120 /// \brief Map-like storage for metadata attachments. 1174 /// Map-like storage for metadata attachments.
1121 class MDAttachmentMap { 1175 class MDAttachmentMap {
1122 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments; 1176 SmallVector<std::pair<unsigned, TrackingMDNodeRef>, 2> Attachments;
1123 1177
1124 public: 1178 public:
1125 bool empty() const { return Attachments.empty(); } 1179 bool empty() const { return Attachments.empty(); }
1126 size_t size() const { return Attachments.size(); } 1180 size_t size() const { return Attachments.size(); }
1127 1181
1128 /// \brief Get a particular attachment (if any). 1182 /// Get a particular attachment (if any).
1129 MDNode *lookup(unsigned ID) const; 1183 MDNode *lookup(unsigned ID) const;
1130 1184
1131 /// \brief Set an attachment to a particular node. 1185 /// Set an attachment to a particular node.
1132 /// 1186 ///
1133 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c 1187 /// Set the \c ID attachment to \c MD, replacing the current attachment at \c
1134 /// ID (if anyway). 1188 /// ID (if anyway).
1135 void set(unsigned ID, MDNode &MD); 1189 void set(unsigned ID, MDNode &MD);
1136 1190
1137 /// \brief Remove an attachment. 1191 /// Remove an attachment.
1138 /// 1192 ///
1139 /// Remove the attachment at \c ID, if any. 1193 /// Remove the attachment at \c ID, if any.
1140 void erase(unsigned ID); 1194 bool erase(unsigned ID);
1141 1195
1142 /// \brief Copy out all the attachments. 1196 /// Copy out all the attachments.
1143 /// 1197 ///
1144 /// Copies all the current attachments into \c Result, sorting by attachment 1198 /// Copies all the current attachments into \c Result, sorting by attachment
1145 /// ID. This function does \em not clear \c Result. 1199 /// ID. This function does \em not clear \c Result.
1146 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; 1200 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1147 1201
1148 /// \brief Erase matching attachments. 1202 /// Erase matching attachments.
1149 /// 1203 ///
1150 /// Erases all attachments matching the \c shouldRemove predicate. 1204 /// Erases all attachments matching the \c shouldRemove predicate.
1151 template <class PredTy> void remove_if(PredTy shouldRemove) { 1205 template <class PredTy> void remove_if(PredTy shouldRemove) {
1152 Attachments.erase(llvm::remove_if(Attachments, shouldRemove), 1206 Attachments.erase(llvm::remove_if(Attachments, shouldRemove),
1153 Attachments.end()); 1207 Attachments.end());
1168 bool empty() const { return Attachments.empty(); } 1222 bool empty() const { return Attachments.empty(); }
1169 1223
1170 /// Appends all attachments with the given ID to \c Result in insertion order. 1224 /// 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, 1225 /// If the global has no attachments with the given ID, or if ID is invalid,
1172 /// leaves Result unchanged. 1226 /// leaves Result unchanged.
1173 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result); 1227 void get(unsigned ID, SmallVectorImpl<MDNode *> &Result) const;
1228
1229 /// Returns the first attachment with the given ID or nullptr if no such
1230 /// attachment exists.
1231 MDNode *lookup(unsigned ID) const;
1174 1232
1175 void insert(unsigned ID, MDNode &MD); 1233 void insert(unsigned ID, MDNode &MD);
1176 void erase(unsigned ID); 1234 bool erase(unsigned ID);
1177 1235
1178 /// Appends all attachments for the global to \c Result, sorting by attachment 1236 /// 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 1237 /// ID. Attachments with the same ID appear in insertion order. This function
1180 /// does \em not clear \c Result. 1238 /// does \em not clear \c Result.
1181 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const; 1239 void getAll(SmallVectorImpl<std::pair<unsigned, MDNode *>> &Result) const;
1184 class LLVMContextImpl { 1242 class LLVMContextImpl {
1185 public: 1243 public:
1186 /// OwnedModules - The set of modules instantiated in this context, and which 1244 /// OwnedModules - The set of modules instantiated in this context, and which
1187 /// will be automatically deleted if this context is deleted. 1245 /// will be automatically deleted if this context is deleted.
1188 SmallPtrSet<Module*, 4> OwnedModules; 1246 SmallPtrSet<Module*, 4> OwnedModules;
1189 1247
1190 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr; 1248 LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler = nullptr;
1191 void *InlineAsmDiagContext = nullptr; 1249 void *InlineAsmDiagContext = nullptr;
1192 1250
1193 std::unique_ptr<DiagnosticHandler> DiagHandler; 1251 std::unique_ptr<DiagnosticHandler> DiagHandler;
1194 bool RespectDiagnosticFilters = false; 1252 bool RespectDiagnosticFilters = false;
1195 bool DiagnosticsHotnessRequested = false; 1253 bool DiagnosticsHotnessRequested = false;
1196 uint64_t DiagnosticsHotnessThreshold = 0; 1254 uint64_t DiagnosticsHotnessThreshold = 0;
1197 std::unique_ptr<yaml::Output> DiagnosticsOutputFile; 1255 std::unique_ptr<RemarkStreamer> RemarkDiagStreamer;
1198 1256
1199 LLVMContext::YieldCallbackTy YieldCallback = nullptr; 1257 LLVMContext::YieldCallbackTy YieldCallback = nullptr;
1200 void *YieldOpaqueHandle = nullptr; 1258 void *YieldOpaqueHandle = nullptr;
1201 1259
1202 using IntMapTy = 1260 using IntMapTy =
1232 1290
1233 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants; 1291 DenseMap<Type *, std::unique_ptr<ConstantAggregateZero>> CAZConstants;
1234 1292
1235 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>; 1293 using ArrayConstantsTy = ConstantUniqueMap<ConstantArray>;
1236 ArrayConstantsTy ArrayConstants; 1294 ArrayConstantsTy ArrayConstants;
1237 1295
1238 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>; 1296 using StructConstantsTy = ConstantUniqueMap<ConstantStruct>;
1239 StructConstantsTy StructConstants; 1297 StructConstantsTy StructConstants;
1240 1298
1241 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>; 1299 using VectorConstantsTy = ConstantUniqueMap<ConstantVector>;
1242 VectorConstantsTy VectorConstants; 1300 VectorConstantsTy VectorConstants;
1243 1301
1244 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants; 1302 DenseMap<PointerType *, std::unique_ptr<ConstantPointerNull>> CPNConstants;
1245 1303
1263 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy; 1321 Type X86_FP80Ty, FP128Ty, PPC_FP128Ty, X86_MMXTy;
1264 #ifndef noCbC 1322 #ifndef noCbC
1265 Type __CodeTy; 1323 Type __CodeTy;
1266 #endif 1324 #endif
1267 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty; 1325 IntegerType Int1Ty, Int8Ty, Int16Ty, Int32Ty, Int64Ty, Int128Ty;
1268 1326
1269 /// TypeAllocator - All dynamically allocated types are allocated from this. 1327 BumpPtrAllocator Alloc;
1270 /// They live forever until the context is torn down. 1328 UniqueStringSaver Saver{Alloc};
1271 BumpPtrAllocator TypeAllocator; 1329
1272
1273 DenseMap<unsigned, IntegerType*> IntegerTypes; 1330 DenseMap<unsigned, IntegerType*> IntegerTypes;
1274 1331
1275 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>; 1332 using FunctionTypeSet = DenseSet<FunctionType *, FunctionTypeKeyInfo>;
1276 FunctionTypeSet FunctionTypes; 1333 FunctionTypeSet FunctionTypes;
1277 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>; 1334 using StructTypeSet = DenseSet<StructType *, AnonStructTypeKeyInfo>;
1278 StructTypeSet AnonStructTypes; 1335 StructTypeSet AnonStructTypes;
1279 StringMap<StructType*> NamedStructTypes; 1336 StringMap<StructType*> NamedStructTypes;
1280 unsigned NamedStructTypesUniqueID = 0; 1337 unsigned NamedStructTypesUniqueID = 0;
1281 1338
1282 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes; 1339 DenseMap<std::pair<Type *, uint64_t>, ArrayType*> ArrayTypes;
1283 DenseMap<std::pair<Type *, unsigned>, VectorType*> VectorTypes; 1340 DenseMap<std::pair<Type *, ElementCount>, VectorType*> VectorTypes;
1284 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0 1341 DenseMap<Type*, PointerType*> PointerTypes; // Pointers in AddrSpace = 0
1285 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes; 1342 DenseMap<std::pair<Type*, unsigned>, PointerType*> ASPointerTypes;
1286 1343
1287 /// ValueHandles - This map keeps track of all of the value handles that are 1344 /// ValueHandles - This map keeps track of all of the value handles that are
1288 /// watching a Value*. The Value::HasValueHandle bit is used to know 1345 /// watching a Value*. The Value::HasValueHandle bit is used to know
1289 /// whether or not a value has an entry in this map. 1346 /// whether or not a value has an entry in this map.
1290 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>; 1347 using ValueHandlesTy = DenseMap<Value *, ValueHandleBase *>;
1291 ValueHandlesTy ValueHandles; 1348 ValueHandlesTy ValueHandles;
1292 1349
1293 /// CustomMDKindNames - Map to hold the metadata string to ID mapping. 1350 /// CustomMDKindNames - Map to hold the metadata string to ID mapping.
1294 StringMap<unsigned> CustomMDKindNames; 1351 StringMap<unsigned> CustomMDKindNames;
1295 1352
1296 /// Collection of per-instruction metadata used in this context. 1353 /// Collection of per-instruction metadata used in this context.
1297 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata; 1354 DenseMap<const Instruction *, MDAttachmentMap> InstructionMetadata;
1300 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata; 1357 DenseMap<const GlobalObject *, MDGlobalAttachmentMap> GlobalObjectMetadata;
1301 1358
1302 /// Collection of per-GlobalObject sections used in this context. 1359 /// Collection of per-GlobalObject sections used in this context.
1303 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections; 1360 DenseMap<const GlobalObject *, StringRef> GlobalObjectSections;
1304 1361
1305 /// Stable collection of section strings. 1362 /// Collection of per-GlobalValue partitions used in this context.
1306 StringSet<> SectionStrings; 1363 DenseMap<const GlobalValue *, StringRef> GlobalValuePartitions;
1307 1364
1308 /// DiscriminatorTable - This table maps file:line locations to an 1365 /// DiscriminatorTable - This table maps file:line locations to an
1309 /// integer representing the next DWARF path discriminator to assign to 1366 /// integer representing the next DWARF path discriminator to assign to
1310 /// instructions in different blocks at the same location. 1367 /// instructions in different blocks at the same location.
1311 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable; 1368 DenseMap<std::pair<const char *, unsigned>, unsigned> DiscriminatorTable;
1312 1369
1313 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx); 1370 int getOrAddScopeRecordIdxEntry(MDNode *N, int ExistingIdx);
1314 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx); 1371 int getOrAddScopeInlinedAtIdxEntry(MDNode *Scope, MDNode *IA,int ExistingIdx);
1315 1372
1316 /// \brief A set of interned tags for operand bundles. The StringMap maps 1373 /// A set of interned tags for operand bundles. The StringMap maps
1317 /// bundle tags to their IDs. 1374 /// bundle tags to their IDs.
1318 /// 1375 ///
1319 /// \see LLVMContext::getOperandBundleTagID 1376 /// \see LLVMContext::getOperandBundleTagID
1320 StringMap<uint32_t> BundleTagCache; 1377 StringMap<uint32_t> BundleTagCache;
1321 1378
1352 ~LLVMContextImpl(); 1409 ~LLVMContextImpl();
1353 1410
1354 /// Destroy the ConstantArrays if they are not used. 1411 /// Destroy the ConstantArrays if they are not used.
1355 void dropTriviallyDeadConstantArrays(); 1412 void dropTriviallyDeadConstantArrays();
1356 1413
1357 /// \brief Access the object which manages optimization bisection for failure 1414 mutable OptPassGate *OPG = nullptr;
1358 /// analysis. 1415
1359 OptBisect &getOptBisect(); 1416 /// Access the object which can disable optional passes and individual
1417 /// optimizations at compile time.
1418 OptPassGate &getOptPassGate() const;
1419
1420 /// Set the object which can disable optional passes and individual
1421 /// optimizations at compile time.
1422 ///
1423 /// The lifetime of the object must be guaranteed to extend as long as the
1424 /// LLVMContext is used by compilation.
1425 void setOptPassGate(OptPassGate&);
1360 }; 1426 };
1361 1427
1362 } // end namespace llvm 1428 } // end namespace llvm
1363 1429
1364 #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H 1430 #endif // LLVM_LIB_IR_LLVMCONTEXTIMPL_H